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
@@ -1,53 +1,141 @@
1
1
  import { SourceNode } from 'source-map';
2
2
  import type { Range } from 'vscode-languageserver';
3
- import type { FileReference, TranspileResult } from '../interfaces';
3
+ import type { FileReference } from '../interfaces';
4
+ import { BooleanType } from '../types/BooleanType';
5
+ import { DynamicType } from '../types/DynamicType';
6
+ import { FloatType } from '../types/FloatType';
7
+ import { FunctionType } from '../types/FunctionType';
8
+ import { IntegerType } from '../types/IntegerType';
9
+ import { LongIntegerType } from '../types/LongIntegerType';
10
+ import { StringType } from '../types/StringType';
4
11
  import type { TranspileState } from './TranspileState';
5
12
  export interface SGToken {
6
13
  text: string;
7
14
  range?: Range;
8
15
  }
9
- export interface SGAttribute {
10
- key: SGToken;
11
- value: SGToken;
12
- range?: Range;
16
+ export declare class SGAttribute {
17
+ constructor(key: SGToken, equals?: SGToken, openingQuote?: SGToken, value?: SGToken, closingQuote?: SGToken);
18
+ tokens: {
19
+ key: SGToken;
20
+ equals?: SGToken;
21
+ openingQuote?: SGToken;
22
+ value?: SGToken;
23
+ closingQuote?: SGToken;
24
+ };
25
+ get key(): string;
26
+ /**
27
+ * The value of this attribute. This does not including the opening or closing quote
28
+ */
29
+ get value(): string | undefined;
30
+ set value(val: string | undefined);
31
+ get range(): Range;
32
+ private _range;
33
+ transpile(state: TranspileState): SourceNode;
13
34
  }
14
35
  export declare class SGTag {
15
- tag: SGToken;
36
+ constructor(startTagOpen: SGToken, startTagName: SGToken, attributes?: SGAttribute[], startTagClose?: SGToken, childNodes?: SGTag[], endTagOpen?: SGToken, endTagName?: SGToken, endTagClose?: SGToken);
37
+ tokens: {
38
+ /**
39
+ * The first portion of the startTag. (i.e. `<` or `<?`)
40
+ */
41
+ startTagOpen: SGToken;
42
+ /**
43
+ * The name of the opening tag (i.e. CoolTag in `<CoolTag>`).
44
+ */
45
+ startTagName: SGToken;
46
+ /**
47
+ * The last bit of the startTag (i.e. `/>` for self-closing, `?>` for xml prologue, or `>` for tag with children)
48
+ */
49
+ startTagClose?: SGToken;
50
+ /**
51
+ * The endTag opening char `<`
52
+ */
53
+ endTagOpen?: SGToken;
54
+ /**
55
+ * The name of the ending tag (i.e. CoolTag in `</CoolTag>`)
56
+ */
57
+ endTagName?: SGToken;
58
+ /**
59
+ * The endTag closing char `>`
60
+ */
61
+ endTagClose?: SGToken;
62
+ };
63
+ /**
64
+ * Array of attributes found on this tag
65
+ */
16
66
  attributes: SGAttribute[];
17
- range?: Range;
18
- constructor(tag: SGToken, attributes?: SGAttribute[], range?: Range);
67
+ /**
68
+ * The array of direct children AST elements of this AST node
69
+ */
70
+ childNodes: SGTag[];
71
+ get range(): Range;
72
+ private _range;
73
+ /**
74
+ * Is this a self-closing tag?
75
+ */
76
+ get isSelfClosing(): boolean;
19
77
  get id(): string;
20
78
  set id(value: string);
79
+ /**
80
+ * Get the lower-case name of this tag.
81
+ */
82
+ get tagName(): string;
83
+ /**
84
+ * Find all direct children by their tag name (case insensitive).
85
+ * This does not step into children's children.
86
+ *
87
+ */
88
+ getChildNodesByTagName<T extends SGTag>(tagName: string): readonly T[];
89
+ /**
90
+ * Add a child to the end of the children array
91
+ */
92
+ addChild<T extends SGTag>(tag: T): T;
93
+ /**
94
+ * Remove a child from the children array.
95
+ * @returns true if node was found and removed, false if the node wasn't there and thus nothing was done
96
+ */
97
+ removeChild(tag: SGTag): boolean;
98
+ /**
99
+ * Does this node have the specified attribute?
100
+ */
101
+ hasAttribute(name: string): boolean;
102
+ /**
103
+ * Get an SGAttribute by its name
104
+ */
21
105
  getAttribute(name: string): SGAttribute | undefined;
106
+ /**
107
+ * Get an attribute value by its name
108
+ */
22
109
  getAttributeValue(name: string): string | undefined;
23
- setAttribute(name: string, value: string): void;
110
+ /**
111
+ * Set an attribute value by its name. If no attribute exists with this name, it is created
112
+ */
113
+ setAttributeValue(name: string, value: string): void;
114
+ /**
115
+ * Remove an attribute by its name
116
+ * @returns true if an attribute was found and removed. False if no attribute was found
117
+ */
118
+ removeAttribute(name: string): boolean;
24
119
  transpile(state: TranspileState): SourceNode;
25
- protected transpileBody(state: TranspileState): (string | SourceNode)[];
26
- protected transpileAttributes(state: TranspileState, attributes: SGAttribute[]): (string | SourceNode)[];
120
+ protected transpileBody(state: TranspileState): SourceNode;
121
+ protected transpileAttributes(state: TranspileState, attributes: SGAttribute[]): SourceNode;
27
122
  }
28
123
  export declare class SGProlog extends SGTag {
29
- transpile(state: TranspileState): SourceNode;
30
124
  }
31
125
  export declare class SGNode extends SGTag {
32
- children: SGNode[];
33
- constructor(tag: SGToken, attributes?: SGAttribute[], children?: SGNode[], range?: Range);
34
- protected transpileBody(state: TranspileState): (string | SourceNode)[];
35
126
  }
36
- export declare class SGChildren extends SGNode {
37
- constructor(tag?: SGToken, children?: SGNode[], range?: Range);
127
+ export declare class SGChildren extends SGTag {
38
128
  }
39
129
  export declare class SGScript extends SGTag {
40
130
  cdata?: SGToken;
41
- constructor(tag?: SGToken, attributes?: SGAttribute[], cdata?: SGToken, range?: Range);
42
131
  get type(): string;
43
132
  set type(value: string);
44
133
  get uri(): string;
45
134
  set uri(value: string);
46
- protected transpileBody(state: TranspileState): (string | SourceNode)[];
47
- protected transpileAttributes(state: TranspileState, attributes: SGAttribute[]): (string | SourceNode)[];
135
+ protected transpileBody(state: TranspileState): SourceNode;
136
+ protected transpileAttributes(state: TranspileState, attributes: SGAttribute[]): SourceNode;
48
137
  }
49
- export declare class SGField extends SGTag {
50
- constructor(tag?: SGToken, attributes?: SGAttribute[], range?: Range);
138
+ export declare class SGInterfaceField extends SGTag {
51
139
  get type(): string;
52
140
  set type(value: string);
53
141
  get alias(): string;
@@ -58,33 +146,110 @@ export declare class SGField extends SGTag {
58
146
  set onChange(value: string);
59
147
  get alwaysNotify(): string;
60
148
  set alwaysNotify(value: string);
149
+ get bscType(): DynamicType | FloatType | IntegerType | LongIntegerType | StringType | BooleanType;
61
150
  }
62
151
  export declare const SGFieldTypes: string[];
63
- export declare class SGFunction extends SGTag {
64
- constructor(tag?: SGToken, attributes?: SGAttribute[], range?: Range);
152
+ export declare function getBscTypeFromSGFieldType(sgFieldType: string): DynamicType | FloatType | IntegerType | LongIntegerType | StringType | BooleanType;
153
+ export declare class SGInterfaceFunction extends SGTag {
65
154
  get name(): string;
66
155
  set name(value: string);
156
+ get functionType(): FunctionType;
67
157
  }
158
+ export declare type SGInterfaceMember = SGInterfaceField | SGInterfaceFunction;
68
159
  export declare class SGInterface extends SGTag {
69
- fields: SGField[];
70
- functions: SGFunction[];
71
- constructor(tag?: SGToken, content?: SGTag[], range?: Range);
72
- getField(id: string): SGField;
73
- setField(id: string, type: string, onChange?: string, alwaysNotify?: boolean, alias?: string): void;
74
- getFunction(name: string): SGFunction;
75
- setFunction(name: string): void;
76
- protected transpileBody(state: TranspileState): (string | SourceNode)[];
160
+ get fields(): readonly SGInterfaceField[];
161
+ get functions(): readonly SGInterfaceFunction[];
162
+ get members(): readonly SGInterfaceMember[];
163
+ /**
164
+ * Check if there's an SGField with the specified name
165
+ */
166
+ hasField(id: string): boolean;
167
+ /**
168
+ * Check if there's an SGFunction with the specified name
169
+ */
170
+ hasFunction(name: string): boolean;
171
+ /**
172
+ * Find a field by its ID
173
+ */
174
+ getField(id: string): SGInterfaceField;
175
+ /**
176
+ * Set the value of a field. Creates a new field if one does not already exist with this ID
177
+ */
178
+ setField(id: string, type: string, onChange?: string, alwaysNotify?: boolean, alias?: string): SGInterfaceField;
179
+ /**
180
+ * Remove a field from the interface
181
+ * @returns true if a field was found and removed. Returns false if no field was found with that name
182
+ */
183
+ removeField(id: string): boolean;
184
+ /**
185
+ * Get the interface function with the specified name
186
+ */
187
+ getFunction(name: string): SGInterfaceFunction;
188
+ /**
189
+ * Add or replace a function on the interface
190
+ */
191
+ setFunction(name: string): SGInterfaceFunction;
192
+ /**
193
+ * Remove a function from the interface
194
+ * @returns true if a function was found and removed. Returns false if no function was found with that name
195
+ */
196
+ removeFunction(name: string): boolean;
77
197
  }
78
198
  export declare class SGComponent extends SGTag {
79
- constructor(tag?: SGToken, attributes?: SGAttribute[], content?: SGTag[], range?: Range);
80
- api: SGInterface;
81
- scripts: SGScript[];
82
- children: SGChildren;
199
+ /**
200
+ * Get all the <Field> and <Function> elements across all <Interface> nodes in this component
201
+ */
202
+ get interfaceMembers(): readonly SGInterfaceMember[];
203
+ get scripts(): readonly SGScript[];
204
+ /**
205
+ * Get the `<children>` element of this component. (not to be confused with the AST `childNodes` property).
206
+ * If there are multiope `<children>` elements, this function will return the last `<children>` tag because that's what Roku devices do.
207
+ */
208
+ get children(): SGChildren;
83
209
  get name(): string;
84
210
  set name(value: string);
85
211
  get extends(): string;
86
212
  set extends(value: string);
87
- protected transpileBody(state: TranspileState): (string | SourceNode)[];
213
+ /**
214
+ * Does the specified field exist in the component interface?
215
+ */
216
+ hasInterfaceField(id: string): boolean;
217
+ /**
218
+ * Does the specified function exist in the component interface?
219
+ */
220
+ hasInterfaceFunction(name: string): boolean;
221
+ /**
222
+ * Get an interface field with the specified name
223
+ */
224
+ getInterfaceField(name: string): SGInterfaceField | undefined;
225
+ /**
226
+ * Return the first SGInterface node found, or insert a new one then return it
227
+ */
228
+ private ensureInterfaceNode;
229
+ /**
230
+ * Create or update a <field> interface element.
231
+ * This will create a new `<interface>` element if there are none on the component already
232
+ */
233
+ setInterfaceField(id: string, type: string, onChange?: string, alwaysNotify?: boolean, alias?: string): SGInterfaceField;
234
+ /**
235
+ * Create or update a <function> interface element.
236
+ * This will create a new `<interface>` element if there are none on the component already
237
+ */
238
+ setInterfaceFunction(name: string): SGInterfaceFunction;
239
+ /**
240
+ * Remove an interface field.
241
+ * @returns true if a field was found and removed. Returns false if no field was found with that name
242
+ */
243
+ removeInterfaceField(id: string): boolean;
244
+ /**
245
+ * Get an interface field with the specified name
246
+ */
247
+ getInterfaceFunction(name: string): SGInterfaceFunction | undefined;
248
+ /**
249
+ * Remove an interface function.
250
+ * @returns true if a function was found and removed. Returns false if no function was found with that name
251
+ */
252
+ removeInterfaceFunction(name: string): boolean;
88
253
  }
89
254
  export interface SGReferences {
90
255
  name?: SGToken;
@@ -96,5 +261,5 @@ export declare class SGAst {
96
261
  root?: SGTag;
97
262
  component?: SGComponent;
98
263
  constructor(prolog?: SGProlog, root?: SGTag, component?: SGComponent);
99
- transpile(state: TranspileState): TranspileResult;
264
+ transpile(state: TranspileState): SourceNode;
100
265
  }