brighterscript 1.0.0-alpha.1 → 1.0.0-alpha.13
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 +362 -248
- package/README.md +2 -2
- package/bsconfig.schema.json +1 -1
- package/dist/CodeActionUtil.d.ts +11 -2
- package/dist/CodeActionUtil.js +17 -3
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +4 -4
- package/dist/CommentFlagProcessor.js +5 -3
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticCollection.js +2 -2
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.js +3 -3
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +15 -5
- package/dist/DiagnosticMessages.js +19 -9
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.d.ts +11 -10
- package/dist/LanguageServer.js +87 -58
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.d.ts +2 -0
- package/dist/Logger.js +5 -3
- package/dist/Logger.js.map +1 -1
- package/dist/Program.d.ts +76 -46
- package/dist/Program.js +254 -180
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +7 -7
- package/dist/ProgramBuilder.js +37 -43
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +33 -23
- package/dist/Scope.js +222 -147
- package/dist/Scope.js.map +1 -1
- package/dist/SemanticTokenUtils.d.ts +14 -0
- package/dist/SemanticTokenUtils.js +81 -0
- package/dist/SemanticTokenUtils.js.map +1 -0
- package/dist/SymbolTable.d.ts +9 -3
- package/dist/SymbolTable.js +40 -13
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.d.ts +7 -2
- package/dist/XmlScope.js +67 -29
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +27 -0
- package/dist/astUtils/AstEditor.js +97 -0
- package/dist/astUtils/AstEditor.js.map +1 -0
- package/dist/astUtils/AstEditor.spec.d.ts +1 -0
- package/dist/astUtils/AstEditor.spec.js +133 -0
- package/dist/astUtils/AstEditor.spec.js.map +1 -0
- 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/creators.spec.js +4 -4
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/index.js +1 -1
- package/dist/astUtils/reflection.d.ts +20 -8
- package/dist/astUtils/reflection.js +42 -1
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +115 -115
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +13 -13
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.js +1 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +28 -28
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +4 -3
- package/dist/astUtils/xml.js +8 -3
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +2 -1
- package/dist/bscPlugin/BscPlugin.js +4 -0
- package/dist/bscPlugin/BscPlugin.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 +30 -30
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +7 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js +63 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +45 -0
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +1 -0
- package/dist/diagnosticUtils.d.ts +1 -0
- package/dist/diagnosticUtils.js +14 -7
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +2 -2
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +486 -71
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +48 -23
- package/dist/files/BrsFile.js +403 -233
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +367 -316
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +13 -6
- package/dist/files/XmlFile.js +27 -21
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +274 -228
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +49 -49
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +359 -87
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +51 -14
- package/dist/lexer/Lexer.d.ts +14 -1
- package/dist/lexer/Lexer.js +91 -21
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +187 -132
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +2 -2
- package/dist/lexer/TokenKind.d.ts +7 -1
- package/dist/lexer/TokenKind.js +51 -3
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/lexer/index.js +2 -1
- package/dist/lexer/index.js.map +1 -1
- 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 -5
- package/dist/parser/Expression.js +124 -75
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +159 -60
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +114 -26
- package/dist/parser/Parser.js +471 -126
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +396 -235
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +41 -4
- package/dist/parser/SGParser.js +186 -175
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +35 -22
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +206 -38
- package/dist/parser/SGTypes.js +470 -161
- 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 +92 -18
- package/dist/parser/Statement.js +287 -58
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +11 -11
- 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/index.js +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +8 -7
- package/dist/parser/tests/Parser.spec.js +12 -8
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +50 -50
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +31 -31
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +174 -156
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +32 -32
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +21 -21
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +105 -105
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +148 -124
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +17 -17
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +30 -30
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +16 -16
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +247 -247
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +73 -73
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +36 -36
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +59 -47
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +35 -35
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +26 -26
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +170 -0
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
- package/dist/parser/tests/expression/Relational.spec.js +42 -42
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +8 -8
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +12 -12
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +100 -100
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +35 -35
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/Declaration.spec.js +39 -39
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +21 -21
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Function.spec.js +192 -192
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +11 -11
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +46 -46
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +61 -0
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
- package/dist/parser/tests/statement/LibraryStatement.spec.js +10 -10
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +37 -36
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +30 -30
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +43 -43
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +69 -69
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +9 -9
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +5 -5
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +13 -13
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Chunk.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.js +1 -1
- package/dist/preprocessor/Preprocessor.js.map +1 -1
- package/dist/preprocessor/Preprocessor.spec.js +49 -49
- package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
- package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
- package/dist/preprocessor/index.js +1 -1
- package/dist/types/ArrayType.js +5 -4
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +8 -8
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/BooleanType.js +3 -3
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +2 -2
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +19 -5
- 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 +17 -6
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.js +8 -8
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +2 -2
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.js +1 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +2 -2
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/FloatType.d.ts +1 -1
- package/dist/types/FloatType.js +8 -8
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +2 -2
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +5 -11
- package/dist/types/FunctionType.js +24 -13
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +11 -5
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.d.ts +1 -1
- package/dist/types/IntegerType.js +8 -8
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +2 -2
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +8 -2
- package/dist/types/InterfaceType.js +42 -6
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.d.ts +1 -0
- package/dist/types/InterfaceType.spec.js +174 -0
- package/dist/types/InterfaceType.spec.js.map +1 -0
- package/dist/types/InvalidType.js +4 -4
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +2 -2
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LazyType.d.ts +9 -7
- package/dist/types/LazyType.js +22 -10
- package/dist/types/LazyType.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +1 -1
- package/dist/types/LongIntegerType.js +8 -8
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +2 -2
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/ObjectType.d.ts +7 -4
- package/dist/types/ObjectType.js +6 -3
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +2 -2
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/StringType.js +3 -3
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +2 -2
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/UninitializedType.js +3 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.js +3 -3
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +2 -2
- package/dist/types/VoidType.spec.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 +77 -17
- package/dist/util.js +247 -59
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +5 -1
- package/dist/validators/ClassValidator.js +59 -24
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +13 -13
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTypeFromDottedGetExpression = exports.getTypeFromNewExpression = exports.getTypeFromVariableExpression = exports.getTypeFromCallExpression = void 0;
|
|
4
|
+
const reflection_1 = require("../astUtils/reflection");
|
|
5
|
+
const LazyType_1 = require("./LazyType");
|
|
6
|
+
const UninitializedType_1 = require("./UninitializedType");
|
|
7
|
+
const Parser_1 = require("../parser/Parser");
|
|
8
|
+
const CustomType_1 = require("./CustomType");
|
|
9
|
+
/**
|
|
10
|
+
* Gets the return type of a function, taking into account that the function may not have been declared yet
|
|
11
|
+
* If the callee already exists in symbol table, use that return type
|
|
12
|
+
* otherwise, make a lazy type which will not compute its type until the file is done parsing
|
|
13
|
+
*
|
|
14
|
+
* @param call the Expression to process
|
|
15
|
+
* @param functionExpression the wrapping function expression
|
|
16
|
+
* @return the best guess type of that expression
|
|
17
|
+
*/
|
|
18
|
+
function getTypeFromCallExpression(call, functionExpression) {
|
|
19
|
+
let calleeName = call.callee.name;
|
|
20
|
+
if (calleeName) {
|
|
21
|
+
const currentKnownType = functionExpression.symbolTable.getSymbolType(calleeName.text.toLowerCase());
|
|
22
|
+
if ((0, reflection_1.isFunctionType)(currentKnownType)) {
|
|
23
|
+
return currentKnownType.returnType;
|
|
24
|
+
}
|
|
25
|
+
if (currentKnownType) {
|
|
26
|
+
// this will probably only happen if a functionName has been assigned to something else previously?
|
|
27
|
+
return currentKnownType;
|
|
28
|
+
}
|
|
29
|
+
return new LazyType_1.LazyType((context) => {
|
|
30
|
+
var _a;
|
|
31
|
+
let futureType;
|
|
32
|
+
if ((0, reflection_1.isBrsFile)(context === null || context === void 0 ? void 0 : context.file)) {
|
|
33
|
+
const file = context.file;
|
|
34
|
+
futureType = (_a = file.getSymbolTypeFromToken(calleeName, functionExpression, context.scope)) === null || _a === void 0 ? void 0 : _a.type;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// Give best guess if there is no file context
|
|
38
|
+
futureType = functionExpression.symbolTable.getSymbolType(calleeName.text);
|
|
39
|
+
}
|
|
40
|
+
if ((0, reflection_1.isFunctionType)(futureType)) {
|
|
41
|
+
return futureType.returnType;
|
|
42
|
+
}
|
|
43
|
+
return futureType;
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.getTypeFromCallExpression = getTypeFromCallExpression;
|
|
48
|
+
/**
|
|
49
|
+
* Gets the type of a variable
|
|
50
|
+
* if it already exists in symbol table, use that type
|
|
51
|
+
* otherwise defer the type until first read, which will allow us to derive types from variables defined after this one (like from a loop perhaps)
|
|
52
|
+
*
|
|
53
|
+
* @param variable the Expression to process
|
|
54
|
+
* @param functionExpression the wrapping function expression
|
|
55
|
+
* @return the best guess type of that expression
|
|
56
|
+
*/
|
|
57
|
+
function getTypeFromVariableExpression(variable, functionExpression) {
|
|
58
|
+
let variableName = variable.name.text.toLowerCase();
|
|
59
|
+
const currentKnownType = functionExpression.symbolTable.getSymbolType(variableName);
|
|
60
|
+
if ((0, reflection_1.isPrimitiveType)(currentKnownType)) {
|
|
61
|
+
// for "contextless" types, eg. myVar = 3.14
|
|
62
|
+
return currentKnownType;
|
|
63
|
+
}
|
|
64
|
+
return resolveLazyType(variable.name, functionExpression);
|
|
65
|
+
}
|
|
66
|
+
exports.getTypeFromVariableExpression = getTypeFromVariableExpression;
|
|
67
|
+
/**
|
|
68
|
+
* Gets the type of a variable
|
|
69
|
+
* if it already exists in symbol table, use that type
|
|
70
|
+
* otherwise defer the type until first read, which will allow us to derive types from variables defined after this one (like from a loop perhaps)
|
|
71
|
+
*
|
|
72
|
+
* @param newExp the Expression to process
|
|
73
|
+
* @param functionExpression the wrapping function expression
|
|
74
|
+
* @return the best guess type of that expression
|
|
75
|
+
*/
|
|
76
|
+
function getTypeFromNewExpression(newExp, functionExpression) {
|
|
77
|
+
let className = newExp.className.getName(Parser_1.ParseMode.BrighterScript);
|
|
78
|
+
return new LazyType_1.LazyType((context) => {
|
|
79
|
+
var _a, _b, _c;
|
|
80
|
+
return new CustomType_1.CustomType(className, (_c = (_a = context === null || context === void 0 ? void 0 : context.scope) === null || _a === void 0 ? void 0 : _a.getClass(className, (_b = functionExpression.namespaceName) === null || _b === void 0 ? void 0 : _b.getName())) === null || _c === void 0 ? void 0 : _c.memberTable);
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.getTypeFromNewExpression = getTypeFromNewExpression;
|
|
84
|
+
function resolveLazyType(currentToken, functionExpression) {
|
|
85
|
+
return new LazyType_1.LazyType((context) => {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
let futureType;
|
|
88
|
+
if ((0, reflection_1.isBrsFile)(context === null || context === void 0 ? void 0 : context.file)) {
|
|
89
|
+
const file = context.file;
|
|
90
|
+
futureType = (_a = file.getSymbolTypeFromToken(currentToken, functionExpression, context.scope)) === null || _a === void 0 ? void 0 : _a.type;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// Give best guess if there is no file context
|
|
94
|
+
futureType = (_b = functionExpression.symbolTable.getSymbolType(currentToken.text)) !== null && _b !== void 0 ? _b : new UninitializedType_1.UninitializedType();
|
|
95
|
+
}
|
|
96
|
+
return futureType;
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Gets the type of a variable
|
|
101
|
+
* if it already exists in symbol table, use that type
|
|
102
|
+
* otherwise defer the type until first read, which will allow us to derive types from variables defined after this one (like from a loop perhaps)
|
|
103
|
+
*
|
|
104
|
+
* @param variable the Expression to process
|
|
105
|
+
* @param functionExpression the wrapping function expression
|
|
106
|
+
* @return the best guess type of that expression
|
|
107
|
+
*/
|
|
108
|
+
function getTypeFromDottedGetExpression(expr, functionExpression) {
|
|
109
|
+
const currentToken = (0, reflection_1.isCallExpression)(expr) ? (expr.callee).name : expr.name;
|
|
110
|
+
return resolveLazyType(currentToken, functionExpression);
|
|
111
|
+
}
|
|
112
|
+
exports.getTypeFromDottedGetExpression = getTypeFromDottedGetExpression;
|
|
113
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/types/helpers.ts"],"names":[],"mappings":";;;AAAA,uDAAsG;AAGtG,yCAAsC;AAEtC,2DAAwD;AACxD,6CAA6C;AAC7C,6CAA0C;AAE1C;;;;;;;;GAQG;AACH,SAAgB,yBAAyB,CAAC,IAAoB,EAAE,kBAAsC;IAClG,IAAI,UAAU,GAAK,IAAI,CAAC,MAAc,CAAC,IAAc,CAAC;IACtD,IAAI,UAAU,EAAE;QACZ,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC;QACrG,IAAI,IAAA,2BAAc,EAAC,gBAAgB,CAAC,EAAE;YAClC,OAAO,gBAAgB,CAAC,UAAU,CAAC;SACtC;QACD,IAAI,gBAAgB,EAAE;YAClB,mGAAmG;YACnG,OAAO,gBAAgB,CAAC;SAC3B;QACD,OAAO,IAAI,mBAAQ,CAAC,CAAC,OAAqB,EAAE,EAAE;;YAC1C,IAAI,UAAmB,CAAC;YACxB,IAAI,IAAA,sBAAS,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,EAAE;gBAC1B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;gBAC1B,UAAU,GAAG,MAAA,IAAI,CAAC,sBAAsB,CAAC,UAAU,EAAE,kBAAkB,EAAE,OAAO,CAAC,KAAK,CAAC,0CAAE,IAAI,CAAC;aACjG;iBAAM;gBACH,8CAA8C;gBAC9C,UAAU,GAAG,kBAAkB,CAAC,WAAW,CAAC,aAAa,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;aAC9E;YACD,IAAI,IAAA,2BAAc,EAAC,UAAU,CAAC,EAAE;gBAC5B,OAAO,UAAU,CAAC,UAAU,CAAC;aAChC;YAED,OAAO,UAAU,CAAC;QACtB,CAAC,CAAC,CAAC;KACN;AACL,CAAC;AA3BD,8DA2BC;AAED;;;;;;;;GAQG;AACH,SAAgB,6BAA6B,CAAC,QAA4B,EAAE,kBAAsC;IAC9G,IAAI,YAAY,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;IACpD,MAAM,gBAAgB,GAAG,kBAAkB,CAAC,WAAW,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC;IACpF,IAAI,IAAA,4BAAe,EAAC,gBAAgB,CAAC,EAAE;QACnC,4CAA4C;QAC5C,OAAO,gBAAgB,CAAC;KAC3B;IACD,OAAO,eAAe,CAAC,QAAQ,CAAC,IAAI,EAAE,kBAAkB,CAAC,CAAC;AAC9D,CAAC;AARD,sEAQC;AAED;;;;;;;;GAQG;AACH,SAAgB,wBAAwB,CAAC,MAAqB,EAAE,kBAAsC;IAClG,IAAI,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,OAAO,CAAC,kBAAS,CAAC,cAAc,CAAC,CAAC;IACnE,OAAO,IAAI,mBAAQ,CAAC,CAAC,OAAqB,EAAE,EAAE;;QAC1C,OAAO,IAAI,uBAAU,CAAC,SAAS,EAAE,MAAA,MAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,KAAK,0CAAE,QAAQ,CAAC,SAAS,EAAE,MAAA,kBAAkB,CAAC,aAAa,0CAAE,OAAO,EAAE,CAAC,0CAAE,WAAW,CAAC,CAAC;IACpI,CAAC,CAAC,CAAC;AACP,CAAC;AALD,4DAKC;AAGD,SAAS,eAAe,CAAC,YAAmB,EAAE,kBAAsC;IAChF,OAAO,IAAI,mBAAQ,CAAC,CAAC,OAAqB,EAAE,EAAE;;QAC1C,IAAI,UAAmB,CAAC;QACxB,IAAI,IAAA,sBAAS,EAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,EAAE;YAC1B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAC1B,UAAU,GAAG,MAAA,IAAI,CAAC,sBAAsB,CAAC,YAAY,EAAE,kBAAkB,EAAE,OAAO,CAAC,KAAK,CAAC,0CAAE,IAAI,CAAC;SACnG;aAAM;YACH,8CAA8C;YAC9C,UAAU,GAAG,MAAA,kBAAkB,CAAC,WAAW,CAAC,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,mCAAI,IAAI,qCAAiB,EAAE,CAAC;SAC3G;QACD,OAAO,UAAU,CAAC;IACtB,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;;;;GAQG;AACH,SAAgB,8BAA8B,CAAC,IAAyB,EAAE,kBAAsC;IAC5G,MAAM,YAAY,GAAG,IAAA,6BAAgB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,IAAI,CAAC,MAAM,CAAS,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IAEtF,OAAO,eAAe,CAAC,YAAY,EAAE,kBAAkB,CAAC,CAAC;AAE7D,CAAC;AALD,wEAKC"}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as rokuDeploy from 'roku-deploy';
|
|
2
2
|
import type { Diagnostic, Position, Range } from 'vscode-languageserver';
|
|
3
3
|
import type { BsConfig } from './BsConfig';
|
|
4
|
-
import type { CallableContainer, BsDiagnostic, FileReference, CallableContainerMap, CompilerPlugin, ExpressionInfo, FunctionCall } from './interfaces';
|
|
4
|
+
import type { CallableContainer, BsDiagnostic, FileReference, CallableContainerMap, CompilerPlugin, ExpressionInfo, FunctionCall, CallableParam, TranspileResult } from './interfaces';
|
|
5
5
|
import { BooleanType } from './types/BooleanType';
|
|
6
6
|
import { DoubleType } from './types/DoubleType';
|
|
7
7
|
import { DynamicType } from './types/DynamicType';
|
|
@@ -13,10 +13,11 @@ import { LongIntegerType } from './types/LongIntegerType';
|
|
|
13
13
|
import { ObjectType } from './types/ObjectType';
|
|
14
14
|
import { StringType } from './types/StringType';
|
|
15
15
|
import { VoidType } from './types/VoidType';
|
|
16
|
-
import type { DottedGetExpression, Expression, VariableExpression } from './parser/Expression';
|
|
17
|
-
import type { Token } from './lexer';
|
|
16
|
+
import type { DottedGetExpression, Expression, NamespacedVariableNameExpression, VariableExpression } from './parser/Expression';
|
|
17
|
+
import type { Locatable, Token } from './lexer';
|
|
18
18
|
import { SourceNode } from 'source-map';
|
|
19
|
-
import
|
|
19
|
+
import { SGAttribute } from './parser/SGTypes';
|
|
20
|
+
import { LazyType } from './types/LazyType';
|
|
20
21
|
export declare class Util {
|
|
21
22
|
clearConsole(): void;
|
|
22
23
|
/**
|
|
@@ -36,7 +37,11 @@ export declare class Util {
|
|
|
36
37
|
/**
|
|
37
38
|
* Given a pkg path of any kind, transform it to a roku-specific pkg path (i.e. "pkg:/some/path.brs")
|
|
38
39
|
*/
|
|
39
|
-
|
|
40
|
+
sanitizePkgPath(pkgPath: string): string;
|
|
41
|
+
/**
|
|
42
|
+
* Determine if the given path starts with a protocol
|
|
43
|
+
*/
|
|
44
|
+
startsWithProtocol(path: string): boolean;
|
|
40
45
|
/**
|
|
41
46
|
* Given a path to a file/directory, replace all path separators with the current system's version.
|
|
42
47
|
* @param filePath
|
|
@@ -104,12 +109,11 @@ export declare class Util {
|
|
|
104
109
|
*/
|
|
105
110
|
getLines(text: string): string[];
|
|
106
111
|
/**
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* @param
|
|
110
|
-
* @param targetPath
|
|
112
|
+
* Compute the pkg path for the target relative to the source file's location
|
|
113
|
+
* @param sourcePkgPath The pkgPath of the file that contains the target path
|
|
114
|
+
* @param targetPath a full pkgPath, or a path relative to the containing file
|
|
111
115
|
*/
|
|
112
|
-
getPkgPathFromTarget(
|
|
116
|
+
getPkgPathFromTarget(sourcePkgPath: string, targetPath: string): string;
|
|
113
117
|
/**
|
|
114
118
|
* Compute the relative path from the source file to the target file
|
|
115
119
|
* @param pkgSourcePathAbsolute - the absolute path to the source relative to the package location
|
|
@@ -156,8 +160,9 @@ export declare class Util {
|
|
|
156
160
|
areArraysEqual(arr1: any[], arr2: any[]): boolean;
|
|
157
161
|
/**
|
|
158
162
|
* Given a file path, convert it to a URI string
|
|
163
|
+
* @param srcPath The absolute path to the source file on disk
|
|
159
164
|
*/
|
|
160
|
-
pathToUri(
|
|
165
|
+
pathToUri(srcPath: string): string;
|
|
161
166
|
/**
|
|
162
167
|
* Get the outDir from options, taking into account cwd and absolute outFile paths
|
|
163
168
|
* @param options
|
|
@@ -169,7 +174,8 @@ export declare class Util {
|
|
|
169
174
|
getFilePaths(options: BsConfig): Promise<rokuDeploy.StandardizedFileEntry[]>;
|
|
170
175
|
/**
|
|
171
176
|
* Given a path to a brs file, compute the path to a theoretical d.bs file.
|
|
172
|
-
* Only `.brs` files can have typedef
|
|
177
|
+
* Only `.brs` files can have a typedef, so return undefined for everything else
|
|
178
|
+
* @param brsSrcPath The absolute path to the .brs source file on disk
|
|
173
179
|
*/
|
|
174
180
|
getTypedefPath(brsSrcPath: string): string;
|
|
175
181
|
/**
|
|
@@ -252,6 +258,13 @@ export declare class Util {
|
|
|
252
258
|
* Create a `Range` from two `Position`s
|
|
253
259
|
*/
|
|
254
260
|
createRangeFromPositions(startPosition: Position, endPosition: Position): Range;
|
|
261
|
+
/**
|
|
262
|
+
* Given a list of ranges, create a range that starts with the first non-null lefthand range, and ends with the first non-null
|
|
263
|
+
* righthand range. Returns undefined if none of the items have a range.
|
|
264
|
+
*/
|
|
265
|
+
createBoundingRange(...locatables: Array<{
|
|
266
|
+
range?: Range;
|
|
267
|
+
}>): Range;
|
|
255
268
|
/**
|
|
256
269
|
* Create a `Position` object. Prefer this over `Position.create` for performance reasons
|
|
257
270
|
*/
|
|
@@ -266,7 +279,7 @@ export declare class Util {
|
|
|
266
279
|
/**
|
|
267
280
|
* Convert a token into a BscType
|
|
268
281
|
*/
|
|
269
|
-
tokenToBscType(token: Token, allowCustomType?: boolean): DynamicType |
|
|
282
|
+
tokenToBscType(token: Token, allowCustomType?: boolean, currentNamespaceName?: NamespacedVariableNameExpression): DynamicType | FloatType | FunctionType | IntegerType | LongIntegerType | StringType | BooleanType | LazyType | ObjectType | DoubleType | InvalidType | VoidType;
|
|
270
283
|
/**
|
|
271
284
|
* Get the extension for the given file path. Basically the part after the final dot, except for
|
|
272
285
|
* `d.bs` which is treated as single extension
|
|
@@ -288,12 +301,20 @@ export declare class Util {
|
|
|
288
301
|
*/
|
|
289
302
|
simpleMap(source: string, src: string): SourceNode;
|
|
290
303
|
/**
|
|
291
|
-
* Creates a new SGAttribute object, but keeps the existing Range references (since those
|
|
304
|
+
* Creates a new SGAttribute object, but keeps the existing Range references (since those should be immutable)
|
|
292
305
|
*/
|
|
293
306
|
cloneSGAttribute(attr: SGAttribute, value: string): SGAttribute;
|
|
294
307
|
/**
|
|
295
|
-
*
|
|
308
|
+
* Shorthand for creating a new source node
|
|
296
309
|
*/
|
|
310
|
+
sourceNode(source: string, locatable: {
|
|
311
|
+
range: Range;
|
|
312
|
+
}, code: string | SourceNode | TranspileResult): SourceNode | undefined;
|
|
313
|
+
/**
|
|
314
|
+
* Remove leading simple protocols from a path (if present)
|
|
315
|
+
*/
|
|
316
|
+
removeProtocol(pkgPath: string): string;
|
|
317
|
+
standardizePath(thePath: string): string;
|
|
297
318
|
copyBslibToStaging(stagingDir: string): Promise<void>;
|
|
298
319
|
/**
|
|
299
320
|
* Given a Diagnostic or BsDiagnostic, return a copy of the diagnostic
|
|
@@ -310,11 +331,45 @@ export declare class Util {
|
|
|
310
331
|
source: string;
|
|
311
332
|
};
|
|
312
333
|
/**
|
|
313
|
-
*
|
|
334
|
+
* Gets the minimum and maximum number of allowed params
|
|
335
|
+
* @param params The list of callable parameters to check
|
|
336
|
+
* @returns the minimum and maximum number of allowed params
|
|
337
|
+
*/
|
|
338
|
+
getMinMaxParamCount(params: CallableParam[]): MinMax;
|
|
339
|
+
/**
|
|
340
|
+
* Gets the minimum and maximum number of allowed params for ALL functions with the name of the function call
|
|
341
|
+
* @param callablesByLowerName The map of callable containers
|
|
342
|
+
* @param expCall function call expression to use for the name
|
|
343
|
+
* @returns the minimum and maximum number of allowed params
|
|
344
|
+
*/
|
|
345
|
+
getMinMaxParamCountByFunctionCall(callablesByLowerName: CallableContainerMap, expCall: FunctionCall): MinMax;
|
|
346
|
+
/**
|
|
347
|
+
* Finds the array of callables from a container map, based on the name of the function call
|
|
314
348
|
* If the callable was called in a function in a namespace, functions in that namespace are preferred
|
|
349
|
+
* @param callablesByLowerName The map of callable containers
|
|
350
|
+
* @param expCall function call expression to use for the name
|
|
315
351
|
* @return an array with callable containers - could be empty if nothing was found
|
|
316
352
|
*/
|
|
317
|
-
|
|
353
|
+
getCallableContainersByName(callablesByLowerName: CallableContainerMap, expCall: FunctionCall): CallableContainer[];
|
|
354
|
+
/**
|
|
355
|
+
* Sort an array of objects that have a Range
|
|
356
|
+
*/
|
|
357
|
+
sortByRange(locatables: Locatable[]): Locatable[];
|
|
358
|
+
/**
|
|
359
|
+
* Split the given text and return ranges for each chunk.
|
|
360
|
+
* Only works for single-line strings
|
|
361
|
+
*/
|
|
362
|
+
splitGetRange(separator: string, text: string, range: Range): {
|
|
363
|
+
text: string;
|
|
364
|
+
range: Range;
|
|
365
|
+
}[];
|
|
366
|
+
/**
|
|
367
|
+
* Finds a callable from a container map based on the name AND number of arguments
|
|
368
|
+
* If the callable was called in a function in a namespace, functions in that namespace are preferred
|
|
369
|
+
* The first callable that matches the name AND will accept the number of arguments given is returned
|
|
370
|
+
* @return a callable containers that matches the call
|
|
371
|
+
*/
|
|
372
|
+
getCallableContainerByFunctionCall(callablesByLowerName: CallableContainerMap, expCall: FunctionCall): CallableContainer;
|
|
318
373
|
}
|
|
319
374
|
/**
|
|
320
375
|
* A tagged template literal function for standardizing the path. This has to be defined as standalone function since it's a tagged template literal function,
|
|
@@ -323,3 +378,8 @@ export declare class Util {
|
|
|
323
378
|
export declare function standardizePath(stringParts: any, ...expressions: any[]): string;
|
|
324
379
|
export declare let util: Util;
|
|
325
380
|
export default util;
|
|
381
|
+
export interface MinMax {
|
|
382
|
+
min: number;
|
|
383
|
+
max: number;
|
|
384
|
+
}
|
|
385
|
+
export declare const MAX_PARAM_COUNT = 32;
|