brighterscript 1.0.0-alpha.14 → 1.0.0-alpha.17

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.
Files changed (151) hide show
  1. package/CHANGELOG.md +83 -1
  2. package/README.md +28 -9
  3. package/dist/Cache.d.ts +2 -7
  4. package/dist/Cache.js +4 -13
  5. package/dist/Cache.js.map +1 -1
  6. package/dist/DependencyGraph.js +5 -4
  7. package/dist/DependencyGraph.js.map +1 -1
  8. package/dist/DiagnosticMessages.d.ts +21 -1
  9. package/dist/DiagnosticMessages.js +21 -1
  10. package/dist/DiagnosticMessages.js.map +1 -1
  11. package/dist/Logger.js +5 -5
  12. package/dist/Logger.js.map +1 -1
  13. package/dist/Program.d.ts +3 -3
  14. package/dist/Program.js +9 -7
  15. package/dist/Program.js.map +1 -1
  16. package/dist/ProgramBuilder.js +1 -1
  17. package/dist/ProgramBuilder.js.map +1 -1
  18. package/dist/Scope.d.ts +16 -11
  19. package/dist/Scope.js +42 -12
  20. package/dist/Scope.js.map +1 -1
  21. package/dist/XmlScope.d.ts +3 -3
  22. package/dist/XmlScope.js +1 -1
  23. package/dist/XmlScope.js.map +1 -1
  24. package/dist/astUtils/AstEditor.d.ts +6 -0
  25. package/dist/astUtils/AstEditor.js +10 -0
  26. package/dist/astUtils/AstEditor.js.map +1 -1
  27. package/dist/astUtils/AstEditor.spec.js +37 -0
  28. package/dist/astUtils/AstEditor.spec.js.map +1 -1
  29. package/dist/astUtils/creators.d.ts +10 -6
  30. package/dist/astUtils/creators.js +93 -12
  31. package/dist/astUtils/creators.js.map +1 -1
  32. package/dist/astUtils/creators.spec.js +10 -0
  33. package/dist/astUtils/creators.spec.js.map +1 -1
  34. package/dist/astUtils/reflection.d.ts +7 -2
  35. package/dist/astUtils/reflection.js +19 -3
  36. package/dist/astUtils/reflection.js.map +1 -1
  37. package/dist/astUtils/reflection.spec.js +5 -4
  38. package/dist/astUtils/reflection.spec.js.map +1 -1
  39. package/dist/astUtils/visitors.d.ts +3 -1
  40. package/dist/astUtils/visitors.js.map +1 -1
  41. package/dist/astUtils/visitors.spec.js +2 -0
  42. package/dist/astUtils/visitors.spec.js.map +1 -1
  43. package/dist/bscPlugin/BscPlugin.d.ts +4 -1
  44. package/dist/bscPlugin/BscPlugin.js +16 -0
  45. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  46. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +1 -0
  47. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +38 -2
  48. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  49. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +28 -0
  50. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
  51. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +8 -0
  52. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +40 -0
  53. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
  54. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +1 -0
  55. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
  56. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
  57. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +9 -0
  58. package/dist/bscPlugin/validation/BrsFileValidator.js +66 -0
  59. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
  60. package/dist/bscPlugin/validation/ScopeValidator.d.ts +11 -0
  61. package/dist/bscPlugin/validation/ScopeValidator.js +94 -0
  62. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
  63. package/dist/diagnosticUtils.js +3 -3
  64. package/dist/diagnosticUtils.js.map +1 -1
  65. package/dist/examples/plugins/removePrint.js +12 -14
  66. package/dist/examples/plugins/removePrint.js.map +1 -1
  67. package/dist/files/BrsFile.Class.spec.js +22 -23
  68. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  69. package/dist/files/BrsFile.d.ts +10 -3
  70. package/dist/files/BrsFile.js +133 -49
  71. package/dist/files/BrsFile.js.map +1 -1
  72. package/dist/files/BrsFile.spec.js +299 -123
  73. package/dist/files/BrsFile.spec.js.map +1 -1
  74. package/dist/files/XmlFile.d.ts +5 -5
  75. package/dist/files/XmlFile.js +3 -3
  76. package/dist/files/XmlFile.js.map +1 -1
  77. package/dist/files/XmlFile.spec.js +9 -9
  78. package/dist/files/XmlFile.spec.js.map +1 -1
  79. package/dist/interfaces.d.ts +29 -37
  80. package/dist/lexer/Lexer.spec.js +8 -0
  81. package/dist/lexer/Lexer.spec.js.map +1 -1
  82. package/dist/lexer/TokenKind.d.ts +2 -0
  83. package/dist/lexer/TokenKind.js +5 -0
  84. package/dist/lexer/TokenKind.js.map +1 -1
  85. package/dist/parser/Expression.d.ts +85 -21
  86. package/dist/parser/Expression.js +177 -53
  87. package/dist/parser/Expression.js.map +1 -1
  88. package/dist/parser/Parser.Class.spec.js +1 -1
  89. package/dist/parser/Parser.Class.spec.js.map +1 -1
  90. package/dist/parser/Parser.d.ts +12 -3
  91. package/dist/parser/Parser.js +156 -56
  92. package/dist/parser/Parser.js.map +1 -1
  93. package/dist/parser/Parser.spec.js +57 -2
  94. package/dist/parser/Parser.spec.js.map +1 -1
  95. package/dist/parser/Statement.d.ts +94 -30
  96. package/dist/parser/Statement.js +281 -106
  97. package/dist/parser/Statement.js.map +1 -1
  98. package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
  99. package/dist/parser/tests/statement/Enum.spec.js +774 -0
  100. package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
  101. package/dist/parser/tests/statement/For.spec.d.ts +1 -0
  102. package/dist/parser/tests/statement/For.spec.js +46 -0
  103. package/dist/parser/tests/statement/For.spec.js.map +1 -0
  104. package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
  105. package/dist/parser/tests/statement/ForEach.spec.js +37 -0
  106. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
  107. package/dist/types/BooleanType.d.ts +4 -2
  108. package/dist/types/BooleanType.js +5 -1
  109. package/dist/types/BooleanType.js.map +1 -1
  110. package/dist/types/DoubleType.d.ts +2 -0
  111. package/dist/types/DoubleType.js +5 -1
  112. package/dist/types/DoubleType.js.map +1 -1
  113. package/dist/types/DynamicType.d.ts +2 -0
  114. package/dist/types/DynamicType.js +5 -1
  115. package/dist/types/DynamicType.js.map +1 -1
  116. package/dist/types/FloatType.d.ts +3 -1
  117. package/dist/types/FloatType.js +5 -1
  118. package/dist/types/FloatType.js.map +1 -1
  119. package/dist/types/FunctionType.d.ts +2 -1
  120. package/dist/types/FunctionType.js +11 -8
  121. package/dist/types/FunctionType.js.map +1 -1
  122. package/dist/types/FunctionType.spec.js +6 -0
  123. package/dist/types/FunctionType.spec.js.map +1 -1
  124. package/dist/types/IntegerType.d.ts +3 -1
  125. package/dist/types/IntegerType.js +5 -1
  126. package/dist/types/IntegerType.js.map +1 -1
  127. package/dist/types/InvalidType.d.ts +4 -2
  128. package/dist/types/InvalidType.js +5 -1
  129. package/dist/types/InvalidType.js.map +1 -1
  130. package/dist/types/LongIntegerType.d.ts +3 -1
  131. package/dist/types/LongIntegerType.js +5 -1
  132. package/dist/types/LongIntegerType.js.map +1 -1
  133. package/dist/types/ObjectType.d.ts +2 -1
  134. package/dist/types/ObjectType.js +4 -2
  135. package/dist/types/ObjectType.js.map +1 -1
  136. package/dist/types/StringType.d.ts +4 -2
  137. package/dist/types/StringType.js +5 -1
  138. package/dist/types/StringType.js.map +1 -1
  139. package/dist/types/UninitializedType.js.map +1 -1
  140. package/dist/types/UniversalFunctionType.d.ts +9 -0
  141. package/dist/types/UniversalFunctionType.js +25 -0
  142. package/dist/types/UniversalFunctionType.js.map +1 -0
  143. package/dist/types/VoidType.d.ts +4 -2
  144. package/dist/types/VoidType.js +5 -1
  145. package/dist/types/VoidType.js.map +1 -1
  146. package/dist/util.d.ts +12 -2
  147. package/dist/util.js +74 -44
  148. package/dist/util.js.map +1 -1
  149. package/dist/validators/ClassValidator.js +3 -3
  150. package/dist/validators/ClassValidator.js.map +1 -1
  151. package/package.json +2 -3
