brighterscript 1.0.0-alpha.32 → 1.0.0-alpha.34
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 +45 -0
- package/README.md +2 -2
- package/bsconfig.schema.json +3 -1
- package/dist/CrossScopeValidator.js +11 -11
- package/dist/CrossScopeValidator.js.map +1 -1
- package/dist/DiagnosticManager.js +3 -3
- package/dist/DiagnosticManager.js.map +1 -1
- package/dist/DiagnosticMessages.js +6 -4
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/FunctionScope.js +2 -2
- package/dist/FunctionScope.js.map +1 -1
- package/dist/Program.js +4 -3
- package/dist/Program.js.map +1 -1
- package/dist/astUtils/creators.d.ts +13 -19
- package/dist/astUtils/creators.js +27 -42
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +1 -1
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +4 -6
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.js +9 -5
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
- package/dist/bscPlugin/SignatureHelpUtil.js +5 -5
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +4 -4
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +5 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.js +94 -70
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +24 -3
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/definition/DefinitionProvider.js +20 -17
- package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.js +4 -4
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/references/ReferencesProvider.js +4 -3
- package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +2 -2
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
- package/dist/bscPlugin/symbols/symbolUtils.js +22 -21
- package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +4 -4
- package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.js +32 -25
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.js +84 -76
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +78 -0
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
- package/dist/bscPlugin/validation/XmlFileValidator.js +4 -3
- package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -1
- package/dist/files/BrsFile.js +42 -32
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +124 -26
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.js +4 -1
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +4 -2
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/globalCallables.js +1 -1
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +6 -4
- package/dist/interfaces.js +3 -3
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +10 -1
- package/dist/lexer/Lexer.js +16 -6
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +9 -8
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.d.ts +16 -8
- package/dist/lexer/Token.js.map +1 -1
- package/dist/parser/AstNode.d.ts +4 -4
- package/dist/parser/AstNode.js +3 -3
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/BrsTranspileState.d.ts +2 -2
- package/dist/parser/Expression.d.ts +55 -55
- package/dist/parser/Expression.js +95 -101
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +59 -59
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +5 -1
- package/dist/parser/Parser.js +123 -97
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +233 -223
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +19 -6
- package/dist/parser/SGParser.js +22 -11
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +4 -4
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +6 -6
- package/dist/parser/SGTypes.js +11 -11
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +100 -102
- package/dist/parser/Statement.js +215 -149
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +89 -3
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +6 -6
- package/dist/parser/TranspileState.js +29 -12
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +0 -7
- package/dist/parser/tests/Parser.spec.js +2 -12
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +19 -21
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +16 -15
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +219 -97
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +13 -12
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +25 -17
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +51 -38
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +51 -38
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +21 -14
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +43 -34
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +4 -4
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +53 -44
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +50 -37
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +8 -8
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +37 -37
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +23 -17
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +42 -26
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Relational.spec.js +12 -12
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +12 -11
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +51 -51
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TypeExpression.spec.js +15 -15
- package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +14 -14
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +3 -3
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Declaration.spec.js +29 -23
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +1 -1
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.js +10 -10
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/Function.spec.js +36 -35
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +23 -18
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +6 -6
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +6 -6
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +20 -18
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +13 -12
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +35 -34
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +3 -3
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/roku-types/data.json +81 -15
- package/dist/roku-types/index.d.ts +29 -4
- package/dist/types/ArrayType.js +6 -1
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/BuiltInInterfaceAdder.js +1 -1
- package/dist/types/BuiltInInterfaceAdder.js.map +1 -1
- package/dist/types/InheritableType.js.map +1 -1
- package/dist/util.d.ts +46 -26
- package/dist/util.js +168 -59
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +13 -11
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +8 -3
|
@@ -117,12 +117,13 @@ class ScopeValidator {
|
|
|
117
117
|
this.validateUnaryExpression(file, unaryExpr);
|
|
118
118
|
},
|
|
119
119
|
AssignmentStatement: (assignStmt) => {
|
|
120
|
+
var _a;
|
|
120
121
|
this.validateAssignmentStatement(file, assignStmt);
|
|
121
122
|
// Note: this also includes For statements
|
|
122
123
|
this.detectShadowedLocalVar(file, {
|
|
123
124
|
name: assignStmt.tokens.name.text,
|
|
124
125
|
type: this.getNodeTypeWrapper(file, assignStmt, { flags: 1 /* SymbolTypeFlag.runtime */ }),
|
|
125
|
-
nameRange: assignStmt.tokens.name.range
|
|
126
|
+
nameRange: (_a = assignStmt.tokens.name.location) === null || _a === void 0 ? void 0 : _a.range
|
|
126
127
|
});
|
|
127
128
|
},
|
|
128
129
|
AugmentedAssignmentStatement: (binaryExpr) => {
|
|
@@ -135,17 +136,19 @@ class ScopeValidator {
|
|
|
135
136
|
this.validateNewExpression(file, newExpr);
|
|
136
137
|
},
|
|
137
138
|
ForEachStatement: (forEachStmt) => {
|
|
139
|
+
var _a;
|
|
138
140
|
this.detectShadowedLocalVar(file, {
|
|
139
141
|
name: forEachStmt.tokens.item.text,
|
|
140
142
|
type: this.getNodeTypeWrapper(file, forEachStmt, { flags: 1 /* SymbolTypeFlag.runtime */ }),
|
|
141
|
-
nameRange: forEachStmt.tokens.item.range
|
|
143
|
+
nameRange: (_a = forEachStmt.tokens.item.location) === null || _a === void 0 ? void 0 : _a.range
|
|
142
144
|
});
|
|
143
145
|
},
|
|
144
146
|
FunctionParameterExpression: (funcParam) => {
|
|
147
|
+
var _a;
|
|
145
148
|
this.detectShadowedLocalVar(file, {
|
|
146
149
|
name: funcParam.tokens.name.text,
|
|
147
150
|
type: this.getNodeTypeWrapper(file, funcParam, { flags: 1 /* SymbolTypeFlag.runtime */ }),
|
|
148
|
-
nameRange: funcParam.tokens.name.range
|
|
151
|
+
nameRange: (_a = funcParam.tokens.name.location) === null || _a === void 0 ? void 0 : _a.range
|
|
149
152
|
});
|
|
150
153
|
}
|
|
151
154
|
});
|
|
@@ -220,9 +223,9 @@ class ScopeValidator {
|
|
|
220
223
|
* do this manually for now.
|
|
221
224
|
*/
|
|
222
225
|
validateCreateObjectCall(file, call) {
|
|
223
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
226
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
224
227
|
//skip non CreateObject function calls
|
|
225
|
-
const callName = (_a = util_1.
|
|
228
|
+
const callName = (_a = util_1.util.getAllDottedGetPartsAsString(call.callee)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
226
229
|
if (callName !== 'createobject' || !(0, reflection_1.isLiteralExpression)(call === null || call === void 0 ? void 0 : call.args[0])) {
|
|
227
230
|
return;
|
|
228
231
|
}
|
|
@@ -242,15 +245,15 @@ class ScopeValidator {
|
|
|
242
245
|
//add diagnostic for unknown components
|
|
243
246
|
const unquotedComponentName = (_g = componentName === null || componentName === void 0 ? void 0 : componentName.text) === null || _g === void 0 ? void 0 : _g.replace(/"/g, '');
|
|
244
247
|
if (unquotedComponentName && !platformNodeNames.has(unquotedComponentName.toLowerCase()) && !this.event.program.getComponent(unquotedComponentName)) {
|
|
245
|
-
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.unknownRoSGNode(unquotedComponentName)), { range: componentName.range }));
|
|
248
|
+
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.unknownRoSGNode(unquotedComponentName)), { range: (_h = componentName.location) === null || _h === void 0 ? void 0 : _h.range }));
|
|
246
249
|
}
|
|
247
250
|
else if ((call === null || call === void 0 ? void 0 : call.args.length) !== 2) {
|
|
248
251
|
// roSgNode should only ever have 2 args in `createObject`
|
|
249
|
-
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.mismatchCreateObjectArgumentCount(firstParamStringValue, [2], call === null || call === void 0 ? void 0 : call.args.length)), { range: call.range }));
|
|
252
|
+
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.mismatchCreateObjectArgumentCount(firstParamStringValue, [2], call === null || call === void 0 ? void 0 : call.args.length)), { range: (_j = call.location) === null || _j === void 0 ? void 0 : _j.range }));
|
|
250
253
|
}
|
|
251
254
|
}
|
|
252
255
|
else if (!platformComponentNames.has(firstParamStringValueLower)) {
|
|
253
|
-
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.unknownBrightScriptComponent(firstParamStringValue)), { range: firstParamToken.range }));
|
|
256
|
+
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.unknownBrightScriptComponent(firstParamStringValue)), { range: (_k = firstParamToken.location) === null || _k === void 0 ? void 0 : _k.range }));
|
|
254
257
|
}
|
|
255
258
|
else {
|
|
256
259
|
// This is valid brightscript component
|
|
@@ -264,11 +267,11 @@ class ScopeValidator {
|
|
|
264
267
|
}
|
|
265
268
|
if (!validArgCounts.includes(call === null || call === void 0 ? void 0 : call.args.length)) {
|
|
266
269
|
// Incorrect number of arguments included in `createObject()`
|
|
267
|
-
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.mismatchCreateObjectArgumentCount(firstParamStringValue, validArgCounts, call === null || call === void 0 ? void 0 : call.args.length)), { range: call.range }));
|
|
270
|
+
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.mismatchCreateObjectArgumentCount(firstParamStringValue, validArgCounts, call === null || call === void 0 ? void 0 : call.args.length)), { range: (_l = call.location) === null || _l === void 0 ? void 0 : _l.range }));
|
|
268
271
|
}
|
|
269
272
|
// Test for deprecation
|
|
270
273
|
if (brightScriptComponent === null || brightScriptComponent === void 0 ? void 0 : brightScriptComponent.isDeprecated) {
|
|
271
|
-
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.deprecatedBrightScriptComponent(firstParamStringValue, brightScriptComponent.deprecatedDescription)), { range: call.range }));
|
|
274
|
+
this.addDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.deprecatedBrightScriptComponent(firstParamStringValue, brightScriptComponent.deprecatedDescription)), { range: (_m = call.location) === null || _m === void 0 ? void 0 : _m.range }));
|
|
272
275
|
}
|
|
273
276
|
}
|
|
274
277
|
}
|
|
@@ -276,7 +279,7 @@ class ScopeValidator {
|
|
|
276
279
|
* Detect calls to functions with the incorrect number of parameters, or wrong types of arguments
|
|
277
280
|
*/
|
|
278
281
|
validateFunctionCall(file, expression) {
|
|
279
|
-
var _a;
|
|
282
|
+
var _a, _b, _c;
|
|
280
283
|
const getTypeOptions = { flags: 1 /* SymbolTypeFlag.runtime */, data: {} };
|
|
281
284
|
let funcType = this.getNodeTypeWrapper(file, expression === null || expression === void 0 ? void 0 : expression.callee, getTypeOptions);
|
|
282
285
|
if ((funcType === null || funcType === void 0 ? void 0 : funcType.isResolvable()) && (0, reflection_1.isClassType)(funcType)) {
|
|
@@ -303,7 +306,7 @@ class ScopeValidator {
|
|
|
303
306
|
let expCallArgCount = expression.args.length;
|
|
304
307
|
if (expCallArgCount > maxParams || expCallArgCount < minParams) {
|
|
305
308
|
let minMaxParamsText = minParams === maxParams ? maxParams : `${minParams}-${maxParams}`;
|
|
306
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(minMaxParamsText, expCallArgCount)), { range: expression.callee.range,
|
|
309
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(minMaxParamsText, expCallArgCount)), { range: (_a = expression.callee.location) === null || _a === void 0 ? void 0 : _a.range,
|
|
307
310
|
//TODO detect end of expression call
|
|
308
311
|
file: file }));
|
|
309
312
|
}
|
|
@@ -311,7 +314,7 @@ class ScopeValidator {
|
|
|
311
314
|
for (let arg of expression.args) {
|
|
312
315
|
const data = {};
|
|
313
316
|
let argType = this.getNodeTypeWrapper(file, arg, { flags: 1 /* SymbolTypeFlag.runtime */, data: data });
|
|
314
|
-
const paramType = (
|
|
317
|
+
const paramType = (_b = funcType.params[paramIndex]) === null || _b === void 0 ? void 0 : _b.type;
|
|
315
318
|
if (!paramType) {
|
|
316
319
|
// unable to find a paramType -- maybe there are more args than params
|
|
317
320
|
break;
|
|
@@ -326,7 +329,7 @@ class ScopeValidator {
|
|
|
326
329
|
const compatibilityData = {};
|
|
327
330
|
const isAllowedArgConversion = this.checkAllowedArgConversions(paramType, argType);
|
|
328
331
|
if (!isAllowedArgConversion && !(paramType === null || paramType === void 0 ? void 0 : paramType.isTypeCompatible(argType, compatibilityData))) {
|
|
329
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch(argType.toString(), paramType.toString(), compatibilityData)), { range: arg.range,
|
|
332
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch(argType.toString(), paramType.toString(), compatibilityData)), { range: (_c = arg.location) === null || _c === void 0 ? void 0 : _c.range,
|
|
330
333
|
//TODO detect end of expression call
|
|
331
334
|
file: file }));
|
|
332
335
|
}
|
|
@@ -344,13 +347,14 @@ class ScopeValidator {
|
|
|
344
347
|
* Detect return statements with incompatible types vs. declared return type
|
|
345
348
|
*/
|
|
346
349
|
validateReturnStatement(file, returnStmt) {
|
|
350
|
+
var _a;
|
|
347
351
|
const getTypeOptions = { flags: 1 /* SymbolTypeFlag.runtime */ };
|
|
348
352
|
let funcType = returnStmt.findAncestor(reflection_1.isFunctionExpression).getType({ flags: 2 /* SymbolTypeFlag.typetime */ });
|
|
349
353
|
if ((0, reflection_1.isTypedFunctionType)(funcType)) {
|
|
350
354
|
const actualReturnType = this.getNodeTypeWrapper(file, returnStmt === null || returnStmt === void 0 ? void 0 : returnStmt.value, getTypeOptions);
|
|
351
355
|
const compatibilityData = {};
|
|
352
356
|
if (actualReturnType && !funcType.returnType.isTypeCompatible(actualReturnType, compatibilityData)) {
|
|
353
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch(actualReturnType.toString(), funcType.returnType.toString(), compatibilityData)), { range: returnStmt.value.range, file: file }));
|
|
357
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch(actualReturnType.toString(), funcType.returnType.toString(), compatibilityData)), { range: (_a = returnStmt.value.location) === null || _a === void 0 ? void 0 : _a.range, file: file }));
|
|
354
358
|
}
|
|
355
359
|
}
|
|
356
360
|
}
|
|
@@ -358,13 +362,13 @@ class ScopeValidator {
|
|
|
358
362
|
* Detect assigned type different from expected member type
|
|
359
363
|
*/
|
|
360
364
|
validateDottedSetStatement(file, dottedSetStmt) {
|
|
361
|
-
var _a;
|
|
365
|
+
var _a, _b, _c;
|
|
362
366
|
const typeChainExpectedLHS = [];
|
|
363
367
|
const getTypeOpts = { flags: 1 /* SymbolTypeFlag.runtime */ };
|
|
364
368
|
const expectedLHSType = this.getNodeTypeWrapper(file, dottedSetStmt, Object.assign(Object.assign({}, getTypeOpts), { data: {}, typeChain: typeChainExpectedLHS }));
|
|
365
369
|
const actualRHSType = this.getNodeTypeWrapper(file, dottedSetStmt === null || dottedSetStmt === void 0 ? void 0 : dottedSetStmt.value, getTypeOpts);
|
|
366
370
|
const compatibilityData = {};
|
|
367
|
-
const typeChainScan = util_1.
|
|
371
|
+
const typeChainScan = util_1.util.processTypeChain(typeChainExpectedLHS);
|
|
368
372
|
// check if anything in typeChain is an AA - if so, just allow it
|
|
369
373
|
if (typeChainExpectedLHS.find(typeChainItem => (0, reflection_1.isAssociativeArrayType)(typeChainItem.type))) {
|
|
370
374
|
// something in the chain is an AA
|
|
@@ -372,26 +376,27 @@ class ScopeValidator {
|
|
|
372
376
|
return;
|
|
373
377
|
}
|
|
374
378
|
if (!expectedLHSType || !(expectedLHSType === null || expectedLHSType === void 0 ? void 0 : expectedLHSType.isResolvable())) {
|
|
375
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindName(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: typeChainScan.range }));
|
|
379
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindName(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: (_a = typeChainScan === null || typeChainScan === void 0 ? void 0 : typeChainScan.location) === null || _a === void 0 ? void 0 : _a.range }));
|
|
376
380
|
return;
|
|
377
381
|
}
|
|
378
382
|
let accessibilityIsOk = this.checkMemberAccessibility(file, dottedSetStmt, typeChainExpectedLHS);
|
|
379
383
|
//Most Component fields can be set with strings
|
|
380
384
|
//TODO: be more precise about which fields can actually accept strings
|
|
381
385
|
//TODO: if RHS is a string literal, we can do more validation to make sure it's the correct type
|
|
382
|
-
if ((0, reflection_1.isComponentType)((
|
|
386
|
+
if ((0, reflection_1.isComponentType)((_b = dottedSetStmt.obj) === null || _b === void 0 ? void 0 : _b.getType({ flags: 1 /* SymbolTypeFlag.runtime */ }))) {
|
|
383
387
|
if ((0, reflection_1.isStringType)(actualRHSType)) {
|
|
384
388
|
return;
|
|
385
389
|
}
|
|
386
390
|
}
|
|
387
391
|
if (accessibilityIsOk && !(expectedLHSType === null || expectedLHSType === void 0 ? void 0 : expectedLHSType.isTypeCompatible(actualRHSType, compatibilityData))) {
|
|
388
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch(actualRHSType.toString(), expectedLHSType.toString(), compatibilityData)), { range: dottedSetStmt.range, file: file }));
|
|
392
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch(actualRHSType.toString(), expectedLHSType.toString(), compatibilityData)), { range: (_c = dottedSetStmt.location) === null || _c === void 0 ? void 0 : _c.range, file: file }));
|
|
389
393
|
}
|
|
390
394
|
}
|
|
391
395
|
/**
|
|
392
396
|
* Detect when declared type does not match rhs type
|
|
393
397
|
*/
|
|
394
398
|
validateAssignmentStatement(file, assignStmt) {
|
|
399
|
+
var _a;
|
|
395
400
|
if (!(assignStmt === null || assignStmt === void 0 ? void 0 : assignStmt.typeExpression)) {
|
|
396
401
|
// nothing to check
|
|
397
402
|
return;
|
|
@@ -405,15 +410,16 @@ class ScopeValidator {
|
|
|
405
410
|
// LHS is not resolvable... handled elsewhere
|
|
406
411
|
}
|
|
407
412
|
else if (!(expectedLHSType === null || expectedLHSType === void 0 ? void 0 : expectedLHSType.isTypeCompatible(actualRHSType, compatibilityData))) {
|
|
408
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch(actualRHSType.toString(), expectedLHSType.toString(), compatibilityData)), { range: assignStmt.range, file: file }));
|
|
413
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch(actualRHSType.toString(), expectedLHSType.toString(), compatibilityData)), { range: (_a = assignStmt.location) === null || _a === void 0 ? void 0 : _a.range, file: file }));
|
|
409
414
|
}
|
|
410
415
|
}
|
|
411
416
|
/**
|
|
412
417
|
* Detect invalid use of a binary operator
|
|
413
418
|
*/
|
|
414
419
|
validateBinaryExpression(file, binaryExpr) {
|
|
420
|
+
var _a;
|
|
415
421
|
const getTypeOpts = { flags: 1 /* SymbolTypeFlag.runtime */ };
|
|
416
|
-
if (util_1.
|
|
422
|
+
if (util_1.util.isInTypeExpression(binaryExpr)) {
|
|
417
423
|
return;
|
|
418
424
|
}
|
|
419
425
|
let leftType = (0, reflection_1.isBinaryExpression)(binaryExpr)
|
|
@@ -451,16 +457,17 @@ class ScopeValidator {
|
|
|
451
457
|
// one operand is basically "any" type... ignore;
|
|
452
458
|
return;
|
|
453
459
|
}
|
|
454
|
-
const opResult = util_1.
|
|
460
|
+
const opResult = util_1.util.binaryOperatorResultType(leftTypeToTest, binaryExpr.tokens.operator, rightTypeToTest);
|
|
455
461
|
if ((0, reflection_1.isDynamicType)(opResult)) {
|
|
456
462
|
// if the result was dynamic, that means there wasn't a valid operation
|
|
457
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch(binaryExpr.tokens.operator.text, leftType.toString(), rightType.toString())), { range: binaryExpr.range, file: file }));
|
|
463
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch(binaryExpr.tokens.operator.text, leftType.toString(), rightType.toString())), { range: (_a = binaryExpr.location) === null || _a === void 0 ? void 0 : _a.range, file: file }));
|
|
458
464
|
}
|
|
459
465
|
}
|
|
460
466
|
/**
|
|
461
467
|
* Detect invalid use of a Unary operator
|
|
462
468
|
*/
|
|
463
469
|
validateUnaryExpression(file, unaryExpr) {
|
|
470
|
+
var _a, _b;
|
|
464
471
|
const getTypeOpts = { flags: 1 /* SymbolTypeFlag.runtime */ };
|
|
465
472
|
let rightType = this.getNodeTypeWrapper(file, unaryExpr.right, getTypeOpts);
|
|
466
473
|
if (!rightType.isResolvable()) {
|
|
@@ -479,17 +486,18 @@ class ScopeValidator {
|
|
|
479
486
|
// operand is basically "any" type... ignore;
|
|
480
487
|
}
|
|
481
488
|
else if ((0, reflection_1.isPrimitiveType)(rightType)) {
|
|
482
|
-
const opResult = util_1.
|
|
489
|
+
const opResult = util_1.util.unaryOperatorResultType(unaryExpr.tokens.operator, rightTypeToTest);
|
|
483
490
|
if ((0, reflection_1.isDynamicType)(opResult)) {
|
|
484
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch(unaryExpr.tokens.operator.text, rightType.toString())), { range: unaryExpr.range, file: file }));
|
|
491
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch(unaryExpr.tokens.operator.text, rightType.toString())), { range: (_a = unaryExpr.location) === null || _a === void 0 ? void 0 : _a.range, file: file }));
|
|
485
492
|
}
|
|
486
493
|
}
|
|
487
494
|
else {
|
|
488
495
|
// rhs is not a primitive, so no binary operator is allowed
|
|
489
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch(unaryExpr.tokens.operator.text, rightType.toString())), { range: unaryExpr.range, file: file }));
|
|
496
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch(unaryExpr.tokens.operator.text, rightType.toString())), { range: (_b = unaryExpr.location) === null || _b === void 0 ? void 0 : _b.range, file: file }));
|
|
490
497
|
}
|
|
491
498
|
}
|
|
492
499
|
validateIncrementStatement(file, incStmt) {
|
|
500
|
+
var _a;
|
|
493
501
|
const getTypeOpts = { flags: 1 /* SymbolTypeFlag.runtime */ };
|
|
494
502
|
let rightType = this.getNodeTypeWrapper(file, incStmt.value, getTypeOpts);
|
|
495
503
|
if (!rightType.isResolvable()) {
|
|
@@ -508,11 +516,11 @@ class ScopeValidator {
|
|
|
508
516
|
}
|
|
509
517
|
else {
|
|
510
518
|
// rhs is not a number, so no increment operator is not allowed
|
|
511
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch(incStmt.tokens.operator.text, rightType.toString())), { range: incStmt.range, file: file }));
|
|
519
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch(incStmt.tokens.operator.text, rightType.toString())), { range: (_a = incStmt.location) === null || _a === void 0 ? void 0 : _a.range, file: file }));
|
|
512
520
|
}
|
|
513
521
|
}
|
|
514
522
|
validateVariableAndDottedGetExpressions(file, expression) {
|
|
515
|
-
var _a, _b, _c, _d;
|
|
523
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
|
|
516
524
|
if ((0, reflection_1.isDottedGetExpression)(expression.parent)) {
|
|
517
525
|
// We validate dottedGetExpressions at the top-most level
|
|
518
526
|
return;
|
|
@@ -528,7 +536,7 @@ class ScopeValidator {
|
|
|
528
536
|
}
|
|
529
537
|
let symbolType = 1 /* SymbolTypeFlag.runtime */;
|
|
530
538
|
let oppositeSymbolType = 2 /* SymbolTypeFlag.typetime */;
|
|
531
|
-
const isUsedAsType = util_1.
|
|
539
|
+
const isUsedAsType = util_1.util.isInTypeExpression(expression);
|
|
532
540
|
if (isUsedAsType) {
|
|
533
541
|
// This is used in a TypeExpression - only look up types from SymbolTable
|
|
534
542
|
symbolType = 2 /* SymbolTypeFlag.typetime */;
|
|
@@ -546,51 +554,51 @@ class ScopeValidator {
|
|
|
546
554
|
const hasValidDeclaration = this.hasValidDeclaration(expression, exprType, typeData === null || typeData === void 0 ? void 0 : typeData.definingNode);
|
|
547
555
|
//include a hint diagnostic if this type is marked as deprecated
|
|
548
556
|
if (typeData.flags & 64 /* SymbolTypeFlag.deprecated */) { // eslint-disable-line no-bitwise
|
|
549
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemIsDeprecated()), { range: expression.tokens.name.range, file: file, tags: [vscode_languageserver_1.DiagnosticTag.Deprecated] }));
|
|
557
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemIsDeprecated()), { range: (_a = expression.tokens.name.location) === null || _a === void 0 ? void 0 : _a.range, file: file, tags: [vscode_languageserver_1.DiagnosticTag.Deprecated] }));
|
|
550
558
|
}
|
|
551
559
|
if (!this.isTypeKnown(exprType) && !hasValidDeclaration) {
|
|
552
|
-
if ((
|
|
560
|
+
if ((_b = this.getNodeTypeWrapper(file, expression, { flags: oppositeSymbolType, isExistenceTest: true })) === null || _b === void 0 ? void 0 : _b.isResolvable()) {
|
|
553
561
|
const oppoSiteTypeChain = [];
|
|
554
562
|
const invalidlyUsedResolvedType = this.getNodeTypeWrapper(file, expression, { flags: oppositeSymbolType, typeChain: oppoSiteTypeChain, isExistenceTest: true });
|
|
555
|
-
const typeChainScan = util_1.
|
|
563
|
+
const typeChainScan = util_1.util.processTypeChain(oppoSiteTypeChain);
|
|
556
564
|
if (isUsedAsType) {
|
|
557
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsType(typeChainScan.fullChainName)), { range: expression.range, file: file }));
|
|
565
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsType(typeChainScan.fullChainName)), { range: (_c = expression.location) === null || _c === void 0 ? void 0 : _c.range, file: file }));
|
|
558
566
|
}
|
|
559
567
|
else if (invalidlyUsedResolvedType && !(0, reflection_1.isReferenceType)(invalidlyUsedResolvedType)) {
|
|
560
568
|
if (!(0, reflection_1.isAliasStatement)(expression.parent)) {
|
|
561
569
|
// alias rhs CAN be a type!
|
|
562
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable(invalidlyUsedResolvedType.toString())), { range: expression.range, file: file }));
|
|
570
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable(invalidlyUsedResolvedType.toString())), { range: (_d = expression.location) === null || _d === void 0 ? void 0 : _d.range, file: file }));
|
|
563
571
|
}
|
|
564
572
|
}
|
|
565
573
|
else {
|
|
566
|
-
const typeChainScan = util_1.
|
|
574
|
+
const typeChainScan = util_1.util.processTypeChain(typeChain);
|
|
567
575
|
//if this is a function call, provide a different diganostic code
|
|
568
576
|
if ((0, reflection_1.isCallExpression)(typeChainScan.astNode.parent) && typeChainScan.astNode.parent.callee === expression) {
|
|
569
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindFunction(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: typeChainScan.range }));
|
|
577
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindFunction(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: (_e = typeChainScan === null || typeChainScan === void 0 ? void 0 : typeChainScan.location) === null || _e === void 0 ? void 0 : _e.range }));
|
|
570
578
|
}
|
|
571
579
|
else {
|
|
572
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindName(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: typeChainScan.range }));
|
|
580
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindName(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: (_f = typeChainScan === null || typeChainScan === void 0 ? void 0 : typeChainScan.location) === null || _f === void 0 ? void 0 : _f.range }));
|
|
573
581
|
}
|
|
574
582
|
}
|
|
575
583
|
}
|
|
576
584
|
else {
|
|
577
|
-
const typeChainScan = util_1.
|
|
585
|
+
const typeChainScan = util_1.util.processTypeChain(typeChain);
|
|
578
586
|
if ((0, reflection_1.isCallExpression)(typeChainScan.astNode.parent) && typeChainScan.astNode.parent.callee === expression) {
|
|
579
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindFunction(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: typeChainScan.range }));
|
|
587
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindFunction(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: (_g = typeChainScan === null || typeChainScan === void 0 ? void 0 : typeChainScan.location) === null || _g === void 0 ? void 0 : _g.range }));
|
|
580
588
|
}
|
|
581
589
|
else {
|
|
582
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindName(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: typeChainScan.range }));
|
|
590
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.cannotFindName(typeChainScan.itemName, typeChainScan.fullNameOfItem, typeChainScan.itemParentTypeName, this.getParentTypeDescriptor(typeChainScan))), { range: (_h = typeChainScan === null || typeChainScan === void 0 ? void 0 : typeChainScan.location) === null || _h === void 0 ? void 0 : _h.range }));
|
|
583
591
|
}
|
|
584
592
|
}
|
|
585
593
|
}
|
|
586
594
|
if (isUsedAsType) {
|
|
587
595
|
return;
|
|
588
596
|
}
|
|
589
|
-
const containingNamespaceName = (
|
|
590
|
-
if (!((0, reflection_1.isCallExpression)(expression.parent) && (0, reflection_1.isNewExpression)((
|
|
597
|
+
const containingNamespaceName = (_j = expression.findAncestor(reflection_1.isNamespaceStatement)) === null || _j === void 0 ? void 0 : _j.getName(Parser_1.ParseMode.BrighterScript);
|
|
598
|
+
if (!((0, reflection_1.isCallExpression)(expression.parent) && (0, reflection_1.isNewExpression)((_k = expression.parent) === null || _k === void 0 ? void 0 : _k.parent))) {
|
|
591
599
|
const classUsedAsVarEntry = this.checkTypeChainForClassUsedAsVar(typeChain, containingNamespaceName);
|
|
592
600
|
if (classUsedAsVarEntry) {
|
|
593
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable(classUsedAsVarEntry.toString())), { range: expression.range, file: file }));
|
|
601
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable(classUsedAsVarEntry.toString())), { range: (_l = expression.location) === null || _l === void 0 ? void 0 : _l.range, file: file }));
|
|
594
602
|
return;
|
|
595
603
|
}
|
|
596
604
|
}
|
|
@@ -598,22 +606,22 @@ class ScopeValidator {
|
|
|
598
606
|
const parentTypeInfo = typeChain[typeChain.length - 2];
|
|
599
607
|
this.checkMemberAccessibility(file, expression, typeChain);
|
|
600
608
|
if ((0, reflection_1.isNamespaceType)(exprType) && !(0, reflection_1.isAliasStatement)(expression.parent)) {
|
|
601
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable('namespace')), { range: expression.range, file: file }));
|
|
609
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable('namespace')), { range: (_m = expression.location) === null || _m === void 0 ? void 0 : _m.range, file: file }));
|
|
602
610
|
}
|
|
603
611
|
else if ((0, reflection_1.isEnumType)(exprType) && !(0, reflection_1.isAliasStatement)(expression.parent)) {
|
|
604
|
-
const enumStatement = this.event.scope.getEnum(util_1.
|
|
612
|
+
const enumStatement = this.event.scope.getEnum(util_1.util.getAllDottedGetPartsAsString(expression));
|
|
605
613
|
if (enumStatement) {
|
|
606
614
|
// there's an enum with this name
|
|
607
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable('enum')), { range: expression.range, file: file }));
|
|
615
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.itemCannotBeUsedAsVariable('enum')), { range: (_o = expression.location) === null || _o === void 0 ? void 0 : _o.range, file: file }));
|
|
608
616
|
}
|
|
609
617
|
}
|
|
610
618
|
else if ((0, reflection_1.isDynamicType)(exprType) && (0, reflection_1.isEnumType)(parentTypeInfo === null || parentTypeInfo === void 0 ? void 0 : parentTypeInfo.type) && (0, reflection_1.isDottedGetExpression)(expression)) {
|
|
611
|
-
const enumFileLink = this.event.scope.getEnumFileLink(util_1.
|
|
612
|
-
const typeChainScanForParent = util_1.
|
|
619
|
+
const enumFileLink = this.event.scope.getEnumFileLink(util_1.util.getAllDottedGetPartsAsString(expression.obj));
|
|
620
|
+
const typeChainScanForParent = util_1.util.processTypeChain(typeChain.slice(0, -1));
|
|
613
621
|
if (enumFileLink) {
|
|
614
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.unknownEnumValue(lastTypeInfo === null || lastTypeInfo === void 0 ? void 0 : lastTypeInfo.name, typeChainScanForParent.fullChainName)), { range: lastTypeInfo === null || lastTypeInfo === void 0 ? void 0 : lastTypeInfo.range, relatedInformation: [{
|
|
622
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.unknownEnumValue(lastTypeInfo === null || lastTypeInfo === void 0 ? void 0 : lastTypeInfo.name, typeChainScanForParent.fullChainName)), { range: (_p = lastTypeInfo === null || lastTypeInfo === void 0 ? void 0 : lastTypeInfo.location) === null || _p === void 0 ? void 0 : _p.range, relatedInformation: [{
|
|
615
623
|
message: 'Enum declared here',
|
|
616
|
-
location: util_1.
|
|
624
|
+
location: util_1.util.createLocationFromRange(vscode_uri_1.URI.file(enumFileLink === null || enumFileLink === void 0 ? void 0 : enumFileLink.file.srcPath).toString(), (_r = (_q = enumFileLink === null || enumFileLink === void 0 ? void 0 : enumFileLink.item) === null || _q === void 0 ? void 0 : _q.tokens.name.location) === null || _r === void 0 ? void 0 : _r.range)
|
|
617
625
|
}] }));
|
|
618
626
|
}
|
|
619
627
|
}
|
|
@@ -651,7 +659,7 @@ class ScopeValidator {
|
|
|
651
659
|
* @returns true if member accesiibility is okay
|
|
652
660
|
*/
|
|
653
661
|
checkMemberAccessibility(file, expression, typeChain) {
|
|
654
|
-
var _a, _b, _c;
|
|
662
|
+
var _a, _b, _c, _d, _e;
|
|
655
663
|
for (let i = 0; i < typeChain.length - 1; i++) {
|
|
656
664
|
const parentChainItem = typeChain[i];
|
|
657
665
|
const childChainItem = typeChain[i + 1];
|
|
@@ -664,7 +672,7 @@ class ScopeValidator {
|
|
|
664
672
|
// eslint-disable-next-line no-bitwise
|
|
665
673
|
if (childChainItem.data.flags & 8 /* SymbolTypeFlag.private */) {
|
|
666
674
|
if (!inMatchingClassStmt || childChainItem.data.memberOfAncestor) {
|
|
667
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.memberAccessibilityMismatch(childChainItem.name, childChainItem.data.flags, definingClassName)), { range: expression.range, file: file }));
|
|
675
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.memberAccessibilityMismatch(childChainItem.name, childChainItem.data.flags, definingClassName)), { range: (_c = expression.location) === null || _c === void 0 ? void 0 : _c.range, file: file }));
|
|
668
676
|
// there's an error... don't worry about the rest of the chain
|
|
669
677
|
return false;
|
|
670
678
|
}
|
|
@@ -672,11 +680,11 @@ class ScopeValidator {
|
|
|
672
680
|
// eslint-disable-next-line no-bitwise
|
|
673
681
|
if (childChainItem.data.flags & 16 /* SymbolTypeFlag.protected */) {
|
|
674
682
|
const containingClassName = containingClassStmt === null || containingClassStmt === void 0 ? void 0 : containingClassStmt.getName(Parser_1.ParseMode.BrighterScript);
|
|
675
|
-
const containingNamespaceName = (
|
|
683
|
+
const containingNamespaceName = (_d = expression.findAncestor(reflection_1.isNamespaceStatement)) === null || _d === void 0 ? void 0 : _d.getName(Parser_1.ParseMode.BrighterScript);
|
|
676
684
|
const ancestorClasses = this.event.scope.getClassHierarchy(containingClassName, containingNamespaceName).map(link => link.item);
|
|
677
685
|
const isSubClassOfDefiningClass = ancestorClasses.includes(classStmtThatDefinesChildMember);
|
|
678
686
|
if (!isSubClassOfDefiningClass) {
|
|
679
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.memberAccessibilityMismatch(childChainItem.name, childChainItem.data.flags, definingClassName)), { range: expression.range, file: file }));
|
|
687
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.memberAccessibilityMismatch(childChainItem.name, childChainItem.data.flags, definingClassName)), { range: (_e = expression.location) === null || _e === void 0 ? void 0 : _e.range, file: file }));
|
|
680
688
|
// there's an error... don't worry about the rest of the chain
|
|
681
689
|
return false;
|
|
682
690
|
}
|
|
@@ -691,7 +699,7 @@ class ScopeValidator {
|
|
|
691
699
|
* and make sure we can find a class with that name
|
|
692
700
|
*/
|
|
693
701
|
validateNewExpression(file, newExpression) {
|
|
694
|
-
var _a;
|
|
702
|
+
var _a, _b;
|
|
695
703
|
const newExprType = this.getNodeTypeWrapper(file, newExpression, { flags: 2 /* SymbolTypeFlag.typetime */ });
|
|
696
704
|
if ((0, reflection_1.isClassType)(newExprType)) {
|
|
697
705
|
return;
|
|
@@ -701,8 +709,8 @@ class ScopeValidator {
|
|
|
701
709
|
let newableClass = this.event.scope.getClass(potentialClassName, namespaceName);
|
|
702
710
|
if (!newableClass) {
|
|
703
711
|
//try and find functions with this name.
|
|
704
|
-
let fullName = util_1.
|
|
705
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expressionIsNotConstructable(fullName)), { file: file, range: newExpression.className.range }));
|
|
712
|
+
let fullName = util_1.util.getFullyQualifiedClassName(potentialClassName, namespaceName);
|
|
713
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.expressionIsNotConstructable(fullName)), { file: file, range: (_b = newExpression.className.location) === null || _b === void 0 ? void 0 : _b.range }));
|
|
706
714
|
}
|
|
707
715
|
}
|
|
708
716
|
/**
|
|
@@ -757,7 +765,7 @@ class ScopeValidator {
|
|
|
757
765
|
if (ownCallable.callable.nameRange !== callable.nameRange) {
|
|
758
766
|
related.push({
|
|
759
767
|
message: `Function declared here`,
|
|
760
|
-
location: util_1.
|
|
768
|
+
location: util_1.util.createLocationFromRange(vscode_uri_1.URI.file((_a = ownCallable.callable.file) === null || _a === void 0 ? void 0 : _a.srcPath).toString(), thatNameRange)
|
|
761
769
|
});
|
|
762
770
|
}
|
|
763
771
|
}
|
|
@@ -824,7 +832,7 @@ class ScopeValidator {
|
|
|
824
832
|
}
|
|
825
833
|
}
|
|
826
834
|
detectShadowedLocalVar(file, varDeclaration) {
|
|
827
|
-
var _a;
|
|
835
|
+
var _a, _b;
|
|
828
836
|
const varName = varDeclaration.name;
|
|
829
837
|
const lowerVarName = varName.toLowerCase();
|
|
830
838
|
const callableContainerMap = this.event.scope.getCallableContainerMap();
|
|
@@ -845,13 +853,13 @@ class ScopeValidator {
|
|
|
845
853
|
if (varIsFunction()) {
|
|
846
854
|
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.localVarFunctionShadowsParentFunction('scope')), { range: varDeclaration.nameRange, file: file, relatedInformation: [{
|
|
847
855
|
message: 'Function declared here',
|
|
848
|
-
location: util_1.
|
|
856
|
+
location: util_1.util.createLocationFromRange(vscode_uri_1.URI.file(callable[0].callable.file.srcPath).toString(), callable[0].callable.nameRange)
|
|
849
857
|
}] }));
|
|
850
858
|
}
|
|
851
859
|
else {
|
|
852
860
|
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.localVarShadowedByScopedFunction()), { range: varDeclaration.nameRange, file: file, relatedInformation: [{
|
|
853
861
|
message: 'Function declared here',
|
|
854
|
-
location: util_1.
|
|
862
|
+
location: util_1.util.createLocationFromRange(vscode_uri_1.URI.file(callable[0].callable.file.srcPath).toString(), callable[0].callable.nameRange)
|
|
855
863
|
}] }));
|
|
856
864
|
}
|
|
857
865
|
//has the same name as an in-scope class
|
|
@@ -861,13 +869,13 @@ class ScopeValidator {
|
|
|
861
869
|
if (classStmtLink) {
|
|
862
870
|
this.addMultiScopeDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.localVarSameNameAsClass((_a = classStmtLink === null || classStmtLink === void 0 ? void 0 : classStmtLink.item) === null || _a === void 0 ? void 0 : _a.getName(Parser_1.ParseMode.BrighterScript))), { range: varDeclaration.nameRange, file: file, relatedInformation: [{
|
|
863
871
|
message: 'Class declared here',
|
|
864
|
-
location: util_1.
|
|
872
|
+
location: util_1.util.createLocationFromRange(vscode_uri_1.URI.file(classStmtLink.file.srcPath).toString(), (_b = classStmtLink === null || classStmtLink === void 0 ? void 0 : classStmtLink.item.tokens.name.location) === null || _b === void 0 ? void 0 : _b.range)
|
|
865
873
|
}] }));
|
|
866
874
|
}
|
|
867
875
|
}
|
|
868
876
|
}
|
|
869
877
|
detectVariableNamespaceCollisions(file) {
|
|
870
|
-
var _a, _b;
|
|
878
|
+
var _a, _b, _c, _d;
|
|
871
879
|
this.event.program.diagnostics.clearByFilter({ scope: this.event.scope, file: file, tag: "ScopeValidatorNamespaceCollisions" /* ScopeValidatorDiagnosticTag.NamespaceCollisions */ });
|
|
872
880
|
//find all function parameters
|
|
873
881
|
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
@@ -877,9 +885,9 @@ class ScopeValidator {
|
|
|
877
885
|
let namespace = this.event.scope.getNamespace(lowerParamName, (_a = param.findAncestor(reflection_1.isNamespaceStatement)) === null || _a === void 0 ? void 0 : _a.getName(Parser_1.ParseMode.BrighterScript).toLowerCase());
|
|
878
886
|
//see if the param matches any starting namespace part
|
|
879
887
|
if (namespace) {
|
|
880
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.parameterMayNotHaveSameNameAsNamespace(param.tokens.name.text)), { range: param.tokens.name.range, relatedInformation: [{
|
|
888
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.parameterMayNotHaveSameNameAsNamespace(param.tokens.name.text)), { range: (_b = param.tokens.name.location) === null || _b === void 0 ? void 0 : _b.range, relatedInformation: [{
|
|
881
889
|
message: 'Namespace declared here',
|
|
882
|
-
location: util_1.
|
|
890
|
+
location: util_1.util.createLocationFromRange(vscode_uri_1.URI.file(namespace.file.srcPath).toString(), namespace.nameRange)
|
|
883
891
|
}] }), "ScopeValidatorNamespaceCollisions" /* ScopeValidatorDiagnosticTag.NamespaceCollisions */);
|
|
884
892
|
}
|
|
885
893
|
}
|
|
@@ -887,18 +895,18 @@ class ScopeValidator {
|
|
|
887
895
|
// eslint-disable-next-line @typescript-eslint/dot-notation
|
|
888
896
|
for (let assignment of file['_cachedLookups'].assignmentStatements) {
|
|
889
897
|
let lowerAssignmentName = assignment.tokens.name.text.toLowerCase();
|
|
890
|
-
let namespace = this.event.scope.getNamespace(lowerAssignmentName, (
|
|
898
|
+
let namespace = this.event.scope.getNamespace(lowerAssignmentName, (_c = assignment.findAncestor(reflection_1.isNamespaceStatement)) === null || _c === void 0 ? void 0 : _c.getName(Parser_1.ParseMode.BrighterScript).toLowerCase());
|
|
891
899
|
//see if the param matches any starting namespace part
|
|
892
900
|
if (namespace) {
|
|
893
|
-
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.variableMayNotHaveSameNameAsNamespace(assignment.tokens.name.text)), { range: assignment.tokens.name.range, relatedInformation: [{
|
|
901
|
+
this.addMultiScopeDiagnostic(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.variableMayNotHaveSameNameAsNamespace(assignment.tokens.name.text)), { range: (_d = assignment.tokens.name.location) === null || _d === void 0 ? void 0 : _d.range, relatedInformation: [{
|
|
894
902
|
message: 'Namespace declared here',
|
|
895
|
-
location: util_1.
|
|
903
|
+
location: util_1.util.createLocationFromRange(vscode_uri_1.URI.file(namespace.file.srcPath).toString(), namespace.nameRange)
|
|
896
904
|
}] }), "ScopeValidatorNamespaceCollisions" /* ScopeValidatorDiagnosticTag.NamespaceCollisions */);
|
|
897
905
|
}
|
|
898
906
|
}
|
|
899
907
|
}
|
|
900
908
|
validateXmlInterface(scope) {
|
|
901
|
-
var _a, _b, _c, _d, _e;
|
|
909
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
902
910
|
if (!((_b = (_a = scope.xmlFile.parser.ast) === null || _a === void 0 ? void 0 : _a.componentElement) === null || _b === void 0 ? void 0 : _b.interfaceElement)) {
|
|
903
911
|
return;
|
|
904
912
|
}
|
|
@@ -909,29 +917,29 @@ class ScopeValidator {
|
|
|
909
917
|
for (const func of iface.functions) {
|
|
910
918
|
const name = func.name;
|
|
911
919
|
if (!name) {
|
|
912
|
-
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlTagMissingAttribute(func.tokens.startTagName.text, 'name')), { range: func.tokens.startTagName.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
920
|
+
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlTagMissingAttribute(func.tokens.startTagName.text, 'name')), { range: (_c = func.tokens.startTagName.location) === null || _c === void 0 ? void 0 : _c.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
913
921
|
}
|
|
914
922
|
else if (!callableContainerMap.has(name.toLowerCase())) {
|
|
915
|
-
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlFunctionNotFound(name)), { range: (
|
|
923
|
+
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlFunctionNotFound(name)), { range: (_e = (_d = func.getAttribute('name')) === null || _d === void 0 ? void 0 : _d.tokens.value.location) === null || _e === void 0 ? void 0 : _e.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
916
924
|
}
|
|
917
925
|
}
|
|
918
926
|
//validate fields
|
|
919
927
|
for (const field of iface.fields) {
|
|
920
928
|
const { id, type, onChange } = field;
|
|
921
929
|
if (!id) {
|
|
922
|
-
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlTagMissingAttribute(field.tokens.startTagName.text, 'id')), { range: field.tokens.startTagName.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
930
|
+
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlTagMissingAttribute(field.tokens.startTagName.text, 'id')), { range: (_f = field.tokens.startTagName.location) === null || _f === void 0 ? void 0 : _f.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
923
931
|
}
|
|
924
932
|
if (!type) {
|
|
925
933
|
if (!field.alias) {
|
|
926
|
-
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlTagMissingAttribute(field.tokens.startTagName.text, 'type')), { range: field.tokens.startTagName.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
934
|
+
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlTagMissingAttribute(field.tokens.startTagName.text, 'type')), { range: (_g = field.tokens.startTagName.location) === null || _g === void 0 ? void 0 : _g.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
927
935
|
}
|
|
928
936
|
}
|
|
929
937
|
else if (!SGTypes_1.SGFieldTypes.includes(type.toLowerCase())) {
|
|
930
|
-
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlInvalidFieldType(type)), { range: (
|
|
938
|
+
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlInvalidFieldType(type)), { range: (_j = (_h = field.getAttribute('type')) === null || _h === void 0 ? void 0 : _h.tokens.value.location) === null || _j === void 0 ? void 0 : _j.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
931
939
|
}
|
|
932
940
|
if (onChange) {
|
|
933
941
|
if (!callableContainerMap.has(onChange.toLowerCase())) {
|
|
934
|
-
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlFunctionNotFound(onChange)), { range: (
|
|
942
|
+
this.addDiagnostic(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlFunctionNotFound(onChange)), { range: (_l = (_k = field.getAttribute('onchange')) === null || _k === void 0 ? void 0 : _k.tokens.value.location) === null || _l === void 0 ? void 0 : _l.range, file: scope.xmlFile }), "ScopeValidatorXML" /* ScopeValidatorDiagnosticTag.XMLInterface */);
|
|
935
943
|
}
|
|
936
944
|
}
|
|
937
945
|
}
|