brighterscript 1.0.0-alpha.25 → 1.0.0-alpha.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/CHANGELOG.md +44 -0
  2. package/bsconfig.schema.json +5 -0
  3. package/dist/AstValidationSegmenter.d.ts +1 -1
  4. package/dist/AstValidationSegmenter.js +6 -7
  5. package/dist/AstValidationSegmenter.js.map +1 -1
  6. package/dist/BsConfig.d.ts +1 -0
  7. package/dist/DiagnosticMessages.d.ts +1 -3
  8. package/dist/DiagnosticMessages.js +5 -8
  9. package/dist/DiagnosticMessages.js.map +1 -1
  10. package/dist/Program.d.ts +1 -1
  11. package/dist/Program.js +40 -42
  12. package/dist/Program.js.map +1 -1
  13. package/dist/Scope.d.ts +2 -13
  14. package/dist/Scope.js +27 -35
  15. package/dist/Scope.js.map +1 -1
  16. package/dist/SymbolTable.d.ts +1 -8
  17. package/dist/SymbolTable.js +1 -10
  18. package/dist/SymbolTable.js.map +1 -1
  19. package/dist/SymbolTableFlag.d.ts +8 -0
  20. package/dist/SymbolTableFlag.js +13 -0
  21. package/dist/SymbolTableFlag.js.map +1 -0
  22. package/dist/XmlScope.d.ts +1 -6
  23. package/dist/XmlScope.js +6 -25
  24. package/dist/XmlScope.js.map +1 -1
  25. package/dist/astUtils/CachedLookups.d.ts +1 -2
  26. package/dist/astUtils/CachedLookups.js +3 -14
  27. package/dist/astUtils/CachedLookups.js.map +1 -1
  28. package/dist/astUtils/Editor.spec.js +1 -1
  29. package/dist/astUtils/Editor.spec.js.map +1 -1
  30. package/dist/astUtils/creators.js +77 -18
  31. package/dist/astUtils/creators.js.map +1 -1
  32. package/dist/astUtils/creators.spec.js +4 -4
  33. package/dist/astUtils/creators.spec.js.map +1 -1
  34. package/dist/astUtils/reflection.d.ts +3 -1
  35. package/dist/astUtils/reflection.js +12 -4
  36. package/dist/astUtils/reflection.js.map +1 -1
  37. package/dist/astUtils/reflection.spec.js +59 -42
  38. package/dist/astUtils/reflection.spec.js.map +1 -1
  39. package/dist/astUtils/visitors.spec.js +30 -19
  40. package/dist/astUtils/visitors.spec.js.map +1 -1
  41. package/dist/bscPlugin/BscPlugin.d.ts +2 -1
  42. package/dist/bscPlugin/BscPlugin.js +7 -3
  43. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  44. package/dist/bscPlugin/CallExpressionInfo.js +7 -7
  45. package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
  46. package/dist/bscPlugin/SignatureHelpUtil.js +5 -4
  47. package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -1
  48. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +2 -2
  49. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  50. package/dist/bscPlugin/completions/CompletionsProcessor.js +23 -23
  51. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
  52. package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
  53. package/dist/bscPlugin/definition/DefinitionProvider.js +210 -0
  54. package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
  55. package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +1 -0
  56. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +88 -0
  57. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
  58. package/dist/bscPlugin/hover/HoverProcessor.d.ts +1 -0
  59. package/dist/bscPlugin/hover/HoverProcessor.js +28 -8
  60. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
  61. package/dist/bscPlugin/hover/HoverProcessor.spec.js +74 -2
  62. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
  63. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -5
  64. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  65. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +8 -6
  66. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -1
  67. package/dist/bscPlugin/validation/BrsFileValidator.js +46 -47
  68. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  69. package/dist/bscPlugin/validation/ScopeValidator.d.ts +10 -0
  70. package/dist/bscPlugin/validation/ScopeValidator.js +120 -39
  71. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  72. package/dist/bscPlugin/validation/ScopeValidator.spec.js +165 -10
  73. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
  74. package/dist/diagnosticUtils.d.ts +1 -1
  75. package/dist/files/BrsFile.Class.spec.js +7 -6
  76. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  77. package/dist/files/BrsFile.d.ts +7 -15
  78. package/dist/files/BrsFile.js +49 -309
  79. package/dist/files/BrsFile.js.map +1 -1
  80. package/dist/files/BrsFile.spec.js +111 -157
  81. package/dist/files/BrsFile.spec.js.map +1 -1
  82. package/dist/files/XmlFile.d.ts +2 -3
  83. package/dist/files/XmlFile.js +0 -2
  84. package/dist/files/XmlFile.js.map +1 -1
  85. package/dist/interfaces.d.ts +109 -84
  86. package/dist/interfaces.js +9 -9
  87. package/dist/interfaces.js.map +1 -1
  88. package/dist/parser/AstNode.spec.js +6 -6
  89. package/dist/parser/AstNode.spec.js.map +1 -1
  90. package/dist/parser/Expression.d.ts +301 -164
  91. package/dist/parser/Expression.js +355 -294
  92. package/dist/parser/Expression.js.map +1 -1
  93. package/dist/parser/Parser.Class.spec.js +26 -27
  94. package/dist/parser/Parser.Class.spec.js.map +1 -1
  95. package/dist/parser/Parser.d.ts +6 -2
  96. package/dist/parser/Parser.js +361 -160
  97. package/dist/parser/Parser.js.map +1 -1
  98. package/dist/parser/Parser.spec.js +69 -213
  99. package/dist/parser/Parser.spec.js.map +1 -1
  100. package/dist/parser/SGParser.js +49 -35
  101. package/dist/parser/SGParser.js.map +1 -1
  102. package/dist/parser/SGTypes.d.ts +36 -24
  103. package/dist/parser/SGTypes.js +26 -55
  104. package/dist/parser/SGTypes.js.map +1 -1
  105. package/dist/parser/Statement.d.ts +381 -238
  106. package/dist/parser/Statement.js +510 -386
  107. package/dist/parser/Statement.js.map +1 -1
  108. package/dist/parser/Statement.spec.js +2 -2
  109. package/dist/parser/Statement.spec.js.map +1 -1
  110. package/dist/parser/tests/controlFlow/For.spec.js +1 -1
  111. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  112. package/dist/parser/tests/controlFlow/ForEach.spec.js +2 -2
  113. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  114. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +1 -1
  115. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  116. package/dist/parser/tests/expression/Call.spec.js +11 -11
  117. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  118. package/dist/parser/tests/expression/Indexing.spec.js +30 -5
  119. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  120. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +2 -2
  121. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  122. package/dist/parser/tests/expression/TernaryExpression.spec.js +2 -2
  123. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  124. package/dist/parser/tests/expression/TypeExpression.spec.js +8 -9
  125. package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -1
  126. package/dist/parser/tests/statement/ConstStatement.spec.js +1 -1
  127. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
  128. package/dist/parser/tests/statement/Dim.spec.js +8 -8
  129. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  130. package/dist/parser/tests/statement/Enum.spec.js +2 -2
  131. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  132. package/dist/parser/tests/statement/LibraryStatement.spec.js +2 -2
  133. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  134. package/dist/parser/tests/statement/Misc.spec.js +2 -2
  135. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  136. package/dist/parser/tests/statement/PrintStatement.spec.js +1 -1
  137. package/dist/parser/tests/statement/TryCatch.spec.js +10 -3
  138. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  139. package/dist/roku-types/data.json +70 -52
  140. package/dist/roku-types/index.d.ts +43 -21
  141. package/dist/types/ArrayType.js +1 -2
  142. package/dist/types/ArrayType.js.map +1 -1
  143. package/dist/types/ArrayType.spec.js +7 -8
  144. package/dist/types/ArrayType.spec.js.map +1 -1
  145. package/dist/types/AssociativeArrayType.js +2 -3
  146. package/dist/types/AssociativeArrayType.js.map +1 -1
  147. package/dist/types/BscType.d.ts +1 -1
  148. package/dist/types/BscType.js +2 -3
  149. package/dist/types/BscType.js.map +1 -1
  150. package/dist/types/BuiltInInterfaceAdder.js +15 -9
  151. package/dist/types/BuiltInInterfaceAdder.js.map +1 -1
  152. package/dist/types/BuiltInInterfaceAdder.spec.js +31 -32
  153. package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -1
  154. package/dist/types/ClassType.spec.js +10 -11
  155. package/dist/types/ClassType.spec.js.map +1 -1
  156. package/dist/types/ComponentType.d.ts +2 -1
  157. package/dist/types/ComponentType.js.map +1 -1
  158. package/dist/types/EnumType.js +2 -3
  159. package/dist/types/EnumType.js.map +1 -1
  160. package/dist/types/InheritableType.js +3 -4
  161. package/dist/types/InheritableType.js.map +1 -1
  162. package/dist/types/InterfaceType.js +2 -3
  163. package/dist/types/InterfaceType.js.map +1 -1
  164. package/dist/types/InterfaceType.spec.js +3 -4
  165. package/dist/types/InterfaceType.spec.js.map +1 -1
  166. package/dist/types/ObjectType.js +1 -2
  167. package/dist/types/ObjectType.js.map +1 -1
  168. package/dist/types/ReferenceType.d.ts +1 -1
  169. package/dist/types/ReferenceType.spec.js +21 -22
  170. package/dist/types/ReferenceType.spec.js.map +1 -1
  171. package/dist/types/UnionType.js +3 -3
  172. package/dist/types/UnionType.js.map +1 -1
  173. package/dist/types/UnionType.spec.js +37 -38
  174. package/dist/types/UnionType.spec.js.map +1 -1
  175. package/dist/types/helper.spec.js +4 -5
  176. package/dist/types/helper.spec.js.map +1 -1
  177. package/dist/util.d.ts +16 -7
  178. package/dist/util.js +89 -43
  179. package/dist/util.js.map +1 -1
  180. package/dist/validators/ClassValidator.d.ts +0 -9
  181. package/dist/validators/ClassValidator.js +9 -52
  182. package/dist/validators/ClassValidator.js.map +1 -1
  183. package/package.json +1 -1
@@ -8,10 +8,9 @@ const Parser_1 = require("./Parser");
8
8
  const visitors_1 = require("../astUtils/visitors");
9
9
  const reflection_1 = require("../astUtils/reflection");
10
10
  const interfaces_1 = require("../interfaces");
11
- const SymbolTable_1 = require("../SymbolTable");
12
11
  const creators_1 = require("../astUtils/creators");
13
12
  const DynamicType_1 = require("../types/DynamicType");
14
- const SymbolTable_2 = require("../SymbolTable");
13
+ const SymbolTable_1 = require("../SymbolTable");
15
14
  const AstNode_1 = require("./AstNode");
16
15
  const AstNode_2 = require("./AstNode");
17
16
  const ClassType_1 = require("../types/ClassType");
@@ -20,15 +19,13 @@ const NamespaceType_1 = require("../types/NamespaceType");
20
19
  const InterfaceType_1 = require("../types/InterfaceType");
21
20
  const VoidType_1 = require("../types/VoidType");
22
21
  const TypedFunctionType_1 = require("../types/TypedFunctionType");
