brighterscript 1.0.0-alpha.26 → 1.0.0-alpha.28
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 +82 -5
- package/README.md +1 -1
- package/dist/AstValidationSegmenter.d.ts +1 -1
- package/dist/AstValidationSegmenter.js +4 -5
- package/dist/AstValidationSegmenter.js.map +1 -1
- package/dist/DiagnosticFilterer.d.ts +7 -4
- package/dist/DiagnosticFilterer.js +67 -37
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +1 -3
- package/dist/DiagnosticMessages.js +5 -8
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/PluginInterface.js +1 -1
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +1 -1
- package/dist/Program.js +34 -31
- package/dist/Program.js.map +1 -1
- package/dist/Scope.d.ts +7 -34
- package/dist/Scope.js +45 -305
- 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/SymbolTypeFlag.d.ts +8 -0
- package/dist/SymbolTypeFlag.js +13 -0
- package/dist/SymbolTypeFlag.js.map +1 -0
- package/dist/XmlScope.d.ts +0 -8
- package/dist/XmlScope.js +6 -84
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/CachedLookups.d.ts +1 -2
- package/dist/astUtils/CachedLookups.js +4 -19
- package/dist/astUtils/CachedLookups.js.map +1 -1
- package/dist/astUtils/creators.d.ts +1 -0
- package/dist/astUtils/creators.js +48 -8
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +0 -10
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +3 -2
- package/dist/astUtils/reflection.js +11 -7
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +11 -16
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +1 -2
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +1 -5
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +2 -1
- package/dist/bscPlugin/BscPlugin.js +4 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/SignatureHelpUtil.js +4 -3
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +1 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js +46 -29
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +39 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +30 -10
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +125 -7
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
- package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
- package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -3
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +25 -31
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +34 -1
- package/dist/bscPlugin/validation/ScopeValidator.js +435 -27
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +178 -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 +15 -7
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +14 -5
- package/dist/files/BrsFile.js +83 -150
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +429 -162
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +2 -3
- package/dist/files/XmlFile.js +1 -3
- package/dist/files/XmlFile.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 +117 -85
- package/dist/interfaces.js +9 -9
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +9 -3
- package/dist/lexer/Lexer.js +36 -15
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +76 -38
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.js +1 -1
- package/dist/lexer/Token.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +1 -0
- package/dist/lexer/TokenKind.js +4 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +1 -2
- package/dist/parser/AstNode.js +0 -1
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/BrsTranspileState.d.ts +1 -1
- package/dist/parser/Expression.d.ts +153 -135
- package/dist/parser/Expression.js +204 -114
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +15 -16
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +8 -4
- package/dist/parser/Parser.js +108 -149
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +48 -72
- 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 +31 -60
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +214 -207
- package/dist/parser/Statement.js +248 -169
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +0 -13
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +17 -8
- package/dist/parser/TranspileState.js +64 -6
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +1 -1
- package/dist/parser/tests/Parser.spec.js +1 -2
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +1 -3
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +44 -0
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +6 -6
- package/dist/parser/tests/expression/TernaryExpression.spec.js +47 -0
- 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 +2 -2
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +8 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +25 -5
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +9 -2
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Chunk.js +1 -2
- package/dist/preprocessor/Chunk.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.js +2 -1
- package/dist/preprocessor/PreprocessorParser.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.d.ts +3 -0
- package/dist/types/AssociativeArrayType.js +10 -2
- package/dist/types/AssociativeArrayType.js.map +1 -1
- package/dist/types/BscType.d.ts +1 -1
- package/dist/types/BscType.js +3 -3
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.js +7 -8
- 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 +21 -11
- package/dist/util.js +116 -37
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +0 -9
- package/dist/validators/ClassValidator.js +3 -46
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +6 -3
|
@@ -11,17 +11,17 @@ const reflection_1 = require("../astUtils/reflection");
|
|
|
11
11
|
const interfaces_1 = require("../interfaces");
|
|
12
12
|
const VoidType_1 = require("../types/VoidType");
|
|
13
13
|
const DynamicType_1 = require("../types/DynamicType");
|
|
14
|
-
const SymbolTable_1 = require("../SymbolTable");
|
|
15
|
-
const TypedFunctionType_1 = require("../types/TypedFunctionType");
|
|
16
14
|
const AstNode_1 = require("./AstNode");
|
|
17
|
-
const
|
|
15
|
+
const SymbolTable_1 = require("../SymbolTable");
|
|
18
16
|
const source_map_1 = require("source-map");
|
|
19
17
|
const StringType_1 = require("../types/StringType");
|
|
20
18
|
const ReferenceType_1 = require("../types/ReferenceType");
|
|
21
19
|
const UnionType_1 = require("../types/UnionType");
|
|
22
|
-
const
|
|
20
|
+
const ArrayType_1 = require("../types/ArrayType");
|
|
23
21
|
const AssociativeArrayType_1 = require("../types/AssociativeArrayType");
|
|
24
22
|
const creators_1 = require("../astUtils/creators");
|
|
23
|
+
const types_1 = require("../types");
|
|
24
|
+
const FunctionType_1 = require("../types/FunctionType");
|
|
25
25
|
class BinaryExpression extends AstNode_1.Expression {
|
|
26
26
|
constructor(options) {
|
|
27
27
|
super();
|
|
@@ -50,7 +50,7 @@ class BinaryExpression extends AstNode_1.Expression {
|
|
|
50
50
|
}
|
|
51
51
|
getType(options) {
|
|
52
52
|
const operatorKind = this.tokens.operator.kind;
|
|
53
|
-
if (options.flags &
|
|
53
|
+
if (options.flags & 2 /* SymbolTypeFlag.typetime */) {
|
|
54
54
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
55
55
|
switch (operatorKind) {
|
|
56
56
|
case TokenKind_1.TokenKind.Or:
|
|
@@ -58,11 +58,14 @@ class BinaryExpression extends AstNode_1.Expression {
|
|
|
58
58
|
//TODO: Intersection Types?, eg. case TokenKind.And:
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
|
-
else if (options.flags &
|
|
61
|
+
else if (options.flags & 1 /* SymbolTypeFlag.runtime */) {
|
|
62
62
|
return util_1.default.binaryOperatorResultType(this.left.getType(options), this.tokens.operator, this.right.getType(options));
|
|
63
63
|
}
|
|
64
64
|
return DynamicType_1.DynamicType.instance;
|
|
65
65
|
}
|
|
66
|
+
getLeadingTrivia() {
|
|
67
|
+
return this.left.getLeadingTrivia();
|
|
68
|
+
}
|
|
66
69
|
}
|
|
67
70
|
exports.BinaryExpression = BinaryExpression;
|
|
68
71
|
class CallExpression extends AstNode_1.Expression {
|
|
@@ -119,11 +122,14 @@ class CallExpression extends AstNode_1.Expression {
|
|
|
119
122
|
if ((0, reflection_1.isCallableType)(calleeType) && (!(0, reflection_1.isReferenceType)(calleeType.returnType) || ((_a = calleeType.returnType) === null || _a === void 0 ? void 0 : _a.isResolvable()))) {
|
|
120
123
|
return calleeType.returnType;
|
|
121
124
|
}
|
|
122
|
-
if (!(0, reflection_1.isReferenceType)(calleeType) && ((_b = calleeType.returnType) === null || _b === void 0 ? void 0 : _b.isResolvable())) {
|
|
125
|
+
if (!(0, reflection_1.isReferenceType)(calleeType) && ((_b = calleeType === null || calleeType === void 0 ? void 0 : calleeType.returnType) === null || _b === void 0 ? void 0 : _b.isResolvable())) {
|
|
123
126
|
return calleeType.returnType;
|
|
124
127
|
}
|
|
125
128
|
return new ReferenceType_1.TypePropertyReferenceType(calleeType, 'returnType');
|
|
126
129
|
}
|
|
130
|
+
getLeadingTrivia() {
|
|
131
|
+
return this.callee.getLeadingTrivia();
|
|
132
|
+
}
|
|
127
133
|
}
|
|
128
134
|
exports.CallExpression = CallExpression;
|
|
129
135
|
CallExpression.MaximumArguments = 32;
|
|
@@ -132,11 +138,6 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
132
138
|
var _a;
|
|
133
139
|
super();
|
|
134
140
|
this.kind = AstNode_1.AstNodeKind.FunctionExpression;
|
|
135
|
-
/**
|
|
136
|
-
* The list of function calls that are declared within this function scope. This excludes CallExpressions
|
|
137
|
-
* declared in child functions
|
|
138
|
-
*/
|
|
139
|
-
this.callExpressions = [];
|
|
140
141
|
this.tokens = {
|
|
141
142
|
functionType: options.functionType,
|
|
142
143
|
leftParen: options.leftParen,
|
|
@@ -149,9 +150,9 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
149
150
|
this.returnTypeExpression = options.returnTypeExpression;
|
|
150
151
|
//if there's a body, and it doesn't have a SymbolTable, assign one
|
|
151
152
|
if (this.body && !this.body.symbolTable) {
|
|
152
|
-
this.body.symbolTable = new
|
|
153
|
+
this.body.symbolTable = new SymbolTable_1.SymbolTable(`Block`, () => this.getSymbolTable());
|
|
153
154
|
}
|
|
154
|
-
this.symbolTable = new
|
|
155
|
+
this.symbolTable = new SymbolTable_1.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
|
|
155
156
|
}
|
|
156
157
|
getLeadingTrivia() {
|
|
157
158
|
var _a, _b;
|
|
@@ -165,7 +166,7 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
165
166
|
return util_1.default.createBoundingRange(this.tokens.functionType, this.tokens.leftParen, ...this.parameters, this.tokens.rightParen, this.tokens.as, this.returnTypeExpression, this.tokens.endFunctionType);
|
|
166
167
|
}
|
|
167
168
|
transpile(state, name, includeBody = true) {
|
|
168
|
-
var _a;
|
|
169
|
+
var _a, _b, _c;
|
|
169
170
|
let results = [];
|
|
170
171
|
//'function'|'sub'
|
|
171
172
|
results.push(state.transpileToken(this.tokens.functionType, 'function'));
|
|
@@ -195,15 +196,16 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
195
196
|
//return type
|
|
196
197
|
...this.returnTypeExpression.transpile(state));
|
|
197
198
|
}
|
|
199
|
+
let hasBody = false;
|
|
198
200
|
if (includeBody) {
|
|
199
201
|
state.lineage.unshift(this);
|
|
200
202
|
let body = this.body.transpile(state);
|
|
203
|
+
hasBody = body.length > 0;
|
|
201
204
|
state.lineage.shift();
|
|
202
205
|
results.push(...body);
|
|
203
206
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
results.push(state.indent(), state.transpileToken(this.tokens.endFunctionType, `end ${(_a = this.tokens.functionType) !== null && _a !== void 0 ? _a : 'function'}`));
|
|
207
|
+
const lastLocatable = hasBody ? this.body : (_b = (_a = this.returnTypeExpression) !== null && _a !== void 0 ? _a : this.tokens.leftParen) !== null && _b !== void 0 ? _b : this.tokens.functionType;
|
|
208
|
+
results.push(...state.transpileEndBlockToken(lastLocatable, this.tokens.endFunctionType, `end ${(_c = this.tokens.functionType) !== null && _c !== void 0 ? _c : 'function'}`));
|
|
207
209
|
return results;
|
|
208
210
|
}
|
|
209
211
|
getTypedef(state) {
|
|
@@ -258,7 +260,7 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
258
260
|
if (!returnType) {
|
|
259
261
|
returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
|
|
260
262
|
}
|
|
261
|
-
const resultType = new
|
|
263
|
+
const resultType = new types_1.TypedFunctionType(returnType);
|
|
262
264
|
resultType.isSub = isSub;
|
|
263
265
|
for (let param of this.parameters) {
|
|
264
266
|
resultType.addParameter(param.tokens.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
|
|
@@ -278,7 +280,7 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
278
280
|
if (funcName) {
|
|
279
281
|
resultType.setName(funcName);
|
|
280
282
|
}
|
|
281
|
-
(_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry(funcName, resultType, options.data, this.range));
|
|
283
|
+
(_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 }));
|
|
282
284
|
return resultType;
|
|
283
285
|
}
|
|
284
286
|
}
|
|
@@ -297,8 +299,8 @@ class FunctionParameterExpression extends AstNode_1.Expression {
|
|
|
297
299
|
}
|
|
298
300
|
getType(options) {
|
|
299
301
|
var _a, _b, _c, _d, _e;
|
|
300
|
-
const paramType = (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags:
|
|
301
|
-
(_e = options.typeChain) === null || _e === void 0 ? void 0 : _e.push(new interfaces_1.TypeChainEntry(this.tokens.name.text, paramType, options.data, this.range));
|
|
302
|
+
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;
|
|
303
|
+
(_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 }));
|
|
302
304
|
return paramType;
|
|
303
305
|
}
|
|
304
306
|
get range() {
|
|
@@ -326,20 +328,19 @@ class FunctionParameterExpression extends AstNode_1.Expression {
|
|
|
326
328
|
}
|
|
327
329
|
getTypedef(state) {
|
|
328
330
|
var _a, _b;
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
this.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
];
|
|
331
|
+
const results = [this.tokens.name.text];
|
|
332
|
+
if (this.defaultValue) {
|
|
333
|
+
results.push(' = ', ...this.defaultValue.transpile(state));
|
|
334
|
+
}
|
|
335
|
+
if (this.tokens.as) {
|
|
336
|
+
results.push(' as ');
|
|
337
|
+
// TODO: Is this conditional needed? Will typeToken always exist
|
|
338
|
+
// so long as `asToken` exists?
|
|
339
|
+
if (this.typeExpression) {
|
|
340
|
+
results.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getTypedef(state)) !== null && _b !== void 0 ? _b : ['']));
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return results;
|
|
343
344
|
}
|
|
344
345
|
walk(visitor, options) {
|
|
345
346
|
// eslint-disable-next-line no-bitwise
|
|
@@ -348,6 +349,10 @@ class FunctionParameterExpression extends AstNode_1.Expression {
|
|
|
348
349
|
(0, visitors_2.walk)(this, 'typeExpression', visitor, options);
|
|
349
350
|
}
|
|
350
351
|
}
|
|
352
|
+
getLeadingTrivia() {
|
|
353
|
+
var _a;
|
|
354
|
+
return (_a = this.tokens.name.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
355
|
+
}
|
|
351
356
|
}
|
|
352
357
|
exports.FunctionParameterExpression = FunctionParameterExpression;
|
|
353
358
|
class DottedGetExpression extends AstNode_1.Expression {
|
|
@@ -384,10 +389,22 @@ class DottedGetExpression extends AstNode_1.Expression {
|
|
|
384
389
|
getType(options) {
|
|
385
390
|
var _a, _b, _c, _d, _e, _f;
|
|
386
391
|
const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
|
|
387
|
-
|
|
388
|
-
(
|
|
389
|
-
|
|
390
|
-
|
|
392
|
+
let result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text, options);
|
|
393
|
+
if (util_1.default.isClassUsedAsFunction(result, this, options)) {
|
|
394
|
+
// treat this class constructor as a function
|
|
395
|
+
result = FunctionType_1.FunctionType.instance;
|
|
396
|
+
}
|
|
397
|
+
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
|
|
398
|
+
name: (_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text,
|
|
399
|
+
type: result,
|
|
400
|
+
data: options.data,
|
|
401
|
+
range: (_f = (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range,
|
|
402
|
+
kind: this.kind
|
|
403
|
+
}));
|
|
404
|
+
if (result ||
|
|
405
|
+
options.flags & 2 /* SymbolTypeFlag.typetime */ ||
|
|
406
|
+
((0, reflection_1.isPrimitiveType)(objType) || (0, reflection_1.isCallableType)(objType))) {
|
|
407
|
+
// All types should be known at typeTime, or the obj is well known
|
|
391
408
|
return result;
|
|
392
409
|
}
|
|
393
410
|
// It is possible at runtime that a value has been added dynamically to an object, or something
|
|
@@ -397,6 +414,9 @@ class DottedGetExpression extends AstNode_1.Expression {
|
|
|
397
414
|
getName(parseMode) {
|
|
398
415
|
return util_1.default.getAllDottedGetPartsAsString(this, parseMode);
|
|
399
416
|
}
|
|
417
|
+
getLeadingTrivia() {
|
|
418
|
+
return this.obj.getLeadingTrivia();
|
|
419
|
+
}
|
|
400
420
|
}
|
|
401
421
|
exports.DottedGetExpression = DottedGetExpression;
|
|
402
422
|
class XmlAttributeGetExpression extends AstNode_1.Expression {
|
|
@@ -419,6 +439,9 @@ class XmlAttributeGetExpression extends AstNode_1.Expression {
|
|
|
419
439
|
(0, visitors_2.walk)(this, 'obj', visitor, options);
|
|
420
440
|
}
|
|
421
441
|
}
|
|
442
|
+
getLeadingTrivia() {
|
|
443
|
+
return this.obj.getLeadingTrivia();
|
|
444
|
+
}
|
|
422
445
|
}
|
|
423
446
|
exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
|
|
424
447
|
class IndexedGetExpression extends AstNode_1.Expression {
|
|
@@ -463,6 +486,9 @@ class IndexedGetExpression extends AstNode_1.Expression {
|
|
|
463
486
|
}
|
|
464
487
|
return super.getType(options);
|
|
465
488
|
}
|
|
489
|
+
getLeadingTrivia() {
|
|
490
|
+
return this.obj.getLeadingTrivia();
|
|
491
|
+
}
|
|
466
492
|
}
|
|
467
493
|
exports.IndexedGetExpression = IndexedGetExpression;
|
|
468
494
|
class GroupingExpression extends AstNode_1.Expression {
|
|
@@ -494,6 +520,10 @@ class GroupingExpression extends AstNode_1.Expression {
|
|
|
494
520
|
getType(options) {
|
|
495
521
|
return this.expression.getType(options);
|
|
496
522
|
}
|
|
523
|
+
getLeadingTrivia() {
|
|
524
|
+
var _a, _b;
|
|
525
|
+
return (_b = (_a = this.tokens.leftParen) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
526
|
+
}
|
|
497
527
|
}
|
|
498
528
|
exports.GroupingExpression = GroupingExpression;
|
|
499
529
|
class LiteralExpression extends AstNode_1.Expression {
|
|
@@ -527,12 +557,16 @@ class LiteralExpression extends AstNode_1.Expression {
|
|
|
527
557
|
text = this.tokens.value.text;
|
|
528
558
|
}
|
|
529
559
|
return [
|
|
530
|
-
state.
|
|
560
|
+
state.transpileToken(Object.assign(Object.assign({}, this.tokens.value), { text: text }))
|
|
531
561
|
];
|
|
532
562
|
}
|
|
533
563
|
walk(visitor, options) {
|
|
534
564
|
//nothing to walk
|
|
535
565
|
}
|
|
566
|
+
getLeadingTrivia() {
|
|
567
|
+
var _a;
|
|
568
|
+
return (_a = this.tokens.value.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
569
|
+
}
|
|
536
570
|
}
|
|
537
571
|
exports.LiteralExpression = LiteralExpression;
|
|
538
572
|
/**
|
|
@@ -568,6 +602,7 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
|
568
602
|
this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
|
|
569
603
|
}
|
|
570
604
|
transpile(state) {
|
|
605
|
+
var _a;
|
|
571
606
|
let result = [];
|
|
572
607
|
result.push(state.transpileToken(this.tokens.open, '['));
|
|
573
608
|
let hasChildren = this.elements.length > 0;
|
|
@@ -575,32 +610,18 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
|
575
610
|
for (let i = 0; i < this.elements.length; i++) {
|
|
576
611
|
let previousElement = this.elements[i - 1];
|
|
577
612
|
let element = this.elements[i];
|
|
578
|
-
if ((0,
|
|
579
|
-
|
|
580
|
-
if (util_1.default.linesTouch(this.tokens.open, element) || util_1.default.linesTouch(previousElement, element)) {
|
|
581
|
-
result.push(' ');
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
result.push('\n', state.indent());
|
|
585
|
-
}
|
|
586
|
-
state.lineage.unshift(this);
|
|
587
|
-
result.push(element.transpile(state));
|
|
588
|
-
state.lineage.shift();
|
|
613
|
+
if (util_1.default.isLeadingCommentOnSameLine(previousElement !== null && previousElement !== void 0 ? previousElement : this.tokens.open, element)) {
|
|
614
|
+
result.push(' ');
|
|
589
615
|
}
|
|
590
616
|
else {
|
|
591
|
-
result.push('\n');
|
|
592
|
-
result.push(state.indent(), ...element.transpile(state));
|
|
617
|
+
result.push('\n', state.indent());
|
|
593
618
|
}
|
|
619
|
+
result.push(...element.transpile(state));
|
|
594
620
|
}
|
|
595
621
|
state.blockDepth--;
|
|
596
622
|
//add a newline between open and close if there are elements
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
result.push(state.indent());
|
|
600
|
-
}
|
|
601
|
-
if (this.tokens.close) {
|
|
602
|
-
result.push(state.transpileToken(this.tokens.close));
|
|
603
|
-
}
|
|
623
|
+
const lastLocatable = (_a = this.elements[this.elements.length - 1]) !== null && _a !== void 0 ? _a : this.tokens.open;
|
|
624
|
+
result.push(...state.transpileEndBlockToken(lastLocatable, this.tokens.close, ']', hasChildren));
|
|
604
625
|
return result;
|
|
605
626
|
}
|
|
606
627
|
walk(visitor, options) {
|
|
@@ -609,8 +630,12 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
|
609
630
|
}
|
|
610
631
|
}
|
|
611
632
|
getType(options) {
|
|
612
|
-
const innerTypes = this.elements.
|
|
613
|
-
return new
|
|
633
|
+
const innerTypes = this.elements.map(expr => expr.getType(options));
|
|
634
|
+
return new ArrayType_1.ArrayType(...innerTypes);
|
|
635
|
+
}
|
|
636
|
+
getLeadingTrivia() {
|
|
637
|
+
var _a;
|
|
638
|
+
return (_a = this.tokens.open.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
614
639
|
}
|
|
615
640
|
}
|
|
616
641
|
exports.ArrayLiteralExpression = ArrayLiteralExpression;
|
|
@@ -636,6 +661,10 @@ class AAMemberExpression extends AstNode_1.Expression {
|
|
|
636
661
|
getType(options) {
|
|
637
662
|
return this.value.getType(options);
|
|
638
663
|
}
|
|
664
|
+
getLeadingTrivia() {
|
|
665
|
+
var _a;
|
|
666
|
+
return (_a = this.tokens.key.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
667
|
+
}
|
|
639
668
|
}
|
|
640
669
|
exports.AAMemberExpression = AAMemberExpression;
|
|
641
670
|
class AALiteralExpression extends AstNode_1.Expression {
|
|
@@ -650,12 +679,13 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
650
679
|
this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
|
|
651
680
|
}
|
|
652
681
|
transpile(state) {
|
|
682
|
+
var _a;
|
|
653
683
|
let result = [];
|
|
654
684
|
//open curly
|
|
655
685
|
result.push(state.transpileToken(this.tokens.open, '{'));
|
|
656
686
|
let hasChildren = this.elements.length > 0;
|
|
657
687
|
//add newline if the object has children and the first child isn't a comment starting on the same line as opening curly
|
|
658
|
-
if (hasChildren &&
|
|
688
|
+
if (hasChildren && !util_1.default.isLeadingCommentOnSameLine(this.tokens.open, this.elements[0])) {
|
|
659
689
|
result.push('\n');
|
|
660
690
|
}
|
|
661
691
|
state.blockDepth++;
|
|
@@ -664,41 +694,29 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
664
694
|
let previousElement = this.elements[i - 1];
|
|
665
695
|
let nextElement = this.elements[i + 1];
|
|
666
696
|
//don't indent if comment is same-line
|
|
667
|
-
if ((
|
|
668
|
-
|
|
697
|
+
if (util_1.default.isLeadingCommentOnSameLine(this.tokens.open, element) ||
|
|
698
|
+
util_1.default.isLeadingCommentOnSameLine(previousElement, element)) {
|
|
669
699
|
result.push(' ');
|
|
670
|
-
//indent line
|
|
671
700
|
}
|
|
672
701
|
else {
|
|
702
|
+
//indent line
|
|
673
703
|
result.push(state.indent());
|
|
674
704
|
}
|
|
675
|
-
//
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
result.push(state.transpileToken(element.tokens.key));
|
|
682
|
-
//colon
|
|
683
|
-
result.push(state.transpileToken(element.tokens.colon, ':'), ' ');
|
|
684
|
-
//value
|
|
685
|
-
result.push(...element.value.transpile(state));
|
|
686
|
-
}
|
|
705
|
+
//key
|
|
706
|
+
result.push(state.transpileToken(element.tokens.key));
|
|
707
|
+
//colon
|
|
708
|
+
result.push(state.transpileToken(element.tokens.colon, ':'), ' ');
|
|
709
|
+
//value
|
|
710
|
+
result.push(...element.value.transpile(state));
|
|
687
711
|
//if next element is a same-line comment, skip the newline
|
|
688
|
-
if (nextElement && (
|
|
712
|
+
if (nextElement && !util_1.default.isLeadingCommentOnSameLine(element, nextElement)) {
|
|
689
713
|
//add a newline between statements
|
|
690
|
-
}
|
|
691
|
-
else {
|
|
692
714
|
result.push('\n');
|
|
693
715
|
}
|
|
694
716
|
}
|
|
695
717
|
state.blockDepth--;
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
result.push(state.indent());
|
|
699
|
-
}
|
|
700
|
-
//close curly
|
|
701
|
-
result.push(state.transpileToken(this.tokens.close, '}'));
|
|
718
|
+
const lastElement = (_a = this.elements[this.elements.length - 1]) !== null && _a !== void 0 ? _a : this.tokens.open;
|
|
719
|
+
result.push(...state.transpileEndBlockToken(lastElement, this.tokens.close, '}', hasChildren));
|
|
702
720
|
return result;
|
|
703
721
|
}
|
|
704
722
|
walk(visitor, options) {
|
|
@@ -708,13 +726,18 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
708
726
|
}
|
|
709
727
|
getType(options) {
|
|
710
728
|
const resultType = new AssociativeArrayType_1.AssociativeArrayType();
|
|
729
|
+
resultType.addBuiltInInterfaces();
|
|
711
730
|
for (const element of this.elements) {
|
|
712
731
|
if ((0, reflection_1.isAAMemberExpression)(element)) {
|
|
713
|
-
resultType.addMember(element.tokens.key.text, { definingNode: element }, element.getType(options),
|
|
732
|
+
resultType.addMember(element.tokens.key.text, { definingNode: element }, element.getType(options), 1 /* SymbolTypeFlag.runtime */);
|
|
714
733
|
}
|
|
715
734
|
}
|
|
716
735
|
return resultType;
|
|
717
736
|
}
|
|
737
|
+
getLeadingTrivia() {
|
|
738
|
+
var _a;
|
|
739
|
+
return (_a = this.tokens.open.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
740
|
+
}
|
|
718
741
|
}
|
|
719
742
|
exports.AALiteralExpression = AALiteralExpression;
|
|
720
743
|
class UnaryExpression extends AstNode_1.Expression {
|
|
@@ -752,6 +775,10 @@ class UnaryExpression extends AstNode_1.Expression {
|
|
|
752
775
|
getType(options) {
|
|
753
776
|
return util_1.default.unaryOperatorResultType(this.tokens.operator, this.right.getType(options));
|
|
754
777
|
}
|
|
778
|
+
getLeadingTrivia() {
|
|
779
|
+
var _a;
|
|
780
|
+
return (_a = this.tokens.operator.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
781
|
+
}
|
|
755
782
|
}
|
|
756
783
|
exports.UnaryExpression = UnaryExpression;
|
|
757
784
|
class VariableExpression extends AstNode_1.Expression {
|
|
@@ -771,7 +798,7 @@ class VariableExpression extends AstNode_1.Expression {
|
|
|
771
798
|
let result = [];
|
|
772
799
|
const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
|
|
773
800
|
//if the callee is the name of a known namespace function
|
|
774
|
-
if (state.file.calleeIsKnownNamespaceFunction(this, namespace
|
|
801
|
+
if (namespace && state.file.calleeIsKnownNamespaceFunction(this, namespace.getName(Parser_1.ParseMode.BrighterScript))) {
|
|
775
802
|
result.push(state.sourceNode(this, [
|
|
776
803
|
namespace.getName(Parser_1.ParseMode.BrightScript),
|
|
777
804
|
'_',
|
|
@@ -794,10 +821,17 @@ class VariableExpression extends AstNode_1.Expression {
|
|
|
794
821
|
if (!resultType) {
|
|
795
822
|
const symbolTable = this.getSymbolTable();
|
|
796
823
|
resultType = symbolTable === null || symbolTable === void 0 ? void 0 : symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
|
|
824
|
+
if (util_1.default.isClassUsedAsFunction(resultType, this, options)) {
|
|
825
|
+
resultType = FunctionType_1.FunctionType.instance;
|
|
826
|
+
}
|
|
797
827
|
}
|
|
798
|
-
(_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry(nameKey, resultType, options.data, this.range));
|
|
828
|
+
(_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 }));
|
|
799
829
|
return resultType;
|
|
800
830
|
}
|
|
831
|
+
getLeadingTrivia() {
|
|
832
|
+
var _a;
|
|
833
|
+
return (_a = this.tokens.name.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
834
|
+
}
|
|
801
835
|
}
|
|
802
836
|
exports.VariableExpression = VariableExpression;
|
|
803
837
|
class SourceLiteralExpression extends AstNode_1.Expression {
|
|
@@ -828,7 +862,7 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
828
862
|
return index;
|
|
829
863
|
}
|
|
830
864
|
getFunctionName(state, parseMode) {
|
|
831
|
-
let func =
|
|
865
|
+
let func = this.findAncestor(reflection_1.isFunctionExpression);
|
|
832
866
|
let nameParts = [];
|
|
833
867
|
let parentFunction;
|
|
834
868
|
while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
|
|
@@ -840,6 +874,19 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
840
874
|
nameParts.unshift(func.functionStatement.getName(parseMode));
|
|
841
875
|
return nameParts.join('$');
|
|
842
876
|
}
|
|
877
|
+
/**
|
|
878
|
+
* Get the line number from our token or from the closest ancestor that has a range
|
|
879
|
+
*/
|
|
880
|
+
getClosestLineNumber() {
|
|
881
|
+
let node = this;
|
|
882
|
+
while (node) {
|
|
883
|
+
if (node.range) {
|
|
884
|
+
return node.range.start.line + 1;
|
|
885
|
+
}
|
|
886
|
+
node = node.parent;
|
|
887
|
+
}
|
|
888
|
+
return -1;
|
|
889
|
+
}
|
|
843
890
|
transpile(state) {
|
|
844
891
|
let text;
|
|
845
892
|
switch (this.tokens.value.kind) {
|
|
@@ -848,7 +895,8 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
848
895
|
text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
|
|
849
896
|
break;
|
|
850
897
|
case TokenKind_1.TokenKind.SourceLineNumLiteral:
|
|
851
|
-
|
|
898
|
+
//TODO find first parent that has range, or default to -1
|
|
899
|
+
text = `${this.getClosestLineNumber()}`;
|
|
852
900
|
break;
|
|
853
901
|
case TokenKind_1.TokenKind.FunctionNameLiteral:
|
|
854
902
|
text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
|
|
@@ -858,7 +906,8 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
858
906
|
break;
|
|
859
907
|
case TokenKind_1.TokenKind.SourceLocationLiteral:
|
|
860
908
|
const locationUrl = fileUrl(state.srcPath);
|
|
861
|
-
|
|
909
|
+
//TODO find first parent that has range, or default to -1
|
|
910
|
+
text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.getClosestLineNumber()}"`;
|
|
862
911
|
break;
|
|
863
912
|
case TokenKind_1.TokenKind.PkgPathLiteral:
|
|
864
913
|
text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
|
|
@@ -879,6 +928,10 @@ class SourceLiteralExpression extends AstNode_1.Expression {
|
|
|
879
928
|
walk(visitor, options) {
|
|
880
929
|
//nothing to walk
|
|
881
930
|
}
|
|
931
|
+
getLeadingTrivia() {
|
|
932
|
+
var _a;
|
|
933
|
+
return (_a = this.tokens.value.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
934
|
+
}
|
|
882
935
|
}
|
|
883
936
|
exports.SourceLiteralExpression = SourceLiteralExpression;
|
|
884
937
|
/**
|
|
@@ -918,7 +971,19 @@ class NewExpression extends AstNode_1.Expression {
|
|
|
918
971
|
}
|
|
919
972
|
}
|
|
920
973
|
getType(options) {
|
|
921
|
-
|
|
974
|
+
const result = this.call.getType(options);
|
|
975
|
+
if (options.typeChain) {
|
|
976
|
+
// modify last typechain entry to show it is a new ...()
|
|
977
|
+
const lastEntry = options.typeChain[options.typeChain.length - 1];
|
|
978
|
+
if (lastEntry) {
|
|
979
|
+
lastEntry.kind = this.kind;
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return result;
|
|
983
|
+
}
|
|
984
|
+
getLeadingTrivia() {
|
|
985
|
+
var _a;
|
|
986
|
+
return (_a = this.tokens.new.leadingTrivia) !== null && _a !== void 0 ? _a : [];
|
|
922
987
|
}
|
|
923
988
|
}
|
|
924
989
|
exports.NewExpression = NewExpression;
|
|
@@ -972,11 +1037,17 @@ class CallfuncExpression extends AstNode_1.Expression {
|
|
|
972
1037
|
let result = DynamicType_1.DynamicType.instance;
|
|
973
1038
|
// a little hacky here with checking options.ignoreCall because callFuncExpression has the method name
|
|
974
1039
|
// It's nicer for CallExpression, because it's a call on any expression.
|
|
975
|
-
const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags:
|
|
1040
|
+
const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */ }));
|
|
976
1041
|
if ((0, reflection_1.isComponentType)(calleeType) || (0, reflection_1.isReferenceType)(calleeType)) {
|
|
977
1042
|
const funcType = (_b = (_a = calleeType).getCallFuncType) === null || _b === void 0 ? void 0 : _b.call(_a, this.tokens.methodName.text, options);
|
|
978
1043
|
if (funcType) {
|
|
979
|
-
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry(
|
|
1044
|
+
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
|
|
1045
|
+
name: this.tokens.methodName.text,
|
|
1046
|
+
type: funcType,
|
|
1047
|
+
data: options.data, range: this.tokens.methodName.range,
|
|
1048
|
+
separatorToken: (0, creators_1.createToken)(TokenKind_1.TokenKind.Callfunc),
|
|
1049
|
+
kind: this.kind
|
|
1050
|
+
}));
|
|
980
1051
|
if (options.ignoreCall) {
|
|
981
1052
|
result = funcType;
|
|
982
1053
|
}
|
|
@@ -994,6 +1065,9 @@ class CallfuncExpression extends AstNode_1.Expression {
|
|
|
994
1065
|
}
|
|
995
1066
|
return result;
|
|
996
1067
|
}
|
|
1068
|
+
getLeadingTrivia() {
|
|
1069
|
+
return this.callee.getLeadingTrivia();
|
|
1070
|
+
}
|
|
997
1071
|
}
|
|
998
1072
|
exports.CallfuncExpression = CallfuncExpression;
|
|
999
1073
|
/**
|
|
@@ -1169,8 +1243,8 @@ class AnnotationExpression extends AstNode_1.Expression {
|
|
|
1169
1243
|
return this.call.args.map(e => expressionToValue(e, strict));
|
|
1170
1244
|
}
|
|
1171
1245
|
getLeadingTrivia() {
|
|
1172
|
-
var _a;
|
|
1173
|
-
return (_a = this.tokens.at) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
|
|
1246
|
+
var _a, _b;
|
|
1247
|
+
return (_b = (_a = this.tokens.at) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
1174
1248
|
}
|
|
1175
1249
|
transpile(state) {
|
|
1176
1250
|
return [];
|
|
@@ -1204,8 +1278,9 @@ class TernaryExpression extends AstNode_1.Expression {
|
|
|
1204
1278
|
transpile(state) {
|
|
1205
1279
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
1206
1280
|
let result = [];
|
|
1207
|
-
|
|
1208
|
-
let
|
|
1281
|
+
const file = state.file;
|
|
1282
|
+
let consequentInfo = util_1.default.getExpressionInfo(this.consequent, file);
|
|
1283
|
+
let alternateInfo = util_1.default.getExpressionInfo(this.alternate, file);
|
|
1209
1284
|
//get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
|
|
1210
1285
|
let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
|
|
1211
1286
|
let mutatingExpressions = [
|
|
@@ -1216,9 +1291,9 @@ class TernaryExpression extends AstNode_1.Expression {
|
|
|
1216
1291
|
result.push(state.sourceNode(this.tokens.questionMark,
|
|
1217
1292
|
//write all the scope variables as parameters.
|
|
1218
1293
|
//TODO handle when there are more than 31 parameters
|
|
1219
|
-
`(function(__bsCondition,
|
|
1294
|
+
`(function(${['__bsCondition', ...allUniqueVarNames].join(', ')})`), state.newline,
|
|
1220
1295
|
//double indent so our `end function` line is still indented one at the end
|
|
1221
|
-
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,
|
|
1296
|
+
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(', ')})`));
|
|
1222
1297
|
state.blockDepth--;
|
|
1223
1298
|
}
|
|
1224
1299
|
else {
|
|
@@ -1233,6 +1308,9 @@ class TernaryExpression extends AstNode_1.Expression {
|
|
|
1233
1308
|
(0, visitors_2.walk)(this, 'alternate', visitor, options);
|
|
1234
1309
|
}
|
|
1235
1310
|
}
|
|
1311
|
+
getLeadingTrivia() {
|
|
1312
|
+
return this.test.getLeadingTrivia();
|
|
1313
|
+
}
|
|
1236
1314
|
}
|
|
1237
1315
|
exports.TernaryExpression = TernaryExpression;
|
|
1238
1316
|
class NullCoalescingExpression extends AstNode_1.Expression {
|
|
@@ -1248,8 +1326,8 @@ class NullCoalescingExpression extends AstNode_1.Expression {
|
|
|
1248
1326
|
}
|
|
1249
1327
|
transpile(state) {
|
|
1250
1328
|
let result = [];
|
|
1251
|
-
let consequentInfo = util_1.default.getExpressionInfo(this.consequent);
|
|
1252
|
-
let alternateInfo = util_1.default.getExpressionInfo(this.alternate);
|
|
1329
|
+
let consequentInfo = util_1.default.getExpressionInfo(this.consequent, state.file);
|
|
1330
|
+
let alternateInfo = util_1.default.getExpressionInfo(this.alternate, state.file);
|
|
1253
1331
|
//get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
|
|
1254
1332
|
let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
|
|
1255
1333
|
let hasMutatingExpression = [
|
|
@@ -1278,6 +1356,9 @@ class NullCoalescingExpression extends AstNode_1.Expression {
|
|
|
1278
1356
|
(0, visitors_2.walk)(this, 'alternate', visitor, options);
|
|
1279
1357
|
}
|
|
1280
1358
|
}
|
|
1359
|
+
getLeadingTrivia() {
|
|
1360
|
+
return this.consequent.getLeadingTrivia();
|
|
1361
|
+
}
|
|
1281
1362
|
}
|
|
1282
1363
|
exports.NullCoalescingExpression = NullCoalescingExpression;
|
|
1283
1364
|
class RegexLiteralExpression extends AstNode_1.Expression {
|
|
@@ -1319,6 +1400,10 @@ class RegexLiteralExpression extends AstNode_1.Expression {
|
|
|
1319
1400
|
walk(visitor, options) {
|
|
1320
1401
|
//nothing to walk
|
|
1321
1402
|
}
|
|
1403
|
+
getLeadingTrivia() {
|
|
1404
|
+
var _a, _b;
|
|
1405
|
+
return (_b = (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
|
|
1406
|
+
}
|
|
1322
1407
|
}
|
|
1323
1408
|
exports.RegexLiteralExpression = RegexLiteralExpression;
|
|
1324
1409
|
function expressionToValue(expr, strict) {
|
|
@@ -1340,14 +1425,11 @@ function expressionToValue(expr, strict) {
|
|
|
1340
1425
|
}
|
|
1341
1426
|
if ((0, reflection_1.isArrayLiteralExpression)(expr)) {
|
|
1342
1427
|
return expr.elements
|
|
1343
|
-
.filter(e => !(0, reflection_1.isCommentStatement)(e))
|
|
1344
1428
|
.map(e => expressionToValue(e, strict));
|
|
1345
1429
|
}
|
|
1346
1430
|
if ((0, reflection_1.isAALiteralExpression)(expr)) {
|
|
1347
1431
|
return expr.elements.reduce((acc, e) => {
|
|
1348
|
-
|
|
1349
|
-
acc[e.tokens.key.text] = expressionToValue(e.value, strict);
|
|
1350
|
-
}
|
|
1432
|
+
acc[e.tokens.key.text] = expressionToValue(e.value, strict);
|
|
1351
1433
|
return acc;
|
|
1352
1434
|
}, {});
|
|
1353
1435
|
}
|
|
@@ -1370,7 +1452,7 @@ class TypeExpression extends AstNode_1.Expression {
|
|
|
1370
1452
|
this.range = (_a = this.expression) === null || _a === void 0 ? void 0 : _a.range;
|
|
1371
1453
|
}
|
|
1372
1454
|
transpile(state) {
|
|
1373
|
-
return [this.getType({ flags:
|
|
1455
|
+
return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
|
|
1374
1456
|
}
|
|
1375
1457
|
walk(visitor, options) {
|
|
1376
1458
|
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
@@ -1378,7 +1460,7 @@ class TypeExpression extends AstNode_1.Expression {
|
|
|
1378
1460
|
}
|
|
1379
1461
|
}
|
|
1380
1462
|
getType(options) {
|
|
1381
|
-
return this.expression.getType(Object.assign(Object.assign({}, options), { flags:
|
|
1463
|
+
return this.expression.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */ }));
|
|
1382
1464
|
}
|
|
1383
1465
|
getTypedef(state) {
|
|
1384
1466
|
// TypeDefs should pass through any valid type names
|
|
@@ -1415,7 +1497,15 @@ class TypeCastExpression extends AstNode_1.Expression {
|
|
|
1415
1497
|
}
|
|
1416
1498
|
}
|
|
1417
1499
|
getType(options) {
|
|
1418
|
-
|
|
1500
|
+
const result = this.typeExpression.getType(options);
|
|
1501
|
+
if (options.typeChain) {
|
|
1502
|
+
// modify last typechain entry to show it is a typecast
|
|
1503
|
+
const lastEntry = options.typeChain[options.typeChain.length - 1];
|
|
1504
|
+
if (lastEntry) {
|
|
1505
|
+
lastEntry.kind = this.kind;
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
return result;
|
|
1419
1509
|
}
|
|
1420
1510
|
}
|
|
1421
1511
|
exports.TypeCastExpression = TypeCastExpression;
|
|
@@ -1431,7 +1521,7 @@ class TypedArrayExpression extends AstNode_1.Expression {
|
|
|
1431
1521
|
this.range = util_1.default.createBoundingRange(this.innerType, this.tokens.leftBracket, this.tokens.rightBracket);
|
|
1432
1522
|
}
|
|
1433
1523
|
transpile(state) {
|
|
1434
|
-
return [this.getType({ flags:
|
|
1524
|
+
return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
|
|
1435
1525
|
}
|
|
1436
1526
|
walk(visitor, options) {
|
|
1437
1527
|
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
@@ -1439,7 +1529,7 @@ class TypedArrayExpression extends AstNode_1.Expression {
|
|
|
1439
1529
|
}
|
|
1440
1530
|
}
|
|
1441
1531
|
getType(options) {
|
|
1442
|
-
return new
|
|
1532
|
+
return new ArrayType_1.ArrayType(this.innerType.getType(options));
|
|
1443
1533
|
}
|
|
1444
1534
|
}
|
|
1445
1535
|
exports.TypedArrayExpression = TypedArrayExpression;
|