brighterscript 1.0.0-alpha.10 → 1.0.0-alpha.14
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 +247 -267
- package/README.md +2 -2
- package/dist/Cache.d.ts +3 -3
- package/dist/Cache.js +10 -6
- package/dist/Cache.js.map +1 -1
- package/dist/CodeActionUtil.js.map +1 -1
- package/dist/CommentFlagProcessor.d.ts +4 -4
- package/dist/CommentFlagProcessor.js +5 -3
- package/dist/CommentFlagProcessor.js.map +1 -1
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticFilterer.js +1 -1
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/LanguageServer.d.ts +1 -6
- package/dist/LanguageServer.js +5 -14
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Logger.js.map +1 -1
- package/dist/PluginInterface.d.ts +3 -3
- package/dist/PluginInterface.js +3 -0
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +35 -20
- package/dist/Program.js +132 -67
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.js +4 -4
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +22 -13
- package/dist/Scope.js +85 -70
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +1 -1
- package/dist/SymbolTable.js +2 -2
- package/dist/SymbolTable.js.map +1 -1
- package/dist/XmlScope.d.ts +2 -2
- package/dist/XmlScope.js +5 -5
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +27 -0
- package/dist/astUtils/AstEditor.js +97 -0
- package/dist/astUtils/AstEditor.js.map +1 -0
- package/dist/{bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts → astUtils/AstEditor.spec.d.ts} +0 -0
- package/dist/astUtils/AstEditor.spec.js +133 -0
- package/dist/astUtils/AstEditor.spec.js.map +1 -0
- package/dist/astUtils/creators.spec.js +4 -4
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +4 -2
- package/dist/astUtils/reflection.js +10 -1
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +116 -116
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +13 -13
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.js +1 -1
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +26 -26
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +1 -0
- package/dist/astUtils/xml.js +6 -1
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.js +5 -2
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +3 -3
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +17 -17
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +8 -0
- package/dist/bscPlugin/semanticTokens/{SemanticTokensProcessor.js → BrsFileSemanticTokensProcessor.js} +13 -15
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/semanticTokens/{SemanticTokensProcessor.spec.js → BrsFileSemanticTokensProcessor.spec.js} +5 -5
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
- package/dist/diagnosticUtils.d.ts +1 -0
- package/dist/diagnosticUtils.js +14 -7
- package/dist/diagnosticUtils.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +2 -2
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +444 -269
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +17 -11
- package/dist/files/BrsFile.js +220 -153
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +620 -272
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +6 -5
- package/dist/files/XmlFile.js +14 -9
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +238 -191
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +29 -27
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/globalCallables.d.ts +3 -1
- package/dist/globalCallables.js +198 -99
- package/dist/globalCallables.js.map +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +71 -10
- package/dist/lexer/Lexer.d.ts +5 -1
- package/dist/lexer/Lexer.js +52 -35
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +564 -534
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +4 -0
- package/dist/lexer/TokenKind.js +44 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/Expression.d.ts +1 -1
- package/dist/parser/Expression.js +66 -66
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +107 -106
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +17 -5
- package/dist/parser/Parser.js +431 -315
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +418 -296
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.js +2 -2
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +22 -22
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +3 -0
- package/dist/parser/SGTypes.js +12 -7
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/SGTypes.spec.js +84 -84
- package/dist/parser/SGTypes.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +3 -3
- package/dist/parser/Statement.js +61 -61
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +10 -10
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +3 -3
- package/dist/parser/tests/Parser.spec.js +4 -4
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +58 -58
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +40 -39
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +201 -200
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +37 -37
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +30 -30
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +119 -119
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +141 -141
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +24 -24
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +41 -40
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +17 -17
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +256 -256
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +87 -87
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +37 -37
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +74 -62
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +41 -41
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +41 -41
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +110 -2
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/Relational.spec.js +43 -43
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +6 -6
- package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +18 -18
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +100 -100
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +36 -36
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/Declaration.spec.js +44 -44
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +21 -21
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Function.spec.js +198 -197
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +15 -14
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +50 -50
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +14 -2
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +17 -17
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +91 -90
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +34 -34
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +46 -46
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +83 -83
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +12 -11
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +5 -5
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +13 -13
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Chunk.d.ts +1 -1
- package/dist/preprocessor/Chunk.js.map +1 -1
- package/dist/preprocessor/Manifest.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.d.ts +1 -1
- package/dist/preprocessor/Preprocessor.js +8 -8
- package/dist/preprocessor/Preprocessor.js.map +1 -1
- package/dist/preprocessor/Preprocessor.spec.js +49 -49
- package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
- package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
- package/dist/types/ArrayType.d.ts +8 -5
- package/dist/types/ArrayType.js +48 -12
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/ArrayType.spec.js +69 -10
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/BooleanType.js +3 -3
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BooleanType.spec.js +2 -2
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/BscType.d.ts +1 -1
- package/dist/types/BscType.js +1 -1
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/CustomType.d.ts +1 -1
- package/dist/types/CustomType.js +6 -4
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.js +7 -7
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DoubleType.spec.js +2 -2
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.js +1 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +2 -2
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/FloatType.js +7 -7
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FloatType.spec.js +2 -2
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.d.ts +5 -5
- package/dist/types/FunctionType.js +13 -13
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +7 -7
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.js +7 -7
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/IntegerType.spec.js +2 -2
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.js +3 -3
- package/dist/types/InterfaceType.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +7 -7
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/InvalidType.js +4 -4
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/InvalidType.spec.js +2 -2
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LazyType.d.ts +1 -2
- package/dist/types/LazyType.js +1 -5
- package/dist/types/LazyType.js.map +1 -1
- package/dist/types/LongIntegerType.js +8 -8
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +2 -2
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/ObjectType.js +3 -3
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/ObjectType.spec.js +2 -2
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/StringType.js +3 -3
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/StringType.spec.js +2 -2
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/UninitializedType.js +3 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.js +3 -3
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/VoidType.spec.js +2 -2
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/types/helpers.js +6 -6
- package/dist/types/helpers.js.map +1 -1
- package/dist/util.d.ts +15 -9
- package/dist/util.js +104 -57
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.js +40 -40
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +10 -9
- package/dist/astUtils/index.d.ts +0 -7
- package/dist/astUtils/index.js +0 -26
- package/dist/astUtils/index.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +0 -7
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +0 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +0 -1
- package/dist/lexer/index.d.ts +0 -3
- package/dist/lexer/index.js +0 -17
- package/dist/lexer/index.js.map +0 -1
- package/dist/parser/index.d.ts +0 -3
- package/dist/parser/index.js +0 -16
- package/dist/parser/index.js.map +0 -1
- package/dist/preprocessor/index.d.ts +0 -3
- package/dist/preprocessor/index.js +0 -16
- package/dist/preprocessor/index.js.map +0 -1
|
@@ -12,7 +12,8 @@ const IntegerType_1 = require("../types/IntegerType");
|
|
|
12
12
|
const StringType_1 = require("../types/StringType");
|
|
13
13
|
const BrsFile_1 = require("./BrsFile");
|
|
14
14
|
const source_map_1 = require("source-map");
|
|
15
|
-
const
|
|
15
|
+
const Lexer_1 = require("../lexer/Lexer");
|
|
16
|
+
const TokenKind_1 = require("../lexer/TokenKind");
|
|
16
17
|
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
17
18
|
const util_1 = require("../util");
|
|
18
19
|
const PluginInterface_1 = require("../PluginInterface");
|
|
@@ -20,14 +21,17 @@ const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
|
20
21
|
const Parser_1 = require("../parser/Parser");
|
|
21
22
|
const Logger_1 = require("../Logger");
|
|
22
23
|
const VoidType_1 = require("../types/VoidType");
|
|
24
|
+
const FloatType_1 = require("../types/FloatType");
|
|
25
|
+
const ObjectType_1 = require("../types/ObjectType");
|
|
26
|
+
const ArrayType_1 = require("../types/ArrayType");
|
|
23
27
|
let sinon = sinonImport.createSandbox();
|
|
24
28
|
describe('BrsFile', () => {
|
|
25
|
-
let rootDir = util_1.standardizePath `${process.cwd()}/.tmp/rootDir`;
|
|
29
|
+
let rootDir = (0, util_1.standardizePath) `${process.cwd()}/.tmp/rootDir`;
|
|
26
30
|
let program;
|
|
27
|
-
let srcPath = util_1.standardizePath `${rootDir}/source/main.brs`;
|
|
31
|
+
let srcPath = (0, util_1.standardizePath) `${rootDir}/source/main.brs`;
|
|
28
32
|
let destPath = 'source/main.brs';
|
|
29
33
|
let file;
|
|
30
|
-
let testTranspile = testHelpers_spec_1.getTestTranspile(() => [program, rootDir]);
|
|
34
|
+
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, rootDir]);
|
|
31
35
|
beforeEach(() => {
|
|
32
36
|
program = new Program_1.Program({ rootDir: rootDir, sourceMap: true });
|
|
33
37
|
file = new BrsFile_1.BrsFile(srcPath, destPath, program);
|
|
@@ -37,30 +41,28 @@ describe('BrsFile', () => {
|
|
|
37
41
|
program.dispose();
|
|
38
42
|
});
|
|
39
43
|
it('supports the third parameter in CreateObject', () => {
|
|
40
|
-
var _a;
|
|
41
44
|
program.setFile('source/main.brs', `
|
|
42
45
|
sub main()
|
|
43
46
|
regexp = CreateObject("roRegex", "[a-z]+", "i")
|
|
44
47
|
end sub
|
|
45
48
|
`);
|
|
46
49
|
program.validate();
|
|
47
|
-
|
|
50
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
48
51
|
});
|
|
49
52
|
it('supports the 6 params in CreateObject for roRegion', () => {
|
|
50
|
-
var _a;
|
|
51
53
|
program.setFile('source/main.brs', `
|
|
52
54
|
sub createRegion(bitmap as object)
|
|
53
55
|
region = CreateObject("roRegion", bitmap, 20, 40, 100, 200)
|
|
54
56
|
end sub
|
|
55
57
|
`);
|
|
56
58
|
program.validate();
|
|
57
|
-
|
|
59
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
58
60
|
});
|
|
59
61
|
it('sets needsTranspiled to true for .bs files', () => {
|
|
60
62
|
//BrightScript
|
|
61
|
-
chai_1.expect(new BrsFile_1.BrsFile(`${rootDir}/source/main.brs`, 'source/main.brs', program).needsTranspiled).to.be.false;
|
|
63
|
+
(0, chai_1.expect)(new BrsFile_1.BrsFile(`${rootDir}/source/main.brs`, 'source/main.brs', program).needsTranspiled).to.be.false;
|
|
62
64
|
//BrighterScript
|
|
63
|
-
chai_1.expect(new BrsFile_1.BrsFile(`${rootDir}/source/main.bs`, 'source/main.bs', program).needsTranspiled).to.be.true;
|
|
65
|
+
(0, chai_1.expect)(new BrsFile_1.BrsFile(`${rootDir}/source/main.bs`, 'source/main.bs', program).needsTranspiled).to.be.true;
|
|
64
66
|
});
|
|
65
67
|
it('allows adding diagnostics', () => {
|
|
66
68
|
const expected = [{
|
|
@@ -69,8 +71,7 @@ describe('BrsFile', () => {
|
|
|
69
71
|
range: undefined
|
|
70
72
|
}];
|
|
71
73
|
file.addDiagnostics(expected);
|
|
72
|
-
|
|
73
|
-
chai_1.expect(actual).deep.equal(expected);
|
|
74
|
+
(0, testHelpers_spec_1.expectDiagnostics)(file, expected);
|
|
74
75
|
});
|
|
75
76
|
describe('getPartialVariableName', () => {
|
|
76
77
|
let entry = {
|
|
@@ -79,19 +80,19 @@ describe('BrsFile', () => {
|
|
|
79
80
|
};
|
|
80
81
|
it('creates proper tokens', () => {
|
|
81
82
|
file = program.setFile(entry, `call(ModuleA.ModuleB.ModuleC.`);
|
|
82
|
-
chai_1.expect(file['getPartialVariableName'](file.parser.tokens[7])).to.equal('ModuleA.ModuleB.ModuleC.');
|
|
83
|
-
chai_1.expect(file['getPartialVariableName'](file.parser.tokens[6])).to.equal('ModuleA.ModuleB.ModuleC');
|
|
84
|
-
chai_1.expect(file['getPartialVariableName'](file.parser.tokens[5])).to.equal('ModuleA.ModuleB.');
|
|
85
|
-
chai_1.expect(file['getPartialVariableName'](file.parser.tokens[4])).to.equal('ModuleA.ModuleB');
|
|
86
|
-
chai_1.expect(file['getPartialVariableName'](file.parser.tokens[3])).to.equal('ModuleA.');
|
|
87
|
-
chai_1.expect(file['getPartialVariableName'](file.parser.tokens[2])).to.equal('ModuleA');
|
|
83
|
+
(0, chai_1.expect)(file['getPartialVariableName'](file.parser.tokens[7])).to.equal('ModuleA.ModuleB.ModuleC.');
|
|
84
|
+
(0, chai_1.expect)(file['getPartialVariableName'](file.parser.tokens[6])).to.equal('ModuleA.ModuleB.ModuleC');
|
|
85
|
+
(0, chai_1.expect)(file['getPartialVariableName'](file.parser.tokens[5])).to.equal('ModuleA.ModuleB.');
|
|
86
|
+
(0, chai_1.expect)(file['getPartialVariableName'](file.parser.tokens[4])).to.equal('ModuleA.ModuleB');
|
|
87
|
+
(0, chai_1.expect)(file['getPartialVariableName'](file.parser.tokens[3])).to.equal('ModuleA.');
|
|
88
|
+
(0, chai_1.expect)(file['getPartialVariableName'](file.parser.tokens[2])).to.equal('ModuleA');
|
|
88
89
|
});
|
|
89
90
|
});
|
|
90
91
|
describe('getScopesForFile', () => {
|
|
91
92
|
it('finds the scope for the file', () => {
|
|
92
93
|
var _a;
|
|
93
94
|
let file = program.setFile('source/main.brs', ``);
|
|
94
|
-
chai_1.expect((_a = program.getScopesForFile(file)[0]) === null || _a === void 0 ? void 0 : _a.name).to.equal('source');
|
|
95
|
+
(0, chai_1.expect)((_a = program.getScopesForFile(file)[0]) === null || _a === void 0 ? void 0 : _a.name).to.equal('source');
|
|
95
96
|
});
|
|
96
97
|
});
|
|
97
98
|
describe('getCompletions', () => {
|
|
@@ -101,7 +102,7 @@ describe('BrsFile', () => {
|
|
|
101
102
|
getManager()@.
|
|
102
103
|
end sub
|
|
103
104
|
`);
|
|
104
|
-
chai_1.expect(() => {
|
|
105
|
+
(0, chai_1.expect)(() => {
|
|
105
106
|
program.getCompletions(file.srcPath, util_1.default.createPosition(2, 34));
|
|
106
107
|
}).not.to.throw;
|
|
107
108
|
});
|
|
@@ -113,7 +114,7 @@ describe('BrsFile', () => {
|
|
|
113
114
|
`);
|
|
114
115
|
const result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
115
116
|
const names = result.map(x => x.label);
|
|
116
|
-
chai_1.expect(names.sort()).to.eql([
|
|
117
|
+
(0, chai_1.expect)(names.sort()).to.eql([
|
|
117
118
|
'pkg:/source/main.brs'
|
|
118
119
|
]);
|
|
119
120
|
});
|
|
@@ -125,7 +126,7 @@ describe('BrsFile', () => {
|
|
|
125
126
|
`);
|
|
126
127
|
const result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
127
128
|
const names = result.map(x => x.label);
|
|
128
|
-
chai_1.expect(names.sort()).to.eql([
|
|
129
|
+
(0, chai_1.expect)(names.sort()).to.eql([
|
|
129
130
|
'libpkg:/source/main.brs'
|
|
130
131
|
]);
|
|
131
132
|
});
|
|
@@ -137,7 +138,7 @@ describe('BrsFile', () => {
|
|
|
137
138
|
`);
|
|
138
139
|
const result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
139
140
|
const names = result.map(x => x.label);
|
|
140
|
-
chai_1.expect(names.sort()).to.eql([
|
|
141
|
+
(0, chai_1.expect)(names.sort()).to.eql([
|
|
141
142
|
'pkg:/source/main.brs'
|
|
142
143
|
]);
|
|
143
144
|
});
|
|
@@ -154,8 +155,8 @@ describe('BrsFile', () => {
|
|
|
154
155
|
`);
|
|
155
156
|
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 23));
|
|
156
157
|
let names = result.map(x => x.label);
|
|
157
|
-
chai_1.expect(names).to.includes('Main');
|
|
158
|
-
chai_1.expect(names).to.includes('SayHello');
|
|
158
|
+
(0, chai_1.expect)(names).to.includes('Main');
|
|
159
|
+
(0, chai_1.expect)(names).to.includes('SayHello');
|
|
159
160
|
});
|
|
160
161
|
it('always includes `m`', () => {
|
|
161
162
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -166,12 +167,12 @@ describe('BrsFile', () => {
|
|
|
166
167
|
`);
|
|
167
168
|
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
168
169
|
let names = result.map(x => x.label);
|
|
169
|
-
chai_1.expect(names).to.contain('m');
|
|
170
|
+
(0, chai_1.expect)(names).to.contain('m');
|
|
170
171
|
});
|
|
171
172
|
it('does not fail for missing previousToken', () => {
|
|
172
173
|
//add a single character to the file, and get completions after it
|
|
173
174
|
program.setFile('source/main.brs', `i`);
|
|
174
|
-
chai_1.expect(() => {
|
|
175
|
+
(0, chai_1.expect)(() => {
|
|
175
176
|
program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(0, 1)).map(x => x.label);
|
|
176
177
|
}).not.to.throw;
|
|
177
178
|
});
|
|
@@ -182,18 +183,18 @@ describe('BrsFile', () => {
|
|
|
182
183
|
|
|
183
184
|
end sub
|
|
184
185
|
`);
|
|
185
|
-
let keywords = Object.keys(
|
|
186
|
+
let keywords = Object.keys(TokenKind_1.Keywords).filter(x => !x.includes(' '));
|
|
186
187
|
//inside the function
|
|
187
188
|
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
188
189
|
let names = result.map(x => x.label);
|
|
189
190
|
for (let keyword of keywords) {
|
|
190
|
-
chai_1.expect(names).to.include(keyword);
|
|
191
|
+
(0, chai_1.expect)(names).to.include(keyword);
|
|
191
192
|
}
|
|
192
193
|
//outside the function
|
|
193
194
|
result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(4, 8));
|
|
194
195
|
names = result.map(x => x.label);
|
|
195
196
|
for (let keyword of keywords) {
|
|
196
|
-
chai_1.expect(names).to.include(keyword);
|
|
197
|
+
(0, chai_1.expect)(names).to.include(keyword);
|
|
197
198
|
}
|
|
198
199
|
});
|
|
199
200
|
it('does not provide completions within a comment', () => {
|
|
@@ -205,7 +206,7 @@ describe('BrsFile', () => {
|
|
|
205
206
|
`);
|
|
206
207
|
//inside the function
|
|
207
208
|
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 33));
|
|
208
|
-
chai_1.expect(result).to.be.lengthOf(0);
|
|
209
|
+
(0, chai_1.expect)(result).to.be.lengthOf(0);
|
|
209
210
|
});
|
|
210
211
|
it('does not provide duplicate entries for variables', () => {
|
|
211
212
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -220,7 +221,7 @@ describe('BrsFile', () => {
|
|
|
220
221
|
let count = result.reduce((total, x) => {
|
|
221
222
|
return x.label === 'name' ? total + 1 : total;
|
|
222
223
|
}, 0);
|
|
223
|
-
chai_1.expect(count).to.equal(1);
|
|
224
|
+
(0, chai_1.expect)(count).to.equal(1);
|
|
224
225
|
});
|
|
225
226
|
it('does not include `as` and `string` text options when used in function params', () => {
|
|
226
227
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -230,8 +231,8 @@ describe('BrsFile', () => {
|
|
|
230
231
|
end sub
|
|
231
232
|
`);
|
|
232
233
|
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
233
|
-
chai_1.expect(result.filter(x => x.kind === vscode_languageserver_1.CompletionItemKind.Text)).not.to.contain('as');
|
|
234
|
-
chai_1.expect(result.filter(x => x.kind === vscode_languageserver_1.CompletionItemKind.Text)).not.to.contain('string');
|
|
234
|
+
(0, chai_1.expect)(result.filter(x => x.kind === vscode_languageserver_1.CompletionItemKind.Text)).not.to.contain('as');
|
|
235
|
+
(0, chai_1.expect)(result.filter(x => x.kind === vscode_languageserver_1.CompletionItemKind.Text)).not.to.contain('string');
|
|
235
236
|
});
|
|
236
237
|
it('does not provide intellisense results when inside a comment', () => {
|
|
237
238
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -241,7 +242,7 @@ describe('BrsFile', () => {
|
|
|
241
242
|
end sub
|
|
242
243
|
`);
|
|
243
244
|
let results = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 30));
|
|
244
|
-
chai_1.expect(results).to.be.empty;
|
|
245
|
+
(0, chai_1.expect)(results).to.be.empty;
|
|
245
246
|
});
|
|
246
247
|
it('does provide intellisence for labels only after a goto keyword', () => {
|
|
247
248
|
var _a;
|
|
@@ -252,8 +253,8 @@ describe('BrsFile', () => {
|
|
|
252
253
|
goto \nend sub
|
|
253
254
|
`);
|
|
254
255
|
let results = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 25));
|
|
255
|
-
chai_1.expect(results.length).to.equal(1);
|
|
256
|
-
chai_1.expect((_a = results[0]) === null || _a === void 0 ? void 0 : _a.label).to.equal('something');
|
|
256
|
+
(0, chai_1.expect)(results.length).to.equal(1);
|
|
257
|
+
(0, chai_1.expect)((_a = results[0]) === null || _a === void 0 ? void 0 : _a.label).to.equal('something');
|
|
257
258
|
});
|
|
258
259
|
it('includes properties of objects', () => {
|
|
259
260
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -265,9 +266,9 @@ describe('BrsFile', () => {
|
|
|
265
266
|
`);
|
|
266
267
|
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 26));
|
|
267
268
|
let names = result.map(x => x.label);
|
|
268
|
-
chai_1.expect(names).to.contain('name');
|
|
269
|
-
chai_1.expect(names).to.contain('age');
|
|
270
|
-
chai_1.expect(names).to.contain('height');
|
|
269
|
+
(0, chai_1.expect)(names).to.contain('name');
|
|
270
|
+
(0, chai_1.expect)(names).to.contain('age');
|
|
271
|
+
(0, chai_1.expect)(names).to.contain('height');
|
|
271
272
|
});
|
|
272
273
|
it('includes properties of m', () => {
|
|
273
274
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
@@ -279,13 +280,12 @@ describe('BrsFile', () => {
|
|
|
279
280
|
`);
|
|
280
281
|
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 22));
|
|
281
282
|
let names = result.map(x => x.label);
|
|
282
|
-
chai_1.expect(names).to.contain('someField');
|
|
283
|
+
(0, chai_1.expect)(names).to.contain('someField');
|
|
283
284
|
});
|
|
284
285
|
});
|
|
285
286
|
describe('comment flags', () => {
|
|
286
287
|
describe('bs:disable-next-line', () => {
|
|
287
288
|
it('disables critical diagnostic issues', () => {
|
|
288
|
-
var _a, _b;
|
|
289
289
|
program.setFile('source/main.brs', `
|
|
290
290
|
sub main()
|
|
291
291
|
Dim requestData
|
|
@@ -293,19 +293,18 @@ describe('BrsFile', () => {
|
|
|
293
293
|
`);
|
|
294
294
|
//should have an error
|
|
295
295
|
program.validate();
|
|
296
|
-
|
|
296
|
+
(0, testHelpers_spec_1.expectHasDiagnostics)(program);
|
|
297
297
|
program.setFile('source/main.brs', `
|
|
298
298
|
sub main()
|
|
299
299
|
'bs:disable-next-line
|
|
300
300
|
Dim requestData
|
|
301
301
|
end sub
|
|
302
302
|
`);
|
|
303
|
-
//should have an error
|
|
303
|
+
//should not have an error
|
|
304
304
|
program.validate();
|
|
305
|
-
|
|
305
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
306
306
|
});
|
|
307
307
|
it('works with leading whitespace', () => {
|
|
308
|
-
var _a;
|
|
309
308
|
program.setFile('source/main.brs', `
|
|
310
309
|
sub main()
|
|
311
310
|
' bs:disable-next-line
|
|
@@ -314,53 +313,66 @@ describe('BrsFile', () => {
|
|
|
314
313
|
`);
|
|
315
314
|
//should have an error
|
|
316
315
|
program.validate();
|
|
317
|
-
|
|
316
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
318
317
|
});
|
|
319
318
|
it('works for all', () => {
|
|
320
|
-
var _a;
|
|
321
319
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
322
320
|
sub Main()
|
|
323
321
|
'bs:disable-next-line
|
|
324
322
|
name = "bob
|
|
325
323
|
end sub
|
|
326
324
|
`);
|
|
327
|
-
chai_1.expect(file.commentFlags[0]).to.exist;
|
|
328
|
-
chai_1.expect(file.commentFlags[0]).to.deep.include({
|
|
325
|
+
(0, chai_1.expect)(file.commentFlags[0]).to.exist;
|
|
326
|
+
(0, chai_1.expect)(file.commentFlags[0]).to.deep.include({
|
|
329
327
|
codes: null,
|
|
330
328
|
range: vscode_languageserver_1.Range.create(2, 24, 2, 45),
|
|
331
329
|
affectedRange: util_1.default.createRange(3, 0, 3, Number.MAX_SAFE_INTEGER)
|
|
332
330
|
});
|
|
333
331
|
program.validate();
|
|
334
332
|
//the "unterminated string" error should be filtered out
|
|
335
|
-
|
|
333
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
336
334
|
});
|
|
337
335
|
it('works for specific codes', () => {
|
|
338
|
-
var _a;
|
|
339
336
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
340
337
|
sub Main()
|
|
341
338
|
'bs:disable-next-line: 1083, 1001
|
|
342
339
|
name = "bob
|
|
343
340
|
end sub
|
|
344
341
|
`);
|
|
345
|
-
chai_1.expect(file.commentFlags[0]).to.exist;
|
|
346
|
-
chai_1.expect(file.commentFlags[0]).to.deep.include({
|
|
342
|
+
(0, chai_1.expect)(file.commentFlags[0]).to.exist;
|
|
343
|
+
(0, chai_1.expect)(file.commentFlags[0]).to.deep.include({
|
|
347
344
|
codes: [1083, 1001],
|
|
348
345
|
range: vscode_languageserver_1.Range.create(2, 24, 2, 57),
|
|
349
346
|
affectedRange: util_1.default.createRange(3, 0, 3, Number.MAX_SAFE_INTEGER)
|
|
350
347
|
});
|
|
351
348
|
//the "unterminated string" error should be filtered out
|
|
352
|
-
|
|
349
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
353
350
|
});
|
|
354
|
-
it('
|
|
355
|
-
|
|
356
|
-
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
351
|
+
it('recognizes non-numeric codes', () => {
|
|
352
|
+
let file = program.setFile('source/main.brs', `
|
|
357
353
|
sub Main()
|
|
358
354
|
'bs:disable-next-line: LINT9999
|
|
359
355
|
name = "bob
|
|
360
356
|
end sub
|
|
361
357
|
`);
|
|
362
|
-
chai_1.expect(file.commentFlags[0]).to.
|
|
363
|
-
|
|
358
|
+
(0, chai_1.expect)(file.commentFlags[0]).to.exist;
|
|
359
|
+
(0, testHelpers_spec_1.expectHasDiagnostics)(program);
|
|
360
|
+
});
|
|
361
|
+
it('supports disabling non-numeric error codes', () => {
|
|
362
|
+
const program = new Program_1.Program({});
|
|
363
|
+
const file = program.setFile('source/main.brs', `
|
|
364
|
+
sub main()
|
|
365
|
+
something = true 'bs:disable-line: LINT1005
|
|
366
|
+
end sub
|
|
367
|
+
`);
|
|
368
|
+
file.addDiagnostics([{
|
|
369
|
+
code: 'LINT1005',
|
|
370
|
+
file: file,
|
|
371
|
+
message: 'Something is not right',
|
|
372
|
+
range: util_1.default.createRange(2, 16, 2, 26)
|
|
373
|
+
}]);
|
|
374
|
+
const scope = program.getScopesForFile(file)[0];
|
|
375
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(scope);
|
|
364
376
|
});
|
|
365
377
|
it('adds diagnostics for unknown numeric diagnostic codes', () => {
|
|
366
378
|
program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -369,13 +381,7 @@ describe('BrsFile', () => {
|
|
|
369
381
|
end sub
|
|
370
382
|
`);
|
|
371
383
|
program.validate();
|
|
372
|
-
|
|
373
|
-
chai_1.expect(program.getDiagnostics()[0]).to.deep.include({
|
|
374
|
-
range: vscode_languageserver_1.Range.create(2, 53, 2, 59)
|
|
375
|
-
});
|
|
376
|
-
chai_1.expect(program.getDiagnostics()[1]).to.deep.include({
|
|
377
|
-
range: vscode_languageserver_1.Range.create(2, 60, 2, 66)
|
|
378
|
-
});
|
|
384
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.unknownDiagnosticCode(123456)), { range: vscode_languageserver_1.Range.create(2, 53, 2, 59) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.unknownDiagnosticCode(999999)), { range: vscode_languageserver_1.Range.create(2, 60, 2, 66) })]);
|
|
379
385
|
});
|
|
380
386
|
});
|
|
381
387
|
describe('bs:disable-line', () => {
|
|
@@ -385,15 +391,15 @@ describe('BrsFile', () => {
|
|
|
385
391
|
z::;;%%%%%% 'bs:disable-line
|
|
386
392
|
end sub
|
|
387
393
|
`);
|
|
388
|
-
chai_1.expect(file.commentFlags[0]).to.exist;
|
|
389
|
-
chai_1.expect(file.commentFlags[0]).to.deep.include({
|
|
394
|
+
(0, chai_1.expect)(file.commentFlags[0]).to.exist;
|
|
395
|
+
(0, chai_1.expect)(file.commentFlags[0]).to.deep.include({
|
|
390
396
|
codes: null,
|
|
391
397
|
range: vscode_languageserver_1.Range.create(2, 36, 2, 52),
|
|
392
398
|
affectedRange: vscode_languageserver_1.Range.create(2, 0, 2, 36)
|
|
393
399
|
});
|
|
394
400
|
program.validate();
|
|
395
401
|
//the "unterminated string" error should be filtered out
|
|
396
|
-
|
|
402
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
397
403
|
});
|
|
398
404
|
it('works for specific codes', () => {
|
|
399
405
|
program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -407,10 +413,9 @@ describe('BrsFile', () => {
|
|
|
407
413
|
end sub
|
|
408
414
|
`);
|
|
409
415
|
program.validate();
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
});
|
|
416
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [{
|
|
417
|
+
range: vscode_languageserver_1.Range.create(5, 24, 5, 35)
|
|
418
|
+
}]);
|
|
414
419
|
});
|
|
415
420
|
it('handles the erraneous `stop` keyword', () => {
|
|
416
421
|
//the current version of BRS causes parse errors after the `parse` keyword, showing error in comments
|
|
@@ -423,7 +428,7 @@ describe('BrsFile', () => {
|
|
|
423
428
|
end sub
|
|
424
429
|
`);
|
|
425
430
|
program.validate();
|
|
426
|
-
|
|
431
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
427
432
|
});
|
|
428
433
|
});
|
|
429
434
|
});
|
|
@@ -437,12 +442,12 @@ describe('BrsFile', () => {
|
|
|
437
442
|
end sub)()
|
|
438
443
|
end sub
|
|
439
444
|
`);
|
|
440
|
-
testHelpers_spec_1.expectZeroDiagnostics(program);
|
|
445
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
441
446
|
});
|
|
442
447
|
it('uses the proper parse mode based on file extension', () => {
|
|
443
448
|
function testParseMode(destPath, expectedParseMode) {
|
|
444
449
|
const file = program.setFile(destPath, '');
|
|
445
|
-
chai_1.expect(file.parseMode).to.equal(expectedParseMode);
|
|
450
|
+
(0, chai_1.expect)(file.parseMode).to.equal(expectedParseMode);
|
|
446
451
|
}
|
|
447
452
|
testParseMode('source/main.brs', Parser_1.ParseMode.BrightScript);
|
|
448
453
|
testParseMode('source/main.spec.brs', Parser_1.ParseMode.BrightScript);
|
|
@@ -459,7 +464,7 @@ describe('BrsFile', () => {
|
|
|
459
464
|
myLabel:
|
|
460
465
|
end sub
|
|
461
466
|
`);
|
|
462
|
-
|
|
467
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
463
468
|
});
|
|
464
469
|
it('supports empty print statements', () => {
|
|
465
470
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -467,7 +472,7 @@ describe('BrsFile', () => {
|
|
|
467
472
|
print
|
|
468
473
|
end sub
|
|
469
474
|
`);
|
|
470
|
-
|
|
475
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
471
476
|
});
|
|
472
477
|
describe('conditional compile', () => {
|
|
473
478
|
it('works for upper case keywords', () => {
|
|
@@ -483,7 +488,7 @@ describe('BrsFile', () => {
|
|
|
483
488
|
#ENDIF
|
|
484
489
|
end sub
|
|
485
490
|
`);
|
|
486
|
-
|
|
491
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
487
492
|
});
|
|
488
493
|
it('supports single-word #elseif and #endif', () => {
|
|
489
494
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -496,7 +501,7 @@ describe('BrsFile', () => {
|
|
|
496
501
|
#endif
|
|
497
502
|
end sub
|
|
498
503
|
`);
|
|
499
|
-
|
|
504
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
500
505
|
});
|
|
501
506
|
it('supports multi-word #else if and #end if', () => {
|
|
502
507
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -509,7 +514,7 @@ describe('BrsFile', () => {
|
|
|
509
514
|
#end if
|
|
510
515
|
end sub
|
|
511
516
|
`);
|
|
512
|
-
|
|
517
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
513
518
|
});
|
|
514
519
|
it('does not choke on invalid code inside a false conditional compile', () => {
|
|
515
520
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -519,7 +524,7 @@ describe('BrsFile', () => {
|
|
|
519
524
|
#end if
|
|
520
525
|
end sub
|
|
521
526
|
`);
|
|
522
|
-
|
|
527
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
523
528
|
});
|
|
524
529
|
it('detects syntax error in #if', () => {
|
|
525
530
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -529,7 +534,9 @@ describe('BrsFile', () => {
|
|
|
529
534
|
#end if
|
|
530
535
|
end sub
|
|
531
536
|
`);
|
|
532
|
-
|
|
537
|
+
(0, testHelpers_spec_1.expectDiagnostics)(file, [
|
|
538
|
+
DiagnosticMessages_1.DiagnosticMessages.referencedConstDoesNotExist()
|
|
539
|
+
]);
|
|
533
540
|
});
|
|
534
541
|
it('detects syntax error in #const', () => {
|
|
535
542
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -539,7 +546,10 @@ describe('BrsFile', () => {
|
|
|
539
546
|
#end if
|
|
540
547
|
end sub
|
|
541
548
|
`);
|
|
542
|
-
|
|
549
|
+
(0, testHelpers_spec_1.expectDiagnostics)(file, [
|
|
550
|
+
DiagnosticMessages_1.DiagnosticMessages.unexpectedCharacter('%'),
|
|
551
|
+
DiagnosticMessages_1.DiagnosticMessages.invalidHashIfValue()
|
|
552
|
+
]);
|
|
543
553
|
});
|
|
544
554
|
it('detects #const name using reserved word', () => {
|
|
545
555
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -547,7 +557,10 @@ describe('BrsFile', () => {
|
|
|
547
557
|
#const function = true
|
|
548
558
|
end sub
|
|
549
559
|
`);
|
|
550
|
-
|
|
560
|
+
(0, testHelpers_spec_1.expectDiagnostics)(file, [
|
|
561
|
+
DiagnosticMessages_1.DiagnosticMessages.constNameCannotBeReservedWord(),
|
|
562
|
+
DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('#const')
|
|
563
|
+
]);
|
|
551
564
|
});
|
|
552
565
|
it('detects syntax error in #const', () => {
|
|
553
566
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -555,7 +568,9 @@ describe('BrsFile', () => {
|
|
|
555
568
|
#const someConst = 123
|
|
556
569
|
end sub
|
|
557
570
|
`);
|
|
558
|
-
|
|
571
|
+
(0, testHelpers_spec_1.expectDiagnostics)(file, [
|
|
572
|
+
DiagnosticMessages_1.DiagnosticMessages.invalidHashConstValue()
|
|
573
|
+
]);
|
|
559
574
|
});
|
|
560
575
|
});
|
|
561
576
|
it('supports stop statement', () => {
|
|
@@ -564,7 +579,7 @@ describe('BrsFile', () => {
|
|
|
564
579
|
stop
|
|
565
580
|
end sub
|
|
566
581
|
`);
|
|
567
|
-
|
|
582
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
568
583
|
});
|
|
569
584
|
it('supports single-line if statements', () => {
|
|
570
585
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -577,16 +592,15 @@ describe('BrsFile', () => {
|
|
|
577
592
|
if true then : test = sub() : print "yes" : end sub : end if
|
|
578
593
|
end sub
|
|
579
594
|
`);
|
|
580
|
-
|
|
595
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
581
596
|
});
|
|
582
597
|
it('supports line_num as global variable', () => {
|
|
583
|
-
var _a;
|
|
584
598
|
file.parse(`
|
|
585
599
|
sub Main()
|
|
586
600
|
print LINE_NUM
|
|
587
601
|
end sub
|
|
588
602
|
`);
|
|
589
|
-
|
|
603
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
590
604
|
});
|
|
591
605
|
it('supports many keywords as object property names', () => {
|
|
592
606
|
file.parse(`
|
|
@@ -652,7 +666,7 @@ describe('BrsFile', () => {
|
|
|
652
666
|
person.new = true
|
|
653
667
|
end sub
|
|
654
668
|
`);
|
|
655
|
-
|
|
669
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
656
670
|
});
|
|
657
671
|
it('does not error on numeric literal type designators', () => {
|
|
658
672
|
file.parse(`
|
|
@@ -666,7 +680,7 @@ describe('BrsFile', () => {
|
|
|
666
680
|
print 9876543210&
|
|
667
681
|
end sub
|
|
668
682
|
`);
|
|
669
|
-
|
|
683
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
670
684
|
});
|
|
671
685
|
it('does not error when encountering sub with return type', () => {
|
|
672
686
|
file.parse(`
|
|
@@ -674,7 +688,7 @@ describe('BrsFile', () => {
|
|
|
674
688
|
return
|
|
675
689
|
end sub
|
|
676
690
|
`);
|
|
677
|
-
|
|
691
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
678
692
|
});
|
|
679
693
|
it('does not lose function statements when mismatched end sub', () => {
|
|
680
694
|
file.parse(`
|
|
@@ -686,7 +700,7 @@ describe('BrsFile', () => {
|
|
|
686
700
|
print "hello world"
|
|
687
701
|
end sub
|
|
688
702
|
`);
|
|
689
|
-
chai_1.expect(file.parser.references.functionStatements).to.be.lengthOf(2);
|
|
703
|
+
(0, chai_1.expect)(file.parser.references.functionStatements).to.be.lengthOf(2);
|
|
690
704
|
});
|
|
691
705
|
it('does not lose sub scope when mismatched end function', () => {
|
|
692
706
|
file.parse(`
|
|
@@ -698,7 +712,7 @@ describe('BrsFile', () => {
|
|
|
698
712
|
print "hello world"
|
|
699
713
|
end sub
|
|
700
714
|
`);
|
|
701
|
-
chai_1.expect(file.parser.references.functionStatements).to.be.lengthOf(2);
|
|
715
|
+
(0, chai_1.expect)(file.parser.references.functionStatements).to.be.lengthOf(2);
|
|
702
716
|
});
|
|
703
717
|
it('does not error with boolean in RHS of set statement', () => {
|
|
704
718
|
file.parse(`
|
|
@@ -709,7 +723,7 @@ describe('BrsFile', () => {
|
|
|
709
723
|
foo.bar = true and false or 3 > 4
|
|
710
724
|
end sub
|
|
711
725
|
`);
|
|
712
|
-
|
|
726
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
713
727
|
});
|
|
714
728
|
it('does not error with boolean in RHS of set statement', () => {
|
|
715
729
|
file.parse(`
|
|
@@ -722,7 +736,7 @@ describe('BrsFile', () => {
|
|
|
722
736
|
m.isTrue = m.isTrue = m.isTrue
|
|
723
737
|
end sub
|
|
724
738
|
`);
|
|
725
|
-
|
|
739
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
726
740
|
});
|
|
727
741
|
it('supports variable names ending with type designators', () => {
|
|
728
742
|
file.parse(`
|
|
@@ -734,7 +748,7 @@ describe('BrsFile', () => {
|
|
|
734
748
|
someHex& = 13
|
|
735
749
|
end sub
|
|
736
750
|
`);
|
|
737
|
-
|
|
751
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
738
752
|
});
|
|
739
753
|
it('supports multiple spaces between two-word keywords', () => {
|
|
740
754
|
file.parse(`
|
|
@@ -746,7 +760,7 @@ describe('BrsFile', () => {
|
|
|
746
760
|
end if
|
|
747
761
|
end sub
|
|
748
762
|
`);
|
|
749
|
-
|
|
763
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
750
764
|
});
|
|
751
765
|
it('does not error with `stop` as object key', () => {
|
|
752
766
|
file.parse(`
|
|
@@ -759,7 +773,7 @@ describe('BrsFile', () => {
|
|
|
759
773
|
return obj
|
|
760
774
|
end function
|
|
761
775
|
`);
|
|
762
|
-
|
|
776
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
763
777
|
});
|
|
764
778
|
it('does not error with `run` as object key', () => {
|
|
765
779
|
file.parse(`
|
|
@@ -772,7 +786,7 @@ describe('BrsFile', () => {
|
|
|
772
786
|
return obj
|
|
773
787
|
end function
|
|
774
788
|
`);
|
|
775
|
-
|
|
789
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
776
790
|
});
|
|
777
791
|
it('supports assignment operators', () => {
|
|
778
792
|
file.parse(`
|
|
@@ -789,7 +803,7 @@ describe('BrsFile', () => {
|
|
|
789
803
|
print x
|
|
790
804
|
end function
|
|
791
805
|
`);
|
|
792
|
-
|
|
806
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
793
807
|
});
|
|
794
808
|
it('supports `then` as object property', () => {
|
|
795
809
|
file.parse(`
|
|
@@ -801,7 +815,7 @@ describe('BrsFile', () => {
|
|
|
801
815
|
promise.then()
|
|
802
816
|
end function
|
|
803
817
|
`);
|
|
804
|
-
|
|
818
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
805
819
|
});
|
|
806
820
|
it('supports function as parameter type', () => {
|
|
807
821
|
file.parse(`
|
|
@@ -810,7 +824,7 @@ describe('BrsFile', () => {
|
|
|
810
824
|
end function
|
|
811
825
|
end sub
|
|
812
826
|
`);
|
|
813
|
-
|
|
827
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
814
828
|
});
|
|
815
829
|
it('supports increment operator', () => {
|
|
816
830
|
file.parse(`
|
|
@@ -819,8 +833,7 @@ describe('BrsFile', () => {
|
|
|
819
833
|
x++
|
|
820
834
|
end function
|
|
821
835
|
`);
|
|
822
|
-
|
|
823
|
-
chai_1.expect(file.getDiagnostics()).to.be.lengthOf(0);
|
|
836
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
824
837
|
});
|
|
825
838
|
it('supports decrement operator', () => {
|
|
826
839
|
file.parse(`
|
|
@@ -829,8 +842,7 @@ describe('BrsFile', () => {
|
|
|
829
842
|
x--
|
|
830
843
|
end function
|
|
831
844
|
`);
|
|
832
|
-
|
|
833
|
-
chai_1.expect(file.getDiagnostics()).to.be.lengthOf(0);
|
|
845
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
834
846
|
});
|
|
835
847
|
it('supports writing numbers with decimal but no trailing digit', () => {
|
|
836
848
|
file.parse(`
|
|
@@ -839,7 +851,7 @@ describe('BrsFile', () => {
|
|
|
839
851
|
print x
|
|
840
852
|
end function
|
|
841
853
|
`);
|
|
842
|
-
|
|
854
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
843
855
|
});
|
|
844
856
|
it('supports assignment operators against object properties', () => {
|
|
845
857
|
file.parse(`
|
|
@@ -861,7 +873,7 @@ describe('BrsFile', () => {
|
|
|
861
873
|
print m.age
|
|
862
874
|
end function
|
|
863
875
|
`);
|
|
864
|
-
|
|
876
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
865
877
|
});
|
|
866
878
|
//skipped until `brs` supports this
|
|
867
879
|
it('supports bitshift assignment operators', () => {
|
|
@@ -873,7 +885,7 @@ describe('BrsFile', () => {
|
|
|
873
885
|
print x
|
|
874
886
|
end function
|
|
875
887
|
`);
|
|
876
|
-
|
|
888
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
877
889
|
});
|
|
878
890
|
//skipped until `brs` supports this
|
|
879
891
|
it('supports bitshift assignment operators on objects', () => {
|
|
@@ -885,7 +897,7 @@ describe('BrsFile', () => {
|
|
|
885
897
|
print m.x
|
|
886
898
|
end function
|
|
887
899
|
`);
|
|
888
|
-
|
|
900
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
889
901
|
});
|
|
890
902
|
it('supports leading and trailing periods for numeric literals', () => {
|
|
891
903
|
file.parse(`
|
|
@@ -896,7 +908,7 @@ describe('BrsFile', () => {
|
|
|
896
908
|
print pointOne
|
|
897
909
|
end function
|
|
898
910
|
`);
|
|
899
|
-
|
|
911
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
900
912
|
});
|
|
901
913
|
it('supports bitshift assignment operators on object properties accessed by array syntax', () => {
|
|
902
914
|
file.parse(`
|
|
@@ -907,7 +919,7 @@ describe('BrsFile', () => {
|
|
|
907
919
|
print m.x
|
|
908
920
|
end function
|
|
909
921
|
`);
|
|
910
|
-
|
|
922
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
911
923
|
});
|
|
912
924
|
it('supports weird period AA accessor', () => {
|
|
913
925
|
file.parse(`
|
|
@@ -916,42 +928,46 @@ describe('BrsFile', () => {
|
|
|
916
928
|
print m.["_uuid"]
|
|
917
929
|
end function
|
|
918
930
|
`);
|
|
919
|
-
|
|
931
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
920
932
|
});
|
|
921
933
|
it('adds error for library statements NOT at top of file', () => {
|
|
922
|
-
|
|
934
|
+
program.setFile('source/file.brs', ``);
|
|
935
|
+
program.setFile('source/main.bs', `
|
|
923
936
|
sub main()
|
|
924
937
|
end sub
|
|
925
938
|
import "file.brs"
|
|
926
939
|
`);
|
|
927
|
-
|
|
928
|
-
|
|
940
|
+
program.validate();
|
|
941
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
942
|
+
DiagnosticMessages_1.DiagnosticMessages.importStatementMustBeDeclaredAtTopOfFile()
|
|
929
943
|
]);
|
|
930
944
|
});
|
|
931
945
|
it('supports library imports', () => {
|
|
932
|
-
|
|
946
|
+
program.setFile('source/main.brs', `
|
|
933
947
|
Library "v30/bslCore.brs"
|
|
934
948
|
`);
|
|
935
|
-
|
|
949
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
936
950
|
});
|
|
937
951
|
it('adds error for library statements NOT at top of file', () => {
|
|
938
|
-
|
|
952
|
+
program.setFile('source/main.brs', `
|
|
939
953
|
sub main()
|
|
940
954
|
end sub
|
|
941
955
|
Library "v30/bslCore.brs"
|
|
942
956
|
`);
|
|
943
|
-
|
|
944
|
-
|
|
957
|
+
program.validate();
|
|
958
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
959
|
+
DiagnosticMessages_1.DiagnosticMessages.libraryStatementMustBeDeclaredAtTopOfFile()
|
|
945
960
|
]);
|
|
946
961
|
});
|
|
947
962
|
it('adds error for library statements inside of function body', () => {
|
|
948
|
-
|
|
963
|
+
program.setFile('source/main.brs', `
|
|
949
964
|
sub main()
|
|
950
965
|
Library "v30/bslCore.brs"
|
|
951
966
|
end sub
|
|
952
967
|
`);
|
|
953
|
-
|
|
954
|
-
|
|
968
|
+
program.validate();
|
|
969
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
970
|
+
DiagnosticMessages_1.DiagnosticMessages.libraryStatementMustBeDeclaredAtTopOfFile()
|
|
955
971
|
]);
|
|
956
972
|
});
|
|
957
973
|
it('supports colons as separators in associative array properties', () => {
|
|
@@ -960,7 +976,7 @@ describe('BrsFile', () => {
|
|
|
960
976
|
obj = {x:0 : y: 1}
|
|
961
977
|
end sub
|
|
962
978
|
`);
|
|
963
|
-
|
|
979
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
964
980
|
});
|
|
965
981
|
it('succeeds when finding variables with "sub" in them', () => {
|
|
966
982
|
let file = program.setFile('source/main.brs', `
|
|
@@ -968,7 +984,7 @@ describe('BrsFile', () => {
|
|
|
968
984
|
return value.subType()
|
|
969
985
|
end function
|
|
970
986
|
`);
|
|
971
|
-
chai_1.expect(file.callables[0]).to.deep.include({
|
|
987
|
+
(0, chai_1.expect)(file.callables[0]).to.deep.include({
|
|
972
988
|
file: file,
|
|
973
989
|
nameRange: vscode_languageserver_1.Range.create(1, 25, 1, 36)
|
|
974
990
|
});
|
|
@@ -991,10 +1007,10 @@ describe('BrsFile', () => {
|
|
|
991
1007
|
print "B"
|
|
992
1008
|
end function
|
|
993
1009
|
`);
|
|
994
|
-
chai_1.expect(file.callables[0].name).to.equal('DoA');
|
|
995
|
-
chai_1.expect(file.callables[0].nameRange).to.eql(vscode_languageserver_1.Range.create(1, 25, 1, 28));
|
|
996
|
-
chai_1.expect(file.callables[1].name).to.equal('DoB');
|
|
997
|
-
chai_1.expect(file.callables[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 26, 5, 29));
|
|
1010
|
+
(0, chai_1.expect)(file.callables[0].name).to.equal('DoA');
|
|
1011
|
+
(0, chai_1.expect)(file.callables[0].nameRange).to.eql(vscode_languageserver_1.Range.create(1, 25, 1, 28));
|
|
1012
|
+
(0, chai_1.expect)(file.callables[1].name).to.equal('DoB');
|
|
1013
|
+
(0, chai_1.expect)(file.callables[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 26, 5, 29));
|
|
998
1014
|
});
|
|
999
1015
|
it('throws an error if the file has already been parsed', () => {
|
|
1000
1016
|
let file = new BrsFile_1.BrsFile('abspath', 'relpath', program);
|
|
@@ -1018,11 +1034,11 @@ describe('BrsFile', () => {
|
|
|
1018
1034
|
print "A"
|
|
1019
1035
|
end function
|
|
1020
1036
|
`);
|
|
1021
|
-
chai_1.expect(file.callables.length).to.equal(2);
|
|
1022
|
-
chai_1.expect(file.callables[0].name).to.equal('DoA');
|
|
1023
|
-
chai_1.expect(file.callables[0].nameRange.start.line).to.equal(1);
|
|
1024
|
-
chai_1.expect(file.callables[1].name).to.equal('DoA');
|
|
1025
|
-
chai_1.expect(file.callables[1].nameRange.start.line).to.equal(5);
|
|
1037
|
+
(0, chai_1.expect)(file.callables.length).to.equal(2);
|
|
1038
|
+
(0, chai_1.expect)(file.callables[0].name).to.equal('DoA');
|
|
1039
|
+
(0, chai_1.expect)(file.callables[0].nameRange.start.line).to.equal(1);
|
|
1040
|
+
(0, chai_1.expect)(file.callables[1].name).to.equal('DoA');
|
|
1041
|
+
(0, chai_1.expect)(file.callables[1].nameRange.start.line).to.equal(5);
|
|
1026
1042
|
});
|
|
1027
1043
|
it('finds function call line and column numbers', () => {
|
|
1028
1044
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1034,11 +1050,11 @@ describe('BrsFile', () => {
|
|
|
1034
1050
|
DoC()
|
|
1035
1051
|
end function
|
|
1036
1052
|
`);
|
|
1037
|
-
chai_1.expect(file.functionCalls.length).to.equal(2);
|
|
1038
|
-
chai_1.expect(file.functionCalls[0].range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 28));
|
|
1039
|
-
chai_1.expect(file.functionCalls[0].nameRange).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 23));
|
|
1040
|
-
chai_1.expect(file.functionCalls[1].range).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 25));
|
|
1041
|
-
chai_1.expect(file.functionCalls[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 23));
|
|
1053
|
+
(0, chai_1.expect)(file.functionCalls.length).to.equal(2);
|
|
1054
|
+
(0, chai_1.expect)(file.functionCalls[0].range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 28));
|
|
1055
|
+
(0, chai_1.expect)(file.functionCalls[0].nameRange).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 23));
|
|
1056
|
+
(0, chai_1.expect)(file.functionCalls[1].range).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 25));
|
|
1057
|
+
(0, chai_1.expect)(file.functionCalls[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 23));
|
|
1042
1058
|
});
|
|
1043
1059
|
it('sanitizes brs errors', () => {
|
|
1044
1060
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1046,11 +1062,9 @@ describe('BrsFile', () => {
|
|
|
1046
1062
|
function DoSomething
|
|
1047
1063
|
end function
|
|
1048
1064
|
`);
|
|
1049
|
-
|
|
1050
|
-
chai_1.expect(file.getDiagnostics()[0]).to.
|
|
1051
|
-
|
|
1052
|
-
});
|
|
1053
|
-
chai_1.expect(file.getDiagnostics()[0].range.start.line).to.equal(1);
|
|
1065
|
+
(0, testHelpers_spec_1.expectHasDiagnostics)(file);
|
|
1066
|
+
(0, chai_1.expect)(file.getDiagnostics()[0].file).to.equal(file);
|
|
1067
|
+
(0, chai_1.expect)(file.getDiagnostics()[0].range.start.line).to.equal(1);
|
|
1054
1068
|
});
|
|
1055
1069
|
it('supports using the `next` keyword in a for loop', () => {
|
|
1056
1070
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1061,7 +1075,7 @@ describe('BrsFile', () => {
|
|
|
1061
1075
|
next
|
|
1062
1076
|
end sub
|
|
1063
1077
|
`);
|
|
1064
|
-
|
|
1078
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
1065
1079
|
});
|
|
1066
1080
|
//test is not working yet, but will be enabled when brs supports this syntax
|
|
1067
1081
|
it('supports assigning functions to objects', () => {
|
|
@@ -1074,7 +1088,7 @@ describe('BrsFile', () => {
|
|
|
1074
1088
|
end sub
|
|
1075
1089
|
end function
|
|
1076
1090
|
`);
|
|
1077
|
-
|
|
1091
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
1078
1092
|
});
|
|
1079
1093
|
});
|
|
1080
1094
|
describe('findCallables', () => {
|
|
@@ -1086,7 +1100,7 @@ describe('BrsFile', () => {
|
|
|
1086
1100
|
end sub
|
|
1087
1101
|
`);
|
|
1088
1102
|
let callable = file.callables[0];
|
|
1089
|
-
chai_1.expect(callable.range).to.eql(vscode_languageserver_1.Range.create(1, 16, 3, 23));
|
|
1103
|
+
(0, chai_1.expect)(callable.range).to.eql(vscode_languageserver_1.Range.create(1, 16, 3, 23));
|
|
1090
1104
|
});
|
|
1091
1105
|
it('finds correct body range even with inner function', () => {
|
|
1092
1106
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1099,7 +1113,7 @@ describe('BrsFile', () => {
|
|
|
1099
1113
|
end sub
|
|
1100
1114
|
`);
|
|
1101
1115
|
let callable = file.callables[0];
|
|
1102
|
-
chai_1.expect(callable.range).to.eql(vscode_languageserver_1.Range.create(1, 16, 6, 23));
|
|
1116
|
+
(0, chai_1.expect)(callable.range).to.eql(vscode_languageserver_1.Range.create(1, 16, 6, 23));
|
|
1103
1117
|
});
|
|
1104
1118
|
it('finds callable parameters', () => {
|
|
1105
1119
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1109,24 +1123,24 @@ describe('BrsFile', () => {
|
|
|
1109
1123
|
end function
|
|
1110
1124
|
`);
|
|
1111
1125
|
let callable = file.callables[0];
|
|
1112
|
-
chai_1.expect(callable.params[0]).to.deep.include({
|
|
1126
|
+
(0, chai_1.expect)(callable.params[0]).to.deep.include({
|
|
1113
1127
|
name: 'a',
|
|
1114
1128
|
isOptional: false,
|
|
1115
1129
|
isRestArgument: false
|
|
1116
1130
|
});
|
|
1117
|
-
chai_1.expect(callable.params[0].type).instanceof(DynamicType_1.DynamicType);
|
|
1118
|
-
chai_1.expect(callable.params[1]).to.deep.include({
|
|
1131
|
+
(0, chai_1.expect)(callable.params[0].type).instanceof(DynamicType_1.DynamicType);
|
|
1132
|
+
(0, chai_1.expect)(callable.params[1]).to.deep.include({
|
|
1119
1133
|
name: 'b',
|
|
1120
1134
|
isOptional: false,
|
|
1121
1135
|
isRestArgument: false
|
|
1122
1136
|
});
|
|
1123
|
-
chai_1.expect(callable.params[1].type).instanceof(DynamicType_1.DynamicType);
|
|
1124
|
-
chai_1.expect(callable.params[2]).to.deep.include({
|
|
1137
|
+
(0, chai_1.expect)(callable.params[1].type).instanceof(DynamicType_1.DynamicType);
|
|
1138
|
+
(0, chai_1.expect)(callable.params[2]).to.deep.include({
|
|
1125
1139
|
name: 'c',
|
|
1126
1140
|
isOptional: false,
|
|
1127
1141
|
isRestArgument: false
|
|
1128
1142
|
});
|
|
1129
|
-
chai_1.expect(callable.params[2].type).instanceof(DynamicType_1.DynamicType);
|
|
1143
|
+
(0, chai_1.expect)(callable.params[2].type).instanceof(DynamicType_1.DynamicType);
|
|
1130
1144
|
});
|
|
1131
1145
|
it('finds optional parameters', () => {
|
|
1132
1146
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1136,12 +1150,12 @@ describe('BrsFile', () => {
|
|
|
1136
1150
|
end function
|
|
1137
1151
|
`);
|
|
1138
1152
|
let callable = file.callables[0];
|
|
1139
|
-
chai_1.expect(callable.params[0]).to.deep.include({
|
|
1153
|
+
(0, chai_1.expect)(callable.params[0]).to.deep.include({
|
|
1140
1154
|
name: 'a',
|
|
1141
1155
|
isOptional: true,
|
|
1142
1156
|
isRestArgument: false
|
|
1143
1157
|
});
|
|
1144
|
-
chai_1.expect(callable.params[0].type).instanceof(IntegerType_1.IntegerType);
|
|
1158
|
+
(0, chai_1.expect)(callable.params[0].type).instanceof(IntegerType_1.IntegerType);
|
|
1145
1159
|
});
|
|
1146
1160
|
it('finds parameter types', () => {
|
|
1147
1161
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1151,24 +1165,24 @@ describe('BrsFile', () => {
|
|
|
1151
1165
|
end function
|
|
1152
1166
|
`);
|
|
1153
1167
|
let callable = file.callables[0];
|
|
1154
|
-
chai_1.expect(callable.params[0]).to.deep.include({
|
|
1168
|
+
(0, chai_1.expect)(callable.params[0]).to.deep.include({
|
|
1155
1169
|
name: 'a',
|
|
1156
1170
|
isOptional: false,
|
|
1157
1171
|
isRestArgument: false
|
|
1158
1172
|
});
|
|
1159
|
-
chai_1.expect(callable.params[0].type).instanceof(DynamicType_1.DynamicType);
|
|
1160
|
-
chai_1.expect(callable.params[1]).to.deep.include({
|
|
1173
|
+
(0, chai_1.expect)(callable.params[0].type).instanceof(DynamicType_1.DynamicType);
|
|
1174
|
+
(0, chai_1.expect)(callable.params[1]).to.deep.include({
|
|
1161
1175
|
name: 'b',
|
|
1162
1176
|
isOptional: false,
|
|
1163
1177
|
isRestArgument: false
|
|
1164
1178
|
});
|
|
1165
|
-
chai_1.expect(callable.params[1].type).instanceof(IntegerType_1.IntegerType);
|
|
1166
|
-
chai_1.expect(callable.params[2]).to.deep.include({
|
|
1179
|
+
(0, chai_1.expect)(callable.params[1].type).instanceof(IntegerType_1.IntegerType);
|
|
1180
|
+
(0, chai_1.expect)(callable.params[2]).to.deep.include({
|
|
1167
1181
|
name: 'c',
|
|
1168
1182
|
isOptional: false,
|
|
1169
1183
|
isRestArgument: false
|
|
1170
1184
|
});
|
|
1171
|
-
chai_1.expect(callable.params[2].type).instanceof(StringType_1.StringType);
|
|
1185
|
+
(0, chai_1.expect)(callable.params[2].type).instanceof(StringType_1.StringType);
|
|
1172
1186
|
});
|
|
1173
1187
|
});
|
|
1174
1188
|
describe('findCallableInvocations', () => {
|
|
@@ -1179,8 +1193,8 @@ describe('BrsFile', () => {
|
|
|
1179
1193
|
DoSomething("name", 12, true)
|
|
1180
1194
|
end function
|
|
1181
1195
|
`);
|
|
1182
|
-
chai_1.expect(file.functionCalls.length).to.equal(1);
|
|
1183
|
-
chai_1.expect(file.functionCalls[0].args).to.eql([{
|
|
1196
|
+
(0, chai_1.expect)(file.functionCalls.length).to.equal(1);
|
|
1197
|
+
(0, chai_1.expect)(file.functionCalls[0].args).to.eql([{
|
|
1184
1198
|
type: new StringType_1.StringType(),
|
|
1185
1199
|
range: util_1.default.createRange(2, 32, 2, 38),
|
|
1186
1200
|
text: '"name"'
|
|
@@ -1195,7 +1209,6 @@ describe('BrsFile', () => {
|
|
|
1195
1209
|
}]);
|
|
1196
1210
|
});
|
|
1197
1211
|
it('finds function calls nested inside statements', () => {
|
|
1198
|
-
var _a;
|
|
1199
1212
|
program.setFile(`source/main.brs`, `
|
|
1200
1213
|
sub main()
|
|
1201
1214
|
if true then
|
|
@@ -1204,7 +1217,9 @@ describe('BrsFile', () => {
|
|
|
1204
1217
|
end sub
|
|
1205
1218
|
`);
|
|
1206
1219
|
program.validate();
|
|
1207
|
-
|
|
1220
|
+
(0, testHelpers_spec_1.expectDiagnostics)(program, [
|
|
1221
|
+
DiagnosticMessages_1.DiagnosticMessages.callToUnknownFunction('DoesNotExist', 'source')
|
|
1222
|
+
]);
|
|
1208
1223
|
});
|
|
1209
1224
|
it('finds arguments with variable values', () => {
|
|
1210
1225
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1216,16 +1231,16 @@ describe('BrsFile', () => {
|
|
|
1216
1231
|
DoSomething(count, name, isAlive)
|
|
1217
1232
|
end function
|
|
1218
1233
|
`);
|
|
1219
|
-
chai_1.expect(file.functionCalls.length).to.equal(1);
|
|
1220
|
-
chai_1.expect(file.functionCalls[0].args[0]).deep.include({
|
|
1234
|
+
(0, chai_1.expect)(file.functionCalls.length).to.equal(1);
|
|
1235
|
+
(0, chai_1.expect)(file.functionCalls[0].args[0]).deep.include({
|
|
1221
1236
|
type: new IntegerType_1.IntegerType(),
|
|
1222
1237
|
text: 'count'
|
|
1223
1238
|
});
|
|
1224
|
-
chai_1.expect(file.functionCalls[0].args[1]).deep.include({
|
|
1239
|
+
(0, chai_1.expect)(file.functionCalls[0].args[1]).deep.include({
|
|
1225
1240
|
type: new StringType_1.StringType(),
|
|
1226
1241
|
text: 'name'
|
|
1227
1242
|
});
|
|
1228
|
-
chai_1.expect(file.functionCalls[0].args[2]).deep.include({
|
|
1243
|
+
(0, chai_1.expect)(file.functionCalls[0].args[2]).deep.include({
|
|
1229
1244
|
type: new BooleanType_1.BooleanType(),
|
|
1230
1245
|
text: 'isAlive'
|
|
1231
1246
|
});
|
|
@@ -1236,20 +1251,20 @@ describe('BrsFile', () => {
|
|
|
1236
1251
|
it('skips top-level statements', () => {
|
|
1237
1252
|
let file = new BrsFile_1.BrsFile('absolute', 'relative', program);
|
|
1238
1253
|
file.parse('name = "Bob"');
|
|
1239
|
-
chai_1.expect(file.callables.length).to.equal(0);
|
|
1254
|
+
(0, chai_1.expect)(file.callables.length).to.equal(0);
|
|
1240
1255
|
});
|
|
1241
1256
|
it('finds return type', () => {
|
|
1242
1257
|
let file = program.setFile('source/main.brs', `
|
|
1243
1258
|
function DoSomething() as string
|
|
1244
1259
|
end function
|
|
1245
1260
|
`);
|
|
1246
|
-
chai_1.expect(file.callables[0]).to.deep.include({
|
|
1261
|
+
(0, chai_1.expect)(file.callables[0]).to.deep.include({
|
|
1247
1262
|
file: file,
|
|
1248
1263
|
nameRange: vscode_languageserver_1.Range.create(1, 25, 1, 36),
|
|
1249
1264
|
name: 'DoSomething',
|
|
1250
1265
|
params: []
|
|
1251
1266
|
});
|
|
1252
|
-
chai_1.expect(file.callables[0].type.returnType).instanceof(StringType_1.StringType);
|
|
1267
|
+
(0, chai_1.expect)(file.callables[0].type.returnType).instanceof(StringType_1.StringType);
|
|
1253
1268
|
});
|
|
1254
1269
|
});
|
|
1255
1270
|
describe('function local variable handling', () => {
|
|
@@ -1259,7 +1274,7 @@ describe('BrsFile', () => {
|
|
|
1259
1274
|
name = 'bob"
|
|
1260
1275
|
end sub
|
|
1261
1276
|
`);
|
|
1262
|
-
chai_1.expect(file.parser.references.functionStatements[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 3, 23));
|
|
1277
|
+
(0, chai_1.expect)(file.parser.references.functionStatements[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 3, 23));
|
|
1263
1278
|
});
|
|
1264
1279
|
it('creates scopes for parent and child functions', () => {
|
|
1265
1280
|
file.parse(`
|
|
@@ -1273,7 +1288,7 @@ describe('BrsFile', () => {
|
|
|
1273
1288
|
end sub)
|
|
1274
1289
|
end sub
|
|
1275
1290
|
`);
|
|
1276
|
-
chai_1.expect(file.parser.references.functionExpressions).to.be.length(3);
|
|
1291
|
+
(0, chai_1.expect)(file.parser.references.functionExpressions).to.be.length(3);
|
|
1277
1292
|
});
|
|
1278
1293
|
it('finds variables declared in function expressions', () => {
|
|
1279
1294
|
file.parse(`
|
|
@@ -1287,13 +1302,13 @@ describe('BrsFile', () => {
|
|
|
1287
1302
|
end sub)
|
|
1288
1303
|
end sub
|
|
1289
1304
|
`);
|
|
1290
|
-
testHelpers_spec_1.expectSymbolTableEquals(file.parser.references.functionExpressions[0].symbolTable, [
|
|
1305
|
+
(0, testHelpers_spec_1.expectSymbolTableEquals)(file.parser.references.functionExpressions[0].symbolTable, [
|
|
1291
1306
|
['sayHi', new FunctionType_1.FunctionType(new VoidType_1.VoidType(), true), util_1.default.createRange(2, 20, 2, 25)]
|
|
1292
1307
|
]);
|
|
1293
|
-
testHelpers_spec_1.expectSymbolTableEquals(file.parser.references.functionExpressions[1].symbolTable, [
|
|
1308
|
+
(0, testHelpers_spec_1.expectSymbolTableEquals)(file.parser.references.functionExpressions[1].symbolTable, [
|
|
1294
1309
|
['age', new IntegerType_1.IntegerType(), util_1.default.createRange(3, 24, 3, 27)]
|
|
1295
1310
|
]);
|
|
1296
|
-
testHelpers_spec_1.expectSymbolTableEquals(file.parser.references.functionExpressions[2].symbolTable, [
|
|
1311
|
+
(0, testHelpers_spec_1.expectSymbolTableEquals)(file.parser.references.functionExpressions[2].symbolTable, [
|
|
1297
1312
|
['name', new StringType_1.StringType(), util_1.default.createRange(7, 24, 7, 28)]
|
|
1298
1313
|
]);
|
|
1299
1314
|
});
|
|
@@ -1305,7 +1320,7 @@ describe('BrsFile', () => {
|
|
|
1305
1320
|
end if
|
|
1306
1321
|
end sub
|
|
1307
1322
|
`);
|
|
1308
|
-
testHelpers_spec_1.expectSymbolTableEquals(file.parser.references.functionExpressions[0].symbolTable, [
|
|
1323
|
+
(0, testHelpers_spec_1.expectSymbolTableEquals)(file.parser.references.functionExpressions[0].symbolTable, [
|
|
1309
1324
|
['theLength', new IntegerType_1.IntegerType(), util_1.default.createRange(3, 24, 3, 33)]
|
|
1310
1325
|
]);
|
|
1311
1326
|
});
|
|
@@ -1319,7 +1334,7 @@ describe('BrsFile', () => {
|
|
|
1319
1334
|
return "bob"
|
|
1320
1335
|
end function
|
|
1321
1336
|
`);
|
|
1322
|
-
testHelpers_spec_1.expectSymbolTableEquals(file.parser.references.functionExpressions[0].symbolTable, [
|
|
1337
|
+
(0, testHelpers_spec_1.expectSymbolTableEquals)(file.parser.references.functionExpressions[0].symbolTable, [
|
|
1323
1338
|
['myName', new StringType_1.StringType(), util_1.default.createRange(2, 19, 2, 25)]
|
|
1324
1339
|
]);
|
|
1325
1340
|
});
|
|
@@ -1330,7 +1345,7 @@ describe('BrsFile', () => {
|
|
|
1330
1345
|
nameCopy = name
|
|
1331
1346
|
end sub
|
|
1332
1347
|
`);
|
|
1333
|
-
testHelpers_spec_1.expectSymbolTableEquals(file.parser.references.functionExpressions[0].symbolTable, [
|
|
1348
|
+
(0, testHelpers_spec_1.expectSymbolTableEquals)(file.parser.references.functionExpressions[0].symbolTable, [
|
|
1334
1349
|
['name', new StringType_1.StringType(), util_1.default.createRange(2, 19, 2, 23)],
|
|
1335
1350
|
['nameCopy', new StringType_1.StringType(), util_1.default.createRange(3, 19, 3, 27)]
|
|
1336
1351
|
]);
|
|
@@ -1343,8 +1358,8 @@ describe('BrsFile', () => {
|
|
|
1343
1358
|
end function
|
|
1344
1359
|
end sub
|
|
1345
1360
|
`);
|
|
1346
|
-
chai_1.expect(file.parser.references.functionExpressions).to.be.length(2);
|
|
1347
|
-
chai_1.expect(file.parser.references.functionExpressions.map(x => x.range)).to.eql([
|
|
1361
|
+
(0, chai_1.expect)(file.parser.references.functionExpressions).to.be.length(2);
|
|
1362
|
+
(0, chai_1.expect)(file.parser.references.functionExpressions.map(x => x.range)).to.eql([
|
|
1348
1363
|
util_1.default.createRange(1, 16, 5, 23),
|
|
1349
1364
|
util_1.default.createRange(2, 30, 4, 32)
|
|
1350
1365
|
]);
|
|
@@ -1361,12 +1376,12 @@ describe('BrsFile', () => {
|
|
|
1361
1376
|
`);
|
|
1362
1377
|
//hover over the `name = 1` line
|
|
1363
1378
|
let hover = file.getHover(vscode_languageserver_1.Position.create(2, 24));
|
|
1364
|
-
chai_1.expect(hover).to.exist;
|
|
1365
|
-
chai_1.expect(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 24));
|
|
1379
|
+
(0, chai_1.expect)(hover).to.exist;
|
|
1380
|
+
(0, chai_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 24));
|
|
1366
1381
|
//hover over the `name` parameter declaration
|
|
1367
1382
|
hover = file.getHover(vscode_languageserver_1.Position.create(1, 34));
|
|
1368
|
-
chai_1.expect(hover).to.exist;
|
|
1369
|
-
chai_1.expect(hover.range).to.eql(vscode_languageserver_1.Range.create(1, 32, 1, 36));
|
|
1383
|
+
(0, chai_1.expect)(hover).to.exist;
|
|
1384
|
+
(0, chai_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(1, 32, 1, 36));
|
|
1370
1385
|
});
|
|
1371
1386
|
//ignore this for now...it's not a huge deal
|
|
1372
1387
|
it('does not match on keywords or data types', () => {
|
|
@@ -1377,9 +1392,9 @@ describe('BrsFile', () => {
|
|
|
1377
1392
|
end sub
|
|
1378
1393
|
`);
|
|
1379
1394
|
//hover over the `as`
|
|
1380
|
-
chai_1.expect(file.getHover(vscode_languageserver_1.Position.create(1, 31))).not.to.exist;
|
|
1395
|
+
(0, chai_1.expect)(file.getHover(vscode_languageserver_1.Position.create(1, 31))).not.to.exist;
|
|
1381
1396
|
//hover over the `string`
|
|
1382
|
-
chai_1.expect(file.getHover(vscode_languageserver_1.Position.create(1, 36))).not.to.exist;
|
|
1397
|
+
(0, chai_1.expect)(file.getHover(vscode_languageserver_1.Position.create(1, 36))).not.to.exist;
|
|
1383
1398
|
});
|
|
1384
1399
|
it('finds declared function', () => {
|
|
1385
1400
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -1390,9 +1405,13 @@ describe('BrsFile', () => {
|
|
|
1390
1405
|
end function
|
|
1391
1406
|
`);
|
|
1392
1407
|
let hover = file.getHover(vscode_languageserver_1.Position.create(1, 28));
|
|
1393
|
-
chai_1.expect(hover).to.exist;
|
|
1394
|
-
chai_1.expect(hover.range).to.eql(vscode_languageserver_1.Range.create(1, 25, 1, 29));
|
|
1395
|
-
chai_1.expect(hover.contents).to.equal(
|
|
1408
|
+
(0, chai_1.expect)(hover).to.exist;
|
|
1409
|
+
(0, chai_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(1, 25, 1, 29));
|
|
1410
|
+
(0, chai_1.expect)(hover.contents).to.equal([
|
|
1411
|
+
'```brightscript',
|
|
1412
|
+
'function Main(count? as integer) as dynamic',
|
|
1413
|
+
'```'
|
|
1414
|
+
].join('\n'));
|
|
1396
1415
|
});
|
|
1397
1416
|
it('finds variable function hover in same scope', () => {
|
|
1398
1417
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -1404,8 +1423,36 @@ describe('BrsFile', () => {
|
|
|
1404
1423
|
end sub
|
|
1405
1424
|
`);
|
|
1406
1425
|
let hover = file.getHover(vscode_languageserver_1.Position.create(5, 24));
|
|
1407
|
-
chai_1.expect(hover.range).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 29));
|
|
1408
|
-
chai_1.expect(hover.contents).to.equal(
|
|
1426
|
+
(0, chai_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 29));
|
|
1427
|
+
(0, chai_1.expect)(hover.contents).to.equal([
|
|
1428
|
+
'```brightscript',
|
|
1429
|
+
'sub (name as string) as void',
|
|
1430
|
+
'```'
|
|
1431
|
+
].join('\n'));
|
|
1432
|
+
});
|
|
1433
|
+
it('does not crash when hovering on built-in functions', async () => {
|
|
1434
|
+
let file = program.setFile('source/main.brs', `
|
|
1435
|
+
function doUcase(text)
|
|
1436
|
+
return ucase(text)
|
|
1437
|
+
end function
|
|
1438
|
+
`);
|
|
1439
|
+
(0, chai_1.expect)((await program.getHover(file.srcPath, vscode_languageserver_1.Position.create(2, 30))).contents).to.equal([
|
|
1440
|
+
'```brightscript',
|
|
1441
|
+
'function UCase(s as string) as string',
|
|
1442
|
+
'```'
|
|
1443
|
+
].join('\n'));
|
|
1444
|
+
});
|
|
1445
|
+
it('does not crash when hovering on object method call', async () => {
|
|
1446
|
+
let file = program.setFile('source/main.brs', `
|
|
1447
|
+
function getInstr(url, text)
|
|
1448
|
+
return url.instr(text)
|
|
1449
|
+
end function
|
|
1450
|
+
`);
|
|
1451
|
+
(0, chai_1.expect)((await program.getHover(file.srcPath, vscode_languageserver_1.Position.create(2, 35))).contents).to.equal([
|
|
1452
|
+
'```brightscript',
|
|
1453
|
+
'instr as dynamic',
|
|
1454
|
+
'```'
|
|
1455
|
+
].join('\n'));
|
|
1409
1456
|
});
|
|
1410
1457
|
it('finds function hover in file scope', () => {
|
|
1411
1458
|
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -1418,8 +1465,12 @@ describe('BrsFile', () => {
|
|
|
1418
1465
|
end sub
|
|
1419
1466
|
`);
|
|
1420
1467
|
let hover = file.getHover(vscode_languageserver_1.Position.create(2, 25));
|
|
1421
|
-
chai_1.expect(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 29));
|
|
1422
|
-
chai_1.expect(hover.contents).to.equal(
|
|
1468
|
+
(0, chai_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 29));
|
|
1469
|
+
(0, chai_1.expect)(hover.contents).to.equal([
|
|
1470
|
+
'```brightscript',
|
|
1471
|
+
'sub sayMyName() as void',
|
|
1472
|
+
'```'
|
|
1473
|
+
].join('\n'));
|
|
1423
1474
|
});
|
|
1424
1475
|
it('finds function hover in scope', () => {
|
|
1425
1476
|
let rootDir = process.cwd();
|
|
@@ -1437,9 +1488,55 @@ describe('BrsFile', () => {
|
|
|
1437
1488
|
end sub
|
|
1438
1489
|
`);
|
|
1439
1490
|
let hover = mainFile.getHover(vscode_languageserver_1.Position.create(2, 25));
|
|
1440
|
-
chai_1.expect(hover).to.exist;
|
|
1441
|
-
chai_1.expect(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 29));
|
|
1442
|
-
chai_1.expect(hover.contents).to.equal(
|
|
1491
|
+
(0, chai_1.expect)(hover).to.exist;
|
|
1492
|
+
(0, chai_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 29));
|
|
1493
|
+
(0, chai_1.expect)(hover.contents).to.equal([
|
|
1494
|
+
'```brightscript',
|
|
1495
|
+
'sub sayMyName(name as string) as void',
|
|
1496
|
+
'```'
|
|
1497
|
+
].join('\n'));
|
|
1498
|
+
});
|
|
1499
|
+
it('includes markdown comments in hover.', async () => {
|
|
1500
|
+
let rootDir = process.cwd();
|
|
1501
|
+
program = new Program_1.Program({
|
|
1502
|
+
rootDir: rootDir
|
|
1503
|
+
});
|
|
1504
|
+
const file = program.setFile('source/lib.brs', `
|
|
1505
|
+
'
|
|
1506
|
+
' The main function
|
|
1507
|
+
'
|
|
1508
|
+
sub main()
|
|
1509
|
+
log("hello")
|
|
1510
|
+
end sub
|
|
1511
|
+
|
|
1512
|
+
'
|
|
1513
|
+
' Prints a message to the log.
|
|
1514
|
+
' Works with *markdown* **content**
|
|
1515
|
+
'
|
|
1516
|
+
sub log(message as string)
|
|
1517
|
+
print message
|
|
1518
|
+
end sub
|
|
1519
|
+
`);
|
|
1520
|
+
//hover over log("hello")
|
|
1521
|
+
(0, chai_1.expect)((await program.getHover(file.srcPath, vscode_languageserver_1.Position.create(5, 22))).contents).to.equal([
|
|
1522
|
+
'```brightscript',
|
|
1523
|
+
'sub log(message as string) as void',
|
|
1524
|
+
'```',
|
|
1525
|
+
'***',
|
|
1526
|
+
'',
|
|
1527
|
+
' Prints a message to the log.',
|
|
1528
|
+
' Works with *markdown* **content**',
|
|
1529
|
+
''
|
|
1530
|
+
].join('\n'));
|
|
1531
|
+
//hover over sub ma|in()
|
|
1532
|
+
(0, chai_1.expect)((await program.getHover(file.srcPath, vscode_languageserver_1.Position.create(4, 22))).contents).to.equal((0, testHelpers_spec_1.trim) `
|
|
1533
|
+
\`\`\`brightscript
|
|
1534
|
+
sub main() as void
|
|
1535
|
+
\`\`\`
|
|
1536
|
+
***
|
|
1537
|
+
|
|
1538
|
+
The main function
|
|
1539
|
+
`);
|
|
1443
1540
|
});
|
|
1444
1541
|
it('handles mixed case `then` partions of conditionals', () => {
|
|
1445
1542
|
let mainFile = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
@@ -1449,7 +1546,7 @@ describe('BrsFile', () => {
|
|
|
1449
1546
|
end if
|
|
1450
1547
|
end sub
|
|
1451
1548
|
`);
|
|
1452
|
-
|
|
1549
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(mainFile);
|
|
1453
1550
|
mainFile = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
1454
1551
|
sub Main()
|
|
1455
1552
|
if true Then
|
|
@@ -1457,7 +1554,7 @@ describe('BrsFile', () => {
|
|
|
1457
1554
|
end if
|
|
1458
1555
|
end sub
|
|
1459
1556
|
`);
|
|
1460
|
-
|
|
1557
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(mainFile);
|
|
1461
1558
|
mainFile = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
1462
1559
|
sub Main()
|
|
1463
1560
|
if true THEN
|
|
@@ -1465,7 +1562,7 @@ describe('BrsFile', () => {
|
|
|
1465
1562
|
end if
|
|
1466
1563
|
end sub
|
|
1467
1564
|
`);
|
|
1468
|
-
|
|
1565
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(mainFile);
|
|
1469
1566
|
});
|
|
1470
1567
|
it('displays the context from multiple scopes', () => {
|
|
1471
1568
|
let commonFile = program.setFile('source/common.brs', `
|
|
@@ -1479,8 +1576,8 @@ describe('BrsFile', () => {
|
|
|
1479
1576
|
return "apple"
|
|
1480
1577
|
end function
|
|
1481
1578
|
`);
|
|
1482
|
-
chai_1.expect(scope1File.getDiagnostics()).to.be.lengthOf(0);
|
|
1483
|
-
program.setFile('components/comp1/comp1.xml', testHelpers_spec_1.trim `
|
|
1579
|
+
(0, chai_1.expect)(scope1File.getDiagnostics()).to.be.lengthOf(0);
|
|
1580
|
+
program.setFile('components/comp1/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
1484
1581
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1485
1582
|
<component name="Component1" extends="Group">
|
|
1486
1583
|
<script type="text/brightscript" uri="scope1.brs" />
|
|
@@ -1492,8 +1589,8 @@ describe('BrsFile', () => {
|
|
|
1492
1589
|
return 3.14
|
|
1493
1590
|
end function
|
|
1494
1591
|
`);
|
|
1495
|
-
chai_1.expect(scope2File.getDiagnostics()).to.be.lengthOf(0);
|
|
1496
|
-
program.setFile('components/comp2/comp2.xml', testHelpers_spec_1.trim `
|
|
1592
|
+
(0, chai_1.expect)(scope2File.getDiagnostics()).to.be.lengthOf(0);
|
|
1593
|
+
program.setFile('components/comp2/comp2.xml', (0, testHelpers_spec_1.trim) `
|
|
1497
1594
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1498
1595
|
<component name="Component2" extends="Group">
|
|
1499
1596
|
<script type="text/brightscript" uri="scope2.brs" />
|
|
@@ -1502,11 +1599,61 @@ describe('BrsFile', () => {
|
|
|
1502
1599
|
`);
|
|
1503
1600
|
program.validate();
|
|
1504
1601
|
let funcCallHover = commonFile.getHover(vscode_languageserver_1.Position.create(2, 27));
|
|
1505
|
-
chai_1.expect(funcCallHover).to.
|
|
1506
|
-
|
|
1602
|
+
(0, chai_1.expect)(funcCallHover === null || funcCallHover === void 0 ? void 0 : funcCallHover.contents).to.equal([
|
|
1603
|
+
'```brightscript',
|
|
1604
|
+
'function getPi() as string | function getPi() as float | getPi as uninitialized',
|
|
1605
|
+
'```'
|
|
1606
|
+
].join('\n'));
|
|
1507
1607
|
let variableHover = commonFile.getHover(vscode_languageserver_1.Position.create(3, 27));
|
|
1508
|
-
chai_1.expect(variableHover).to.
|
|
1509
|
-
|
|
1608
|
+
(0, chai_1.expect)(variableHover === null || variableHover === void 0 ? void 0 : variableHover.contents).to.equal([
|
|
1609
|
+
'```brightscript',
|
|
1610
|
+
'pi as string | pi as float | pi as uninitialized',
|
|
1611
|
+
'```'
|
|
1612
|
+
].join('\n'));
|
|
1613
|
+
});
|
|
1614
|
+
it('finds function with custom types as parameters and return types', () => {
|
|
1615
|
+
let file = program.setFile('source/main.bs', `
|
|
1616
|
+
sub main()
|
|
1617
|
+
k = new MyKlass()
|
|
1618
|
+
processMyKlass(k)
|
|
1619
|
+
end sub
|
|
1620
|
+
|
|
1621
|
+
function processMyKlass(data as MyKlass) as MyKlass
|
|
1622
|
+
return data
|
|
1623
|
+
end function
|
|
1624
|
+
|
|
1625
|
+
class MyKlass
|
|
1626
|
+
end class
|
|
1627
|
+
`);
|
|
1628
|
+
let hover = file.getHover(vscode_languageserver_1.Position.create(3, 29));
|
|
1629
|
+
(0, chai_1.expect)(hover).to.exist;
|
|
1630
|
+
(0, chai_1.expect)(hover.contents).to.equal([
|
|
1631
|
+
'```brightscript',
|
|
1632
|
+
'function processMyKlass(data as MyKlass) as MyKlass',
|
|
1633
|
+
'```'
|
|
1634
|
+
].join('\n'));
|
|
1635
|
+
});
|
|
1636
|
+
it('finds function with arrays as parameters and return types', () => {
|
|
1637
|
+
let file = program.setFile('source/main.bs', `
|
|
1638
|
+
sub main()
|
|
1639
|
+
k = new MyKlass()
|
|
1640
|
+
processData([k])
|
|
1641
|
+
end sub
|
|
1642
|
+
|
|
1643
|
+
function processData(data as MyKlass[]) as MyKlass[]
|
|
1644
|
+
return data
|
|
1645
|
+
end function
|
|
1646
|
+
|
|
1647
|
+
class MyKlass
|
|
1648
|
+
end class
|
|
1649
|
+
`);
|
|
1650
|
+
let hover = file.getHover(vscode_languageserver_1.Position.create(3, 29));
|
|
1651
|
+
(0, chai_1.expect)(hover).to.exist;
|
|
1652
|
+
(0, chai_1.expect)(hover.contents).to.equal([
|
|
1653
|
+
'```brightscript',
|
|
1654
|
+
'function processData(data as MyKlass[]) as MyKlass[]',
|
|
1655
|
+
'```'
|
|
1656
|
+
].join('\n'));
|
|
1510
1657
|
});
|
|
1511
1658
|
});
|
|
1512
1659
|
it('does not throw when encountering incomplete import statement', () => {
|
|
@@ -1806,18 +1953,18 @@ describe('BrsFile', () => {
|
|
|
1806
1953
|
return consumer.generatedPositionFor({
|
|
1807
1954
|
line: 3,
|
|
1808
1955
|
column: 0,
|
|
1809
|
-
source: util_1.standardizePath `${rootDir}/source/main.bs`,
|
|
1956
|
+
source: (0, util_1.standardizePath) `${rootDir}/source/main.bs`,
|
|
1810
1957
|
bias: source_map_1.SourceMapConsumer.LEAST_UPPER_BOUND
|
|
1811
1958
|
});
|
|
1812
1959
|
});
|
|
1813
|
-
chai_1.expect(location.line).to.eql(2);
|
|
1814
|
-
chai_1.expect(location.column).eql(4);
|
|
1960
|
+
(0, chai_1.expect)(location.line).to.eql(2);
|
|
1961
|
+
(0, chai_1.expect)(location.column).eql(4);
|
|
1815
1962
|
});
|
|
1816
1963
|
it('computes correct locations for sourcemap', async () => {
|
|
1817
1964
|
let source = `function abc(name)\n firstName = name\nend function`;
|
|
1818
|
-
let tokens =
|
|
1965
|
+
let tokens = Lexer_1.Lexer.scan(source).tokens
|
|
1819
1966
|
//remove newlines and EOF
|
|
1820
|
-
.filter(x => x.kind !==
|
|
1967
|
+
.filter(x => x.kind !== TokenKind_1.TokenKind.Eof && x.kind !== TokenKind_1.TokenKind.Newline);
|
|
1821
1968
|
program.options.sourceMap = true;
|
|
1822
1969
|
let result = testTranspile(source, source, 'none');
|
|
1823
1970
|
//load the source map
|
|
@@ -1839,7 +1986,7 @@ describe('BrsFile', () => {
|
|
|
1839
1986
|
originalPosition.line - 1, originalPosition.column)
|
|
1840
1987
|
};
|
|
1841
1988
|
});
|
|
1842
|
-
chai_1.expect(sourcemapResult).to.eql(tokenResult);
|
|
1989
|
+
(0, chai_1.expect)(sourcemapResult).to.eql(tokenResult);
|
|
1843
1990
|
});
|
|
1844
1991
|
});
|
|
1845
1992
|
it('handles empty if block', () => {
|
|
@@ -2033,22 +2180,22 @@ describe('BrsFile', () => {
|
|
|
2033
2180
|
`);
|
|
2034
2181
|
});
|
|
2035
2182
|
it('simple mapped files include a reference to the source map', () => {
|
|
2036
|
-
let file = program.setFile('source/logger.brs', testHelpers_spec_1.trim `
|
|
2183
|
+
let file = program.setFile('source/logger.brs', (0, testHelpers_spec_1.trim) `
|
|
2037
2184
|
sub logInfo()
|
|
2038
2185
|
end sub
|
|
2039
2186
|
`);
|
|
2040
2187
|
file.needsTranspiled = false;
|
|
2041
2188
|
const { code } = file.transpile();
|
|
2042
|
-
chai_1.expect(code.endsWith(`'//# sourceMappingURL=./logger.brs.map`)).to.be.true;
|
|
2189
|
+
(0, chai_1.expect)(code.endsWith(`'//# sourceMappingURL=./logger.brs.map`)).to.be.true;
|
|
2043
2190
|
});
|
|
2044
2191
|
it('AST generated files include a reference to the source map', () => {
|
|
2045
|
-
let file = program.setFile('source/logger.brs', testHelpers_spec_1.trim `
|
|
2192
|
+
let file = program.setFile('source/logger.brs', (0, testHelpers_spec_1.trim) `
|
|
2046
2193
|
sub logInfo()
|
|
2047
2194
|
end sub
|
|
2048
2195
|
`);
|
|
2049
2196
|
file.needsTranspiled = true;
|
|
2050
2197
|
const { code } = file.transpile();
|
|
2051
|
-
chai_1.expect(code.endsWith(`'//# sourceMappingURL=./logger.brs.map`)).to.be.true;
|
|
2198
|
+
(0, chai_1.expect)(code.endsWith(`'//# sourceMappingURL=./logger.brs.map`)).to.be.true;
|
|
2052
2199
|
});
|
|
2053
2200
|
it('replaces custom types in parameter types and return types', () => {
|
|
2054
2201
|
program.setFile('source/SomeKlass.bs', `
|
|
@@ -2075,14 +2222,13 @@ describe('BrsFile', () => {
|
|
|
2075
2222
|
describe('callfunc operator', () => {
|
|
2076
2223
|
describe('transpile', () => {
|
|
2077
2224
|
it('does not produce diagnostics', () => {
|
|
2078
|
-
var _a;
|
|
2079
2225
|
program.setFile('source/main.bs', `
|
|
2080
2226
|
sub main()
|
|
2081
2227
|
someObject@.someFunction(paramObject.value)
|
|
2082
2228
|
end sub
|
|
2083
2229
|
`);
|
|
2084
2230
|
program.validate();
|
|
2085
|
-
|
|
2231
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2086
2232
|
});
|
|
2087
2233
|
it('sets invalid on empty callfunc', () => {
|
|
2088
2234
|
testTranspile(`
|
|
@@ -2122,34 +2268,34 @@ describe('BrsFile', () => {
|
|
|
2122
2268
|
name: 'transform callback',
|
|
2123
2269
|
afterFileParse: onParsed
|
|
2124
2270
|
});
|
|
2125
|
-
file = program.setFile(`
|
|
2271
|
+
file = program.setFile({ src: `absolute_path/file${ext}`, dest: `relative_path/file${ext}` }, `
|
|
2126
2272
|
sub Sum()
|
|
2127
2273
|
print "hello world"
|
|
2128
2274
|
end sub
|
|
2129
2275
|
`);
|
|
2130
|
-
chai_1.expect(file.extension).to.equal(ext);
|
|
2276
|
+
(0, chai_1.expect)(file.extension).to.equal(ext);
|
|
2131
2277
|
return file;
|
|
2132
2278
|
}
|
|
2133
2279
|
it('called for BRS file', () => {
|
|
2134
2280
|
const onParsed = sinon.spy();
|
|
2135
2281
|
parseFileWithCallback('.brs', onParsed);
|
|
2136
|
-
chai_1.expect(onParsed.callCount).to.equal(1);
|
|
2282
|
+
(0, chai_1.expect)(onParsed.callCount).to.equal(1);
|
|
2137
2283
|
});
|
|
2138
2284
|
it('called for BS file', () => {
|
|
2139
2285
|
const onParsed = sinon.spy();
|
|
2140
2286
|
parseFileWithCallback('.bs', onParsed);
|
|
2141
|
-
chai_1.expect(onParsed.callCount).to.equal(1);
|
|
2287
|
+
(0, chai_1.expect)(onParsed.callCount).to.equal(1);
|
|
2142
2288
|
});
|
|
2143
2289
|
});
|
|
2144
2290
|
describe('typedefKey', () => {
|
|
2145
2291
|
it('works for .brs files', () => {
|
|
2146
|
-
chai_1.expect(util_1.standardizePath((program.setFile('source/main.brs', '')).typedefSrcPath)).to.equal(util_1.standardizePath `${rootDir.toLowerCase()}/source/main.d.bs`);
|
|
2292
|
+
(0, chai_1.expect)((0, util_1.standardizePath)((program.setFile('source/main.brs', '')).typedefSrcPath)).to.equal((0, util_1.standardizePath) `${rootDir.toLowerCase()}/source/main.d.bs`);
|
|
2147
2293
|
});
|
|
2148
2294
|
it('returns undefined for files that should not have a typedef', () => {
|
|
2149
|
-
chai_1.expect((program.setFile('source/main.bs', '')).typedefSrcPath).to.be.undefined;
|
|
2150
|
-
chai_1.expect((program.setFile('source/main.d.bs', '')).typedefSrcPath).to.be.undefined;
|
|
2295
|
+
(0, chai_1.expect)((program.setFile('source/main.bs', '')).typedefSrcPath).to.be.undefined;
|
|
2296
|
+
(0, chai_1.expect)((program.setFile('source/main.d.bs', '')).typedefSrcPath).to.be.undefined;
|
|
2151
2297
|
const xmlFile = program.setFile('components/comp.xml', '');
|
|
2152
|
-
chai_1.expect(xmlFile.typedefSrcPath).to.be.undefined;
|
|
2298
|
+
(0, chai_1.expect)(xmlFile.typedefSrcPath).to.be.undefined;
|
|
2153
2299
|
});
|
|
2154
2300
|
});
|
|
2155
2301
|
describe('type definitions', () => {
|
|
@@ -2167,8 +2313,8 @@ describe('BrsFile', () => {
|
|
|
2167
2313
|
`);
|
|
2168
2314
|
const sourceScope = program.getScopeByName('source');
|
|
2169
2315
|
const functionNames = sourceScope.getAllCallables().map(x => x.callable.name);
|
|
2170
|
-
chai_1.expect(functionNames).to.include('main');
|
|
2171
|
-
chai_1.expect(functionNames).not.to.include('speak');
|
|
2316
|
+
(0, chai_1.expect)(functionNames).to.include('main');
|
|
2317
|
+
(0, chai_1.expect)(functionNames).not.to.include('speak');
|
|
2172
2318
|
});
|
|
2173
2319
|
it('reacts to typedef file changes', () => {
|
|
2174
2320
|
let file = program.setFile('source/main.brs', `
|
|
@@ -2177,14 +2323,14 @@ describe('BrsFile', () => {
|
|
|
2177
2323
|
sub speak()
|
|
2178
2324
|
end sub
|
|
2179
2325
|
`);
|
|
2180
|
-
chai_1.expect(file.hasTypedef).to.be.false;
|
|
2181
|
-
chai_1.expect(file.typedefFile).not.to.exist;
|
|
2326
|
+
(0, chai_1.expect)(file.hasTypedef).to.be.false;
|
|
2327
|
+
(0, chai_1.expect)(file.typedefFile).not.to.exist;
|
|
2182
2328
|
program.setFile('source/main.d.bs', `
|
|
2183
2329
|
sub main()
|
|
2184
2330
|
end sub
|
|
2185
2331
|
`);
|
|
2186
|
-
chai_1.expect(file.hasTypedef).to.be.true;
|
|
2187
|
-
chai_1.expect(file.typedefFile).to.exist;
|
|
2332
|
+
(0, chai_1.expect)(file.hasTypedef).to.be.true;
|
|
2333
|
+
(0, chai_1.expect)(file.typedefFile).to.exist;
|
|
2188
2334
|
//add replace file, does it still find the typedef
|
|
2189
2335
|
file = program.setFile('source/main.brs', `
|
|
2190
2336
|
sub main()
|
|
@@ -2192,46 +2338,46 @@ describe('BrsFile', () => {
|
|
|
2192
2338
|
sub speak()
|
|
2193
2339
|
end sub
|
|
2194
2340
|
`);
|
|
2195
|
-
chai_1.expect(file.hasTypedef).to.be.true;
|
|
2196
|
-
chai_1.expect(file.typedefFile).to.exist;
|
|
2197
|
-
program.removeFile(util_1.standardizePath `${rootDir}/source/main.d.bs`);
|
|
2198
|
-
chai_1.expect(file.hasTypedef).to.be.false;
|
|
2199
|
-
chai_1.expect(file.typedefFile).not.to.exist;
|
|
2341
|
+
(0, chai_1.expect)(file.hasTypedef).to.be.true;
|
|
2342
|
+
(0, chai_1.expect)(file.typedefFile).to.exist;
|
|
2343
|
+
program.removeFile((0, util_1.standardizePath) `${rootDir}/source/main.d.bs`);
|
|
2344
|
+
(0, chai_1.expect)(file.hasTypedef).to.be.false;
|
|
2345
|
+
(0, chai_1.expect)(file.typedefFile).not.to.exist;
|
|
2200
2346
|
});
|
|
2201
2347
|
});
|
|
2202
2348
|
describe('typedef', () => {
|
|
2203
2349
|
it('sets typedef path properly', () => {
|
|
2204
|
-
chai_1.expect((program.setFile('source/main1.brs', '')).typedefSrcPath).to.equal(util_1.standardizePath `${rootDir}/source/main1.d.bs`.toLowerCase());
|
|
2205
|
-
chai_1.expect((program.setFile('source/main2.d.bs', '')).typedefSrcPath).to.equal(undefined);
|
|
2206
|
-
chai_1.expect((program.setFile('source/main3.bs', '')).typedefSrcPath).to.equal(undefined);
|
|
2350
|
+
(0, chai_1.expect)((program.setFile('source/main1.brs', '')).typedefSrcPath).to.equal((0, util_1.standardizePath) `${rootDir}/source/main1.d.bs`.toLowerCase());
|
|
2351
|
+
(0, chai_1.expect)((program.setFile('source/main2.d.bs', '')).typedefSrcPath).to.equal(undefined);
|
|
2352
|
+
(0, chai_1.expect)((program.setFile('source/main3.bs', '')).typedefSrcPath).to.equal(undefined);
|
|
2207
2353
|
//works for dest with `.brs` extension
|
|
2208
|
-
chai_1.expect((program.setFile({ src: 'source/main4.bs', dest: 'source/main4.brs' }, '')).typedefSrcPath).to.equal(undefined);
|
|
2354
|
+
(0, chai_1.expect)((program.setFile({ src: 'source/main4.bs', dest: 'source/main4.brs' }, '')).typedefSrcPath).to.equal(undefined);
|
|
2209
2355
|
});
|
|
2210
2356
|
it('does not link when missing from program', () => {
|
|
2211
2357
|
const file = program.setFile('source/main.brs', ``);
|
|
2212
|
-
chai_1.expect(file.typedefFile).not.to.exist;
|
|
2358
|
+
(0, chai_1.expect)(file.typedefFile).not.to.exist;
|
|
2213
2359
|
});
|
|
2214
2360
|
it('links typedef when added BEFORE .brs file', () => {
|
|
2215
2361
|
const typedef = program.setFile('source/main.d.bs', ``);
|
|
2216
2362
|
const file = program.setFile('source/main.brs', ``);
|
|
2217
|
-
chai_1.expect(file.typedefFile).to.equal(typedef);
|
|
2363
|
+
(0, chai_1.expect)(file.typedefFile).to.equal(typedef);
|
|
2218
2364
|
});
|
|
2219
2365
|
it('links typedef when added AFTER .brs file', () => {
|
|
2220
2366
|
const file = program.setFile('source/main.brs', ``);
|
|
2221
2367
|
const typedef = program.setFile('source/main.d.bs', ``);
|
|
2222
|
-
chai_1.expect(file.typedefFile).to.eql(typedef);
|
|
2368
|
+
(0, chai_1.expect)(file.typedefFile).to.eql(typedef);
|
|
2223
2369
|
});
|
|
2224
2370
|
it('removes typedef link when typedef is removed', () => {
|
|
2225
2371
|
const typedef = program.setFile('source/main.d.bs', ``);
|
|
2226
2372
|
const file = program.setFile('source/main.brs', ``);
|
|
2227
2373
|
program.removeFile(typedef.srcPath);
|
|
2228
|
-
chai_1.expect(file.typedefFile).to.be.undefined;
|
|
2374
|
+
(0, chai_1.expect)(file.typedefFile).to.be.undefined;
|
|
2229
2375
|
});
|
|
2230
2376
|
});
|
|
2231
2377
|
describe('getTypedef', () => {
|
|
2232
2378
|
function testTypedef(original, expected) {
|
|
2233
2379
|
let file = program.setFile('source/main.brs', original);
|
|
2234
|
-
chai_1.expect(file.getTypedef()).to.eql(expected);
|
|
2380
|
+
(0, chai_1.expect)(file.getTypedef()).to.eql(expected);
|
|
2235
2381
|
}
|
|
2236
2382
|
it('includes namespace on extend class names', () => {
|
|
2237
2383
|
testTypedef(`
|
|
@@ -2240,7 +2386,7 @@ describe('BrsFile', () => {
|
|
|
2240
2386
|
end class
|
|
2241
2387
|
class Duck extends Bird
|
|
2242
2388
|
end class
|
|
2243
|
-
end namespace`, testHelpers_spec_1.trim `
|
|
2389
|
+
end namespace`, (0, testHelpers_spec_1.trim) `
|
|
2244
2390
|
namespace AnimalKingdom
|
|
2245
2391
|
class Bird
|
|
2246
2392
|
end class
|
|
@@ -2254,7 +2400,7 @@ describe('BrsFile', () => {
|
|
|
2254
2400
|
sub main(param1 as string)
|
|
2255
2401
|
print "main"
|
|
2256
2402
|
end sub
|
|
2257
|
-
`, testHelpers_spec_1.trim `
|
|
2403
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2258
2404
|
sub main(param1 as string)
|
|
2259
2405
|
end sub
|
|
2260
2406
|
`);
|
|
@@ -2277,7 +2423,7 @@ describe('BrsFile', () => {
|
|
|
2277
2423
|
end function
|
|
2278
2424
|
end class
|
|
2279
2425
|
end namespace
|
|
2280
|
-
`, testHelpers_spec_1.trim `
|
|
2426
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2281
2427
|
namespace test
|
|
2282
2428
|
@an
|
|
2283
2429
|
@anFunc("value")
|
|
@@ -2298,7 +2444,7 @@ describe('BrsFile', () => {
|
|
|
2298
2444
|
it('includes import statements', () => {
|
|
2299
2445
|
testTypedef(`
|
|
2300
2446
|
import "pkg:/source/lib.brs"
|
|
2301
|
-
`, testHelpers_spec_1.trim `
|
|
2447
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2302
2448
|
import "pkg:/source/lib.brs"
|
|
2303
2449
|
`);
|
|
2304
2450
|
});
|
|
@@ -2312,7 +2458,7 @@ describe('BrsFile', () => {
|
|
|
2312
2458
|
sub logInfo()
|
|
2313
2459
|
end sub
|
|
2314
2460
|
end namespace
|
|
2315
|
-
`, testHelpers_spec_1.trim `
|
|
2461
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2316
2462
|
namespace Name
|
|
2317
2463
|
sub logInfo()
|
|
2318
2464
|
end sub
|
|
@@ -2341,7 +2487,7 @@ describe('BrsFile', () => {
|
|
|
2341
2487
|
end sub
|
|
2342
2488
|
end class
|
|
2343
2489
|
end namespace
|
|
2344
|
-
`, testHelpers_spec_1.trim `
|
|
2490
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2345
2491
|
class Person
|
|
2346
2492
|
public name as string
|
|
2347
2493
|
public age as integer
|
|
@@ -2364,7 +2510,7 @@ describe('BrsFile', () => {
|
|
|
2364
2510
|
public firstName = invalid
|
|
2365
2511
|
public lastName as string = invalid
|
|
2366
2512
|
end class
|
|
2367
|
-
`, testHelpers_spec_1.trim `
|
|
2513
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2368
2514
|
class Human
|
|
2369
2515
|
public firstName as dynamic
|
|
2370
2516
|
public lastName as string
|
|
@@ -2383,7 +2529,7 @@ describe('BrsFile', () => {
|
|
|
2383
2529
|
super(name)
|
|
2384
2530
|
end sub
|
|
2385
2531
|
end class
|
|
2386
|
-
`, testHelpers_spec_1.trim `
|
|
2532
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2387
2533
|
class Human
|
|
2388
2534
|
sub new(name as string)
|
|
2389
2535
|
end sub
|
|
@@ -2410,7 +2556,7 @@ describe('BrsFile', () => {
|
|
|
2410
2556
|
return m.lastName
|
|
2411
2557
|
end function
|
|
2412
2558
|
end class
|
|
2413
|
-
`, testHelpers_spec_1.trim `
|
|
2559
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2414
2560
|
class Human
|
|
2415
2561
|
public firstName as string
|
|
2416
2562
|
protected middleName as string
|
|
@@ -2436,7 +2582,7 @@ describe('BrsFile', () => {
|
|
|
2436
2582
|
print "Hello Dog"
|
|
2437
2583
|
end sub
|
|
2438
2584
|
end class
|
|
2439
|
-
`, testHelpers_spec_1.trim `
|
|
2585
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2440
2586
|
class Animal
|
|
2441
2587
|
public sub speak()
|
|
2442
2588
|
end sub
|
|
@@ -2463,7 +2609,7 @@ describe('BrsFile', () => {
|
|
|
2463
2609
|
end sub
|
|
2464
2610
|
end class
|
|
2465
2611
|
end namespace
|
|
2466
|
-
`, testHelpers_spec_1.trim `
|
|
2612
|
+
`, (0, testHelpers_spec_1.trim) `
|
|
2467
2613
|
namespace NameA
|
|
2468
2614
|
class Human
|
|
2469
2615
|
sub new(name as string)
|
|
@@ -2490,25 +2636,25 @@ describe('BrsFile', () => {
|
|
|
2490
2636
|
file['_parser'] = undefined;
|
|
2491
2637
|
//force the file to get a new instance of parser
|
|
2492
2638
|
const newParser = file.parser;
|
|
2493
|
-
chai_1.expect(newParser).to.exist.and.to.not.equal(parser);
|
|
2639
|
+
(0, chai_1.expect)(newParser).to.exist.and.to.not.equal(parser);
|
|
2494
2640
|
//reference shouldn't change in subsequent accesses
|
|
2495
|
-
chai_1.expect(file.parser).to.equal(newParser);
|
|
2641
|
+
(0, chai_1.expect)(file.parser).to.equal(newParser);
|
|
2496
2642
|
});
|
|
2497
2643
|
it('call parse when previously skipped', () => {
|
|
2498
|
-
program.setFile('source/main.d.bs', `
|
|
2644
|
+
program.setFile('source/main.d.bs', `'typedef
|
|
2499
2645
|
sub main()
|
|
2500
2646
|
end sub
|
|
2501
2647
|
`);
|
|
2502
|
-
const file = program.setFile('source/main.brs', `
|
|
2648
|
+
const file = program.setFile('source/main.brs', `'source
|
|
2503
2649
|
sub main()
|
|
2504
2650
|
end sub
|
|
2505
2651
|
`);
|
|
2506
2652
|
//no functions should be found since the parser was skipped
|
|
2507
|
-
chai_1.expect(file['_parser']).to.not.exist;
|
|
2653
|
+
(0, chai_1.expect)(file['_parser']).to.not.exist;
|
|
2508
2654
|
const stub = sinon.stub(file, 'parse').callThrough();
|
|
2509
2655
|
//`file.parser` is a getter, so that should force the parse to occur
|
|
2510
|
-
chai_1.expect(file.parser.references.functionStatements).to.be.lengthOf(1);
|
|
2511
|
-
chai_1.expect(stub.called).to.be.true;
|
|
2656
|
+
(0, chai_1.expect)(file.parser.references.functionStatements).to.be.lengthOf(1);
|
|
2657
|
+
(0, chai_1.expect)(stub.called).to.be.true;
|
|
2512
2658
|
//parse should have been called
|
|
2513
2659
|
});
|
|
2514
2660
|
});
|
|
@@ -2556,5 +2702,207 @@ describe('BrsFile', () => {
|
|
|
2556
2702
|
testPluginTranspile();
|
|
2557
2703
|
});
|
|
2558
2704
|
});
|
|
2705
|
+
describe('getSymbolTypeFromToken', () => {
|
|
2706
|
+
function checkSymbolLookups(file, funcExpr, lookups) {
|
|
2707
|
+
const mainScope = program.getScopesForFile(file)[0];
|
|
2708
|
+
mainScope.linkSymbolTable();
|
|
2709
|
+
for (const lookup of lookups) {
|
|
2710
|
+
const position = vscode_languageserver_1.Position.create(lookup.line, lookup.col);
|
|
2711
|
+
const token = file.parser.getTokenAt(position);
|
|
2712
|
+
const symbol = file.getSymbolTypeFromToken(token, funcExpr, mainScope);
|
|
2713
|
+
const context = {
|
|
2714
|
+
file: file,
|
|
2715
|
+
scope: mainScope,
|
|
2716
|
+
position: position
|
|
2717
|
+
};
|
|
2718
|
+
(0, chai_1.expect)(symbol.expandedTokenText).to.equal(lookup.name);
|
|
2719
|
+
(0, chai_1.expect)(symbol.type.equals(lookup.type, context)).be.true;
|
|
2720
|
+
}
|
|
2721
|
+
}
|
|
2722
|
+
it('gets simple types based on the containing function expression', () => {
|
|
2723
|
+
const file = program.setFile('source/main.bs', `
|
|
2724
|
+
sub doSomething(aInt as integer, aFloat as float, aStr as string, aBool as boolean, aObj as object)
|
|
2725
|
+
print aInt
|
|
2726
|
+
print aFloat
|
|
2727
|
+
print aStr
|
|
2728
|
+
print aBool
|
|
2729
|
+
print aObj
|
|
2730
|
+
end sub
|
|
2731
|
+
`);
|
|
2732
|
+
const funcExpr = file.parser.references.functionExpressions[0];
|
|
2733
|
+
const lookups = [
|
|
2734
|
+
{ line: 2, col: 28, name: 'aInt', type: new IntegerType_1.IntegerType() },
|
|
2735
|
+
{ line: 3, col: 28, name: 'aFloat', type: new FloatType_1.FloatType() },
|
|
2736
|
+
{ line: 4, col: 28, name: 'aStr', type: new StringType_1.StringType() },
|
|
2737
|
+
{ line: 5, col: 28, name: 'aBool', type: new BooleanType_1.BooleanType() },
|
|
2738
|
+
{ line: 6, col: 28, name: 'aObj', type: new ObjectType_1.ObjectType() }
|
|
2739
|
+
];
|
|
2740
|
+
checkSymbolLookups(file, funcExpr, lookups);
|
|
2741
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2742
|
+
});
|
|
2743
|
+
it('gets custom types based on the containing function expression', () => {
|
|
2744
|
+
const file = program.setFile('source/main.bs', `
|
|
2745
|
+
sub doSomething(klass as MyKlass)
|
|
2746
|
+
print klass
|
|
2747
|
+
end sub
|
|
2748
|
+
|
|
2749
|
+
class MyKlass
|
|
2750
|
+
end class
|
|
2751
|
+
`);
|
|
2752
|
+
const mainScope = program.getScopesForFile(file)[0];
|
|
2753
|
+
mainScope.linkSymbolTable();
|
|
2754
|
+
const funcExpr = file.parser.references.functionExpressions[0];
|
|
2755
|
+
const token = file.parser.getTokenAt(vscode_languageserver_1.Position.create(2, 28));
|
|
2756
|
+
const symbol = file.getSymbolTypeFromToken(token, funcExpr, mainScope);
|
|
2757
|
+
(0, chai_1.expect)(symbol.expandedTokenText).to.equal('klass');
|
|
2758
|
+
const classStmt = file.parser.references.classStatements[0];
|
|
2759
|
+
(0, chai_1.expect)(classStmt.name.text).to.equal('MyKlass');
|
|
2760
|
+
(0, chai_1.expect)(symbol.type.isAssignableTo(classStmt.getCustomType())).be.true;
|
|
2761
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2762
|
+
});
|
|
2763
|
+
it('gets types of properties of a klass', () => {
|
|
2764
|
+
const file = program.setFile('source/main.bs', `
|
|
2765
|
+
sub doSomething()
|
|
2766
|
+
klass = new MyKlass()
|
|
2767
|
+
print klass.name
|
|
2768
|
+
print klass.age
|
|
2769
|
+
' verify case insensitivity
|
|
2770
|
+
print KLASS.NAME
|
|
2771
|
+
print klass.AGE
|
|
2772
|
+
end sub
|
|
2773
|
+
|
|
2774
|
+
class MyKlass
|
|
2775
|
+
name as string
|
|
2776
|
+
age as integer
|
|
2777
|
+
end class
|
|
2778
|
+
`);
|
|
2779
|
+
const funcExpr = file.parser.references.functionExpressions[0];
|
|
2780
|
+
const lookups = [
|
|
2781
|
+
{ line: 3, col: 35, name: 'MyKlass.name', type: new StringType_1.StringType() },
|
|
2782
|
+
{ line: 4, col: 35, name: 'MyKlass.age', type: new IntegerType_1.IntegerType() }
|
|
2783
|
+
];
|
|
2784
|
+
checkSymbolLookups(file, funcExpr, lookups);
|
|
2785
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2786
|
+
});
|
|
2787
|
+
it('gets types of properties of an object', () => {
|
|
2788
|
+
const file = program.setFile('source/main.bs', `
|
|
2789
|
+
sub doSomething()
|
|
2790
|
+
obj = { name: "Joe", age: 37}
|
|
2791
|
+
print obj.name
|
|
2792
|
+
print obj.age
|
|
2793
|
+
end sub
|
|
2794
|
+
`);
|
|
2795
|
+
const funcExpr = file.parser.references.functionExpressions[0];
|
|
2796
|
+
const lookups = [
|
|
2797
|
+
{ line: 3, col: 32, name: 'obj.name', type: new StringType_1.StringType() },
|
|
2798
|
+
{ line: 4, col: 32, name: 'obj.age', type: new IntegerType_1.IntegerType() }
|
|
2799
|
+
];
|
|
2800
|
+
checkSymbolLookups(file, funcExpr, lookups);
|
|
2801
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2802
|
+
});
|
|
2803
|
+
it('gets return types of functions', () => {
|
|
2804
|
+
const file = program.setFile('source/main.bs', `
|
|
2805
|
+
sub doSomething()
|
|
2806
|
+
pi = makeKlass().getSelf().getPi()
|
|
2807
|
+
print pi
|
|
2808
|
+
end sub
|
|
2809
|
+
|
|
2810
|
+
function makeKlass() as MyKlass
|
|
2811
|
+
return new MyKlass()
|
|
2812
|
+
end function
|
|
2813
|
+
|
|
2814
|
+
class MyKlass
|
|
2815
|
+
function getPi() as float
|
|
2816
|
+
return 3.14
|
|
2817
|
+
end function
|
|
2818
|
+
|
|
2819
|
+
function getSelf() as MyKlass
|
|
2820
|
+
return m
|
|
2821
|
+
end function
|
|
2822
|
+
end class
|
|
2823
|
+
`);
|
|
2824
|
+
const mainScope = program.getScopesForFile(file)[0];
|
|
2825
|
+
mainScope.linkSymbolTable();
|
|
2826
|
+
const funcExpr = file.parser.references.functionExpressions[0];
|
|
2827
|
+
const klassMemberTable = file.parser.references.classStatements[0].memberTable;
|
|
2828
|
+
const lookups = [
|
|
2829
|
+
{ line: 2, col: 31, name: 'makeKlass', type: file.parser.references.functionExpressions[1].getFunctionType() },
|
|
2830
|
+
// The expanded text for this should probably be MyKlass.getSelf()
|
|
2831
|
+
{ line: 2, col: 41, name: 'MyKlass.MyKlass', type: klassMemberTable.getSymbol('getSelf')[0].type },
|
|
2832
|
+
{ line: 2, col: 51, name: 'MyKlass.getPi', type: klassMemberTable.getSymbol('getPi')[0].type },
|
|
2833
|
+
{ line: 3, col: 28, name: 'pi', type: new FloatType_1.FloatType() }
|
|
2834
|
+
];
|
|
2835
|
+
checkSymbolLookups(file, funcExpr, lookups);
|
|
2836
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2837
|
+
});
|
|
2838
|
+
it('gets types of elements of arrays', () => {
|
|
2839
|
+
const file = program.setFile('source/main.bs', `
|
|
2840
|
+
sub doSomething(words as string[], klasses as MyKlass[])
|
|
2841
|
+
myWord = words[0]
|
|
2842
|
+
pi = klasses[0].getPi()
|
|
2843
|
+
print myWord
|
|
2844
|
+
print pi
|
|
2845
|
+
end sub
|
|
2846
|
+
|
|
2847
|
+
class MyKlass
|
|
2848
|
+
function getPi() as float
|
|
2849
|
+
return 3.14
|
|
2850
|
+
end function
|
|
2851
|
+
end class
|
|
2852
|
+
`);
|
|
2853
|
+
const mainScope = program.getScopesForFile(file)[0];
|
|
2854
|
+
mainScope.linkSymbolTable();
|
|
2855
|
+
const funcExpr = file.parser.references.functionExpressions[0];
|
|
2856
|
+
const klassMemberTable = file.parser.references.classStatements[0].memberTable;
|
|
2857
|
+
const lookups = [
|
|
2858
|
+
{ line: 2, col: 34, name: 'words', type: new ArrayType_1.ArrayType(new StringType_1.StringType()) },
|
|
2859
|
+
{ line: 3, col: 41, name: 'MyKlass.getPi', type: klassMemberTable.getSymbol('getPi')[0].type },
|
|
2860
|
+
{ line: 4, col: 28, name: 'myWord', type: new StringType_1.StringType() },
|
|
2861
|
+
{ line: 5, col: 28, name: 'pi', type: new FloatType_1.FloatType() }
|
|
2862
|
+
];
|
|
2863
|
+
checkSymbolLookups(file, funcExpr, lookups);
|
|
2864
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2865
|
+
});
|
|
2866
|
+
it('gets types of elements of arrays via square bracket reference', () => {
|
|
2867
|
+
const file = program.setFile('source/main.bs', `
|
|
2868
|
+
function printFirst(numbers as float[]) as float
|
|
2869
|
+
firstFloat = numbers[0]
|
|
2870
|
+
print firstFloat
|
|
2871
|
+
return firstFloat
|
|
2872
|
+
end function
|
|
2873
|
+
`);
|
|
2874
|
+
const mainScope = program.getScopesForFile(file)[0];
|
|
2875
|
+
mainScope.linkSymbolTable();
|
|
2876
|
+
const funcExpr = file.parser.references.functionExpressions[0];
|
|
2877
|
+
const lookups = [
|
|
2878
|
+
{ line: 2, col: 26, name: 'firstFloat', type: new FloatType_1.FloatType() },
|
|
2879
|
+
{ line: 3, col: 32, name: 'firstFloat', type: new FloatType_1.FloatType() }
|
|
2880
|
+
];
|
|
2881
|
+
checkSymbolLookups(file, funcExpr, lookups);
|
|
2882
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2883
|
+
});
|
|
2884
|
+
it('gets types of elements of arrays after for each', () => {
|
|
2885
|
+
const file = program.setFile('source/main.bs', `
|
|
2886
|
+
function printAllReturnFirst(numbers as float[]) as float
|
|
2887
|
+
for each num in numbers
|
|
2888
|
+
print num
|
|
2889
|
+
end for
|
|
2890
|
+
|
|
2891
|
+
firstFloat = numbers[0]
|
|
2892
|
+
print firstFloat
|
|
2893
|
+
return firstFloat
|
|
2894
|
+
end function
|
|
2895
|
+
`);
|
|
2896
|
+
const mainScope = program.getScopesForFile(file)[0];
|
|
2897
|
+
mainScope.linkSymbolTable();
|
|
2898
|
+
const funcExpr = file.parser.references.functionExpressions[0];
|
|
2899
|
+
const lookups = [
|
|
2900
|
+
{ line: 6, col: 26, name: 'firstFloat', type: new FloatType_1.FloatType() },
|
|
2901
|
+
{ line: 7, col: 32, name: 'firstFloat', type: new FloatType_1.FloatType() }
|
|
2902
|
+
];
|
|
2903
|
+
checkSymbolLookups(file, funcExpr, lookups);
|
|
2904
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
2905
|
+
});
|
|
2906
|
+
});
|
|
2559
2907
|
});
|
|
2560
2908
|
//# sourceMappingURL=BrsFile.spec.js.map
|