brighterscript 0.41.2 → 1.0.0-alpha.12

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 (170) hide show
  1. package/CHANGELOG.md +112 -0
  2. package/README.md +2 -2
  3. package/dist/DiagnosticCollection.js +2 -2
  4. package/dist/DiagnosticCollection.js.map +1 -1
  5. package/dist/DiagnosticFilterer.js +2 -2
  6. package/dist/DiagnosticFilterer.js.map +1 -1
  7. package/dist/DiagnosticMessages.d.ts +6 -1
  8. package/dist/DiagnosticMessages.js +5 -0
  9. package/dist/DiagnosticMessages.js.map +1 -1
  10. package/dist/LanguageServer.d.ts +8 -2
  11. package/dist/LanguageServer.js +50 -44
  12. package/dist/LanguageServer.js.map +1 -1
  13. package/dist/Program.d.ts +61 -45
  14. package/dist/Program.js +305 -188
  15. package/dist/Program.js.map +1 -1
  16. package/dist/ProgramBuilder.d.ts +7 -7
  17. package/dist/ProgramBuilder.js +60 -51
  18. package/dist/ProgramBuilder.js.map +1 -1
  19. package/dist/Scope.d.ts +42 -19
  20. package/dist/Scope.js +261 -129
  21. package/dist/Scope.js.map +1 -1
  22. package/dist/SymbolTable.d.ts +73 -0
  23. package/dist/SymbolTable.js +157 -0
  24. package/dist/SymbolTable.js.map +1 -0
  25. package/dist/XmlScope.d.ts +5 -0
  26. package/dist/XmlScope.js +66 -28
  27. package/dist/XmlScope.js.map +1 -1
  28. package/dist/astUtils/creators.d.ts +15 -1
  29. package/dist/astUtils/creators.js +39 -9
  30. package/dist/astUtils/creators.js.map +1 -1
  31. package/dist/astUtils/reflection.d.ts +28 -16
  32. package/dist/astUtils/reflection.js +52 -30
  33. package/dist/astUtils/reflection.js.map +1 -1
  34. package/dist/astUtils/reflection.spec.js +3 -3
  35. package/dist/astUtils/reflection.spec.js.map +1 -1
  36. package/dist/astUtils/visitors.spec.js +12 -13
  37. package/dist/astUtils/visitors.spec.js.map +1 -1
  38. package/dist/astUtils/xml.d.ts +3 -3
  39. package/dist/astUtils/xml.js +2 -2
  40. package/dist/astUtils/xml.js.map +1 -1
  41. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +5 -6
  42. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  43. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +24 -22
  44. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  45. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +2 -2
  46. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +1 -1
  47. package/dist/examples/plugins/removePrint.js +1 -1
  48. package/dist/examples/plugins/removePrint.js.map +1 -1
  49. package/dist/files/BrsFile.Class.spec.js +356 -41
  50. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  51. package/dist/files/BrsFile.d.ts +55 -37
  52. package/dist/files/BrsFile.js +430 -399
  53. package/dist/files/BrsFile.js.map +1 -1
  54. package/dist/files/BrsFile.spec.js +199 -158
  55. package/dist/files/BrsFile.spec.js.map +1 -1
  56. package/dist/files/XmlFile.d.ts +20 -9
  57. package/dist/files/XmlFile.js +36 -31
  58. package/dist/files/XmlFile.js.map +1 -1
  59. package/dist/files/XmlFile.spec.js +113 -113
  60. package/dist/files/XmlFile.spec.js.map +1 -1
  61. package/dist/files/tests/imports.spec.js +32 -32
  62. package/dist/files/tests/imports.spec.js.map +1 -1
  63. package/dist/globalCallables.js +17 -6
  64. package/dist/globalCallables.js.map +1 -1
  65. package/dist/interfaces.d.ts +155 -39
  66. package/dist/parser/BrsTranspileState.d.ts +7 -0
  67. package/dist/parser/BrsTranspileState.js +10 -1
  68. package/dist/parser/BrsTranspileState.js.map +1 -1
  69. package/dist/parser/Expression.d.ts +23 -12
  70. package/dist/parser/Expression.js +45 -30
  71. package/dist/parser/Expression.js.map +1 -1
  72. package/dist/parser/Parser.Class.spec.js +100 -1
  73. package/dist/parser/Parser.Class.spec.js.map +1 -1
  74. package/dist/parser/Parser.d.ts +118 -5
  75. package/dist/parser/Parser.js +398 -37
  76. package/dist/parser/Parser.js.map +1 -1
  77. package/dist/parser/Parser.spec.js +404 -7
  78. package/dist/parser/Parser.spec.js.map +1 -1
  79. package/dist/parser/SGParser.d.ts +41 -4
  80. package/dist/parser/SGParser.js +185 -174
  81. package/dist/parser/SGParser.js.map +1 -1
  82. package/dist/parser/SGParser.spec.js +17 -4
  83. package/dist/parser/SGParser.spec.js.map +1 -1
  84. package/dist/parser/SGTypes.d.ts +203 -38
  85. package/dist/parser/SGTypes.js +464 -160
  86. package/dist/parser/SGTypes.js.map +1 -1
  87. package/dist/parser/SGTypes.spec.d.ts +1 -0
  88. package/dist/parser/SGTypes.spec.js +351 -0
  89. package/dist/parser/SGTypes.spec.js.map +1 -0
  90. package/dist/parser/Statement.d.ts +37 -26
  91. package/dist/parser/Statement.js +81 -20
  92. package/dist/parser/Statement.js.map +1 -1
  93. package/dist/parser/Statement.spec.js +5 -5
  94. package/dist/parser/Statement.spec.js.map +1 -1
  95. package/dist/parser/TranspileState.d.ts +1 -1
  96. package/dist/parser/TranspileState.js +15 -7
  97. package/dist/parser/TranspileState.js.map +1 -1
  98. package/dist/parser/tests/controlFlow/ForEach.spec.js +5 -4
  99. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  100. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +1 -1
  101. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  102. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +1 -1
  103. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
  104. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +1 -1
  105. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  106. package/dist/parser/tests/expression/TernaryExpression.spec.js +1 -1
  107. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  108. package/dist/types/ArrayType.d.ts +1 -0
  109. package/dist/types/ArrayType.js +23 -19
  110. package/dist/types/ArrayType.js.map +1 -1
  111. package/dist/types/BooleanType.d.ts +3 -2
  112. package/dist/types/BooleanType.js +6 -3
  113. package/dist/types/BooleanType.js.map +1 -1
  114. package/dist/types/BscType.d.ts +19 -4
  115. package/dist/types/BscType.js +9 -0
  116. package/dist/types/BscType.js.map +1 -1
  117. package/dist/types/CustomType.d.ts +8 -5
  118. package/dist/types/CustomType.js +12 -12
  119. package/dist/types/CustomType.js.map +1 -1
  120. package/dist/types/DoubleType.d.ts +1 -0
  121. package/dist/types/DoubleType.js +11 -11
  122. package/dist/types/DoubleType.js.map +1 -1
  123. package/dist/types/DynamicType.d.ts +1 -0
  124. package/dist/types/DynamicType.js +4 -0
  125. package/dist/types/DynamicType.js.map +1 -1
  126. package/dist/types/FloatType.d.ts +2 -1
  127. package/dist/types/FloatType.js +11 -11
  128. package/dist/types/FloatType.js.map +1 -1
  129. package/dist/types/FunctionType.d.ts +13 -10
  130. package/dist/types/FunctionType.js +34 -18
  131. package/dist/types/FunctionType.js.map +1 -1
  132. package/dist/types/FunctionType.spec.js +8 -2
  133. package/dist/types/FunctionType.spec.js.map +1 -1
  134. package/dist/types/IntegerType.d.ts +2 -1
  135. package/dist/types/IntegerType.js +11 -11
  136. package/dist/types/IntegerType.js.map +1 -1
  137. package/dist/types/InvalidType.d.ts +3 -2
  138. package/dist/types/InvalidType.js +7 -4
  139. package/dist/types/InvalidType.js.map +1 -1
  140. package/dist/types/LazyType.d.ts +17 -0
  141. package/dist/types/LazyType.js +44 -0
  142. package/dist/types/LazyType.js.map +1 -0
  143. package/dist/types/LongIntegerType.d.ts +2 -1
  144. package/dist/types/LongIntegerType.js +11 -11
  145. package/dist/types/LongIntegerType.js.map +1 -1
  146. package/dist/types/ObjectType.d.ts +6 -2
  147. package/dist/types/ObjectType.js +9 -3
  148. package/dist/types/ObjectType.js.map +1 -1
  149. package/dist/types/StringType.d.ts +3 -2
  150. package/dist/types/StringType.js +6 -3
  151. package/dist/types/StringType.js.map +1 -1
  152. package/dist/types/UninitializedType.d.ts +4 -2
  153. package/dist/types/UninitializedType.js +8 -3
  154. package/dist/types/UninitializedType.js.map +1 -1
  155. package/dist/types/VoidType.d.ts +3 -2
  156. package/dist/types/VoidType.js +6 -3
  157. package/dist/types/VoidType.js.map +1 -1
  158. package/dist/types/helpers.d.ts +42 -0
  159. package/dist/types/helpers.js +113 -0
  160. package/dist/types/helpers.js.map +1 -0
  161. package/dist/util.d.ts +68 -15
  162. package/dist/util.js +193 -45
  163. package/dist/util.js.map +1 -1
  164. package/dist/validators/ClassValidator.d.ts +5 -1
  165. package/dist/validators/ClassValidator.js +31 -17
  166. package/dist/validators/ClassValidator.js.map +1 -1
  167. package/package.json +1 -1
  168. package/dist/FunctionScope.d.ts +0 -27
  169. package/dist/FunctionScope.js +0 -49
  170. package/dist/FunctionScope.js.map +0 -1
