brighterscript 0.65.1 → 0.66.0-alpha.1
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 +14 -0
- package/README.md +8 -0
- package/dist/BsConfig.d.ts +5 -11
- package/dist/CacheVerifier.d.ts +8 -0
- package/dist/CacheVerifier.js +20 -0
- package/dist/CacheVerifier.js.map +1 -0
- package/dist/DiagnosticMessages.d.ts +9 -4
- package/dist/DiagnosticMessages.js +8 -3
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/FunctionScope.d.ts +1 -0
- package/dist/FunctionScope.js +3 -0
- package/dist/FunctionScope.js.map +1 -1
- package/dist/PluginInterface.d.ts +0 -4
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +6 -39
- package/dist/Program.js +94 -68
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +4 -0
- package/dist/ProgramBuilder.js +33 -13
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +1 -5
- package/dist/Scope.js +53 -37
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +44 -6
- package/dist/SymbolTable.js +154 -26
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.js +11 -12
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/creators.d.ts +16 -6
- package/dist/astUtils/creators.js +39 -16
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +46 -37
- package/dist/astUtils/reflection.js +145 -147
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +1 -6
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +4 -11
- package/dist/astUtils/visitors.js +0 -7
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +8 -6
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +9 -9
- package/dist/astUtils/xml.js +6 -6
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +2 -3
- package/dist/bscPlugin/BscPlugin.js +6 -2
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +2 -2
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.js +71 -59
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +110 -10
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +6 -5
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +11 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +53 -0
- package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +4 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +37 -16
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
- package/dist/bscPlugin/validation/ProgramValidator.d.ts +3 -3
- package/dist/bscPlugin/validation/ProgramValidator.js +6 -6
- package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +1 -0
- package/dist/bscPlugin/validation/ScopeValidator.js +72 -18
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/XmlFileValidator.js +9 -9
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +9 -10
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +8 -10
- package/dist/files/BrsFile.js +72 -52
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +57 -15
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +19 -19
- package/dist/files/XmlFile.js +24 -42
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +70 -17
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +8 -11
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/globalCallables.js +2 -1
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +107 -28
- package/dist/interfaces.js +13 -0
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +2 -0
- package/dist/lexer/TokenKind.js +5 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +78 -1
- package/dist/parser/AstNode.js +80 -1
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/Expression.d.ts +87 -53
- package/dist/parser/Expression.js +243 -139
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +10 -7
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +9 -5
- package/dist/parser/Parser.js +125 -78
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.d.ts +2 -0
- package/dist/parser/Parser.spec.js +117 -5
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +42 -4
- package/dist/parser/SGParser.js +191 -195
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +13 -10
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +279 -51
- package/dist/parser/SGTypes.js +562 -185
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +88 -70
- package/dist/parser/Statement.js +212 -136
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +1 -1
- package/dist/parser/TranspileState.js +5 -2
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
- package/dist/parser/tests/expression/TypeExpression.spec.js +127 -0
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
- package/dist/types/ArrayType.d.ts +6 -4
- package/dist/types/ArrayType.js +30 -22
- 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.d.ts +7 -4
- package/dist/types/BooleanType.js +13 -8
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +9 -3
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +25 -2
- package/dist/types/BscType.js +64 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/BscTypeKind.d.ts +22 -0
- package/dist/types/BscTypeKind.js +27 -0
- package/dist/types/BscTypeKind.js.map +1 -0
- package/dist/types/ClassType.d.ts +11 -0
- package/dist/types/ClassType.js +31 -0
- package/dist/types/ClassType.js.map +1 -0
- package/dist/types/ClassType.spec.d.ts +1 -0
- package/dist/types/ClassType.spec.js +75 -0
- package/dist/types/ClassType.spec.js.map +1 -0
- package/dist/types/DoubleType.d.ts +7 -4
- package/dist/types/DoubleType.js +16 -20
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +11 -3
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +9 -3
- package/dist/types/DynamicType.js +16 -2
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +15 -4
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/EnumType.d.ts +22 -0
- package/dist/types/EnumType.js +59 -0
- package/dist/types/EnumType.js.map +1 -0
- package/dist/types/EnumType.spec.d.ts +1 -0
- package/dist/types/EnumType.spec.js +33 -0
- package/dist/types/EnumType.spec.js.map +1 -0
- package/dist/types/FloatType.d.ts +7 -4
- package/dist/types/FloatType.js +16 -20
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +3 -3
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +6 -4
- package/dist/types/FunctionType.js +22 -19
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +5 -5
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/InheritableType.d.ts +25 -0
- package/dist/types/InheritableType.js +88 -0
- package/dist/types/InheritableType.js.map +1 -0
- package/dist/types/IntegerType.d.ts +7 -4
- package/dist/types/IntegerType.js +16 -20
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +7 -3
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.d.ts +10 -10
- package/dist/types/InterfaceType.js +24 -45
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +59 -45
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/InvalidType.d.ts +6 -4
- package/dist/types/InvalidType.js +12 -8
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +7 -3
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +7 -4
- package/dist/types/LongIntegerType.js +16 -20
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +9 -3
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/NamespaceType.d.ts +11 -0
- package/dist/types/NamespaceType.js +25 -0
- package/dist/types/NamespaceType.js.map +1 -0
- package/dist/types/ObjectType.d.ts +8 -4
- package/dist/types/ObjectType.js +26 -7
- 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/ReferenceType.d.ts +51 -0
- package/dist/types/ReferenceType.js +274 -0
- package/dist/types/ReferenceType.js.map +1 -0
- package/dist/types/ReferenceType.spec.d.ts +1 -0
- package/dist/types/ReferenceType.spec.js +122 -0
- package/dist/types/ReferenceType.spec.js.map +1 -0
- package/dist/types/StringType.d.ts +10 -4
- package/dist/types/StringType.js +16 -8
- 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.d.ts +6 -3
- package/dist/types/UninitializedType.js +14 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/UnionType.d.ts +18 -0
- package/dist/types/UnionType.js +91 -0
- package/dist/types/UnionType.js.map +1 -0
- package/dist/types/UnionType.spec.d.ts +1 -0
- package/dist/types/UnionType.spec.js +103 -0
- package/dist/types/UnionType.spec.js.map +1 -0
- package/dist/types/VoidType.d.ts +7 -4
- package/dist/types/VoidType.js +13 -8
- 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/helper.spec.d.ts +1 -0
- package/dist/types/helper.spec.js +130 -0
- package/dist/types/helper.spec.js.map +1 -0
- package/dist/types/helpers.d.ts +19 -0
- package/dist/types/helpers.js +131 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/types/index.d.ts +22 -0
- package/dist/types/index.js +39 -0
- package/dist/types/index.js.map +1 -0
- package/dist/util.d.ts +9 -8
- package/dist/util.js +78 -32
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +0 -4
- package/dist/validators/ClassValidator.js +6 -30
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +2 -1
- package/dist/types/CustomType.d.ts +0 -9
- package/dist/types/CustomType.js +0 -32
- package/dist/types/CustomType.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.
|
|
3
|
+
exports.TypeCastExpression = exports.TypeExpression = exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = void 0;
|
|
4
4
|
const TokenKind_1 = require("../lexer/TokenKind");
|
|
5
5
|
const util_1 = require("../util");
|
|
6
6
|
const Parser_1 = require("./Parser");
|
|
@@ -8,18 +8,24 @@ const fileUrl = require("file-url");
|
|
|
8
8
|
const visitors_1 = require("../astUtils/visitors");
|
|
9
9
|
const visitors_2 = require("../astUtils/visitors");
|
|
10
10
|
const reflection_1 = require("../astUtils/reflection");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const interfaces_1 = require("../interfaces");
|
|
12
|
+
const SymbolTable_1 = require("../SymbolTable");
|
|
13
13
|
const FunctionType_1 = require("../types/FunctionType");
|
|
14
14
|
const AstNode_1 = require("./AstNode");
|
|
15
|
-
const
|
|
15
|
+
const SymbolTable_2 = require("../SymbolTable");
|
|
16
16
|
const source_map_1 = require("source-map");
|
|
17
|
+
const StringType_1 = require("../types/StringType");
|
|
18
|
+
const DynamicType_1 = require("../types/DynamicType");
|
|
19
|
+
const VoidType_1 = require("../types/VoidType");
|
|
20
|
+
const ReferenceType_1 = require("../types/ReferenceType");
|
|
21
|
+
const UnionType_1 = require("../types/UnionType");
|
|
17
22
|
class BinaryExpression extends AstNode_1.Expression {
|
|
18
23
|
constructor(left, operator, right) {
|
|
19
24
|
super();
|
|
20
25
|
this.left = left;
|
|
21
26
|
this.operator = operator;
|
|
22
27
|
this.right = right;
|
|
28
|
+
this.kind = AstNode_1.AstNodeKind.BinaryExpression;
|
|
23
29
|
this.range = util_1.default.createRangeFromPositions(this.left.range.start, this.right.range.end);
|
|
24
30
|
}
|
|
25
31
|
transpile(state) {
|
|
@@ -37,6 +43,19 @@ class BinaryExpression extends AstNode_1.Expression {
|
|
|
37
43
|
(0, visitors_2.walk)(this, 'right', visitor, options);
|
|
38
44
|
}
|
|
39
45
|
}
|
|
46
|
+
getType(options) {
|
|
47
|
+
const operatorKind = this.operator.kind;
|
|
48
|
+
if (options.flags & SymbolTable_1.SymbolTypeFlag.typetime) {
|
|
49
|
+
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
50
|
+
switch (operatorKind) {
|
|
51
|
+
case TokenKind_1.TokenKind.Or:
|
|
52
|
+
return new UnionType_1.UnionType([this.left.getType(options), this.right.getType(options)]);
|
|
53
|
+
//TODO: Intersection Types?, eg. case TokenKind.And:
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//TODO: figure out result type on +, *, or, and, etc!
|
|
57
|
+
return DynamicType_1.DynamicType.instance;
|
|
58
|
+
}
|
|
40
59
|
}
|
|
41
60
|
exports.BinaryExpression = BinaryExpression;
|
|
42
61
|
class CallExpression extends AstNode_1.Expression {
|
|
@@ -50,16 +69,9 @@ class CallExpression extends AstNode_1.Expression {
|
|
|
50
69
|
this.openingParen = openingParen;
|
|
51
70
|
this.closingParen = closingParen;
|
|
52
71
|
this.args = args;
|
|
72
|
+
this.kind = AstNode_1.AstNodeKind.CallExpression;
|
|
53
73
|
this.range = util_1.default.createBoundingRange(this.callee, this.openingParen, ...args, this.closingParen);
|
|
54
74
|
}
|
|
55
|
-
/**
|
|
56
|
-
* Get the name of the wrapping namespace (if it exists)
|
|
57
|
-
* @deprecated use `.findAncestor(isNamespaceStatement)` instead.
|
|
58
|
-
*/
|
|
59
|
-
get namespaceName() {
|
|
60
|
-
var _a;
|
|
61
|
-
return (_a = this.findAncestor(reflection_1.isNamespaceStatement)) === null || _a === void 0 ? void 0 : _a.nameExpression;
|
|
62
|
-
}
|
|
63
75
|
transpile(state, nameOverride) {
|
|
64
76
|
let result = [];
|
|
65
77
|
//transpile the name
|
|
@@ -89,11 +101,25 @@ class CallExpression extends AstNode_1.Expression {
|
|
|
89
101
|
(0, visitors_2.walkArray)(this.args, visitor, options, this);
|
|
90
102
|
}
|
|
91
103
|
}
|
|
104
|
+
getType(options) {
|
|
105
|
+
var _a;
|
|
106
|
+
const calleeType = this.callee.getType(options);
|
|
107
|
+
if ((0, reflection_1.isNewExpression)(this.parent)) {
|
|
108
|
+
return calleeType;
|
|
109
|
+
}
|
|
110
|
+
if ((0, reflection_1.isFunctionType)(calleeType) && (!(0, reflection_1.isReferenceType)(calleeType.returnType) || calleeType.returnType.isResolvable())) {
|
|
111
|
+
return calleeType.returnType;
|
|
112
|
+
}
|
|
113
|
+
if (!(0, reflection_1.isReferenceType)(calleeType) && ((_a = calleeType.returnType) === null || _a === void 0 ? void 0 : _a.isResolvable())) {
|
|
114
|
+
return calleeType.returnType;
|
|
115
|
+
}
|
|
116
|
+
return new ReferenceType_1.TypePropertyReferenceType(calleeType, 'returnType');
|
|
117
|
+
}
|
|
92
118
|
}
|
|
93
119
|
exports.CallExpression = CallExpression;
|
|
94
120
|
CallExpression.MaximumArguments = 32;
|
|
95
121
|
class FunctionExpression extends AstNode_1.Expression {
|
|
96
|
-
constructor(parameters, body, functionType, end, leftParen, rightParen, asToken,
|
|
122
|
+
constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeExpression) {
|
|
97
123
|
super();
|
|
98
124
|
this.parameters = parameters;
|
|
99
125
|
this.body = body;
|
|
@@ -102,63 +128,25 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
102
128
|
this.leftParen = leftParen;
|
|
103
129
|
this.rightParen = rightParen;
|
|
104
130
|
this.asToken = asToken;
|
|
105
|
-
this.
|
|
131
|
+
this.returnTypeExpression = returnTypeExpression;
|
|
132
|
+
this.kind = AstNode_1.AstNodeKind.FunctionExpression;
|
|
106
133
|
/**
|
|
107
134
|
* The list of function calls that are declared within this function scope. This excludes CallExpressions
|
|
108
135
|
* declared in child functions
|
|
109
136
|
*/
|
|
110
137
|
this.callExpressions = [];
|
|
111
|
-
if (this.returnTypeToken) {
|
|
112
|
-
this.returnType = util_1.default.tokenToBscType(this.returnTypeToken);
|
|
113
|
-
}
|
|
114
|
-
else if (this.functionType.text.toLowerCase() === 'sub') {
|
|
115
|
-
this.returnType = new VoidType_1.VoidType();
|
|
116
|
-
}
|
|
117
|
-
else {
|
|
118
|
-
this.returnType = DynamicType_1.DynamicType.instance;
|
|
119
|
-
}
|
|
120
138
|
//if there's a body, and it doesn't have a SymbolTable, assign one
|
|
121
139
|
if (this.body && !this.body.symbolTable) {
|
|
122
|
-
this.body.symbolTable = new
|
|
140
|
+
this.body.symbolTable = new SymbolTable_2.SymbolTable(`Function Body`);
|
|
123
141
|
}
|
|
124
|
-
this.symbolTable = new
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Get the name of the wrapping namespace (if it exists)
|
|
128
|
-
* @deprecated use `.findAncestor(isNamespaceStatement)` instead.
|
|
129
|
-
*/
|
|
130
|
-
get namespaceName() {
|
|
131
|
-
var _a;
|
|
132
|
-
return (_a = this.findAncestor(reflection_1.isNamespaceStatement)) === null || _a === void 0 ? void 0 : _a.nameExpression;
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Get the name of the wrapping namespace (if it exists)
|
|
136
|
-
* @deprecated use `.findAncestor(isFunctionExpression)` instead.
|
|
137
|
-
*/
|
|
138
|
-
get parentFunction() {
|
|
139
|
-
return this.findAncestor(reflection_1.isFunctionExpression);
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* A list of all child functions declared directly within this function
|
|
143
|
-
* @deprecated use `.walk(createVisitor({ FunctionExpression: ()=>{}), { walkMode: WalkMode.visitAllRecursive })` instead
|
|
144
|
-
*/
|
|
145
|
-
get childFunctionExpressions() {
|
|
146
|
-
const expressions = [];
|
|
147
|
-
this.walk((0, visitors_1.createVisitor)({
|
|
148
|
-
FunctionExpression: (expression) => {
|
|
149
|
-
expressions.push(expression);
|
|
150
|
-
}
|
|
151
|
-
}), {
|
|
152
|
-
walkMode: visitors_1.WalkMode.visitAllRecursive
|
|
153
|
-
});
|
|
154
|
-
return expressions;
|
|
142
|
+
this.symbolTable = new SymbolTable_2.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
|
|
155
143
|
}
|
|
156
144
|
/**
|
|
157
145
|
* The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
|
|
158
146
|
* and ending with the last n' in 'end function' or 'b' in 'end sub'
|
|
159
147
|
*/
|
|
160
148
|
get range() {
|
|
161
|
-
return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...this.parameters, this.rightParen, this.asToken, this.
|
|
149
|
+
return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...this.parameters, this.rightParen, this.asToken, this.returnTypeExpression, this.end);
|
|
162
150
|
}
|
|
163
151
|
transpile(state, name, includeBody = true) {
|
|
164
152
|
let results = [];
|
|
@@ -188,7 +176,7 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
188
176
|
//as
|
|
189
177
|
state.transpileToken(this.asToken), ' ',
|
|
190
178
|
//return type
|
|
191
|
-
|
|
179
|
+
...this.returnTypeExpression.transpile(state));
|
|
192
180
|
}
|
|
193
181
|
if (includeBody) {
|
|
194
182
|
state.lineage.unshift(this);
|
|
@@ -202,7 +190,7 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
202
190
|
return results;
|
|
203
191
|
}
|
|
204
192
|
getTypedef(state) {
|
|
205
|
-
var _a, _b, _c, _d, _e
|
|
193
|
+
var _a, _b, _c, _d, _e;
|
|
206
194
|
let results = [
|
|
207
195
|
new source_map_1.SourceNode(1, 0, null, [
|
|
208
196
|
//'function'|'sub'
|
|
@@ -222,7 +210,7 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
222
210
|
//as <ReturnType>
|
|
223
211
|
...(this.asToken ? [
|
|
224
212
|
' as ',
|
|
225
|
-
|
|
213
|
+
...this.returnTypeExpression.getTypedef(state)
|
|
226
214
|
] : []),
|
|
227
215
|
'\n',
|
|
228
216
|
state.indent(),
|
|
@@ -235,40 +223,50 @@ class FunctionExpression extends AstNode_1.Expression {
|
|
|
235
223
|
walk(visitor, options) {
|
|
236
224
|
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
237
225
|
(0, visitors_2.walkArray)(this.parameters, visitor, options, this);
|
|
226
|
+
(0, visitors_2.walk)(this, 'returnTypeExpression', visitor, options);
|
|
238
227
|
//This is the core of full-program walking...it allows us to step into sub functions
|
|
239
228
|
if (options.walkMode & visitors_2.InternalWalkMode.recurseChildFunctions) {
|
|
240
229
|
(0, visitors_2.walk)(this, 'body', visitor, options);
|
|
241
230
|
}
|
|
242
231
|
}
|
|
243
232
|
}
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
233
|
+
getType(options) {
|
|
234
|
+
var _a;
|
|
235
|
+
//if there's a defined return type, use that
|
|
236
|
+
let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(options);
|
|
237
|
+
const isSub = this.functionType.kind === TokenKind_1.TokenKind.Sub;
|
|
238
|
+
//if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
|
|
239
|
+
if (!returnType) {
|
|
240
|
+
returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
|
|
241
|
+
}
|
|
242
|
+
const resultType = new FunctionType_1.FunctionType(returnType);
|
|
243
|
+
resultType.isSub = isSub;
|
|
247
244
|
for (let param of this.parameters) {
|
|
248
|
-
|
|
245
|
+
resultType.addParameter(param.name.text, param.getType(options), !!param.defaultValue);
|
|
249
246
|
}
|
|
250
|
-
return
|
|
247
|
+
return resultType;
|
|
251
248
|
}
|
|
252
249
|
}
|
|
253
250
|
exports.FunctionExpression = FunctionExpression;
|
|
254
251
|
class FunctionParameterExpression extends AstNode_1.Expression {
|
|
255
|
-
constructor(name,
|
|
252
|
+
constructor(name, equalToken, defaultValue, asToken, typeExpression) {
|
|
256
253
|
super();
|
|
257
254
|
this.name = name;
|
|
258
|
-
this.
|
|
255
|
+
this.equalToken = equalToken;
|
|
259
256
|
this.defaultValue = defaultValue;
|
|
260
257
|
this.asToken = asToken;
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
258
|
+
this.typeExpression = typeExpression;
|
|
259
|
+
this.kind = AstNode_1.AstNodeKind.FunctionParameterExpression;
|
|
260
|
+
}
|
|
261
|
+
getType(options) {
|
|
262
|
+
var _a, _b, _c, _d;
|
|
263
|
+
return (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.typetime }))) !== null && _b !== void 0 ? _b : (_c = this.defaultValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.runtime }))) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
|
|
267
264
|
}
|
|
268
265
|
get range() {
|
|
269
|
-
return util_1.default.createBoundingRange(this.name, this.asToken, this.
|
|
266
|
+
return util_1.default.createBoundingRange(this.name, this.asToken, this.typeExpression, this.defaultValue);
|
|
270
267
|
}
|
|
271
268
|
transpile(state) {
|
|
269
|
+
var _a, _b;
|
|
272
270
|
let result = [
|
|
273
271
|
//name
|
|
274
272
|
state.transpileToken(this.name)
|
|
@@ -283,12 +281,12 @@ class FunctionParameterExpression extends AstNode_1.Expression {
|
|
|
283
281
|
result.push(' ');
|
|
284
282
|
result.push(state.transpileToken(this.asToken));
|
|
285
283
|
result.push(' ');
|
|
286
|
-
result.push(
|
|
284
|
+
result.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []));
|
|
287
285
|
}
|
|
288
286
|
return result;
|
|
289
287
|
}
|
|
290
288
|
getTypedef(state) {
|
|
291
|
-
var _a;
|
|
289
|
+
var _a, _b;
|
|
292
290
|
return [
|
|
293
291
|
//name
|
|
294
292
|
this.name.text,
|
|
@@ -300,63 +298,19 @@ class FunctionParameterExpression extends AstNode_1.Expression {
|
|
|
300
298
|
//type declaration
|
|
301
299
|
...(this.asToken ? [
|
|
302
300
|
' as ',
|
|
303
|
-
(_a = this.
|
|
301
|
+
...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getTypedef(state)) !== null && _b !== void 0 ? _b : [''])
|
|
304
302
|
] : [])
|
|
305
303
|
];
|
|
306
304
|
}
|
|
307
305
|
walk(visitor, options) {
|
|
308
306
|
// eslint-disable-next-line no-bitwise
|
|
309
|
-
if (
|
|
307
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
310
308
|
(0, visitors_2.walk)(this, 'defaultValue', visitor, options);
|
|
309
|
+
(0, visitors_2.walk)(this, 'typeExpression', visitor, options);
|
|
311
310
|
}
|
|
312
311
|
}
|
|
313
312
|
}
|
|
314
313
|
exports.FunctionParameterExpression = FunctionParameterExpression;
|
|
315
|
-
class NamespacedVariableNameExpression extends AstNode_1.Expression {
|
|
316
|
-
constructor(
|
|
317
|
-
//if this is a `DottedGetExpression`, it must be comprised only of `VariableExpression`s
|
|
318
|
-
expression) {
|
|
319
|
-
super();
|
|
320
|
-
this.expression = expression;
|
|
321
|
-
this.range = expression.range;
|
|
322
|
-
}
|
|
323
|
-
transpile(state) {
|
|
324
|
-
return [
|
|
325
|
-
state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
|
|
326
|
-
];
|
|
327
|
-
}
|
|
328
|
-
getNameParts() {
|
|
329
|
-
let parts = [];
|
|
330
|
-
if ((0, reflection_1.isVariableExpression)(this.expression)) {
|
|
331
|
-
parts.push(this.expression.name.text);
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
let expr = this.expression;
|
|
335
|
-
parts.push(expr.name.text);
|
|
336
|
-
while ((0, reflection_1.isVariableExpression)(expr) === false) {
|
|
337
|
-
expr = expr.obj;
|
|
338
|
-
parts.unshift(expr.name.text);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return parts;
|
|
342
|
-
}
|
|
343
|
-
getName(parseMode) {
|
|
344
|
-
if (parseMode === Parser_1.ParseMode.BrighterScript) {
|
|
345
|
-
return this.getNameParts().join('.');
|
|
346
|
-
}
|
|
347
|
-
else {
|
|
348
|
-
return this.getNameParts().join('_');
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
walk(visitor, options) {
|
|
352
|
-
var _a;
|
|
353
|
-
(_a = this.expression) === null || _a === void 0 ? void 0 : _a.link();
|
|
354
|
-
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
355
|
-
(0, visitors_2.walk)(this, 'expression', visitor, options);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
|
|
360
314
|
class DottedGetExpression extends AstNode_1.Expression {
|
|
361
315
|
constructor(obj, name,
|
|
362
316
|
/**
|
|
@@ -367,12 +321,15 @@ class DottedGetExpression extends AstNode_1.Expression {
|
|
|
367
321
|
this.obj = obj;
|
|
368
322
|
this.name = name;
|
|
369
323
|
this.dot = dot;
|
|
324
|
+
this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
|
|
370
325
|
this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
|
|
371
326
|
}
|
|
372
327
|
transpile(state) {
|
|
373
328
|
//if the callee starts with a namespace name, transpile the name
|
|
374
329
|
if (state.file.calleeStartsWithNamespace(this)) {
|
|
375
|
-
return
|
|
330
|
+
return [
|
|
331
|
+
state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
|
|
332
|
+
];
|
|
376
333
|
}
|
|
377
334
|
else {
|
|
378
335
|
return [
|
|
@@ -387,6 +344,22 @@ class DottedGetExpression extends AstNode_1.Expression {
|
|
|
387
344
|
(0, visitors_2.walk)(this, 'obj', visitor, options);
|
|
388
345
|
}
|
|
389
346
|
}
|
|
347
|
+
getType(options) {
|
|
348
|
+
var _a, _b, _c, _d, _e, _f;
|
|
349
|
+
const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
|
|
350
|
+
const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.name) === null || _b === void 0 ? void 0 : _b.text, options);
|
|
351
|
+
(_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry((_d = this.name) === null || _d === void 0 ? void 0 : _d.text, result, (_f = (_e = this.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range));
|
|
352
|
+
if (result || options.flags & SymbolTable_1.SymbolTypeFlag.typetime) {
|
|
353
|
+
// All types should be known at typetime
|
|
354
|
+
return result;
|
|
355
|
+
}
|
|
356
|
+
// It is possible at runtime that a value has been added dynamically to an object, or something
|
|
357
|
+
// TODO: maybe have a strict flag on this?
|
|
358
|
+
return DynamicType_1.DynamicType.instance;
|
|
359
|
+
}
|
|
360
|
+
getName(parseMode) {
|
|
361
|
+
return util_1.default.getAllDottedGetPartsAsString(this, parseMode);
|
|
362
|
+
}
|
|
390
363
|
}
|
|
391
364
|
exports.DottedGetExpression = DottedGetExpression;
|
|
392
365
|
class XmlAttributeGetExpression extends AstNode_1.Expression {
|
|
@@ -399,6 +372,7 @@ class XmlAttributeGetExpression extends AstNode_1.Expression {
|
|
|
399
372
|
this.obj = obj;
|
|
400
373
|
this.name = name;
|
|
401
374
|
this.at = at;
|
|
375
|
+
this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
|
|
402
376
|
this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
|
|
403
377
|
}
|
|
404
378
|
transpile(state) {
|
|
@@ -428,6 +402,7 @@ class IndexedGetExpression extends AstNode_1.Expression {
|
|
|
428
402
|
this.openingSquare = openingSquare;
|
|
429
403
|
this.closingSquare = closingSquare;
|
|
430
404
|
this.questionDotToken = questionDotToken;
|
|
405
|
+
this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
|
|
431
406
|
this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.questionDotToken, this.openingSquare, this.index, this.closingSquare);
|
|
432
407
|
}
|
|
433
408
|
transpile(state) {
|
|
@@ -453,6 +428,7 @@ class GroupingExpression extends AstNode_1.Expression {
|
|
|
453
428
|
super();
|
|
454
429
|
this.tokens = tokens;
|
|
455
430
|
this.expression = expression;
|
|
431
|
+
this.kind = AstNode_1.AstNodeKind.GroupingExpression;
|
|
456
432
|
this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
|
|
457
433
|
}
|
|
458
434
|
transpile(state) {
|
|
@@ -467,24 +443,30 @@ class GroupingExpression extends AstNode_1.Expression {
|
|
|
467
443
|
(0, visitors_2.walk)(this, 'expression', visitor, options);
|
|
468
444
|
}
|
|
469
445
|
}
|
|
446
|
+
getType(options) {
|
|
447
|
+
return this.expression.getType(options);
|
|
448
|
+
}
|
|
470
449
|
}
|
|
471
450
|
exports.GroupingExpression = GroupingExpression;
|
|
472
451
|
class LiteralExpression extends AstNode_1.Expression {
|
|
473
452
|
constructor(token) {
|
|
474
453
|
super();
|
|
475
454
|
this.token = token;
|
|
476
|
-
this.
|
|
455
|
+
this.kind = AstNode_1.AstNodeKind.LiteralExpression;
|
|
477
456
|
}
|
|
478
457
|
get range() {
|
|
479
458
|
return this.token.range;
|
|
480
459
|
}
|
|
460
|
+
getType(options) {
|
|
461
|
+
return util_1.default.tokenToBscType(this.token);
|
|
462
|
+
}
|
|
481
463
|
transpile(state) {
|
|
482
464
|
let text;
|
|
483
465
|
if (this.token.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
|
|
484
466
|
//wrap quasis with quotes (and escape inner quotemarks)
|
|
485
467
|
text = `"${this.token.text.replace(/"/g, '""')}"`;
|
|
486
468
|
}
|
|
487
|
-
else if (
|
|
469
|
+
else if (this.token.kind === TokenKind_1.TokenKind.StringLiteral) {
|
|
488
470
|
text = this.token.text;
|
|
489
471
|
//add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
|
|
490
472
|
if (text.endsWith('"') === false) {
|
|
@@ -511,6 +493,7 @@ class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
|
|
|
511
493
|
constructor(token) {
|
|
512
494
|
super();
|
|
513
495
|
this.token = token;
|
|
496
|
+
this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
|
|
514
497
|
this.range = token.range;
|
|
515
498
|
}
|
|
516
499
|
transpile(state) {
|
|
@@ -530,6 +513,7 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
|
|
|
530
513
|
this.open = open;
|
|
531
514
|
this.close = close;
|
|
532
515
|
this.hasSpread = hasSpread;
|
|
516
|
+
this.kind = AstNode_1.AstNodeKind.ArrayLiteralExpression;
|
|
533
517
|
this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
|
|
534
518
|
}
|
|
535
519
|
transpile(state) {
|
|
@@ -583,6 +567,7 @@ class AAMemberExpression extends AstNode_1.Expression {
|
|
|
583
567
|
this.keyToken = keyToken;
|
|
584
568
|
this.colonToken = colonToken;
|
|
585
569
|
this.value = value;
|
|
570
|
+
this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
|
|
586
571
|
this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
|
|
587
572
|
}
|
|
588
573
|
transpile(state) {
|
|
@@ -592,6 +577,9 @@ class AAMemberExpression extends AstNode_1.Expression {
|
|
|
592
577
|
walk(visitor, options) {
|
|
593
578
|
(0, visitors_2.walk)(this, 'value', visitor, options);
|
|
594
579
|
}
|
|
580
|
+
getType(options) {
|
|
581
|
+
return this.value.getType(options);
|
|
582
|
+
}
|
|
595
583
|
}
|
|
596
584
|
exports.AAMemberExpression = AAMemberExpression;
|
|
597
585
|
class AALiteralExpression extends AstNode_1.Expression {
|
|
@@ -600,6 +588,7 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
600
588
|
this.elements = elements;
|
|
601
589
|
this.open = open;
|
|
602
590
|
this.close = close;
|
|
591
|
+
this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
|
|
603
592
|
this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
|
|
604
593
|
}
|
|
605
594
|
transpile(state) {
|
|
@@ -661,6 +650,20 @@ class AALiteralExpression extends AstNode_1.Expression {
|
|
|
661
650
|
(0, visitors_2.walkArray)(this.elements, visitor, options, this);
|
|
662
651
|
}
|
|
663
652
|
}
|
|
653
|
+
getType(options) {
|
|
654
|
+
return super.getType(options);
|
|
655
|
+
// TODO: create an AssocArray type, and populate its members:
|
|
656
|
+
/*
|
|
657
|
+
const resultType = new AssocArrayType();
|
|
658
|
+
for (const element of this.elements) {
|
|
659
|
+
if (isAAMemberExpression(element)) {
|
|
660
|
+
resultType.addMember(element.keyToken.text, element.range, element.getType(options), SymbolTypeFlags.runtime);
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
}
|
|
664
|
+
return resultType;
|
|
665
|
+
*/
|
|
666
|
+
}
|
|
664
667
|
}
|
|
665
668
|
exports.AALiteralExpression = AALiteralExpression;
|
|
666
669
|
class UnaryExpression extends AstNode_1.Expression {
|
|
@@ -668,6 +671,7 @@ class UnaryExpression extends AstNode_1.Expression {
|
|
|
668
671
|
super();
|
|
669
672
|
this.operator = operator;
|
|
670
673
|
this.right = right;
|
|
674
|
+
this.kind = AstNode_1.AstNodeKind.UnaryExpression;
|
|
671
675
|
this.range = util_1.default.createBoundingRange(this.operator, this.right);
|
|
672
676
|
}
|
|
673
677
|
transpile(state) {
|
|
@@ -689,6 +693,7 @@ class VariableExpression extends AstNode_1.Expression {
|
|
|
689
693
|
var _a;
|
|
690
694
|
super();
|
|
691
695
|
this.name = name;
|
|
696
|
+
this.kind = AstNode_1.AstNodeKind.VariableExpression;
|
|
692
697
|
this.range = (_a = this.name) === null || _a === void 0 ? void 0 : _a.range;
|
|
693
698
|
}
|
|
694
699
|
getName(parseMode) {
|
|
@@ -714,21 +719,51 @@ class VariableExpression extends AstNode_1.Expression {
|
|
|
714
719
|
walk(visitor, options) {
|
|
715
720
|
//nothing to walk
|
|
716
721
|
}
|
|
722
|
+
getType(options) {
|
|
723
|
+
var _a;
|
|
724
|
+
let resultType = util_1.default.tokenToBscType(this.name);
|
|
725
|
+
const nameKey = this.name.text;
|
|
726
|
+
if (!resultType) {
|
|
727
|
+
const symbolTable = this.getSymbolTable();
|
|
728
|
+
resultType = symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
|
|
729
|
+
}
|
|
730
|
+
(_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry(nameKey, resultType, this.range));
|
|
731
|
+
return resultType;
|
|
732
|
+
}
|
|
717
733
|
}
|
|
718
734
|
exports.VariableExpression = VariableExpression;
|
|
719
735
|
class SourceLiteralExpression extends AstNode_1.Expression {
|
|
720
736
|
constructor(token) {
|
|
721
737
|
super();
|
|
722
738
|
this.token = token;
|
|
739
|
+
this.kind = AstNode_1.AstNodeKind.SourceLiteralExpression;
|
|
723
740
|
this.range = token === null || token === void 0 ? void 0 : token.range;
|
|
724
741
|
}
|
|
742
|
+
/**
|
|
743
|
+
* Find the index of the function in its parent
|
|
744
|
+
*/
|
|
745
|
+
findFunctionIndex(parentFunction, func) {
|
|
746
|
+
let index = -1;
|
|
747
|
+
parentFunction.findChild((node) => {
|
|
748
|
+
if ((0, reflection_1.isFunctionExpression)(node)) {
|
|
749
|
+
index++;
|
|
750
|
+
if (node === func) {
|
|
751
|
+
return true;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}, {
|
|
755
|
+
walkMode: visitors_1.WalkMode.visitAllRecursive
|
|
756
|
+
});
|
|
757
|
+
return index;
|
|
758
|
+
}
|
|
725
759
|
getFunctionName(state, parseMode) {
|
|
726
760
|
let func = state.file.getFunctionScopeAtPosition(this.token.range.start).func;
|
|
727
761
|
let nameParts = [];
|
|
728
|
-
|
|
729
|
-
|
|
762
|
+
let parentFunction;
|
|
763
|
+
while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
|
|
764
|
+
let index = this.findFunctionIndex(parentFunction, func);
|
|
730
765
|
nameParts.unshift(`anon${index}`);
|
|
731
|
-
func =
|
|
766
|
+
func = parentFunction;
|
|
732
767
|
}
|
|
733
768
|
//get the index of this function in its parent
|
|
734
769
|
nameParts.unshift(func.functionStatement.getName(parseMode));
|
|
@@ -791,6 +826,7 @@ class NewExpression extends AstNode_1.Expression {
|
|
|
791
826
|
super();
|
|
792
827
|
this.newKeyword = newKeyword;
|
|
793
828
|
this.call = call;
|
|
829
|
+
this.kind = AstNode_1.AstNodeKind.NewExpression;
|
|
794
830
|
this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
|
|
795
831
|
}
|
|
796
832
|
/**
|
|
@@ -798,7 +834,7 @@ class NewExpression extends AstNode_1.Expression {
|
|
|
798
834
|
*/
|
|
799
835
|
get className() {
|
|
800
836
|
//the parser guarantees the callee of a new statement's call object will be
|
|
801
|
-
//a
|
|
837
|
+
//either a VariableExpression or a DottedGet
|
|
802
838
|
return this.call.callee;
|
|
803
839
|
}
|
|
804
840
|
transpile(state) {
|
|
@@ -814,6 +850,9 @@ class NewExpression extends AstNode_1.Expression {
|
|
|
814
850
|
(0, visitors_2.walk)(this, 'call', visitor, options);
|
|
815
851
|
}
|
|
816
852
|
}
|
|
853
|
+
getType(options) {
|
|
854
|
+
return this.call.getType(options);
|
|
855
|
+
}
|
|
817
856
|
}
|
|
818
857
|
exports.NewExpression = NewExpression;
|
|
819
858
|
class CallfuncExpression extends AstNode_1.Expression {
|
|
@@ -825,16 +864,9 @@ class CallfuncExpression extends AstNode_1.Expression {
|
|
|
825
864
|
this.openingParen = openingParen;
|
|
826
865
|
this.args = args;
|
|
827
866
|
this.closingParen = closingParen;
|
|
867
|
+
this.kind = AstNode_1.AstNodeKind.CallfuncExpression;
|
|
828
868
|
this.range = util_1.default.createBoundingRange(callee, operator, methodName, openingParen, ...args, closingParen);
|
|
829
869
|
}
|
|
830
|
-
/**
|
|
831
|
-
* Get the name of the wrapping namespace (if it exists)
|
|
832
|
-
* @deprecated use `.findAncestor(isNamespaceStatement)` instead.
|
|
833
|
-
*/
|
|
834
|
-
get namespaceName() {
|
|
835
|
-
var _a;
|
|
836
|
-
return (_a = this.findAncestor(reflection_1.isNamespaceStatement)) === null || _a === void 0 ? void 0 : _a.nameExpression;
|
|
837
|
-
}
|
|
838
870
|
transpile(state) {
|
|
839
871
|
let result = [];
|
|
840
872
|
result.push(...this.callee.transpile(state), state.sourceNode(this.operator, '.callfunc'), state.transpileToken(this.openingParen),
|
|
@@ -864,6 +896,9 @@ class CallfuncExpression extends AstNode_1.Expression {
|
|
|
864
896
|
(0, visitors_2.walkArray)(this.args, visitor, options, this);
|
|
865
897
|
}
|
|
866
898
|
}
|
|
899
|
+
getType(options) {
|
|
900
|
+
return this.callee.getType(options);
|
|
901
|
+
}
|
|
867
902
|
}
|
|
868
903
|
exports.CallfuncExpression = CallfuncExpression;
|
|
869
904
|
/**
|
|
@@ -874,6 +909,7 @@ class TemplateStringQuasiExpression extends AstNode_1.Expression {
|
|
|
874
909
|
constructor(expressions) {
|
|
875
910
|
super();
|
|
876
911
|
this.expressions = expressions;
|
|
912
|
+
this.kind = AstNode_1.AstNodeKind.TemplateStringQuasiExpression;
|
|
877
913
|
this.range = util_1.default.createBoundingRange(...expressions);
|
|
878
914
|
}
|
|
879
915
|
transpile(state, skipEmptyStrings = true) {
|
|
@@ -904,8 +940,12 @@ class TemplateStringExpression extends AstNode_1.Expression {
|
|
|
904
940
|
this.quasis = quasis;
|
|
905
941
|
this.expressions = expressions;
|
|
906
942
|
this.closingBacktick = closingBacktick;
|
|
943
|
+
this.kind = AstNode_1.AstNodeKind.TemplateStringExpression;
|
|
907
944
|
this.range = util_1.default.createBoundingRange(openingBacktick, quasis[0], quasis[quasis.length - 1], closingBacktick);
|
|
908
945
|
}
|
|
946
|
+
getType(options) {
|
|
947
|
+
return StringType_1.StringType.instance;
|
|
948
|
+
}
|
|
909
949
|
transpile(state) {
|
|
910
950
|
if (this.quasis.length === 1 && this.expressions.length === 0) {
|
|
911
951
|
return this.quasis[0].transpile(state);
|
|
@@ -929,7 +969,7 @@ class TemplateStringExpression extends AstNode_1.Expression {
|
|
|
929
969
|
if (expression) {
|
|
930
970
|
//skip the toString wrapper around certain expressions
|
|
931
971
|
if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
|
|
932
|
-
((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.
|
|
972
|
+
((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.getType()))) {
|
|
933
973
|
add(...expression.transpile(state));
|
|
934
974
|
//wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
|
|
935
975
|
}
|
|
@@ -964,6 +1004,7 @@ class TaggedTemplateStringExpression extends AstNode_1.Expression {
|
|
|
964
1004
|
this.quasis = quasis;
|
|
965
1005
|
this.expressions = expressions;
|
|
966
1006
|
this.closingBacktick = closingBacktick;
|
|
1007
|
+
this.kind = AstNode_1.AstNodeKind.TaggedTemplateStringExpression;
|
|
967
1008
|
this.range = util_1.default.createBoundingRange(tagName, openingBacktick, quasis[0], quasis[quasis.length - 1], closingBacktick);
|
|
968
1009
|
}
|
|
969
1010
|
transpile(state) {
|
|
@@ -1009,6 +1050,7 @@ class AnnotationExpression extends AstNode_1.Expression {
|
|
|
1009
1050
|
super();
|
|
1010
1051
|
this.atToken = atToken;
|
|
1011
1052
|
this.nameToken = nameToken;
|
|
1053
|
+
this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
|
|
1012
1054
|
this.name = nameToken.text;
|
|
1013
1055
|
this.range = util_1.default.createBoundingRange(atToken, nameToken);
|
|
1014
1056
|
}
|
|
@@ -1046,6 +1088,7 @@ class TernaryExpression extends AstNode_1.Expression {
|
|
|
1046
1088
|
this.consequent = consequent;
|
|
1047
1089
|
this.colonToken = colonToken;
|
|
1048
1090
|
this.alternate = alternate;
|
|
1091
|
+
this.kind = AstNode_1.AstNodeKind.TernaryExpression;
|
|
1049
1092
|
this.range = util_1.default.createBoundingRange(test, questionMarkToken, consequent, colonToken, alternate);
|
|
1050
1093
|
}
|
|
1051
1094
|
transpile(state) {
|
|
@@ -1088,6 +1131,7 @@ class NullCoalescingExpression extends AstNode_1.Expression {
|
|
|
1088
1131
|
this.consequent = consequent;
|
|
1089
1132
|
this.questionQuestionToken = questionQuestionToken;
|
|
1090
1133
|
this.alternate = alternate;
|
|
1134
|
+
this.kind = AstNode_1.AstNodeKind.NullCoalescingExpression;
|
|
1091
1135
|
this.range = util_1.default.createBoundingRange(consequent, questionQuestionToken, alternate);
|
|
1092
1136
|
}
|
|
1093
1137
|
transpile(state) {
|
|
@@ -1128,6 +1172,7 @@ class RegexLiteralExpression extends AstNode_1.Expression {
|
|
|
1128
1172
|
constructor(tokens) {
|
|
1129
1173
|
super();
|
|
1130
1174
|
this.tokens = tokens;
|
|
1175
|
+
this.kind = AstNode_1.AstNodeKind.RegexLiteralExpression;
|
|
1131
1176
|
}
|
|
1132
1177
|
get range() {
|
|
1133
1178
|
var _a, _b;
|
|
@@ -1195,11 +1240,70 @@ function expressionToValue(expr, strict) {
|
|
|
1195
1240
|
return strict ? null : expr;
|
|
1196
1241
|
}
|
|
1197
1242
|
function numberExpressionToValue(expr, operator = '') {
|
|
1198
|
-
if ((0, reflection_1.isIntegerType)(expr.
|
|
1243
|
+
if ((0, reflection_1.isIntegerType)(expr.getType()) || (0, reflection_1.isLongIntegerType)(expr.getType())) {
|
|
1199
1244
|
return parseInt(operator + expr.token.text);
|
|
1200
1245
|
}
|
|
1201
1246
|
else {
|
|
1202
1247
|
return parseFloat(operator + expr.token.text);
|
|
1203
1248
|
}
|
|
1204
1249
|
}
|
|
1250
|
+
class TypeExpression extends AstNode_1.Expression {
|
|
1251
|
+
constructor(
|
|
1252
|
+
/**
|
|
1253
|
+
* The standard AST expression that represents the type for this TypeExpression.
|
|
1254
|
+
*/
|
|
1255
|
+
expression) {
|
|
1256
|
+
super();
|
|
1257
|
+
this.expression = expression;
|
|
1258
|
+
this.kind = AstNode_1.AstNodeKind.TypeExpression;
|
|
1259
|
+
this.range = expression === null || expression === void 0 ? void 0 : expression.range;
|
|
1260
|
+
}
|
|
1261
|
+
transpile(state) {
|
|
1262
|
+
return [this.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime }).toTypeString()];
|
|
1263
|
+
}
|
|
1264
|
+
walk(visitor, options) {
|
|
1265
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1266
|
+
(0, visitors_2.walk)(this, 'expression', visitor, options);
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
getType(options) {
|
|
1270
|
+
return this.expression.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.typetime }));
|
|
1271
|
+
}
|
|
1272
|
+
getTypedef(state) {
|
|
1273
|
+
// TypeDefs should pass through any valid type names
|
|
1274
|
+
return this.expression.transpile(state);
|
|
1275
|
+
}
|
|
1276
|
+
getName(parseMode = Parser_1.ParseMode.BrighterScript) {
|
|
1277
|
+
//TODO: this may not support Complex Types, eg. generics or Unions
|
|
1278
|
+
return util_1.default.getAllDottedGetPartsAsString(this.expression, parseMode);
|
|
1279
|
+
}
|
|
1280
|
+
getNameParts() {
|
|
1281
|
+
//TODO: really, this code is only used to get Namespaces. It could be more clear.
|
|
1282
|
+
return util_1.default.getAllDottedGetParts(this.expression).map(x => x.text);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
exports.TypeExpression = TypeExpression;
|
|
1286
|
+
class TypeCastExpression extends AstNode_1.Expression {
|
|
1287
|
+
constructor(obj, asToken, typeExpression) {
|
|
1288
|
+
super();
|
|
1289
|
+
this.obj = obj;
|
|
1290
|
+
this.asToken = asToken;
|
|
1291
|
+
this.typeExpression = typeExpression;
|
|
1292
|
+
this.kind = AstNode_1.AstNodeKind.TypeCastExpression;
|
|
1293
|
+
this.range = util_1.default.createBoundingRange(this.obj, this.asToken, this.typeExpression);
|
|
1294
|
+
}
|
|
1295
|
+
transpile(state) {
|
|
1296
|
+
return this.obj.transpile(state);
|
|
1297
|
+
}
|
|
1298
|
+
walk(visitor, options) {
|
|
1299
|
+
if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
|
|
1300
|
+
(0, visitors_2.walk)(this, 'obj', visitor, options);
|
|
1301
|
+
(0, visitors_2.walk)(this, 'typeExpression', visitor, options);
|
|
1302
|
+
}
|
|
1303
|
+
}
|
|
1304
|
+
getType(options) {
|
|
1305
|
+
return this.typeExpression.getType(options);
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
exports.TypeCastExpression = TypeCastExpression;
|
|
1205
1309
|
//# sourceMappingURL=Expression.js.map
|