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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/CHANGELOG.md +83 -1
  2. package/README.md +28 -9
  3. package/dist/Cache.d.ts +2 -7
  4. package/dist/Cache.js +4 -13
  5. package/dist/Cache.js.map +1 -1
  6. package/dist/DependencyGraph.js +5 -4
  7. package/dist/DependencyGraph.js.map +1 -1
  8. package/dist/DiagnosticMessages.d.ts +21 -1
  9. package/dist/DiagnosticMessages.js +21 -1
  10. package/dist/DiagnosticMessages.js.map +1 -1
  11. package/dist/Logger.js +5 -5
  12. package/dist/Logger.js.map +1 -1
  13. package/dist/Program.d.ts +3 -3
  14. package/dist/Program.js +9 -7
  15. package/dist/Program.js.map +1 -1
  16. package/dist/ProgramBuilder.js +1 -1
  17. package/dist/ProgramBuilder.js.map +1 -1
  18. package/dist/Scope.d.ts +16 -11
  19. package/dist/Scope.js +42 -12
  20. package/dist/Scope.js.map +1 -1
  21. package/dist/XmlScope.d.ts +3 -3
  22. package/dist/XmlScope.js +1 -1
  23. package/dist/XmlScope.js.map +1 -1
  24. package/dist/astUtils/AstEditor.d.ts +6 -0
  25. package/dist/astUtils/AstEditor.js +10 -0
  26. package/dist/astUtils/AstEditor.js.map +1 -1
  27. package/dist/astUtils/AstEditor.spec.js +37 -0
  28. package/dist/astUtils/AstEditor.spec.js.map +1 -1
  29. package/dist/astUtils/creators.d.ts +10 -6
  30. package/dist/astUtils/creators.js +93 -12
  31. package/dist/astUtils/creators.js.map +1 -1
  32. package/dist/astUtils/creators.spec.js +10 -0
  33. package/dist/astUtils/creators.spec.js.map +1 -1
  34. package/dist/astUtils/reflection.d.ts +7 -2
  35. package/dist/astUtils/reflection.js +19 -3
  36. package/dist/astUtils/reflection.js.map +1 -1
  37. package/dist/astUtils/reflection.spec.js +5 -4
  38. package/dist/astUtils/reflection.spec.js.map +1 -1
  39. package/dist/astUtils/visitors.d.ts +3 -1
  40. package/dist/astUtils/visitors.js.map +1 -1
  41. package/dist/astUtils/visitors.spec.js +2 -0
  42. package/dist/astUtils/visitors.spec.js.map +1 -1
  43. package/dist/bscPlugin/BscPlugin.d.ts +4 -1
  44. package/dist/bscPlugin/BscPlugin.js +16 -0
  45. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  46. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +1 -0
  47. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +38 -2
  48. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  49. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +28 -0
  50. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
  51. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +8 -0
  52. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +40 -0
  53. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
  54. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +1 -0
  55. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
  56. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
  57. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +9 -0
  58. package/dist/bscPlugin/validation/BrsFileValidator.js +66 -0
  59. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
  60. package/dist/bscPlugin/validation/ScopeValidator.d.ts +11 -0
  61. package/dist/bscPlugin/validation/ScopeValidator.js +94 -0
  62. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
  63. package/dist/diagnosticUtils.js +3 -3
  64. package/dist/diagnosticUtils.js.map +1 -1
  65. package/dist/examples/plugins/removePrint.js +12 -14
  66. package/dist/examples/plugins/removePrint.js.map +1 -1
  67. package/dist/files/BrsFile.Class.spec.js +22 -23
  68. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  69. package/dist/files/BrsFile.d.ts +10 -3
  70. package/dist/files/BrsFile.js +133 -49
  71. package/dist/files/BrsFile.js.map +1 -1
  72. package/dist/files/BrsFile.spec.js +299 -123
  73. package/dist/files/BrsFile.spec.js.map +1 -1
  74. package/dist/files/XmlFile.d.ts +5 -5
  75. package/dist/files/XmlFile.js +3 -3
  76. package/dist/files/XmlFile.js.map +1 -1
  77. package/dist/files/XmlFile.spec.js +9 -9
  78. package/dist/files/XmlFile.spec.js.map +1 -1
  79. package/dist/interfaces.d.ts +29 -37
  80. package/dist/lexer/Lexer.spec.js +8 -0
  81. package/dist/lexer/Lexer.spec.js.map +1 -1
  82. package/dist/lexer/TokenKind.d.ts +2 -0
  83. package/dist/lexer/TokenKind.js +5 -0
  84. package/dist/lexer/TokenKind.js.map +1 -1
  85. package/dist/parser/Expression.d.ts +85 -21
  86. package/dist/parser/Expression.js +177 -53
  87. package/dist/parser/Expression.js.map +1 -1
  88. package/dist/parser/Parser.Class.spec.js +1 -1
  89. package/dist/parser/Parser.Class.spec.js.map +1 -1
  90. package/dist/parser/Parser.d.ts +12 -3
  91. package/dist/parser/Parser.js +156 -56
  92. package/dist/parser/Parser.js.map +1 -1
  93. package/dist/parser/Parser.spec.js +57 -2
  94. package/dist/parser/Parser.spec.js.map +1 -1
  95. package/dist/parser/Statement.d.ts +94 -30
  96. package/dist/parser/Statement.js +281 -106
  97. package/dist/parser/Statement.js.map +1 -1
  98. package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
  99. package/dist/parser/tests/statement/Enum.spec.js +774 -0
  100. package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
  101. package/dist/parser/tests/statement/For.spec.d.ts +1 -0
  102. package/dist/parser/tests/statement/For.spec.js +46 -0
  103. package/dist/parser/tests/statement/For.spec.js.map +1 -0
  104. package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
  105. package/dist/parser/tests/statement/ForEach.spec.js +37 -0
  106. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
  107. package/dist/types/BooleanType.d.ts +4 -2
  108. package/dist/types/BooleanType.js +5 -1
  109. package/dist/types/BooleanType.js.map +1 -1
  110. package/dist/types/DoubleType.d.ts +2 -0
  111. package/dist/types/DoubleType.js +5 -1
  112. package/dist/types/DoubleType.js.map +1 -1
  113. package/dist/types/DynamicType.d.ts +2 -0
  114. package/dist/types/DynamicType.js +5 -1
  115. package/dist/types/DynamicType.js.map +1 -1
  116. package/dist/types/FloatType.d.ts +3 -1
  117. package/dist/types/FloatType.js +5 -1
  118. package/dist/types/FloatType.js.map +1 -1
  119. package/dist/types/FunctionType.d.ts +2 -1
  120. package/dist/types/FunctionType.js +11 -8
  121. package/dist/types/FunctionType.js.map +1 -1
  122. package/dist/types/FunctionType.spec.js +6 -0
  123. package/dist/types/FunctionType.spec.js.map +1 -1
  124. package/dist/types/IntegerType.d.ts +3 -1
  125. package/dist/types/IntegerType.js +5 -1
  126. package/dist/types/IntegerType.js.map +1 -1
  127. package/dist/types/InvalidType.d.ts +4 -2
  128. package/dist/types/InvalidType.js +5 -1
  129. package/dist/types/InvalidType.js.map +1 -1
  130. package/dist/types/LongIntegerType.d.ts +3 -1
  131. package/dist/types/LongIntegerType.js +5 -1
  132. package/dist/types/LongIntegerType.js.map +1 -1
  133. package/dist/types/ObjectType.d.ts +2 -1
  134. package/dist/types/ObjectType.js +4 -2
  135. package/dist/types/ObjectType.js.map +1 -1
  136. package/dist/types/StringType.d.ts +4 -2
  137. package/dist/types/StringType.js +5 -1
  138. package/dist/types/StringType.js.map +1 -1
  139. package/dist/types/UninitializedType.js.map +1 -1
  140. package/dist/types/UniversalFunctionType.d.ts +9 -0
  141. package/dist/types/UniversalFunctionType.js +25 -0
  142. package/dist/types/UniversalFunctionType.js.map +1 -0
  143. package/dist/types/VoidType.d.ts +4 -2
  144. package/dist/types/VoidType.js +5 -1
  145. package/dist/types/VoidType.js.map +1 -1
  146. package/dist/util.d.ts +12 -2
  147. package/dist/util.js +74 -44
  148. package/dist/util.js.map +1 -1
  149. package/dist/validators/ClassValidator.js +3 -3
  150. package/dist/validators/ClassValidator.js.map +1 -1
  151. package/package.json +2 -3