22
+ const ArrayType_1 = require("../types/ArrayType");
23
23
  class EmptyStatement extends AstNode_2.Statement {
24
- constructor(
25
- /**
26
- * Create a negative range to indicate this is an interpolated location
27
- */
28
- range = creators_1.interpolatedRange) {
24
+ constructor(options) {
25
+ var _a;
29
26
  super();
30
- this.range = range;
31
27
  this.kind = AstNode_1.AstNodeKind.EmptyStatement;
28
+ this.range = (_a = options === null || options === void 0 ? void 0 : options.range) !== null && _a !== void 0 ? _a : creators_1.interpolatedRange;
32
29
  }
33
30
  transpile(state) {
34
31
  return [];
@@ -42,11 +39,13 @@ exports.EmptyStatement = EmptyStatement;
42
39
  * This is a top-level statement. Consider this the root of the AST
43
40
  */
44
41
  class Body extends AstNode_2.Statement {
45
- constructor(statements = []) {
42
+ constructor(options) {
43
+ var _a;
46
44
  super();
47
- this.statements = statements;
45
+ this.statements = [];
48
46
  this.kind = AstNode_1.AstNodeKind.Body;
49
- this.symbolTable = new SymbolTable_2.SymbolTable('Body', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
47
+ this.symbolTable = new SymbolTable_1.SymbolTable('Body', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
48
+ this.statements = (_a = options === null || options === void 0 ? void 0 : options.statements) !== null && _a !== void 0 ? _a : [];
50
49
  }
51
50
  get range() {
52
51
  var _a;
@@ -100,27 +99,29 @@ class Body extends AstNode_2.Statement {
100
99
  }
101
100
  exports.Body = Body;
102
101
  class AssignmentStatement extends AstNode_2.Statement {
103
- constructor(equals, name, value, asToken, typeExpression) {
102
+ constructor(options) {
104
103
  super();
105
- this.equals = equals;
106
- this.name = name;
107
- this.value = value;
108
- this.asToken = asToken;
109
- this.typeExpression = typeExpression;
110
104
  this.kind = AstNode_1.AstNodeKind.AssignmentStatement;
111
- this.range = util_1.util.createBoundingRange(name, equals, value);
105
+ this.value = options.value;
106
+ this.tokens = {
107
+ equals: options.equals,
108
+ name: options.name,
109
+ as: options.as
110
+ };
111
+ this.typeExpression = options.typeExpression;
112
+ this.range = util_1.util.createBoundingRange(util_1.util.createBoundingRangeFromTokens(this.tokens), this.value);
112
113
  }
113
114
  transpile(state) {
114
- var _a, _b;
115
+ var _a, _b, _c, _d;
115
116
  //if the value is a compound assignment, just transpile the expression itself
116
- if (TokenKind_1.CompoundAssignmentOperators.includes((_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.operator) === null || _b === void 0 ? void 0 : _b.kind)) {
117
+ if (TokenKind_1.CompoundAssignmentOperators.includes((_c = (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.operator) === null || _c === void 0 ? void 0 : _c.kind)) {
117
118
  return this.value.transpile(state);
118
119
  }
119
120
  else {
120
121
  return [
121
- state.transpileToken(this.name),
122
+ state.transpileToken(this.tokens.name),
122
123
  ' ',
123
- state.transpileToken(this.equals),
124
+ state.transpileToken((_d = this.tokens.equals) !== null && _d !== void 0 ? _d : (0, creators_1.createToken)(TokenKind_1.TokenKind.Equal)),
124
125
  ' ',
125
126
  ...this.value.transpile(state)
126
127
  ];
@@ -133,23 +134,23 @@ class AssignmentStatement extends AstNode_2.Statement {
133
134
  }
134
135
  }
135
136
  getType(options) {
136
- // TODO: Do we still need this.typeExpression?
137
- var _a;
137
+ var _a, _b, _c;
138
+ const variableType = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }))) !== null && _b !== void 0 ? _b : this.value.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
138
139
  // Note: compound assignments (eg. +=) are internally dealt with via the RHS being a BinaryExpression
139
140
  // so this.value will be a BinaryExpression, and BinaryExpressions can figure out their own types
140
- const rhs = this.value.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
141
- (_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry(this.name.text, rhs, options.data, this.name.range));
142
- return rhs;
141
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({ name: this.tokens.name.text, type: variableType, data: options.data, range: this.tokens.name.range, kind: this.kind }));
142
+ return variableType;
143
143
  }
144
144
  }
145
145
  exports.AssignmentStatement = AssignmentStatement;
146
146
  class Block extends AstNode_2.Statement {
147
- constructor(statements, startingRange) {
147
+ constructor(options) {
148
+ var _a;
148
149
  super();
149
- this.statements = statements;
150
- this.startingRange = startingRange;
151
150
  this.kind = AstNode_1.AstNodeKind.Block;
152
- this.range = util_1.util.createBoundingRange({ range: this.startingRange }, ...(statements !== null && statements !== void 0 ? statements : []));
151
+ this.statements = options.statements;
152
+ this.startingRange = options.startingRange;
153
+ this.range = util_1.util.createBoundingRange(this.startingRange, ...((_a = this.statements) !== null && _a !== void 0 ? _a : []));
153
154
  }
154
155
  transpile(state) {
155
156
  state.blockDepth++;
@@ -183,10 +184,10 @@ class Block extends AstNode_2.Statement {
183
184
  }
184
185
  exports.Block = Block;
185
186
  class ExpressionStatement extends AstNode_2.Statement {
186
- constructor(expression) {
187
+ constructor(options) {
187
188
  super();
188
- this.expression = expression;
189
189
  this.kind = AstNode_1.AstNodeKind.ExpressionStatement;
190
+ this.expression = options.expression;
190
191
  this.range = this.expression.range;
191
192
  }
192
193
  transpile(state) {
@@ -200,29 +201,31 @@ class ExpressionStatement extends AstNode_2.Statement {
200
201
  }
201
202
  exports.ExpressionStatement = ExpressionStatement;
202
203
  class CommentStatement extends AstNode_2.Statement {
203
- constructor(comments) {
204
+ constructor(options) {
204
205
  var _a;
205
206
  super();
206
- this.comments = comments;
207
207
  this.kind = AstNode_1.AstNodeKind.CommentStatement;
208
208
  this.visitMode = visitors_1.InternalWalkMode.visitStatements | visitors_1.InternalWalkMode.visitExpressions;
209
- if (((_a = this.comments) === null || _a === void 0 ? void 0 : _a.length) > 0) {
210
- this.range = util_1.util.createBoundingRange(...this.comments);
209
+ this.tokens = {
210
+ comments: options.comments
211
+ };
212
+ if (((_a = this.tokens.comments) === null || _a === void 0 ? void 0 : _a.length) > 0) {
213
+ this.range = util_1.util.createBoundingRange(...this.tokens.comments);
211
214
  }
212
215
  }
213
216
  get text() {
214
- return this.comments.map(x => x.text).join('\n');
217
+ return this.tokens.comments.map(x => x.text).join('\n');
215
218
  }
216
219
  transpile(state) {
217
220
  let result = [];
218
- for (let i = 0; i < this.comments.length; i++) {
219
- let comment = this.comments[i];
221
+ for (let i = 0; i < this.tokens.comments.length; i++) {
222
+ let comment = this.tokens.comments[i];
220
223
  if (i > 0) {
221
224
  result.push(state.indent());
222
225
  }
223
226
  result.push(state.transpileToken(comment));
224
227
  //add newline for all except final comment
225
- if (i < this.comments.length - 1) {
228
+ if (i < this.tokens.comments.length - 1) {
226
229
  result.push('\n');
227
230
  }
228
231
  }
@@ -237,15 +240,18 @@ class CommentStatement extends AstNode_2.Statement {
237
240
  }
238
241
  exports.CommentStatement = CommentStatement;
239
242
  class ExitForStatement extends AstNode_2.Statement {
240
- constructor(tokens) {
243
+ constructor(options) {
244
+ var _a;
241
245
  super();
242
- this.tokens = tokens;
243
246
  this.kind = AstNode_1.AstNodeKind.ExitForStatement;
244
- this.range = this.tokens.exitFor.range;
247
+ this.tokens = {
248
+ exitFor: options === null || options === void 0 ? void 0 : options.exitFor
249
+ };
250
+ this.range = (_a = this.tokens.exitFor) === null || _a === void 0 ? void 0 : _a.range;
245
251
  }
246
252
  transpile(state) {
247
253
  return [
248
- state.transpileToken(this.tokens.exitFor)
254
+ this.tokens.exitFor ? state.transpileToken(this.tokens.exitFor) : 'exit for'
249
255
  ];
250
256
  }
251
257
  walk(visitor, options) {
@@ -254,15 +260,18 @@ class ExitForStatement extends AstNode_2.Statement {
254
260
  }
255
261
  exports.ExitForStatement = ExitForStatement;
256
262
  class ExitWhileStatement extends AstNode_2.Statement {
257
- constructor(tokens) {
263
+ constructor(options) {
264
+ var _a;
258
265
  super();
259
- this.tokens = tokens;
260
266
  this.kind = AstNode_1.AstNodeKind.ExitWhileStatement;
261
- this.range = this.tokens.exitWhile.range;
267
+ this.tokens = {
268
+ exitWhile: options === null || options === void 0 ? void 0 : options.exitWhile
269
+ };
270
+ this.range = (_a = this.tokens.exitWhile) === null || _a === void 0 ? void 0 : _a.range;
262
271
  }
263
272
  transpile(state) {
264
273
  return [
265
- state.transpileToken(this.tokens.exitWhile)
274
+ this.tokens.exitWhile ? state.transpileToken(this.tokens.exitWhile) : 'exit while'
266
275
  ];
267
276
  }
268
277
  walk(visitor, options) {
@@ -271,11 +280,16 @@ class ExitWhileStatement extends AstNode_2.Statement {
271
280
  }
272
281
  exports.ExitWhileStatement = ExitWhileStatement;
273
282
  class FunctionStatement extends AstNode_2.Statement {
274
- constructor(name, func) {
283
+ constructor(options) {
284
+ var _a;
275
285
  super();
276
- this.name = name;
277
- this.func = func;
278
286
  this.kind = AstNode_1.AstNodeKind.FunctionStatement;
287
+ this.tokens = {
288
+ name: options.name
289
+ };
290
+ this.func = options.func;
291
+ this.func.symbolTable.name += `: '${(_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text}'`;
292
+ this.func.functionStatement = this;
279
293
  this.range = this.func.range;
280
294
  }
281
295
  /**
@@ -287,10 +301,10 @@ class FunctionStatement extends AstNode_2.Statement {
287
301
  if (namespace) {
288
302
  let delimiter = parseMode === Parser_1.ParseMode.BrighterScript ? '.' : '_';
289
303
  let namespaceName = namespace.getName(parseMode);
290
- return namespaceName + delimiter + ((_a = this.name) === null || _a === void 0 ? void 0 : _a.text);
304
+ return namespaceName + delimiter + ((_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text);
291
305
  }
292
306
  else {
293
- return this.name.text;
307
+ return this.tokens.name.text;
294
308
  }
295
309
  }
296
310
  getLeadingTrivia() {
@@ -298,7 +312,7 @@ class FunctionStatement extends AstNode_2.Statement {
298
312
  }
299
313
  transpile(state) {
300
314
  //create a fake token using the full transpiled name
301
- let nameToken = Object.assign(Object.assign({}, this.name), { text: this.getName(Parser_1.ParseMode.BrightScript) });
315
+ let nameToken = Object.assign(Object.assign({}, this.tokens.name), { text: this.getName(Parser_1.ParseMode.BrightScript) });
302
316
  return this.func.transpile(state, nameToken);
303
317
  }
304
318
  getTypedef(state) {
@@ -318,26 +332,32 @@ class FunctionStatement extends AstNode_2.Statement {
318
332
  getType(options) {
319
333
  var _a;
320
334
  const funcExprType = this.func.getType(options);
321
- funcExprType.setName((_a = this.name) === null || _a === void 0 ? void 0 : _a.text);
335
+ funcExprType.setName((_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text);
322
336
  return funcExprType;
323
337
  }
324
338
  }
325
339
  exports.FunctionStatement = FunctionStatement;
326
340
  class IfStatement extends AstNode_2.Statement {
327
- constructor(tokens, condition, thenBranch, elseBranch, isInline) {
341
+ constructor(options) {
328
342
  super();
329
- this.tokens = tokens;
330
- this.condition = condition;
331
- this.thenBranch = thenBranch;
332
- this.elseBranch = elseBranch;
333
- this.isInline = isInline;
334
343
  this.kind = AstNode_1.AstNodeKind.IfStatement;
335
- this.range = util_1.util.createBoundingRange(tokens.if, condition, tokens.then, thenBranch, tokens.else, elseBranch, tokens.endIf);
344
+ this.condition = options.condition;
345
+ this.thenBranch = options.thenBranch;
346
+ this.elseBranch = options.elseBranch;
347
+ this.isInline = options.isInline;
348
+ this.tokens = {
349
+ if: options.if,
350
+ then: options.then,
351
+ else: options.else,
352
+ endIf: options.endIf
353
+ };
354
+ this.range = util_1.util.createBoundingRange(util_1.util.createBoundingRangeFromTokens(this.tokens), this.condition, this.thenBranch, this.elseBranch);
336
355
  }
337
356
  transpile(state) {
357
+ var _a;
338
358
  let results = [];
339
359
  //if (already indented by block)
340
- results.push(state.transpileToken(this.tokens.if));
360
+ results.push(state.transpileToken((_a = this.tokens.if) !== null && _a !== void 0 ? _a : (0, creators_1.createToken)(TokenKind_1.TokenKind.If)));
341
361
  results.push(' ');
342
362
  //conditions
343
363
  results.push(...this.condition.transpile(state));
@@ -411,17 +431,19 @@ class IfStatement extends AstNode_2.Statement {
411
431
  }
412
432
  exports.IfStatement = IfStatement;
413
433
  class IncrementStatement extends AstNode_2.Statement {
414
- constructor(value, operator) {
434
+ constructor(options) {
415
435
  super();
416
- this.value = value;
417
- this.operator = operator;
418
436
  this.kind = AstNode_1.AstNodeKind.IncrementStatement;
419
- this.range = util_1.util.createBoundingRange(value, operator);
437
+ this.value = options.value;
438
+ this.tokens = {
439
+ operator: options.operator
440
+ };
441
+ this.range = util_1.util.createBoundingRange(this.value, this.tokens.operator);
420
442
  }
421
443
  transpile(state) {
422
444
  return [
423
445
  ...this.value.transpile(state),
424
- state.transpileToken(this.operator)
446
+ state.transpileToken(this.tokens.operator)
425
447
  ];
426
448
  }
427
449
  walk(visitor, options) {
@@ -437,16 +459,19 @@ exports.IncrementStatement = IncrementStatement;
437
459
  class PrintStatement extends AstNode_2.Statement {
438
460
  /**
439
461
  * Creates a new internal representation of a BrightScript `print` statement.
440
- * @param tokens the tokens for this statement
441
- * @param tokens.print a print token
442
- * @param expressions an array of expressions or `PrintSeparator`s to be evaluated and printed.
462
+ * @param options the options for this statement
463
+ * @param options.print a print token
464
+ * @param options.expressions an array of expressions or `PrintSeparator`s to be evaluated and printed.
443
465
  */
444
- constructor(tokens, expressions) {
466
+ constructor(options) {
467
+ var _a;
445
468
  super();
446
- this.tokens = tokens;
447
- this.expressions = expressions;
448
469
  this.kind = AstNode_1.AstNodeKind.PrintStatement;
449
- this.range = util_1.util.createBoundingRange(tokens.print, ...(expressions !== null && expressions !== void 0 ? expressions : []));
470
+ this.tokens = {
471
+ print: options.print
472
+ };
473
+ this.expressions = options.expressions;
474
+ this.range = util_1.util.createBoundingRange(this.tokens.print, ...((_a = this.expressions) !== null && _a !== void 0 ? _a : []));
450
475
  }
451
476
  transpile(state) {
452
477
  var _a;
@@ -478,22 +503,25 @@ class PrintStatement extends AstNode_2.Statement {
478
503
  }
479
504
  exports.PrintStatement = PrintStatement;
480
505
  class DimStatement extends AstNode_2.Statement {
481
- constructor(dimToken, identifier, openingSquare, dimensions, closingSquare) {
506
+ constructor(options) {
507
+ var _a;
482
508
  super();
483
- this.dimToken = dimToken;
484
- this.identifier = identifier;
485
- this.openingSquare = openingSquare;
486
- this.dimensions = dimensions;
487
- this.closingSquare = closingSquare;
488
509
  this.kind = AstNode_1.AstNodeKind.DimStatement;
489
- this.range = util_1.util.createBoundingRange(dimToken, identifier, openingSquare, ...(dimensions !== null && dimensions !== void 0 ? dimensions : []), closingSquare);
510
+ this.tokens = {
511
+ dim: options === null || options === void 0 ? void 0 : options.dim,
512
+ name: options.name,
513
+ openingSquare: options.openingSquare,
514
+ closingSquare: options.closingSquare
515
+ };
516
+ this.dimensions = options.dimensions;
517
+ this.range = util_1.util.createBoundingRange(options.dim, options.name, options.openingSquare, ...((_a = this.dimensions) !== null && _a !== void 0 ? _a : []), options.closingSquare);
490
518
  }
491
519
  transpile(state) {
492
520
  let result = [
493
- state.transpileToken(this.dimToken),
521
+ state.transpileToken(this.tokens.dim, 'dim'),
494
522
  ' ',
495
- state.transpileToken(this.identifier),
496
- state.transpileToken(this.openingSquare)
523
+ state.transpileToken(this.tokens.name),
524
+ state.transpileToken(this.tokens.openingSquare, '[')
497
525
  ];
498
526
  for (let i = 0; i < this.dimensions.length; i++) {
499
527
  if (i > 0) {
@@ -501,7 +529,7 @@ class DimStatement extends AstNode_2.Statement {
501
529
  }
502
530
  result.push(...this.dimensions[i].transpile(state));
503
531
  }
504
- result.push(state.transpileToken(this.closingSquare));
532
+ result.push(state.transpileToken(this.tokens.closingSquare, ']'));
505
533
  return result;
506
534
  }
507
535
  walk(visitor, options) {
@@ -510,18 +538,30 @@ class DimStatement extends AstNode_2.Statement {
510
538
  (0, visitors_1.walkArray)(this.dimensions, visitor, options, this);
511
539
  }
512
540
  }
541
+ getType(options) {
542
+ var _a, _b;
543
+ const numDimensions = (_b = (_a = this.dimensions) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1;
544
+ let type = new ArrayType_1.ArrayType();
545
+ for (let i = 0; i < numDimensions - 1; i++) {
546
+ type = new ArrayType_1.ArrayType(type);
547
+ }
548
+ return type;
549
+ }
513
550
  }
514
551
  exports.DimStatement = DimStatement;
515
552
  class GotoStatement extends AstNode_2.Statement {
516
- constructor(tokens) {
553
+ constructor(options) {
517
554
  super();
518
- this.tokens = tokens;
519
555
  this.kind = AstNode_1.AstNodeKind.GotoStatement;
520
- this.range = util_1.util.createBoundingRange(tokens.goto, tokens.label);
556
+ this.tokens = {
557
+ goto: options.goto,
558
+ label: options.label
559
+ };
560
+ this.range = util_1.util.createBoundingRange(this.tokens.goto, this.tokens.label);
521
561
  }
522
562
  transpile(state) {
523
563
  return [
524
- state.transpileToken(this.tokens.goto),
564
+ state.transpileToken(this.tokens.goto, 'goto'),
525
565
  ' ',
526
566
  state.transpileToken(this.tokens.label)
527
567
  ];
@@ -532,19 +572,22 @@ class GotoStatement extends AstNode_2.Statement {
532
572
  }
533
573
  exports.GotoStatement = GotoStatement;
534
574
  class LabelStatement extends AstNode_2.Statement {
535
- constructor(tokens) {
575
+ constructor(options) {
536
576
  super();
537
- this.tokens = tokens;
538
577
  this.kind = AstNode_1.AstNodeKind.LabelStatement;
539
- this.range = util_1.util.createBoundingRange(tokens.identifier, tokens.colon);
578
+ this.tokens = {
579
+ name: options.name,
580
+ colon: options.colon
581
+ };
582
+ this.range = util_1.util.createBoundingRange(this.tokens.name, this.tokens.colon);
540
583
  }
541
584
  getLeadingTrivia() {
542
- return util_1.util.concatAnnotationLeadingTrivia(this, this.tokens.identifier.leadingTrivia);
585
+ return util_1.util.concatAnnotationLeadingTrivia(this, this.tokens.name.leadingTrivia);
543
586
  }
544
587
  transpile(state) {
545
588
  return [
546
- state.transpileToken(this.tokens.identifier),
547
- state.transpileToken(this.tokens.colon)
589
+ state.transpileToken(this.tokens.name),
590
+ state.transpileToken(this.tokens.colon, ':')
548
591
  ];
549
592
  }
550
593
  walk(visitor, options) {
@@ -553,16 +596,18 @@ class LabelStatement extends AstNode_2.Statement {
553
596
  }
554
597
  exports.LabelStatement = LabelStatement;
555
598
  class ReturnStatement extends AstNode_2.Statement {
556
- constructor(tokens, value) {
599
+ constructor(options) {
557
600
  super();
558
- this.tokens = tokens;
559
- this.value = value;
560
601
  this.kind = AstNode_1.AstNodeKind.ReturnStatement;
561
- this.range = util_1.util.createBoundingRange(tokens.return, value);
602
+ this.tokens = {
603
+ return: options === null || options === void 0 ? void 0 : options.return
604
+ };
605
+ this.value = options === null || options === void 0 ? void 0 : options.value;
606
+ this.range = util_1.util.createBoundingRange(this.tokens.return, this.value);
562
607
  }
563
608
  transpile(state) {
564
609
  let result = [];
565
- result.push(state.transpileToken(this.tokens.return));
610
+ result.push(state.transpileToken(this.tokens.return, 'return'));
566
611
  if (this.value) {
567
612
  result.push(' ');
568
613
  result.push(...this.value.transpile(state));
@@ -577,15 +622,18 @@ class ReturnStatement extends AstNode_2.Statement {
577
622
  }
578
623
  exports.ReturnStatement = ReturnStatement;
579
624
  class EndStatement extends AstNode_2.Statement {
580
- constructor(tokens) {
625
+ constructor(options) {
626
+ var _a;
581
627
  super();
582
- this.tokens = tokens;
583
628
  this.kind = AstNode_1.AstNodeKind.EndStatement;
584
- this.range = tokens.end.range;
629
+ this.tokens = {
630
+ end: options === null || options === void 0 ? void 0 : options.end
631
+ };
632
+ this.range = (_a = this.tokens.end) === null || _a === void 0 ? void 0 : _a.range;
585
633
  }
586
634
  transpile(state) {
587
635
  return [
588
- state.transpileToken(this.tokens.end)
636
+ state.transpileToken(this.tokens.end, 'end')
589
637
  ];
590
638
  }
591
639
  walk(visitor, options) {
@@ -594,16 +642,16 @@ class EndStatement extends AstNode_2.Statement {
594
642
  }
595
643
  exports.EndStatement = EndStatement;
596
644
  class StopStatement extends AstNode_2.Statement {
597
- constructor(tokens) {
598
- var _a;
645
+ constructor(options) {
646
+ var _a, _b;
599
647
  super();
600
- this.tokens = tokens;
601
648
  this.kind = AstNode_1.AstNodeKind.StopStatement;
602
- this.range = (_a = tokens === null || tokens === void 0 ? void 0 : tokens.stop) === null || _a === void 0 ? void 0 : _a.range;
649
+ this.tokens = { stop: options === null || options === void 0 ? void 0 : options.stop };
650
+ this.range = (_b = (_a = this.tokens) === null || _a === void 0 ? void 0 : _a.stop) === null || _b === void 0 ? void 0 : _b.range;
603
651
  }
604
652
  transpile(state) {
605
653
  return [
606
- state.transpileToken(this.tokens.stop)
654
+ state.transpileToken(this.tokens.stop, 'stop')
607
655
  ];
608
656
  }
609
657
  walk(visitor, options) {
@@ -612,32 +660,34 @@ class StopStatement extends AstNode_2.Statement {
612
660
  }
613
661
  exports.StopStatement = StopStatement;
614
662
  class ForStatement extends AstNode_2.Statement {
615
- constructor(forToken, counterDeclaration, toToken, finalValue, body, endForToken, stepToken, increment) {
663
+ constructor(options) {
616
664
  super();
617
- this.forToken = forToken;
618
- this.counterDeclaration = counterDeclaration;
619
- this.toToken = toToken;
620
- this.finalValue = finalValue;
621
- this.body = body;
622
- this.endForToken = endForToken;
623
- this.stepToken = stepToken;
624
- this.increment = increment;
625
665
  this.kind = AstNode_1.AstNodeKind.ForStatement;
626
- this.range = util_1.util.createBoundingRange(forToken, counterDeclaration, toToken, finalValue, stepToken, increment, body, endForToken);
666
+ this.tokens = {
667
+ for: options.for,
668
+ to: options.to,
669
+ endFor: options.endFor,
670
+ step: options.step
671
+ };
672
+ this.counterDeclaration = options.counterDeclaration;
673
+ this.finalValue = options.finalValue;
674
+ this.body = options.body;
675
+ this.increment = options.increment;
676
+ this.range = util_1.util.createBoundingRange(this.tokens.for, this.counterDeclaration, this.tokens.to, this.finalValue, this.tokens.step, this.increment, this.body, this.tokens.endFor);
627
677
  }
628
678
  transpile(state) {
629
679
  let result = [];
630
680
  //for
631
- result.push(state.transpileToken(this.forToken), ' ');
681
+ result.push(state.transpileToken(this.tokens.for, 'for'), ' ');
632
682
  //i=1
633
683
  result.push(...this.counterDeclaration.transpile(state), ' ');
634
684
  //to
635
- result.push(state.transpileToken(this.toToken), ' ');
685
+ result.push(state.transpileToken(this.tokens.to, 'to'), ' ');
636
686
  //final value
637
687
  result.push(this.finalValue.transpile(state));
638
688
  //step
639
- if (this.stepToken) {
640
- result.push(' ', state.transpileToken(this.stepToken), ' ', this.increment.transpile(state));
689
+ if (this.increment) {
690
+ result.push(' ', state.transpileToken(this.tokens.step, 'step'), ' ', this.increment.transpile(state));
641
691
  }
642
692
  //loop body
643
693
  state.lineage.unshift(this);
@@ -646,7 +696,7 @@ class ForStatement extends AstNode_2.Statement {
646
696
  // add new line before "end for"
647
697
  result.push('\n');
648
698
  //end for
649
- result.push(state.indent(), state.transpileToken(this.endForToken));
699
+ result.push(state.indent(), state.transpileToken(this.tokens.endFor, 'end for'));
650
700
  return result;
651
701
  }
652
702
  walk(visitor, options) {
@@ -664,23 +714,27 @@ class ForStatement extends AstNode_2.Statement {
664
714
  }
665
715
  exports.ForStatement = ForStatement;
666
716
  class ForEachStatement extends AstNode_2.Statement {
667
- constructor(tokens, item, target, body) {
717
+ constructor(options) {
668
718
  super();
669
- this.tokens = tokens;
670
- this.item = item;
671
- this.target = target;
672
- this.body = body;
673
719
  this.kind = AstNode_1.AstNodeKind.ForEachStatement;
674
- this.range = util_1.util.createBoundingRange(tokens.forEach, item, tokens.in, target, body, tokens.endFor);
720
+ this.tokens = {
721
+ forEach: options.forEach,
722
+ item: options.item,
723
+ in: options.in,
724
+ endFor: options.endFor
725
+ };
726
+ this.body = options.body;
727
+ this.target = options.target;
728
+ this.range = util_1.util.createBoundingRange(this.tokens.forEach, this.tokens.item, this.tokens.in, this.target, this.body, this.tokens.endFor);
675
729
  }
676
730
  transpile(state) {
677
731
  let result = [];
678
732
  //for each
679
- result.push(state.transpileToken(this.tokens.forEach), ' ');
733
+ result.push(state.transpileToken(this.tokens.forEach, 'for each'), ' ');
680
734
  //item
681
- result.push(state.transpileToken(this.item), ' ');
735
+ result.push(state.transpileToken(this.tokens.item), ' ');
682
736
  //in
683
- result.push(state.transpileToken(this.tokens.in), ' ');
737
+ result.push(state.transpileToken(this.tokens.in, 'in'), ' ');
684
738
  //target
685
739
  result.push(...this.target.transpile(state));
686
740
  //body
@@ -690,7 +744,7 @@ class ForEachStatement extends AstNode_2.Statement {
690
744
  // add new line before "end for"
691
745
  result.push('\n');
692
746
  //end for
693
- result.push(state.indent(), state.transpileToken(this.tokens.endFor));
747
+ result.push(state.indent(), state.transpileToken(this.tokens.endFor, 'end for'));
694
748
  return result;
695
749
  }
696
750
  walk(visitor, options) {
@@ -704,18 +758,21 @@ class ForEachStatement extends AstNode_2.Statement {
704
758
  }
705
759
  exports.ForEachStatement = ForEachStatement;
706
760
  class WhileStatement extends AstNode_2.Statement {
707
- constructor(tokens, condition, body) {
761
+ constructor(options) {
708
762
  super();
709
- this.tokens = tokens;
710
- this.condition = condition;
711
- this.body = body;
712
763
  this.kind = AstNode_1.AstNodeKind.WhileStatement;
713
- this.range = util_1.util.createBoundingRange(tokens.while, condition, body, tokens.endWhile);
764
+ this.tokens = {
765
+ while: options.while,
766
+ endWhile: options.endWhile
767
+ };
768
+ this.body = options.body;
769
+ this.condition = options.condition;
770
+ this.range = util_1.util.createBoundingRange(this.tokens.while, this.condition, this.body, this.tokens.endWhile);
714
771
  }
715
772
  transpile(state) {
716
773
  let result = [];
717
774
  //while
718
- result.push(state.transpileToken(this.tokens.while), ' ');
775
+ result.push(state.transpileToken(this.tokens.while, 'while'), ' ');
719
776
  //condition
720
777
  result.push(...this.condition.transpile(state));
721
778
  state.lineage.unshift(this);
@@ -725,7 +782,7 @@ class WhileStatement extends AstNode_2.Statement {
725
782
  //trailing newline only if we have body statements
726
783
  result.push('\n');
727
784
  //end while
728
- result.push(state.indent(), state.transpileToken(this.tokens.endWhile));
785
+ result.push(state.indent(), state.transpileToken(this.tokens.endWhile, 'end while'));
729
786
  return result;
730
787
  }
731
788
  walk(visitor, options) {
@@ -739,28 +796,30 @@ class WhileStatement extends AstNode_2.Statement {
739
796
  }
740
797
  exports.WhileStatement = WhileStatement;
741
798
  class DottedSetStatement extends AstNode_2.Statement {
742
- constructor(obj, name, value, dot) {
799
+ constructor(options) {
743
800
  super();
744
- this.obj = obj;
745
- this.name = name;
746
- this.value = value;
747
- this.dot = dot;
748
801
  this.kind = AstNode_1.AstNodeKind.DottedSetStatement;
749
- this.range = util_1.util.createBoundingRange(obj, dot, name, value);
802
+ this.tokens = {
803
+ name: options.name,
804
+ dot: options.dot
805
+ };
806
+ this.obj = options.obj;
807
+ this.value = options.value;
808
+ this.range = util_1.util.createBoundingRange(this.obj, this.tokens.dot, this.tokens.name, this.value);
750
809
  }
751
810
  transpile(state) {
752
- var _a, _b;
811
+ var _a, _b, _c;
753
812
  //if the value is a compound assignment, don't add the obj, dot, name, or operator...the expression will handle that
754
- if (TokenKind_1.CompoundAssignmentOperators.includes((_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.operator) === null || _b === void 0 ? void 0 : _b.kind)) {
813
+ if (TokenKind_1.CompoundAssignmentOperators.includes((_c = (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.operator) === null || _c === void 0 ? void 0 : _c.kind)) {
755
814
  return this.value.transpile(state);
756
815
  }
757
816
  else {
758
817
  return [
759
818
  //object
760
819
  ...this.obj.transpile(state),
761
- this.dot ? state.tokenToSourceNode(this.dot) : '.',
820
+ this.tokens.dot ? state.tokenToSourceNode(this.tokens.dot) : '.',
762
821
  //name
763
- state.transpileToken(this.name),
822
+ state.transpileToken(this.tokens.name),
764
823
  ' = ',
765
824
  //right-hand-side of assignment
766
825
  ...this.value.transpile(state)
@@ -776,60 +835,72 @@ class DottedSetStatement extends AstNode_2.Statement {
776
835
  getType(options) {
777
836
  var _a, _b, _c, _d, _e, _f;
778
837
  const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
779
- const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.name) === null || _b === void 0 ? void 0 : _b.text, options);
780
- (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry((_d = this.name) === null || _d === void 0 ? void 0 : _d.text, result, options.data, (_f = (_e = this.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range));
838
+ const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text, options);
839
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
840
+ name: (_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text,
841
+ type: result, data: options.data,
842
+ range: (_f = (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range,
843
+ kind: this.kind
844
+ }));
781
845
  return result;
782
846
  }
783
847
  }
784
848
  exports.DottedSetStatement = DottedSetStatement;
785
849
  class IndexedSetStatement extends AstNode_2.Statement {
786
- constructor(obj, index, value, openingSquare, closingSquare) {
850
+ constructor(options) {
787
851
  super();
788
- this.obj = obj;
789
- this.index = index;
790
- this.value = value;
791
- this.openingSquare = openingSquare;
792
- this.closingSquare = closingSquare;
793
852
  this.kind = AstNode_1.AstNodeKind.IndexedSetStatement;
794
- this.range = util_1.util.createBoundingRange(obj, openingSquare, index, closingSquare, value);
853
+ this.tokens = {
854
+ openingSquare: options.openingSquare,
855
+ closingSquare: options.closingSquare
856
+ };
857
+ this.obj = options.obj;
858
+ this.indexes = options.indexes;
859
+ this.value = options.value;
860
+ this.range = util_1.util.createBoundingRange(this.obj, this.tokens.openingSquare, ...this.indexes, this.tokens.closingSquare, this.value);
795
861
  }
796
862
  transpile(state) {
797
- var _a, _b;
863
+ var _a, _b, _c, _d;
798
864
  //if the value is a component assignment, don't add the obj, index or operator...the expression will handle that
799
- if (TokenKind_1.CompoundAssignmentOperators.includes((_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.operator) === null || _b === void 0 ? void 0 : _b.kind)) {
865
+ if (TokenKind_1.CompoundAssignmentOperators.includes((_c = (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.operator) === null || _c === void 0 ? void 0 : _c.kind)) {
800
866
  return this.value.transpile(state);
801
867
  }
802
868
  else {
803
- return [
804
- //obj
805
- ...this.obj.transpile(state),
806
- // [
807
- state.transpileToken(this.openingSquare),
808
- // index
809
- ...this.index.transpile(state),
810
- // ]
811
- state.transpileToken(this.closingSquare),
812
- // =
813
- ' = ',
814
- // value
815
- ...this.value.transpile(state)
816
- ];
869
+ const result = [];
870
+ result.push(
871
+ //obj
872
+ ...this.obj.transpile(state),
873
+ // [
874
+ state.transpileToken(this.tokens.openingSquare));
875
+ for (let i = 0; i < this.indexes.length; i++) {
876
+ //add comma between indexes
877
+ if (i > 0) {
878
+ result.push(', ');
879
+ }
880
+ let index = this.indexes[i];
881
+ result.push(...((_d = index === null || index === void 0 ? void 0 : index.transpile(state)) !== null && _d !== void 0 ? _d : []));
882
+ }
883
+ result.push(state.transpileToken(this.tokens.closingSquare), ' = ', ...this.value.transpile(state));
884
+ return result;
817
885
  }
818
886
  }
819
887
  walk(visitor, options) {
820
888
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
821
889
  (0, visitors_1.walk)(this, 'obj', visitor, options);
822
- (0, visitors_1.walk)(this, 'index', visitor, options);
890
+ (0, visitors_1.walkArray)(this.indexes, visitor, options, this);
823
891
  (0, visitors_1.walk)(this, 'value', visitor, options);
824
892
  }
825
893
  }
826
894
  }
827
895
  exports.IndexedSetStatement = IndexedSetStatement;
828
896
  class LibraryStatement extends AstNode_2.Statement {
829
- constructor(tokens) {
897
+ constructor(options) {
830
898
  super();
831
- this.tokens = tokens;
832
899
  this.kind = AstNode_1.AstNodeKind.LibraryStatement;
900
+ this.tokens = {
901
+ library: options.library,
902
+ filePath: options.filePath
903
+ };
833
904
  this.range = util_1.util.createBoundingRange(this.tokens.library, this.tokens.filePath);
834
905
  }
835
906
  transpile(state) {
@@ -850,15 +921,17 @@ class LibraryStatement extends AstNode_2.Statement {
850
921
  }
851
922
  exports.LibraryStatement = LibraryStatement;
852
923
  class NamespaceStatement extends AstNode_2.Statement {
853
- constructor(keyword, nameExpression, body, endKeyword) {
924
+ constructor(options) {
854
925
  super();
855
- this.keyword = keyword;
856
- this.nameExpression = nameExpression;
857
- this.body = body;
858
- this.endKeyword = endKeyword;
859
926
  this.kind = AstNode_1.AstNodeKind.NamespaceStatement;
927
+ this.tokens = {
928
+ namespace: options.namespace,
929
+ endNamespace: options.endNamespace
930
+ };
931
+ this.nameExpression = options.nameExpression;
932
+ this.body = options.body;
860
933
  this.name = this.getName(Parser_1.ParseMode.BrighterScript);
861
- this.symbolTable = new SymbolTable_2.SymbolTable(`NamespaceStatement: '${this.name}'`, () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
934
+ this.symbolTable = new SymbolTable_1.SymbolTable(`NamespaceStatement: '${this.name}'`, () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
862
935
  }
863
936
  get range() {
864
937
  return this.cacheRange();
@@ -866,7 +939,7 @@ class NamespaceStatement extends AstNode_2.Statement {
866
939
  cacheRange() {
867
940
  var _a;
868
941
  if (!this._range) {
869
- this._range = (_a = util_1.util.createBoundingRange(this.keyword, this.nameExpression, this.body, this.endKeyword)) !== null && _a !== void 0 ? _a : creators_1.interpolatedRange;
942
+ this._range = (_a = util_1.util.createBoundingRange(this.tokens.namespace, this.nameExpression, this.body, this.tokens.endNamespace)) !== null && _a !== void 0 ? _a : creators_1.interpolatedRange;
870
943
  }
871
944
  return this._range;
872
945
  }
@@ -880,7 +953,8 @@ class NamespaceStatement extends AstNode_2.Statement {
880
953
  return name;
881
954
  }
882
955
  getLeadingTrivia() {
883
- return util_1.util.concatAnnotationLeadingTrivia(this, this.keyword.leadingTrivia);
956
+ var _a;
957
+ return util_1.util.concatAnnotationLeadingTrivia(this, (_a = this.tokens.namespace) === null || _a === void 0 ? void 0 : _a.leadingTrivia);
884
958
  }
885
959
  getNameParts() {
886
960
  var _a, _b;
@@ -921,17 +995,19 @@ class NamespaceStatement extends AstNode_2.Statement {
921
995
  }
922
996
  exports.NamespaceStatement = NamespaceStatement;
923
997
  class ImportStatement extends AstNode_2.Statement {
924
- constructor(importToken, filePathToken) {
998
+ constructor(options) {
925
999
  super();
926
- this.importToken = importToken;
927
- this.filePathToken = filePathToken;
928
1000
  this.kind = AstNode_1.AstNodeKind.ImportStatement;
929
- this.range = util_1.util.createBoundingRange(importToken, filePathToken);
930
- if (this.filePathToken) {
1001
+ this.tokens = {
1002
+ import: options.import,
1003
+ path: options.path
1004
+ };
1005
+ this.range = util_1.util.createBoundingRange(this.tokens.import, this.tokens.path);
1006
+ if (this.tokens.path) {
931
1007
  //remove quotes
932
- this.filePath = this.filePathToken.text.replace(/"/g, '');
1008
+ this.filePath = this.tokens.path.text.replace(/"/g, '');
933
1009
  //adjust the range to exclude the quotes
934
- this.filePathToken.range = util_1.util.createRange(this.filePathToken.range.start.line, this.filePathToken.range.start.character + 1, this.filePathToken.range.end.line, this.filePathToken.range.end.character - 1);
1010
+ this.tokens.path.range = util_1.util.createRange(this.tokens.path.range.start.line, this.tokens.path.range.start.character + 1, this.tokens.path.range.end.line, this.tokens.path.range.end.character - 1);
935
1011
  }
936
1012
  }
937
1013
  transpile(state) {
@@ -939,20 +1015,21 @@ class ImportStatement extends AstNode_2.Statement {
939
1015
  //add the import statement as a comment just for debugging purposes
940
1016
  return [
941
1017
  `'`,
942
- state.transpileToken(this.importToken),
1018
+ state.transpileToken(this.tokens.import, 'import'),
943
1019
  ' ',
944
- state.transpileToken(this.filePathToken)
1020
+ state.transpileToken(this.tokens.path)
945
1021
  ];
946
1022
  }
947
1023
  /**
948
1024
  * Get the typedef for this statement
949
1025
  */
950
1026
  getTypedef(state) {
1027
+ var _a, _b;
951
1028
  return [
952
- this.importToken.text,
1029
+ (_b = (_a = this.tokens.import) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'import',
953
1030
  ' ',
954
1031
  //replace any `.bs` extension with `.brs`
955
- this.filePathToken.text.replace(/\.bs"?$/i, '.brs"')
1032
+ this.tokens.path.text.replace(/\.bs"?$/i, '.brs"')
956
1033
  ];
957
1034
  }
958
1035
  walk(visitor, options) {
@@ -961,16 +1038,18 @@ class ImportStatement extends AstNode_2.Statement {
961
1038
  }
962
1039
  exports.ImportStatement = ImportStatement;
963
1040
  class InterfaceStatement extends AstNode_2.Statement {
964
- constructor(interfaceToken, name, extendsToken, parentInterfaceName, body, endInterfaceToken) {
1041
+ constructor(options) {
965
1042
  super();
966
- this.parentInterfaceName = parentInterfaceName;
967
- this.body = body;
968
1043
  this.kind = AstNode_1.AstNodeKind.InterfaceStatement;
969
1044
  this.tokens = {};
970
- this.tokens.interface = interfaceToken;
971
- this.tokens.name = name;
972
- this.tokens.extends = extendsToken;
973
- this.tokens.endInterface = endInterfaceToken;
1045
+ this.tokens = {
1046
+ interface: options.interface,
1047
+ name: options.name,
1048
+ extends: options.extends,
1049
+ endInterface: options.endInterface
1050
+ };
1051
+ this.parentInterfaceName = options.parentInterfaceName;
1052
+ this.body = options.body;
974
1053
  this.range = util_1.util.createBoundingRange(this.tokens.interface, this.tokens.name, this.tokens.extends, this.parentInterfaceName, ...this.body, this.tokens.endInterface);
975
1054
  }
976
1055
  get fields() {
@@ -1073,28 +1152,35 @@ class InterfaceStatement extends AstNode_2.Statement {
1073
1152
  const resultType = new InterfaceType_1.InterfaceType(this.getName(Parser_1.ParseMode.BrighterScript), superIface);
1074
1153
  for (const statement of this.methods) {
1075
1154
  const memberType = statement === null || statement === void 0 ? void 0 : statement.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); // no typechain info needed
1076
- const flag = statement.isOptional ? SymbolTable_1.SymbolTypeFlag.runtime | SymbolTable_1.SymbolTypeFlag.optional : SymbolTable_1.SymbolTypeFlag.runtime;
1155
+ const flag = statement.isOptional ? 1 /* SymbolTypeFlag.runtime */ | 4 /* SymbolTypeFlag.optional */ : 1 /* SymbolTypeFlag.runtime */;
1077
1156
  resultType.addMember((_b = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _b === void 0 ? void 0 : _b.text, { definingNode: statement }, memberType, flag);
1078
1157
  }
1079
1158
  for (const statement of this.fields) {
1080
1159
  const memberType = statement === null || statement === void 0 ? void 0 : statement.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); // no typechain info needed
1081
- const flag = statement.isOptional ? SymbolTable_1.SymbolTypeFlag.runtime | SymbolTable_1.SymbolTypeFlag.optional : SymbolTable_1.SymbolTypeFlag.runtime;
1160
+ const flag = statement.isOptional ? 1 /* SymbolTypeFlag.runtime */ | 4 /* SymbolTypeFlag.optional */ : 1 /* SymbolTypeFlag.runtime */;
1082
1161
  resultType.addMember((_c = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _c === void 0 ? void 0 : _c.text, { definingNode: statement }, memberType, flag);
1083
1162
  }
1084
- (_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry(this.getName(Parser_1.ParseMode.BrighterScript), resultType, options.data, this.range));
1163
+ (_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry({
1164
+ name: this.getName(Parser_1.ParseMode.BrighterScript),
1165
+ type: resultType,
1166
+ data: options.data,
1167
+ range: this.range,
1168
+ kind: this.kind
1169
+ }));
1085
1170
  return resultType;
1086
1171
  }
1087
1172
  }
1088
1173
  exports.InterfaceStatement = InterfaceStatement;
1089
1174
  class InterfaceFieldStatement extends AstNode_2.Statement {
1090
- constructor(nameToken, asToken, typeExpression, optionalToken) {
1175
+ constructor(options) {
1091
1176
  super();
1092
- this.typeExpression = typeExpression;
1093
1177
  this.kind = AstNode_1.AstNodeKind.InterfaceFieldStatement;
1094
- this.tokens = {};
1095
- this.tokens.optional = optionalToken;
1096
- this.tokens.name = nameToken;
1097
- this.tokens.as = asToken;
1178
+ this.tokens = {
1179
+ optional: options.optional,
1180
+ name: options.name,
1181
+ as: options.as
1182
+ };
1183
+ this.typeExpression = options.typeExpression;
1098
1184
  this.range = util_1.util.createBoundingRange(this.tokens.optional, this.tokens.name, this.tokens.as, this.typeExpression);
1099
1185
  }
1100
1186
  transpile(state) {
@@ -1139,18 +1225,20 @@ exports.InterfaceFieldStatement = InterfaceFieldStatement;
1139
1225
  //TODO: there is much that is similar with this and FunctionExpression.
1140
1226
  //It would be nice to refactor this so there is less duplicated code
1141
1227
  class InterfaceMethodStatement extends AstNode_2.Statement {
1142
- constructor(functionTypeToken, nameToken, leftParen, params, rightParen, asToken, returnTypeExpression, optionalToken) {
1228
+ constructor(options) {
1229
+ var _a;
1143
1230
  super();
1144
- this.params = params;
1145
- this.returnTypeExpression = returnTypeExpression;
1146
1231
  this.kind = AstNode_1.AstNodeKind.InterfaceMethodStatement;
1147
- this.tokens = {};
1148
- this.tokens.optional = optionalToken;
1149
- this.tokens.functionType = functionTypeToken;
1150
- this.tokens.name = nameToken;
1151
- this.tokens.leftParen = leftParen;
1152
- this.tokens.rightParen = rightParen;
1153
- this.tokens.as = asToken;
1232
+ this.tokens = {
1233
+ optional: options.optional,
1234
+ functionType: options.functionType,
1235
+ name: options.name,
1236
+ leftParen: options.leftParen,
1237
+ rightParen: options.rightParen,
1238
+ as: options.as
1239
+ };
1240
+ this.params = (_a = options.params) !== null && _a !== void 0 ? _a : [];
1241
+ this.returnTypeExpression = options.returnTypeExpression;
1154
1242
  }
1155
1243
  transpile(state) {
1156
1244
  throw new Error('Method not implemented.');
@@ -1178,7 +1266,7 @@ class InterfaceMethodStatement extends AstNode_2.Statement {
1178
1266
  }
1179
1267
  }
1180
1268
  getTypedef(state) {
1181
- var _a, _b;
1269
+ var _a, _b, _c, _d;
1182
1270
  const result = [];
1183
1271
  for (let annotation of (_a = this.annotations) !== null && _a !== void 0 ? _a : []) {
1184
1272
  result.push(...annotation.getTypedef(state), state.newline, state.indent());
@@ -1186,14 +1274,14 @@ class InterfaceMethodStatement extends AstNode_2.Statement {
1186
1274
  if (this.isOptional) {
1187
1275
  result.push(this.tokens.optional.text, ' ');
1188
1276
  }
1189
- result.push(this.tokens.functionType.text, ' ', this.tokens.name.text, '(');
1190
- const params = (_b = this.params) !== null && _b !== void 0 ? _b : [];
1277
+ result.push((_c = (_b = this.tokens.functionType) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : 'function', ' ', this.tokens.name.text, '(');
1278
+ const params = (_d = this.params) !== null && _d !== void 0 ? _d : [];
1191
1279
  for (let i = 0; i < params.length; i++) {
1192
1280
  if (i > 0) {
1193
1281
  result.push(', ');
1194
1282
  }
1195
1283
  const param = params[i];
1196
- result.push(param.name.text);
1284
+ result.push(param.tokens.name.text);
1197
1285
  if (param.typeExpression) {
1198
1286
  result.push(' as ', ...param.typeExpression.getTypedef(state));
1199
1287
  }
@@ -1205,10 +1293,10 @@ class InterfaceMethodStatement extends AstNode_2.Statement {
1205
1293
  return result;
1206
1294
  }
1207
1295
  getType(options) {
1208
- var _a, _b, _c;
1296
+ var _a, _b, _c, _d;
1209
1297
  //if there's a defined return type, use that
1210
1298
  let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(options);
1211
- const isSub = this.tokens.functionType.kind === TokenKind_1.TokenKind.Sub;
1299
+ const isSub = ((_b = this.tokens.functionType) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Sub || !returnType;
1212
1300
  //if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
1213
1301
  if (!returnType) {
1214
1302
  returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
@@ -1216,54 +1304,51 @@ class InterfaceMethodStatement extends AstNode_2.Statement {
1216
1304
  const resultType = new TypedFunctionType_1.TypedFunctionType(returnType);
1217
1305
  resultType.isSub = isSub;
1218
1306
  for (let param of this.params) {
1219
- resultType.addParameter(param.name.text, param.getType(options), !!param.defaultValue);
1307
+ resultType.addParameter(param.tokens.name.text, param.getType(options), !!param.defaultValue);
1220
1308
  }
1221
1309
  if (options.typeChain) {
1222
1310
  // need Interface type for type chain
1223
- (_b = this.parent) === null || _b === void 0 ? void 0 : _b.getType(options);
1311
+ (_c = this.parent) === null || _c === void 0 ? void 0 : _c.getType(options);
1224
1312
  }
1225
1313
  let funcName = this.getName(Parser_1.ParseMode.BrighterScript);
1226
1314
  resultType.setName(funcName);
1227
- (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry(resultType.name, resultType, options.data, this.range));
1315
+ (_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry({ name: resultType.name, type: resultType, data: options.data, range: this.range, kind: this.kind }));
1228
1316
  return resultType;
1229
1317
  }
1230
1318
  }
1231
1319
  exports.InterfaceMethodStatement = InterfaceMethodStatement;
1232
1320
  class ClassStatement extends AstNode_2.Statement {
1233
- constructor(classKeyword,
1234
- /**
1235
- * The name of the class (without namespace prefix)
1236
- */
1237
- name, body, end, extendsKeyword, parentClassName) {
1238
- var _a, _b, _c, _d;
1321
+ constructor(options) {
1322
+ var _a, _b, _c, _d, _e;
1239
1323
  super();
1240
- this.classKeyword = classKeyword;
1241
- this.name = name;
1242
- this.body = body;
1243
- this.end = end;
1244
- this.extendsKeyword = extendsKeyword;
1245
- this.parentClassName = parentClassName;
1246
1324
  this.kind = AstNode_1.AstNodeKind.ClassStatement;
1247
1325
  this.memberMap = {};
1248
1326
  this.methods = [];
1249
1327
  this.fields = [];
1250
- this.body = (_a = this.body) !== null && _a !== void 0 ? _a : [];
1251
- this.symbolTable = new SymbolTable_2.SymbolTable(`ClassStatement: '${(_b = this.name) === null || _b === void 0 ? void 0 : _b.text}'`, () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
1328
+ this.body = (_a = options.body) !== null && _a !== void 0 ? _a : [];
1329
+ this.tokens = {
1330
+ name: options.name,
1331
+ class: options.class,
1332
+ endClass: options.endClass,
1333
+ extends: options.extends
1334
+ };
1335
+ this.parentClassName = options.parentClassName;
1336
+ this.symbolTable = new SymbolTable_1.SymbolTable(`ClassStatement: '${(_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text}'`, () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
1252
1337
  for (let statement of this.body) {
1253
1338
  if ((0, reflection_1.isMethodStatement)(statement)) {
1254
1339
  this.methods.push(statement);
1255
- this.memberMap[(_c = statement === null || statement === void 0 ? void 0 : statement.name) === null || _c === void 0 ? void 0 : _c.text.toLowerCase()] = statement;
1340
+ this.memberMap[(_c = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _c === void 0 ? void 0 : _c.text.toLowerCase()] = statement;
1256
1341
  }
1257
1342
  else if ((0, reflection_1.isFieldStatement)(statement)) {
1258
1343
  this.fields.push(statement);
1259
- this.memberMap[(_d = statement === null || statement === void 0 ? void 0 : statement.name) === null || _d === void 0 ? void 0 : _d.text.toLowerCase()] = statement;
1344
+ this.memberMap[(_d = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _d === void 0 ? void 0 : _d.text.toLowerCase()] = statement;
1260
1345
  }
1261
1346
  }
1262
- this.range = util_1.util.createBoundingRange(classKeyword, name, extendsKeyword, parentClassName, ...(body !== null && body !== void 0 ? body : []), end);
1347
+ this.range = util_1.util.createBoundingRange(this.parentClassName, ...((_e = this.body) !== null && _e !== void 0 ? _e : []), util_1.util.createBoundingRangeFromTokens(this.tokens));
1263
1348
  }
1264
1349
  getName(parseMode) {
1265
1350
  var _a;
1266
- const name = (_a = this.name) === null || _a === void 0 ? void 0 : _a.text;
1351
+ const name = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text;
1267
1352
  if (name) {
1268
1353
  const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
1269
1354
  if (namespace) {
@@ -1281,7 +1366,8 @@ class ClassStatement extends AstNode_2.Statement {
1281
1366
  }
1282
1367
  }
1283
1368
  getLeadingTrivia() {
1284
- return util_1.util.concatAnnotationLeadingTrivia(this, this.classKeyword.leadingTrivia);
1369
+ var _a;
1370
+ return util_1.util.concatAnnotationLeadingTrivia(this, (_a = this.tokens.class) === null || _a === void 0 ? void 0 : _a.leadingTrivia);
1285
1371
  }
1286
1372
  transpile(state) {
1287
1373
  let result = [];
@@ -1298,8 +1384,8 @@ class ClassStatement extends AstNode_2.Statement {
1298
1384
  for (let annotation of (_a = this.annotations) !== null && _a !== void 0 ? _a : []) {
1299
1385
  result.push(...annotation.getTypedef(state), state.newline, state.indent());
1300
1386
  }
1301
- result.push('class ', this.name.text);
1302
- if (this.extendsKeyword && this.parentClassName) {
1387
+ result.push('class ', this.tokens.name.text);
1388
+ if (this.parentClassName) {
1303
1389
  const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
1304
1390
  const fqName = util_1.util.getFullyQualifiedClassName(this.parentClassName.getName(), namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript));
1305
1391
  result.push(` extends ${fqName}`);
@@ -1386,8 +1472,8 @@ class ClassStatement extends AstNode_2.Statement {
1386
1472
  }
1387
1473
  getConstructorType() {
1388
1474
  var _a, _b;
1389
- const constructorType = (_b = (_a = this.getConstructorFunction()) === null || _a === void 0 ? void 0 : _a.getType({ flags: SymbolTable_1.SymbolTypeFlag.runtime })) !== null && _b !== void 0 ? _b : new TypedFunctionType_1.TypedFunctionType(null);
1390
- constructorType.returnType = this.getType({ flags: SymbolTable_1.SymbolTypeFlag.runtime });
1475
+ const constructorType = (_b = (_a = this.getConstructorFunction()) === null || _a === void 0 ? void 0 : _a.getType({ flags: 1 /* SymbolTypeFlag.runtime */ })) !== null && _b !== void 0 ? _b : new TypedFunctionType_1.TypedFunctionType(null);
1476
+ constructorType.returnType = this.getType({ flags: 1 /* SymbolTypeFlag.runtime */ });
1391
1477
  return constructorType;
1392
1478
  }
1393
1479
  /**
@@ -1396,7 +1482,7 @@ class ClassStatement extends AstNode_2.Statement {
1396
1482
  getConstructorFunction() {
1397
1483
  return this.body.find((stmt) => {
1398
1484
  var _a, _b;
1399
- return ((_b = (_a = stmt === null || stmt === void 0 ? void 0 : stmt.name) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'new';
1485
+ return ((_b = (_a = stmt === null || stmt === void 0 ? void 0 : stmt.tokens.name) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'new';
1400
1486
  });
1401
1487
  }
1402
1488
  /**
@@ -1457,13 +1543,13 @@ class ClassStatement extends AstNode_2.Statement {
1457
1543
  //store overridden parent methods as super{parentIndex}_{methodName}
1458
1544
  if (
1459
1545
  //is override method
1460
- statement.override ||
1546
+ statement.tokens.override ||
1461
1547
  //is constructor function in child class
1462
- (statement.name.text.toLowerCase() === 'new' && ancestors[0])) {
1463
- result.push(`instance.super${parentClassIndex}_${statement.name.text} = instance.${statement.name.text}`, state.newline, state.indent());
1548
+ (statement.tokens.name.text.toLowerCase() === 'new' && ancestors[0])) {
1549
+ result.push(`instance.super${parentClassIndex}_${statement.tokens.name.text} = instance.${statement.tokens.name.text}`, state.newline, state.indent());
1464
1550
  }
1465
1551
  state.classStatement = this;
1466
- result.push('instance.', state.transpileToken(statement.name), ' = ', ...statement.transpile(state), state.newline, state.indent());
1552
+ result.push('instance.', state.transpileToken(statement.tokens.name), ' = ', ...statement.transpile(state), state.newline, state.indent());
1467
1553
  delete state.classStatement;
1468
1554
  }
1469
1555
  else {
@@ -1487,7 +1573,7 @@ class ClassStatement extends AstNode_2.Statement {
1487
1573
  let result = [];
1488
1574
  const constructorFunction = this.getConstructorFunction();
1489
1575
  const constructorParams = constructorFunction ? constructorFunction.func.parameters : [];
1490
- result.push(state.sourceNode(this.classKeyword, 'function'), state.sourceNode(this.classKeyword, ' '), state.sourceNode(this.name, this.getName(Parser_1.ParseMode.BrightScript)), `(`);
1576
+ result.push(state.sourceNode(this, 'function'), state.sourceNode(this, ' '), state.sourceNode(this.tokens.name, this.getName(Parser_1.ParseMode.BrightScript)), `(`);
1491
1577
  let i = 0;
1492
1578
  for (let param of constructorParams) {
1493
1579
  if (i > 0) {
@@ -1508,7 +1594,7 @@ class ClassStatement extends AstNode_2.Statement {
1508
1594
  if (i > 0) {
1509
1595
  result.push(', ');
1510
1596
  }
1511
- result.push(state.transpileToken(param.name));
1597
+ result.push(state.transpileToken(param.tokens.name));
1512
1598
  i++;
1513
1599
  }
1514
1600
  result.push(')', '\n');
@@ -1532,30 +1618,30 @@ class ClassStatement extends AstNode_2.Statement {
1532
1618
  const resultType = new ClassType_1.ClassType(this.getName(Parser_1.ParseMode.BrighterScript), superClass);
1533
1619
  for (const statement of this.methods) {
1534
1620
  const funcType = statement === null || statement === void 0 ? void 0 : statement.func.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); //no typechain needed
1535
- let flag = SymbolTable_1.SymbolTypeFlag.runtime;
1621
+ let flag = 1 /* SymbolTypeFlag.runtime */;
1536
1622
  if (((_b = statement.accessModifier) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Private) {
1537
- flag |= SymbolTable_1.SymbolTypeFlag.private;
1623
+ flag |= 8 /* SymbolTypeFlag.private */;
1538
1624
  }
1539
1625
  if (((_c = statement.accessModifier) === null || _c === void 0 ? void 0 : _c.kind) === TokenKind_1.TokenKind.Protected) {
1540
- flag |= SymbolTable_1.SymbolTypeFlag.protected;
1626
+ flag |= 16 /* SymbolTypeFlag.protected */;
1541
1627
  }
1542
- resultType.addMember((_d = statement === null || statement === void 0 ? void 0 : statement.name) === null || _d === void 0 ? void 0 : _d.text, { definingNode: statement }, funcType, flag);
1628
+ resultType.addMember((_d = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _d === void 0 ? void 0 : _d.text, { definingNode: statement }, funcType, flag);
1543
1629
  }
1544
1630
  for (const statement of this.fields) {
1545
1631
  const fieldType = statement.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); //no typechain needed
1546
- let flag = SymbolTable_1.SymbolTypeFlag.runtime;
1632
+ let flag = 1 /* SymbolTypeFlag.runtime */;
1547
1633
  if (statement.isOptional) {
1548
- flag |= SymbolTable_1.SymbolTypeFlag.optional;
1634
+ flag |= 4 /* SymbolTypeFlag.optional */;
1549
1635
  }
1550
- if (((_e = statement.accessModifier) === null || _e === void 0 ? void 0 : _e.kind) === TokenKind_1.TokenKind.Private) {
1551
- flag |= SymbolTable_1.SymbolTypeFlag.private;
1636
+ if (((_e = statement.tokens.accessModifier) === null || _e === void 0 ? void 0 : _e.kind) === TokenKind_1.TokenKind.Private) {
1637
+ flag |= 8 /* SymbolTypeFlag.private */;
1552
1638
  }
1553
- if (((_f = statement.accessModifier) === null || _f === void 0 ? void 0 : _f.kind) === TokenKind_1.TokenKind.Protected) {
1554
- flag |= SymbolTable_1.SymbolTypeFlag.protected;
1639
+ if (((_f = statement.tokens.accessModifier) === null || _f === void 0 ? void 0 : _f.kind) === TokenKind_1.TokenKind.Protected) {
1640
+ flag |= 16 /* SymbolTypeFlag.protected */;
1555
1641
  }
1556
- resultType.addMember((_g = statement === null || statement === void 0 ? void 0 : statement.name) === null || _g === void 0 ? void 0 : _g.text, { definingNode: statement }, fieldType, flag);
1642
+ resultType.addMember((_g = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _g === void 0 ? void 0 : _g.text, { definingNode: statement }, fieldType, flag);
1557
1643
  }
1558
- (_h = options.typeChain) === null || _h === void 0 ? void 0 : _h.push(new interfaces_1.TypeChainEntry(resultType.name, resultType, options.data, this.range));
1644
+ (_h = options.typeChain) === null || _h === void 0 ? void 0 : _h.push(new interfaces_1.TypeChainEntry({ name: resultType.name, type: resultType, data: options.data, range: this.range, kind: this.kind }));
1559
1645
  return resultType;
1560
1646
  }
1561
1647
  }
@@ -1566,20 +1652,20 @@ const accessModifiers = [
1566
1652
  TokenKind_1.TokenKind.Private
1567
1653
  ];
1568
1654
  class MethodStatement extends FunctionStatement {
1569
- constructor(modifiers, name, func, override) {
1570
- super(name, func);
1571
- this.override = override;
1655
+ constructor(options) {
1656
+ super(options);
1572
1657
  this.kind = AstNode_1.AstNodeKind.MethodStatement;
1573
1658
  this.modifiers = [];
1574
- if (modifiers) {
1575
- if (Array.isArray(modifiers)) {
1576
- this.modifiers.push(...modifiers);
1659
+ if (options.modifiers) {
1660
+ if (Array.isArray(options.modifiers)) {
1661
+ this.modifiers.push(...options.modifiers);
1577
1662
  }
1578
1663
  else {
1579
- this.modifiers.push(modifiers);
1664
+ this.modifiers.push(options.modifiers);
1580
1665
  }
1581
1666
  }
1582
- this.range = util_1.util.createBoundingRange(...(this.modifiers), override, func);
1667
+ this.tokens = Object.assign(Object.assign({}, this.tokens), { override: options.override });
1668
+ this.range = util_1.util.createBoundingRange(...(this.modifiers), util_1.util.createBoundingRangeFromTokens(this.tokens), this.func);
1583
1669
  }
1584
1670
  get accessModifier() {
1585
1671
  return this.modifiers.find(x => accessModifiers.includes(x.kind));
@@ -1588,13 +1674,13 @@ class MethodStatement extends FunctionStatement {
1588
1674
  * Get the name of this method.
1589
1675
  */
1590
1676
  getName(parseMode) {
1591
- return this.name.text;
1677
+ return this.tokens.name.text;
1592
1678
  }
1593
1679
  getLeadingTrivia() {
1594
1680
  return util_1.util.concatAnnotationLeadingTrivia(this, this.func.getLeadingTrivia());
1595
1681
  }
1596
1682
  transpile(state) {
1597
- if (this.name.text.toLowerCase() === 'new') {
1683
+ if (this.tokens.name.text.toLowerCase() === 'new') {
1598
1684
  this.ensureSuperConstructorCall(state);
1599
1685
  //TODO we need to undo this at the bottom of this method
1600
1686
  this.injectFieldInitializersForConstructor(state);
@@ -1604,16 +1690,16 @@ class MethodStatement extends FunctionStatement {
1604
1690
  const parentClassIndex = state.classStatement.getParentClassIndex(state);
1605
1691
  const visitor = (0, visitors_1.createVisitor)({
1606
1692
  VariableExpression: e => {
1607
- if (e.name.text.toLocaleLowerCase() === 'super') {
1608
- state.editor.setProperty(e.name, 'text', `m.super${parentClassIndex}_new`);
1693
+ if (e.tokens.name.text.toLocaleLowerCase() === 'super') {
1694
+ state.editor.setProperty(e.tokens.name, 'text', `m.super${parentClassIndex}_new`);
1609
1695
  }
1610
1696
  },
1611
1697
  DottedGetExpression: e => {
1612
1698
  const beginningVariable = util_1.util.findBeginningVariableExpression(e);
1613
1699
  const lowerName = beginningVariable === null || beginningVariable === void 0 ? void 0 : beginningVariable.getName(Parser_1.ParseMode.BrighterScript).toLowerCase();
1614
1700
  if (lowerName === 'super') {
1615
- state.editor.setProperty(beginningVariable.name, 'text', 'm');
1616
- state.editor.setProperty(e.name, 'text', `super${parentClassIndex}_${e.name.text}`);
1701
+ state.editor.setProperty(beginningVariable.tokens.name, 'text', 'm');
1702
+ state.editor.setProperty(e.tokens.name, 'text', `super${parentClassIndex}_${e.tokens.name.text}`);
1617
1703
  }
1618
1704
  }
1619
1705
  });
@@ -1633,7 +1719,7 @@ class MethodStatement extends FunctionStatement {
1633
1719
  if (this.accessModifier) {
1634
1720
  result.push(this.accessModifier.text, ' ');
1635
1721
  }
1636
- if (this.override) {
1722
+ if (this.tokens.override) {
1637
1723
  result.push('override ');
1638
1724
  }
1639
1725
  result.push(...this.func.getTypedef(state));
@@ -1653,35 +1739,44 @@ class MethodStatement extends FunctionStatement {
1653
1739
  //is a call statement
1654
1740
  return (0, reflection_1.isExpressionStatement)(x) && (0, reflection_1.isCallExpression)(x.expression) &&
1655
1741
  //is a call to super
1656
- util_1.util.findBeginningVariableExpression(x.expression.callee).name.text.toLowerCase() === 'super';
1742
+ util_1.util.findBeginningVariableExpression(x.expression.callee).tokens.name.text.toLowerCase() === 'super';
1657
1743
  }) !== -1;
1658
1744
  //if a call to super exists, quit here
1659
1745
  if (containsSuperCall) {
1660
1746
  return;
1661
1747
  }
1662
1748
  //this is a child class, and the constructor doesn't contain a call to super. Inject one
1663
- const superCall = new ExpressionStatement(new Expression_1.CallExpression(new Expression_1.VariableExpression({
1664
- kind: TokenKind_1.TokenKind.Identifier,
1665
- text: 'super',
1666
- isReserved: false,
1667
- range: state.classStatement.name.range,
1668
- leadingWhitespace: '',
1669
- leadingTrivia: []
1670
- }), {
1671
- kind: TokenKind_1.TokenKind.LeftParen,
1672
- text: '(',
1673
- isReserved: false,
1674
- range: state.classStatement.name.range,
1675
- leadingWhitespace: '',
1676
- leadingTrivia: []
1677
- }, {
1678
- kind: TokenKind_1.TokenKind.RightParen,
1679
- text: ')',
1680
- isReserved: false,
1681
- range: state.classStatement.name.range,
1682
- leadingWhitespace: '',
1683
- leadingTrivia: []
1684
- }, []));
1749
+ const superCall = new ExpressionStatement({
1750
+ expression: new Expression_1.CallExpression({
1751
+ callee: new Expression_1.VariableExpression({
1752
+ name: {
1753
+ kind: TokenKind_1.TokenKind.Identifier,
1754
+ text: 'super',
1755
+ isReserved: false,
1756
+ range: state.classStatement.tokens.name.range,
1757
+ leadingWhitespace: '',
1758
+ leadingTrivia: []
1759
+ }
1760
+ }),
1761
+ openingParen: {
1762
+ kind: TokenKind_1.TokenKind.LeftParen,
1763
+ text: '(',
1764
+ isReserved: false,
1765
+ range: state.classStatement.tokens.name.range,
1766
+ leadingWhitespace: '',
1767
+ leadingTrivia: []
1768
+ },
1769
+ closingParen: {
1770
+ kind: TokenKind_1.TokenKind.RightParen,
1771
+ text: ')',
1772
+ isReserved: false,
1773
+ range: state.classStatement.tokens.name.range,
1774
+ leadingWhitespace: '',
1775
+ leadingTrivia: []
1776
+ },
1777
+ args: []
1778
+ })
1779
+ });
1685
1780
  state.editor.arrayUnshift(this.func.body.statements, superCall);
1686
1781
  }
1687
1782
  /**
@@ -1692,13 +1787,20 @@ class MethodStatement extends FunctionStatement {
1692
1787
  let newStatements = [];
1693
1788
  //insert the field initializers in order
1694
1789
  for (let field of state.classStatement.fields) {
1695
- let thisQualifiedName = Object.assign({}, field.name);
1696
- thisQualifiedName.text = 'm.' + field.name.text;
1790
+ let thisQualifiedName = Object.assign({}, field.tokens.name);
1791
+ thisQualifiedName.text = 'm.' + field.tokens.name.text;
1697
1792
  const fieldAssignment = field.initialValue
1698
- ? new AssignmentStatement(field.equal, thisQualifiedName, field.initialValue)
1699
- : new AssignmentStatement((0, creators_1.createToken)(TokenKind_1.TokenKind.Equal, '=', field.name.range), thisQualifiedName,
1700
- //if there is no initial value, set the initial value to `invalid`
1701
- (0, creators_1.createInvalidLiteral)('invalid', field.name.range));
1793
+ ? new AssignmentStatement({
1794
+ equals: field.tokens.equals,
1795
+ name: thisQualifiedName,
1796
+ value: field.initialValue
1797
+ })
1798
+ : new AssignmentStatement({
1799
+ equals: (0, creators_1.createToken)(TokenKind_1.TokenKind.Equal, '=', field.tokens.name.range),
1800
+ name: thisQualifiedName,
1801
+ //if there is no initial value, set the initial value to `invalid`
1802
+ value: (0, creators_1.createInvalidLiteral)('invalid', field.tokens.name.range)
1803
+ });
1702
1804
  // Add parent so namespace lookups work
1703
1805
  fieldAssignment.parent = state.classStatement;
1704
1806
  newStatements.push(fieldAssignment);
@@ -1713,17 +1815,19 @@ class MethodStatement extends FunctionStatement {
1713
1815
  }
1714
1816
  exports.MethodStatement = MethodStatement;
1715
1817
  class FieldStatement extends AstNode_2.Statement {
1716
- constructor(accessModifier, name, as, typeExpression, equal, initialValue, optional) {
1818
+ constructor(options) {
1717
1819
  super();
1718
- this.accessModifier = accessModifier;
1719
- this.name = name;
1720
- this.as = as;
1721
- this.typeExpression = typeExpression;
1722
- this.equal = equal;
1723
- this.initialValue = initialValue;
1724
- this.optional = optional;
1725
1820
  this.kind = AstNode_1.AstNodeKind.FieldStatement;
1726
- this.range = util_1.util.createBoundingRange(accessModifier, optional, name, as, typeExpression, equal, initialValue);
1821
+ this.tokens = {
1822
+ accessModifier: options.accessModifier,
1823
+ name: options.name,
1824
+ as: options.as,
1825
+ equals: options.equals,
1826
+ optional: options.optional
1827
+ };
1828
+ this.typeExpression = options.typeExpression;
1829
+ this.initialValue = options.initialValue;
1830
+ this.range = util_1.util.createBoundingRange(util_1.util.createBoundingRangeFromTokens(this.tokens), this.typeExpression, this.initialValue);
1727
1831
  }
1728
1832
  /**
1729
1833
  * Derive a ValueKind from the type token, or the initial value.
@@ -1731,14 +1835,14 @@ class FieldStatement extends AstNode_2.Statement {
1731
1835
  */
1732
1836
  getType(options) {
1733
1837
  var _a, _b, _c, _d;
1734
- return (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.typetime }))) !== null && _b !== void 0 ? _b : (_c = this.initialValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.runtime }))) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
1838
+ return (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */ }))) !== null && _b !== void 0 ? _b : (_c = this.initialValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */ }))) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
1735
1839
  }
1736
1840
  getLeadingTrivia() {
1737
1841
  var _a, _b, _c, _d, _e, _f;
1738
- return util_1.util.concatAnnotationLeadingTrivia(this, (_f = (_d = (_b = (_a = this.accessModifier) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : (_c = this.optional) === null || _c === void 0 ? void 0 : _c.leadingTrivia) !== null && _d !== void 0 ? _d : (_e = this.name) === null || _e === void 0 ? void 0 : _e.leadingTrivia) !== null && _f !== void 0 ? _f : []);
1842
+ return util_1.util.concatAnnotationLeadingTrivia(this, (_f = (_d = (_b = (_a = this.tokens.accessModifier) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : (_c = this.tokens.optional) === null || _c === void 0 ? void 0 : _c.leadingTrivia) !== null && _d !== void 0 ? _d : (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.leadingTrivia) !== null && _f !== void 0 ? _f : []);
1739
1843
  }
1740
1844
  get isOptional() {
1741
- return !!this.optional;
1845
+ return !!this.tokens.optional;
1742
1846
  }
1743
1847
  transpile(state) {
1744
1848
  throw new Error('transpile not implemented for ' + Object.getPrototypeOf(this).constructor.name);
@@ -1746,19 +1850,19 @@ class FieldStatement extends AstNode_2.Statement {
1746
1850
  getTypedef(state) {
1747
1851
  var _a, _b, _c, _d;
1748
1852
  const result = [];
1749
- if (this.name) {
1853
+ if (this.tokens.name) {
1750
1854
  for (let annotation of (_a = this.annotations) !== null && _a !== void 0 ? _a : []) {
1751
1855
  result.push(...annotation.getTypedef(state), state.newline, state.indent());
1752
1856
  }
1753
- let type = this.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime });
1857
+ let type = this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ });
1754
1858
  if ((0, reflection_1.isInvalidType)(type) || (0, reflection_1.isVoidType)(type)) {
1755
1859
  type = new DynamicType_1.DynamicType();
1756
1860
  }
1757
- result.push((_c = (_b = this.accessModifier) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : 'public', ' ');
1861
+ result.push((_c = (_b = this.tokens.accessModifier) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : 'public', ' ');
1758
1862
  if (this.isOptional) {
1759
- result.push(this.optional.text, ' ');
1863
+ result.push(this.tokens.optional.text, ' ');
1760
1864
  }
1761
- result.push((_d = this.name) === null || _d === void 0 ? void 0 : _d.text, ' as ', type.toTypeString());
1865
+ result.push((_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text, ' as ', type.toTypeString());
1762
1866
  }
1763
1867
  return result;
1764
1868
  }
@@ -1771,25 +1875,28 @@ class FieldStatement extends AstNode_2.Statement {
1771
1875
  }
1772
1876
  exports.FieldStatement = FieldStatement;
1773
1877
  class TryCatchStatement extends AstNode_2.Statement {
1774
- constructor(tokens, tryBranch, catchStatement) {
1878
+ constructor(options) {
1775
1879
  super();
1776
- this.tokens = tokens;
1777
- this.tryBranch = tryBranch;
1778
- this.catchStatement = catchStatement;
1779
1880
  this.kind = AstNode_1.AstNodeKind.TryCatchStatement;
1780
- this.range = util_1.util.createBoundingRange(tokens.try, tryBranch, catchStatement, tokens.endTry);
1881
+ this.tokens = {
1882
+ try: options.try,
1883
+ endTry: options.endTry
1884
+ };
1885
+ this.tryBranch = options.tryBranch;
1886
+ this.catchStatement = options.catchStatement;
1887
+ this.range = util_1.util.createBoundingRange(this.tokens.try, this.tryBranch, this.catchStatement, this.tokens.endTry);
1781
1888
  }
1782
1889
  transpile(state) {
1783
1890
  var _a, _b;
1784
1891
  return [
1785
- state.transpileToken(this.tokens.try),
1892
+ state.transpileToken(this.tokens.try, 'try'),
1786
1893
  ...this.tryBranch.transpile(state),
1787
1894
  state.newline,
1788
1895
  state.indent(),
1789
1896
  ...((_b = (_a = this.catchStatement) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : ['catch']),
1790
1897
  state.newline,
1791
1898
  state.indent(),
1792
- state.transpileToken(this.tokens.endTry)
1899
+ state.transpileToken(this.tokens.endTry, 'end try')
1793
1900
  ];
1794
1901
  }
1795
1902
  walk(visitor, options) {
@@ -1801,20 +1908,22 @@ class TryCatchStatement extends AstNode_2.Statement {
1801
1908
  }
1802
1909
  exports.TryCatchStatement = TryCatchStatement;
1803
1910
  class CatchStatement extends AstNode_2.Statement {
1804
- constructor(tokens, exceptionVariable, catchBranch) {
1911
+ constructor(options) {
1805
1912
  super();
1806
- this.tokens = tokens;
1807
- this.exceptionVariable = exceptionVariable;
1808
- this.catchBranch = catchBranch;
1809
1913
  this.kind = AstNode_1.AstNodeKind.CatchStatement;
1810
- this.range = util_1.util.createBoundingRange(tokens.catch, exceptionVariable, catchBranch);
1914
+ this.tokens = {
1915
+ catch: options === null || options === void 0 ? void 0 : options.catch,
1916
+ exceptionVariable: options === null || options === void 0 ? void 0 : options.exceptionVariable
1917
+ };
1918
+ this.catchBranch = options === null || options === void 0 ? void 0 : options.catchBranch;
1919
+ this.range = util_1.util.createBoundingRange(this.tokens.catch, this.tokens.exceptionVariable, this.catchBranch);
1811
1920
  }
1812
1921
  transpile(state) {
1813
1922
  var _a, _b, _c, _d;
1814
1923
  return [
1815
- state.transpileToken(this.tokens.catch),
1924
+ state.transpileToken(this.tokens.catch, 'catch'),
1816
1925
  ' ',
1817
- (_b = (_a = this.exceptionVariable) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'e',
1926
+ (_b = (_a = this.tokens.exceptionVariable) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'e',
1818
1927
  ...((_d = (_c = this.catchBranch) === null || _c === void 0 ? void 0 : _c.transpile(state)) !== null && _d !== void 0 ? _d : [])
1819
1928
  ];
1820
1929
  }
@@ -1826,16 +1935,18 @@ class CatchStatement extends AstNode_2.Statement {
1826
1935
  }
1827
1936
  exports.CatchStatement = CatchStatement;
1828
1937
  class ThrowStatement extends AstNode_2.Statement {
1829
- constructor(throwToken, expression) {
1938
+ constructor(options) {
1830
1939
  super();
1831
- this.throwToken = throwToken;
1832
- this.expression = expression;
1833
1940
  this.kind = AstNode_1.AstNodeKind.ThrowStatement;
1834
- this.range = util_1.util.createBoundingRange(throwToken, expression);
1941
+ this.tokens = {
1942
+ throw: options.throw
1943
+ };
1944
+ this.expression = options.expression;
1945
+ this.range = util_1.util.createBoundingRange(this.tokens.throw, this.expression);
1835
1946
  }
1836
1947
  transpile(state) {
1837
1948
  const result = [
1838
- state.transpileToken(this.throwToken),
1949
+ state.transpileToken(this.tokens.throw, 'throw'),
1839
1950
  ' '
1840
1951
  ];
1841
1952
  //if we have an expression, transpile it
@@ -1856,14 +1967,17 @@ class ThrowStatement extends AstNode_2.Statement {
1856
1967
  }
1857
1968
  exports.ThrowStatement = ThrowStatement;
1858
1969
  class EnumStatement extends AstNode_2.Statement {
1859
- constructor(tokens, body) {
1970
+ constructor(options) {
1860
1971
  var _a;
1861
1972
  super();
1862
- this.tokens = tokens;
1863
- this.body = body;
1864
1973
  this.kind = AstNode_1.AstNodeKind.EnumStatement;
1865
- this.symbolTable = new SymbolTable_2.SymbolTable('Enum');
1866
- this.body = (_a = this.body) !== null && _a !== void 0 ? _a : [];
1974
+ this.tokens = {
1975
+ enum: options.enum,
1976
+ name: options.name,
1977
+ endEnum: options.endEnum
1978
+ };
1979
+ this.symbolTable = new SymbolTable_1.SymbolTable('Enum');
1980
+ this.body = (_a = options.body) !== null && _a !== void 0 ? _a : [];
1867
1981
  }
1868
1982
  get range() {
1869
1983
  return util_1.util.createBoundingRange(this.tokens.enum, this.tokens.name, ...this.body, this.tokens.endEnum);
@@ -1885,7 +1999,7 @@ class EnumStatement extends AstNode_2.Statement {
1885
1999
  * All values are stored as their AST LiteralExpression representation (i.e. string enum values include the wrapping quotes)
1886
2000
  */
1887
2001
  getMemberValueMap() {
1888
- var _a, _b, _c, _d, _e, _f, _g, _h;
2002
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1889
2003
  const result = new Map();
1890
2004
  const members = this.getMembers();
1891
2005
  let currentIntValue = 0;
@@ -1896,22 +2010,22 @@ class EnumStatement extends AstNode_2.Statement {
1896
2010
  currentIntValue++;
1897
2011
  //if explicit integer value, use it and increment the int counter
1898
2012
  }
1899
- else if ((0, reflection_1.isLiteralExpression)(member.value) && member.value.token.kind === TokenKind_1.TokenKind.IntegerLiteral) {
2013
+ else if ((0, reflection_1.isLiteralExpression)(member.value) && member.value.tokens.value.kind === TokenKind_1.TokenKind.IntegerLiteral) {
1900
2014
  //try parsing as integer literal, then as hex integer literal.
1901
- let tokenIntValue = (_b = util_1.util.parseInt(member.value.token.text)) !== null && _b !== void 0 ? _b : util_1.util.parseInt(member.value.token.text.replace(/&h/i, '0x'));
2015
+ let tokenIntValue = (_b = util_1.util.parseInt(member.value.tokens.value.text)) !== null && _b !== void 0 ? _b : util_1.util.parseInt(member.value.tokens.value.text.replace(/&h/i, '0x'));
1902
2016
  if (tokenIntValue !== undefined) {
1903
2017
  currentIntValue = tokenIntValue;
1904
2018
  currentIntValue++;
1905
2019
  }
1906
- result.set((_c = member.name) === null || _c === void 0 ? void 0 : _c.toLowerCase(), member.value.token.text);
2020
+ result.set((_c = member.name) === null || _c === void 0 ? void 0 : _c.toLowerCase(), member.value.tokens.value.text);
1907
2021
  //simple unary expressions (like `-1`)
1908
2022
  }
1909
2023
  else if ((0, reflection_1.isUnaryExpression)(member.value) && (0, reflection_1.isLiteralExpression)(member.value.right)) {
1910
- result.set((_d = member.name) === null || _d === void 0 ? void 0 : _d.toLowerCase(), member.value.operator.text + member.value.right.token.text);
2024
+ result.set((_d = member.name) === null || _d === void 0 ? void 0 : _d.toLowerCase(), member.value.tokens.operator.text + member.value.right.tokens.value.text);
1911
2025
  //all other values
1912
2026
  }
1913
2027
  else {
1914
- result.set((_e = member.name) === null || _e === void 0 ? void 0 : _e.toLowerCase(), (_h = (_g = (_f = member.value) === null || _f === void 0 ? void 0 : _f.token) === null || _g === void 0 ? void 0 : _g.text) !== null && _h !== void 0 ? _h : 'invalid');
2028
+ result.set((_e = member.name) === null || _e === void 0 ? void 0 : _e.toLowerCase(), (_j = (_h = (_g = (_f = member.value) === null || _f === void 0 ? void 0 : _f.tokens) === null || _g === void 0 ? void 0 : _g.value) === null || _h === void 0 ? void 0 : _h.text) !== null && _j !== void 0 ? _j : 'invalid');
1915
2029
  }
1916
2030
  }
1917
2031
  return result;
@@ -1952,12 +2066,12 @@ class EnumStatement extends AstNode_2.Statement {
1952
2066
  return [];
1953
2067
  }
1954
2068
  getTypedef(state) {
1955
- var _a, _b, _c;
2069
+ var _a, _b, _c, _d, _e;
1956
2070
  const result = [];
1957
2071
  for (let annotation of (_a = this.annotations) !== null && _a !== void 0 ? _a : []) {
1958
2072
  result.push(...annotation.getTypedef(state), state.newline, state.indent());
1959
2073
  }
1960
- result.push((_b = this.tokens.enum.text) !== null && _b !== void 0 ? _b : 'enum', ' ', this.tokens.name.text);
2074
+ result.push((_c = (_b = this.tokens.enum) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : 'enum', ' ', this.tokens.name.text);
1961
2075
  result.push(state.newline);
1962
2076
  state.blockDepth++;
1963
2077
  for (const member of this.body) {
@@ -1966,7 +2080,7 @@ class EnumStatement extends AstNode_2.Statement {
1966
2080
  }
1967
2081
  }
1968
2082
  state.blockDepth--;
1969
- result.push(state.indent(), (_c = this.tokens.endEnum.text) !== null && _c !== void 0 ? _c : 'end enum');
2083
+ result.push(state.indent(), (_e = (_d = this.tokens.endEnum) === null || _d === void 0 ? void 0 : _d.text) !== null && _e !== void 0 ? _e : 'end enum');
1970
2084
  return result;
1971
2085
  }
1972
2086
  walk(visitor, options) {
@@ -1980,21 +2094,24 @@ class EnumStatement extends AstNode_2.Statement {
1980
2094
  const resultType = new EnumType_1.EnumType(this.fullName, (_a = members[0]) === null || _a === void 0 ? void 0 : _a.getType(options).underlyingType);
1981
2095
  resultType.pushMemberProvider(() => this.getSymbolTable());
1982
2096
  for (const statement of members) {
1983
- resultType.addMember((_c = (_b = statement === null || statement === void 0 ? void 0 : statement.tokens) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.text, { definingNode: statement }, statement.getType(options), SymbolTable_1.SymbolTypeFlag.runtime);
2097
+ resultType.addMember((_c = (_b = statement === null || statement === void 0 ? void 0 : statement.tokens) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.text, { definingNode: statement }, statement.getType(options), 1 /* SymbolTypeFlag.runtime */);
1984
2098
  }
1985
2099
  return resultType;
1986
2100
  }
1987
2101
  }
1988
2102
  exports.EnumStatement = EnumStatement;
1989
2103
  class EnumMemberStatement extends AstNode_2.Statement {
1990
- constructor(tokens, value) {
2104
+ constructor(options) {
1991
2105
  super();
1992
- this.tokens = tokens;
1993
- this.value = value;
1994
2106
  this.kind = AstNode_1.AstNodeKind.EnumMemberStatement;
2107
+ this.tokens = {
2108
+ name: options.name,
2109
+ equals: options.equals
2110
+ };
2111
+ this.value = options.value;
1995
2112
  }
1996
2113
  get range() {
1997
- return util_1.util.createBoundingRange(this.tokens.name, this.tokens.equal, this.value);
2114
+ return util_1.util.createBoundingRange(this.tokens.name, this.tokens.equals, this.value);
1998
2115
  }
1999
2116
  /**
2000
2117
  * The name of the member
@@ -2012,8 +2129,8 @@ class EnumMemberStatement extends AstNode_2.Statement {
2012
2129
  const result = [
2013
2130
  this.tokens.name.text
2014
2131
  ];
2015
- if (this.tokens.equal) {
2016
- result.push(' ', this.tokens.equal.text, ' ');
2132
+ if (this.tokens.equals) {
2133
+ result.push(' ', this.tokens.equals.text, ' ');
2017
2134
  if (this.value) {
2018
2135
  result.push(...this.value.transpile(state));
2019
2136
  }
@@ -2032,11 +2149,15 @@ class EnumMemberStatement extends AstNode_2.Statement {
2032
2149
  }
2033
2150
  exports.EnumMemberStatement = EnumMemberStatement;
2034
2151
  class ConstStatement extends AstNode_2.Statement {
2035
- constructor(tokens, value) {
2152
+ constructor(options) {
2036
2153
  super();
2037
- this.tokens = tokens;
2038
- this.value = value;
2039
2154
  this.kind = AstNode_1.AstNodeKind.ConstStatement;
2155
+ this.tokens = {
2156
+ const: options.const,
2157
+ name: options.name,
2158
+ equals: options.equals
2159
+ };
2160
+ this.value = options.value;
2040
2161
  this.range = util_1.util.createBoundingRange(this.tokens.const, this.tokens.name, this.tokens.equals, this.value);
2041
2162
  }
2042
2163
  get name() {
@@ -2072,11 +2193,11 @@ class ConstStatement extends AstNode_2.Statement {
2072
2193
  }
2073
2194
  getTypedef(state) {
2074
2195
  return [
2075
- state.tokenToSourceNode(this.tokens.const),
2196
+ this.tokens.const ? state.tokenToSourceNode(this.tokens.const) : 'const',
2076
2197
  ' ',
2077
2198
  state.tokenToSourceNode(this.tokens.name),
2078
2199
  ' ',
2079
- state.tokenToSourceNode(this.tokens.equals),
2200
+ this.tokens.equals ? state.tokenToSourceNode(this.tokens.equals) : '=',
2080
2201
  ' ',
2081
2202
  ...this.value.transpile(state)
2082
2203
  ];
@@ -2092,11 +2213,14 @@ class ConstStatement extends AstNode_2.Statement {
2092
2213
  }
2093
2214
  exports.ConstStatement = ConstStatement;
2094
2215
  class ContinueStatement extends AstNode_2.Statement {
2095
- constructor(tokens) {
2216
+ constructor(options) {
2096
2217
  super();
2097
- this.tokens = tokens;
2098
2218
  this.kind = AstNode_1.AstNodeKind.ContinueStatement;
2099
- this.range = util_1.util.createBoundingRange(tokens.continue, tokens.loopType);
2219
+ this.tokens = {
2220
+ continue: options.continue,
2221
+ loopType: options.loopType
2222
+ };
2223
+ this.range = util_1.util.createBoundingRange(this.tokens.continue, this.tokens.loopType);
2100
2224
  }
2101
2225
  transpile(state) {
2102
2226
  var _a, _b, _c, _d, _e;