Skip to content

Commit a27f270

Browse files
committed
modifyEverythingToV2: added arg : is_AHK_H=true ; const whichBuffer = is_AHK_H ? 'BufferAlloc' : 'Buffer' ; #16
1 parent 13bd696 commit a27f270

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
'key-spacing':['error',{'afterColon':false}],
2222
'object-curly-spacing':'off',
2323
'@typescript-eslint/object-curly-spacing':['error','never'],
24-
'@typescript-eslint/naming-convention':'warn',
24+
'@typescript-eslint/naming-convention':'off',
2525
'@typescript-eslint/semi':['error','never'],
2626
'semi':'off',
2727
'curly':'warn',

mocha/test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('toV2(text)',function() {
1212
describe('VarSetCapacity()',function() {
1313
doIt('VarSetCapacity(a,b,c)','a:=BufferAlloc(b,c)')
1414
doIt('VarSetCapacity(a,VarSetCapacity(a,b,c),c)','a:=BufferAlloc(a:=BufferAlloc(b,c),c)')
15+
doIt('VarSetCapacity(a,b,c)','a:=Buffer(b,c)',false)
1516
})
1617
// describe('v1 removed #DIRECTIVES',function() {
1718
// doIt('#NoEnv\n','')
@@ -35,21 +36,21 @@ describe('toV2(text)',function() {
3536

3637
})
3738

38-
function toV2(text) {
39+
function toV2(text,is_AHK_H = true) {
3940
const everything = ahkParser(text.replace(/\r/g,''))
40-
const converted = modifyEverythingToV2(everything)
41+
const converted = modifyEverythingToV2(everything,is_AHK_H)
4142
return converted
4243
}
43-
function doIt(v1,v2) {
44+
function doIt(v1,v2,is_AHK_H = true) {
4445
it(`\`${v1}\`,\`${v2}\``,function() {
45-
strictEqual(toV2(v1),v2)
46+
strictEqual(toV2(v1,is_AHK_H),v2)
4647
})
4748
}
4849
function readFileToString(path) {
4950
return fs.readFileSync(`${__dirname}/${path}`).toString()
5051
}
51-
function doItFiles(path1,path2) {
52+
function doItFiles(path1,path2,is_AHK_H = true) {
5253
it(`FILE: '${path1}' vs '${path2}'`,function() {
53-
strictEqual(toV2(readFileToString(path1)),readFileToString(path2))
54+
strictEqual(toV2(readFileToString(path1),is_AHK_H),readFileToString(path2))
5455
})
5556
}

src/modifyEverythingToV2.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ const startOfV1Expr: stringIndexBool = {'v1String findV1Expression':true,'%START
5151

5252
const typesThatAreVars: stringIndexBool = {'Param':true,'idkVariable':true,'assignment':true,'v1String findIdkVar':true,'var at v1Assignment':true}
5353

54-
export default (everything: ExtendedEverythingType): string => {
54+
export default (everything: ExtendedEverythingType,is_AHK_H = true): string => {
55+
const whichBuffer = is_AHK_H ? 'BufferAlloc' : 'Buffer'
5556
// I'd never think I'd come to this day, but..
5657
// preprocessing..
5758
const varNames: {[key: string]: true} = {}
@@ -227,7 +228,7 @@ export default (everything: ExtendedEverythingType): string => {
227228
} else {
228229
// VarSetStrCapacity(TargetVar, RequestedCapacity, FillByte)
229230
// TargetVar:=BufferAlloc(RequestedCapacity,FillByte)
230-
a(1); p(':=BufferAlloc('); a(2); o(',',3); a(3); p(')'); s()
231+
a(1); p(`:=${whichBuffer}(`); a(2); o(',',3); a(3); p(')'); s()
231232
}
232233
} else if (thisLowered === 'strreplace') {
233234
// StrReplace(Haystack, Needle [, ReplaceText, OutputVarCount, Limit])
@@ -271,7 +272,7 @@ export default (everything: ExtendedEverythingType): string => {
271272
// ObjSetCapacity( this, "allData", newSize )
272273
// NOPE: this["allData"].Size := newSize
273274
// this["allData"]:=BufferAlloc(newSize)
274-
a(1); p('['); a(2); p(']:=BufferAlloc('); a(3); p(')'); s()
275+
a(1); p('['); a(2); p(`]:=${whichBuffer}(`); a(3); p(')'); s()
275276
} else {
276277
p('ObjSetCapacity('); a(1); p(','); a(2); p(')'); s()
277278
}

0 commit comments

Comments
 (0)