brighterscript 1.0.0-alpha.15 → 1.0.0-alpha.18
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 +83 -0
- package/README.md +28 -9
- package/dist/DependencyGraph.js +5 -4
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +16 -1
- package/dist/DiagnosticMessages.js +15 -0
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/Logger.js +5 -5
- package/dist/Logger.js.map +1 -1
- package/dist/Program.d.ts +2 -2
- package/dist/Program.js +5 -3
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +1 -1
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +58 -8
- package/dist/Scope.js +142 -23
- package/dist/Scope.js.map +1 -1
- package/dist/XmlScope.js +1 -1
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/creators.d.ts +10 -6
- package/dist/astUtils/creators.js +93 -12
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +10 -0
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +8 -3
- package/dist/astUtils/reflection.js +18 -2
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +15 -4
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +4 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +2 -0
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -2
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +7 -3
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -1
- package/dist/{types/FunctionType.spec.d.ts → bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts} +0 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
- package/dist/diagnosticUtils.js +3 -3
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +12 -14
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +3 -3
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +2 -2
- package/dist/files/BrsFile.js +99 -63
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +187 -67
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.js +3 -3
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/globalCallables.js +79 -79
- package/dist/globalCallables.js.map +1 -1
- package/dist/interfaces.d.ts +43 -4
- package/dist/parser/Expression.d.ts +91 -22
- package/dist/parser/Expression.js +191 -57
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +6 -6
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +3 -6
- package/dist/parser/Parser.js +166 -155
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +61 -6
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +2 -2
- package/dist/parser/SGTypes.js +2 -2
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +85 -57
- package/dist/parser/Statement.js +228 -173
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/tests/statement/For.spec.d.ts +1 -0
- package/dist/parser/tests/statement/For.spec.js +46 -0
- package/dist/parser/tests/statement/For.spec.js.map +1 -0
- package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ForEach.spec.js +37 -0
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +181 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +7 -5
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/types/ArrayType.js +4 -1
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +3 -1
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/BooleanType.d.ts +4 -2
- package/dist/types/BooleanType.js +7 -2
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +3 -1
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +1 -0
- package/dist/types/BscType.js +16 -1
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/CustomType.js +10 -0
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.d.ts +2 -0
- package/dist/types/DoubleType.js +7 -2
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +3 -1
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +2 -0
- package/dist/types/DynamicType.js +5 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/FloatType.d.ts +3 -1
- package/dist/types/FloatType.js +7 -2
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +2 -0
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +3 -21
- package/dist/types/FunctionType.js +8 -65
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/IntegerType.d.ts +3 -1
- package/dist/types/IntegerType.js +7 -2
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +3 -1
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +13 -10
- package/dist/types/InterfaceType.js +33 -29
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +36 -16
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/InvalidType.d.ts +4 -2
- package/dist/types/InvalidType.js +7 -2
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +2 -0
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LazyType.js +4 -0
- package/dist/types/LazyType.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +3 -1
- package/dist/types/LongIntegerType.js +7 -2
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +2 -0
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/ObjectType.d.ts +2 -1
- package/dist/types/ObjectType.js +4 -2
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/StringType.d.ts +4 -2
- package/dist/types/StringType.js +7 -2
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +2 -0
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/TypedFunctionType.d.ts +28 -0
- package/dist/types/TypedFunctionType.js +88 -0
- package/dist/types/TypedFunctionType.js.map +1 -0
- package/dist/types/TypedFunctionType.spec.d.ts +1 -0
- package/dist/types/TypedFunctionType.spec.js +37 -0
- package/dist/types/TypedFunctionType.spec.js.map +1 -0
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.d.ts +4 -2
- package/dist/types/VoidType.js +5 -1
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/helpers.js +7 -2
- package/dist/types/helpers.js.map +1 -1
- package/dist/util.d.ts +2 -2
- package/dist/util.js +39 -46
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +14 -1
- package/dist/validators/ClassValidator.js +129 -82
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +2 -3
- package/dist/types/FunctionType.spec.js +0 -29
- package/dist/types/FunctionType.spec.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = exports.Expression = void 0;
|
|
3
|
+
exports.ArrayTypeExpression = exports.TypeExpression = exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = exports.Expression = void 0;
|
|
4
4
|
const TokenKind_1 = require("../lexer/TokenKind");
|
|
5
5
|
const util_1 = require("../util");
|
|
6
6
|
const Parser_1 = require("./Parser");
|
|
@@ -10,8 +10,9 @@ const reflection_1 = require("../astUtils/reflection");
|
|
|
10
10
|
const VoidType_1 = require("../types/VoidType");
|
|
11
11
|
const DynamicType_1 = require("../types/DynamicType");
|
|
12
12
|
const SymbolTable_1 = require("../SymbolTable");
|
|
13
|
-
const
|
|
13
|
+
const TypedFunctionType_1 = require("../types/TypedFunctionType");
|
|
14
14
|
const ObjectType_1 = require("../types/ObjectType");
|
|
15
|
+
const ArrayType_1 = require("../types/ArrayType");
|
|
15
16
|
/** A BrightScript expression */
|
|
16
17
|
class Expression {
|
|
17
18
|
constructor() {
|
|
@@ -28,7 +29,7 @@ class BinaryExpression extends Expression {
|
|
|
28
29
|
this.left = left;
|
|
29
30
|
this.operator = operator;
|
|
30
31
|
this.right = right;
|
|
31
|
-
this.range = util_1.default.
|
|
32
|
+
this.range = util_1.default.createBoundingRange(this.left, this.right);
|
|
32
33
|
}
|
|
33
34
|
transpile(state) {
|
|
34
35
|
return [
|
|
@@ -59,7 +60,7 @@ class CallExpression extends Expression {
|
|
|
59
60
|
this.closingParen = closingParen;
|
|
60
61
|
this.args = args;
|
|
61
62
|
this.namespaceName = namespaceName;
|
|
62
|
-
this.range = util_1.default.
|
|
63
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.closingParen);
|
|
63
64
|
}
|
|
64
65
|
transpile(state, nameOverride) {
|
|
65
66
|
let result = [];
|
|
@@ -94,7 +95,7 @@ class CallExpression extends Expression {
|
|
|
94
95
|
exports.CallExpression = CallExpression;
|
|
95
96
|
CallExpression.MaximumArguments = util_1.MAX_PARAM_COUNT;
|
|
96
97
|
class FunctionExpression extends Expression {
|
|
97
|
-
constructor(parameters, body, functionType, end, leftParen, rightParen, asToken,
|
|
98
|
+
constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnType,
|
|
98
99
|
/**
|
|
99
100
|
* If this function is enclosed within another function, this will reference that parent function
|
|
100
101
|
*/
|
|
@@ -107,7 +108,7 @@ class FunctionExpression extends Expression {
|
|
|
107
108
|
this.leftParen = leftParen;
|
|
108
109
|
this.rightParen = rightParen;
|
|
109
110
|
this.asToken = asToken;
|
|
110
|
-
this.
|
|
111
|
+
this.returnType = returnType;
|
|
111
112
|
this.parentFunction = parentFunction;
|
|
112
113
|
this.namespaceName = namespaceName;
|
|
113
114
|
this.parentSymbolTable = parentSymbolTable;
|
|
@@ -121,27 +122,46 @@ class FunctionExpression extends Expression {
|
|
|
121
122
|
* A list of all child functions declared directly within this function
|
|
122
123
|
*/
|
|
123
124
|
this.childFunctionExpressions = [];
|
|
124
|
-
if (this.
|
|
125
|
-
this.
|
|
125
|
+
if (this.returnType) {
|
|
126
|
+
this._returnType = this.returnType.type;
|
|
126
127
|
}
|
|
127
128
|
else if (this.functionType.text.toLowerCase() === 'sub') {
|
|
128
|
-
this.
|
|
129
|
+
this._returnType = new VoidType_1.VoidType();
|
|
129
130
|
}
|
|
130
131
|
else {
|
|
131
|
-
this.
|
|
132
|
+
this._returnType = new DynamicType_1.DynamicType();
|
|
132
133
|
}
|
|
133
134
|
this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
|
|
134
135
|
for (let param of parameters) {
|
|
135
|
-
this.symbolTable.addSymbol(param.name.text, param.name.range, param.
|
|
136
|
+
this.symbolTable.addSymbol(param.name.text, param.name.range, param.getType());
|
|
136
137
|
}
|
|
137
138
|
}
|
|
139
|
+
get range() {
|
|
140
|
+
return this.cacheRange();
|
|
141
|
+
}
|
|
138
142
|
/**
|
|
139
|
-
* The range of the function
|
|
140
|
-
* and ending with the last n' in 'end function' or 'b' in 'end sub'
|
|
143
|
+
* The range of the function
|
|
141
144
|
*/
|
|
142
|
-
|
|
143
|
-
var _a
|
|
144
|
-
|
|
145
|
+
cacheRange() {
|
|
146
|
+
var _a;
|
|
147
|
+
if (!this._range) {
|
|
148
|
+
this._range = util_1.default.createBoundingRange(this.functionType, this.leftParen, ...((_a = this.parameters) !== null && _a !== void 0 ? _a : []), this.rightParen, this.asToken, this.returnType, this.body, this.end);
|
|
149
|
+
}
|
|
150
|
+
return this._range;
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The type this function returns
|
|
154
|
+
*/
|
|
155
|
+
getReturnType() {
|
|
156
|
+
return this._returnType;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The range of the function declaration, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
|
|
160
|
+
* and ending with the last character in the returnTypeToken, or the 's' in 'as', or the rightParen
|
|
161
|
+
*/
|
|
162
|
+
get functionDeclarationRange() {
|
|
163
|
+
var _a;
|
|
164
|
+
return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...((_a = this.parameters) !== null && _a !== void 0 ? _a : []), this.rightParen, this.asToken, this.returnType);
|
|
145
165
|
}
|
|
146
166
|
transpile(state, name, includeBody = true) {
|
|
147
167
|
let results = [];
|
|
@@ -171,7 +191,7 @@ class FunctionExpression extends Expression {
|
|
|
171
191
|
//as
|
|
172
192
|
state.transpileToken(this.asToken), ' ',
|
|
173
193
|
//return type
|
|
174
|
-
state.sourceNode(this.
|
|
194
|
+
state.sourceNode(this.returnType, this.getReturnType().toTypeString(state.typeContext)));
|
|
175
195
|
}
|
|
176
196
|
if (includeBody) {
|
|
177
197
|
state.lineage.unshift(this);
|
|
@@ -179,9 +199,11 @@ class FunctionExpression extends Expression {
|
|
|
179
199
|
state.lineage.shift();
|
|
180
200
|
results.push(...body);
|
|
181
201
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
202
|
+
if (this.end) {
|
|
203
|
+
results.push('\n');
|
|
204
|
+
//'end sub'|'end function'
|
|
205
|
+
results.push(state.indent(), state.transpileToken(this.end));
|
|
206
|
+
}
|
|
185
207
|
return results;
|
|
186
208
|
}
|
|
187
209
|
getTypedef(state, name) {
|
|
@@ -194,36 +216,35 @@ class FunctionExpression extends Expression {
|
|
|
194
216
|
}
|
|
195
217
|
//This is the core of full-program walking...it allows us to step into sub functions
|
|
196
218
|
if (options.walkMode & visitors_1.InternalWalkMode.recurseChildFunctions) {
|
|
219
|
+
(0, visitors_1.walk)(this, 'returnType', visitor, options);
|
|
197
220
|
(0, visitors_1.walk)(this, 'body', visitor, options);
|
|
198
221
|
}
|
|
199
222
|
}
|
|
200
223
|
}
|
|
201
224
|
getFunctionType() {
|
|
202
|
-
let functionType = new
|
|
225
|
+
let functionType = new TypedFunctionType_1.TypedFunctionType(this.getReturnType());
|
|
203
226
|
functionType.isSub = this.functionType.text === 'sub';
|
|
204
227
|
for (let param of this.parameters) {
|
|
205
|
-
functionType.addParameter(param.name.text, param.
|
|
228
|
+
functionType.addParameter(param.name.text, param.getType(), param.isOptional);
|
|
206
229
|
}
|
|
207
230
|
return functionType;
|
|
208
231
|
}
|
|
209
232
|
}
|
|
210
233
|
exports.FunctionExpression = FunctionExpression;
|
|
211
234
|
class FunctionParameterExpression extends Expression {
|
|
212
|
-
constructor(name,
|
|
235
|
+
constructor(name, typeInContext, equalsToken, defaultValue, asToken, type, namespaceName) {
|
|
213
236
|
super();
|
|
214
237
|
this.name = name;
|
|
215
|
-
this.
|
|
238
|
+
this.typeInContext = typeInContext;
|
|
216
239
|
this.equalsToken = equalsToken;
|
|
217
240
|
this.defaultValue = defaultValue;
|
|
218
241
|
this.asToken = asToken;
|
|
219
|
-
this.
|
|
242
|
+
this.type = type;
|
|
220
243
|
this.namespaceName = namespaceName;
|
|
244
|
+
this.range = util_1.default.createBoundingRange(this.name, this.equalsToken, this.defaultValue, this.asToken, this.type);
|
|
221
245
|
}
|
|
222
|
-
|
|
223
|
-
return
|
|
224
|
-
start: this.name.range.start,
|
|
225
|
-
end: this.typeToken ? this.typeToken.range.end : this.name.range.end
|
|
226
|
-
};
|
|
246
|
+
getType() {
|
|
247
|
+
return this.typeInContext;
|
|
227
248
|
}
|
|
228
249
|
transpile(state) {
|
|
229
250
|
let result = [
|
|
@@ -240,7 +261,7 @@ class FunctionParameterExpression extends Expression {
|
|
|
240
261
|
result.push(' ');
|
|
241
262
|
result.push(state.transpileToken(this.asToken));
|
|
242
263
|
result.push(' ');
|
|
243
|
-
result.push(state.sourceNode(this.
|
|
264
|
+
result.push(state.sourceNode(this.type, this.getType().toTypeString(state.typeContext)));
|
|
244
265
|
}
|
|
245
266
|
return result;
|
|
246
267
|
}
|
|
@@ -248,6 +269,7 @@ class FunctionParameterExpression extends Expression {
|
|
|
248
269
|
// eslint-disable-next-line no-bitwise
|
|
249
270
|
if (this.defaultValue && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
250
271
|
(0, visitors_1.walk)(this, 'defaultValue', visitor, options);
|
|
272
|
+
(0, visitors_1.walk)(this, 'type', visitor, options);
|
|
251
273
|
}
|
|
252
274
|
}
|
|
253
275
|
get isOptional() {
|
|
@@ -304,7 +326,7 @@ class DottedGetExpression extends Expression {
|
|
|
304
326
|
this.obj = obj;
|
|
305
327
|
this.name = name;
|
|
306
328
|
this.dot = dot;
|
|
307
|
-
this.range = util_1.default.
|
|
329
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
|
|
308
330
|
}
|
|
309
331
|
transpile(state) {
|
|
310
332
|
//if the callee starts with a namespace name, transpile the name
|
|
@@ -332,7 +354,7 @@ class XmlAttributeGetExpression extends Expression {
|
|
|
332
354
|
this.obj = obj;
|
|
333
355
|
this.name = name;
|
|
334
356
|
this.at = at;
|
|
335
|
-
this.range = util_1.default.
|
|
357
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
|
|
336
358
|
}
|
|
337
359
|
transpile(state) {
|
|
338
360
|
return [
|
|
@@ -355,7 +377,7 @@ class IndexedGetExpression extends Expression {
|
|
|
355
377
|
this.index = index;
|
|
356
378
|
this.openingSquare = openingSquare;
|
|
357
379
|
this.closingSquare = closingSquare;
|
|
358
|
-
this.range = util_1.default.
|
|
380
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.index, this.closingSquare);
|
|
359
381
|
}
|
|
360
382
|
transpile(state) {
|
|
361
383
|
return [
|
|
@@ -378,7 +400,7 @@ class GroupingExpression extends Expression {
|
|
|
378
400
|
super();
|
|
379
401
|
this.tokens = tokens;
|
|
380
402
|
this.expression = expression;
|
|
381
|
-
this.range = util_1.default.
|
|
403
|
+
this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
|
|
382
404
|
}
|
|
383
405
|
transpile(state) {
|
|
384
406
|
return [
|
|
@@ -398,11 +420,9 @@ class LiteralExpression extends Expression {
|
|
|
398
420
|
constructor(token) {
|
|
399
421
|
super();
|
|
400
422
|
this.token = token;
|
|
423
|
+
this.range = this.token.range;
|
|
401
424
|
this.type = util_1.default.tokenToBscType(token);
|
|
402
425
|
}
|
|
403
|
-
get range() {
|
|
404
|
-
return this.token.range;
|
|
405
|
-
}
|
|
406
426
|
transpile(state) {
|
|
407
427
|
let text;
|
|
408
428
|
if (this.token.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
|
|
@@ -450,12 +470,13 @@ class EscapedCharCodeLiteralExpression extends Expression {
|
|
|
450
470
|
exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
|
|
451
471
|
class ArrayLiteralExpression extends Expression {
|
|
452
472
|
constructor(elements, open, close, hasSpread = false) {
|
|
473
|
+
var _a;
|
|
453
474
|
super();
|
|
454
475
|
this.elements = elements;
|
|
455
476
|
this.open = open;
|
|
456
477
|
this.close = close;
|
|
457
478
|
this.hasSpread = hasSpread;
|
|
458
|
-
this.range = util_1.default.
|
|
479
|
+
this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
|
|
459
480
|
}
|
|
460
481
|
transpile(state) {
|
|
461
482
|
let result = [];
|
|
@@ -518,7 +539,7 @@ class AAMemberExpression extends Expression {
|
|
|
518
539
|
this.colonToken = colonToken;
|
|
519
540
|
this.value = value;
|
|
520
541
|
this.type = type;
|
|
521
|
-
this.range = util_1.default.
|
|
542
|
+
this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
|
|
522
543
|
}
|
|
523
544
|
transpile(state) {
|
|
524
545
|
//TODO move the logic from AALiteralExpression loop into this function
|
|
@@ -531,6 +552,7 @@ class AAMemberExpression extends Expression {
|
|
|
531
552
|
exports.AAMemberExpression = AAMemberExpression;
|
|
532
553
|
class AALiteralExpression extends Expression {
|
|
533
554
|
constructor(elements, open, close, functionExpression) {
|
|
555
|
+
var _a;
|
|
534
556
|
super();
|
|
535
557
|
this.elements = elements;
|
|
536
558
|
this.open = open;
|
|
@@ -538,12 +560,12 @@ class AALiteralExpression extends Expression {
|
|
|
538
560
|
this.functionExpression = functionExpression;
|
|
539
561
|
this.symbolTable = new SymbolTable_1.SymbolTable();
|
|
540
562
|
this.memberTable = new SymbolTable_1.SymbolTable();
|
|
541
|
-
this.range = util_1.default.
|
|
563
|
+
this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
|
|
542
564
|
this.buildSymbolTable();
|
|
543
565
|
}
|
|
544
566
|
buildSymbolTable() {
|
|
545
567
|
this.symbolTable.clear();
|
|
546
|
-
this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType(this.memberTable));
|
|
568
|
+
this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType('object', this.memberTable));
|
|
547
569
|
for (const element of this.elements) {
|
|
548
570
|
if ((0, reflection_1.isAAMemberExpression)(element)) {
|
|
549
571
|
this.memberTable.addSymbol(element.keyToken.text, element.keyToken.range, (0, Parser_1.getBscTypeFromExpression)(element.value, this.functionExpression));
|
|
@@ -633,7 +655,7 @@ class UnaryExpression extends Expression {
|
|
|
633
655
|
super();
|
|
634
656
|
this.operator = operator;
|
|
635
657
|
this.right = right;
|
|
636
|
-
this.range = util_1.default.
|
|
658
|
+
this.range = util_1.default.createBoundingRange(this.operator, this.right);
|
|
637
659
|
}
|
|
638
660
|
transpile(state) {
|
|
639
661
|
return [
|
|
@@ -750,7 +772,7 @@ class NewExpression extends Expression {
|
|
|
750
772
|
super();
|
|
751
773
|
this.newKeyword = newKeyword;
|
|
752
774
|
this.call = call;
|
|
753
|
-
this.range = util_1.default.
|
|
775
|
+
this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
|
|
754
776
|
}
|
|
755
777
|
/**
|
|
756
778
|
* The name of the class to initialize (with optional namespace prefixed)
|
|
@@ -779,7 +801,7 @@ class NewExpression extends Expression {
|
|
|
779
801
|
exports.NewExpression = NewExpression;
|
|
780
802
|
class CallfuncExpression extends Expression {
|
|
781
803
|
constructor(callee, operator, methodName, openingParen, args, closingParen) {
|
|
782
|
-
var _a
|
|
804
|
+
var _a;
|
|
783
805
|
super();
|
|
784
806
|
this.callee = callee;
|
|
785
807
|
this.operator = operator;
|
|
@@ -787,7 +809,7 @@ class CallfuncExpression extends Expression {
|
|
|
787
809
|
this.openingParen = openingParen;
|
|
788
810
|
this.args = args;
|
|
789
811
|
this.closingParen = closingParen;
|
|
790
|
-
this.range = util_1.default.
|
|
812
|
+
this.range = util_1.default.createBoundingRange(this.callee, this.operator, this.methodName, this.openingParen, ...((_a = this.args) !== null && _a !== void 0 ? _a : []), this.closingParen);
|
|
791
813
|
}
|
|
792
814
|
transpile(state) {
|
|
793
815
|
let result = [];
|
|
@@ -828,9 +850,10 @@ exports.CallfuncExpression = CallfuncExpression;
|
|
|
828
850
|
*/
|
|
829
851
|
class TemplateStringQuasiExpression extends Expression {
|
|
830
852
|
constructor(expressions) {
|
|
853
|
+
var _a;
|
|
831
854
|
super();
|
|
832
855
|
this.expressions = expressions;
|
|
833
|
-
this.range = util_1.default.
|
|
856
|
+
this.range = util_1.default.createBoundingRange(...((_a = this.expressions) !== null && _a !== void 0 ? _a : []));
|
|
834
857
|
}
|
|
835
858
|
transpile(state, skipEmptyStrings = true) {
|
|
836
859
|
let result = [];
|
|
@@ -857,12 +880,14 @@ class TemplateStringQuasiExpression extends Expression {
|
|
|
857
880
|
exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
|
|
858
881
|
class TemplateStringExpression extends Expression {
|
|
859
882
|
constructor(openingBacktick, quasis, expressions, closingBacktick) {
|
|
883
|
+
var _a;
|
|
860
884
|
super();
|
|
861
885
|
this.openingBacktick = openingBacktick;
|
|
862
886
|
this.quasis = quasis;
|
|
863
887
|
this.expressions = expressions;
|
|
864
888
|
this.closingBacktick = closingBacktick;
|
|
865
|
-
|
|
889
|
+
//the expression always starts and ends with a quasi, so we don't need to consider the expression locations
|
|
890
|
+
this.range = util_1.default.createBoundingRange(this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
|
|
866
891
|
}
|
|
867
892
|
transpile(state) {
|
|
868
893
|
if (this.quasis.length === 1 && this.expressions.length === 0) {
|
|
@@ -914,13 +939,15 @@ class TemplateStringExpression extends Expression {
|
|
|
914
939
|
exports.TemplateStringExpression = TemplateStringExpression;
|
|
915
940
|
class TaggedTemplateStringExpression extends Expression {
|
|
916
941
|
constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
|
|
942
|
+
var _a;
|
|
917
943
|
super();
|
|
918
944
|
this.tagName = tagName;
|
|
919
945
|
this.openingBacktick = openingBacktick;
|
|
920
946
|
this.quasis = quasis;
|
|
921
947
|
this.expressions = expressions;
|
|
922
948
|
this.closingBacktick = closingBacktick;
|
|
923
|
-
|
|
949
|
+
//the expression always starts and ends with a quasi, so we don't need to consider the expression locations
|
|
950
|
+
this.range = util_1.default.createBoundingRange(this.tagName, this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
|
|
924
951
|
}
|
|
925
952
|
transpile(state) {
|
|
926
953
|
let result = [];
|
|
@@ -966,7 +993,15 @@ class AnnotationExpression extends Expression {
|
|
|
966
993
|
this.atToken = atToken;
|
|
967
994
|
this.nameToken = nameToken;
|
|
968
995
|
this.name = nameToken.text;
|
|
969
|
-
|
|
996
|
+
}
|
|
997
|
+
get range() {
|
|
998
|
+
return this.cacheRange();
|
|
999
|
+
}
|
|
1000
|
+
cacheRange() {
|
|
1001
|
+
if (!this._range) {
|
|
1002
|
+
this._range = util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
|
|
1003
|
+
}
|
|
1004
|
+
return this._range;
|
|
970
1005
|
}
|
|
971
1006
|
/**
|
|
972
1007
|
* Convert annotation arguments to JavaScript types
|
|
@@ -996,14 +1031,13 @@ class AnnotationExpression extends Expression {
|
|
|
996
1031
|
exports.AnnotationExpression = AnnotationExpression;
|
|
997
1032
|
class TernaryExpression extends Expression {
|
|
998
1033
|
constructor(test, questionMarkToken, consequent, colonToken, alternate) {
|
|
999
|
-
var _a, _b, _c;
|
|
1000
1034
|
super();
|
|
1001
1035
|
this.test = test;
|
|
1002
1036
|
this.questionMarkToken = questionMarkToken;
|
|
1003
1037
|
this.consequent = consequent;
|
|
1004
1038
|
this.colonToken = colonToken;
|
|
1005
1039
|
this.alternate = alternate;
|
|
1006
|
-
this.range = util_1.default.
|
|
1040
|
+
this.range = util_1.default.createBoundingRange(this.test, this.questionMarkToken, this.consequent, this.colonToken, this.alternate);
|
|
1007
1041
|
}
|
|
1008
1042
|
transpile(state) {
|
|
1009
1043
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
@@ -1041,12 +1075,11 @@ class TernaryExpression extends Expression {
|
|
|
1041
1075
|
exports.TernaryExpression = TernaryExpression;
|
|
1042
1076
|
class NullCoalescingExpression extends Expression {
|
|
1043
1077
|
constructor(consequent, questionQuestionToken, alternate) {
|
|
1044
|
-
var _a;
|
|
1045
1078
|
super();
|
|
1046
1079
|
this.consequent = consequent;
|
|
1047
1080
|
this.questionQuestionToken = questionQuestionToken;
|
|
1048
1081
|
this.alternate = alternate;
|
|
1049
|
-
this.range = util_1.default.
|
|
1082
|
+
this.range = util_1.default.createBoundingRange(this.consequent, this.questionQuestionToken, this.alternate);
|
|
1050
1083
|
}
|
|
1051
1084
|
transpile(state) {
|
|
1052
1085
|
let result = [];
|
|
@@ -1086,9 +1119,7 @@ class RegexLiteralExpression extends Expression {
|
|
|
1086
1119
|
constructor(tokens) {
|
|
1087
1120
|
super();
|
|
1088
1121
|
this.tokens = tokens;
|
|
1089
|
-
|
|
1090
|
-
get range() {
|
|
1091
|
-
return this.tokens.regexLiteral.range;
|
|
1122
|
+
this.range = this.tokens.regexLiteral.range;
|
|
1092
1123
|
}
|
|
1093
1124
|
transpile(state) {
|
|
1094
1125
|
var _a, _b;
|
|
@@ -1119,6 +1150,109 @@ class RegexLiteralExpression extends Expression {
|
|
|
1119
1150
|
}
|
|
1120
1151
|
}
|
|
1121
1152
|
exports.RegexLiteralExpression = RegexLiteralExpression;
|
|
1153
|
+
class TypeExpression extends Expression {
|
|
1154
|
+
constructor(tokens, namespaceName) {
|
|
1155
|
+
super();
|
|
1156
|
+
this.tokens = tokens;
|
|
1157
|
+
this.namespaceName = namespaceName;
|
|
1158
|
+
this.range = util_1.default.createBoundingRange(this.tokens.type);
|
|
1159
|
+
}
|
|
1160
|
+
/**
|
|
1161
|
+
* The this TypeExpression refers to
|
|
1162
|
+
*/
|
|
1163
|
+
get type() {
|
|
1164
|
+
if (this._type) {
|
|
1165
|
+
return this._type;
|
|
1166
|
+
}
|
|
1167
|
+
this._type = this.getType(Parser_1.ParseMode.BrighterScript);
|
|
1168
|
+
return this._type;
|
|
1169
|
+
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Derive a BscType from the type token
|
|
1172
|
+
* Can deal with multiple brackets to make multidimensional arrays, eg. float[][]
|
|
1173
|
+
* Defaults to `DynamicType`
|
|
1174
|
+
*/
|
|
1175
|
+
getType(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1176
|
+
let exprType = this.tokens.type
|
|
1177
|
+
? util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName)
|
|
1178
|
+
: new DynamicType_1.DynamicType();
|
|
1179
|
+
return exprType;
|
|
1180
|
+
}
|
|
1181
|
+
/**
|
|
1182
|
+
* Is this a valid, (eg. known) type?
|
|
1183
|
+
*/
|
|
1184
|
+
isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1185
|
+
return !!util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName);
|
|
1186
|
+
}
|
|
1187
|
+
/**
|
|
1188
|
+
* Gives a human readable string that says the type
|
|
1189
|
+
* @returns text to display to show the type
|
|
1190
|
+
*/
|
|
1191
|
+
getText() {
|
|
1192
|
+
let result = this.tokens.type.text;
|
|
1193
|
+
return result;
|
|
1194
|
+
}
|
|
1195
|
+
transpile(state) {
|
|
1196
|
+
let result = [];
|
|
1197
|
+
//type declaration
|
|
1198
|
+
result.push(state.sourceNode({ range: this.range }, this.type.toTypeString(state.typeContext)));
|
|
1199
|
+
return result;
|
|
1200
|
+
}
|
|
1201
|
+
walk(visitor, options) {
|
|
1202
|
+
//nothing to walk
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
exports.TypeExpression = TypeExpression;
|
|
1206
|
+
class ArrayTypeExpression extends TypeExpression {
|
|
1207
|
+
constructor(innerTypes, // this is an array so that in the future when we support union types
|
|
1208
|
+
bracketTokens, namespaceName) {
|
|
1209
|
+
super({}, namespaceName);
|
|
1210
|
+
this.innerTypes = innerTypes;
|
|
1211
|
+
this.bracketTokens = bracketTokens;
|
|
1212
|
+
this.namespaceName = namespaceName;
|
|
1213
|
+
this.range = util_1.default.createBoundingRange(this.bracketTokens.leftBracket, this.bracketTokens.rightBracket, ...this.innerTypes);
|
|
1214
|
+
}
|
|
1215
|
+
/*
|
|
1216
|
+
* TODO - Support union types
|
|
1217
|
+
*/
|
|
1218
|
+
get defaultTypeExpression() {
|
|
1219
|
+
return this.innerTypes[0];
|
|
1220
|
+
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Derive a BscType from the type token
|
|
1223
|
+
* Returns an array type with the inner types based on the inner type expressions
|
|
1224
|
+
*/
|
|
1225
|
+
getType(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1226
|
+
const innerBscTypes = this.innerTypes.map(inner => inner.getType(parseMode));
|
|
1227
|
+
return new ArrayType_1.ArrayType(...innerBscTypes);
|
|
1228
|
+
}
|
|
1229
|
+
/**
|
|
1230
|
+
* Is this a valid, (eg. known) type?
|
|
1231
|
+
*/
|
|
1232
|
+
isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1233
|
+
if (parseMode === Parser_1.ParseMode.BrighterScript) {
|
|
1234
|
+
return this.innerTypes.reduce((validSoFar, innerType) => {
|
|
1235
|
+
return validSoFar && innerType.isValidType(parseMode);
|
|
1236
|
+
}, true);
|
|
1237
|
+
}
|
|
1238
|
+
return false;
|
|
1239
|
+
}
|
|
1240
|
+
/**
|
|
1241
|
+
* Gives a human readable string that says the type
|
|
1242
|
+
* @returns text to display to show the type
|
|
1243
|
+
*/
|
|
1244
|
+
getText() {
|
|
1245
|
+
return this.defaultTypeExpression.getText() + '[]';
|
|
1246
|
+
}
|
|
1247
|
+
walk(visitor, options) {
|
|
1248
|
+
if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
|
|
1249
|
+
for (let i = 0; i < this.innerTypes.length; i++) {
|
|
1250
|
+
(0, visitors_1.walk)(this.innerTypes, i, visitor, options, this);
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1255
|
+
exports.ArrayTypeExpression = ArrayTypeExpression;
|
|
1122
1256
|
function expressionToValue(expr, strict) {
|
|
1123
1257
|
if (!expr) {
|
|
1124
1258
|
return null;
|