brighterscript 1.0.0-alpha.25 → 1.0.0-alpha.27
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 +44 -0
- package/bsconfig.schema.json +5 -0
- package/dist/AstValidationSegmenter.d.ts +1 -1
- package/dist/AstValidationSegmenter.js +6 -7
- package/dist/AstValidationSegmenter.js.map +1 -1
- package/dist/BsConfig.d.ts +1 -0
- package/dist/DiagnosticMessages.d.ts +1 -3
- package/dist/DiagnosticMessages.js +5 -8
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/Program.d.ts +1 -1
- package/dist/Program.js +40 -42
- package/dist/Program.js.map +1 -1
- package/dist/Scope.d.ts +2 -13
- package/dist/Scope.js +27 -35
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +1 -8
- package/dist/SymbolTable.js +1 -10
- package/dist/SymbolTable.js.map +1 -1
- package/dist/SymbolTableFlag.d.ts +8 -0
- package/dist/SymbolTableFlag.js +13 -0
- package/dist/SymbolTableFlag.js.map +1 -0
- package/dist/XmlScope.d.ts +1 -6
- package/dist/XmlScope.js +6 -25
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/CachedLookups.d.ts +1 -2
- package/dist/astUtils/CachedLookups.js +3 -14
- package/dist/astUtils/CachedLookups.js.map +1 -1
- package/dist/astUtils/Editor.spec.js +1 -1
- package/dist/astUtils/Editor.spec.js.map +1 -1
- package/dist/astUtils/creators.js +77 -18
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +4 -4
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +3 -1
- package/dist/astUtils/reflection.js +12 -4
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +59 -42
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +30 -19
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +2 -1
- package/dist/bscPlugin/BscPlugin.js +7 -3
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.js +7 -7
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/SignatureHelpUtil.js +5 -4
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +2 -2
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.js +23 -23
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js +210 -0
- package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +1 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js +88 -0
- package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +28 -8
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +74 -2
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -5
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +8 -6
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +46 -47
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +10 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +120 -39
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +165 -10
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
- package/dist/diagnosticUtils.d.ts +1 -1
- package/dist/files/BrsFile.Class.spec.js +7 -6
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +7 -15
- package/dist/files/BrsFile.js +49 -309
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +111 -157
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +2 -3
- package/dist/files/XmlFile.js +0 -2
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/interfaces.d.ts +109 -84
- package/dist/interfaces.js +9 -9
- package/dist/interfaces.js.map +1 -1
- package/dist/parser/AstNode.spec.js +6 -6
- package/dist/parser/AstNode.spec.js.map +1 -1
- package/dist/parser/Expression.d.ts +301 -164
- package/dist/parser/Expression.js +355 -294
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +26 -27
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +6 -2
- package/dist/parser/Parser.js +361 -160
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +69 -213
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.js +49 -35
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +36 -24
- package/dist/parser/SGTypes.js +26 -55
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +381 -238
- package/dist/parser/Statement.js +510 -386
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +2 -2
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +2 -2
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +11 -11
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +30 -5
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +2 -2
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +2 -2
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TypeExpression.spec.js +8 -9
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +8 -8
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.js +2 -2
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +2 -2
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +2 -2
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +10 -3
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/roku-types/data.json +70 -52
- package/dist/roku-types/index.d.ts +43 -21
- package/dist/types/ArrayType.js +1 -2
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +7 -8
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/AssociativeArrayType.js +2 -3
- package/dist/types/AssociativeArrayType.js.map +1 -1
- package/dist/types/BscType.d.ts +1 -1
- package/dist/types/BscType.js +2 -3
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.js +15 -9
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.spec.js +31 -32
- package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -1
- package/dist/types/ClassType.spec.js +10 -11
- package/dist/types/ClassType.spec.js.map +1 -1
- package/dist/types/ComponentType.d.ts +2 -1
- package/dist/types/ComponentType.js.map +1 -1
- package/dist/types/EnumType.js +2 -3
- package/dist/types/EnumType.js.map +1 -1
- package/dist/types/InheritableType.js +3 -4
- package/dist/types/InheritableType.js.map +1 -1
- package/dist/types/InterfaceType.js +2 -3
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +3 -4
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/ObjectType.js +1 -2
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ReferenceType.d.ts +1 -1
- package/dist/types/ReferenceType.spec.js +21 -22
- package/dist/types/ReferenceType.spec.js.map +1 -1
- package/dist/types/UnionType.js +3 -3
- package/dist/types/UnionType.js.map +1 -1
- package/dist/types/UnionType.spec.js +37 -38
- package/dist/types/UnionType.spec.js.map +1 -1
- package/dist/types/helper.spec.js +4 -5
- package/dist/types/helper.spec.js.map +1 -1
- package/dist/util.d.ts +16 -7
- package/dist/util.js +89 -43
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +0 -9
- package/dist/validators/ClassValidator.js +9 -52
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +1 -1
|
@@ -9,33 +9,34 @@ const visitors_1 = require("../astUtils/visitors");
|
|
|
9
9
|
const visitors_2 = require("../astUtils/visitors");
|
|
10
10
|
const reflection_1 = require("../astUtils/reflection");
|
|
11
11
|
const interfaces_1 = require("../interfaces");
|
|
12
|
-
const
|
|
12
|
+
const VoidType_1 = require("../types/VoidType");
|
|
13
|
+
const DynamicType_1 = require("../types/DynamicType");
|
|
13
14
|
const TypedFunctionType_1 = require("../types/TypedFunctionType");
|
|
14
15
|
const AstNode_1 = require("./AstNode");
|
|
15
|
-
const
|
|
16
|
+
const SymbolTable_1 = require("../SymbolTable");
|
|
16
17
|
const source_map_1 = require("source-map");
|
|
17
18
|
const StringType_1 = require("../types/StringType");
|
|
18
|
-
const DynamicType_1 = require("../types/DynamicType");
|
|
19
|
-
const VoidType_1 = require("../types/VoidType");
|
|
20
19
|
const ReferenceType_1 = require("../types/ReferenceType");
|
|
21
20
|
const UnionType_1 = require("../types/UnionType");
|
|
22
|
-
const
|
|
21
|
+
const ArrayType_1 = require("../types/ArrayType");
|
|
23
22
|
const AssociativeArrayType_1 = require("../types/AssociativeArrayType");
|
|
24
23
|
const creators_1 = require("../astUtils/creators");
|
|
25
24
|
class BinaryExpression extends AstNode_1.Expression {
|
|
26
|
-
constructor(
|
|
25
|
+
constructor(options) {
|
|
27
26
|
super();
|
|
28
|
-
this.left = left;
|
|
29
|
-
this.operator = operator;
|
|
30
|
-
this.right = right;
|
|
31
27
|
this.kind = AstNode_1.AstNodeKind.BinaryExpression;
|
|
32
|
-
this.
|
|
28
|
+
this.tokens = {
|
|
29
|
+
operator: options.operator
|
|
30
|
+
};
|
|
31
|
+
this.left = options.left;
|
|
32
|
+
this.right = options.right;
|
|
33
|
+
this.range = util_1.default.createBoundingRange(this.left, this.tokens.operator, this.right);
|
|
33
34
|
}
|
|
34
35
|
transpile(state) {
|
|
35
36
|
return [
|
|
36
37
|
state.sourceNode(this.left, this.left.transpile(state)),
|
|
37
38
|
' ',
|
|
38
|
-
state.transpileToken(this.operator),
|
|
39
|
+
state.transpileToken(this.tokens.operator),
|
|
39
40
|
' ',
|
|
40
41
|
state.sourceNode(this.right, this.right.transpile(state))
|
|
41
42
|
];
|
|
@@ -47,8 +48,8 @@ class BinaryExpression extends AstNode_1.Expression {
|
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
50
|
getType(options) {
|
|
50
|
-
const operatorKind = this.operator.kind;
|
|
51
|
-
if (options.flags &
|
|
51
|
+
const operatorKind = this.tokens.operator.kind;
|
|
52
|
+
if (options.flags & 2 /* SymbolTypeFlag.typetime */) {
|
|
52
53
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
53
54
|
switch (operatorKind) {
|
|
54
55
|
case TokenKind_1.TokenKind.Or:
|
|
@@ -56,26 +57,25 @@ class BinaryExpression extends AstNode_1.Expression {
|
|
|
56
57
|
//TODO: Intersection Types?, eg. case TokenKind.And:
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
|
-
else if (options.flags &
|
|
60
|
-
return util_1.default.binaryOperatorResultType(this.left.getType(options), this.operator, this.right.getType(options));
|
|
60
|
+
else if (options.flags & 1 /* SymbolTypeFlag.runtime */) {
|
|
61
|
+
return util_1.default.binaryOperatorResultType(this.left.getType(options), this.tokens.operator, this.right.getType(options));
|
|
61
62
|
}
|
|
62
63
|
return DynamicType_1.DynamicType.instance;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
66
|
exports.BinaryExpression = BinaryExpression;
|
|
66
67
|
class CallExpression extends AstNode_1.Expression {
|
|
67
|
-
constructor(
|
|
68
|
-
|
|
69
|
-
* Can either be `(`, or `?(` for optional chaining
|
|
70
|
-
*/
|
|
71
|
-
openingParen, closingParen, args, unused) {
|
|
68
|
+
constructor(options) {
|
|
69
|
+
var _a;
|
|
72
70
|
super();
|
|
73
|
-
this.callee = callee;
|
|
74
|
-
this.openingParen = openingParen;
|
|
75
|
-
this.closingParen = closingParen;
|
|
76
|
-
this.args = args;
|
|
77
71
|
this.kind = AstNode_1.AstNodeKind.CallExpression;
|
|
78
|
-
this.
|
|
72
|
+
this.tokens = {
|
|
73
|
+
openingParen: options.openingParen,
|
|
74
|
+
closingParen: options.closingParen
|
|
75
|
+
};
|
|
76
|
+
this.callee = options.callee;
|
|
77
|
+
this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
|
|
78
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.tokens.openingParen, ...this.args, this.tokens.closingParen);
|
|
79
79
|
}
|
|
80
80
|
transpile(state, nameOverride) {
|
|
81
81
|
let result = [];
|
|
@@ -86,7 +86,7 @@ class CallExpression extends AstNode_1.Expression {
|
|
|
86
86
|
else {
|
|
87
87
|
result.push(...this.callee.transpile(state));
|
|
88
88
|
}
|
|
89
|
-
result.push(state.transpileToken(this.openingParen));
|
|
89
|
+
result.push(state.transpileToken(this.tokens.openingParen, '('));
|
|
90
90
|
for (let i = 0; i < this.args.length; i++) {
|
|
91
91
|
//add comma between args
|
|
92
92
|
if (i > 0) {
|
|
@@ -95,8 +95,8 @@ class CallExpression extends AstNode_1.Expression {
|
|
|
95
95
|
let arg = this.args[i];
|
|
96
96
|
result.push(...arg.transpile(state));
|
|
97
97
|
}
|
|
98
|
-
if (this.closingParen) {
|
|
99
|
-
result.push(state.transpileToken(this.closingParen));
|
|
98
|
+
if (this.tokens.closingParen) {
|
|
99
|
+
result.push(state.transpileToken(this.tokens.closingParen));
|
|
100
100
|
}
|
|
101
101
|
return result;
|
|
102
102
|
}
|
|
@@ -127,49 +127,48 @@ class CallExpression extends AstNode_1.Expression {
|
|
|
127
127
|
exports.CallExpression = CallExpression;
|
|
128
128
|
CallExpression.MaximumArguments = 32;
|
|
129
129
|
class FunctionExpression extends AstNode_1.Expression {
|
|
130
|
-
constructor(
|
|
130
|
+
constructor(options) {
|
|
131
|
+
var _a;
|
|
131
132
|
super();
|
|
132
|
-
this.parameters = parameters;
|
|
133
|
-
this.body = body;
|
|
134
|
-
this.functionType = functionType;
|
|
135
|
-
this.end = end;
|
|
136
|
-
this.leftParen = leftParen;
|
|
137
|
-
this.rightParen = rightParen;
|
|
138
|
-
this.asToken = asToken;
|
|
139
|
-
this.returnTypeExpression = returnTypeExpression;
|
|
140
133
|
this.kind = AstNode_1.AstNodeKind.FunctionExpression;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
134
|
+
this.tokens = {
|
|
135
|
+
functionType: options.functionType,
|
|
136
|
+
leftParen: options.leftParen,
|
|
137
|
+
rightParen: options.rightParen,
|
|
138
|
+
as: options.as,
|
|
139
|
+
endFunctionType: options.endFunctionType
|
|
140
|
+
};
|
|
141
|
+
this.parameters = (_a = options.parameters) !== null && _a !== void 0 ? _a : [];
|
|
142
|
+
this.body = options.body;
|
|
143
|
+
this.returnTypeExpression = options.returnTypeExpression;
|
|
146
144
|
//if there's a body, and it doesn't have a SymbolTable, assign one
|
|
147
145
|
if (this.body && !this.body.symbolTable) {
|
|
148
|
-
this.body.symbolTable = new
|
|
146
|
+
this.body.symbolTable = new SymbolTable_1.SymbolTable(`Block`, () => this.getSymbolTable());
|
|
149
147
|
}
|
|
150
|
-
this.symbolTable = new
|
|
148
|
+
this.symbolTable = new SymbolTable_1.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
|
|
151
149
|
}
|
|
152
150
|
getLeadingTrivia() {
|
|
153
151
|
var _a, _b;
|
|
154
|
-
return (_b = (_a = this.functionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
152
|
+
return (_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
155
153
|
}
|
|
156
154
|
/**
|
|
157
155
|
* The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
|
|
158
156
|
* and ending with the last n' in 'end function' or 'b' in 'end sub'
|
|
159
157
|
*/
|
|
160
158
|
get range() {
|
|
161
|
-
return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...this.parameters, this.rightParen, this.
|
|
159
|
+
return util_1.default.createBoundingRange(this.tokens.functionType, this.tokens.leftParen, ...this.parameters, this.tokens.rightParen, this.tokens.as, this.returnTypeExpression, this.tokens.endFunctionType);
|
|
162
160
|
}
|
|
163
161
|
transpile(state, name, includeBody = true) {
|
|
162
|
+
var _a;
|
|
164
163
|
let results = [];
|
|
165
164
|
//'function'|'sub'
|
|
166
|
-
results.push(state.transpileToken(this.functionType));
|
|
165
|
+
results.push(state.transpileToken(this.tokens.functionType, 'function'));
|
|
167
166
|
//functionName?
|
|
168
167
|
if (name) {
|
|
169
168
|
results.push(' ', state.transpileToken(name));
|
|
170
169
|
}
|
|
171
170
|
//leftParen
|
|
172
|
-
results.push(state.transpileToken(this.leftParen));
|
|
171
|
+
results.push(state.transpileToken(this.tokens.leftParen));
|
|
173
172
|
//parameters
|
|
174
173
|
for (let i = 0; i < this.parameters.length; i++) {
|
|
175
174
|
let param = this.parameters[i];
|
|
@@ -181,12 +180,12 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
181
180
|
results.push(param.transpile(state));
|
|
182
181
|
}
|
|
183
182
|
//right paren
|
|
184
|
-
results.push(state.transpileToken(this.rightParen));
|
|
183
|
+
results.push(state.transpileToken(this.tokens.rightParen));
|
|
185
184
|
//as [Type]
|
|
186
|
-
if (
|
|
185
|
+
if (!state.options.removeParameterTypes && this.returnTypeExpression) {
|
|
187
186
|
results.push(' ',
|
|
188
187
|
//as
|
|
189
|
-
state.transpileToken(this.
|
|
188
|
+
state.transpileToken(this.tokens.as, 'as'), ' ',
|
|
190
189
|
//return type
|
|
191
190
|
...this.returnTypeExpression.transpile(state));
|
|
192
191
|
}
|
|
@@ -198,36 +197,38 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
198
197
|
}
|
|
199
198
|
results.push('\n');
|
|
200
199
|
//'end sub'|'end function'
|
|
201
|
-
results.push(state.indent(), state.transpileToken(this.end));
|
|
200
|
+
results.push(state.indent(), state.transpileToken(this.tokens.endFunctionType, `end ${(_a = this.tokens.functionType) !== null && _a !== void 0 ? _a : 'function'}`));
|
|
202
201
|
return results;
|
|
203
202
|
}
|
|
204
203
|
getTypedef(state) {
|
|
205
|
-
var _a, _b, _c, _d, _e;
|
|
204
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
206
205
|
let results = [
|
|
207
206
|
new source_map_1.SourceNode(1, 0, null, [
|
|
208
207
|
//'function'|'sub'
|
|
209
|
-
(_a = this.functionType) === null || _a === void 0 ? void 0 : _a.text,
|
|
208
|
+
(_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'function',
|
|
210
209
|
//functionName?
|
|
211
|
-
...((0, reflection_1.isFunctionStatement)(this.parent) || (0, reflection_1.isMethodStatement)(this.parent) ? [' ', (
|
|
210
|
+
...((0, reflection_1.isFunctionStatement)(this.parent) || (0, reflection_1.isMethodStatement)(this.parent) ? [' ', (_d = (_c = this.parent.tokens.name) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : ''] : []),
|
|
212
211
|
//leftParen
|
|
213
212
|
'(',
|
|
214
213
|
//parameters
|
|
215
|
-
...((
|
|
214
|
+
...((_f = (_e = this.parameters) === null || _e === void 0 ? void 0 : _e.map((param, i) => ([
|
|
216
215
|
//separating comma
|
|
217
216
|
i > 0 ? ', ' : '',
|
|
218
217
|
...param.getTypedef(state)
|
|
219
|
-
]))) !== null &&
|
|
218
|
+
]))) !== null && _f !== void 0 ? _f : []),
|
|
220
219
|
//right paren
|
|
221
220
|
')',
|
|
222
221
|
//as <ReturnType>
|
|
223
|
-
...(this.
|
|
224
|
-
'
|
|
222
|
+
...(this.returnTypeExpression ? [
|
|
223
|
+
' ',
|
|
224
|
+
(_h = (_g = this.tokens.as) === null || _g === void 0 ? void 0 : _g.text) !== null && _h !== void 0 ? _h : 'as',
|
|
225
|
+
' ',
|
|
225
226
|
...this.returnTypeExpression.getTypedef(state)
|
|
226
227
|
] : []),
|
|
227
228
|
'\n',
|
|
228
229
|
state.indent(),
|
|
229
230
|
//'end sub'|'end function'
|
|
230
|
-
this.end.
|
|
231
|
+
(_k = (_j = this.tokens.endFunctionType) === null || _j === void 0 ? void 0 : _j.text) !== null && _k !== void 0 ? _k : `end ${(_l = this.tokens.functionType) !== null && _l !== void 0 ? _l : 'function'}`
|
|
231
232
|
])
|
|
232
233
|
];
|
|
233
234
|
return results;
|
|
@@ -243,10 +244,10 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
243
244
|
}
|
|
244
245
|
}
|
|
245
246
|
getType(options) {
|
|
246
|
-
var _a, _b, _c;
|
|
247
|
+
var _a, _b, _c, _d;
|
|
247
248
|
//if there's a defined return type, use that
|
|
248
249
|
let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
|
|
249
|
-
const isSub = this.functionType.kind === TokenKind_1.TokenKind.Sub;
|
|
250
|
+
const isSub = ((_b = this.tokens.functionType) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Sub;
|
|
250
251
|
//if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
|
|
251
252
|
if (!returnType) {
|
|
252
253
|
returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
|
|
@@ -254,7 +255,7 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
254
255
|
const resultType = new TypedFunctionType_1.TypedFunctionType(returnType);
|
|
255
256
|
resultType.isSub = isSub;
|
|
256
257
|
for (let param of this.parameters) {
|
|
257
|
-
resultType.addParameter(param.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
|
|
258
|
+
resultType.addParameter(param.tokens.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
|
|
258
259
|
}
|
|
259
260
|
// Figure out this function's name if we can
|
|
260
261
|
let funcName = '';
|
|
@@ -262,7 +263,7 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
262
263
|
funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
|
|
263
264
|
if (options.typeChain) {
|
|
264
265
|
// Get the typechain info from the parent class
|
|
265
|
-
(
|
|
266
|
+
(_c = this.parent.parent) === null || _c === void 0 ? void 0 : _c.getType(options);
|
|
266
267
|
}
|
|
267
268
|
}
|
|
268
269
|
else if ((0, reflection_1.isFunctionStatement)(this.parent)) {
|
|
@@ -271,35 +272,37 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
271
272
|
if (funcName) {
|
|
272
273
|
resultType.setName(funcName);
|
|
273
274
|
}
|
|
274
|
-
(
|
|
275
|
+
(_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry({ name: funcName, type: resultType, data: options.data, range: this.range, kind: this.kind }));
|
|
275
276
|
return resultType;
|
|
276
277
|
}
|
|
277
278
|
}
|
|
278
279
|
exports.FunctionExpression = FunctionExpression;
|
|
279
280
|
class FunctionParameterExpression extends AstNode_1.Expression {
|
|
280
|
-
constructor(
|
|
281
|
+
constructor(options) {
|
|
281
282
|
super();
|
|
282
|
-
this.name = name;
|
|
283
|
-
this.equalToken = equalToken;
|
|
284
|
-
this.defaultValue = defaultValue;
|
|
285
|
-
this.asToken = asToken;
|
|
286
|
-
this.typeExpression = typeExpression;
|
|
287
283
|
this.kind = AstNode_1.AstNodeKind.FunctionParameterExpression;
|
|
284
|
+
this.tokens = {
|
|
285
|
+
name: options.name,
|
|
286
|
+
equals: options.equals,
|
|
287
|
+
as: options.as
|
|
288
|
+
};
|
|
289
|
+
this.defaultValue = options.defaultValue;
|
|
290
|
+
this.typeExpression = options.typeExpression;
|
|
288
291
|
}
|
|
289
292
|
getType(options) {
|
|
290
293
|
var _a, _b, _c, _d, _e;
|
|
291
|
-
const paramType = (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags:
|
|
292
|
-
(_e = options.typeChain) === null || _e === void 0 ? void 0 : _e.push(new interfaces_1.TypeChainEntry(this.name.text, paramType, options.data, this.range));
|
|
294
|
+
const paramType = (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */, typeChain: undefined }))) !== null && _b !== void 0 ? _b : (_c = this.defaultValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */, typeChain: undefined }))) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
|
|
295
|
+
(_e = options.typeChain) === null || _e === void 0 ? void 0 : _e.push(new interfaces_1.TypeChainEntry({ name: this.tokens.name.text, type: paramType, data: options.data, range: this.range, kind: this.kind }));
|
|
293
296
|
return paramType;
|
|
294
297
|
}
|
|
295
298
|
get range() {
|
|
296
|
-
return util_1.default.createBoundingRange(this.name, this.
|
|
299
|
+
return util_1.default.createBoundingRange(this.tokens.name, this.tokens.as, this.typeExpression, this.tokens.equals, this.defaultValue);
|
|
297
300
|
}
|
|
298
301
|
transpile(state) {
|
|
299
302
|
var _a, _b;
|
|
300
303
|
let result = [
|
|
301
304
|
//name
|
|
302
|
-
state.transpileToken(this.name)
|
|
305
|
+
state.transpileToken(this.tokens.name)
|
|
303
306
|
];
|
|
304
307
|
//default value
|
|
305
308
|
if (this.defaultValue) {
|
|
@@ -307,9 +310,9 @@ class FunctionParameterExpression extends AstNode_1.Expression {
|
|
|
307
310
|
result.push(this.defaultValue.transpile(state));
|
|
308
311
|
}
|
|
309
312
|
//type declaration
|
|
310
|
-
if (this.
|
|
313
|
+
if (this.typeExpression && !state.options.removeParameterTypes) {
|
|
311
314
|
result.push(' ');
|
|
312
|
-
result.push(state.transpileToken(this.
|
|
315
|
+
result.push(state.transpileToken(this.tokens.as, 'as'));
|
|
313
316
|
result.push(' ');
|
|
314
317
|
result.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []));
|
|
315
318
|
}
|
|
@@ -319,14 +322,14 @@ class FunctionParameterExpression extends AstNode_1.Expression {
|
|
|
319
322
|
var _a, _b;
|
|
320
323
|
return [
|
|
321
324
|
//name
|
|
322
|
-
this.name.text,
|
|
325
|
+
this.tokens.name.text,
|
|
323
326
|
//default value
|
|
324
327
|
...(this.defaultValue ? [
|
|
325
328
|
' = ',
|
|
326
329
|
...this.defaultValue.transpile(state)
|
|
327
330
|
] : []),
|
|
328
331
|
//type declaration
|
|
329
|
-
...(this.
|
|
332
|
+
...(this.typeExpression ? [
|
|
330
333
|
' as ',
|
|
331
334
|
...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getTypedef(state)) !== null && _b !== void 0 ? _b : [''])
|
|
332
335
|
] : [])
|
|
@@ -342,17 +345,15 @@ class FunctionParameterExpression extends AstNode_1.Expression {
|
|
|
342
345
|
}
|
|
343
346
|
exports.FunctionParameterExpression = FunctionParameterExpression;
|
|
344
347
|
class DottedGetExpression extends AstNode_1.Expression {
|
|
345
|
-
constructor(
|
|
346
|
-
/**
|
|
347
|
-
* Can either be `.`, or `?.` for optional chaining
|
|
348
|
-
*/
|
|
349
|
-
dot) {
|
|
348
|
+
constructor(options) {
|
|
350
349
|
super();
|
|
351
|
-
this.obj = obj;
|
|
352
|
-
this.name = name;
|
|
353
|
-
this.dot = dot;
|
|
354
350
|
this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
|
|
355
|
-
this.
|
|
351
|
+
this.tokens = {
|
|
352
|
+
name: options.name,
|
|
353
|
+
dot: options.dot
|
|
354
|
+
};
|
|
355
|
+
this.obj = options.obj;
|
|
356
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.tokens.dot, this.tokens.name);
|
|
356
357
|
}
|
|
357
358
|
transpile(state) {
|
|
358
359
|
//if the callee starts with a namespace name, transpile the name
|
|
@@ -364,8 +365,8 @@ class DottedGetExpression extends AstNode_1.Expression {
|
|
|
364
365
|
else {
|
|
365
366
|
return [
|
|
366
367
|
...this.obj.transpile(state),
|
|
367
|
-
state.transpileToken(this.dot),
|
|
368
|
-
state.transpileToken(this.name)
|
|
368
|
+
state.transpileToken(this.tokens.dot, '.'),
|
|
369
|
+
state.transpileToken(this.tokens.name)
|
|
369
370
|
];
|
|
370
371
|
}
|
|
371
372
|
}
|
|
@@ -377,9 +378,15 @@ class DottedGetExpression extends AstNode_1.Expression {
|
|
|
377
378
|
getType(options) {
|
|
378
379
|
var _a, _b, _c, _d, _e, _f;
|
|
379
380
|
const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
|
|
380
|
-
const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.name) === null || _b === void 0 ? void 0 : _b.text, options);
|
|
381
|
-
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry(
|
|
382
|
-
|
|
381
|
+
const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text, options);
|
|
382
|
+
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
|
|
383
|
+
name: (_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text,
|
|
384
|
+
type: result,
|
|
385
|
+
data: options.data,
|
|
386
|
+
range: (_f = (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range,
|
|
387
|
+
kind: this.kind
|
|
388
|
+
}));
|
|
389
|
+
if (result || options.flags & 2 /* SymbolTypeFlag.typetime */) {
|
|
383
390
|
// All types should be known at typetime
|
|
384
391
|
return result;
|
|
385
392
|
}
|
|
@@ -393,23 +400,18 @@ class DottedGetExpression extends AstNode_1.Expression {
|
|
|
393
400
|
}
|
|
394
401
|
exports.DottedGetExpression = DottedGetExpression;
|
|
395
402
|
class XmlAttributeGetExpression extends AstNode_1.Expression {
|
|
396
|
-
constructor(
|
|
397
|
-
/**
|
|
398
|
-
* Can either be `@`, or `?@` for optional chaining
|
|
399
|
-
*/
|
|
400
|
-
at) {
|
|
403
|
+
constructor(options) {
|
|
401
404
|
super();
|
|
402
|
-
this.obj = obj;
|
|
403
|
-
this.name = name;
|
|
404
|
-
this.at = at;
|
|
405
405
|
this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
|
|
406
|
-
this.
|
|
406
|
+
this.obj = options.obj;
|
|
407
|
+
this.tokens = { at: options.at, name: options.name };
|
|
408
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.tokens.at, this.tokens.name);
|
|
407
409
|
}
|
|
408
410
|
transpile(state) {
|
|
409
411
|
return [
|
|
410
412
|
...this.obj.transpile(state),
|
|
411
|
-
state.transpileToken(this.at),
|
|
412
|
-
state.transpileToken(this.name)
|
|
413
|
+
state.transpileToken(this.tokens.at, '@'),
|
|
414
|
+
state.transpileToken(this.tokens.name)
|
|
413
415
|
];
|
|
414
416
|
}
|
|
415
417
|
walk(visitor, options) {
|
|
@@ -420,35 +422,37 @@ class XmlAttributeGetExpression extends AstNode_1.Expression {
|
|
|
420
422
|
}
|
|
421
423
|
exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
|
|
422
424
|
class IndexedGetExpression extends AstNode_1.Expression {
|
|
423
|
-
constructor(
|
|
424
|
-
/**
|
|
425
|
-
* Can either be `[` or `?[`. If `?.[` is used, this will be `[` and `optionalChainingToken` will be `?.`
|
|
426
|
-
*/
|
|
427
|
-
openingSquare, closingSquare, questionDotToken // ? or ?.
|
|
428
|
-
) {
|
|
425
|
+
constructor(options) {
|
|
429
426
|
super();
|
|
430
|
-
this.obj = obj;
|
|
431
|
-
this.index = index;
|
|
432
|
-
this.openingSquare = openingSquare;
|
|
433
|
-
this.closingSquare = closingSquare;
|
|
434
|
-
this.questionDotToken = questionDotToken;
|
|
435
427
|
this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
|
|
436
|
-
this.
|
|
428
|
+
this.tokens = {
|
|
429
|
+
openingSquare: options.openingSquare,
|
|
430
|
+
closingSquare: options.closingSquare,
|
|
431
|
+
questionDot: options.questionDot
|
|
432
|
+
};
|
|
433
|
+
this.obj = options.obj;
|
|
434
|
+
this.indexes = options.indexes;
|
|
435
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.tokens.openingSquare, this.tokens.questionDot, this.tokens.openingSquare, ...this.indexes, this.tokens.closingSquare);
|
|
437
436
|
}
|
|
438
437
|
transpile(state) {
|
|
439
|
-
var _a
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
438
|
+
var _a;
|
|
439
|
+
const result = [];
|
|
440
|
+
result.push(...this.obj.transpile(state), this.tokens.questionDot ? state.transpileToken(this.tokens.questionDot) : '', state.transpileToken(this.tokens.openingSquare, '['));
|
|
441
|
+
for (let i = 0; i < this.indexes.length; i++) {
|
|
442
|
+
//add comma between indexes
|
|
443
|
+
if (i > 0) {
|
|
444
|
+
result.push(', ');
|
|
445
|
+
}
|
|
446
|
+
let index = this.indexes[i];
|
|
447
|
+
result.push(...((_a = index === null || index === void 0 ? void 0 : index.transpile(state)) !== null && _a !== void 0 ? _a : []));
|
|
448
|
+
}
|
|
449
|
+
result.push(state.transpileToken(this.tokens.closingSquare, ']'));
|
|
450
|
+
return result;
|
|
447
451
|
}
|
|
448
452
|
walk(visitor, options) {
|
|
449
453
|
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
450
454
|
(0, visitors_2.walk)(this, 'obj', visitor, options);
|
|
451
|
-
(0, visitors_2.
|
|
455
|
+
(0, visitors_2.walkArray)(this.indexes, visitor, options, this);
|
|
452
456
|
}
|
|
453
457
|
}
|
|
454
458
|
getType(options) {
|
|
@@ -462,21 +466,24 @@ class IndexedGetExpression extends AstNode_1.Expression {
|
|
|
462
466
|
}
|
|
463
467
|
exports.IndexedGetExpression = IndexedGetExpression;
|
|
464
468
|
class GroupingExpression extends AstNode_1.Expression {
|
|
465
|
-
constructor(
|
|
469
|
+
constructor(options) {
|
|
466
470
|
super();
|
|
467
|
-
this.tokens = tokens;
|
|
468
|
-
this.expression = expression;
|
|
469
471
|
this.kind = AstNode_1.AstNodeKind.GroupingExpression;
|
|
470
|
-
this.
|
|
472
|
+
this.tokens = {
|
|
473
|
+
rightParen: options.rightParen,
|
|
474
|
+
leftParen: options.leftParen
|
|
475
|
+
};
|
|
476
|
+
this.expression = options.expression;
|
|
477
|
+
this.range = util_1.default.createBoundingRange(this.tokens.leftParen, this.expression, this.tokens.rightParen);
|
|
471
478
|
}
|
|
472
479
|
transpile(state) {
|
|
473
480
|
if ((0, reflection_1.isTypeCastExpression)(this.expression)) {
|
|
474
481
|
return this.expression.transpile(state);
|
|
475
482
|
}
|
|
476
483
|
return [
|
|
477
|
-
state.transpileToken(this.tokens.
|
|
484
|
+
state.transpileToken(this.tokens.leftParen),
|
|
478
485
|
...this.expression.transpile(state),
|
|
479
|
-
state.transpileToken(this.tokens.
|
|
486
|
+
state.transpileToken(this.tokens.rightParen)
|
|
480
487
|
];
|
|
481
488
|
}
|
|
482
489
|
walk(visitor, options) {
|
|
@@ -490,32 +497,34 @@ class GroupingExpression extends AstNode_1.Expression {
|
|
|
490
497
|
}
|
|
491
498
|
exports.GroupingExpression = GroupingExpression;
|
|
492
499
|
class LiteralExpression extends AstNode_1.Expression {
|
|
493
|
-
constructor(
|
|
500
|
+
constructor(options) {
|
|
494
501
|
super();
|
|
495
|
-
this.token = token;
|
|
496
502
|
this.kind = AstNode_1.AstNodeKind.LiteralExpression;
|
|
503
|
+
this.tokens = {
|
|
504
|
+
value: options.value
|
|
505
|
+
};
|
|
497
506
|
}
|
|
498
507
|
get range() {
|
|
499
|
-
return this.
|
|
508
|
+
return this.tokens.value.range;
|
|
500
509
|
}
|
|
501
510
|
getType(options) {
|
|
502
|
-
return util_1.default.tokenToBscType(this.
|
|
511
|
+
return util_1.default.tokenToBscType(this.tokens.value);
|
|
503
512
|
}
|
|
504
513
|
transpile(state) {
|
|
505
514
|
let text;
|
|
506
|
-
if (this.
|
|
515
|
+
if (this.tokens.value.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
|
|
507
516
|
//wrap quasis with quotes (and escape inner quotemarks)
|
|
508
|
-
text = `"${this.
|
|
517
|
+
text = `"${this.tokens.value.text.replace(/"/g, '""')}"`;
|
|
509
518
|
}
|
|
510
|
-
else if (this.
|
|
511
|
-
text = this.
|
|
519
|
+
else if (this.tokens.value.kind === TokenKind_1.TokenKind.StringLiteral) {
|
|
520
|
+
text = this.tokens.value.text;
|
|
512
521
|
//add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
|
|
513
522
|
if (text.endsWith('"') === false) {
|
|
514
523
|
text += '"';
|
|
515
524
|
}
|
|
516
525
|
}
|
|
517
526
|
else {
|
|
518
|
-
text = this.
|
|
527
|
+
text = this.tokens.value.text;
|
|
519
528
|
}
|
|
520
529
|
return [
|
|
521
530
|
state.sourceNode(this, text)
|
|
@@ -531,15 +540,15 @@ exports.LiteralExpression = LiteralExpression;
|
|
|
531
540
|
* during template string transpile by identifying these expressions explicitly and skipping the bslib_toString around them
|
|
532
541
|
*/
|
|
533
542
|
class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
|
|
534
|
-
constructor(
|
|
543
|
+
constructor(options) {
|
|
535
544
|
super();
|
|
536
|
-
this.token = token;
|
|
537
545
|
this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
|
|
538
|
-
this.
|
|
546
|
+
this.tokens = { value: options.value };
|
|
547
|
+
this.range = this.tokens.value.range;
|
|
539
548
|
}
|
|
540
549
|
transpile(state) {
|
|
541
550
|
return [
|
|
542
|
-
state.sourceNode(this, `chr(${this.
|
|
551
|
+
state.sourceNode(this, `chr(${this.tokens.value.charCode})`)
|
|
543
552
|
];
|
|
544
553
|
}
|
|
545
554
|
walk(visitor, options) {
|
|
@@ -548,18 +557,19 @@ class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
|
|
|
548
557
|
}
|
|
549
558
|
exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
|
|
550
559
|
class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
551
|
-
constructor(
|
|
560
|
+
constructor(options) {
|
|
552
561
|
super();
|
|
553
|
-
this.elements = elements;
|
|
554
|
-
this.open = open;
|
|
555
|
-
this.close = close;
|
|
556
|
-
this.hasSpread = hasSpread;
|
|
557
562
|
this.kind = AstNode_1.AstNodeKind.ArrayLiteralExpression;
|
|
558
|
-
this.
|
|
563
|
+
this.tokens = {
|
|
564
|
+
open: options.open,
|
|
565
|
+
close: options.close
|
|
566
|
+
};
|
|
567
|
+
this.elements = options.elements;
|
|
568
|
+
this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
|
|
559
569
|
}
|
|
560
570
|
transpile(state) {
|
|
561
571
|
let result = [];
|
|
562
|
-
result.push(state.transpileToken(this.open));
|
|
572
|
+
result.push(state.transpileToken(this.tokens.open, '['));
|
|
563
573
|
let hasChildren = this.elements.length > 0;
|
|
564
574
|
state.blockDepth++;
|
|
565
575
|
for (let i = 0; i < this.elements.length; i++) {
|
|
@@ -567,7 +577,7 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
|
567
577
|
let element = this.elements[i];
|
|
568
578
|
if ((0, reflection_1.isCommentStatement)(element)) {
|
|
569
579
|
//if the comment is on the same line as opening square or previous statement, don't add newline
|
|
570
|
-
if (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element)) {
|
|
580
|
+
if (util_1.default.linesTouch(this.tokens.open, element) || util_1.default.linesTouch(previousElement, element)) {
|
|
571
581
|
result.push(' ');
|
|
572
582
|
}
|
|
573
583
|
else {
|
|
@@ -588,8 +598,8 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
|
588
598
|
result.push('\n');
|
|
589
599
|
result.push(state.indent());
|
|
590
600
|
}
|
|
591
|
-
if (this.close) {
|
|
592
|
-
result.push(state.transpileToken(this.close));
|
|
601
|
+
if (this.tokens.close) {
|
|
602
|
+
result.push(state.transpileToken(this.tokens.close));
|
|
593
603
|
}
|
|
594
604
|
return result;
|
|
595
605
|
}
|
|
@@ -600,20 +610,21 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
|
600
610
|
}
|
|
601
611
|
getType(options) {
|
|
602
612
|
const innerTypes = this.elements.filter(x => !(0, reflection_1.isCommentStatement)(x)).map(expr => expr.getType(options));
|
|
603
|
-
return new
|
|
613
|
+
return new ArrayType_1.ArrayType(...innerTypes);
|
|
604
614
|
}
|
|
605
615
|
}
|
|
606
616
|
exports.ArrayLiteralExpression = ArrayLiteralExpression;
|
|
607
617
|
class AAMemberExpression extends AstNode_1.Expression {
|
|
608
|
-
constructor(
|
|
609
|
-
/** The expression evaluated to determine the member's initial value. */
|
|
610
|
-
value) {
|
|
618
|
+
constructor(options) {
|
|
611
619
|
super();
|
|
612
|
-
this.keyToken = keyToken;
|
|
613
|
-
this.colonToken = colonToken;
|
|
614
|
-
this.value = value;
|
|
615
620
|
this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
|
|
616
|
-
this.
|
|
621
|
+
this.tokens = {
|
|
622
|
+
key: options.key,
|
|
623
|
+
colon: options.colon,
|
|
624
|
+
comma: options.comma
|
|
625
|
+
};
|
|
626
|
+
this.value = options.value;
|
|
627
|
+
this.range = util_1.default.createBoundingRange(this.tokens.key, this.tokens.colon, this.value);
|
|
617
628
|
}
|
|
618
629
|
transpile(state) {
|
|
619
630
|
//TODO move the logic from AALiteralExpression loop into this function
|
|
@@ -628,21 +639,23 @@ class AAMemberExpression extends AstNode_1.Expression {
|
|
|
628
639
|
}
|
|
629
640
|
exports.AAMemberExpression = AAMemberExpression;
|
|
630
641
|
class AALiteralExpression extends AstNode_1.Expression {
|
|
631
|
-
constructor(
|
|
642
|
+
constructor(options) {
|
|
632
643
|
super();
|
|
633
|
-
this.elements = elements;
|
|
634
|
-
this.open = open;
|
|
635
|
-
this.close = close;
|
|
636
644
|
this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
|
|
637
|
-
this.
|
|
645
|
+
this.tokens = {
|
|
646
|
+
open: options.open,
|
|
647
|
+
close: options.close
|
|
648
|
+
};
|
|
649
|
+
this.elements = options.elements;
|
|
650
|
+
this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
|
|
638
651
|
}
|
|
639
652
|
transpile(state) {
|
|
640
653
|
let result = [];
|
|
641
654
|
//open curly
|
|
642
|
-
result.push(state.transpileToken(this.open));
|
|
655
|
+
result.push(state.transpileToken(this.tokens.open, '{'));
|
|
643
656
|
let hasChildren = this.elements.length > 0;
|
|
644
657
|
//add newline if the object has children and the first child isn't a comment starting on the same line as opening curly
|
|
645
|
-
if (hasChildren && ((0, reflection_1.isCommentStatement)(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.open))) {
|
|
658
|
+
if (hasChildren && ((0, reflection_1.isCommentStatement)(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.tokens.open))) {
|
|
646
659
|
result.push('\n');
|
|
647
660
|
}
|
|
648
661
|
state.blockDepth++;
|
|
@@ -652,7 +665,7 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
652
665
|
let nextElement = this.elements[i + 1];
|
|
653
666
|
//don't indent if comment is same-line
|
|
654
667
|
if ((0, reflection_1.isCommentStatement)(element) &&
|
|
655
|
-
(util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element))) {
|
|
668
|
+
(util_1.default.linesTouch(this.tokens.open, element) || util_1.default.linesTouch(previousElement, element))) {
|
|
656
669
|
result.push(' ');
|
|
657
670
|
//indent line
|
|
658
671
|
}
|
|
@@ -665,9 +678,9 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
665
678
|
}
|
|
666
679
|
else {
|
|
667
680
|
//key
|
|
668
|
-
result.push(state.transpileToken(element.
|
|
681
|
+
result.push(state.transpileToken(element.tokens.key));
|
|
669
682
|
//colon
|
|
670
|
-
result.push(state.transpileToken(element.
|
|
683
|
+
result.push(state.transpileToken(element.tokens.colon, ':'), ' ');
|
|
671
684
|
//value
|
|
672
685
|
result.push(...element.value.transpile(state));
|
|
673
686
|
}
|
|
@@ -685,9 +698,7 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
685
698
|
result.push(state.indent());
|
|
686
699
|
}
|
|
687
700
|
//close curly
|
|
688
|
-
|
|
689
|
-
result.push(state.transpileToken(this.close));
|
|
690
|
-
}
|
|
701
|
+
result.push(state.transpileToken(this.tokens.close, '}'));
|
|
691
702
|
return result;
|
|
692
703
|
}
|
|
693
704
|
walk(visitor, options) {
|
|
@@ -699,7 +710,7 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
699
710
|
const resultType = new AssociativeArrayType_1.AssociativeArrayType();
|
|
700
711
|
for (const element of this.elements) {
|
|
701
712
|
if ((0, reflection_1.isAAMemberExpression)(element)) {
|
|
702
|
-
resultType.addMember(element.
|
|
713
|
+
resultType.addMember(element.tokens.key.text, { definingNode: element }, element.getType(options), 1 /* SymbolTypeFlag.runtime */);
|
|
703
714
|
}
|
|
704
715
|
}
|
|
705
716
|
return resultType;
|
|
@@ -707,26 +718,28 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
707
718
|
}
|
|
708
719
|
exports.AALiteralExpression = AALiteralExpression;
|
|
709
720
|
class UnaryExpression extends AstNode_1.Expression {
|
|
710
|
-
constructor(
|
|
721
|
+
constructor(options) {
|
|
711
722
|
super();
|
|
712
|
-
this.operator = operator;
|
|
713
|
-
this.right = right;
|
|
714
723
|
this.kind = AstNode_1.AstNodeKind.UnaryExpression;
|
|
715
|
-
this.
|
|
724
|
+
this.tokens = {
|
|
725
|
+
operator: options.operator
|
|
726
|
+
};
|
|
727
|
+
this.right = options.right;
|
|
728
|
+
this.range = util_1.default.createBoundingRange(this.tokens.operator, this.right);
|
|
716
729
|
}
|
|
717
730
|
transpile(state) {
|
|
718
731
|
let separatingWhitespace;
|
|
719
732
|
if ((0, reflection_1.isVariableExpression)(this.right)) {
|
|
720
|
-
separatingWhitespace = this.right.name.leadingWhitespace;
|
|
733
|
+
separatingWhitespace = this.right.tokens.name.leadingWhitespace;
|
|
721
734
|
}
|
|
722
735
|
else if ((0, reflection_1.isLiteralExpression)(this.right)) {
|
|
723
|
-
separatingWhitespace = this.right.
|
|
736
|
+
separatingWhitespace = this.right.tokens.value.leadingWhitespace;
|
|
724
737
|
}
|
|
725
738
|
else {
|
|
726
739
|
separatingWhitespace = ' ';
|
|
727
740
|
}
|
|
728
741
|
return [
|
|
729
|
-
state.transpileToken(this.operator),
|
|
742
|
+
state.transpileToken(this.tokens.operator),
|
|
730
743
|
separatingWhitespace,
|
|
731
744
|
...this.right.transpile(state)
|
|
732
745
|
];
|
|
@@ -737,20 +750,22 @@ class UnaryExpression extends AstNode_1.Expression {
|
|
|
737
750
|
}
|
|
738
751
|
}
|
|
739
752
|
getType(options) {
|
|
740
|
-
return util_1.default.unaryOperatorResultType(this.operator, this.right.getType(options));
|
|
753
|
+
return util_1.default.unaryOperatorResultType(this.tokens.operator, this.right.getType(options));
|
|
741
754
|
}
|
|
742
755
|
}
|
|
743
756
|
exports.UnaryExpression = UnaryExpression;
|
|
744
757
|
class VariableExpression extends AstNode_1.Expression {
|
|
745
|
-
constructor(
|
|
758
|
+
constructor(options) {
|
|
746
759
|
var _a;
|
|
747
760
|
super();
|
|
748
|
-
this.name = name;
|
|
749
761
|
this.kind = AstNode_1.AstNodeKind.VariableExpression;
|
|
750
|
-
this.
|
|
762
|
+
this.tokens = {
|
|
763
|
+
name: options.name
|
|
764
|
+
};
|
|
765
|
+
this.range = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.range;
|
|
751
766
|
}
|
|
752
767
|
getName(parseMode) {
|
|
753
|
-
return this.name.text;
|
|
768
|
+
return this.tokens.name.text;
|
|
754
769
|
}
|
|
755
770
|
transpile(state) {
|
|
756
771
|
let result = [];
|
|
@@ -765,7 +780,7 @@ class VariableExpression extends AstNode_1.Expression {
|
|
|
765
780
|
//transpile normally
|
|
766
781
|
}
|
|
767
782
|
else {
|
|
768
|
-
result.push(state.transpileToken(this.name));
|
|
783
|
+
result.push(state.transpileToken(this.tokens.name));
|
|
769
784
|
}
|
|
770
785
|
return result;
|
|
771
786
|
}
|
|
@@ -774,23 +789,26 @@ class VariableExpression extends AstNode_1.Expression {
|
|
|
774
789
|
}
|
|
775
790
|
getType(options) {
|
|
776
791
|
var _a;
|
|
777
|
-
let resultType = util_1.default.tokenToBscType(this.name);
|
|
778
|
-
const nameKey = this.
|
|
792
|
+
let resultType = util_1.default.tokenToBscType(this.tokens.name);
|
|
793
|
+
const nameKey = this.getName();
|
|
779
794
|
if (!resultType) {
|
|
780
795
|
const symbolTable = this.getSymbolTable();
|
|
781
796
|
resultType = symbolTable === null || symbolTable === void 0 ? void 0 : symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
|
|
782
797
|
}
|
|
783
|
-
(_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry(nameKey, resultType, options.data, this.range));
|
|
798
|
+
(_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry({ name: nameKey, type: resultType, data: options.data, range: this.range, kind: this.kind }));
|
|
784
799
|
return resultType;
|
|
785
800
|
}
|
|
786
801
|
}
|
|
787
802
|
exports.VariableExpression = VariableExpression;
|
|
788
803
|
class SourceLiteralExpression extends AstNode_1.Expression {
|
|
789
|
-
constructor(
|
|
804
|
+
constructor(options) {
|
|
805
|
+
var _a;
|
|
790
806
|
super();
|
|
791
|
-
this.token = token;
|
|
792
807
|
this.kind = AstNode_1.AstNodeKind.SourceLiteralExpression;
|
|
793
|
-
this.
|
|
808
|
+
this.tokens = {
|
|
809
|
+
value: options.value
|
|
810
|
+
};
|
|
811
|
+
this.range = (_a = this.tokens.value) === null || _a === void 0 ? void 0 : _a.range;
|
|
794
812
|
}
|
|
795
813
|
/**
|
|
796
814
|
* Find the index of the function in its parent
|
|
@@ -810,7 +828,7 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
810
828
|
return index;
|
|
811
829
|
}
|
|
812
830
|
getFunctionName(state, parseMode) {
|
|
813
|
-
let func = state.file.getFunctionScopeAtPosition(this.
|
|
831
|
+
let func = state.file.getFunctionScopeAtPosition(this.tokens.value.range.start).func;
|
|
814
832
|
let nameParts = [];
|
|
815
833
|
let parentFunction;
|
|
816
834
|
while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
|
|
@@ -824,13 +842,13 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
824
842
|
}
|
|
825
843
|
transpile(state) {
|
|
826
844
|
let text;
|
|
827
|
-
switch (this.
|
|
845
|
+
switch (this.tokens.value.kind) {
|
|
828
846
|
case TokenKind_1.TokenKind.SourceFilePathLiteral:
|
|
829
847
|
const pathUrl = fileUrl(state.srcPath);
|
|
830
848
|
text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
|
|
831
849
|
break;
|
|
832
850
|
case TokenKind_1.TokenKind.SourceLineNumLiteral:
|
|
833
|
-
text = `${this.
|
|
851
|
+
text = `${this.tokens.value.range.start.line + 1}`;
|
|
834
852
|
break;
|
|
835
853
|
case TokenKind_1.TokenKind.FunctionNameLiteral:
|
|
836
854
|
text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
|
|
@@ -840,7 +858,7 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
840
858
|
break;
|
|
841
859
|
case TokenKind_1.TokenKind.SourceLocationLiteral:
|
|
842
860
|
const locationUrl = fileUrl(state.srcPath);
|
|
843
|
-
text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.
|
|
861
|
+
text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.tokens.value.range.start.line + 1}"`;
|
|
844
862
|
break;
|
|
845
863
|
case TokenKind_1.TokenKind.PkgPathLiteral:
|
|
846
864
|
text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
|
|
@@ -851,7 +869,7 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
851
869
|
case TokenKind_1.TokenKind.LineNumLiteral:
|
|
852
870
|
default:
|
|
853
871
|
//use the original text (because it looks like a variable)
|
|
854
|
-
text = this.
|
|
872
|
+
text = this.tokens.value.text;
|
|
855
873
|
break;
|
|
856
874
|
}
|
|
857
875
|
return [
|
|
@@ -869,12 +887,14 @@ exports.SourceLiteralExpression = SourceLiteralExpression;
|
|
|
869
887
|
* do more type checking.
|
|
870
888
|
*/
|
|
871
889
|
class NewExpression extends AstNode_1.Expression {
|
|
872
|
-
constructor(
|
|
890
|
+
constructor(options) {
|
|
873
891
|
super();
|
|
874
|
-
this.newKeyword = newKeyword;
|
|
875
|
-
this.call = call;
|
|
876
892
|
this.kind = AstNode_1.AstNodeKind.NewExpression;
|
|
877
|
-
this.
|
|
893
|
+
this.tokens = {
|
|
894
|
+
new: options.new
|
|
895
|
+
};
|
|
896
|
+
this.call = options.call;
|
|
897
|
+
this.range = util_1.default.createBoundingRange(this.tokens.new, this.call);
|
|
878
898
|
}
|
|
879
899
|
/**
|
|
880
900
|
* The name of the class to initialize (with optional namespace prefixed)
|
|
@@ -898,33 +918,42 @@ class NewExpression extends AstNode_1.Expression {
|
|
|
898
918
|
}
|
|
899
919
|
}
|
|
900
920
|
getType(options) {
|
|
901
|
-
|
|
921
|
+
const result = this.call.getType(options);
|
|
922
|
+
if (options.typeChain) {
|
|
923
|
+
// modify last typechain entry to show it is a new ...()
|
|
924
|
+
const lastEntry = options.typeChain[options.typeChain.length - 1];
|
|
925
|
+
if (lastEntry) {
|
|
926
|
+
lastEntry.kind = this.kind;
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
return result;
|
|
902
930
|
}
|
|
903
931
|
}
|
|
904
932
|
exports.NewExpression = NewExpression;
|
|
905
933
|
class CallfuncExpression extends AstNode_1.Expression {
|
|
906
|
-
constructor(
|
|
934
|
+
constructor(options) {
|
|
935
|
+
var _a;
|
|
907
936
|
super();
|
|
908
|
-
this.callee = callee;
|
|
909
|
-
this.operator = operator;
|
|
910
|
-
this.methodName = methodName;
|
|
911
|
-
this.openingParen = openingParen;
|
|
912
|
-
this.args = args;
|
|
913
|
-
this.closingParen = closingParen;
|
|
914
937
|
this.kind = AstNode_1.AstNodeKind.CallfuncExpression;
|
|
915
|
-
this.
|
|
938
|
+
this.tokens = {
|
|
939
|
+
operator: options.operator,
|
|
940
|
+
methodName: options.methodName,
|
|
941
|
+
openingParen: options.openingParen,
|
|
942
|
+
closingParen: options.closingParen
|
|
943
|
+
};
|
|
944
|
+
this.callee = options.callee;
|
|
945
|
+
this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
|
|
946
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.tokens.operator, this.tokens.methodName, this.tokens.openingParen, ...this.args, this.tokens.closingParen);
|
|
916
947
|
}
|
|
917
948
|
transpile(state) {
|
|
949
|
+
var _a;
|
|
918
950
|
let result = [];
|
|
919
|
-
result.push(...this.callee.transpile(state), state.sourceNode(this.operator, '.callfunc'), state.transpileToken(this.openingParen),
|
|
951
|
+
result.push(...this.callee.transpile(state), state.sourceNode(this.tokens.operator, '.callfunc'), state.transpileToken(this.tokens.openingParen, '('),
|
|
920
952
|
//the name of the function
|
|
921
|
-
state.sourceNode(this.methodName, ['"', this.methodName.text, '"'])
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
result.push('invalid');
|
|
926
|
-
}
|
|
927
|
-
else {
|
|
953
|
+
state.sourceNode(this.tokens.methodName, ['"', this.tokens.methodName.text, '"']));
|
|
954
|
+
if (((_a = this.args) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
955
|
+
result.push(', ');
|
|
956
|
+
//transpile args
|
|
928
957
|
for (let i = 0; i < this.args.length; i++) {
|
|
929
958
|
//add comma between args
|
|
930
959
|
if (i > 0) {
|
|
@@ -934,7 +963,10 @@ class CallfuncExpression extends AstNode_1.Expression {
|
|
|
934
963
|
result.push(...arg.transpile(state));
|
|
935
964
|
}
|
|
936
965
|
}
|
|
937
|
-
|
|
966
|
+
else if (state.options.legacyCallfuncHandling) {
|
|
967
|
+
result.push(', ', 'invalid');
|
|
968
|
+
}
|
|
969
|
+
result.push(state.transpileToken(this.tokens.closingParen, ')'));
|
|
938
970
|
return result;
|
|
939
971
|
}
|
|
940
972
|
walk(visitor, options) {
|
|
@@ -948,11 +980,17 @@ class CallfuncExpression extends AstNode_1.Expression {
|
|
|
948
980
|
let result = DynamicType_1.DynamicType.instance;
|
|
949
981
|
// a little hacky here with checking options.ignoreCall because callFuncExpression has the method name
|
|
950
982
|
// It's nicer for CallExpression, because it's a call on any expression.
|
|
951
|
-
const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags:
|
|
983
|
+
const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */ }));
|
|
952
984
|
if ((0, reflection_1.isComponentType)(calleeType) || (0, reflection_1.isReferenceType)(calleeType)) {
|
|
953
|
-
const funcType = (_b = (_a = calleeType).getCallFuncType) === null || _b === void 0 ? void 0 : _b.call(_a, this.methodName.text, options);
|
|
985
|
+
const funcType = (_b = (_a = calleeType).getCallFuncType) === null || _b === void 0 ? void 0 : _b.call(_a, this.tokens.methodName.text, options);
|
|
954
986
|
if (funcType) {
|
|
955
|
-
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry(
|
|
987
|
+
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
|
|
988
|
+
name: this.tokens.methodName.text,
|
|
989
|
+
type: funcType,
|
|
990
|
+
data: options.data, range: this.tokens.methodName.range,
|
|
991
|
+
separatorToken: (0, creators_1.createToken)(TokenKind_1.TokenKind.Callfunc),
|
|
992
|
+
kind: this.kind
|
|
993
|
+
}));
|
|
956
994
|
if (options.ignoreCall) {
|
|
957
995
|
result = funcType;
|
|
958
996
|
}
|
|
@@ -977,11 +1015,11 @@ exports.CallfuncExpression = CallfuncExpression;
|
|
|
977
1015
|
* This is a single expression that represents the string contatenation of all parts of a single quasi.
|
|
978
1016
|
*/
|
|
979
1017
|
class TemplateStringQuasiExpression extends AstNode_1.Expression {
|
|
980
|
-
constructor(
|
|
1018
|
+
constructor(options) {
|
|
981
1019
|
super();
|
|
982
|
-
this.expressions = expressions;
|
|
983
1020
|
this.kind = AstNode_1.AstNodeKind.TemplateStringQuasiExpression;
|
|
984
|
-
this.
|
|
1021
|
+
this.expressions = options.expressions;
|
|
1022
|
+
this.range = util_1.default.createBoundingRange(...this.expressions);
|
|
985
1023
|
}
|
|
986
1024
|
transpile(state, skipEmptyStrings = true) {
|
|
987
1025
|
let result = [];
|
|
@@ -989,7 +1027,7 @@ class TemplateStringQuasiExpression extends AstNode_1.Expression {
|
|
|
989
1027
|
for (let expression of this.expressions) {
|
|
990
1028
|
//skip empty strings
|
|
991
1029
|
//TODO what does an empty string literal expression look like?
|
|
992
|
-
if (expression.
|
|
1030
|
+
if (expression.tokens.value.text === '' && skipEmptyStrings === true) {
|
|
993
1031
|
continue;
|
|
994
1032
|
}
|
|
995
1033
|
result.push(plus, ...expression.transpile(state));
|
|
@@ -1005,14 +1043,16 @@ class TemplateStringQuasiExpression extends AstNode_1.Expression {
|
|
|
1005
1043
|
}
|
|
1006
1044
|
exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
|
|
1007
1045
|
class TemplateStringExpression extends AstNode_1.Expression {
|
|
1008
|
-
constructor(
|
|
1046
|
+
constructor(options) {
|
|
1009
1047
|
super();
|
|
1010
|
-
this.openingBacktick = openingBacktick;
|
|
1011
|
-
this.quasis = quasis;
|
|
1012
|
-
this.expressions = expressions;
|
|
1013
|
-
this.closingBacktick = closingBacktick;
|
|
1014
1048
|
this.kind = AstNode_1.AstNodeKind.TemplateStringExpression;
|
|
1015
|
-
this.
|
|
1049
|
+
this.tokens = {
|
|
1050
|
+
openingBacktick: options.openingBacktick,
|
|
1051
|
+
closingBacktick: options.closingBacktick
|
|
1052
|
+
};
|
|
1053
|
+
this.quasis = options.quasis;
|
|
1054
|
+
this.expressions = options.expressions;
|
|
1055
|
+
this.range = util_1.default.createBoundingRange(this.tokens.openingBacktick, this.quasis[0], this.quasis[this.quasis.length - 1], this.tokens.closingBacktick);
|
|
1016
1056
|
}
|
|
1017
1057
|
getType(options) {
|
|
1018
1058
|
return StringType_1.StringType.instance;
|
|
@@ -1068,19 +1108,21 @@ class TemplateStringExpression extends AstNode_1.Expression {
|
|
|
1068
1108
|
}
|
|
1069
1109
|
exports.TemplateStringExpression = TemplateStringExpression;
|
|
1070
1110
|
class TaggedTemplateStringExpression extends AstNode_1.Expression {
|
|
1071
|
-
constructor(
|
|
1111
|
+
constructor(options) {
|
|
1072
1112
|
super();
|
|
1073
|
-
this.tagName = tagName;
|
|
1074
|
-
this.openingBacktick = openingBacktick;
|
|
1075
|
-
this.quasis = quasis;
|
|
1076
|
-
this.expressions = expressions;
|
|
1077
|
-
this.closingBacktick = closingBacktick;
|
|
1078
1113
|
this.kind = AstNode_1.AstNodeKind.TaggedTemplateStringExpression;
|
|
1079
|
-
this.
|
|
1114
|
+
this.tokens = {
|
|
1115
|
+
tagName: options.tagName,
|
|
1116
|
+
openingBacktick: options.openingBacktick,
|
|
1117
|
+
closingBacktick: options.closingBacktick
|
|
1118
|
+
};
|
|
1119
|
+
this.quasis = options.quasis;
|
|
1120
|
+
this.expressions = options.expressions;
|
|
1121
|
+
this.range = util_1.default.createBoundingRange(this.tokens.tagName, this.tokens.openingBacktick, this.quasis[0], this.quasis[this.quasis.length - 1], this.tokens.closingBacktick);
|
|
1080
1122
|
}
|
|
1081
1123
|
transpile(state) {
|
|
1082
1124
|
let result = [];
|
|
1083
|
-
result.push(state.transpileToken(this.tagName), '([');
|
|
1125
|
+
result.push(state.transpileToken(this.tokens.tagName), '([');
|
|
1084
1126
|
//add quasis as the first array
|
|
1085
1127
|
for (let i = 0; i < this.quasis.length; i++) {
|
|
1086
1128
|
let quasi = this.quasis[i];
|
|
@@ -1099,7 +1141,7 @@ class TaggedTemplateStringExpression extends AstNode_1.Expression {
|
|
|
1099
1141
|
}
|
|
1100
1142
|
result.push(...expression.transpile(state));
|
|
1101
1143
|
}
|
|
1102
|
-
result.push(state.sourceNode(this.closingBacktick, '])'));
|
|
1144
|
+
result.push(state.sourceNode(this.tokens.closingBacktick, '])'));
|
|
1103
1145
|
return result;
|
|
1104
1146
|
}
|
|
1105
1147
|
walk(visitor, options) {
|
|
@@ -1117,15 +1159,18 @@ class TaggedTemplateStringExpression extends AstNode_1.Expression {
|
|
|
1117
1159
|
}
|
|
1118
1160
|
exports.TaggedTemplateStringExpression = TaggedTemplateStringExpression;
|
|
1119
1161
|
class AnnotationExpression extends AstNode_1.Expression {
|
|
1120
|
-
constructor(
|
|
1162
|
+
constructor(options) {
|
|
1121
1163
|
super();
|
|
1122
|
-
this.atToken = atToken;
|
|
1123
|
-
this.nameToken = nameToken;
|
|
1124
1164
|
this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
|
|
1125
|
-
this.
|
|
1165
|
+
this.tokens = {
|
|
1166
|
+
at: options.at,
|
|
1167
|
+
name: options.name
|
|
1168
|
+
};
|
|
1169
|
+
this.call = options.call;
|
|
1170
|
+
this.name = this.tokens.name.text;
|
|
1126
1171
|
}
|
|
1127
1172
|
get range() {
|
|
1128
|
-
return util_1.default.createBoundingRange(this.
|
|
1173
|
+
return util_1.default.createBoundingRange(this.tokens.at, this.tokens.name, this.call);
|
|
1129
1174
|
}
|
|
1130
1175
|
/**
|
|
1131
1176
|
* Convert annotation arguments to JavaScript types
|
|
@@ -1138,7 +1183,8 @@ class AnnotationExpression extends AstNode_1.Expression {
|
|
|
1138
1183
|
return this.call.args.map(e => expressionToValue(e, strict));
|
|
1139
1184
|
}
|
|
1140
1185
|
getLeadingTrivia() {
|
|
1141
|
-
|
|
1186
|
+
var _a;
|
|
1187
|
+
return (_a = this.tokens.at) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
|
|
1142
1188
|
}
|
|
1143
1189
|
transpile(state) {
|
|
1144
1190
|
return [];
|
|
@@ -1157,15 +1203,17 @@ class AnnotationExpression extends AstNode_1.Expression {
|
|
|
1157
1203
|
}
|
|
1158
1204
|
exports.AnnotationExpression = AnnotationExpression;
|
|
1159
1205
|
class TernaryExpression extends AstNode_1.Expression {
|
|
1160
|
-
constructor(
|
|
1206
|
+
constructor(options) {
|
|
1161
1207
|
super();
|
|
1162
|
-
this.test = test;
|
|
1163
|
-
this.questionMarkToken = questionMarkToken;
|
|
1164
|
-
this.consequent = consequent;
|
|
1165
|
-
this.colonToken = colonToken;
|
|
1166
|
-
this.alternate = alternate;
|
|
1167
1208
|
this.kind = AstNode_1.AstNodeKind.TernaryExpression;
|
|
1168
|
-
this.
|
|
1209
|
+
this.tokens = {
|
|
1210
|
+
questionMark: options.questionMark,
|
|
1211
|
+
colon: options.colon
|
|
1212
|
+
};
|
|
1213
|
+
this.test = options.test;
|
|
1214
|
+
this.consequent = options.consequent;
|
|
1215
|
+
this.alternate = options.alternate;
|
|
1216
|
+
this.range = util_1.default.createBoundingRange(this.test, this.tokens.questionMark, this.consequent, this.tokens.colon, this.alternate);
|
|
1169
1217
|
}
|
|
1170
1218
|
transpile(state) {
|
|
1171
1219
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
@@ -1179,12 +1227,12 @@ class TernaryExpression extends AstNode_1.Expression {
|
|
|
1179
1227
|
...alternateInfo.expressions
|
|
1180
1228
|
].filter(e => e instanceof CallExpression || e instanceof CallfuncExpression || e instanceof DottedGetExpression);
|
|
1181
1229
|
if (mutatingExpressions.length > 0) {
|
|
1182
|
-
result.push(state.sourceNode(this.
|
|
1230
|
+
result.push(state.sourceNode(this.tokens.questionMark,
|
|
1183
1231
|
//write all the scope variables as parameters.
|
|
1184
1232
|
//TODO handle when there are more than 31 parameters
|
|
1185
1233
|
`(function(__bsCondition, ${allUniqueVarNames.join(', ')})`), state.newline,
|
|
1186
1234
|
//double indent so our `end function` line is still indented one at the end
|
|
1187
|
-
state.indent(2), state.sourceNode(this.test, `if __bsCondition then`), state.newline, state.indent(1), state.sourceNode((_a = this.consequent) !== null && _a !== void 0 ? _a : this.
|
|
1235
|
+
state.indent(2), state.sourceNode(this.test, `if __bsCondition then`), state.newline, state.indent(1), state.sourceNode((_a = this.consequent) !== null && _a !== void 0 ? _a : this.tokens.questionMark, 'return '), ...(_c = (_b = this.consequent) === null || _b === void 0 ? void 0 : _b.transpile(state)) !== null && _c !== void 0 ? _c : [state.sourceNode(this.tokens.questionMark, 'invalid')], state.newline, state.indent(-1), state.sourceNode((_d = this.consequent) !== null && _d !== void 0 ? _d : this.tokens.questionMark, 'else'), state.newline, state.indent(1), state.sourceNode((_e = this.consequent) !== null && _e !== void 0 ? _e : this.tokens.questionMark, 'return '), ...(_g = (_f = this.alternate) === null || _f === void 0 ? void 0 : _f.transpile(state)) !== null && _g !== void 0 ? _g : [state.sourceNode((_h = this.consequent) !== null && _h !== void 0 ? _h : this.tokens.questionMark, 'invalid')], state.newline, state.indent(-1), state.sourceNode(this.tokens.questionMark, 'end if'), state.newline, state.indent(-1), state.sourceNode(this.tokens.questionMark, 'end function)('), ...this.test.transpile(state), state.sourceNode(this.tokens.questionMark, `, ${allUniqueVarNames.join(', ')})`));
|
|
1188
1236
|
state.blockDepth--;
|
|
1189
1237
|
}
|
|
1190
1238
|
else {
|
|
@@ -1202,13 +1250,15 @@ class TernaryExpression extends AstNode_1.Expression {
|
|
|
1202
1250
|
}
|
|
1203
1251
|
exports.TernaryExpression = TernaryExpression;
|
|
1204
1252
|
class NullCoalescingExpression extends AstNode_1.Expression {
|
|
1205
|
-
constructor(
|
|
1253
|
+
constructor(options) {
|
|
1206
1254
|
super();
|
|
1207
|
-
this.consequent = consequent;
|
|
1208
|
-
this.questionQuestionToken = questionQuestionToken;
|
|
1209
|
-
this.alternate = alternate;
|
|
1210
1255
|
this.kind = AstNode_1.AstNodeKind.NullCoalescingExpression;
|
|
1211
|
-
this.
|
|
1256
|
+
this.tokens = {
|
|
1257
|
+
questionQuestion: options.questionQuestion
|
|
1258
|
+
};
|
|
1259
|
+
this.consequent = options.consequent;
|
|
1260
|
+
this.alternate = options.alternate;
|
|
1261
|
+
this.range = util_1.default.createBoundingRange(this.consequent, this.tokens.questionQuestion, this.alternate);
|
|
1212
1262
|
}
|
|
1213
1263
|
transpile(state) {
|
|
1214
1264
|
let result = [];
|
|
@@ -1245,10 +1295,12 @@ class NullCoalescingExpression extends AstNode_1.Expression {
|
|
|
1245
1295
|
}
|
|
1246
1296
|
exports.NullCoalescingExpression = NullCoalescingExpression;
|
|
1247
1297
|
class RegexLiteralExpression extends AstNode_1.Expression {
|
|
1248
|
-
constructor(
|
|
1298
|
+
constructor(options) {
|
|
1249
1299
|
super();
|
|
1250
|
-
this.tokens = tokens;
|
|
1251
1300
|
this.kind = AstNode_1.AstNodeKind.RegexLiteralExpression;
|
|
1301
|
+
this.tokens = {
|
|
1302
|
+
regexLiteral: options.regexLiteral
|
|
1303
|
+
};
|
|
1252
1304
|
}
|
|
1253
1305
|
get range() {
|
|
1254
1306
|
var _a, _b;
|
|
@@ -1288,17 +1340,17 @@ function expressionToValue(expr, strict) {
|
|
|
1288
1340
|
return null;
|
|
1289
1341
|
}
|
|
1290
1342
|
if ((0, reflection_1.isUnaryExpression)(expr) && (0, reflection_1.isLiteralNumber)(expr.right)) {
|
|
1291
|
-
return numberExpressionToValue(expr.right, expr.operator.text);
|
|
1343
|
+
return numberExpressionToValue(expr.right, expr.tokens.operator.text);
|
|
1292
1344
|
}
|
|
1293
1345
|
if ((0, reflection_1.isLiteralString)(expr)) {
|
|
1294
1346
|
//remove leading and trailing quotes
|
|
1295
|
-
return expr.
|
|
1347
|
+
return expr.tokens.value.text.replace(/^"/, '').replace(/"$/, '');
|
|
1296
1348
|
}
|
|
1297
1349
|
if ((0, reflection_1.isLiteralNumber)(expr)) {
|
|
1298
1350
|
return numberExpressionToValue(expr);
|
|
1299
1351
|
}
|
|
1300
1352
|
if ((0, reflection_1.isLiteralBoolean)(expr)) {
|
|
1301
|
-
return expr.
|
|
1353
|
+
return expr.tokens.value.text.toLowerCase() === 'true';
|
|
1302
1354
|
}
|
|
1303
1355
|
if ((0, reflection_1.isArrayLiteralExpression)(expr)) {
|
|
1304
1356
|
return expr.elements
|
|
@@ -1308,7 +1360,7 @@ function expressionToValue(expr, strict) {
|
|
|
1308
1360
|
if ((0, reflection_1.isAALiteralExpression)(expr)) {
|
|
1309
1361
|
return expr.elements.reduce((acc, e) => {
|
|
1310
1362
|
if (!(0, reflection_1.isCommentStatement)(e)) {
|
|
1311
|
-
acc[e.
|
|
1363
|
+
acc[e.tokens.key.text] = expressionToValue(e.value, strict);
|
|
1312
1364
|
}
|
|
1313
1365
|
return acc;
|
|
1314
1366
|
}, {});
|
|
@@ -1317,25 +1369,22 @@ function expressionToValue(expr, strict) {
|
|
|
1317
1369
|
}
|
|
1318
1370
|
function numberExpressionToValue(expr, operator = '') {
|
|
1319
1371
|
if ((0, reflection_1.isIntegerType)(expr.getType()) || (0, reflection_1.isLongIntegerType)(expr.getType())) {
|
|
1320
|
-
return parseInt(operator + expr.
|
|
1372
|
+
return parseInt(operator + expr.tokens.value.text);
|
|
1321
1373
|
}
|
|
1322
1374
|
else {
|
|
1323
|
-
return parseFloat(operator + expr.
|
|
1375
|
+
return parseFloat(operator + expr.tokens.value.text);
|
|
1324
1376
|
}
|
|
1325
1377
|
}
|
|
1326
1378
|
class TypeExpression extends AstNode_1.Expression {
|
|
1327
|
-
constructor(
|
|
1328
|
-
|
|
1329
|
-
* The standard AST expression that represents the type for this TypeExpression.
|
|
1330
|
-
*/
|
|
1331
|
-
expression) {
|
|
1379
|
+
constructor(options) {
|
|
1380
|
+
var _a;
|
|
1332
1381
|
super();
|
|
1333
|
-
this.expression = expression;
|
|
1334
1382
|
this.kind = AstNode_1.AstNodeKind.TypeExpression;
|
|
1335
|
-
this.
|
|
1383
|
+
this.expression = options.expression;
|
|
1384
|
+
this.range = (_a = this.expression) === null || _a === void 0 ? void 0 : _a.range;
|
|
1336
1385
|
}
|
|
1337
1386
|
transpile(state) {
|
|
1338
|
-
return [this.getType({ flags:
|
|
1387
|
+
return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
|
|
1339
1388
|
}
|
|
1340
1389
|
walk(visitor, options) {
|
|
1341
1390
|
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
@@ -1343,7 +1392,7 @@ class TypeExpression extends AstNode_1.Expression {
|
|
|
1343
1392
|
}
|
|
1344
1393
|
}
|
|
1345
1394
|
getType(options) {
|
|
1346
|
-
return this.expression.getType(Object.assign(Object.assign({}, options), { flags:
|
|
1395
|
+
return this.expression.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */ }));
|
|
1347
1396
|
}
|
|
1348
1397
|
getTypedef(state) {
|
|
1349
1398
|
// TypeDefs should pass through any valid type names
|
|
@@ -1360,13 +1409,15 @@ class TypeExpression extends AstNode_1.Expression {
|
|
|
1360
1409
|
}
|
|
1361
1410
|
exports.TypeExpression = TypeExpression;
|
|
1362
1411
|
class TypeCastExpression extends AstNode_1.Expression {
|
|
1363
|
-
constructor(
|
|
1412
|
+
constructor(options) {
|
|
1364
1413
|
super();
|
|
1365
|
-
this.obj = obj;
|
|
1366
|
-
this.asToken = asToken;
|
|
1367
|
-
this.typeExpression = typeExpression;
|
|
1368
1414
|
this.kind = AstNode_1.AstNodeKind.TypeCastExpression;
|
|
1369
|
-
this.
|
|
1415
|
+
this.tokens = {
|
|
1416
|
+
as: options.as
|
|
1417
|
+
};
|
|
1418
|
+
this.obj = options.obj;
|
|
1419
|
+
this.typeExpression = options.typeExpression;
|
|
1420
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.tokens.as, this.typeExpression);
|
|
1370
1421
|
}
|
|
1371
1422
|
transpile(state) {
|
|
1372
1423
|
return this.obj.transpile(state);
|
|
@@ -1378,21 +1429,31 @@ class TypeCastExpression extends AstNode_1.Expression {
|
|
|
1378
1429
|
}
|
|
1379
1430
|
}
|
|
1380
1431
|
getType(options) {
|
|
1381
|
-
|
|
1432
|
+
const result = this.typeExpression.getType(options);
|
|
1433
|
+
if (options.typeChain) {
|
|
1434
|
+
// modify last typechain entry to show it is a typecast
|
|
1435
|
+
const lastEntry = options.typeChain[options.typeChain.length - 1];
|
|
1436
|
+
if (lastEntry) {
|
|
1437
|
+
lastEntry.kind = this.kind;
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
return result;
|
|
1382
1441
|
}
|
|
1383
1442
|
}
|
|
1384
1443
|
exports.TypeCastExpression = TypeCastExpression;
|
|
1385
1444
|
class TypedArrayExpression extends AstNode_1.Expression {
|
|
1386
|
-
constructor(
|
|
1445
|
+
constructor(options) {
|
|
1387
1446
|
super();
|
|
1388
|
-
this.innerType = innerType;
|
|
1389
|
-
this.leftBracket = leftBracket;
|
|
1390
|
-
this.rightBracket = rightBracket;
|
|
1391
1447
|
this.kind = AstNode_1.AstNodeKind.TypedArrayExpression;
|
|
1392
|
-
this.
|
|
1448
|
+
this.tokens = {
|
|
1449
|
+
leftBracket: options.leftBracket,
|
|
1450
|
+
rightBracket: options.rightBracket
|
|
1451
|
+
};
|
|
1452
|
+
this.innerType = options.innerType;
|
|
1453
|
+
this.range = util_1.default.createBoundingRange(this.innerType, this.tokens.leftBracket, this.tokens.rightBracket);
|
|
1393
1454
|
}
|
|
1394
1455
|
transpile(state) {
|
|
1395
|
-
return [this.getType({ flags:
|
|
1456
|
+
return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
|
|
1396
1457
|
}
|
|
1397
1458
|
walk(visitor, options) {
|
|
1398
1459
|
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
@@ -1400,7 +1461,7 @@ class TypedArrayExpression extends AstNode_1.Expression {
|
|
|
1400
1461
|
}
|
|
1401
1462
|
}
|
|
1402
1463
|
getType(options) {
|
|
1403
|
-
return new
|
|
1464
|
+
return new ArrayType_1.ArrayType(this.innerType.getType(options));
|
|
1404
1465
|
}
|
|
1405
1466
|
}
|
|
1406
1467
|
exports.TypedArrayExpression = TypedArrayExpression;
|