@@ -2,15 +2,15 @@ import type { Range, Diagnostic, CodeAction, SemanticTokenTypes, SemanticTokenMo
2
2
  import type { Scope } from './Scope';
3
3
  import type { BrsFile } from './files/BrsFile';
4
4
  import type { XmlFile } from './files/XmlFile';
5
- import type { FunctionScope } from './FunctionScope';
6
5
  import type { FunctionType } from './types/FunctionType';
7
6
  import type { ParseMode } from './parser/Parser';
8
- import type { Program, SourceObj, TranspileObj } from './Program';
7
+ import type { Program } from './Program';
9
8
  import type { ProgramBuilder } from './ProgramBuilder';
10
- import type { Expression, FunctionStatement } from './parser';
9
+ import type { Expression, FunctionStatement, FunctionExpression } from './parser';
11
10
  import type { TranspileState } from './parser/TranspileState';
12
11
  import type { SourceNode } from 'source-map';
13
12
  import type { BscType } from './types/BscType';
13
+ import type { Token } from './lexer/Token';
14
14
  export interface BsDiagnostic extends Diagnostic {
15
15
  file: BscFile;
16
16
  /**
@@ -60,11 +60,12 @@ export interface FunctionCall {
60
60
  * The full range of this function call (from the start of the function name to its closing paren)
61
61
  */
62
62
  range: Range;
63
- functionScope: FunctionScope;
64
- file: File;
65
- name: string;
63
+ functionExpression: FunctionExpression;
64
+ file: BscFile;
65
+ name: Token;
66
66
  args: CallableArg[];
67
67
  nameRange: Range;
68
+ isDottedInvocation: boolean;
68
69
  }
69
70
  /**
70
71
  * An argument for an expression call.
@@ -108,14 +109,6 @@ export interface FileReference {
108
109
  */
109
110
  filePathRange?: Range;
110
111
  }