@@ -6,9 +6,12 @@ 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 { VoidType } from '../types/VoidType';
10
+ import { DynamicType } from '../types/DynamicType';
9
11
  import type { BscType, SymbolContainer } from '../types/BscType';
10
12
  import { SymbolTable } from '../SymbolTable';
11
13
  import { FunctionType } from '../types/FunctionType';
14
+ import { ArrayType } from '../types/ArrayType';
12
15
  export declare type ExpressionVisitor = (expression: Expression, parent: Expression) => void;
13
16
  /** A BrightScript expression */
14
17
  export declare abstract class Expression {
@@ -59,24 +62,31 @@ export declare class FunctionExpression extends Expression implements TypedefPro
59
62
  readonly leftParen: Token;
60
63
  readonly rightParen: Token;
61
64
  readonly asToken?: Token;
62
- readonly returnTypeToken?: Token;
65
+ readonly returnType?: TypeExpression;
63
66
  /**
64
67
  * If this function is enclosed within another function, this will reference that parent function
65
68
  */
66
69
  readonly parentFunction?: FunctionExpression;
67
70
  readonly namespaceName?: NamespacedVariableNameExpression;
68
71
  readonly parentSymbolTable?: SymbolTable;
69
- constructor(parameters: FunctionParameterExpression[], body: Block, functionType: Token | null, end: Token, leftParen: Token, rightParen: Token, asToken?: Token, returnTypeToken?: Token,
72
+ constructor(parameters: FunctionParameterExpression[], body: Block, functionType: Token | null, end: Token, leftParen: Token, rightParen: Token, asToken?: Token, returnType?: TypeExpression,
70
73
  /**
71
74
  * If this function is enclosed within another function, this will reference that parent function
72
75
  */
73
76
  parentFunction?: FunctionExpression, namespaceName?: NamespacedVariableNameExpression, parentSymbolTable?: SymbolTable);
77
+ get range(): Range;
78
+ /**
79
+ * The range of the function
80
+ */
81
+ cacheRange(): Range;
82
+ private _range;
74
83
  readonly symbolTable: SymbolTable;
75
84
  labelStatements: LabelStatement[];
85
+ private _returnType;
76
86
  /**
77
87
  * The type this function returns
78
88
  */
79
- returnType: BscType;
89
+ getReturnType(): BscType;
80
90
  /**
81
91
  * The list of function calls that are declared within this function scope. This excludes CallExpressions
82
92
  * declared in child functions
@@ -90,11 +100,6 @@ export declare class FunctionExpression extends Expression implements TypedefPro
90
100
  * A list of all child functions declared directly within this function
91
101
  */
92
102
  childFunctionExpressions: FunctionExpression[];
93
- /**
94
- * The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
95
- * and ending with the last n' in 'end function' or 'b' in 'end sub'
96
- */
97
- get range(): Range;
98
103
  transpile(state: BrsTranspileState, name?: Identifier, includeBody?: boolean): any[];
99
104
  getTypedef(state: BrsTranspileState, name?: Identifier): any[];
100
105
  walk(visitor: WalkVisitor, options: WalkOptions): void;
@@ -102,14 +107,15 @@ export declare class FunctionExpression extends Expression implements TypedefPro
102
107
  }
103
108
  export declare class FunctionParameterExpression extends Expression {
104
109
  name: Identifier;
105
- type: BscType;
110
+ private typeInContext;
106
111
  equalsToken?: Token;
107
112
  defaultValue?: Expression;
108
113
  asToken?: Token;
109
- typeToken?: Token;
114
+ type?: TypeExpression;
110
115
  readonly namespaceName?: NamespacedVariableNameExpression;
111
- constructor(name: Identifier, type: BscType, equalsToken?: Token, defaultValue?: Expression, asToken?: Token, typeToken?: Token, namespaceName?: NamespacedVariableNameExpression);
112
- get range(): Range;
116
+ constructor(name: Identifier, typeInContext: BscType, equalsToken?: Token, defaultValue?: Expression, asToken?: Token, type?: TypeExpression, namespaceName?: NamespacedVariableNameExpression);
117
+ readonly range: Range;
118
+ getType(): BscType;
113
119
  transpile(state: BrsTranspileState): any[];
114
120
  walk(visitor: WalkVisitor, options: WalkOptions): void;
115
121
  get isOptional(): boolean;
@@ -117,7 +123,7 @@ export declare class FunctionParameterExpression extends Expression {
117
123
  export declare class NamespacedVariableNameExpression extends Expression {
118
124
  readonly expression: DottedGetExpression | VariableExpression;
119
125
  constructor(expression: DottedGetExpression | VariableExpression);
120
- range: Range;
126
+ readonly range: Range;
121
127
  transpile(state: BrsTranspileState): import("source-map").SourceNode[];
122
128
  getNameParts(): string[];
123
129
  getName(parseMode?: ParseMode): string;
@@ -168,7 +174,7 @@ export declare class GroupingExpression extends Expression {
168
174
  export declare class LiteralExpression extends Expression {
169
175
  token: Token;
170
176
  constructor(token: Token);
171
- get range(): Range;
177
+ readonly range: Range;
172
178
  /**
173
179
  * The (data) type of this expression
174
180
  */
@@ -210,7 +216,7 @@ export declare class AAMemberExpression extends Expression {
210
216
  constructor(keyToken: Token, colonToken: Token,
211
217
  /** The expression evaluated to determine the member's initial value. */
212
218
  value: Expression, type: BscType);
213
- range: Range;
219
+ readonly range: Range;
214
220
  commaToken?: Token;
215
221
  transpile(state: BrsTranspileState): any[];
216
222
  walk(visitor: WalkVisitor, options: WalkOptions): void;
@@ -221,9 +227,9 @@ export declare class AALiteralExpression extends Expression implements SymbolCon
221
227
  readonly close: Token;
222
228
  readonly functionExpression: FunctionExpression;
223
229
  constructor(elements: Array<AAMemberExpression | CommentStatement>, open: Token, close: Token, functionExpression: FunctionExpression);
230
+ readonly range: Range;
224
231
  readonly symbolTable: SymbolTable;
225
232
  readonly memberTable: SymbolTable;
226
- readonly range: Range;
227
233
  buildSymbolTable(): void;
228
234
  transpile(state: BrsTranspileState): any[];
229
235
  walk(visitor: WalkVisitor, options: WalkOptions): void;
@@ -241,7 +247,6 @@ export declare class VariableExpression extends Expression {
241
247
  namespaceName: NamespacedVariableNameExpression;
242
248
  constructor(name: Identifier, namespaceName: NamespacedVariableNameExpression);
243
249
  readonly range: Range;
244
- isCalled: boolean;
245
250
  getName(parseMode: ParseMode): string;
246
251
  transpile(state: BrsTranspileState): any[];
247
252
  walk(visitor: WalkVisitor, options: WalkOptions): void;
@@ -263,12 +268,12 @@ export declare class NewExpression extends Expression {
263
268
  readonly newKeyword: Token;
264
269
  readonly call: CallExpression;
265
270
  constructor(newKeyword: Token, call: CallExpression);
271
+ readonly range: Range;
266
272
  /**
267
273
  * The name of the class to initialize (with optional namespace prefixed)
268
274
  */
269
275
  get className(): NamespacedVariableNameExpression;
270
276
  get namespaceName(): NamespacedVariableNameExpression;
271
- readonly range: Range;
272
277
  transpile(state: BrsTranspileState): any[];
273
278
  walk(visitor: WalkVisitor, options: WalkOptions): void;
274
279
  }
@@ -320,8 +325,10 @@ export declare class AnnotationExpression extends Expression {
320
325
  readonly atToken: Token;
321
326
  readonly nameToken: Token;
322
327
  constructor(atToken: Token, nameToken: Token);
328
+ get range(): Range;
329
+ cacheRange(): Range;
330
+ private _range;
323
331
  name: string;
324
- range: Range;
325
332
  call: CallExpression;
326
333
  /**
327
334
  * Convert annotation arguments to JavaScript types
@@ -339,7 +346,7 @@ export declare class TernaryExpression extends Expression {
339
346
  readonly colonToken?: Token;
340
347
  readonly alternate?: Expression;
341
348
  constructor(test: Expression, questionMarkToken: Token, consequent?: Expression, colonToken?: Token, alternate?: Expression);
342
- range: Range;
349
+ readonly range: Range;
343
350
  transpile(state: BrsTranspileState): any[];
344
351
  walk(visitor: WalkVisitor, options: WalkOptions): void;
345
352
  }
@@ -359,10 +366,67 @@ export declare class RegexLiteralExpression extends Expression {
359
366
  constructor(tokens: {
360
367
  regexLiteral: Token;
361
368
  });
362
- get range(): Range;
369
+ readonly range: Range;
363
370
  transpile(state: BrsTranspileState): TranspileResult;
364
371
  walk(visitor: WalkVisitor, options: WalkOptions): void;
365
372
  }
373
+ export declare class TypeExpression extends Expression {
374
+ private tokens;
375
+ namespaceName?: NamespacedVariableNameExpression;
376
+ constructor(tokens: {
377
+ type?: Token;
378
+ }, namespaceName?: NamespacedVariableNameExpression);
379
+ readonly range: Range;
380
+ private _type;
381
+ /**
382
+ * The this TypeExpression refers to
383
+ */
384
+ get type(): BscType;
385
+ /**
386
+ * Derive a BscType from the type token
387
+ * Can deal with multiple brackets to make multidimensional arrays, eg. float[][]
388
+ * Defaults to `DynamicType`
389
+ */
390
+ getType(parseMode?: ParseMode): DynamicType | BscType | import("../types/FloatType").FloatType | import("../types/IntegerType").IntegerType | import("../types/DoubleType").DoubleType | import("../types/LongIntegerType").LongIntegerType | import("../types/StringType").StringType | import("../types/BooleanType").BooleanType | import("../types/UniversalFunctionType").UniversalFunctionType | import("../types/InvalidType").InvalidType | VoidType;
391
+ /**
392
+ * Is this a valid, (eg. known) type?
393
+ */
394
+ isValidType(parseMode?: ParseMode): boolean;
395
+ /**
396
+ * Gives a human readable string that says the type
397
+ * @returns text to display to show the type
398
+ */
399
+ getText(): string;
400
+ transpile(state: BrsTranspileState): TranspileResult;
401
+ walk(visitor: WalkVisitor, options: WalkOptions): void;
402
+ }
403
+ export declare class ArrayTypeExpression extends TypeExpression {
404
+ innerTypes: TypeExpression[];
405
+ private bracketTokens;
406
+ namespaceName?: NamespacedVariableNameExpression;
407
+ constructor(innerTypes: TypeExpression[], // this is an array so that in the future when we support union types
408
+ bracketTokens: {
409
+ leftBracket?: Token;
410
+ rightBracket?: Token;
411
+ }, namespaceName?: NamespacedVariableNameExpression);
412
+ readonly range: Range;
413
+ private get defaultTypeExpression();
414
+ /**
415
+ * Derive a BscType from the type token
416
+ * Returns an array type with the inner types based on the inner type expressions
417
+ */
418
+ getType(parseMode?: ParseMode): ArrayType;
419
+ /**
420
+ * Is this a valid, (eg. known) type?
421
+ */
422
+ isValidType(parseMode?: ParseMode): boolean;
423
+ /**
424
+ * Gives a human readable string that says the type
425
+ * @returns text to display to show the type
426
+ */
427
+ getText(): string;
428
+ walk(visitor: WalkVisitor, options: WalkOptions): void;
429
+ }
366
430
  declare type ExpressionValue = string | number | boolean | Expression | ExpressionValue[] | {
367
431
  [key: string]: ExpressionValue;
368
432
  };