brighterscript 1.0.0-alpha.26 → 1.0.0-alpha.28

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 (200) hide show
  1. package/CHANGELOG.md +82 -5
  2. package/README.md +1 -1
  3. package/dist/AstValidationSegmenter.d.ts +1 -1
  4. package/dist/AstValidationSegmenter.js +4 -5
  5. package/dist/AstValidationSegmenter.js.map +1 -1
  6. package/dist/DiagnosticFilterer.d.ts +7 -4
  7. package/dist/DiagnosticFilterer.js +67 -37
  8. package/dist/DiagnosticFilterer.js.map +1 -1
  9. package/dist/DiagnosticMessages.d.ts +1 -3
  10. package/dist/DiagnosticMessages.js +5 -8
  11. package/dist/DiagnosticMessages.js.map +1 -1
  12. package/dist/PluginInterface.js +1 -1
  13. package/dist/PluginInterface.js.map +1 -1
  14. package/dist/Program.d.ts +1 -1
  15. package/dist/Program.js +34 -31
  16. package/dist/Program.js.map +1 -1
  17. package/dist/Scope.d.ts +7 -34
  18. package/dist/Scope.js +45 -305
  19. package/dist/Scope.js.map +1 -1
  20. package/dist/SymbolTable.d.ts +1 -8
  21. package/dist/SymbolTable.js +1 -10
  22. package/dist/SymbolTable.js.map +1 -1
  23. package/dist/SymbolTypeFlag.d.ts +8 -0
  24. package/dist/SymbolTypeFlag.js +13 -0
  25. package/dist/SymbolTypeFlag.js.map +1 -0
  26. package/dist/XmlScope.d.ts +0 -8
  27. package/dist/XmlScope.js +6 -84
  28. package/dist/XmlScope.js.map +1 -1
  29. package/dist/astUtils/CachedLookups.d.ts +1 -2
  30. package/dist/astUtils/CachedLookups.js +4 -19
  31. package/dist/astUtils/CachedLookups.js.map +1 -1
  32. package/dist/astUtils/creators.d.ts +1 -0
  33. package/dist/astUtils/creators.js +48 -8
  34. package/dist/astUtils/creators.js.map +1 -1
  35. package/dist/astUtils/creators.spec.js +0 -10
  36. package/dist/astUtils/creators.spec.js.map +1 -1
  37. package/dist/astUtils/reflection.d.ts +3 -2
  38. package/dist/astUtils/reflection.js +11 -7
  39. package/dist/astUtils/reflection.js.map +1 -1
  40. package/dist/astUtils/reflection.spec.js +11 -16
  41. package/dist/astUtils/reflection.spec.js.map +1 -1
  42. package/dist/astUtils/visitors.d.ts +1 -2
  43. package/dist/astUtils/visitors.js.map +1 -1
  44. package/dist/astUtils/visitors.spec.js +1 -5
  45. package/dist/astUtils/visitors.spec.js.map +1 -1
  46. package/dist/bscPlugin/BscPlugin.d.ts +2 -1
  47. package/dist/bscPlugin/BscPlugin.js +4 -0
  48. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  49. package/dist/bscPlugin/SignatureHelpUtil.js +4 -3
  50. package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -1
  51. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +1 -0
  52. package/dist/bscPlugin/completions/CompletionsProcessor.js +46 -29
  53. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
  54. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +39 -0
  55. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -1
  56. package/dist/bscPlugin/hover/HoverProcessor.d.ts +1 -0
  57. package/dist/bscPlugin/hover/HoverProcessor.js +30 -10
  58. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
  59. package/dist/bscPlugin/hover/HoverProcessor.spec.js +125 -7
  60. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
  61. package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
  62. package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
  63. package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
  64. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
  65. package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
  66. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
  67. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -3
  68. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  69. package/dist/bscPlugin/validation/BrsFileValidator.js +25 -31
  70. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  71. package/dist/bscPlugin/validation/ScopeValidator.d.ts +34 -1
  72. package/dist/bscPlugin/validation/ScopeValidator.js +435 -27
  73. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  74. package/dist/bscPlugin/validation/ScopeValidator.spec.js +178 -10
  75. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
  76. package/dist/diagnosticUtils.d.ts +1 -1
  77. package/dist/files/BrsFile.Class.spec.js +15 -7
  78. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  79. package/dist/files/BrsFile.d.ts +14 -5
  80. package/dist/files/BrsFile.js +83 -150
  81. package/dist/files/BrsFile.js.map +1 -1
  82. package/dist/files/BrsFile.spec.js +429 -162
  83. package/dist/files/BrsFile.spec.js.map +1 -1
  84. package/dist/files/XmlFile.d.ts +2 -3
  85. package/dist/files/XmlFile.js +1 -3
  86. package/dist/files/XmlFile.js.map +1 -1
  87. package/dist/index.d.ts +1 -0
  88. package/dist/index.js +1 -0
  89. package/dist/index.js.map +1 -1
  90. package/dist/interfaces.d.ts +117 -85
  91. package/dist/interfaces.js +9 -9
  92. package/dist/interfaces.js.map +1 -1
  93. package/dist/lexer/Lexer.d.ts +9 -3
  94. package/dist/lexer/Lexer.js +36 -15
  95. package/dist/lexer/Lexer.js.map +1 -1
  96. package/dist/lexer/Lexer.spec.js +76 -38
  97. package/dist/lexer/Lexer.spec.js.map +1 -1
  98. package/dist/lexer/Token.js +1 -1
  99. package/dist/lexer/Token.js.map +1 -1
  100. package/dist/lexer/TokenKind.d.ts +1 -0
  101. package/dist/lexer/TokenKind.js +4 -1
  102. package/dist/lexer/TokenKind.js.map +1 -1
  103. package/dist/parser/AstNode.d.ts +1 -2
  104. package/dist/parser/AstNode.js +0 -1
  105. package/dist/parser/AstNode.js.map +1 -1
  106. package/dist/parser/BrsTranspileState.d.ts +1 -1
  107. package/dist/parser/Expression.d.ts +153 -135
  108. package/dist/parser/Expression.js +204 -114
  109. package/dist/parser/Expression.js.map +1 -1
  110. package/dist/parser/Parser.Class.spec.js +15 -16
  111. package/dist/parser/Parser.Class.spec.js.map +1 -1
  112. package/dist/parser/Parser.d.ts +8 -4
  113. package/dist/parser/Parser.js +108 -149
  114. package/dist/parser/Parser.js.map +1 -1
  115. package/dist/parser/Parser.spec.js +48 -72
  116. package/dist/parser/Parser.spec.js.map +1 -1
  117. package/dist/parser/SGParser.js +49 -35
  118. package/dist/parser/SGParser.js.map +1 -1
  119. package/dist/parser/SGTypes.d.ts +36 -24
  120. package/dist/parser/SGTypes.js +31 -60
  121. package/dist/parser/SGTypes.js.map +1 -1
  122. package/dist/parser/Statement.d.ts +214 -207
  123. package/dist/parser/Statement.js +248 -169
  124. package/dist/parser/Statement.js.map +1 -1
  125. package/dist/parser/Statement.spec.js +0 -13
  126. package/dist/parser/Statement.spec.js.map +1 -1
  127. package/dist/parser/TranspileState.d.ts +17 -8
  128. package/dist/parser/TranspileState.js +64 -6
  129. package/dist/parser/TranspileState.js.map +1 -1
  130. package/dist/parser/tests/Parser.spec.d.ts +1 -1
  131. package/dist/parser/tests/Parser.spec.js +1 -2
  132. package/dist/parser/tests/Parser.spec.js.map +1 -1
  133. package/dist/parser/tests/controlFlow/If.spec.js +1 -1
  134. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  135. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +1 -3
  136. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  137. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +44 -0
  138. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  139. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +6 -6
  140. package/dist/parser/tests/expression/TernaryExpression.spec.js +47 -0
  141. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  142. package/dist/parser/tests/expression/TypeExpression.spec.js +8 -9
  143. package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -1
  144. package/dist/parser/tests/statement/ConstStatement.spec.js +2 -2
  145. package/dist/parser/tests/statement/InterfaceStatement.spec.js +8 -1
  146. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
  147. package/dist/parser/tests/statement/Misc.spec.js +25 -5
  148. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  149. package/dist/parser/tests/statement/TryCatch.spec.js +9 -2
  150. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  151. package/dist/preprocessor/Chunk.js +1 -2
  152. package/dist/preprocessor/Chunk.js.map +1 -1
  153. package/dist/preprocessor/PreprocessorParser.js +2 -1
  154. package/dist/preprocessor/PreprocessorParser.js.map +1 -1
  155. package/dist/roku-types/data.json +70 -52
  156. package/dist/roku-types/index.d.ts +43 -21
  157. package/dist/types/ArrayType.js +1 -2
  158. package/dist/types/ArrayType.js.map +1 -1
  159. package/dist/types/ArrayType.spec.js +7 -8
  160. package/dist/types/ArrayType.spec.js.map +1 -1
  161. package/dist/types/AssociativeArrayType.d.ts +3 -0
  162. package/dist/types/AssociativeArrayType.js +10 -2
  163. package/dist/types/AssociativeArrayType.js.map +1 -1
  164. package/dist/types/BscType.d.ts +1 -1
  165. package/dist/types/BscType.js +3 -3
  166. package/dist/types/BscType.js.map +1 -1
  167. package/dist/types/BuiltInInterfaceAdder.js +7 -8
  168. package/dist/types/BuiltInInterfaceAdder.js.map +1 -1
  169. package/dist/types/BuiltInInterfaceAdder.spec.js +31 -32
  170. package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -1
  171. package/dist/types/ClassType.spec.js +10 -11
  172. package/dist/types/ClassType.spec.js.map +1 -1
  173. package/dist/types/ComponentType.d.ts +2 -1
  174. package/dist/types/ComponentType.js.map +1 -1
  175. package/dist/types/EnumType.js +2 -3
  176. package/dist/types/EnumType.js.map +1 -1
  177. package/dist/types/InheritableType.js +3 -4
  178. package/dist/types/InheritableType.js.map +1 -1
  179. package/dist/types/InterfaceType.js +2 -3
  180. package/dist/types/InterfaceType.js.map +1 -1
  181. package/dist/types/InterfaceType.spec.js +3 -4
  182. package/dist/types/InterfaceType.spec.js.map +1 -1
  183. package/dist/types/ObjectType.js +1 -2
  184. package/dist/types/ObjectType.js.map +1 -1
  185. package/dist/types/ReferenceType.d.ts +1 -1
  186. package/dist/types/ReferenceType.spec.js +21 -22
  187. package/dist/types/ReferenceType.spec.js.map +1 -1
  188. package/dist/types/UnionType.js +3 -3
  189. package/dist/types/UnionType.js.map +1 -1
  190. package/dist/types/UnionType.spec.js +37 -38
  191. package/dist/types/UnionType.spec.js.map +1 -1
  192. package/dist/types/helper.spec.js +4 -5
  193. package/dist/types/helper.spec.js.map +1 -1
  194. package/dist/util.d.ts +21 -11
  195. package/dist/util.js +116 -37
  196. package/dist/util.js.map +1 -1
  197. package/dist/validators/ClassValidator.d.ts +0 -9
  198. package/dist/validators/ClassValidator.js +3 -46
  199. package/dist/validators/ClassValidator.js.map +1 -1
  200. package/package.json +6 -3
