diff --git a/README.md b/README.md index 45ad016f9..4acbba1cf 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,12 @@ Type: `boolean` Prevent the staging folder from being deleted after creating the package. Defaults to `false`, meaning that the folder is deleted every time. +#### `removeParameterTypes` + +Type: `boolean` + +If true, removes the explicit type to function's parameters and return (i.e. the `as type` syntax); otherwise keep this information. + #### `files` Type: diff --git a/bsconfig.schema.json b/bsconfig.schema.json index af9668980..fea4b494b 100644 --- a/bsconfig.schema.json +++ b/bsconfig.schema.json @@ -149,6 +149,11 @@ "type": "boolean", "default": false }, + "removeParameterTypes": { + "description": "Removes the explicit type to function's parameters and return (i.e. the `as type` syntax) ", + "type": "boolean", + "default": false + }, "diagnosticFilters": { "description": "A collection of filters used to hide diagnostics for certain files", "type": "array", diff --git a/src/BsConfig.ts b/src/BsConfig.ts index 51c6ba995..34423f3c8 100644 --- a/src/BsConfig.ts +++ b/src/BsConfig.ts @@ -117,6 +117,12 @@ export interface BsConfig { */ emitDefinitions?: boolean; + /** + * If true, removes the explicit type to function's parameters and return (i.e. the `as type` syntax); otherwise keep this information. + * @default false + */ + removeParameterTypes?: boolean; + /** * A list of filters used to exclude diagnostics from the output */ diff --git a/src/files/BrsFile.spec.ts b/src/files/BrsFile.spec.ts index 76fc4e29f..e89f26072 100644 --- a/src/files/BrsFile.spec.ts +++ b/src/files/BrsFile.spec.ts @@ -2332,6 +2332,30 @@ describe('BrsFile', () => { `); }); + it('discard parameter types when removeParameterTypes is true', () => { + program.options.removeParameterTypes = true; + testTranspile(` + sub one(a as integer, b = "" as string, c = invalid as dynamic) + end sub + `, ` + sub one(a, b = "", c = invalid) + end sub + `); + }); + + it('discard return type when removeParameterTypes is true', () => { + program.options.removeParameterTypes = true; + testTranspile(` + function one() as string + return "" + end function + `, ` + function one() + return "" + end function + `); + }); + it('transpiles local var assignment operators', () => { testTranspile(` sub main() diff --git a/src/parser/Expression.ts b/src/parser/Expression.ts index 25d80211a..19bd26cb4 100644 --- a/src/parser/Expression.ts +++ b/src/parser/Expression.ts @@ -232,7 +232,7 @@ export class FunctionExpression extends Expression implements TypedefProvider { state.transpileToken(this.rightParen) ); //as [Type] - if (this.asToken) { + if (this.asToken && !state.options.removeParameterTypes) { results.push( ' ', //as @@ -317,7 +317,7 @@ export class FunctionParameterExpression extends Expression { result.push(this.defaultValue.transpile(state)); } //type declaration - if (this.asToken) { + if (this.asToken && !state.options.removeParameterTypes) { result.push(' '); result.push(state.transpileToken(this.asToken)); result.push(' '); diff --git a/src/util.ts b/src/util.ts index d1676e8f6..c36adc753 100644 --- a/src/util.ts +++ b/src/util.ts @@ -343,6 +343,7 @@ export class Util { config.sourceRoot = config.sourceRoot ? standardizePath(config.sourceRoot) : undefined; config.allowBrighterScriptInBrightScript = config.allowBrighterScriptInBrightScript === true ? true : false; config.emitDefinitions = config.emitDefinitions === true ? true : false; + config.removeParameterTypes = config.removeParameterTypes === true ? true : false; if (typeof config.logLevel === 'string') { config.logLevel = LogLevel[(config.logLevel as string).toLowerCase()]; }