brighterscript 0.57.2 → 0.59.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +31 -0
- package/README.md +16 -6
- package/bsconfig.schema.json +11 -0
- package/dist/BsConfig.d.ts +11 -0
- package/dist/DiagnosticMessages.d.ts +7 -2
- package/dist/DiagnosticMessages.js +7 -2
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/Program.d.ts +12 -2
- package/dist/Program.js +69 -24
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +1 -1
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +6 -3
- package/dist/Scope.js +24 -17
- package/dist/Scope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +2 -3
- package/dist/astUtils/AstEditor.js.map +1 -1
- package/dist/astUtils/creators.d.ts +4 -4
- package/dist/astUtils/creators.js +6 -6
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +67 -64
- package/dist/astUtils/reflection.js +10 -2
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +8 -3
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +33 -31
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.js +4 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +6 -6
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +40 -34
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -2
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +2 -2
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +4 -5
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +2 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +166 -12
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +21 -19
- package/dist/bscPlugin/validation/ScopeValidator.js +164 -179
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +33 -35
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +11 -5
- package/dist/files/BrsFile.js +15 -47
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +107 -79
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +9 -4
- package/dist/files/XmlFile.js +6 -30
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +57 -90
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +13 -15
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +10 -12
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +2 -3
- package/dist/lexer/Lexer.spec.js +6 -0
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +1 -0
- package/dist/lexer/TokenKind.js +6 -2
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +65 -0
- package/dist/parser/AstNode.js +93 -0
- package/dist/parser/AstNode.js.map +1 -0
- package/dist/parser/AstNode.spec.d.ts +1 -0
- package/dist/parser/AstNode.spec.js +42 -0
- package/dist/parser/AstNode.spec.js.map +1 -0
- package/dist/parser/Expression.d.ts +6 -43
- package/dist/parser/Expression.js +53 -81
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.d.ts +15 -12
- package/dist/parser/Parser.js +130 -117
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.d.ts +1 -1
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.spec.js +2 -3
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +28 -44
- package/dist/parser/Statement.js +118 -104
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +16 -10
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +37 -0
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +41 -0
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +109 -1
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +49 -4
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +7 -7
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Continue.spec.js +92 -0
- package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
- package/dist/parser/tests/statement/Enum.spec.js +36 -9
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/For.spec.js +3 -4
- package/dist/parser/tests/statement/For.spec.js.map +1 -1
- package/dist/parser/tests/statement/ForEach.spec.js +4 -5
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +4 -5
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +3 -4
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/util.d.ts +11 -5
- package/dist/util.js +57 -6
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +22 -19
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("../util");
|
|
4
|
+
const fsExtra = require("fs-extra");
|
|
5
|
+
const Program_1 = require("../Program");
|
|
6
|
+
const chai_1 = require("chai");
|
|
7
|
+
const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
8
|
+
const testHelpers_spec_2 = require("../testHelpers.spec");
|
|
9
|
+
describe('Program', () => {
|
|
10
|
+
let program;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
|
|
13
|
+
program = new Program_1.Program({
|
|
14
|
+
rootDir: testHelpers_spec_2.rootDir,
|
|
15
|
+
stagingDir: testHelpers_spec_2.stagingDir
|
|
16
|
+
});
|
|
17
|
+
program.createSourceScope(); //ensure source scope is created
|
|
18
|
+
});
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
|
|
21
|
+
program.dispose();
|
|
22
|
+
});
|
|
23
|
+
describe('AstNode', () => {
|
|
24
|
+
describe('findNodeAtPosition', () => {
|
|
25
|
+
it('finds deepest AstNode that matches the position', () => {
|
|
26
|
+
const file = program.setFile('source/main.brs', `
|
|
27
|
+
sub main()
|
|
28
|
+
alpha = invalid
|
|
29
|
+
print alpha.beta.charlie.delta(alpha.echo.foxtrot())
|
|
30
|
+
end sub
|
|
31
|
+
`);
|
|
32
|
+
program.validate();
|
|
33
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
34
|
+
const delta = file.ast.findChildAtPosition(util_1.util.createPosition(3, 52));
|
|
35
|
+
(0, chai_1.expect)(delta.name.text).to.eql('delta');
|
|
36
|
+
const foxtrot = file.ast.findChildAtPosition(util_1.util.createPosition(3, 71));
|
|
37
|
+
(0, chai_1.expect)(foxtrot.name.text).to.eql('foxtrot');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=AstNode.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AstNode.spec.js","sourceRoot":"","sources":["../../src/parser/AstNode.spec.ts"],"names":[],"mappings":";;AAAA,kCAA+B;AAC/B,oCAAoC;AACpC,wCAAqC;AAErC,+BAA8B;AAE9B,0DAA4D;AAC5D,0DAAmE;AAEnE,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACrB,IAAI,OAAgB,CAAC;IAErB,UAAU,CAAC,GAAG,EAAE;QACZ,OAAO,CAAC,YAAY,CAAC,0BAAO,CAAC,CAAC;QAC9B,OAAO,GAAG,IAAI,iBAAO,CAAC;YAClB,OAAO,EAAE,0BAAO;YAChB,UAAU,EAAE,6BAAU;SACzB,CAAC,CAAC;QACH,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC,gCAAgC;IACjE,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,YAAY,CAAC,0BAAO,CAAC,CAAC;QAC9B,OAAO,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;QACrB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,EAAE;YAChC,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE;gBACvD,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,CAAU,iBAAiB,EAAE;;;;;iBAKxD,CAAC,CAAC;gBACH,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACnB,IAAA,wCAAqB,EAAC,OAAO,CAAC,CAAC;gBAC/B,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAsB,WAAI,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;gBAC5F,IAAA,aAAM,EAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAExC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAsB,WAAI,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;gBAC9F,IAAA,aAAM,EAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAChD,CAAC,CAAC,CAAC;QACP,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -1,36 +1,14 @@
|
|
|
1
1
|
import type { Token, Identifier } from '../lexer/Token';
|
|
2
|
-
import type { Block, CommentStatement, FunctionStatement
|
|
2
|
+
import type { Block, CommentStatement, FunctionStatement } from './Statement';
|
|
3
3
|
import type { Range } from 'vscode-languageserver';
|
|
4
4
|
import type { BrsTranspileState } from './BrsTranspileState';
|
|
5
5
|
import { ParseMode } from './Parser';
|
|
6
6
|
import type { WalkOptions, WalkVisitor } from '../astUtils/visitors';
|
|
7
|
-
import { InternalWalkMode } from '../astUtils/visitors';
|
|
8
7
|
import type { TranspileResult, TypedefProvider } from '../interfaces';
|
|
9
8
|
import type { BscType } from '../types/BscType';
|
|
10
9
|
import { FunctionType } from '../types/FunctionType';
|
|
11
|
-
import {
|
|
10
|
+
import { Expression } from './AstNode';
|
|
12
11
|
export declare type ExpressionVisitor = (expression: Expression, parent: Expression) => void;
|
|
13
|
-
/** A BrightScript expression */
|
|
14
|
-
export declare abstract class Expression {
|
|
15
|
-
/**
|
|
16
|
-
* The starting and ending location of the expression.
|
|
17
|
-
*/
|
|
18
|
-
abstract range: Range;
|
|
19
|
-
abstract transpile(state: BrsTranspileState): TranspileResult;
|
|
20
|
-
/**
|
|
21
|
-
* When being considered by the walk visitor, this describes what type of element the current class is.
|
|
22
|
-
*/
|
|
23
|
-
visitMode: InternalWalkMode;
|
|
24
|
-
abstract walk(visitor: WalkVisitor, options: WalkOptions): any;
|
|
25
|
-
/**
|
|
26
|
-
* The parent node for this expression. This is set dynamically during `onFileValidate`, and should not be set directly.
|
|
27
|
-
*/
|
|
28
|
-
parent?: Statement | Expression;
|
|
29
|
-
/**
|
|
30
|
-
* Get the closest symbol table for this node. Should be overridden in children that directly contain a symbol table
|
|
31
|
-
*/
|
|
32
|
-
getSymbolTable(): SymbolTable;
|
|
33
|
-
}
|
|
34
12
|
export declare class BinaryExpression extends Expression {
|
|
35
13
|
left: Expression;
|
|
36
14
|
operator: Token;
|
|
@@ -48,20 +26,12 @@ export declare class CallExpression extends Expression {
|
|
|
48
26
|
readonly openingParen: Token;
|
|
49
27
|
readonly closingParen: Token;
|
|
50
28
|
readonly args: Expression[];
|
|
51
|
-
/**
|
|
52
|
-
* The namespace that currently wraps this call expression. This is NOT the namespace of the callee...that will be represented in the callee expression itself.
|
|
53
|
-
*/
|
|
54
|
-
readonly namespaceName: NamespacedVariableNameExpression;
|
|
55
29
|
static MaximumArguments: number;
|
|
56
30
|
constructor(callee: Expression,
|
|
57
31
|
/**
|
|
58
32
|
* Can either be `(`, or `?(` for optional chaining
|
|
59
33
|
*/
|
|
60
|
-
openingParen: Token, closingParen: Token, args: Expression[]
|
|
61
|
-
/**
|
|
62
|
-
* The namespace that currently wraps this call expression. This is NOT the namespace of the callee...that will be represented in the callee expression itself.
|
|
63
|
-
*/
|
|
64
|
-
namespaceName: NamespacedVariableNameExpression);
|
|
34
|
+
openingParen: Token, closingParen: Token, args: Expression[]);
|
|
65
35
|
readonly range: Range;
|
|
66
36
|
transpile(state: BrsTranspileState, nameOverride?: string): any[];
|
|
67
37
|
walk(visitor: WalkVisitor, options: WalkOptions): void;
|
|
@@ -79,15 +49,11 @@ export declare class FunctionExpression extends Expression implements TypedefPro
|
|
|
79
49
|
* If this function is enclosed within another function, this will reference that parent function
|
|
80
50
|
*/
|
|
81
51
|
readonly parentFunction?: FunctionExpression;
|
|
82
|
-
readonly namespaceName?: NamespacedVariableNameExpression;
|
|
83
|
-
readonly parentSymbolTable?: SymbolTable;
|
|
84
52
|
constructor(parameters: FunctionParameterExpression[], body: Block, functionType: Token | null, end: Token, leftParen: Token, rightParen: Token, asToken?: Token, returnTypeToken?: Token,
|
|
85
53
|
/**
|
|
86
54
|
* If this function is enclosed within another function, this will reference that parent function
|
|
87
55
|
*/
|
|
88
|
-
parentFunction?: FunctionExpression
|
|
89
|
-
symbolTable: SymbolTable;
|
|
90
|
-
getSymbolTable(): SymbolTable;
|
|
56
|
+
parentFunction?: FunctionExpression);
|
|
91
57
|
/**
|
|
92
58
|
* The type this function returns
|
|
93
59
|
*/
|
|
@@ -120,8 +86,7 @@ export declare class FunctionParameterExpression extends Expression {
|
|
|
120
86
|
typeToken?: Token;
|
|
121
87
|
defaultValue?: Expression;
|
|
122
88
|
asToken?: Token;
|
|
123
|
-
|
|
124
|
-
constructor(name: Identifier, typeToken?: Token, defaultValue?: Expression, asToken?: Token, namespaceName?: NamespacedVariableNameExpression);
|
|
89
|
+
constructor(name: Identifier, typeToken?: Token, defaultValue?: Expression, asToken?: Token);
|
|
125
90
|
type: BscType;
|
|
126
91
|
get range(): Range;
|
|
127
92
|
transpile(state: BrsTranspileState): any[];
|
|
@@ -268,8 +233,7 @@ export declare class UnaryExpression extends Expression {
|
|
|
268
233
|
}
|
|
269
234
|
export declare class VariableExpression extends Expression {
|
|
270
235
|
readonly name: Identifier;
|
|
271
|
-
|
|
272
|
-
constructor(name: Identifier, namespaceName: NamespacedVariableNameExpression);
|
|
236
|
+
constructor(name: Identifier);
|
|
273
237
|
readonly range: Range;
|
|
274
238
|
getName(parseMode: ParseMode): string;
|
|
275
239
|
transpile(state: BrsTranspileState): any[];
|
|
@@ -296,7 +260,6 @@ export declare class NewExpression extends Expression {
|
|
|
296
260
|
* The name of the class to initialize (with optional namespace prefixed)
|
|
297
261
|
*/
|
|
298
262
|
get className(): NamespacedVariableNameExpression;
|
|
299
|
-
get namespaceName(): NamespacedVariableNameExpression;
|
|
300
263
|
readonly range: Range;
|
|
301
264
|
transpile(state: BrsTranspileState): any[];
|
|
302
265
|
walk(visitor: WalkVisitor, options: WalkOptions): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression =
|
|
3
|
+
exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = void 0;
|
|
4
4
|
const TokenKind_1 = require("../lexer/TokenKind");
|
|
5
5
|
const util_1 = require("../util");
|
|
6
6
|
const Parser_1 = require("./Parser");
|
|
@@ -10,25 +10,8 @@ const reflection_1 = require("../astUtils/reflection");
|
|
|
10
10
|
const VoidType_1 = require("../types/VoidType");
|
|
11
11
|
const DynamicType_1 = require("../types/DynamicType");
|
|
12
12
|
const FunctionType_1 = require("../types/FunctionType");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
class Expression {
|
|
16
|
-
constructor() {
|
|
17
|
-
/**
|
|
18
|
-
* When being considered by the walk visitor, this describes what type of element the current class is.
|
|
19
|
-
*/
|
|
20
|
-
this.visitMode = visitors_1.InternalWalkMode.visitExpressions;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Get the closest symbol table for this node. Should be overridden in children that directly contain a symbol table
|
|
24
|
-
*/
|
|
25
|
-
getSymbolTable() {
|
|
26
|
-
var _a;
|
|
27
|
-
return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
exports.Expression = Expression;
|
|
31
|
-
class BinaryExpression extends Expression {
|
|
13
|
+
const AstNode_1 = require("./AstNode");
|
|
14
|
+
class BinaryExpression extends AstNode_1.Expression {
|
|
32
15
|
constructor(left, operator, right) {
|
|
33
16
|
super();
|
|
34
17
|
this.left = left;
|
|
@@ -53,23 +36,18 @@ class BinaryExpression extends Expression {
|
|
|
53
36
|
}
|
|
54
37
|
}
|
|
55
38
|
exports.BinaryExpression = BinaryExpression;
|
|
56
|
-
class CallExpression extends Expression {
|
|
39
|
+
class CallExpression extends AstNode_1.Expression {
|
|
57
40
|
constructor(callee,
|
|
58
41
|
/**
|
|
59
42
|
* Can either be `(`, or `?(` for optional chaining
|
|
60
43
|
*/
|
|
61
|
-
openingParen, closingParen, args
|
|
62
|
-
/**
|
|
63
|
-
* The namespace that currently wraps this call expression. This is NOT the namespace of the callee...that will be represented in the callee expression itself.
|
|
64
|
-
*/
|
|
65
|
-
namespaceName) {
|
|
44
|
+
openingParen, closingParen, args) {
|
|
66
45
|
super();
|
|
67
46
|
this.callee = callee;
|
|
68
47
|
this.openingParen = openingParen;
|
|
69
48
|
this.closingParen = closingParen;
|
|
70
49
|
this.args = args;
|
|
71
|
-
this.
|
|
72
|
-
this.range = util_1.default.createRangeFromPositions(this.callee.range.start, this.closingParen.range.end);
|
|
50
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.openingParen, ...args, this.closingParen);
|
|
73
51
|
}
|
|
74
52
|
transpile(state, nameOverride) {
|
|
75
53
|
let result = [];
|
|
@@ -89,7 +67,9 @@ class CallExpression extends Expression {
|
|
|
89
67
|
let arg = this.args[i];
|
|
90
68
|
result.push(...arg.transpile(state));
|
|
91
69
|
}
|
|
92
|
-
|
|
70
|
+
if (this.closingParen) {
|
|
71
|
+
result.push(state.transpileToken(this.closingParen));
|
|
72
|
+
}
|
|
93
73
|
return result;
|
|
94
74
|
}
|
|
95
75
|
walk(visitor, options) {
|
|
@@ -101,12 +81,12 @@ class CallExpression extends Expression {
|
|
|
101
81
|
}
|
|
102
82
|
exports.CallExpression = CallExpression;
|
|
103
83
|
CallExpression.MaximumArguments = 32;
|
|
104
|
-
class FunctionExpression extends Expression {
|
|
84
|
+
class FunctionExpression extends AstNode_1.Expression {
|
|
105
85
|
constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeToken,
|
|
106
86
|
/**
|
|
107
87
|
* If this function is enclosed within another function, this will reference that parent function
|
|
108
88
|
*/
|
|
109
|
-
parentFunction
|
|
89
|
+
parentFunction) {
|
|
110
90
|
super();
|
|
111
91
|
this.parameters = parameters;
|
|
112
92
|
this.body = body;
|
|
@@ -117,8 +97,6 @@ class FunctionExpression extends Expression {
|
|
|
117
97
|
this.asToken = asToken;
|
|
118
98
|
this.returnTypeToken = returnTypeToken;
|
|
119
99
|
this.parentFunction = parentFunction;
|
|
120
|
-
this.namespaceName = namespaceName;
|
|
121
|
-
this.parentSymbolTable = parentSymbolTable;
|
|
122
100
|
/**
|
|
123
101
|
* The list of function calls that are declared within this function scope. This excludes CallExpressions
|
|
124
102
|
* declared in child functions
|
|
@@ -137,13 +115,6 @@ class FunctionExpression extends Expression {
|
|
|
137
115
|
else {
|
|
138
116
|
this.returnType = DynamicType_1.DynamicType.instance;
|
|
139
117
|
}
|
|
140
|
-
this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
|
|
141
|
-
for (let param of parameters) {
|
|
142
|
-
this.symbolTable.addSymbol(param.name.text, param.name.range, DynamicType_1.DynamicType.instance);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
getSymbolTable() {
|
|
146
|
-
return this.symbolTable;
|
|
147
118
|
}
|
|
148
119
|
/**
|
|
149
120
|
* The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
|
|
@@ -216,14 +187,13 @@ class FunctionExpression extends Expression {
|
|
|
216
187
|
}
|
|
217
188
|
}
|
|
218
189
|
exports.FunctionExpression = FunctionExpression;
|
|
219
|
-
class FunctionParameterExpression extends Expression {
|
|
220
|
-
constructor(name, typeToken, defaultValue, asToken
|
|
190
|
+
class FunctionParameterExpression extends AstNode_1.Expression {
|
|
191
|
+
constructor(name, typeToken, defaultValue, asToken) {
|
|
221
192
|
super();
|
|
222
193
|
this.name = name;
|
|
223
194
|
this.typeToken = typeToken;
|
|
224
195
|
this.defaultValue = defaultValue;
|
|
225
196
|
this.asToken = asToken;
|
|
226
|
-
this.namespaceName = namespaceName;
|
|
227
197
|
if (typeToken) {
|
|
228
198
|
this.type = util_1.default.tokenToBscType(typeToken);
|
|
229
199
|
}
|
|
@@ -264,7 +234,7 @@ class FunctionParameterExpression extends Expression {
|
|
|
264
234
|
}
|
|
265
235
|
}
|
|
266
236
|
exports.FunctionParameterExpression = FunctionParameterExpression;
|
|
267
|
-
class NamespacedVariableNameExpression extends Expression {
|
|
237
|
+
class NamespacedVariableNameExpression extends AstNode_1.Expression {
|
|
268
238
|
constructor(
|
|
269
239
|
//if this is a `DottedGetExpression`, it must be comprised only of `VariableExpression`s
|
|
270
240
|
expression) {
|
|
@@ -307,7 +277,7 @@ class NamespacedVariableNameExpression extends Expression {
|
|
|
307
277
|
}
|
|
308
278
|
}
|
|
309
279
|
exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
|
|
310
|
-
class DottedGetExpression extends Expression {
|
|
280
|
+
class DottedGetExpression extends AstNode_1.Expression {
|
|
311
281
|
constructor(obj, name,
|
|
312
282
|
/**
|
|
313
283
|
* Can either be `.`, or `?.` for optional chaining
|
|
@@ -339,7 +309,7 @@ class DottedGetExpression extends Expression {
|
|
|
339
309
|
}
|
|
340
310
|
}
|
|
341
311
|
exports.DottedGetExpression = DottedGetExpression;
|
|
342
|
-
class XmlAttributeGetExpression extends Expression {
|
|
312
|
+
class XmlAttributeGetExpression extends AstNode_1.Expression {
|
|
343
313
|
constructor(obj, name,
|
|
344
314
|
/**
|
|
345
315
|
* Can either be `@`, or `?@` for optional chaining
|
|
@@ -365,7 +335,7 @@ class XmlAttributeGetExpression extends Expression {
|
|
|
365
335
|
}
|
|
366
336
|
}
|
|
367
337
|
exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
|
|
368
|
-
class IndexedGetExpression extends Expression {
|
|
338
|
+
class IndexedGetExpression extends AstNode_1.Expression {
|
|
369
339
|
constructor(obj, index,
|
|
370
340
|
/**
|
|
371
341
|
* Can either be `[` or `?[`. If `?.[` is used, this will be `[` and `optionalChainingToken` will be `?.`
|
|
@@ -381,12 +351,13 @@ class IndexedGetExpression extends Expression {
|
|
|
381
351
|
this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.questionDotToken, this.openingSquare, this.index, this.closingSquare);
|
|
382
352
|
}
|
|
383
353
|
transpile(state) {
|
|
354
|
+
var _a, _b;
|
|
384
355
|
return [
|
|
385
356
|
...this.obj.transpile(state),
|
|
386
357
|
this.questionDotToken ? state.transpileToken(this.questionDotToken) : '',
|
|
387
358
|
state.transpileToken(this.openingSquare),
|
|
388
|
-
...this.index.transpile(state),
|
|
389
|
-
state.transpileToken(this.closingSquare)
|
|
359
|
+
...((_b = (_a = this.index) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []),
|
|
360
|
+
this.closingSquare ? state.transpileToken(this.closingSquare) : ''
|
|
390
361
|
];
|
|
391
362
|
}
|
|
392
363
|
walk(visitor, options) {
|
|
@@ -397,7 +368,7 @@ class IndexedGetExpression extends Expression {
|
|
|
397
368
|
}
|
|
398
369
|
}
|
|
399
370
|
exports.IndexedGetExpression = IndexedGetExpression;
|
|
400
|
-
class GroupingExpression extends Expression {
|
|
371
|
+
class GroupingExpression extends AstNode_1.Expression {
|
|
401
372
|
constructor(tokens, expression) {
|
|
402
373
|
super();
|
|
403
374
|
this.tokens = tokens;
|
|
@@ -418,7 +389,7 @@ class GroupingExpression extends Expression {
|
|
|
418
389
|
}
|
|
419
390
|
}
|
|
420
391
|
exports.GroupingExpression = GroupingExpression;
|
|
421
|
-
class LiteralExpression extends Expression {
|
|
392
|
+
class LiteralExpression extends AstNode_1.Expression {
|
|
422
393
|
constructor(token) {
|
|
423
394
|
super();
|
|
424
395
|
this.token = token;
|
|
@@ -456,7 +427,7 @@ exports.LiteralExpression = LiteralExpression;
|
|
|
456
427
|
* This is a special expression only used within template strings. It exists so we can prevent producing lots of empty strings
|
|
457
428
|
* during template string transpile by identifying these expressions explicitly and skipping the bslib_toString around them
|
|
458
429
|
*/
|
|
459
|
-
class EscapedCharCodeLiteralExpression extends Expression {
|
|
430
|
+
class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
|
|
460
431
|
constructor(token) {
|
|
461
432
|
super();
|
|
462
433
|
this.token = token;
|
|
@@ -472,14 +443,14 @@ class EscapedCharCodeLiteralExpression extends Expression {
|
|
|
472
443
|
}
|
|
473
444
|
}
|
|
474
445
|
exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
|
|
475
|
-
class ArrayLiteralExpression extends Expression {
|
|
446
|
+
class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
476
447
|
constructor(elements, open, close, hasSpread = false) {
|
|
477
448
|
super();
|
|
478
449
|
this.elements = elements;
|
|
479
450
|
this.open = open;
|
|
480
451
|
this.close = close;
|
|
481
452
|
this.hasSpread = hasSpread;
|
|
482
|
-
this.range = util_1.default.
|
|
453
|
+
this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
|
|
483
454
|
}
|
|
484
455
|
transpile(state) {
|
|
485
456
|
let result = [];
|
|
@@ -512,7 +483,9 @@ class ArrayLiteralExpression extends Expression {
|
|
|
512
483
|
result.push('\n');
|
|
513
484
|
result.push(state.indent());
|
|
514
485
|
}
|
|
515
|
-
|
|
486
|
+
if (this.close) {
|
|
487
|
+
result.push(state.transpileToken(this.close));
|
|
488
|
+
}
|
|
516
489
|
return result;
|
|
517
490
|
}
|
|
518
491
|
walk(visitor, options) {
|
|
@@ -522,7 +495,7 @@ class ArrayLiteralExpression extends Expression {
|
|
|
522
495
|
}
|
|
523
496
|
}
|
|
524
497
|
exports.ArrayLiteralExpression = ArrayLiteralExpression;
|
|
525
|
-
class AAMemberExpression extends Expression {
|
|
498
|
+
class AAMemberExpression extends AstNode_1.Expression {
|
|
526
499
|
constructor(keyToken, colonToken,
|
|
527
500
|
/** The expression evaluated to determine the member's initial value. */
|
|
528
501
|
value) {
|
|
@@ -541,13 +514,13 @@ class AAMemberExpression extends Expression {
|
|
|
541
514
|
}
|
|
542
515
|
}
|
|
543
516
|
exports.AAMemberExpression = AAMemberExpression;
|
|
544
|
-
class AALiteralExpression extends Expression {
|
|
517
|
+
class AALiteralExpression extends AstNode_1.Expression {
|
|
545
518
|
constructor(elements, open, close) {
|
|
546
519
|
super();
|
|
547
520
|
this.elements = elements;
|
|
548
521
|
this.open = open;
|
|
549
522
|
this.close = close;
|
|
550
|
-
this.range = util_1.default.
|
|
523
|
+
this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
|
|
551
524
|
}
|
|
552
525
|
transpile(state) {
|
|
553
526
|
let result = [];
|
|
@@ -598,7 +571,9 @@ class AALiteralExpression extends Expression {
|
|
|
598
571
|
result.push(state.indent());
|
|
599
572
|
}
|
|
600
573
|
//close curly
|
|
601
|
-
|
|
574
|
+
if (this.close) {
|
|
575
|
+
result.push(state.transpileToken(this.close));
|
|
576
|
+
}
|
|
602
577
|
return result;
|
|
603
578
|
}
|
|
604
579
|
walk(visitor, options) {
|
|
@@ -608,7 +583,7 @@ class AALiteralExpression extends Expression {
|
|
|
608
583
|
}
|
|
609
584
|
}
|
|
610
585
|
exports.AALiteralExpression = AALiteralExpression;
|
|
611
|
-
class UnaryExpression extends Expression {
|
|
586
|
+
class UnaryExpression extends AstNode_1.Expression {
|
|
612
587
|
constructor(operator, right) {
|
|
613
588
|
super();
|
|
614
589
|
this.operator = operator;
|
|
@@ -629,23 +604,22 @@ class UnaryExpression extends Expression {
|
|
|
629
604
|
}
|
|
630
605
|
}
|
|
631
606
|
exports.UnaryExpression = UnaryExpression;
|
|
632
|
-
class VariableExpression extends Expression {
|
|
633
|
-
constructor(name
|
|
607
|
+
class VariableExpression extends AstNode_1.Expression {
|
|
608
|
+
constructor(name) {
|
|
634
609
|
super();
|
|
635
610
|
this.name = name;
|
|
636
|
-
this.namespaceName = namespaceName;
|
|
637
611
|
this.range = this.name.range;
|
|
638
612
|
}
|
|
639
613
|
getName(parseMode) {
|
|
640
614
|
return this.name.text;
|
|
641
615
|
}
|
|
642
616
|
transpile(state) {
|
|
643
|
-
var _a;
|
|
644
617
|
let result = [];
|
|
618
|
+
const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
|
|
645
619
|
//if the callee is the name of a known namespace function
|
|
646
|
-
if (state.file.calleeIsKnownNamespaceFunction(this,
|
|
620
|
+
if (state.file.calleeIsKnownNamespaceFunction(this, namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) {
|
|
647
621
|
result.push(state.sourceNode(this, [
|
|
648
|
-
|
|
622
|
+
namespace.getName(Parser_1.ParseMode.BrightScript),
|
|
649
623
|
'_',
|
|
650
624
|
this.getName(Parser_1.ParseMode.BrightScript)
|
|
651
625
|
]));
|
|
@@ -661,7 +635,7 @@ class VariableExpression extends Expression {
|
|
|
661
635
|
}
|
|
662
636
|
}
|
|
663
637
|
exports.VariableExpression = VariableExpression;
|
|
664
|
-
class SourceLiteralExpression extends Expression {
|
|
638
|
+
class SourceLiteralExpression extends AstNode_1.Expression {
|
|
665
639
|
constructor(token) {
|
|
666
640
|
super();
|
|
667
641
|
this.token = token;
|
|
@@ -731,7 +705,7 @@ exports.SourceLiteralExpression = SourceLiteralExpression;
|
|
|
731
705
|
* except we need to uniquely identify these statements so we can
|
|
732
706
|
* do more type checking.
|
|
733
707
|
*/
|
|
734
|
-
class NewExpression extends Expression {
|
|
708
|
+
class NewExpression extends AstNode_1.Expression {
|
|
735
709
|
constructor(newKeyword, call) {
|
|
736
710
|
super();
|
|
737
711
|
this.newKeyword = newKeyword;
|
|
@@ -746,12 +720,10 @@ class NewExpression extends Expression {
|
|
|
746
720
|
//a NamespacedVariableNameExpression
|
|
747
721
|
return this.call.callee;
|
|
748
722
|
}
|
|
749
|
-
get namespaceName() {
|
|
750
|
-
return this.call.namespaceName;
|
|
751
|
-
}
|
|
752
723
|
transpile(state) {
|
|
753
|
-
var _a
|
|
754
|
-
const
|
|
724
|
+
var _a;
|
|
725
|
+
const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
|
|
726
|
+
const cls = (_a = state.file.getClassFileLink(this.className.getName(Parser_1.ParseMode.BrighterScript), namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) === null || _a === void 0 ? void 0 : _a.item;
|
|
755
727
|
//new statements within a namespace block can omit the leading namespace if the class resides in that same namespace.
|
|
756
728
|
//So we need to figure out if this is a namespace-omitted class, or if this class exists without a namespace.
|
|
757
729
|
return this.call.transpile(state, cls === null || cls === void 0 ? void 0 : cls.getName(Parser_1.ParseMode.BrightScript));
|
|
@@ -763,7 +735,7 @@ class NewExpression extends Expression {
|
|
|
763
735
|
}
|
|
764
736
|
}
|
|
765
737
|
exports.NewExpression = NewExpression;
|
|
766
|
-
class CallfuncExpression extends Expression {
|
|
738
|
+
class CallfuncExpression extends AstNode_1.Expression {
|
|
767
739
|
constructor(callee, operator, methodName, openingParen, args, closingParen) {
|
|
768
740
|
var _a, _b, _c;
|
|
769
741
|
super();
|
|
@@ -810,7 +782,7 @@ exports.CallfuncExpression = CallfuncExpression;
|
|
|
810
782
|
* Since template strings can contain newlines, we need to concatenate multiple strings together with chr() calls.
|
|
811
783
|
* This is a single expression that represents the string contatenation of all parts of a single quasi.
|
|
812
784
|
*/
|
|
813
|
-
class TemplateStringQuasiExpression extends Expression {
|
|
785
|
+
class TemplateStringQuasiExpression extends AstNode_1.Expression {
|
|
814
786
|
constructor(expressions) {
|
|
815
787
|
super();
|
|
816
788
|
this.expressions = expressions;
|
|
@@ -837,7 +809,7 @@ class TemplateStringQuasiExpression extends Expression {
|
|
|
837
809
|
}
|
|
838
810
|
}
|
|
839
811
|
exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
|
|
840
|
-
class TemplateStringExpression extends Expression {
|
|
812
|
+
class TemplateStringExpression extends AstNode_1.Expression {
|
|
841
813
|
constructor(openingBacktick, quasis, expressions, closingBacktick) {
|
|
842
814
|
super();
|
|
843
815
|
this.openingBacktick = openingBacktick;
|
|
@@ -894,7 +866,7 @@ class TemplateStringExpression extends Expression {
|
|
|
894
866
|
}
|
|
895
867
|
}
|
|
896
868
|
exports.TemplateStringExpression = TemplateStringExpression;
|
|
897
|
-
class TaggedTemplateStringExpression extends Expression {
|
|
869
|
+
class TaggedTemplateStringExpression extends AstNode_1.Expression {
|
|
898
870
|
constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
|
|
899
871
|
super();
|
|
900
872
|
this.tagName = tagName;
|
|
@@ -942,7 +914,7 @@ class TaggedTemplateStringExpression extends Expression {
|
|
|
942
914
|
}
|
|
943
915
|
}
|
|
944
916
|
exports.TaggedTemplateStringExpression = TaggedTemplateStringExpression;
|
|
945
|
-
class AnnotationExpression extends Expression {
|
|
917
|
+
class AnnotationExpression extends AstNode_1.Expression {
|
|
946
918
|
constructor(atToken, nameToken) {
|
|
947
919
|
super();
|
|
948
920
|
this.atToken = atToken;
|
|
@@ -976,7 +948,7 @@ class AnnotationExpression extends Expression {
|
|
|
976
948
|
}
|
|
977
949
|
}
|
|
978
950
|
exports.AnnotationExpression = AnnotationExpression;
|
|
979
|
-
class TernaryExpression extends Expression {
|
|
951
|
+
class TernaryExpression extends AstNode_1.Expression {
|
|
980
952
|
constructor(test, questionMarkToken, consequent, colonToken, alternate) {
|
|
981
953
|
var _a, _b, _c;
|
|
982
954
|
super();
|
|
@@ -1021,7 +993,7 @@ class TernaryExpression extends Expression {
|
|
|
1021
993
|
}
|
|
1022
994
|
}
|
|
1023
995
|
exports.TernaryExpression = TernaryExpression;
|
|
1024
|
-
class NullCoalescingExpression extends Expression {
|
|
996
|
+
class NullCoalescingExpression extends AstNode_1.Expression {
|
|
1025
997
|
constructor(consequent, questionQuestionToken, alternate) {
|
|
1026
998
|
var _a;
|
|
1027
999
|
super();
|
|
@@ -1064,7 +1036,7 @@ class NullCoalescingExpression extends Expression {
|
|
|
1064
1036
|
}
|
|
1065
1037
|
}
|
|
1066
1038
|
exports.NullCoalescingExpression = NullCoalescingExpression;
|
|
1067
|
-
class RegexLiteralExpression extends Expression {
|
|
1039
|
+
class RegexLiteralExpression extends AstNode_1.Expression {
|
|
1068
1040
|
constructor(tokens) {
|
|
1069
1041
|
super();
|
|
1070
1042
|
this.tokens = tokens;
|