@@ -3,13 +3,12 @@ import type { Range, Diagnostic, CodeAction, SemanticTokenTypes, SemanticTokenMo
3
3
  import type { Scope } from './Scope';
4
4
  import type { BrsFile } from './files/BrsFile';
5
5
  import type { XmlFile } from './files/XmlFile';
6
- import type { FunctionScope } from './FunctionScope';
7
6
  import type { TypedFunctionType } from './types/TypedFunctionType';
8
7
  import type { ParseMode } from './parser/Parser';
9
8
  import type { Program } from './Program';
10
9
  import type { ProgramBuilder } from './ProgramBuilder';
11
10
  import type { ClassStatement, ConstStatement, EnumStatement, FunctionStatement, NamespaceStatement } from './parser/Statement';
12
- import type { AstNode, Expression, Statement } from './parser/AstNode';
11
+ import type { AstNode, AstNodeKind, Expression, Statement } from './parser/AstNode';
13
12
  import type { TranspileState } from './parser/TranspileState';
14
13
  import type { SourceNode } from 'source-map';
15
14
  import type { BscType } from './types/BscType';
@@ -18,8 +17,8 @@ import type { Identifier, Token } from './lexer/Token';
18
17
  import type { BscFile } from './files/BscFile';
19
18
  import type { FileFactory } from './files/Factory';
20
19
  import type { LazyFileData } from './files/LazyFileData';
21
- import type { SymbolTable, SymbolTypeFlag } from './SymbolTable';
22
- import type { CallExpression } from './parser/Expression';
20
+ import type { SymbolTable } from './SymbolTable';
21
+ import type { SymbolTypeFlag } from './SymbolTypeFlag';
23
22
  export interface BsDiagnostic extends Diagnostic {
24
23
  file: BscFile;
25
24
  /**
@@ -73,28 +72,6 @@ export interface Callable {
73
72
  */
74
73
  functionStatement: FunctionStatement;
75
74
  }
76
- export interface FunctionCall {
77
- /**
78
- * The full range of this function call (from the start of the function name to its closing paren)
79
- */
80
- range: Range;
81
- expression: CallExpression;
82
- functionScope: FunctionScope;
83
- file: BscFile;
84
- name: string;
85
- args: CallableArg[];
86
- nameRange: Range;
87
- }
88
- /**
89
- * An argument for an expression call.
90
- */
91
- export interface CallableArg {
92
- text: string;
93
- type: BscType;
94
- typeToken: Token;
95
- range: Range;
96
- expression: Expression;
97
- }
98
75
  export interface CallableParam {
99
76
  name: string;
100
77
  type: BscType;
@@ -182,71 +159,71 @@ export interface CompilerPlugin {
182
159
  /**
183
160
  * Called before a new program is created
184
161
  */
185
- beforeProgramCreate?: PluginHandler<BeforeProgramCreateEvent>;
162
+ beforeProgramCreate?(event: BeforeProgramCreateEvent): any;
186
163
  /**
187
164
  * Called after a new program is created
188
165
  */
189
- afterProgramCreate?: PluginHandler<AfterProgramCreateEvent>;
166
+ afterProgramCreate?(event: AfterProgramCreateEvent): any;
190
167
  /**
191
168
  * Called before the program gets prepared for building
192
169
  */
193
- beforePrepareProgram?: PluginHandler<BeforePrepareProgramEvent>;
170
+ beforePrepareProgram?(event: BeforePrepareProgramEvent): any;
194
171
  /**
195
172
  * Called when the program gets prepared for building
196
173
  */
197
- prepareProgram?: PluginHandler<PrepareProgramEvent>;
174
+ prepareProgram?(event: PrepareProgramEvent): any;
198
175
  /**
199
176
  * Called after the program gets prepared for building
200
177
  */
201
- afterPrepareProgram?: PluginHandler<AfterPrepareProgramEvent>;
178
+ afterPrepareProgram?(event: AfterPrepareProgramEvent): any;
202
179
  /**
203
180
  * Called before the entire program is validated
204
181
  */
205
- beforeProgramValidate?: PluginHandler<BeforeProgramValidateEvent>;
182
+ beforeProgramValidate?(event: BeforeProgramValidateEvent): any;
206
183
  /**
207
184
  * Called before the entire program is validated
208
185
  */
209
- onProgramValidate?: PluginHandler<OnProgramValidateEvent>;
186
+ onProgramValidate?(event: OnProgramValidateEvent): any;
210
187
  /**
211
188
  * Called after the program has been validated
212
189
  */
213
- afterProgramValidate?: PluginHandler<AfterProgramValidateEvent>;
190
+ afterProgramValidate?(event: AfterProgramValidateEvent): any;
214
191
  /**
215
192
  * Called right before the program is disposed/destroyed
216
193
  */
217
- beforeProgramDispose?: PluginHandler<BeforeProgramDisposeEvent>;
194
+ beforeProgramDispose?(event: BeforeProgramDisposeEvent): any;
218
195
  /**
219
196
  * Emitted before the program starts collecting completions
220
197
  */
221
- beforeProvideCompletions?: PluginHandler<BeforeProvideCompletionsEvent>;
198
+ beforeProvideCompletions?(event: BeforeProvideCompletionsEvent): any;
222
199
  /**
223
200
  * Use this event to contribute completions
224
201
  */
225
- provideCompletions?: PluginHandler<ProvideCompletionsEvent>;
202
+ provideCompletions?(event: ProvideCompletionsEvent): any;
226
203
  /**
227
204
  * Emitted after the program has finished collecting completions, but before they are sent to the client
228
205
  */
229
- afterProvideCompletions?: PluginHandler<AfterProvideCompletionsEvent>;
206
+ afterProvideCompletions?(event: AfterProvideCompletionsEvent): any;
230
207
  /**
231
208
  * Called before the `provideHover` hook. Use this if you need to prepare any of the in-memory objects before the `provideHover` gets called
232
209
  */
233
- beforeProvideHover?: PluginHandler<BeforeProvideHoverEvent>;
210
+ beforeProvideHover?(event: BeforeProvideHoverEvent): any;
234
211
  /**
235
212
  * Called when bsc looks for hover information. Use this if your plugin wants to contribute hover information.
236
213
  */
237
- provideHover?: PluginHandler<ProvideHoverEvent>;
214
+ provideHover?(event: ProvideHoverEvent): any;
238
215
  /**
239
216
  * Called after the `provideHover` hook. Use this if you want to intercept or sanitize the hover data (even from other plugins) before it gets sent to the client.
240
217
  */
241
- afterProvideHover?: PluginHandler<AfterProvideHoverEvent>;
218
+ afterProvideHover?(event: AfterProvideHoverEvent): any;
242
219
  /**
243
220
  * Called after a scope was created
244
221
  */
245
- afterScopeCreate?: PluginHandler<AfterScopeCreateEvent>;
246
- beforeScopeDispose?: PluginHandler<BeforeScopeDisposeEvent>;
247
- onScopeDispose?: PluginHandler<OnScopeDisposeEvent>;
248
- afterScopeDispose?: PluginHandler<AfterScopeDisposeEvent>;
249
- beforeScopeValidate?: PluginHandler<BeforeScopeValidateEvent>;
222
+ afterScopeCreate?(event: AfterScopeCreateEvent): any;
223
+ beforeScopeDispose?(event: BeforeScopeDisposeEvent): any;
224
+ onScopeDispose?(event: OnScopeDisposeEvent): any;
225
+ afterScopeDispose?(event: AfterScopeDisposeEvent): any;
226
+ beforeScopeValidate?(event: BeforeScopeValidateEvent): any;
250
227
  /**
251
228
  * Called before the `provideDefinition` hook
252
229
  */
@@ -261,120 +238,133 @@ export interface CompilerPlugin {
261
238
  * @param event
262
239
  */
263
240
  afterProvideDefinition?(event: AfterProvideDefinitionEvent): any;
264
- onScopeValidate?: PluginHandler<OnScopeValidateEvent>;
265
- afterScopeValidate?: PluginHandler<BeforeScopeValidateEvent>;
266
- onGetCodeActions?: PluginHandler<OnGetCodeActionsEvent>;
267
- onGetSemanticTokens?: PluginHandler<OnGetSemanticTokensEvent>;
241
+ /**
242
+ * Called before the `provideReferences` hook
243
+ */
244
+ beforeProvideReferences?(event: BeforeProvideReferencesEvent): any;
245
+ /**
246
+ * Provide all of the `Location`s where the symbol at the given position is located
247
+ * @param event
248
+ */
249
+ provideReferences?(event: ProvideReferencesEvent): any;
250
+ /**
251
+ * Called after `provideReferences`. Use this if you want to intercept or sanitize the references data provided by bsc or other plugins
252
+ * @param event
253
+ */
254
+ afterProvideReferences?(event: AfterProvideReferencesEvent): any;
255
+ onScopeValidate?(event: OnScopeValidateEvent): any;
256
+ afterScopeValidate?(event: BeforeScopeValidateEvent): any;
257
+ onGetCodeActions?(event: OnGetCodeActionsEvent): any;
258
+ onGetSemanticTokens?(event: OnGetSemanticTokensEvent): any;
268
259
  /**
269
260
  * Called before plugins are asked to provide files to the program. (excludes virtual files produced by `provideFile` events).
270
261
  * Call the `setFileData()` method to override the file contents.
271
262
  */
272
- beforeProvideFile?: PluginHandler<BeforeProvideFileEvent>;
263
+ beforeProvideFile?(event: BeforeProvideFileEvent): any;
273
264
  /**
274
265
  * Give plugins the opportunity to handle processing a file. (excludes virtual files produced by `provideFile` events)
275
266
  */
276
- provideFile?: PluginHandler<ProvideFileEvent>;
267
+ provideFile?(event: ProvideFileEvent): any;
277
268
  /**
278
269
  * Called after a file was added to the program. (excludes virtual files produced by `provideFile` events)
279
270
  */
280
- afterProvideFile?: PluginHandler<AfterProvideFileEvent>;
271
+ afterProvideFile?(event: AfterProvideFileEvent): any;
281
272
  /**
282
273
  * Called before a file is added to the program.
283
274
  * Includes physical files as well as any virtual files produced by `provideFile` events
284
275
  */
285
- beforeFileAdd?: PluginHandler<BeforeFileAddEvent>;
276
+ beforeFileAdd?(event: BeforeFileAddEvent): any;
286
277
  /**
287
278
  * Called after a file has been added to the program.
288
279
  * Includes physical files as well as any virtual files produced by `provideFile` events
289
280
  */
290
- afterFileAdd?: PluginHandler<AfterFileAddEvent>;
281
+ afterFileAdd?(event: AfterFileAddEvent): any;
291
282
  /**
292
283
  * Called before a file is removed from the program. This includes physical and virtual files
293
284
  */
294
- beforeFileRemove?: PluginHandler<BeforeFileRemoveEvent>;
285
+ beforeFileRemove?(event: BeforeFileRemoveEvent): any;
295
286
  /**
296
287
  * Called after a file has been removed from the program. This includes physical and virtual files
297
288
  */
298
- afterFileRemove?: PluginHandler<AfterFileRemoveEvent>;
289
+ afterFileRemove?(event: AfterFileRemoveEvent): any;
299
290
  /**
300
291
  * Called before each file is validated
301
292
  */
302
- beforeFileValidate?: PluginHandler<BeforeFileValidateEvent>;
293
+ beforeFileValidate?(event: BeforeFileValidateEvent): any;
303
294
  /**
304
295
  * Called during the file validation process. If your plugin contributes file validations, this is a good place to contribute them.
305
296
  */
306
- onFileValidate?: PluginHandler<OnFileValidateEvent>;
297
+ onFileValidate?(event: OnFileValidateEvent): any;
307
298
  /**
308
299
  * Called after each file is validated
309
300
  */
310
- afterFileValidate?: PluginHandler<AfterFileValidateEvent>;
301
+ afterFileValidate?(event: AfterFileValidateEvent): any;
311
302
  /**
312
303
  * Called right before the program builds (i.e. generates the code and puts it in the stagingDir
313
304
  */
314
- beforeBuildProgram?: PluginHandler<BeforeBuildProgramEvent>;
305
+ beforeBuildProgram?(event: BeforeBuildProgramEvent): any;
315
306
  /**
316
307
  * Called right after the program builds (i.e. generates the code and puts it in the stagingDir
317
308
  */
318
- afterBuildProgram?: PluginHandler<AfterBuildProgramEvent>;
309
+ afterBuildProgram?(event: AfterBuildProgramEvent): any;
319
310
  /**
320
311
  * Before preparing the file for building
321
312
  */
322
- beforePrepareFile?: PluginHandler<BeforePrepareFileEvent>;
313
+ beforePrepareFile?(event: BeforePrepareFileEvent): any;
323
314
  /**
324
315
  * Prepare the file for building
325
316
  */
326
- prepareFile?: PluginHandler<PrepareFileEvent>;
317
+ prepareFile?(event: PrepareFileEvent): any;
327
318
  /**
328
319
  * After preparing the file for building
329
320
  */
330
- afterPrepareFile?: PluginHandler<AfterPrepareFileEvent>;
321
+ afterPrepareFile?(event: AfterPrepareFileEvent): any;
331
322
  /**
332
323
  * Before the program turns all file objects into their final buffers
333
324
  */
334
- beforeSerializeProgram?: PluginHandler<BeforeSerializeProgramEvent>;
325
+ beforeSerializeProgram?(event: BeforeSerializeProgramEvent): any;
335
326
  /**
336
327
  * Emitted right at the start of the program turning all file objects into their final buffers
337
328
  */
338
- onSerializeProgram?: PluginHandler<OnSerializeProgramEvent>;
329
+ onSerializeProgram?(event: OnSerializeProgramEvent): any;
339
330
  /**
340
331
  * After the program turns all file objects into their final buffers
341
332
  */
342
- afterSerializeProgram?: PluginHandler<AfterSerializeProgramEvent>;
333
+ afterSerializeProgram?(event: AfterSerializeProgramEvent): any;
343
334
  /**
344
335
  * Before turning the file into its final contents
345
336
  */
346
- beforeSerializeFile?: PluginHandler<BeforeSerializeFileEvent>;
337
+ beforeSerializeFile?(event: BeforeSerializeFileEvent): any;
347
338
  /**
348
339
  * Turn the file into its final contents (i.e. transpile a bs file, compress a jpeg, etc)
349
340
  */
350
- serializeFile?: PluginHandler<SerializeFileEvent>;
341
+ serializeFile?(event: SerializeFileEvent): any;
351
342
  /**
352
343
  * After turning the file into its final contents
353
344
  */
354
- afterSerializeFile?: PluginHandler<AfterSerializeFileEvent>;
345
+ afterSerializeFile?(event: AfterSerializeFileEvent): any;
355
346
  /**
356
347
  * Called before any files are written
357
348
  */
358
- beforeWriteProgram?: PluginHandler<BeforeWriteProgramEvent>;
349
+ beforeWriteProgram?(event: BeforeWriteProgramEvent): any;
359
350
  /**
360
351
  * Called after all files are written
361
352
  */
362
- afterWriteProgram?: PluginHandler<AfterWriteProgramEvent>;
353
+ afterWriteProgram?(event: AfterWriteProgramEvent): any;
363
354
  /**
364
355
  * Before a file is written to disk. These are raw files that contain the final output. One `File` may produce several of these
365
356
  */
366
- beforeWriteFile?: PluginHandler<BeforeWriteFileEvent>;
357
+ beforeWriteFile?(event: BeforeWriteFileEvent): any;
367
358
  /**
368
359
  * Called when a file should be persisted (usually writing to storage). These are raw files that contain the final output. One `File` may produce several of these.
369
360
  * When a plugin has handled a file, it should be pushed to the `handledFiles` set so future plugins don't write the file multiple times
370
361
  */
371
- writeFile?: PluginHandler<WriteFileEvent>;
362
+ writeFile?(event: WriteFileEvent): any;
372
363
  /**
373
364
  * Before a file is written to disk. These are raw files that contain the final output. One `File` may produce several of these
374
365
  */
375
- afterWriteFile?: PluginHandler<AfterWriteFileEvent>;
366
+ afterWriteFile?(event: AfterWriteFileEvent): any;
376
367
  }
377
- export declare type PluginHandler<T, R = void> = (event: T) => R;
378
368
  export interface OnGetCodeActionsEvent<TFile extends BscFile = BscFile> {
379
369
  program: Program;
380
370
  file: TFile;
@@ -486,6 +476,23 @@ export interface ProvideDefinitionEvent<TFile = BscFile> {
486
476
  }
487
477
  export declare type BeforeProvideDefinitionEvent<TFile = BscFile> = ProvideDefinitionEvent<TFile>;
488
478
  export declare type AfterProvideDefinitionEvent<TFile = BscFile> = ProvideDefinitionEvent<TFile>;
479
+ export interface ProvideReferencesEvent<TFile = BscFile> {
480
+ program: Program;
481
+ /**
482
+ * The file that the getDefinition request was invoked in
483
+ */
484
+ file: TFile;
485
+ /**
486
+ * The position in the text document where the getDefinition request was invoked
487
+ */
488
+ position: Position;
489
+ /**
490
+ * The list of locations for where the item at the file and position was defined
491
+ */
492
+ references: Location[];
493
+ }
494
+ export declare type BeforeProvideReferencesEvent<TFile = BscFile> = ProvideReferencesEvent<TFile>;
495
+ export declare type AfterProvideReferencesEvent<TFile = BscFile> = ProvideReferencesEvent<TFile>;
489
496
  export interface OnGetSemanticTokensEvent<T extends BscFile = BscFile> {
490
497
  /**
491
498
  * The program this file is from
@@ -696,9 +703,15 @@ export interface SemanticToken {
696
703
  tokenModifiers?: SemanticTokenModifiers[];
697
704
  }
698
705
  export interface TypedefProvider {
699
- getTypedef(state: TranspileState): Array<SourceNode | string>;
706
+ getTypedef(state: TranspileState): TranspileResult;
700
707
  }
701
- export declare type TranspileResult = Array<(string | SourceNode)>;
708
+ export declare type TranspileResult = Array<(string | SourceNode | TranspileResult)>;
709
+ /**
710
+ * This is the type that the SourceNode class is declared as taking in its constructor.
711
+ * The actual type that SourceNode accepts is the more permissive TranspileResult, but
712
+ * we need to use this declared type for some type casts.
713
+ */
714
+ export declare type FlattenedTranspileResult = Array<string | SourceNode>;
702
715
  export declare type FileResolver = (srcPath: string) => string | Buffer | undefined | Thenable<string | Buffer | undefined> | void;
703
716
  export interface ExpressionInfo {
704
717
  expressions: Expression[];
@@ -724,15 +737,24 @@ export interface GetTypeOptions {
724
737
  ignoreCall?: boolean;
725
738
  onlyCacheResolvedTypes?: boolean;
726
739
  ignoreCacheForRetrieval?: boolean;
740
+ isExistenceTest?: boolean;
727
741
  }
728
742
  export declare class TypeChainEntry {
729
- name: string;
730
- type: BscType;
731
- range: Range;
732
- separatorToken: Token;
733
- data: ExtraSymbolData;
734
- constructor(name: string, type: BscType, data: ExtraSymbolData, range: Range, separatorToken?: Token);
743
+ constructor(options: {
744
+ name: string;
745
+ type: BscType;
746
+ data: ExtraSymbolData;
747
+ range: Range;
748
+ separatorToken?: Token;
749
+ kind?: AstNodeKind;
750
+ });
735
751
  get isResolved(): boolean;
752
+ readonly name: string;
753
+ readonly type: BscType;
754
+ readonly data: ExtraSymbolData;
755
+ readonly range: Range;
756
+ readonly separatorToken: Token;
757
+ kind: AstNodeKind;
736
758
  }
737
759
  export interface TypeChainProcessResult {
738
760
  itemName: string;
@@ -773,3 +795,13 @@ export interface NamespaceContainer {
773
795
  namespaces?: Map<string, NamespaceContainer>;
774
796
  symbolTable: SymbolTable;
775
797
  }
798
+ /**
799
+ * Use Writable<T> to remove readonly flag from properties in T
800
+ * Be careful!
801
+ */
802
+ export declare type Writeable<T> = {
803
+ -readonly [P in keyof T]: T[P];
804
+ };
805
+ export declare type DeepWriteable<T> = {
806
+ -readonly [P in keyof T]: DeepWriteable<T[P]>;
807
+ };
@@ -11,15 +11,15 @@ var DiagnosticOrigin;
11
11
  DiagnosticOrigin["ASTSegment"] = "AstSegment";
12
12
  })(DiagnosticOrigin = exports.DiagnosticOrigin || (exports.DiagnosticOrigin = {}));
13
13
  class TypeChainEntry {
14
- constructor(name, type, data, range, separatorToken = (0, creators_1.createToken)(TokenKind_1.TokenKind.Dot)) {
15
- this.name = name;
16
- this.type = type;
17
- this.range = range;
18
- this.separatorToken = separatorToken;
19
- if (data) {
20
- // make a copy of this data
21
- this.data = Object.assign({}, data);
22
- }
14
+ constructor(options) {
15
+ var _a;
16
+ this.name = options.name;
17
+ // make a copy of this data
18
+ this.data = Object.assign({}, options.data);
19
+ this.type = options.type;
20
+ this.range = options.range;
21
+ this.separatorToken = (_a = options.separatorToken) !== null && _a !== void 0 ? _a : (0, creators_1.createToken)(TokenKind_1.TokenKind.Dot);
22
+ this.kind = options.kind;
23
23
  }
24
24
  get isResolved() {
25
25
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AAqBA,kDAAkD;AAClD,iDAA8C;AAU9C,IAAY,gBAKX;AALD,WAAY,gBAAgB;IACxB,uCAAmB,CAAA;IACnB,mCAAe,CAAA;IACf,iCAAa,CAAA;IACb,6CAAyB,CAAA;AAC7B,CAAC,EALW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAK3B;AAixBD,MAAa,cAAc;IAEvB,YAAmB,IAAY,EAAS,IAAa,EAAE,IAAqB,EAAS,KAAY,EAAS,iBAAwB,IAAA,sBAAW,EAAC,qBAAS,CAAC,GAAG,CAAC;QAAzI,SAAI,GAAJ,IAAI,CAAQ;QAAS,SAAI,GAAJ,IAAI,CAAS;QAAgC,UAAK,GAAL,KAAK,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAoC;QACxJ,IAAI,IAAI,EAAE;YACN,2BAA2B;YAC3B,IAAI,CAAC,IAAI,qBAAQ,IAAI,CAAE,CAAC;SAC3B;IACL,CAAC;IACD,IAAI,UAAU;;QACV,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,YAAY,EAAE,CAAC;IACrC,CAAC;CACJ;AAXD,wCAWC"}
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";;;AAoBA,kDAAkD;AAClD,iDAA8C;AAU9C,IAAY,gBAKX;AALD,WAAY,gBAAgB;IACxB,uCAAmB,CAAA;IACnB,mCAAe,CAAA;IACf,iCAAa,CAAA;IACb,6CAAyB,CAAA;AAC7B,CAAC,EALW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAK3B;AAkyBD,MAAa,cAAc;IACvB,YAAY,OAOX;;QACG,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,2BAA2B;QAC3B,IAAI,CAAC,IAAI,qBAAQ,OAAO,CAAC,IAAI,CAAE,CAAC;QAChC,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC;QAC3B,IAAI,CAAC,cAAc,GAAG,MAAA,OAAO,CAAC,cAAc,mCAAI,IAAA,sBAAW,EAAC,qBAAS,CAAC,GAAG,CAAC,CAAC;QAC3E,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC7B,CAAC;IACD,IAAI,UAAU;;QACV,OAAO,MAAA,IAAI,CAAC,IAAI,0CAAE,YAAY,EAAE,CAAC;IACrC,CAAC;CAQJ;AA3BD,wCA2BC"}
@@ -205,14 +205,20 @@ export declare class Lexer {
205
205
  */
206
206
  private sync;
207
207
  /**
208
- * Creates a `TokenLocation` at the lexer's current position for the provided `text`.
209
- * @returns the range of `text` as a `TokenLocation`
208
+ * Creates a `Range` at the lexer's current position
209
+ * @returns the range of `text`
210
210
  */
211
211
  private rangeOf;
212
212
  }
213
213
  export interface ScanOptions {
214
214
  /**
215
215
  * If true, the whitespace tokens are included. If false, they are discarded
216
+ * @default false
216
217
  */
217
- includeWhitespace: boolean;
218
+ includeWhitespace?: boolean;
219
+ /**
220
+ * Should locations be tracked. If false, the `range` property will be omitted
221
+ * @default true
222
+ */
223
+ trackLocations?: boolean;
218
224
  }
@@ -56,7 +56,9 @@ class Lexer {
56
56
  kind: TokenKind_1.TokenKind.Eof,
57
57
  isReserved: false,
58
58
  text: '',
59
- range: util_1.default.createRange(this.lineBegin, this.columnBegin, this.lineEnd, this.columnEnd + 1),
59
+ range: this.options.trackLocations
60
+ ? util_1.default.createRange(this.lineBegin, this.columnBegin, this.lineEnd, this.columnEnd + 1)
61
+ : undefined,
60
62
  leadingWhitespace: this.leadingWhitespace,
61
63
  leadingTrivia: this.leadingTrivia
62
64
  });
@@ -73,7 +75,11 @@ class Lexer {
73
75
  * Fill in missing/invalid options with defaults
74
76
  */
75
77
  sanitizeOptions(options) {
76
- return Object.assign({ includeWhitespace: false }, options);
78
+ var _a, _b;
79
+ options !== null && options !== void 0 ? options : (options = {});
80
+ (_a = options.includeWhitespace) !== null && _a !== void 0 ? _a : (options.includeWhitespace = false);
81
+ (_b = options.trackLocations) !== null && _b !== void 0 ? _b : (options.trackLocations = true);
82
+ return options;
77
83
  }
78
84
  /**
79
85
  * Determines whether or not the lexer as reached the end of its input.
@@ -595,12 +601,16 @@ class Lexer {
595
601
  */
596
602
  preProcessedConditional() {
597
603
  this.advance(); // advance past the leading #
604
+ //consume whitespace
605
+ while (this.check(' ', '\t')) {
606
+ this.advance();
607
+ }
598
608
  while ((0, Characters_1.isAlphaNumeric)(this.peek())) {
599
609
  this.advance();
600
610
  }
601
611
  let text = this.source.slice(this.start, this.current).toLowerCase();
602
- // some identifiers can be split into two words, so check the "next" word and see what we get
603
- if ((text === '#end' || text === '#else') && this.check(' ', '\t')) {
612
+ // some identifiers can be split into two words (`#end if`, `#else if`), so check the "next" word and see what we get
613
+ if ((text.endsWith('end') || text.endsWith('else')) && this.check(' ', '\t')) {
604
614
  let endOfFirstWord = this.current;
605
615
  //skip past whitespace
606
616
  while (this.check(' ', '\t')) {
@@ -610,18 +620,18 @@ class Lexer {
610
620
  this.advance();
611
621
  } // read the next word
612
622
  let twoWords = this.source.slice(this.start, this.current).toLowerCase();
613
- switch (twoWords.replace(/[\s\t]+/g, ' ')) {
614
- case '#else if':
623
+ switch (twoWords.replace(/\s+/g, '')) {
624
+ case '#elseif':
615
625
  this.addToken(TokenKind_1.TokenKind.HashElseIf);
616
626
  return;
617
- case '#end if':
627
+ case '#endif':
618
628
  this.addToken(TokenKind_1.TokenKind.HashEndIf);
619
629
  return;
620
630
  }
621
631
  // reset if the last word and the current word didn't form a multi-word TokenKind
622
632
  this.current = endOfFirstWord;
623
633
  }
624
- switch (text) {
634
+ switch (text.replace(/\s+/g, '')) {
625
635
  case '#if':
626
636
  this.addToken(TokenKind_1.TokenKind.HashIf);
627
637
  return;
@@ -644,11 +654,15 @@ class Lexer {
644
654
  if (this.check(' ', '\t')) {
645
655
  this.whitespace();
646
656
  }
647
- while (!this.isAtEnd() && !this.check('\n')) {
657
+ let hasErrorMessage = false;
658
+ while (!this.isAtEnd() && !this.check('\r') && !this.check('\n')) {
659
+ hasErrorMessage = true;
648
660
  this.advance();
649
661
  }
650
- // grab all text since we found #error as one token
651
- this.addToken(TokenKind_1.TokenKind.HashErrorMessage);
662
+ if (hasErrorMessage) {
663
+ // grab all text since we found #error as one token
664
+ this.addToken(TokenKind_1.TokenKind.HashErrorMessage);
665
+ }
652
666
  this.start = this.current;
653
667
  return;
654
668
  default:
@@ -737,7 +751,9 @@ class Lexer {
737
751
  this.leadingTrivia = [];
738
752
  }
739
753
  this.leadingWhitespace = '';
740
- this.tokens.push(token);
754
+ if (kind !== TokenKind_1.TokenKind.Comment) {
755
+ this.tokens.push(token);
756
+ }
741
757
  this.sync();
742
758
  return token;
743
759
  }
@@ -750,11 +766,16 @@ class Lexer {
750
766
  this.columnBegin = this.columnEnd;
751
767
  }
752
768
  /**
753
- * Creates a `TokenLocation` at the lexer's current position for the provided `text`.
754
- * @returns the range of `text` as a `TokenLocation`
769
+ * Creates a `Range` at the lexer's current position
770
+ * @returns the range of `text`
755
771
  */
756
772
  rangeOf() {
757
- return util_1.default.createRange(this.lineBegin, this.columnBegin, this.lineEnd, this.columnEnd);
773
+ if (this.options.trackLocations) {
774
+ return util_1.default.createRange(this.lineBegin, this.columnBegin, this.lineEnd, this.columnEnd);
775
+ }
776
+ else {
777
+ return undefined;
778
+ }
758
779
  }
759
780
  }
760
781
  exports.Lexer = Lexer;