@@ -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");
@@ -12,6 +12,7 @@ const DynamicType_1 = require("../types/DynamicType");
12
12
  const SymbolTable_1 = require("../SymbolTable");
13
13
  const FunctionType_1 = require("../types/FunctionType");
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.createRangeFromPositions(this.left.range.start, this.right.range.end);
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.createRangeFromPositions(this.callee.range.start, this.closingParen.range.end);
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, returnTypeToken,
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.returnTypeToken = returnTypeToken;
111
+ this.returnType = returnType;
111
112
  this.parentFunction = parentFunction;
112
113
  this.namespaceName = namespaceName;
113
114
  this.parentSymbolTable = parentSymbolTable;
@@ -121,27 +122,38 @@ 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.returnTypeToken) {
125
- this.returnType = util_1.default.tokenToBscType(this.returnTypeToken, true, namespaceName);
125
+ if (this.returnType) {
126
+ this._returnType = this.returnType.type;
126
127
  }
127
128
  else if (this.functionType.text.toLowerCase() === 'sub') {
128
- this.returnType = new VoidType_1.VoidType();
129
+ this._returnType = new VoidType_1.VoidType();
129
130
  }
130
131
  else {
131
- this.returnType = new DynamicType_1.DynamicType();
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.type);
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, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
140
- * and ending with the last n' in 'end function' or 'b' in 'end sub'
143
+ * The range of the function
141
144
  */
142
- get range() {
143
- var _a, _b, _c, _d, _e;
144
- return util_1.default.createRangeFromPositions(((_a = this.functionType) !== null && _a !== void 0 ? _a : this.leftParen).range.start, ((_e = (_d = (_c = (_b = this.end) !== null && _b !== void 0 ? _b : this.body) !== null && _c !== void 0 ? _c : this.returnTypeToken) !== null && _d !== void 0 ? _d : this.asToken) !== null && _e !== void 0 ? _e : this.rightParen).range.end);
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;
145
157
  }
146
158
  transpile(state, name, includeBody = true) {
147
159
  let results = [];
@@ -171,7 +183,7 @@ class FunctionExpression extends Expression {
171
183
  //as
172
184
  state.transpileToken(this.asToken), ' ',
173
185
  //return type
174
- state.sourceNode(this.returnTypeToken, this.returnType.toTypeString(state.typeContext)));
186
+ state.sourceNode(this.returnType, this.getReturnType().toTypeString(state.typeContext)));
175
187
  }