111
- export interface File {
112
- /**
113
- * The absolute path to the file, relative to the pkg
114
- */
115
- pkgPath: string;
116
- pathAbsolute: string;
117
- getDiagnostics(): BsDiagnostic[];
118
- }
119
112
  export interface VariableDeclaration {
120
113
  name: string;
121
114
  type: BscType;
@@ -160,36 +153,77 @@ export interface CommentFlag {
160
153
  affectedRange: Range;
161
154
  codes: DiagnosticCode[] | null;
162
155
  }
163
- declare type ValidateHandler = (scope: Scope, files: BscFile[], callables: CallableContainerMap) => void;
164
156
  export declare type CompilerPluginFactory = () => CompilerPlugin;
165
157
  export interface CompilerPlugin {
166
158
  name: string;
167
- beforeProgramCreate?: (builder: ProgramBuilder) => void;
168
- beforePrepublish?: (builder: ProgramBuilder, files: FileObj[]) => void;
169
- afterPrepublish?: (builder: ProgramBuilder, files: FileObj[]) => void;
170
- beforePublish?: (builder: ProgramBuilder, files: FileObj[]) => void;
171
- afterPublish?: (builder: ProgramBuilder, files: FileObj[]) => void;
172
- afterProgramCreate?: (program: Program) => void;
173
- beforeProgramValidate?: (program: Program) => void;
174
- afterProgramValidate?: (program: Program) => void;
175
- beforeProgramTranspile?: (program: Program, entries: TranspileObj[]) => void;
176
- afterProgramTranspile?: (program: Program, entries: TranspileObj[]) => void;
159
+ beforeProgramCreate?: PluginHandler<BeforeProgramCreateEvent>;
160
+ afterProgramCreate?: PluginHandler<AfterProgramCreateEvent>;
161
+ beforePrepublish?: PluginHandler<BeforePrepublishEvent>;
162
+ afterPrepublish?: PluginHandler<AfterPrepublishEvent>;
163
+ beforePublish?: PluginHandler<BeforePublishEvent>;
164
+ afterPublish?: PluginHandler<AfterPublishEvent>;
165
+ beforeProgramValidate?: PluginHandler<BeforeProgramValidateEvent>;
166
+ afterProgramValidate?: PluginHandler<AfterProgramValidateEvent>;
167
+ beforeProgramTranspile?: PluginHandler<BeforeProgramTranspileEvent>;
168
+ afterProgramTranspile?: PluginHandler<AfterProgramTranspileEvent>;
177
169
  onGetCodeActions?: PluginHandler<OnGetCodeActionsEvent>;
178
170
  onGetSemanticTokens?: PluginHandler<OnGetSemanticTokensEvent>;
179
- afterScopeCreate?: (scope: Scope) => void;
180
- beforeScopeDispose?: (scope: Scope) => void;
181
- afterScopeDispose?: (scope: Scope) => void;
182
- beforeScopeValidate?: ValidateHandler;
183
- afterScopeValidate?: ValidateHandler;
184
- beforeFileParse?: (source: SourceObj) => void;
185
- afterFileParse?: (file: BscFile) => void;
186
- afterFileValidate?: (file: BscFile) => void;
187
- beforeFileTranspile?: (entry: TranspileObj) => void;
188
- afterFileTranspile?: (entry: TranspileObj) => void;
189
- beforeFileDispose?: (file: BscFile) => void;
190
- afterFileDispose?: (file: BscFile) => void;
171
+ afterScopeCreate?: PluginHandler<AfterScopeCreateEvent>;
172
+ beforeScopeDispose?: PluginHandler<BeforeScopeDisposeEvent>;
173
+ afterScopeDispose?: PluginHandler<AfterScopeDisposeEvent>;
174
+ beforeScopeValidate?: PluginHandler<BeforeScopeValidateEvent>;
175
+ afterScopeValidate?: PluginHandler<AfterScopeValidateEvent>;
176
+ beforeFileParse?: PluginHandler<BeforeFileParseEvent>;
177
+ afterFileParse?: PluginHandler<AfterFileParseEvent>;
178
+ beforeFileValidate?: PluginHandler<BeforeFileValidateEvent>;
179
+ afterFileValidate?: PluginHandler<AfterFileValidateEvent>;
180
+ beforeFileTranspile?: PluginHandler<BeforeFileTranspileEvent>;
181
+ afterFileTranspile?: PluginHandler<AfterFileTranspileEvent>;
182
+ beforeFileDispose?: PluginHandler<BeforeFileDisposeEvent>;
183
+ afterFileDispose?: PluginHandler<AfterFileDisposeEvent>;
191
184
  }
192
185
  export declare type PluginHandler<T> = (event: T) => void;
186
+ export interface BeforeProgramCreateEvent {
187
+ builder: ProgramBuilder;
188
+ }
189
+ export interface BeforePrepublishEvent {
190
+ builder: ProgramBuilder;
191
+ program: Program;
192
+ files: FileObj[];
193
+ }
194
+ export interface AfterPrepublishEvent {
195
+ builder: ProgramBuilder;
196
+ program: Program;
197
+ files: FileObj[];
198
+ }
199
+ export interface BeforePublishEvent {
200
+ builder: ProgramBuilder;
201
+ program: Program;
202
+ files: FileObj[];
203
+ }
204
+ export interface AfterPublishEvent {
205
+ builder: ProgramBuilder;
206
+ program: Program;
207
+ files: FileObj[];
208
+ }
209
+ export interface AfterProgramCreateEvent {
210
+ builder: ProgramBuilder;
211
+ program: Program;
212
+ }
213
+ export interface BeforeProgramValidateEvent {
214
+ program: Program;
215
+ }
216
+ export interface AfterProgramValidateEvent {
217
+ program: Program;
218
+ }
219
+ export interface BeforeProgramTranspileEvent {
220
+ program: Program;
221
+ entries: TranspileEntry[];
222
+ }
223
+ export interface AfterProgramTranspileEvent {
224
+ program: Program;
225
+ entries: TranspileEntry[];
226
+ }
193
227
  export interface OnGetCodeActionsEvent {
194
228
  program: Program;
195
229
  file: BscFile;
@@ -198,6 +232,86 @@ export interface OnGetCodeActionsEvent {
198
232
  diagnostics: BsDiagnostic[];
199
233
  codeActions: CodeAction[];
200
234
  }
235
+ export interface AfterScopeCreateEvent {
236
+ program: Program;
237
+ scope: Scope;
238
+ }
239
+ export interface BeforeScopeDisposeEvent {
240
+ program: Program;
241
+ scope: Scope;
242
+ }
243
+ export interface AfterScopeDisposeEvent {
244
+ program: Program;
245
+ scope: Scope;
246
+ }
247
+ export interface BeforeScopeValidateEvent {
248
+ program: Program;
249
+ scope: Scope;
250
+ }
251
+ export interface AfterScopeValidateEvent {
252
+ program: Program;
253
+ scope: Scope;
254
+ }
255
+ export interface OnScopeGetCodeActionsEvent {
256
+ program: Program;
257
+ scope: Scope;
258
+ file: BscFile;
259
+ range: Range;
260
+ /**
261
+ * A filtered list of diagnostics whose lines touch the lines of the given range
262
+ */
263
+ diagnostics: BsDiagnostic[];
264
+ codeActions: CodeAction[];
265
+ }
266
+ export interface BeforeFileParseEvent {
267
+ program: Program;
268
+ srcPath: string;
269
+ source: string;
270
+ }
271
+ export interface AfterFileParseEvent {
272
+ program: Program;
273
+ file: BscFile;
274
+ }
275
+ export interface BeforeFileValidateEvent {
276
+ program: Program;
277
+ file: BscFile;
278
+ }
279
+ export interface AfterFileValidateEvent {
280
+ program: Program;
281
+ file: BscFile;
282
+ }
283
+ export interface BeforeFileTranspileEvent {
284
+ program: Program;
285
+ file: BscFile;
286
+ outputPath: string;
287
+ }
288
+ export interface AfterFileTranspileEvent {
289
+ program: Program;
290
+ file: BscFile;
291
+ outputPath: string;
292
+ }
293
+ export interface BeforeFileDisposeEvent {
294
+ program: Program;
295
+ file: BscFile;
296
+ }
297
+ export interface AfterFileDisposeEvent {
298
+ program: Program;
299
+ file: BscFile;
300
+ }
301
+ export interface OnFileGetCodeActionsEvent {
302
+ program: Program;
303
+ file: BscFile;
304
+ range: Range;
305
+ /**
306
+ * A filtered list of diagnostics whose lines touch the lines of the given range
307
+ */
308
+ diagnostics: BsDiagnostic[];
309
+ codeActions: CodeAction[];
310
+ }
311
+ export interface TranspileEntry {
312
+ file: BscFile;
313
+ outputPath: string;
314
+ }
201
315
  export interface OnGetSemanticTokensEvent {
202
316
  program: Program;
203
317
  file: BscFile;
@@ -216,11 +330,13 @@ export interface TypedefProvider {
216
330
  getTypedef(state: TranspileState): Array<SourceNode | string>;
217
331
  }
218
332
  export declare type TranspileResult = Array<(string | SourceNode)>;
219
- export declare type FileResolver = (pathAbsolute: string) => string | undefined | Thenable<string | undefined> | void;
333
+ /**
334
+ * @param srcPath The absolute path to the source file on disk
335
+ */
336
+ export declare type FileResolver = (srcPath: string) => string | undefined | Thenable<string | undefined> | void;
220
337
  export interface ExpressionInfo {
221
338
  expressions: Expression[];
222
339
  varExpressions: Expression[];
223
340
  uniqueVarNames: string[];
224
341
  }
225
342
  export declare type DiagnosticCode = number | string;
226
- export {};
@@ -1,5 +1,7 @@
1
1
  import type { Range } from 'vscode-languageserver';
2
2
  import type { BrsFile } from '../files/BrsFile';
3
+ import type { Scope } from '../Scope';
4
+ import type { TypeContext } from '../types/BscType';
3
5
  import type { ClassStatement } from './Statement';
4
6
  import { TranspileState } from './TranspileState';
5
7
  export declare class BrsTranspileState extends TranspileState {
@@ -20,4 +22,9 @@ export declare class BrsTranspileState extends TranspileState {
20
22
  * Used by ClassMethodStatements to determine information about their enclosing class
21
23
  */
22
24
  classStatement?: ClassStatement;
25
+ /**
26
+ * Transpilation of LazyTypes needs access to the scope - just pick the first
27
+ */
28
+ get scope(): Scope;
29
+ get typeContext(): TypeContext;
23
30
  }
@@ -4,7 +4,7 @@ exports.BrsTranspileState = void 0;
4
4
  const TranspileState_1 = require("./TranspileState");
5
5
  class BrsTranspileState extends TranspileState_1.TranspileState {
6
6
  constructor(file) {
7
- super(file.pathAbsolute, file.program.options);
7
+ super(file.srcPath, file.program.options);
8
8
  this.file = file;
9
9
  /**
10
10
  * the tree of parents, with the first index being direct parent, and the last index being the furthest removed ancestor.
@@ -13,6 +13,15 @@ class BrsTranspileState extends TranspileState_1.TranspileState {
13
13
  this.lineage = [];
14
14
  this.bslibPrefix = this.file.program.bslibPrefix;
15
15
  }
16
+ /**
17
+ * Transpilation of LazyTypes needs access to the scope - just pick the first
18
+ */
19
+ get scope() {
20
+ return this.file.program.getScopesForFile(this.file)[0];
21
+ }
22
+ get typeContext() {
23
+ return { file: this.file, scope: this.scope };
24
+ }
16
25
  }
17
26
  exports.BrsTranspileState = BrsTranspileState;
18
27
  //# sourceMappingURL=BrsTranspileState.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BrsTranspileState.js","sourceRoot":"","sources":["../../src/parser/BrsTranspileState.ts"],"names":[],"mappings":";;;AAGA,qDAAkD;AAElD,MAAa,iBAAkB,SAAQ,+BAAc;IACjD,YACW,IAAa;QAEpB,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAFxC,SAAI,GAAJ,IAAI,CAAS;QAWxB;;;WAGG;QACH,YAAO,GAAG,EAER,CAAC;QAdC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;IACrD,CAAC;CAmBJ;AAzBD,8CAyBC"}
1
+ {"version":3,"file":"BrsTranspileState.js","sourceRoot":"","sources":["../../src/parser/BrsTranspileState.ts"],"names":[],"mappings":";;;AAKA,qDAAkD;AAElD,MAAa,iBAAkB,SAAQ,+BAAc;IACjD,YACW,IAAa;QAEpB,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAFnC,SAAI,GAAJ,IAAI,CAAS;QAWxB;;;WAGG;QACH,YAAO,GAAG,EAER,CAAC;QAdC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;IACrD,CAAC;IAoBD;;OAEG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,IAAW,WAAW;QAClB,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IAClD,CAAC;CACJ;AApCD,8CAoCC"}
@@ -1,12 +1,13 @@
1
1
  import type { Token, Identifier } from '../lexer';
2
- import type { Block, CommentStatement, FunctionStatement } from './Statement';
2
+ import type { Block, CommentStatement, FunctionStatement, LabelStatement } from './Statement';
3
3
  import type { Range } from 'vscode-languageserver';
4
4
  import type { BrsTranspileState } from './BrsTranspileState';
5
5
  import { ParseMode } from './Parser';
6
6
  import type { WalkOptions, WalkVisitor } from '../astUtils/visitors';
7
7
  import { InternalWalkMode } from '../astUtils/visitors';
8
8
  import type { TranspileResult, TypedefProvider } from '../interfaces';
9
- import type { BscType } from '../types/BscType';
9
+ import type { BscType, SymbolContainer } from '../types/BscType';
10
+ import { SymbolTable } from '../SymbolTable';
10
11
  import { FunctionType } from '../types/FunctionType';
11
12
  export declare type ExpressionVisitor = (expression: Expression, parent: Expression) => void;
12
13
  /** A BrightScript expression */
@@ -64,11 +65,14 @@ export declare class FunctionExpression extends Expression implements TypedefPro
64
65
  */
65
66
  readonly parentFunction?: FunctionExpression;
66
67
  readonly namespaceName?: NamespacedVariableNameExpression;
68
+ readonly parentSymbolTable?: SymbolTable;
67
69
  constructor(parameters: FunctionParameterExpression[], body: Block, functionType: Token | null, end: Token, leftParen: Token, rightParen: Token, asToken?: Token, returnTypeToken?: Token,
68
70
  /**
69
71
  * If this function is enclosed within another function, this will reference that parent function
70
72
  */
71
- parentFunction?: FunctionExpression, namespaceName?: NamespacedVariableNameExpression);
73
+ parentFunction?: FunctionExpression, namespaceName?: NamespacedVariableNameExpression, parentSymbolTable?: SymbolTable);
74
+ readonly symbolTable: SymbolTable;
75
+ labelStatements: LabelStatement[];
72
76
  /**
73
77
  * The type this function returns
74
78
  */
@@ -98,15 +102,17 @@ export declare class FunctionExpression extends Expression implements TypedefPro
98
102
  }
99
103
  export declare class FunctionParameterExpression extends Expression {
100
104
  name: Identifier;
101
- typeToken?: Token;
105
+ type: BscType;
106
+ equalsToken?: Token;
102
107
  defaultValue?: Expression;
103
108
  asToken?: Token;
109
+ typeToken?: Token;
104
110
  readonly namespaceName?: NamespacedVariableNameExpression;
105
- constructor(name: Identifier, typeToken?: Token, defaultValue?: Expression, asToken?: Token, namespaceName?: NamespacedVariableNameExpression);
106
- type: BscType;
111
+ constructor(name: Identifier, type: BscType, equalsToken?: Token, defaultValue?: Expression, asToken?: Token, typeToken?: Token, namespaceName?: NamespacedVariableNameExpression);
107
112
  get range(): Range;
108
113
  transpile(state: BrsTranspileState): any[];
109
114
  walk(visitor: WalkVisitor, options: WalkOptions): void;
115
+ get isOptional(): boolean;
110
116
  }
111
117
  export declare class NamespacedVariableNameExpression extends Expression {
112
118
  readonly expression: DottedGetExpression | VariableExpression;
@@ -114,7 +120,7 @@ export declare class NamespacedVariableNameExpression extends Expression {
114
120
  range: Range;
115
121
  transpile(state: BrsTranspileState): import("source-map").SourceNode[];
116
122
  getNameParts(): string[];
117
- getName(parseMode: ParseMode): string;
123
+ getName(parseMode?: ParseMode): string;
118
124
  walk(visitor: WalkVisitor, options: WalkOptions): void;
119
125
  }
120
126
  export declare class DottedGetExpression extends Expression {
@@ -200,20 +206,25 @@ export declare class AAMemberExpression extends Expression {
200
206
  colonToken: Token;
201
207
  /** The expression evaluated to determine the member's initial value. */
202
208
  value: Expression;
209
+ type: BscType;
203
210
  constructor(keyToken: Token, colonToken: Token,
204
211
  /** The expression evaluated to determine the member's initial value. */
205
- value: Expression);
212
+ value: Expression, type: BscType);
206
213
  range: Range;
207
214
  commaToken?: Token;
208
215
  transpile(state: BrsTranspileState): any[];
209
216
  walk(visitor: WalkVisitor, options: WalkOptions): void;
210
217
  }
211
- export declare class AALiteralExpression extends Expression {
218
+ export declare class AALiteralExpression extends Expression implements SymbolContainer {
212
219
  readonly elements: Array<AAMemberExpression | CommentStatement>;
213
220
  readonly open: Token;
214
221
  readonly close: Token;
215
- constructor(elements: Array<AAMemberExpression | CommentStatement>, open: Token, close: Token);
222
+ readonly functionExpression: FunctionExpression;
223
+ constructor(elements: Array<AAMemberExpression | CommentStatement>, open: Token, close: Token, functionExpression: FunctionExpression);
224
+ readonly symbolTable: SymbolTable;
225
+ readonly memberTable: SymbolTable;
216
226
  readonly range: Range;
227
+ buildSymbolTable(): void;
217
228
  transpile(state: BrsTranspileState): any[];
218
229
  walk(visitor: WalkVisitor, options: WalkOptions): void;
219
230
  }
@@ -226,8 +237,8 @@ export declare class UnaryExpression extends Expression {
226
237
  walk(visitor: WalkVisitor, options: WalkOptions): void;
227
238
  }
228
239
  export declare class VariableExpression extends Expression {
229
- readonly name: Identifier;
230
- readonly namespaceName: NamespacedVariableNameExpression;
240
+ name: Identifier;
241
+ namespaceName: NamespacedVariableNameExpression;
231
242
  constructor(name: Identifier, namespaceName: NamespacedVariableNameExpression);
232
243
  readonly range: Range;
233
244
  isCalled: boolean;
@@ -9,7 +9,9 @@ const visitors_1 = require("../astUtils/visitors");
9
9
  const reflection_1 = require("../astUtils/reflection");
10
10
  const VoidType_1 = require("../types/VoidType");
11
11
  const DynamicType_1 = require("../types/DynamicType");
12
+ const SymbolTable_1 = require("../SymbolTable");
12
13
  const FunctionType_1 = require("../types/FunctionType");
14
+ const ObjectType_1 = require("../types/ObjectType");
13
15
  /** A BrightScript expression */
14
16
  class Expression {
15
17
  constructor() {
@@ -90,13 +92,13 @@ class CallExpression extends Expression {
90
92
  }
91
93
  }
92
94
  exports.CallExpression = CallExpression;
93
- CallExpression.MaximumArguments = 32;
95
+ CallExpression.MaximumArguments = util_1.MAX_PARAM_COUNT;
94
96
  class FunctionExpression extends Expression {
95
97
  constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeToken,
96
98
  /**
97
99
  * If this function is enclosed within another function, this will reference that parent function
98
100
  */
99
- parentFunction, namespaceName) {
101
+ parentFunction, namespaceName, parentSymbolTable) {
100
102
  super();
101
103
  this.parameters = parameters;
102
104
  this.body = body;
@@ -108,6 +110,8 @@ class FunctionExpression extends Expression {
108
110
  this.returnTypeToken = returnTypeToken;
109
111
  this.parentFunction = parentFunction;
110
112
  this.namespaceName = namespaceName;
113
+ this.parentSymbolTable = parentSymbolTable;
114
+ this.labelStatements = [];
111
115
  /**
112
116
  * The list of function calls that are declared within this function scope. This excludes CallExpressions
113
117
  * declared in child functions
@@ -118,7 +122,7 @@ class FunctionExpression extends Expression {
118
122
  */
119
123
  this.childFunctionExpressions = [];
120
124
  if (this.returnTypeToken) {
121
- this.returnType = util_1.default.tokenToBscType(this.returnTypeToken);
125
+ this.returnType = util_1.default.tokenToBscType(this.returnTypeToken, true, namespaceName);
122
126
  }
123
127
  else if (this.functionType.text.toLowerCase() === 'sub') {
124
128
  this.returnType = new VoidType_1.VoidType();
@@ -126,6 +130,10 @@ class FunctionExpression extends Expression {
126
130
  else {
127
131
  this.returnType = new DynamicType_1.DynamicType();
128
132
  }
133
+ this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
134
+ for (let param of parameters) {
135
+ this.symbolTable.addSymbol(param.name.text, param.name.range, param.type);
136
+ }
129
137
  }
130
138
  /**
131
139
  * The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
@@ -163,7 +171,7 @@ class FunctionExpression extends Expression {
163
171
  //as
164
172
  state.transpileToken(this.asToken), ' ',
165
173
  //return type
166
- state.sourceNode(this.returnTypeToken, this.returnType.toTypeString()));
174
+ state.sourceNode(this.returnTypeToken, this.returnType.toTypeString(state.typeContext)));
167
175
  }
168
176
  if (includeBody) {
169
177
  state.lineage.unshift(this);
@@ -194,26 +202,22 @@ class FunctionExpression extends Expression {
194
202
  let functionType = new FunctionType_1.FunctionType(this.returnType);
195
203
  functionType.isSub = this.functionType.text === 'sub';
196
204
  for (let param of this.parameters) {
197
- functionType.addParameter(param.name.text, param.type, !!param.typeToken);
205
+ functionType.addParameter(param.name.text, param.type, param.isOptional);
198
206
  }
199
207
  return functionType;
200
208
  }
201
209
  }
202
210
  exports.FunctionExpression = FunctionExpression;
203
211
  class FunctionParameterExpression extends Expression {
204
- constructor(name, typeToken, defaultValue, asToken, namespaceName) {
212
+ constructor(name, type, equalsToken, defaultValue, asToken, typeToken, namespaceName) {
205
213
  super();
206
214
  this.name = name;
207
- this.typeToken = typeToken;
215
+ this.type = type;
216
+ this.equalsToken = equalsToken;
208
217
  this.defaultValue = defaultValue;
209
218
  this.asToken = asToken;
219
+ this.typeToken = typeToken;
210
220
  this.namespaceName = namespaceName;
211
- if (typeToken) {
212
- this.type = util_1.default.tokenToBscType(typeToken);
213
- }
214
- else {
215
- this.type = new DynamicType_1.DynamicType();
216
- }
217
221
  }
218
222
  get range() {
219
223
  return {
@@ -236,7 +240,7 @@ class FunctionParameterExpression extends Expression {
236
240
  result.push(' ');
237
241
  result.push(state.transpileToken(this.asToken));
238
242
  result.push(' ');
239
- result.push(state.sourceNode(this.typeToken, this.type.toTypeString()));
243
+ result.push(state.sourceNode(this.typeToken, this.type.toTypeString(state.typeContext)));
240
244
  }
241
245
  return result;
242
246
  }
@@ -246,6 +250,9 @@ class FunctionParameterExpression extends Expression {
246
250
  (0, visitors_1.walk)(this, 'defaultValue', visitor, options);
247
251
  }
248
252
  }
253
+ get isOptional() {
254
+ return !!this.defaultValue;
255
+ }
249
256
  }
250
257
  exports.FunctionParameterExpression = FunctionParameterExpression;
251
258
  class NamespacedVariableNameExpression extends Expression {
@@ -276,7 +283,7 @@ class NamespacedVariableNameExpression extends Expression {
276
283
  }
277
284
  return parts;
278
285
  }
279
- getName(parseMode) {
286
+ getName(parseMode = Parser_1.ParseMode.BrighterScript) {
280
287
  if (parseMode === Parser_1.ParseMode.BrighterScript) {
281
288
  return this.getNameParts().join('.');
282
289
  }
@@ -505,11 +512,12 @@ exports.ArrayLiteralExpression = ArrayLiteralExpression;
505
512
  class AAMemberExpression extends Expression {
506
513
  constructor(keyToken, colonToken,
507
514
  /** The expression evaluated to determine the member's initial value. */
508
- value) {
515
+ value, type) {
509
516
  super();
510
517
  this.keyToken = keyToken;
511
518
  this.colonToken = colonToken;
512
519
  this.value = value;
520
+ this.type = type;
513
521
  this.range = util_1.default.createRangeFromPositions(keyToken.range.start, this.value.range.end);
514
522
  }
515
523
  transpile(state) {
@@ -522,12 +530,25 @@ class AAMemberExpression extends Expression {
522
530
  }
523
531
  exports.AAMemberExpression = AAMemberExpression;
524
532
  class AALiteralExpression extends Expression {
525
- constructor(elements, open, close) {
533
+ constructor(elements, open, close, functionExpression) {
526
534
  super();
527
535
  this.elements = elements;
528
536
  this.open = open;
529
537
  this.close = close;
538
+ this.functionExpression = functionExpression;
539
+ this.symbolTable = new SymbolTable_1.SymbolTable();
540
+ this.memberTable = new SymbolTable_1.SymbolTable();
530
541
  this.range = util_1.default.createRangeFromPositions(this.open.range.start, this.close.range.end);
542
+ this.buildSymbolTable();
543
+ }
544
+ buildSymbolTable() {
545
+ this.symbolTable.clear();
546
+ this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType(this.memberTable));
547
+ for (const element of this.elements) {
548
+ if ((0, reflection_1.isAAMemberExpression)(element)) {
549
+ this.memberTable.addSymbol(element.keyToken.text, element.keyToken.range, (0, Parser_1.getBscTypeFromExpression)(element.value, this.functionExpression));
550
+ }
551
+ }
531
552
  }
532
553
  transpile(state) {
533
554
  let result = [];
@@ -667,15 +688,15 @@ class SourceLiteralExpression extends Expression {
667
688
  this.range = token.range;
668
689
  }
669
690
  getFunctionName(state, parseMode) {
670
- let func = state.file.getFunctionScopeAtPosition(this.token.range.start).func;
691
+ let functionExpression = state.file.getFunctionExpressionAtPosition(this.token.range.start);
671
692
  let nameParts = [];
672
- while (func.parentFunction) {
673
- let index = func.parentFunction.childFunctionExpressions.indexOf(func);
693
+ while (functionExpression.parentFunction) {
694
+ let index = functionExpression.parentFunction.childFunctionExpressions.indexOf(functionExpression);
674
695
  nameParts.unshift(`anon${index}`);
675
- func = func.parentFunction;
696
+ functionExpression = functionExpression.parentFunction;
676
697
  }
677
698
  //get the index of this function in its parent
678
- nameParts.unshift(func.functionStatement.getName(parseMode));
699
+ nameParts.unshift(functionExpression.functionStatement.getName(parseMode));
679
700
  return nameParts.join('$');
680
701
  }
681
702
  transpile(state) {
@@ -699,16 +720,10 @@ class SourceLiteralExpression extends Expression {
699
720
  text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
700
721
  break;
701
722
  case lexer_1.TokenKind.PkgPathLiteral:
702
- let pkgPath1 = `pkg:/${state.file.pkgPath}`
703
- .replace(/\\/g, '/')
704
- .replace(/\.bs$/i, '.brs');
705
- text = `"${pkgPath1}"`;
723
+ text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}"`;
706
724
  break;
707
725
  case lexer_1.TokenKind.PkgLocationLiteral:
708
- let pkgPath2 = `pkg:/${state.file.pkgPath}`
709
- .replace(/\\/g, '/')
710
- .replace(/\.bs$/i, '.brs');
711
- text = `"${pkgPath2}:" + str(LINE_NUM)`;
726
+ text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}:" + str(LINE_NUM)`;
712
727
  break;
713
728
  case lexer_1.TokenKind.LineNumLiteral:
714
729
  default: