brighterscript 1.0.0-alpha.23 → 1.0.0-alpha.24
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 +108 -1
- package/dist/DiagnosticMessages.d.ts +19 -3
- package/dist/DiagnosticMessages.js +23 -7
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.js +74 -20
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Program.d.ts +7 -5
- package/dist/Program.js +84 -49
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +2 -1
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +22 -15
- package/dist/Scope.js +108 -122
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +17 -6
- package/dist/SymbolTable.js +38 -9
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.js +3 -2
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +5 -1
- package/dist/astUtils/reflection.js +15 -2
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +2 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +3 -1
- package/dist/bscPlugin/BscPlugin.js +8 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +11 -5
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +75 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +6 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js +53 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.d.ts +17 -0
- package/dist/bscPlugin/hover/HoverProcessor.js +190 -0
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +195 -0
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +19 -8
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +84 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +7 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +81 -22
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +14 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +104 -27
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +48 -0
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +24 -3
- package/dist/bscPlugin/validation/ScopeValidator.js +249 -48
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/cli.js +18 -10
- package/dist/cli.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +51 -38
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +21 -10
- package/dist/files/BrsFile.js +158 -179
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +222 -126
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +2 -2
- package/dist/files/XmlFile.js +1 -0
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/tests/imports.spec.js +1 -1
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +20 -16
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/globalCallables.js +3 -0
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +65 -3
- package/dist/lexer/Lexer.spec.js +7 -0
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +1 -0
- package/dist/lexer/TokenKind.js +8 -3
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/Expression.d.ts +12 -3
- package/dist/parser/Expression.js +16 -4
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +1 -1
- package/dist/parser/Parser.d.ts +10 -3
- package/dist/parser/Parser.js +107 -47
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +181 -108
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +41 -7
- package/dist/parser/Statement.js +84 -11
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +73 -31
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +148 -47
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +219 -37
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js +213 -0
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/Enum.spec.js +17 -2
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +72 -57
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/preprocessor/Manifest.js +2 -2
- package/dist/preprocessor/Manifest.js.map +1 -1
- package/dist/preprocessor/Preprocessor.js +10 -6
- package/dist/preprocessor/Preprocessor.js.map +1 -1
- package/dist/roku-types/data.json +1002 -788
- package/dist/roku-types/index.d.ts +64 -239
- package/dist/types/DynamicType.d.ts +1 -0
- package/dist/types/DynamicType.js +1 -0
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/util.d.ts +55 -14
- package/dist/util.js +131 -25
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +0 -1
- package/dist/validators/ClassValidator.js +15 -26
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +5 -2
package/dist/parser/Parser.js
CHANGED
|
@@ -13,10 +13,10 @@ const reflection_1 = require("../astUtils/reflection");
|
|
|
13
13
|
const visitors_1 = require("../astUtils/visitors");
|
|
14
14
|
const creators_1 = require("../astUtils/creators");
|
|
15
15
|
const Cache_1 = require("../Cache");
|
|
16
|
+
const SymbolTable_1 = require("../SymbolTable");
|
|
16
17
|
const DynamicType_1 = require("../types/DynamicType");
|
|
17
18
|
const ArrayType_1 = require("../types/ArrayType");
|
|
18
19
|
const helpers_1 = require("../types/helpers");
|
|
19
|
-
const SymbolTable_1 = require("../SymbolTable");
|
|
20
20
|
const ObjectType_1 = require("../types/ObjectType");
|
|
21
21
|
class Parser {
|
|
22
22
|
constructor() {
|
|
@@ -28,7 +28,10 @@ class Parser {
|
|
|
28
28
|
* The list of statements for the parsed file
|
|
29
29
|
*/
|
|
30
30
|
this.ast = new Statement_1.Body([]);
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The top-level symbol table for this file. Things like top-level namespaces, non-namespaced classes, enums, interfaces, and functions beling here.
|
|
33
|
+
*/
|
|
34
|
+
this.symbolTable = new SymbolTable_1.SymbolTable(undefined, `File Parser`);
|
|
32
35
|
this._references = new References();
|
|
33
36
|
this.globalTerminators = [];
|
|
34
37
|
/**
|
|
@@ -40,8 +43,8 @@ class Parser {
|
|
|
40
43
|
return this.ast.statements;
|
|
41
44
|
}
|
|
42
45
|
get currentSymbolTable() {
|
|
43
|
-
var _a, _b;
|
|
44
|
-
return (_b = (_a = this.currentFunctionExpression) === null || _a === void 0 ? void 0 : _a.symbolTable) !== null && _b !== void 0 ? _b : this.symbolTable;
|
|
46
|
+
var _a, _b, _c, _d;
|
|
47
|
+
return (_d = (_b = (_a = this.currentFunctionExpression) === null || _a === void 0 ? void 0 : _a.symbolTable) !== null && _b !== void 0 ? _b : (_c = this.currentNamespace) === null || _c === void 0 ? void 0 : _c.symbolTable) !== null && _d !== void 0 ? _d : this.symbolTable;
|
|
45
48
|
}
|
|
46
49
|
/**
|
|
47
50
|
* References for significant statements/expressions in the parser.
|
|
@@ -93,22 +96,22 @@ class Parser {
|
|
|
93
96
|
* Static wrapper around creating a new parser and parsing a list of tokens
|
|
94
97
|
*/
|
|
95
98
|
static parse(toParse, options) {
|
|
96
|
-
|
|
97
|
-
if (typeof toParse === 'string') {
|
|
98
|
-
tokens = Lexer_1.Lexer.scan(toParse).tokens;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
tokens = toParse;
|
|
102
|
-
}
|
|
103
|
-
return new Parser().parse(tokens, options);
|
|
99
|
+
return new Parser().parse(toParse, options);
|
|
104
100
|
}
|
|
105
101
|
/**
|
|
106
102
|
* Parses an array of `Token`s into an abstract syntax tree
|
|
107
103
|
* @param toParse the array of tokens to parse. May not contain any whitespace tokens
|
|
108
104
|
* @returns the same instance of the parser which contains the diagnostics and statements
|
|
109
105
|
*/
|
|
110
|
-
parse(
|
|
106
|
+
parse(toParse, options) {
|
|
111
107
|
var _a;
|
|
108
|
+
let tokens;
|
|
109
|
+
if (typeof toParse === 'string') {
|
|
110
|
+
tokens = Lexer_1.Lexer.scan(toParse).tokens;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
tokens = toParse;
|
|
114
|
+
}
|
|
112
115
|
this.logger = (_a = options === null || options === void 0 ? void 0 : options.logger) !== null && _a !== void 0 ? _a : new Logger_1.Logger();
|
|
113
116
|
this.tokens = tokens;
|
|
114
117
|
this.options = this.sanitizeParseOptions(options);
|
|
@@ -126,7 +129,7 @@ class Parser {
|
|
|
126
129
|
}
|
|
127
130
|
body() {
|
|
128
131
|
const parentAnnotations = this.enterAnnotationBlock();
|
|
129
|
-
let body = new Statement_1.Body([]);
|
|
132
|
+
let body = new Statement_1.Body([], this.symbolTable);
|
|
130
133
|
if (this.tokens.length > 0) {
|
|
131
134
|
this.consumeStatementSeparators(true);
|
|
132
135
|
try {
|
|
@@ -192,6 +195,9 @@ class Parser {
|
|
|
192
195
|
if (this.checkLibrary()) {
|
|
193
196
|
return this.libraryStatement();
|
|
194
197
|
}
|
|
198
|
+
if (this.check(TokenKind_1.TokenKind.Const) && this.checkAnyNext(TokenKind_1.TokenKind.Identifier, ...this.allowedLocalIdentifiers)) {
|
|
199
|
+
return this.constDeclaration();
|
|
200
|
+
}
|
|
195
201
|
if (this.check(TokenKind_1.TokenKind.At) && this.checkNext(TokenKind_1.TokenKind.Identifier)) {
|
|
196
202
|
return this.annotationExpression();
|
|
197
203
|
}
|
|
@@ -495,11 +501,20 @@ class Parser {
|
|
|
495
501
|
if (!options.onlyCallableAsMember) {
|
|
496
502
|
this._references.functionStatements.push(result);
|
|
497
503
|
}
|
|
504
|
+
// Add the transpiled name for namespace functions
|
|
505
|
+
// to consider an edge case when defining namespaces in .bs files
|
|
506
|
+
// and using them in .brs files.
|
|
507
|
+
if (result.func.namespaceName) {
|
|
508
|
+
const transpiledNamespaceFunctionName = result.getName(ParseMode.BrightScript);
|
|
509
|
+
const funcType = result.func.getFunctionType();
|
|
510
|
+
funcType.setName(transpiledNamespaceFunctionName);
|
|
511
|
+
this.symbolTable.addSymbol(transpiledNamespaceFunctionName, result.name.range, funcType);
|
|
512
|
+
}
|
|
498
513
|
return result;
|
|
499
514
|
}
|
|
500
515
|
}
|
|
501
516
|
functionDeclaration(options = {}) {
|
|
502
|
-
var _a, _b, _c
|
|
517
|
+
var _a, _b, _c;
|
|
503
518
|
let previousCallExpressions = this.callExpressions;
|
|
504
519
|
this.callExpressions = [];
|
|
505
520
|
try {
|
|
@@ -573,10 +588,12 @@ class Parser {
|
|
|
573
588
|
// do not go to next statement - we don't care about any other statement
|
|
574
589
|
this.consumeStatementSeparators(true);
|
|
575
590
|
}
|
|
591
|
+
// Can Not use the current function expression symbol table for a function expression inside of itself
|
|
592
|
+
const funcExprParentSymbolTable = (_c = (_b = this.currentNamespace) === null || _b === void 0 ? void 0 : _b.symbolTable) !== null && _c !== void 0 ? _c : this.symbolTable;
|
|
576
593
|
let func = new Expression_1.FunctionExpression(params, undefined, //body
|
|
577
594
|
functionKeyword, undefined, //ending keyword
|
|
578
595
|
leftParen, rightParen, asToken, typeExpr, //return type
|
|
579
|
-
this.currentFunctionExpression, this.currentNamespaceName,
|
|
596
|
+
this.currentFunctionExpression, this.currentNamespaceName, funcExprParentSymbolTable);
|
|
580
597
|
//if there is a parent function, register this function with the parent
|
|
581
598
|
if (this.currentFunctionExpression) {
|
|
582
599
|
this.currentFunctionExpression.childFunctionExpressions.push(func);
|
|
@@ -585,14 +602,8 @@ class Parser {
|
|
|
585
602
|
if (!options.onlyCallableAsMember && name) {
|
|
586
603
|
const funcType = func.getFunctionType();
|
|
587
604
|
funcType.setName(name.text);
|
|
588
|
-
// add the function as declared to the current
|
|
589
|
-
|
|
590
|
-
let fullyQualifiedName = name.text;
|
|
591
|
-
if (this.currentNamespaceName) {
|
|
592
|
-
// add the "namespaced" name of this function to the parent symbol table
|
|
593
|
-
fullyQualifiedName = this.currentNamespaceName.getName(ParseMode.BrighterScript) + '.' + name.text;
|
|
594
|
-
}
|
|
595
|
-
this.currentSymbolTable.addSymbol(fullyQualifiedName, name.range, funcType);
|
|
605
|
+
// add the function as declared to the current symbol table
|
|
606
|
+
this.currentSymbolTable.addSymbol(name.text, name.range, funcType);
|
|
596
607
|
}
|
|
597
608
|
this._references.functionExpressions.push(func);
|
|
598
609
|
if (options.hasBody) {
|
|
@@ -686,8 +697,10 @@ class Parser {
|
|
|
686
697
|
const nameExpression = new Expression_1.VariableExpression(name, this.currentNamespaceName);
|
|
687
698
|
result = new Statement_1.AssignmentStatement(name, operator, new Expression_1.BinaryExpression(nameExpression, operator, value), this.currentFunctionExpression);
|
|
688
699
|
this.addExpressionsToReferences(nameExpression);
|
|
689
|
-
|
|
690
|
-
|
|
700
|
+
if ((0, reflection_1.isBinaryExpression)(value)) {
|
|
701
|
+
//remove the right-hand-side expression from this assignment operator, and replace with the full assignment expression
|
|
702
|
+
this._references.expressions.delete(value);
|
|
703
|
+
}
|
|
691
704
|
this._references.expressions.add(result);
|
|
692
705
|
}
|
|
693
706
|
this._references.assignmentStatements.push(result);
|
|
@@ -929,6 +942,9 @@ class Parser {
|
|
|
929
942
|
this._references.namespaceStatements.push(result);
|
|
930
943
|
//cache the range property so that plugins can't affect it
|
|
931
944
|
result.cacheRange();
|
|
945
|
+
if (result.name) {
|
|
946
|
+
this.symbolTable.addSymbol(result.name.split('.')[0], result.nameExpression.range, DynamicType_1.DynamicType.instance);
|
|
947
|
+
}
|
|
932
948
|
return result;
|
|
933
949
|
}
|
|
934
950
|
/**
|
|
@@ -981,6 +997,23 @@ class Parser {
|
|
|
981
997
|
}
|
|
982
998
|
return result;
|
|
983
999
|
}
|
|
1000
|
+
constDeclaration() {
|
|
1001
|
+
this.warnIfNotBrighterScriptMode('const declaration');
|
|
1002
|
+
const constToken = this.advance();
|
|
1003
|
+
const nameToken = this.identifier(...this.allowedLocalIdentifiers);
|
|
1004
|
+
const equalToken = this.consumeToken(TokenKind_1.TokenKind.Equal);
|
|
1005
|
+
const expression = this.expression();
|
|
1006
|
+
const statement = new Statement_1.ConstStatement({
|
|
1007
|
+
const: constToken,
|
|
1008
|
+
name: nameToken,
|
|
1009
|
+
equals: equalToken
|
|
1010
|
+
}, expression, this.currentNamespaceName);
|
|
1011
|
+
if (nameToken) {
|
|
1012
|
+
this.currentSymbolTable.addSymbol(nameToken.text, nameToken.range, getBscTypeFromExpression(expression));
|
|
1013
|
+
}
|
|
1014
|
+
this._references.constStatements.push(statement);
|
|
1015
|
+
return statement;
|
|
1016
|
+
}
|
|
984
1017
|
libraryStatement() {
|
|
985
1018
|
let libStatement = new Statement_1.LibraryStatement({
|
|
986
1019
|
library: this.advance(),
|
|
@@ -1151,6 +1184,9 @@ class Parser {
|
|
|
1151
1184
|
else {
|
|
1152
1185
|
statement.tokens.endTry = this.advance();
|
|
1153
1186
|
}
|
|
1187
|
+
if (exceptionVarToken) {
|
|
1188
|
+
this.currentSymbolTable.addSymbol(exceptionVarToken.text, exceptionVarToken.range, DynamicType_1.DynamicType.instance);
|
|
1189
|
+
}
|
|
1154
1190
|
return statement;
|
|
1155
1191
|
}
|
|
1156
1192
|
throwStatement() {
|
|
@@ -1193,6 +1229,9 @@ class Parser {
|
|
|
1193
1229
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.missingExpressionsInDimStatement()), { range: this.peek().range }));
|
|
1194
1230
|
}
|
|
1195
1231
|
let rightSquareBracket = this.tryConsume(DiagnosticMessages_1.DiagnosticMessages.missingRightSquareBracketAfterDimIdentifier(), TokenKind_1.TokenKind.RightSquareBracket);
|
|
1232
|
+
if (identifier) {
|
|
1233
|
+
this.currentSymbolTable.addSymbol(identifier.text, identifier.range, new ArrayType_1.ArrayType(DynamicType_1.DynamicType.instance));
|
|
1234
|
+
}
|
|
1196
1235
|
return new Statement_1.DimStatement(dim, identifier, leftSquareBracket, expressions, rightSquareBracket);
|
|
1197
1236
|
}
|
|
1198
1237
|
ifStatement() {
|
|
@@ -1398,6 +1437,8 @@ class Parser {
|
|
|
1398
1437
|
}
|
|
1399
1438
|
//at this point, it's probably an error. However, we recover a little more gracefully by creating an assignment
|
|
1400
1439
|
this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()), { range: expressionStart.range }));
|
|
1440
|
+
// we can also add this expression to the references, for type checking purposes
|
|
1441
|
+
this._references.expressions.add(expr);
|
|
1401
1442
|
throw this.lastDiagnosticAsError();
|
|
1402
1443
|
}
|
|
1403
1444
|
setStatement() {
|
|
@@ -1921,7 +1962,7 @@ class Parser {
|
|
|
1921
1962
|
range: null
|
|
1922
1963
|
};
|
|
1923
1964
|
if (this.checkAny(TokenKind_1.TokenKind.Identifier, ...TokenKind_1.AllowedProperties)) {
|
|
1924
|
-
result.keyToken = this.
|
|
1965
|
+
result.keyToken = this.identifier(...TokenKind_1.AllowedProperties);
|
|
1925
1966
|
}
|
|
1926
1967
|
else if (this.check(TokenKind_1.TokenKind.StringLiteral)) {
|
|
1927
1968
|
result.keyToken = this.advance();
|
|
@@ -2290,9 +2331,10 @@ class Parser {
|
|
|
2290
2331
|
currentTokenIndex = previousTokenResult === null || previousTokenResult === void 0 ? void 0 : previousTokenResult.index;
|
|
2291
2332
|
}
|
|
2292
2333
|
}
|
|
2334
|
+
const isLiteral = (currentToken === null || currentToken === void 0 ? void 0 : currentToken.kind) === TokenKind_1.TokenKind.StringLiteral || (currentToken === null || currentToken === void 0 ? void 0 : currentToken.kind) === TokenKind_1.TokenKind.IntegerLiteral || (currentToken === null || currentToken === void 0 ? void 0 : currentToken.kind) === TokenKind_1.TokenKind.FloatLiteral || (currentToken === null || currentToken === void 0 ? void 0 : currentToken.kind) === TokenKind_1.TokenKind.Boolean;
|
|
2293
2335
|
// We will not be able to decipher the token type if it was in brackets
|
|
2294
2336
|
// e.g (someVar+otherVar).toStr() -- we don't bother trying to decipher what "(someVar+otherVar)" is
|
|
2295
|
-
let isUnknown = (lastTokenWasLeftBracket && (lastTokenHadLeadingWhitespace || !this.isAcceptableChainToken(currentToken)));
|
|
2337
|
+
let isUnknown = isLiteral || (lastTokenWasLeftBracket && (lastTokenHadLeadingWhitespace || !this.isAcceptableChainToken(currentToken)));
|
|
2296
2338
|
const tokenWithIndex = { token: currentToken, index: currentTokenIndex, tokenTypeIsNotKnowable: isUnknown, hasBrackets: hasBrackets };
|
|
2297
2339
|
return tokenWithIndex;
|
|
2298
2340
|
}
|
|
@@ -2312,7 +2354,7 @@ class Parser {
|
|
|
2312
2354
|
currentToken = previousTokenResult === null || previousTokenResult === void 0 ? void 0 : previousTokenResult.token;
|
|
2313
2355
|
currentTokenIndex = previousTokenResult === null || previousTokenResult === void 0 ? void 0 : previousTokenResult.index;
|
|
2314
2356
|
}
|
|
2315
|
-
if ((currentToken === null || currentToken === void 0 ? void 0 : currentToken.kind) === TokenKind_1.TokenKind.Dot) {
|
|
2357
|
+
if ((currentToken === null || currentToken === void 0 ? void 0 : currentToken.kind) === TokenKind_1.TokenKind.Dot || (currentToken === null || currentToken === void 0 ? void 0 : currentToken.kind) === TokenKind_1.TokenKind.QuestionDot) {
|
|
2316
2358
|
previousTokenResult = this.getPreviousTokenFromIndex(currentTokenIndex);
|
|
2317
2359
|
currentToken = previousTokenResult.token;
|
|
2318
2360
|
currentTokenIndex = previousTokenResult.index;
|
|
@@ -2522,6 +2564,9 @@ class Parser {
|
|
|
2522
2564
|
EnumStatement: e => {
|
|
2523
2565
|
this._references.enumStatements.push(e);
|
|
2524
2566
|
},
|
|
2567
|
+
ConstStatement: s => {
|
|
2568
|
+
this._references.constStatements.push(s);
|
|
2569
|
+
},
|
|
2525
2570
|
UnaryExpression: e => {
|
|
2526
2571
|
this._references.expressions.add(e);
|
|
2527
2572
|
},
|
|
@@ -2532,6 +2577,9 @@ class Parser {
|
|
|
2532
2577
|
walkMode: visitors_1.WalkMode.visitAllRecursive
|
|
2533
2578
|
});
|
|
2534
2579
|
}
|
|
2580
|
+
getContainingExpression(currentToken) {
|
|
2581
|
+
return [...this.references.expressions].find((cs) => util_1.util.rangeContainsRange(cs.range, currentToken.range));
|
|
2582
|
+
}
|
|
2535
2583
|
getContainingClass(currentToken) {
|
|
2536
2584
|
return this.references.classStatements.find((cs) => util_1.util.rangeContains(cs.range, currentToken.range.start));
|
|
2537
2585
|
}
|
|
@@ -2567,6 +2615,7 @@ class References {
|
|
|
2567
2615
|
this.functionStatements = [];
|
|
2568
2616
|
this.interfaceStatements = [];
|
|
2569
2617
|
this.enumStatements = [];
|
|
2618
|
+
this.constStatements = [];
|
|
2570
2619
|
/**
|
|
2571
2620
|
* A collection of full expressions. This excludes intermediary expressions.
|
|
2572
2621
|
*
|
|
@@ -2626,6 +2675,15 @@ class References {
|
|
|
2626
2675
|
return result;
|
|
2627
2676
|
});
|
|
2628
2677
|
}
|
|
2678
|
+
get constStatementLookup() {
|
|
2679
|
+
return this.cache.getOrAdd('consts', () => {
|
|
2680
|
+
const result = new Map();
|
|
2681
|
+
for (const stmt of this.constStatements) {
|
|
2682
|
+
result.set(stmt.fullName.toLowerCase(), stmt);
|
|
2683
|
+
}
|
|
2684
|
+
return result;
|
|
2685
|
+
});
|
|
2686
|
+
}
|
|
2629
2687
|
}
|
|
2630
2688
|
exports.References = References;
|
|
2631
2689
|
var TokenUsage;
|
|
@@ -2667,23 +2725,25 @@ function getBscTypeFromExpression(expression, functionExpression) {
|
|
|
2667
2725
|
return new ArrayType_1.ArrayType(...innerTypes);
|
|
2668
2726
|
//function call
|
|
2669
2727
|
}
|
|
2670
|
-
else if (
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2728
|
+
else if (functionExpression) {
|
|
2729
|
+
// These are more precise, and can't be determined without knowing the function expression you're in
|
|
2730
|
+
if ((0, reflection_1.isNewExpression)(expression)) {
|
|
2731
|
+
return (0, helpers_1.getTypeFromNewExpression)(expression, functionExpression);
|
|
2732
|
+
}
|
|
2733
|
+
else if ((0, reflection_1.isCallExpression)(expression)) {
|
|
2734
|
+
return (0, helpers_1.getTypeFromCallExpression)(expression, functionExpression);
|
|
2735
|
+
}
|
|
2736
|
+
else if ((0, reflection_1.isVariableExpression)(expression)) {
|
|
2737
|
+
return (0, helpers_1.getTypeFromVariableExpression)(expression, functionExpression);
|
|
2738
|
+
}
|
|
2739
|
+
else if ((0, reflection_1.isDottedGetExpression)(expression)) {
|
|
2740
|
+
return (0, helpers_1.getTypeFromDottedGetExpression)(expression, functionExpression);
|
|
2741
|
+
}
|
|
2742
|
+
else if ((0, reflection_1.isIndexedGetExpression)(expression)) {
|
|
2743
|
+
const source = getBscTypeFromExpression(expression.obj, functionExpression);
|
|
2744
|
+
if ((0, reflection_1.isArrayType)(source)) {
|
|
2745
|
+
return source.getDefaultType();
|
|
2746
|
+
}
|
|
2687
2747
|
}
|
|
2688
2748
|
}
|
|
2689
2749
|
}
|
|
@@ -2691,7 +2751,7 @@ function getBscTypeFromExpression(expression, functionExpression) {
|
|
|
2691
2751
|
//do nothing. Just return dynamic
|
|
2692
2752
|
}
|
|
2693
2753
|
//fallback to dynamic
|
|
2694
|
-
return
|
|
2754
|
+
return DynamicType_1.DynamicType.instance;
|
|
2695
2755
|
}
|
|
2696
2756
|
exports.getBscTypeFromExpression = getBscTypeFromExpression;
|
|
2697
2757
|
//# sourceMappingURL=Parser.js.map
|