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.
- package/CHANGELOG.md +112 -0
- package/README.md +2 -2
- package/dist/DiagnosticCollection.js +2 -2
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.js +2 -2
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +6 -1
- package/dist/DiagnosticMessages.js +5 -0
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.d.ts +8 -2
- package/dist/LanguageServer.js +50 -44
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Program.d.ts +61 -45
- package/dist/Program.js +305 -188
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +7 -7
- package/dist/ProgramBuilder.js +60 -51
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +42 -19
- package/dist/Scope.js +261 -129
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +73 -0
- package/dist/SymbolTable.js +157 -0
- package/dist/SymbolTable.js.map +1 -0
- package/dist/XmlScope.d.ts +5 -0
- package/dist/XmlScope.js +66 -28
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/creators.d.ts +15 -1
- package/dist/astUtils/creators.js +39 -9
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +28 -16
- package/dist/astUtils/reflection.js +52 -30
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +3 -3
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +12 -13
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +3 -3
- package/dist/astUtils/xml.js +2 -2
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +5 -6
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +24 -22
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +2 -2
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +1 -1
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +356 -41
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +55 -37
- package/dist/files/BrsFile.js +430 -399
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +199 -158
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +20 -9
- package/dist/files/XmlFile.js +36 -31
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +113 -113
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +32 -32
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/globalCallables.js +17 -6
- package/dist/globalCallables.js.map +1 -1
- package/dist/interfaces.d.ts +155 -39
- package/dist/parser/BrsTranspileState.d.ts +7 -0
- package/dist/parser/BrsTranspileState.js +10 -1
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +23 -12
- package/dist/parser/Expression.js +45 -30
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +100 -1
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +118 -5
- package/dist/parser/Parser.js +398 -37
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +404 -7
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +41 -4
- package/dist/parser/SGParser.js +185 -174
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +17 -4
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +203 -38
- package/dist/parser/SGTypes.js +464 -160
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/SGTypes.spec.d.ts +1 -0
- package/dist/parser/SGTypes.spec.js +351 -0
- package/dist/parser/SGTypes.spec.js.map +1 -0
- package/dist/parser/Statement.d.ts +37 -26
- package/dist/parser/Statement.js +81 -20
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +5 -5
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +1 -1
- package/dist/parser/TranspileState.js +15 -7
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +5 -4
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/types/ArrayType.d.ts +1 -0
- package/dist/types/ArrayType.js +23 -19
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/BooleanType.d.ts +3 -2
- package/dist/types/BooleanType.js +6 -3
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BscType.d.ts +19 -4
- package/dist/types/BscType.js +9 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/CustomType.d.ts +8 -5
- package/dist/types/CustomType.js +12 -12
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.d.ts +1 -0
- package/dist/types/DoubleType.js +11 -11
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DynamicType.d.ts +1 -0
- package/dist/types/DynamicType.js +4 -0
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/FloatType.d.ts +2 -1
- package/dist/types/FloatType.js +11 -11
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FunctionType.d.ts +13 -10
- package/dist/types/FunctionType.js +34 -18
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +8 -2
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.d.ts +2 -1
- package/dist/types/IntegerType.js +11 -11
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/InvalidType.d.ts +3 -2
- package/dist/types/InvalidType.js +7 -4
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/LazyType.d.ts +17 -0
- package/dist/types/LazyType.js +44 -0
- package/dist/types/LazyType.js.map +1 -0
- package/dist/types/LongIntegerType.d.ts +2 -1
- package/dist/types/LongIntegerType.js +11 -11
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/ObjectType.d.ts +6 -2
- package/dist/types/ObjectType.js +9 -3
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/StringType.d.ts +3 -2
- package/dist/types/StringType.js +6 -3
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/UninitializedType.d.ts +4 -2
- package/dist/types/UninitializedType.js +8 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.d.ts +3 -2
- package/dist/types/VoidType.js +6 -3
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/helpers.d.ts +42 -0
- package/dist/types/helpers.js +113 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/util.d.ts +68 -15
- package/dist/util.js +193 -45
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +5 -1
- package/dist/validators/ClassValidator.js +31 -17
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +1 -1
- package/dist/FunctionScope.d.ts +0 -27
- package/dist/FunctionScope.js +0 -49
- package/dist/FunctionScope.js.map +0 -1
package/dist/interfaces.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
64
|
-
file:
|
|
65
|
-
name:
|
|
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?:
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
beforeProgramValidate?:
|
|
174
|
-
afterProgramValidate?:
|
|
175
|
-
beforeProgramTranspile?:
|
|
176
|
-
afterProgramTranspile?:
|
|
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?:
|
|
180
|
-
beforeScopeDispose?:
|
|
181
|
-
afterScopeDispose?:
|
|
182
|
-
beforeScopeValidate?:
|
|
183
|
-
afterScopeValidate?:
|
|
184
|
-
beforeFileParse?:
|
|
185
|
-
afterFileParse?:
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
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.
|
|
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":";;;
|
|
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
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
230
|
-
|
|
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 =
|
|
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,
|
|
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,
|
|
212
|
+
constructor(name, type, equalsToken, defaultValue, asToken, typeToken, namespaceName) {
|
|
205
213
|
super();
|
|
206
214
|
this.name = name;
|
|
207
|
-
this.
|
|
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
|
|
691
|
+
let functionExpression = state.file.getFunctionExpressionAtPosition(this.token.range.start);
|
|
671
692
|
let nameParts = [];
|
|
672
|
-
while (
|
|
673
|
-
let index =
|
|
693
|
+
while (functionExpression.parentFunction) {
|
|
694
|
+
let index = functionExpression.parentFunction.childFunctionExpressions.indexOf(functionExpression);
|
|
674
695
|
nameParts.unshift(`anon${index}`);
|
|
675
|
-
|
|
696
|
+
functionExpression = functionExpression.parentFunction;
|
|
676
697
|
}
|
|
677
698
|
//get the index of this function in its parent
|
|
678
|
-
nameParts.unshift(
|
|
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
|
-
|
|
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
|
-
|
|
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:
|