From d99addb1b7230fbd4c0fd276b59c14c64b0bc240 Mon Sep 17 00:00:00 2001 From: Mark Pearce Date: Tue, 30 Jan 2024 14:19:02 -0400 Subject: [PATCH 1/3] Changed adding invalid as arg to empty callfunc invocations by default --- bsconfig.schema.json | 5 +++++ src/BsConfig.ts | 6 ++++++ src/files/BrsFile.spec.ts | 21 ++++++++++++++++++++- src/parser/Expression.ts | 14 +++++++------- src/util.ts | 3 ++- 5 files changed, 40 insertions(+), 9 deletions(-) diff --git a/bsconfig.schema.json b/bsconfig.schema.json index e7b071a8b..8686643df 100644 --- a/bsconfig.schema.json +++ b/bsconfig.schema.json @@ -281,6 +281,11 @@ "description": "Allow brighterscript features (classes, interfaces, etc...) to be included in BrightScript (`.brs`) files, and force those files to be transpiled.", "type": "boolean", "default": false + }, + "legacyCallfuncHandling": { + "description": "Legacy RokuOS versions required at least a single argument in callfunc() invocations. Previous brighterscript versions handled this by inserting invalid as an argument when no other args are present. This is not necessary in modern RokuOS versions.", + "type": "boolean", + "default": false } } } \ No newline at end of file diff --git a/src/BsConfig.ts b/src/BsConfig.ts index 99289cb9e..073057271 100644 --- a/src/BsConfig.ts +++ b/src/BsConfig.ts @@ -195,6 +195,12 @@ export interface BsConfig { * scripts inside `source` that depend on bslib.brs. Defaults to `source`. */ bslibDestinationDir?: string; + + /* Legacy RokuOS versions required at least a single argument in callfunc() invocations. + * Previous brighterscript versions handled this by inserting invalid as an argument when no other args are present. + * This is not necessary in modern RokuOS versions. + */ + legacyCallfuncHandling?: boolean; } type OptionalBsConfigFields = diff --git a/src/files/BrsFile.spec.ts b/src/files/BrsFile.spec.ts index 9290f2dd3..25f950b26 100644 --- a/src/files/BrsFile.spec.ts +++ b/src/files/BrsFile.spec.ts @@ -2613,7 +2613,8 @@ describe('BrsFile', () => { expectZeroDiagnostics(program); }); - it('sets invalid on empty callfunc', async () => { + it('sets invalid on empty callfunc with legacyCallfuncHandling=true', async () => { + program.options.legacyCallfuncHandling = true; await testTranspile(` sub main() node = invalid @@ -2631,6 +2632,24 @@ describe('BrsFile', () => { `); }); + it('empty callfunc allowed by default', async () => { + await testTranspile(` + sub main() + node = invalid + node@.doSomething() + m.top.node@.doSomething() + m.top.node@.doSomething(1) + end sub + `, ` + sub main() + node = invalid + node.callfunc("doSomething") + m.top.node.callfunc("doSomething") + m.top.node.callfunc("doSomething", 1) + end sub + `); + }); + it('includes original arguments', async () => { await testTranspile(` sub main() diff --git a/src/parser/Expression.ts b/src/parser/Expression.ts index a8a8c628a..6dbb42dbb 100644 --- a/src/parser/Expression.ts +++ b/src/parser/Expression.ts @@ -1140,14 +1140,11 @@ export class CallfuncExpression extends Expression { state.sourceNode(this.operator, '.callfunc'), state.transpileToken(this.openingParen), //the name of the function - state.sourceNode(this.methodName, ['"', this.methodName.text, '"']), - ', ' + state.sourceNode(this.methodName, ['"', this.methodName.text, '"']) ); - //transpile args - //callfunc with zero args never gets called, so pass invalid as the first parameter if there are no args - if (this.args.length === 0) { - result.push('invalid'); - } else { + if (this.args?.length > 0) { + result.push(', '); + //transpile args for (let i = 0; i < this.args.length; i++) { //add comma between args if (i > 0) { @@ -1156,7 +1153,10 @@ export class CallfuncExpression extends Expression { let arg = this.args[i]; result.push(...arg.transpile(state)); } + } else if (state.options.legacyCallfuncHandling) { + result.push(', ', 'invalid'); } + result.push( state.transpileToken(this.closingParen) ); diff --git a/src/util.ts b/src/util.ts index a245ff869..5a55d53a2 100644 --- a/src/util.ts +++ b/src/util.ts @@ -375,7 +375,8 @@ export class Util { emitDefinitions: config.emitDefinitions === true ? true : false, removeParameterTypes: config.removeParameterTypes === true ? true : false, logLevel: logLevel, - bslibDestinationDir: bslibDestinationDir + bslibDestinationDir: bslibDestinationDir, + legacyCallfuncHandling: config.legacyCallfuncHandling === true ? true : false }; //mutate `config` in case anyone is holding a reference to the incomplete one From d601c1949494465bd86a9a28229af4b794607650 Mon Sep 17 00:00:00 2001 From: Mark Pearce Date: Wed, 31 Jan 2024 10:23:44 -0400 Subject: [PATCH 2/3] Update src/BsConfig.ts Co-authored-by: Bronley Plumb --- src/BsConfig.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/BsConfig.ts b/src/BsConfig.ts index 073057271..372322e0b 100644 --- a/src/BsConfig.ts +++ b/src/BsConfig.ts @@ -196,7 +196,7 @@ export interface BsConfig { */ bslibDestinationDir?: string; - /* Legacy RokuOS versions required at least a single argument in callfunc() invocations. + /* Legacy RokuOS versions required at least one argument in callfunc() invocations. * Previous brighterscript versions handled this by inserting invalid as an argument when no other args are present. * This is not necessary in modern RokuOS versions. */ From 06df98e5e1741e3daa711d60d519c48018a22b1c Mon Sep 17 00:00:00 2001 From: Mark Pearce Date: Wed, 31 Jan 2024 10:23:49 -0400 Subject: [PATCH 3/3] Update bsconfig.schema.json Co-authored-by: Bronley Plumb --- bsconfig.schema.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bsconfig.schema.json b/bsconfig.schema.json index 8686643df..67e4649a5 100644 --- a/bsconfig.schema.json +++ b/bsconfig.schema.json @@ -283,7 +283,7 @@ "default": false }, "legacyCallfuncHandling": { - "description": "Legacy RokuOS versions required at least a single argument in callfunc() invocations. Previous brighterscript versions handled this by inserting invalid as an argument when no other args are present. This is not necessary in modern RokuOS versions.", + "description": "Legacy RokuOS versions required at least one argument in callfunc() invocations. Previous brighterscript versions handled this by inserting invalid as an argument when no other args are present. This is not necessary in modern RokuOS versions.", "type": "boolean", "default": false }