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