176
188
  if (includeBody) {
177
189
  state.lineage.unshift(this);
@@ -194,36 +206,35 @@ class FunctionExpression extends Expression {
194
206
  }
195
207
  //This is the core of full-program walking...it allows us to step into sub functions
196
208
  if (options.walkMode & visitors_1.InternalWalkMode.recurseChildFunctions) {
209
+ (0, visitors_1.walk)(this, 'returnType', visitor, options);
197
210
  (0, visitors_1.walk)(this, 'body', visitor, options);
198
211
  }
199
212
  }
200
213
  }
201
214
  getFunctionType() {
202
- let functionType = new FunctionType_1.FunctionType(this.returnType);
215
+ let functionType = new FunctionType_1.FunctionType(this.getReturnType());
203
216
  functionType.isSub = this.functionType.text === 'sub';
204
217
  for (let param of this.parameters) {
205
- functionType.addParameter(param.name.text, param.type, param.isOptional);
218
+ functionType.addParameter(param.name.text, param.getType(), param.isOptional);
206
219
  }
207
220
  return functionType;
208
221
  }
209
222
  }
210
223
  exports.FunctionExpression = FunctionExpression;
211
224
  class FunctionParameterExpression extends Expression {
212
- constructor(name, type, equalsToken, defaultValue, asToken, typeToken, namespaceName) {
225
+ constructor(name, typeInContext, equalsToken, defaultValue, asToken, type, namespaceName) {
213
226
  super();
214
227
  this.name = name;
215
- this.type = type;
228
+ this.typeInContext = typeInContext;
216
229
  this.equalsToken = equalsToken;
217
230
  this.defaultValue = defaultValue;
218
231
  this.asToken = asToken;
219
- this.typeToken = typeToken;
232
+ this.type = type;
220
233
  this.namespaceName = namespaceName;
234
+ this.range = util_1.default.createBoundingRange(this.name, this.equalsToken, this.defaultValue, this.asToken, this.type);
221
235
  }
222
- get range() {
223
- return {
224
- start: this.name.range.start,
225
- end: this.typeToken ? this.typeToken.range.end : this.name.range.end
226
- };
236
+ getType() {
237
+ return this.typeInContext;
227
238
  }
228
239
  transpile(state) {
229
240
  let result = [
@@ -240,7 +251,7 @@ class FunctionParameterExpression extends Expression {
240
251
  result.push(' ');
241
252
  result.push(state.transpileToken(this.asToken));
242
253
  result.push(' ');
243
- result.push(state.sourceNode(this.typeToken, this.type.toTypeString(state.typeContext)));
254
+ result.push(state.sourceNode(this.type, this.getType().toTypeString(state.typeContext)));
244
255
  }
245
256
  return result;
246
257
  }
@@ -248,6 +259,7 @@ class FunctionParameterExpression extends Expression {
248
259
  // eslint-disable-next-line no-bitwise
249
260
  if (this.defaultValue && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
250
261
  (0, visitors_1.walk)(this, 'defaultValue', visitor, options);
262
+ (0, visitors_1.walk)(this, 'type', visitor, options);
251
263
  }
252
264
  }
253
265
  get isOptional() {
@@ -304,7 +316,7 @@ class DottedGetExpression extends Expression {
304
316
  this.obj = obj;
305
317
  this.name = name;
306
318
  this.dot = dot;
307
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.name.range.end);
319
+ this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
308
320
  }
309
321
  transpile(state) {
310
322
  //if the callee starts with a namespace name, transpile the name
@@ -332,7 +344,7 @@ class XmlAttributeGetExpression extends Expression {
332
344
  this.obj = obj;
333
345
  this.name = name;
334
346
  this.at = at;
335
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.name.range.end);
347
+ this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
336
348
  }
337
349
  transpile(state) {
338
350
  return [
@@ -355,7 +367,7 @@ class IndexedGetExpression extends Expression {
355
367
  this.index = index;
356
368
  this.openingSquare = openingSquare;
357
369
  this.closingSquare = closingSquare;
358
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.closingSquare.range.end);
370
+ this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.index, this.closingSquare);
359
371
  }
360
372
  transpile(state) {
361
373
  return [
@@ -378,7 +390,7 @@ class GroupingExpression extends Expression {
378
390
  super();
379
391
  this.tokens = tokens;
380
392
  this.expression = expression;
381
- this.range = util_1.default.createRangeFromPositions(this.tokens.left.range.start, this.tokens.right.range.end);
393
+ this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
382
394
  }
383
395
  transpile(state) {
384
396
  return [
@@ -398,11 +410,9 @@ class LiteralExpression extends Expression {
398
410
  constructor(token) {
399
411
  super();
400
412
  this.token = token;
413
+ this.range = this.token.range;
401
414
  this.type = util_1.default.tokenToBscType(token);
402
415
  }
403
- get range() {
404
- return this.token.range;
405
- }
406
416
  transpile(state) {
407
417
  let text;
408
418
  if (this.token.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
@@ -450,12 +460,13 @@ class EscapedCharCodeLiteralExpression extends Expression {
450
460
  exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
451
461
  class ArrayLiteralExpression extends Expression {
452
462
  constructor(elements, open, close, hasSpread = false) {
463
+ var _a;
453
464
  super();
454
465
  this.elements = elements;
455
466
  this.open = open;
456
467
  this.close = close;
457
468
  this.hasSpread = hasSpread;
458
- this.range = util_1.default.createRangeFromPositions(this.open.range.start, this.close.range.end);
469
+ this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
459
470
  }
460
471
  transpile(state) {
461
472
  let result = [];
@@ -518,7 +529,7 @@ class AAMemberExpression extends Expression {
518
529
  this.colonToken = colonToken;
519
530
  this.value = value;
520
531
  this.type = type;
521
- this.range = util_1.default.createRangeFromPositions(keyToken.range.start, this.value.range.end);
532
+ this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
522
533
  }
523
534
  transpile(state) {
524
535
  //TODO move the logic from AALiteralExpression loop into this function
@@ -531,6 +542,7 @@ class AAMemberExpression extends Expression {
531
542
  exports.AAMemberExpression = AAMemberExpression;
532
543
  class AALiteralExpression extends Expression {
533
544
  constructor(elements, open, close, functionExpression) {
545
+ var _a;
534
546
  super();
535
547
  this.elements = elements;
536
548
  this.open = open;
@@ -538,12 +550,12 @@ class AALiteralExpression extends Expression {
538
550
  this.functionExpression = functionExpression;
539
551
  this.symbolTable = new SymbolTable_1.SymbolTable();
540
552
  this.memberTable = new SymbolTable_1.SymbolTable();
541
- this.range = util_1.default.createRangeFromPositions(this.open.range.start, this.close.range.end);
553
+ this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
542
554
  this.buildSymbolTable();
543
555
  }
544
556
  buildSymbolTable() {
545
557
  this.symbolTable.clear();
546
- this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType(this.memberTable));
558
+ this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType('object', this.memberTable));
547
559
  for (const element of this.elements) {
548
560
  if ((0, reflection_1.isAAMemberExpression)(element)) {
549
561
  this.memberTable.addSymbol(element.keyToken.text, element.keyToken.range, (0, Parser_1.getBscTypeFromExpression)(element.value, this.functionExpression));
@@ -633,7 +645,7 @@ class UnaryExpression extends Expression {
633
645
  super();
634
646
  this.operator = operator;
635
647
  this.right = right;
636
- this.range = util_1.default.createRangeFromPositions(this.operator.range.start, this.right.range.end);
648
+ this.range = util_1.default.createBoundingRange(this.operator, this.right);
637
649
  }
638
650
  transpile(state) {
639
651
  return [
@@ -750,7 +762,7 @@ class NewExpression extends Expression {
750
762
  super();
751
763
  this.newKeyword = newKeyword;
752
764
  this.call = call;
753
- this.range = util_1.default.createRangeFromPositions(this.newKeyword.range.start, this.call.range.end);
765
+ this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
754
766
  }
755
767
  /**
756
768
  * The name of the class to initialize (with optional namespace prefixed)
@@ -779,7 +791,7 @@ class NewExpression extends Expression {
779
791
  exports.NewExpression = NewExpression;
780
792
  class CallfuncExpression extends Expression {
781
793
  constructor(callee, operator, methodName, openingParen, args, closingParen) {
782
- var _a, _b, _c;
794
+ var _a;
783
795
  super();
784
796
  this.callee = callee;
785
797
  this.operator = operator;
@@ -787,7 +799,7 @@ class CallfuncExpression extends Expression {
787
799
  this.openingParen = openingParen;
788
800
  this.args = args;
789
801
  this.closingParen = closingParen;
790
- this.range = util_1.default.createRangeFromPositions(callee.range.start, ((_c = (_b = (_a = closingParen !== null && closingParen !== void 0 ? closingParen : args[args.length - 1]) !== null && _a !== void 0 ? _a : openingParen) !== null && _b !== void 0 ? _b : methodName) !== null && _c !== void 0 ? _c : operator).range.end);
802
+ 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
803
  }
792
804
  transpile(state) {
793
805
  let result = [];
@@ -828,9 +840,10 @@ exports.CallfuncExpression = CallfuncExpression;
828
840
  */
829
841
  class TemplateStringQuasiExpression extends Expression {
830
842
  constructor(expressions) {
843
+ var _a;
831
844
  super();
832
845
  this.expressions = expressions;
833
- this.range = util_1.default.createRangeFromPositions(this.expressions[0].range.start, this.expressions[this.expressions.length - 1].range.end);
846
+ this.range = util_1.default.createBoundingRange(...((_a = this.expressions) !== null && _a !== void 0 ? _a : []));
834
847
  }
835
848
  transpile(state, skipEmptyStrings = true) {
836
849
  let result = [];
@@ -857,12 +870,14 @@ class TemplateStringQuasiExpression extends Expression {
857
870
  exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
858
871
  class TemplateStringExpression extends Expression {
859
872
  constructor(openingBacktick, quasis, expressions, closingBacktick) {
873
+ var _a;
860
874
  super();
861
875
  this.openingBacktick = openingBacktick;
862
876
  this.quasis = quasis;
863
877
  this.expressions = expressions;
864
878
  this.closingBacktick = closingBacktick;
865
- this.range = util_1.default.createRangeFromPositions(quasis[0].range.start, quasis[quasis.length - 1].range.end);
879
+ //the expression always starts and ends with a quasi, so we don't need to consider the expression locations
880
+ this.range = util_1.default.createBoundingRange(this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
866
881
  }
867
882
  transpile(state) {
868
883
  if (this.quasis.length === 1 && this.expressions.length === 0) {
@@ -914,13 +929,15 @@ class TemplateStringExpression extends Expression {
914
929
  exports.TemplateStringExpression = TemplateStringExpression;
915
930
  class TaggedTemplateStringExpression extends Expression {
916
931
  constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
932
+ var _a;
917
933
  super();
918
934
  this.tagName = tagName;
919
935
  this.openingBacktick = openingBacktick;
920
936
  this.quasis = quasis;
921
937
  this.expressions = expressions;
922
938
  this.closingBacktick = closingBacktick;
923
- this.range = util_1.default.createRangeFromPositions(quasis[0].range.start, quasis[quasis.length - 1].range.end);
939
+ //the expression always starts and ends with a quasi, so we don't need to consider the expression locations
940
+ this.range = util_1.default.createBoundingRange(this.tagName, this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
924
941
  }
925
942
  transpile(state) {
926
943
  let result = [];
@@ -966,7 +983,15 @@ class AnnotationExpression extends Expression {
966
983
  this.atToken = atToken;
967
984
  this.nameToken = nameToken;
968
985
  this.name = nameToken.text;
969
- this.range = util_1.default.createRangeFromPositions(atToken.range.start, nameToken.range.end);
986
+ }
987
+ get range() {
988
+ return this.cacheRange();
989
+ }
990
+ cacheRange() {
991
+ if (!this._range) {
992
+ this._range = util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
993
+ }
994
+ return this._range;
970
995
  }
971
996
  /**
972
997
  * Convert annotation arguments to JavaScript types
@@ -996,14 +1021,13 @@ class AnnotationExpression extends Expression {
996
1021
  exports.AnnotationExpression = AnnotationExpression;
997
1022
  class TernaryExpression extends Expression {
998
1023
  constructor(test, questionMarkToken, consequent, colonToken, alternate) {
999
- var _a, _b, _c;
1000
1024
  super();
1001
1025
  this.test = test;
1002
1026
  this.questionMarkToken = questionMarkToken;
1003
1027
  this.consequent = consequent;
1004
1028
  this.colonToken = colonToken;
1005
1029
  this.alternate = alternate;
1006
- this.range = util_1.default.createRangeFromPositions(test.range.start, ((_c = (_b = (_a = alternate !== null && alternate !== void 0 ? alternate : colonToken) !== null && _a !== void 0 ? _a : consequent) !== null && _b !== void 0 ? _b : questionMarkToken) !== null && _c !== void 0 ? _c : test).range.end);
1030
+ this.range = util_1.default.createBoundingRange(this.test, this.questionMarkToken, this.consequent, this.colonToken, this.alternate);
1007
1031
  }
1008
1032
  transpile(state) {
1009
1033
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
@@ -1041,12 +1065,11 @@ class TernaryExpression extends Expression {
1041
1065
  exports.TernaryExpression = TernaryExpression;
1042
1066
  class NullCoalescingExpression extends Expression {
1043
1067
  constructor(consequent, questionQuestionToken, alternate) {
1044
- var _a;
1045
1068
  super();
1046
1069
  this.consequent = consequent;
1047
1070
  this.questionQuestionToken = questionQuestionToken;
1048
1071
  this.alternate = alternate;
1049
- this.range = util_1.default.createRangeFromPositions(consequent.range.start, ((_a = alternate !== null && alternate !== void 0 ? alternate : questionQuestionToken) !== null && _a !== void 0 ? _a : consequent).range.end);
1072
+ this.range = util_1.default.createBoundingRange(this.consequent, this.questionQuestionToken, this.alternate);
1050
1073
  }
1051
1074
  transpile(state) {
1052
1075
  let result = [];
@@ -1086,9 +1109,7 @@ class RegexLiteralExpression extends Expression {
1086
1109
  constructor(tokens) {
1087
1110
  super();
1088
1111
  this.tokens = tokens;
1089
- }
1090
- get range() {
1091
- return this.tokens.regexLiteral.range;
1112
+ this.range = this.tokens.regexLiteral.range;
1092
1113
  }
1093
1114
  transpile(state) {
1094
1115
  var _a, _b;
@@ -1119,6 +1140,109 @@ class RegexLiteralExpression extends Expression {
1119
1140
  }
1120
1141
  }
1121
1142
  exports.RegexLiteralExpression = RegexLiteralExpression;
1143
+ class TypeExpression extends Expression {
1144
+ constructor(tokens, namespaceName) {
1145
+ super();
1146
+ this.tokens = tokens;
1147
+ this.namespaceName = namespaceName;
1148
+ this.range = util_1.default.createBoundingRange(this.tokens.type);
1149
+ }
1150
+ /**
1151
+ * The this TypeExpression refers to
1152
+ */
1153
+ get type() {
1154
+ if (this._type) {
1155
+ return this._type;
1156
+ }
1157
+ this._type = this.getType(Parser_1.ParseMode.BrighterScript);
1158
+ return this._type;
1159
+ }
1160
+ /**
1161
+ * Derive a BscType from the type token
1162
+ * Can deal with multiple brackets to make multidimensional arrays, eg. float[][]
1163
+ * Defaults to `DynamicType`
1164
+ */
1165
+ getType(parseMode = Parser_1.ParseMode.BrighterScript) {
1166
+ let exprType = this.tokens.type
1167
+ ? util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName)
1168
+ : new DynamicType_1.DynamicType();
1169
+ return exprType;
1170
+ }
1171
+ /**
1172
+ * Is this a valid, (eg. known) type?
1173
+ */
1174
+ isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
1175
+ return !!util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName);
1176
+ }
1177
+ /**
1178
+ * Gives a human readable string that says the type
1179
+ * @returns text to display to show the type
1180
+ */
1181
+ getText() {
1182
+ let result = this.tokens.type.text;
1183
+ return result;
1184
+ }
1185
+ transpile(state) {
1186
+ let result = [];
1187
+ //type declaration
1188
+ result.push(state.sourceNode({ range: this.range }, this.type.toTypeString(state.typeContext)));
1189
+ return result;
1190
+ }
1191
+ walk(visitor, options) {
1192
+ //nothing to walk
1193
+ }
1194
+ }
1195
+ exports.TypeExpression = TypeExpression;
1196
+ class ArrayTypeExpression extends TypeExpression {
1197
+ constructor(innerTypes, // this is an array so that in the future when we support union types
1198
+ bracketTokens, namespaceName) {
1199
+ super({}, namespaceName);
1200
+ this.innerTypes = innerTypes;
1201
+ this.bracketTokens = bracketTokens;
1202
+ this.namespaceName = namespaceName;
1203
+ this.range = util_1.default.createBoundingRange(this.bracketTokens.leftBracket, this.bracketTokens.rightBracket, ...this.innerTypes);
1204
+ }
1205
+ /*
1206
+ * TODO - Support union types
1207
+ */
1208
+ get defaultTypeExpression() {
1209
+ return this.innerTypes[0];
1210
+ }
1211
+ /**
1212
+ * Derive a BscType from the type token
1213
+ * Returns an array type with the inner types based on the inner type expressions
1214
+ */
1215
+ getType(parseMode = Parser_1.ParseMode.BrighterScript) {
1216
+ const innerBscTypes = this.innerTypes.map(inner => inner.getType(parseMode));
1217
+ return new ArrayType_1.ArrayType(...innerBscTypes);
1218
+ }
1219
+ /**
1220
+ * Is this a valid, (eg. known) type?
1221
+ */
1222
+ isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
1223
+ if (parseMode === Parser_1.ParseMode.BrighterScript) {
1224
+ return this.innerTypes.reduce((validSoFar, innerType) => {
1225
+ return validSoFar && innerType.isValidType(parseMode);
1226
+ }, true);
1227
+ }
1228
+ return false;
1229
+ }
1230
+ /**
1231
+ * Gives a human readable string that says the type
1232
+ * @returns text to display to show the type
1233
+ */
1234
+ getText() {
1235
+ return this.defaultTypeExpression.getText() + '[]';
1236
+ }
1237
+ walk(visitor, options) {
1238
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1239
+ for (let i = 0; i < this.innerTypes.length; i++) {
1240
+ (0, visitors_1.walk)(this.innerTypes, i, visitor, options, this);
1241
+ }
1242
+ }
1243
+ }
1244
+ }
1245
+ exports.ArrayTypeExpression = ArrayTypeExpression;
1122
1246
  function expressionToValue(expr, strict) {
1123
1247
  if (!expr) {
1124
1248
  return null;