brighterscript 0.58.0 → 0.60.0
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 +25 -0
- package/README.md +18 -9
- package/bsconfig.schema.json +11 -0
- package/dist/BsConfig.d.ts +11 -0
- package/dist/CommentFlagProcessor.d.ts +1 -1
- package/dist/CommentFlagProcessor.js +1 -1
- package/dist/DependencyGraph.d.ts +3 -2
- package/dist/DependencyGraph.js +3 -2
- package/dist/DependencyGraph.js.map +1 -1
- package/dist/DiagnosticFilterer.js +1 -2
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +12 -2
- package/dist/DiagnosticMessages.js +12 -2
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/FunctionScope.d.ts +1 -1
- package/dist/FunctionScope.js +1 -1
- package/dist/KeyedThrottler.d.ts +3 -3
- package/dist/KeyedThrottler.js +3 -3
- package/dist/KeyedThrottler.js.map +1 -1
- package/dist/LanguageServer.d.ts +0 -7
- package/dist/LanguageServer.js +0 -7
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Program.d.ts +10 -8
- package/dist/Program.js +50 -238
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +0 -1
- package/dist/ProgramBuilder.js +1 -2
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +35 -35
- package/dist/Scope.js +63 -42
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +0 -3
- package/dist/SymbolTable.js +0 -3
- package/dist/SymbolTable.js.map +1 -1
- package/dist/Watcher.d.ts +0 -3
- package/dist/Watcher.js +0 -3
- package/dist/Watcher.js.map +1 -1
- package/dist/astUtils/AstEditor.d.ts +1 -1
- package/dist/astUtils/AstEditor.js +1 -1
- package/dist/astUtils/AstEditor.spec.js +58 -58
- package/dist/astUtils/AstEditor.spec.js.map +1 -1
- package/dist/astUtils/creators.spec.js +5 -5
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +3 -1
- package/dist/astUtils/reflection.js +10 -2
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +115 -110
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/stackedVisitor.spec.js +12 -12
- package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +6 -1
- package/dist/astUtils/visitors.js +4 -0
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +21 -21
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/CallExpressionInfo.d.ts +35 -0
- package/dist/bscPlugin/CallExpressionInfo.js +131 -0
- package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
- package/dist/bscPlugin/SignatureHelpUtil.d.ts +10 -0
- package/dist/bscPlugin/SignatureHelpUtil.js +135 -0
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +12 -12
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +48 -48
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +4 -4
- package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +1 -2
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +4 -5
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.d.ts +2 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +59 -6
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js +39 -9
- package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +43 -45
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +8 -20
- package/dist/files/BrsFile.js +16 -97
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +309 -262
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +1 -4
- package/dist/files/XmlFile.js +1 -4
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +136 -169
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +19 -21
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/files/tests/optionalChaning.spec.js +8 -11
- package/dist/files/tests/optionalChaning.spec.js.map +1 -1
- package/dist/lexer/Character.spec.js +5 -5
- package/dist/lexer/Character.spec.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +0 -5
- package/dist/lexer/Lexer.js +0 -5
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +141 -135
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +1 -0
- package/dist/lexer/TokenKind.js +6 -2
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +1 -1
- package/dist/parser/AstNode.spec.js +8 -10
- package/dist/parser/AstNode.spec.js.map +1 -1
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +60 -60
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +8 -4
- package/dist/parser/Parser.js +16 -7
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +229 -221
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.spec.js +16 -17
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/Statement.d.ts +16 -2
- package/dist/parser/Statement.js +40 -8
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +31 -14
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/For.spec.js +15 -15
- package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +13 -13
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +93 -93
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/While.spec.js +12 -12
- package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
- package/dist/parser/tests/expression/Additive.spec.js +8 -8
- package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
- package/dist/parser/tests/expression/ArrayLiterals.spec.js +26 -26
- package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +27 -27
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/Boolean.spec.js +8 -8
- package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
- package/dist/parser/tests/expression/Call.spec.js +45 -45
- package/dist/parser/tests/expression/Call.spec.js.map +1 -1
- package/dist/parser/tests/expression/Exponential.spec.js +5 -5
- package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
- package/dist/parser/tests/expression/Function.spec.js +36 -36
- package/dist/parser/tests/expression/Function.spec.js.map +1 -1
- package/dist/parser/tests/expression/Indexing.spec.js +29 -29
- package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
- package/dist/parser/tests/expression/Multiplicative.spec.js +9 -9
- package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +34 -34
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/PrefixUnary.spec.js +12 -12
- package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Primary.spec.js +12 -12
- package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
- package/dist/parser/tests/expression/Relational.spec.js +13 -13
- package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +10 -10
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +53 -53
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/AssignmentOperators.spec.js +15 -15
- package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +12 -12
- package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
- package/dist/parser/tests/statement/Continue.spec.js +92 -0
- package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
- package/dist/parser/tests/statement/Declaration.spec.js +19 -19
- package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
- package/dist/parser/tests/statement/Dim.spec.js +22 -22
- package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
- package/dist/parser/tests/statement/Enum.spec.js +43 -19
- package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
- package/dist/parser/tests/statement/For.spec.js +3 -4
- package/dist/parser/tests/statement/For.spec.js.map +1 -1
- package/dist/parser/tests/statement/ForEach.spec.js +4 -5
- package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/statement/Function.spec.js +35 -35
- package/dist/parser/tests/statement/Function.spec.js.map +1 -1
- package/dist/parser/tests/statement/Goto.spec.js +5 -5
- package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
- package/dist/parser/tests/statement/Increment.spec.js +20 -20
- package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +4 -5
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/LibraryStatement.spec.js +11 -11
- package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +20 -20
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/parser/tests/statement/PrintStatement.spec.js +19 -20
- package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/ReturnStatement.spec.js +9 -9
- package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Set.spec.js +22 -22
- package/dist/parser/tests/statement/Set.spec.js.map +1 -1
- package/dist/parser/tests/statement/Stop.spec.js +6 -6
- package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
- package/dist/parser/tests/statement/Throw.spec.js +6 -6
- package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
- package/dist/parser/tests/statement/TryCatch.spec.js +15 -15
- package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
- package/dist/preprocessor/Manifest.spec.js +8 -8
- package/dist/preprocessor/Manifest.spec.js.map +1 -1
- package/dist/preprocessor/Preprocessor.d.ts +2 -2
- package/dist/preprocessor/Preprocessor.js +2 -2
- package/dist/preprocessor/Preprocessor.spec.js +25 -25
- package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.d.ts +1 -1
- package/dist/preprocessor/PreprocessorParser.js +1 -1
- package/dist/preprocessor/PreprocessorParser.spec.js +13 -13
- package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
- package/dist/types/ArrayType.spec.js +9 -9
- package/dist/types/ArrayType.spec.js.map +1 -1
- package/dist/types/BooleanType.spec.js +3 -3
- package/dist/types/BooleanType.spec.js.map +1 -1
- package/dist/types/DoubleType.spec.js +3 -3
- package/dist/types/DoubleType.spec.js.map +1 -1
- package/dist/types/DynamicType.d.ts +0 -1
- package/dist/types/DynamicType.js +0 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/DynamicType.spec.js +3 -3
- package/dist/types/DynamicType.spec.js.map +1 -1
- package/dist/types/FloatType.spec.js +3 -3
- package/dist/types/FloatType.spec.js.map +1 -1
- package/dist/types/FunctionType.spec.js +6 -6
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.spec.js +3 -3
- package/dist/types/IntegerType.spec.js.map +1 -1
- package/dist/types/InterfaceType.spec.js +8 -8
- package/dist/types/InterfaceType.spec.js.map +1 -1
- package/dist/types/InvalidType.spec.js +3 -3
- package/dist/types/InvalidType.spec.js.map +1 -1
- package/dist/types/LongIntegerType.spec.js +3 -3
- package/dist/types/LongIntegerType.spec.js.map +1 -1
- package/dist/types/ObjectType.spec.js +3 -3
- package/dist/types/ObjectType.spec.js.map +1 -1
- package/dist/types/StringType.spec.js +3 -3
- package/dist/types/StringType.spec.js.map +1 -1
- package/dist/types/VoidType.spec.js +3 -3
- package/dist/types/VoidType.spec.js.map +1 -1
- package/dist/util.d.ts +21 -43
- package/dist/util.js +33 -60
- package/dist/util.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const
|
|
3
|
+
const chai_config_spec_1 = require("../chai-config.spec");
|
|
4
4
|
const sinonImport = require("sinon");
|
|
5
5
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
6
6
|
const Program_1 = require("../Program");
|
|
@@ -24,18 +24,17 @@ const creators_1 = require("../astUtils/creators");
|
|
|
24
24
|
const fsExtra = require("fs-extra");
|
|
25
25
|
const vscode_uri_1 = require("vscode-uri");
|
|
26
26
|
const undent_1 = require("undent");
|
|
27
|
+
const testHelpers_spec_2 = require("../testHelpers.spec");
|
|
27
28
|
let sinon = sinonImport.createSandbox();
|
|
28
29
|
describe('BrsFile', () => {
|
|
29
|
-
let tempDir = (0, util_1.standardizePath) `${process.cwd()}/.tmp`;
|
|
30
|
-
let rootDir = (0, util_1.standardizePath) `${tempDir}/rootDir`;
|
|
31
30
|
let program;
|
|
32
|
-
let srcPath = (0, util_1.standardizePath) `${rootDir}/source/main.brs`;
|
|
31
|
+
let srcPath = (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/source/main.brs`;
|
|
33
32
|
let destPath = 'source/main.brs';
|
|
34
33
|
let file;
|
|
35
|
-
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, rootDir]);
|
|
34
|
+
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, testHelpers_spec_2.rootDir]);
|
|
36
35
|
beforeEach(() => {
|
|
37
|
-
fsExtra.emptyDirSync(tempDir);
|
|
38
|
-
program = new Program_1.Program({ rootDir: rootDir, sourceMap: true });
|
|
36
|
+
fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
|
|
37
|
+
program = new Program_1.Program({ rootDir: testHelpers_spec_2.rootDir, sourceMap: true });
|
|
39
38
|
file = new BrsFile_1.BrsFile(srcPath, destPath, program);
|
|
40
39
|
});
|
|
41
40
|
afterEach(() => {
|
|
@@ -81,17 +80,17 @@ describe('BrsFile', () => {
|
|
|
81
80
|
});
|
|
82
81
|
it('sets needsTranspiled to true for .bs files', () => {
|
|
83
82
|
//BrightScript
|
|
84
|
-
(0,
|
|
83
|
+
(0, chai_config_spec_1.expect)(new BrsFile_1.BrsFile(`${testHelpers_spec_2.rootDir}/source/main.brs`, 'source/main.brs', program).needsTranspiled).to.be.false;
|
|
85
84
|
//BrighterScript
|
|
86
|
-
(0,
|
|
85
|
+
(0, chai_config_spec_1.expect)(new BrsFile_1.BrsFile(`${testHelpers_spec_2.rootDir}/source/main.bs`, 'source/main.bs', program).needsTranspiled).to.be.true;
|
|
87
86
|
});
|
|
88
87
|
it('computes new import statements after clearing parser references', () => {
|
|
89
88
|
const file = program.setFile('source/main.bs', ``);
|
|
90
|
-
(0,
|
|
89
|
+
(0, chai_config_spec_1.expect)(file.ownScriptImports).to.be.empty;
|
|
91
90
|
file.parser.ast.statements.push(new Statement_1.ImportStatement((0, creators_1.createToken)(TokenKind_1.TokenKind.Import), (0, creators_1.createToken)(TokenKind_1.TokenKind.StringLiteral, 'pkg:/source/lib.brs')));
|
|
92
|
-
(0,
|
|
91
|
+
(0, chai_config_spec_1.expect)(file.ownScriptImports).to.be.empty;
|
|
93
92
|
file.parser.invalidateReferences();
|
|
94
|
-
(0,
|
|
93
|
+
(0, chai_config_spec_1.expect)(file.ownScriptImports.map(x => x.text)).to.eql(['pkg:/source/lib.brs']);
|
|
95
94
|
});
|
|
96
95
|
it('allows adding diagnostics', () => {
|
|
97
96
|
const expected = [{
|
|
@@ -104,24 +103,24 @@ describe('BrsFile', () => {
|
|
|
104
103
|
});
|
|
105
104
|
describe('getPartialVariableName', () => {
|
|
106
105
|
let entry = {
|
|
107
|
-
src: `${rootDir}/source/lib.brs`,
|
|
106
|
+
src: `${testHelpers_spec_2.rootDir}/source/lib.brs`,
|
|
108
107
|
dest: `source/lib.brs`
|
|
109
108
|
};
|
|
110
109
|
it('creates proper tokens', () => {
|
|
111
110
|
file = program.setFile(entry, `call(ModuleA.ModuleB.ModuleC.`);
|
|
112
|
-
(0,
|
|
113
|
-
(0,
|
|
114
|
-
(0,
|
|
115
|
-
(0,
|
|
116
|
-
(0,
|
|
117
|
-
(0,
|
|
111
|
+
(0, chai_config_spec_1.expect)(file['getPartialVariableName'](file.parser.tokens[7])).to.equal('ModuleA.ModuleB.ModuleC.');
|
|
112
|
+
(0, chai_config_spec_1.expect)(file['getPartialVariableName'](file.parser.tokens[6])).to.equal('ModuleA.ModuleB.ModuleC');
|
|
113
|
+
(0, chai_config_spec_1.expect)(file['getPartialVariableName'](file.parser.tokens[5])).to.equal('ModuleA.ModuleB.');
|
|
114
|
+
(0, chai_config_spec_1.expect)(file['getPartialVariableName'](file.parser.tokens[4])).to.equal('ModuleA.ModuleB');
|
|
115
|
+
(0, chai_config_spec_1.expect)(file['getPartialVariableName'](file.parser.tokens[3])).to.equal('ModuleA.');
|
|
116
|
+
(0, chai_config_spec_1.expect)(file['getPartialVariableName'](file.parser.tokens[2])).to.equal('ModuleA');
|
|
118
117
|
});
|
|
119
118
|
});
|
|
120
119
|
describe('getScopesForFile', () => {
|
|
121
120
|
it('finds the scope for the file', () => {
|
|
122
121
|
var _a;
|
|
123
122
|
let file = program.setFile('source/main.brs', ``);
|
|
124
|
-
(0,
|
|
123
|
+
(0, chai_config_spec_1.expect)((_a = program.getScopesForFile(file)[0]) === null || _a === void 0 ? void 0 : _a.name).to.equal('source');
|
|
125
124
|
});
|
|
126
125
|
});
|
|
127
126
|
describe('getCompletions', () => {
|
|
@@ -131,7 +130,7 @@ describe('BrsFile', () => {
|
|
|
131
130
|
getManager()@.
|
|
132
131
|
end sub
|
|
133
132
|
`);
|
|
134
|
-
(0,
|
|
133
|
+
(0, chai_config_spec_1.expect)(() => {
|
|
135
134
|
program.getCompletions(file.srcPath, util_1.default.createPosition(2, 34));
|
|
136
135
|
}).not.to.throw;
|
|
137
136
|
});
|
|
@@ -141,9 +140,9 @@ describe('BrsFile', () => {
|
|
|
141
140
|
print "pkg:"
|
|
142
141
|
end sub
|
|
143
142
|
`);
|
|
144
|
-
const result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
143
|
+
const result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
145
144
|
const names = result.map(x => x.label);
|
|
146
|
-
(0,
|
|
145
|
+
(0, chai_config_spec_1.expect)(names.sort()).to.eql([
|
|
147
146
|
'pkg:/source/main.brs'
|
|
148
147
|
]);
|
|
149
148
|
});
|
|
@@ -153,9 +152,9 @@ describe('BrsFile', () => {
|
|
|
153
152
|
print "libpkg:"
|
|
154
153
|
end sub
|
|
155
154
|
`);
|
|
156
|
-
const result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
155
|
+
const result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
157
156
|
const names = result.map(x => x.label);
|
|
158
|
-
(0,
|
|
157
|
+
(0, chai_config_spec_1.expect)(names.sort()).to.eql([
|
|
159
158
|
'libpkg:/source/main.brs'
|
|
160
159
|
]);
|
|
161
160
|
});
|
|
@@ -165,9 +164,9 @@ describe('BrsFile', () => {
|
|
|
165
164
|
print \`pkg:\`
|
|
166
165
|
end sub
|
|
167
166
|
`);
|
|
168
|
-
const result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
167
|
+
const result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 31));
|
|
169
168
|
const names = result.map(x => x.label);
|
|
170
|
-
(0,
|
|
169
|
+
(0, chai_config_spec_1.expect)(names.sort()).to.eql([
|
|
171
170
|
'pkg:/source/main.brs'
|
|
172
171
|
]);
|
|
173
172
|
});
|
|
@@ -182,10 +181,10 @@ describe('BrsFile', () => {
|
|
|
182
181
|
sub SayHello()
|
|
183
182
|
end sub
|
|
184
183
|
`);
|
|
185
|
-
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 23));
|
|
184
|
+
let result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 23));
|
|
186
185
|
let names = result.map(x => x.label);
|
|
187
|
-
(0,
|
|
188
|
-
(0,
|
|
186
|
+
(0, chai_config_spec_1.expect)(names).to.includes('Main');
|
|
187
|
+
(0, chai_config_spec_1.expect)(names).to.includes('SayHello');
|
|
189
188
|
});
|
|
190
189
|
it('includes every type of item at base level', () => {
|
|
191
190
|
program.setFile('source/main.bs', `
|
|
@@ -231,10 +230,10 @@ describe('BrsFile', () => {
|
|
|
231
230
|
class Person
|
|
232
231
|
end class
|
|
233
232
|
`);
|
|
234
|
-
const result = program.getCompletions(`${rootDir}/source/main.bs`, vscode_languageserver_1.Position.create(2, 24)).map(x => x.label);
|
|
235
|
-
(0,
|
|
236
|
-
(0,
|
|
237
|
-
(0,
|
|
233
|
+
const result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.bs`, vscode_languageserver_1.Position.create(2, 24)).map(x => x.label);
|
|
234
|
+
(0, chai_config_spec_1.expect)(result).includes('main');
|
|
235
|
+
(0, chai_config_spec_1.expect)(result).includes('foo');
|
|
236
|
+
(0, chai_config_spec_1.expect)(result).includes('Person');
|
|
238
237
|
});
|
|
239
238
|
it('gets namespace completions', () => {
|
|
240
239
|
program.setFile('source/main.bs', `
|
|
@@ -249,111 +248,111 @@ describe('BrsFile', () => {
|
|
|
249
248
|
foo.bar.
|
|
250
249
|
end sub
|
|
251
250
|
`);
|
|
252
|
-
let result = program.getCompletions(`${rootDir}/source/main.bs`, vscode_languageserver_1.Position.create(8, 30));
|
|
251
|
+
let result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.bs`, vscode_languageserver_1.Position.create(8, 30));
|
|
253
252
|
let names = result.map(x => x.label);
|
|
254
|
-
(0,
|
|
255
|
-
result = program.getCompletions(`${rootDir}/source/main.bs`, vscode_languageserver_1.Position.create(9, 32));
|
|
253
|
+
(0, chai_config_spec_1.expect)(names).to.includes('bar');
|
|
254
|
+
result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.bs`, vscode_languageserver_1.Position.create(9, 32));
|
|
256
255
|
names = result.map(x => x.label);
|
|
257
|
-
(0,
|
|
256
|
+
(0, chai_config_spec_1.expect)(names).to.includes('sayHello');
|
|
258
257
|
});
|
|
259
258
|
});
|
|
260
259
|
it('always includes `m`', () => {
|
|
261
260
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
262
|
-
program.setFile(
|
|
261
|
+
program.setFile('source/main.brs', `
|
|
263
262
|
sub Main()
|
|
264
263
|
|
|
265
264
|
end sub
|
|
266
265
|
`);
|
|
267
|
-
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
266
|
+
let result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
268
267
|
let names = result.map(x => x.label);
|
|
269
|
-
(0,
|
|
268
|
+
(0, chai_config_spec_1.expect)(names).to.contain('m');
|
|
270
269
|
});
|
|
271
270
|
it('does not fail for missing previousToken', () => {
|
|
272
271
|
//add a single character to the file, and get completions after it
|
|
273
272
|
program.setFile('source/main.brs', `i`);
|
|
274
|
-
(0,
|
|
275
|
-
program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(0, 1)).map(x => x.label);
|
|
273
|
+
(0, chai_config_spec_1.expect)(() => {
|
|
274
|
+
program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(0, 1)).map(x => x.label);
|
|
276
275
|
}).not.to.throw;
|
|
277
276
|
});
|
|
278
277
|
it('includes all keywords`', () => {
|
|
279
278
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
280
|
-
program.setFile(
|
|
279
|
+
program.setFile('source/main.brs', `
|
|
281
280
|
sub Main()
|
|
282
281
|
|
|
283
282
|
end sub
|
|
284
283
|
`);
|
|
285
284
|
let keywords = Object.keys(TokenKind_1.Keywords).filter(x => !x.includes(' '));
|
|
286
285
|
//inside the function
|
|
287
|
-
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
286
|
+
let result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
288
287
|
let names = result.map(x => x.label);
|
|
289
288
|
for (let keyword of keywords) {
|
|
290
|
-
(0,
|
|
289
|
+
(0, chai_config_spec_1.expect)(names).to.include(keyword);
|
|
291
290
|
}
|
|
292
291
|
//outside the function
|
|
293
|
-
result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(4, 8));
|
|
292
|
+
result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(4, 8));
|
|
294
293
|
names = result.map(x => x.label);
|
|
295
294
|
for (let keyword of keywords) {
|
|
296
|
-
(0,
|
|
295
|
+
(0, chai_config_spec_1.expect)(names).to.include(keyword);
|
|
297
296
|
}
|
|
298
297
|
});
|
|
299
298
|
it('does not provide completions within a comment', () => {
|
|
300
299
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
301
|
-
program.setFile(
|
|
300
|
+
program.setFile('source/main.brs', `
|
|
302
301
|
sub Main()
|
|
303
302
|
'some comment
|
|
304
303
|
end sub
|
|
305
304
|
`);
|
|
306
305
|
//inside the function
|
|
307
|
-
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 33));
|
|
308
|
-
(0,
|
|
306
|
+
let result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 33));
|
|
307
|
+
(0, chai_config_spec_1.expect)(result).to.be.lengthOf(0);
|
|
309
308
|
});
|
|
310
309
|
it('does not provide duplicate entries for variables', () => {
|
|
311
310
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
312
|
-
program.setFile(
|
|
311
|
+
program.setFile('source/main.brs', `
|
|
313
312
|
sub Main()
|
|
314
313
|
name = "bob"
|
|
315
314
|
age = 12
|
|
316
315
|
name = "john"
|
|
317
316
|
end sub
|
|
318
317
|
`);
|
|
319
|
-
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 23));
|
|
318
|
+
let result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 23));
|
|
320
319
|
let count = result.reduce((total, x) => {
|
|
321
320
|
return x.label === 'name' ? total + 1 : total;
|
|
322
321
|
}, 0);
|
|
323
|
-
(0,
|
|
322
|
+
(0, chai_config_spec_1.expect)(count).to.equal(1);
|
|
324
323
|
});
|
|
325
324
|
it('does not include `as` and `string` text options when used in function params', () => {
|
|
326
325
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
327
|
-
program.setFile(
|
|
326
|
+
program.setFile('source/main.brs', `
|
|
328
327
|
sub Main(name as string)
|
|
329
328
|
|
|
330
329
|
end sub
|
|
331
330
|
`);
|
|
332
|
-
let result = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
333
|
-
(0,
|
|
334
|
-
(0,
|
|
331
|
+
let result = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 23));
|
|
332
|
+
(0, chai_config_spec_1.expect)(result.filter(x => x.kind === vscode_languageserver_1.CompletionItemKind.Text)).not.to.contain('as');
|
|
333
|
+
(0, chai_config_spec_1.expect)(result.filter(x => x.kind === vscode_languageserver_1.CompletionItemKind.Text)).not.to.contain('string');
|
|
335
334
|
});
|
|
336
335
|
it('does not provide intellisense results when inside a comment', () => {
|
|
337
336
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
338
|
-
program.setFile(
|
|
337
|
+
program.setFile('source/main.brs', `
|
|
339
338
|
sub Main(name as string)
|
|
340
339
|
'this is a comment
|
|
341
340
|
end sub
|
|
342
341
|
`);
|
|
343
|
-
let results = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 30));
|
|
344
|
-
(0,
|
|
342
|
+
let results = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(2, 30));
|
|
343
|
+
(0, chai_config_spec_1.expect)(results).to.be.empty;
|
|
345
344
|
});
|
|
346
345
|
it('does provide intellisence for labels only after a goto keyword', () => {
|
|
347
346
|
var _a;
|
|
348
347
|
//eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
349
|
-
program.setFile(
|
|
348
|
+
program.setFile('source/main.brs', `
|
|
350
349
|
sub Main(name as string)
|
|
351
350
|
something:
|
|
352
351
|
goto \nend sub
|
|
353
352
|
`);
|
|
354
|
-
let results = program.getCompletions(`${rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 25));
|
|
355
|
-
(0,
|
|
356
|
-
(0,
|
|
353
|
+
let results = program.getCompletions(`${testHelpers_spec_2.rootDir}/source/main.brs`, vscode_languageserver_1.Position.create(3, 25));
|
|
354
|
+
(0, chai_config_spec_1.expect)(results.length).to.equal(1);
|
|
355
|
+
(0, chai_config_spec_1.expect)((_a = results[0]) === null || _a === void 0 ? void 0 : _a.label).to.equal('something');
|
|
357
356
|
});
|
|
358
357
|
});
|
|
359
358
|
describe('comment flags', () => {
|
|
@@ -389,14 +388,14 @@ describe('BrsFile', () => {
|
|
|
389
388
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
390
389
|
});
|
|
391
390
|
it('works for all', () => {
|
|
392
|
-
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
391
|
+
let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
393
392
|
sub Main()
|
|
394
393
|
'bs:disable-next-line
|
|
395
394
|
name = "bob
|
|
396
395
|
end sub
|
|
397
396
|
`);
|
|
398
|
-
(0,
|
|
399
|
-
(0,
|
|
397
|
+
(0, chai_config_spec_1.expect)(file.commentFlags[0]).to.exist;
|
|
398
|
+
(0, chai_config_spec_1.expect)(file.commentFlags[0]).to.deep.include({
|
|
400
399
|
codes: null,
|
|
401
400
|
range: vscode_languageserver_1.Range.create(2, 24, 2, 45),
|
|
402
401
|
affectedRange: util_1.default.createRange(3, 0, 3, Number.MAX_SAFE_INTEGER)
|
|
@@ -406,14 +405,14 @@ describe('BrsFile', () => {
|
|
|
406
405
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
407
406
|
});
|
|
408
407
|
it('works for specific codes', () => {
|
|
409
|
-
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
408
|
+
let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
410
409
|
sub Main()
|
|
411
410
|
'bs:disable-next-line: 1083, 1001
|
|
412
411
|
name = "bob
|
|
413
412
|
end sub
|
|
414
413
|
`);
|
|
415
|
-
(0,
|
|
416
|
-
(0,
|
|
414
|
+
(0, chai_config_spec_1.expect)(file.commentFlags[0]).to.exist;
|
|
415
|
+
(0, chai_config_spec_1.expect)(file.commentFlags[0]).to.deep.include({
|
|
417
416
|
codes: [1083, 1001],
|
|
418
417
|
range: vscode_languageserver_1.Range.create(2, 24, 2, 57),
|
|
419
418
|
affectedRange: util_1.default.createRange(3, 0, 3, Number.MAX_SAFE_INTEGER)
|
|
@@ -422,13 +421,13 @@ describe('BrsFile', () => {
|
|
|
422
421
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
423
422
|
});
|
|
424
423
|
it('recognizes non-numeric codes', () => {
|
|
425
|
-
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
424
|
+
let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
426
425
|
sub Main()
|
|
427
426
|
'bs:disable-next-line: LINT9999
|
|
428
427
|
name = "bob
|
|
429
428
|
end sub
|
|
430
429
|
`);
|
|
431
|
-
(0,
|
|
430
|
+
(0, chai_config_spec_1.expect)(file.commentFlags[0]).to.exist;
|
|
432
431
|
(0, testHelpers_spec_1.expectHasDiagnostics)(program);
|
|
433
432
|
});
|
|
434
433
|
it('supports disabling non-numeric error codes', () => {
|
|
@@ -448,7 +447,7 @@ describe('BrsFile', () => {
|
|
|
448
447
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(scope);
|
|
449
448
|
});
|
|
450
449
|
it('adds diagnostics for unknown numeric diagnostic codes', () => {
|
|
451
|
-
program.setFile(
|
|
450
|
+
program.setFile('source/main.brs', `
|
|
452
451
|
sub main()
|
|
453
452
|
print "hi" 'bs:disable-line: 123456 999999 aaaab
|
|
454
453
|
end sub
|
|
@@ -459,13 +458,13 @@ describe('BrsFile', () => {
|
|
|
459
458
|
});
|
|
460
459
|
describe('bs:disable-line', () => {
|
|
461
460
|
it('works for all', () => {
|
|
462
|
-
let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
461
|
+
let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
|
|
463
462
|
sub Main()
|
|
464
463
|
z::;;%%%%%% 'bs:disable-line
|
|
465
464
|
end sub
|
|
466
465
|
`);
|
|
467
|
-
(0,
|
|
468
|
-
(0,
|
|
466
|
+
(0, chai_config_spec_1.expect)(file.commentFlags[0]).to.exist;
|
|
467
|
+
(0, chai_config_spec_1.expect)(file.commentFlags[0]).to.deep.include({
|
|
469
468
|
codes: null,
|
|
470
469
|
range: vscode_languageserver_1.Range.create(2, 36, 2, 52),
|
|
471
470
|
affectedRange: vscode_languageserver_1.Range.create(2, 0, 2, 36)
|
|
@@ -475,7 +474,7 @@ describe('BrsFile', () => {
|
|
|
475
474
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
476
475
|
});
|
|
477
476
|
it('works for specific codes', () => {
|
|
478
|
-
program.setFile(
|
|
477
|
+
program.setFile('source/main.brs', `
|
|
479
478
|
sub main()
|
|
480
479
|
'should not have any errors
|
|
481
480
|
DoSomething(1) 'bs:disable-line:1002
|
|
@@ -494,7 +493,7 @@ describe('BrsFile', () => {
|
|
|
494
493
|
//the current version of BRS causes parse errors after the `parse` keyword, showing error in comments
|
|
495
494
|
//the program should ignore all diagnostics found in brs:* comment lines EXCEPT
|
|
496
495
|
//for the diagnostics about using unknown error codes
|
|
497
|
-
program.setFile(
|
|
496
|
+
program.setFile('source/main.brs', `
|
|
498
497
|
sub main()
|
|
499
498
|
stop 'bs:disable-line
|
|
500
499
|
print "need a valid line to fix stop error"
|
|
@@ -557,7 +556,7 @@ describe('BrsFile', () => {
|
|
|
557
556
|
it('uses the proper parse mode based on file extension', () => {
|
|
558
557
|
function testParseMode(destPath, expectedParseMode) {
|
|
559
558
|
const file = program.setFile(destPath, '');
|
|
560
|
-
(0,
|
|
559
|
+
(0, chai_config_spec_1.expect)(file.parseMode).to.equal(expectedParseMode);
|
|
561
560
|
}
|
|
562
561
|
testParseMode('source/main.brs', Parser_1.ParseMode.BrightScript);
|
|
563
562
|
testParseMode('source/main.spec.brs', Parser_1.ParseMode.BrightScript);
|
|
@@ -567,7 +566,7 @@ describe('BrsFile', () => {
|
|
|
567
566
|
testParseMode('source/main.spec.bs', Parser_1.ParseMode.BrighterScript);
|
|
568
567
|
});
|
|
569
568
|
it('supports labels and goto statements', () => {
|
|
570
|
-
let file = program.setFile(
|
|
569
|
+
let file = program.setFile('source/main.brs', `
|
|
571
570
|
sub Main()
|
|
572
571
|
'multiple goto statements on one line
|
|
573
572
|
goto myLabel : goto myLabel
|
|
@@ -577,7 +576,7 @@ describe('BrsFile', () => {
|
|
|
577
576
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
578
577
|
});
|
|
579
578
|
it('supports empty print statements', () => {
|
|
580
|
-
let file = program.setFile(
|
|
579
|
+
let file = program.setFile('source/main.brs', `
|
|
581
580
|
sub main()
|
|
582
581
|
print
|
|
583
582
|
end sub
|
|
@@ -586,7 +585,7 @@ describe('BrsFile', () => {
|
|
|
586
585
|
});
|
|
587
586
|
describe('conditional compile', () => {
|
|
588
587
|
it('supports case-insensitive bs_const variables', () => {
|
|
589
|
-
fsExtra.outputFileSync(`${rootDir}/manifest`, (0, undent_1.default) `
|
|
588
|
+
fsExtra.outputFileSync(`${testHelpers_spec_2.rootDir}/manifest`, (0, undent_1.default) `
|
|
590
589
|
bs_const=SomeKey=true
|
|
591
590
|
`);
|
|
592
591
|
program.setFile('source/main.brs', `
|
|
@@ -606,7 +605,7 @@ describe('BrsFile', () => {
|
|
|
606
605
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
607
606
|
});
|
|
608
607
|
it('works for upper case keywords', () => {
|
|
609
|
-
let file = program.setFile(
|
|
608
|
+
let file = program.setFile('source/main.brs', `
|
|
610
609
|
sub main()
|
|
611
610
|
#CONST someFlag = true
|
|
612
611
|
#IF someFlag
|
|
@@ -621,7 +620,7 @@ describe('BrsFile', () => {
|
|
|
621
620
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
622
621
|
});
|
|
623
622
|
it('supports single-word #elseif and #endif', () => {
|
|
624
|
-
let file = program.setFile(
|
|
623
|
+
let file = program.setFile('source/main.brs', `
|
|
625
624
|
sub main()
|
|
626
625
|
#const someFlag = true
|
|
627
626
|
#if someFlag
|
|
@@ -634,7 +633,7 @@ describe('BrsFile', () => {
|
|
|
634
633
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
635
634
|
});
|
|
636
635
|
it('supports multi-word #else if and #end if', () => {
|
|
637
|
-
let file = program.setFile(
|
|
636
|
+
let file = program.setFile('source/main.brs', `
|
|
638
637
|
sub main()
|
|
639
638
|
#const someFlag = true
|
|
640
639
|
#if someFlag
|
|
@@ -647,7 +646,7 @@ describe('BrsFile', () => {
|
|
|
647
646
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
648
647
|
});
|
|
649
648
|
it('does not choke on invalid code inside a false conditional compile', () => {
|
|
650
|
-
let file = program.setFile(
|
|
649
|
+
let file = program.setFile('source/main.brs', `
|
|
651
650
|
sub main()
|
|
652
651
|
#if false
|
|
653
652
|
non-commented code here should not cause parse errors
|
|
@@ -657,7 +656,7 @@ describe('BrsFile', () => {
|
|
|
657
656
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
658
657
|
});
|
|
659
658
|
it('detects syntax error in #if', () => {
|
|
660
|
-
let file = program.setFile(
|
|
659
|
+
let file = program.setFile('source/main.brs', `
|
|
661
660
|
sub main()
|
|
662
661
|
#if true1
|
|
663
662
|
print "true"
|
|
@@ -669,7 +668,7 @@ describe('BrsFile', () => {
|
|
|
669
668
|
]);
|
|
670
669
|
});
|
|
671
670
|
it('detects syntax error in #const', () => {
|
|
672
|
-
let file = program.setFile(
|
|
671
|
+
let file = program.setFile('source/main.brs', `
|
|
673
672
|
sub main()
|
|
674
673
|
#if %
|
|
675
674
|
print "true"
|
|
@@ -682,7 +681,7 @@ describe('BrsFile', () => {
|
|
|
682
681
|
]);
|
|
683
682
|
});
|
|
684
683
|
it('detects #const name using reserved word', () => {
|
|
685
|
-
let file = program.setFile(
|
|
684
|
+
let file = program.setFile('source/main.brs', `
|
|
686
685
|
sub main()
|
|
687
686
|
#const function = true
|
|
688
687
|
end sub
|
|
@@ -693,7 +692,7 @@ describe('BrsFile', () => {
|
|
|
693
692
|
]);
|
|
694
693
|
});
|
|
695
694
|
it('detects syntax error in #const', () => {
|
|
696
|
-
let file = program.setFile(
|
|
695
|
+
let file = program.setFile('source/main.brs', `
|
|
697
696
|
sub main()
|
|
698
697
|
#const someConst = 123
|
|
699
698
|
end sub
|
|
@@ -704,7 +703,7 @@ describe('BrsFile', () => {
|
|
|
704
703
|
});
|
|
705
704
|
});
|
|
706
705
|
it('supports stop statement', () => {
|
|
707
|
-
let file = program.setFile(
|
|
706
|
+
let file = program.setFile('source/main.brs', `
|
|
708
707
|
sub main()
|
|
709
708
|
stop
|
|
710
709
|
end sub
|
|
@@ -712,7 +711,7 @@ describe('BrsFile', () => {
|
|
|
712
711
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
713
712
|
});
|
|
714
713
|
it('supports single-line if statements', () => {
|
|
715
|
-
let file = program.setFile(
|
|
714
|
+
let file = program.setFile('source/main.brs', `
|
|
716
715
|
sub main()
|
|
717
716
|
if 1 < 2: return true: end if
|
|
718
717
|
if 1 < 2: return true
|
|
@@ -830,7 +829,7 @@ describe('BrsFile', () => {
|
|
|
830
829
|
print "hello world"
|
|
831
830
|
end sub
|
|
832
831
|
`);
|
|
833
|
-
(0,
|
|
832
|
+
(0, chai_config_spec_1.expect)(file.functionScopes).to.be.lengthOf(2);
|
|
834
833
|
});
|
|
835
834
|
it('does not lose sub scope when mismatched end function', () => {
|
|
836
835
|
file.parse(`
|
|
@@ -842,7 +841,7 @@ describe('BrsFile', () => {
|
|
|
842
841
|
print "hello world"
|
|
843
842
|
end sub
|
|
844
843
|
`);
|
|
845
|
-
(0,
|
|
844
|
+
(0, chai_config_spec_1.expect)(file.functionScopes).to.be.lengthOf(2);
|
|
846
845
|
});
|
|
847
846
|
it('does not error with boolean in RHS of set statement', () => {
|
|
848
847
|
file.parse(`
|
|
@@ -1114,7 +1113,7 @@ describe('BrsFile', () => {
|
|
|
1114
1113
|
return value.subType()
|
|
1115
1114
|
end function
|
|
1116
1115
|
`);
|
|
1117
|
-
(0,
|
|
1116
|
+
(0, chai_config_spec_1.expect)(file.callables[0]).to.deep.include({
|
|
1118
1117
|
file: file,
|
|
1119
1118
|
nameRange: vscode_languageserver_1.Range.create(1, 25, 1, 36)
|
|
1120
1119
|
});
|
|
@@ -1137,17 +1136,17 @@ describe('BrsFile', () => {
|
|
|
1137
1136
|
print "B"
|
|
1138
1137
|
end function
|
|
1139
1138
|
`);
|
|
1140
|
-
(0,
|
|
1141
|
-
(0,
|
|
1142
|
-
(0,
|
|
1143
|
-
(0,
|
|
1139
|
+
(0, chai_config_spec_1.expect)(file.callables[0].name).to.equal('DoA');
|
|
1140
|
+
(0, chai_config_spec_1.expect)(file.callables[0].nameRange).to.eql(vscode_languageserver_1.Range.create(1, 25, 1, 28));
|
|
1141
|
+
(0, chai_config_spec_1.expect)(file.callables[1].name).to.equal('DoB');
|
|
1142
|
+
(0, chai_config_spec_1.expect)(file.callables[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 26, 5, 29));
|
|
1144
1143
|
});
|
|
1145
1144
|
it('throws an error if the file has already been parsed', () => {
|
|
1146
1145
|
let file = new BrsFile_1.BrsFile('abspath', 'relpath', program);
|
|
1147
1146
|
file.parse(`'a comment`);
|
|
1148
1147
|
try {
|
|
1149
1148
|
file.parse(`'a new comment`);
|
|
1150
|
-
|
|
1149
|
+
chai_config_spec_1.assert.fail(null, null, 'Should have thrown an exception, but did not');
|
|
1151
1150
|
}
|
|
1152
1151
|
catch (e) {
|
|
1153
1152
|
//test passes
|
|
@@ -1164,11 +1163,11 @@ describe('BrsFile', () => {
|
|
|
1164
1163
|
print "A"
|
|
1165
1164
|
end function
|
|
1166
1165
|
`);
|
|
1167
|
-
(0,
|
|
1168
|
-
(0,
|
|
1169
|
-
(0,
|
|
1170
|
-
(0,
|
|
1171
|
-
(0,
|
|
1166
|
+
(0, chai_config_spec_1.expect)(file.callables.length).to.equal(2);
|
|
1167
|
+
(0, chai_config_spec_1.expect)(file.callables[0].name).to.equal('DoA');
|
|
1168
|
+
(0, chai_config_spec_1.expect)(file.callables[0].nameRange.start.line).to.equal(1);
|
|
1169
|
+
(0, chai_config_spec_1.expect)(file.callables[1].name).to.equal('DoA');
|
|
1170
|
+
(0, chai_config_spec_1.expect)(file.callables[1].nameRange.start.line).to.equal(5);
|
|
1172
1171
|
});
|
|
1173
1172
|
it('finds function call line and column numbers', () => {
|
|
1174
1173
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1180,11 +1179,11 @@ describe('BrsFile', () => {
|
|
|
1180
1179
|
DoC()
|
|
1181
1180
|
end function
|
|
1182
1181
|
`);
|
|
1183
|
-
(0,
|
|
1184
|
-
(0,
|
|
1185
|
-
(0,
|
|
1186
|
-
(0,
|
|
1187
|
-
(0,
|
|
1182
|
+
(0, chai_config_spec_1.expect)(file.functionCalls.length).to.equal(2);
|
|
1183
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[0].range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 28));
|
|
1184
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[0].nameRange).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 23));
|
|
1185
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[1].range).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 25));
|
|
1186
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 23));
|
|
1188
1187
|
});
|
|
1189
1188
|
it('finds function calls that are unfinished', () => {
|
|
1190
1189
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1203,11 +1202,11 @@ describe('BrsFile', () => {
|
|
|
1203
1202
|
DiagnosticMessages_1.DiagnosticMessages.expectedRightParenAfterFunctionCallArguments(),
|
|
1204
1203
|
DiagnosticMessages_1.DiagnosticMessages.expectedNewlineOrColon()
|
|
1205
1204
|
]);
|
|
1206
|
-
(0,
|
|
1207
|
-
(0,
|
|
1208
|
-
(0,
|
|
1209
|
-
(0,
|
|
1210
|
-
(0,
|
|
1205
|
+
(0, chai_config_spec_1.expect)(file.functionCalls.length).to.equal(2);
|
|
1206
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[0].range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 27));
|
|
1207
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[0].nameRange).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 23));
|
|
1208
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[1].range).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 24));
|
|
1209
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[1].nameRange).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 23));
|
|
1211
1210
|
});
|
|
1212
1211
|
it('sanitizes brs errors', () => {
|
|
1213
1212
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1216,8 +1215,8 @@ describe('BrsFile', () => {
|
|
|
1216
1215
|
end function
|
|
1217
1216
|
`);
|
|
1218
1217
|
(0, testHelpers_spec_1.expectHasDiagnostics)(file);
|
|
1219
|
-
(0,
|
|
1220
|
-
(0,
|
|
1218
|
+
(0, chai_config_spec_1.expect)(file.getDiagnostics()[0].file).to.equal(file);
|
|
1219
|
+
(0, chai_config_spec_1.expect)(file.getDiagnostics()[0].range.start.line).to.equal(1);
|
|
1221
1220
|
});
|
|
1222
1221
|
it('supports using the `next` keyword in a for loop', () => {
|
|
1223
1222
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1253,7 +1252,7 @@ describe('BrsFile', () => {
|
|
|
1253
1252
|
end sub
|
|
1254
1253
|
`);
|
|
1255
1254
|
let callable = file.callables[0];
|
|
1256
|
-
(0,
|
|
1255
|
+
(0, chai_config_spec_1.expect)(callable.range).to.eql(vscode_languageserver_1.Range.create(1, 16, 3, 23));
|
|
1257
1256
|
});
|
|
1258
1257
|
it('finds correct body range even with inner function', () => {
|
|
1259
1258
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1266,7 +1265,7 @@ describe('BrsFile', () => {
|
|
|
1266
1265
|
end sub
|
|
1267
1266
|
`);
|
|
1268
1267
|
let callable = file.callables[0];
|
|
1269
|
-
(0,
|
|
1268
|
+
(0, chai_config_spec_1.expect)(callable.range).to.eql(vscode_languageserver_1.Range.create(1, 16, 6, 23));
|
|
1270
1269
|
});
|
|
1271
1270
|
it('finds callable parameters', () => {
|
|
1272
1271
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1276,24 +1275,24 @@ describe('BrsFile', () => {
|
|
|
1276
1275
|
end function
|
|
1277
1276
|
`);
|
|
1278
1277
|
let callable = file.callables[0];
|
|
1279
|
-
(0,
|
|
1278
|
+
(0, chai_config_spec_1.expect)(callable.params[0]).to.deep.include({
|
|
1280
1279
|
name: 'a',
|
|
1281
1280
|
isOptional: false,
|
|
1282
1281
|
isRestArgument: false
|
|
1283
1282
|
});
|
|
1284
|
-
(0,
|
|
1285
|
-
(0,
|
|
1283
|
+
(0, chai_config_spec_1.expect)(callable.params[0].type).instanceof(DynamicType_1.DynamicType);
|
|
1284
|
+
(0, chai_config_spec_1.expect)(callable.params[1]).to.deep.include({
|
|
1286
1285
|
name: 'b',
|
|
1287
1286
|
isOptional: false,
|
|
1288
1287
|
isRestArgument: false
|
|
1289
1288
|
});
|
|
1290
|
-
(0,
|
|
1291
|
-
(0,
|
|
1289
|
+
(0, chai_config_spec_1.expect)(callable.params[1].type).instanceof(DynamicType_1.DynamicType);
|
|
1290
|
+
(0, chai_config_spec_1.expect)(callable.params[2]).to.deep.include({
|
|
1292
1291
|
name: 'c',
|
|
1293
1292
|
isOptional: false,
|
|
1294
1293
|
isRestArgument: false
|
|
1295
1294
|
});
|
|
1296
|
-
(0,
|
|
1295
|
+
(0, chai_config_spec_1.expect)(callable.params[2].type).instanceof(DynamicType_1.DynamicType);
|
|
1297
1296
|
});
|
|
1298
1297
|
it('finds optional parameters', () => {
|
|
1299
1298
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1303,12 +1302,12 @@ describe('BrsFile', () => {
|
|
|
1303
1302
|
end function
|
|
1304
1303
|
`);
|
|
1305
1304
|
let callable = file.callables[0];
|
|
1306
|
-
(0,
|
|
1305
|
+
(0, chai_config_spec_1.expect)(callable.params[0]).to.deep.include({
|
|
1307
1306
|
name: 'a',
|
|
1308
1307
|
isOptional: true,
|
|
1309
1308
|
isRestArgument: false
|
|
1310
1309
|
});
|
|
1311
|
-
(0,
|
|
1310
|
+
(0, chai_config_spec_1.expect)(callable.params[0].type).instanceof(DynamicType_1.DynamicType);
|
|
1312
1311
|
});
|
|
1313
1312
|
it('finds parameter types', () => {
|
|
1314
1313
|
let file = new BrsFile_1.BrsFile('absolute_path/file.brs', 'relative_path/file.brs', program);
|
|
@@ -1318,24 +1317,24 @@ describe('BrsFile', () => {
|
|
|
1318
1317
|
end function
|
|
1319
1318
|
`);
|
|
1320
1319
|
let callable = file.callables[0];
|
|
1321
|
-
(0,
|
|
1320
|
+
(0, chai_config_spec_1.expect)(callable.params[0]).to.deep.include({
|
|
1322
1321
|
name: 'a',
|
|
1323
1322
|
isOptional: false,
|
|
1324
1323
|
isRestArgument: false
|
|
1325
1324
|
});
|
|
1326
|
-
(0,
|
|
1327
|
-
(0,
|
|
1325
|
+
(0, chai_config_spec_1.expect)(callable.params[0].type).instanceof(DynamicType_1.DynamicType);
|
|
1326
|
+
(0, chai_config_spec_1.expect)(callable.params[1]).to.deep.include({
|
|
1328
1327
|
name: 'b',
|
|
1329
1328
|
isOptional: false,
|
|
1330
1329
|
isRestArgument: false
|
|
1331
1330
|
});
|
|
1332
|
-
(0,
|
|
1333
|
-
(0,
|
|
1331
|
+
(0, chai_config_spec_1.expect)(callable.params[1].type).instanceof(IntegerType_1.IntegerType);
|
|
1332
|
+
(0, chai_config_spec_1.expect)(callable.params[2]).to.deep.include({
|
|
1334
1333
|
name: 'c',
|
|
1335
1334
|
isOptional: false,
|
|
1336
1335
|
isRestArgument: false
|
|
1337
1336
|
});
|
|
1338
|
-
(0,
|
|
1337
|
+
(0, chai_config_spec_1.expect)(callable.params[2].type).instanceof(StringType_1.StringType);
|
|
1339
1338
|
});
|
|
1340
1339
|
});
|
|
1341
1340
|
describe('findCallableInvocations', () => {
|
|
@@ -1346,12 +1345,12 @@ describe('BrsFile', () => {
|
|
|
1346
1345
|
DoSomething("name", 12, true)
|
|
1347
1346
|
end function
|
|
1348
1347
|
`);
|
|
1349
|
-
(0,
|
|
1348
|
+
(0, chai_config_spec_1.expect)(file.functionCalls.length).to.equal(1);
|
|
1350
1349
|
const argsMap = file.functionCalls[0].args.map(arg => {
|
|
1351
1350
|
// disregard arg.expression, etc.
|
|
1352
1351
|
return { type: arg.type, range: arg.range, text: arg.text };
|
|
1353
1352
|
});
|
|
1354
|
-
(0,
|
|
1353
|
+
(0, chai_config_spec_1.expect)(argsMap).to.eql([{
|
|
1355
1354
|
type: new StringType_1.StringType(),
|
|
1356
1355
|
range: util_1.default.createRange(2, 32, 2, 38),
|
|
1357
1356
|
text: '"name"'
|
|
@@ -1388,16 +1387,16 @@ describe('BrsFile', () => {
|
|
|
1388
1387
|
DoSomething(count, name, isAlive)
|
|
1389
1388
|
end function
|
|
1390
1389
|
`);
|
|
1391
|
-
(0,
|
|
1392
|
-
(0,
|
|
1390
|
+
(0, chai_config_spec_1.expect)(file.functionCalls.length).to.equal(1);
|
|
1391
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[0].args[0]).deep.include({
|
|
1393
1392
|
type: new DynamicType_1.DynamicType(),
|
|
1394
1393
|
text: 'count'
|
|
1395
1394
|
});
|
|
1396
|
-
(0,
|
|
1395
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[0].args[1]).deep.include({
|
|
1397
1396
|
type: new DynamicType_1.DynamicType(),
|
|
1398
1397
|
text: 'name'
|
|
1399
1398
|
});
|
|
1400
|
-
(0,
|
|
1399
|
+
(0, chai_config_spec_1.expect)(file.functionCalls[0].args[2]).deep.include({
|
|
1401
1400
|
type: new DynamicType_1.DynamicType(),
|
|
1402
1401
|
text: 'isAlive'
|
|
1403
1402
|
});
|
|
@@ -1408,20 +1407,20 @@ describe('BrsFile', () => {
|
|
|
1408
1407
|
it('skips top-level statements', () => {
|
|
1409
1408
|
let file = new BrsFile_1.BrsFile('absolute', 'relative', program);
|
|
1410
1409
|
file.parse('name = "Bob"');
|
|
1411
|
-
(0,
|
|
1410
|
+
(0, chai_config_spec_1.expect)(file.callables.length).to.equal(0);
|
|
1412
1411
|
});
|
|
1413
1412
|
it('finds return type', () => {
|
|
1414
1413
|
let file = program.setFile('source/main.brs', `
|
|
1415
1414
|
function DoSomething() as string
|
|
1416
1415
|
end function
|
|
1417
1416
|
`);
|
|
1418
|
-
(0,
|
|
1417
|
+
(0, chai_config_spec_1.expect)(file.callables[0]).to.deep.include({
|
|
1419
1418
|
file: file,
|
|
1420
1419
|
nameRange: vscode_languageserver_1.Range.create(1, 25, 1, 36),
|
|
1421
1420
|
name: 'DoSomething',
|
|
1422
1421
|
params: []
|
|
1423
1422
|
});
|
|
1424
|
-
(0,
|
|
1423
|
+
(0, chai_config_spec_1.expect)(file.callables[0].type.returnType).instanceof(StringType_1.StringType);
|
|
1425
1424
|
});
|
|
1426
1425
|
});
|
|
1427
1426
|
describe('createFunctionScopes', () => {
|
|
@@ -1431,7 +1430,7 @@ describe('BrsFile', () => {
|
|
|
1431
1430
|
name = 'bob"
|
|
1432
1431
|
end sub
|
|
1433
1432
|
`);
|
|
1434
|
-
(0,
|
|
1433
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 3, 23));
|
|
1435
1434
|
});
|
|
1436
1435
|
it('creates scopes for parent and child functions', () => {
|
|
1437
1436
|
file.parse(`
|
|
@@ -1445,7 +1444,7 @@ describe('BrsFile', () => {
|
|
|
1445
1444
|
end sub)
|
|
1446
1445
|
end sub
|
|
1447
1446
|
`);
|
|
1448
|
-
(0,
|
|
1447
|
+
(0, chai_config_spec_1.expect)(file.functionScopes).to.length(3);
|
|
1449
1448
|
});
|
|
1450
1449
|
it('outer function does not capture inner statements', () => {
|
|
1451
1450
|
file.parse(`
|
|
@@ -1457,9 +1456,9 @@ describe('BrsFile', () => {
|
|
|
1457
1456
|
end sub
|
|
1458
1457
|
`);
|
|
1459
1458
|
let outerScope = file.getFunctionScopeAtPosition(vscode_languageserver_1.Position.create(2, 25));
|
|
1460
|
-
(0,
|
|
1459
|
+
(0, chai_config_spec_1.expect)(outerScope.variableDeclarations).to.be.lengthOf(2);
|
|
1461
1460
|
let innerScope = file.getFunctionScopeAtPosition(vscode_languageserver_1.Position.create(4, 10));
|
|
1462
|
-
(0,
|
|
1461
|
+
(0, chai_config_spec_1.expect)(innerScope.variableDeclarations).to.be.lengthOf(1);
|
|
1463
1462
|
});
|
|
1464
1463
|
it('finds variables declared in function scopes', () => {
|
|
1465
1464
|
file.parse(`
|
|
@@ -1473,24 +1472,24 @@ describe('BrsFile', () => {
|
|
|
1473
1472
|
end sub)
|
|
1474
1473
|
end sub
|
|
1475
1474
|
`);
|
|
1476
|
-
(0,
|
|
1477
|
-
(0,
|
|
1475
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations).to.be.length(1);
|
|
1476
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations[0]).to.deep.include({
|
|
1478
1477
|
lineIndex: 2,
|
|
1479
1478
|
name: 'sayHi'
|
|
1480
1479
|
});
|
|
1481
|
-
(0,
|
|
1482
|
-
(0,
|
|
1483
|
-
(0,
|
|
1480
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations[0].type).instanceof(FunctionType_1.FunctionType);
|
|
1481
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[1].variableDeclarations).to.be.length(1);
|
|
1482
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[1].variableDeclarations[0]).to.deep.include({
|
|
1484
1483
|
lineIndex: 3,
|
|
1485
1484
|
name: 'age'
|
|
1486
1485
|
});
|
|
1487
|
-
(0,
|
|
1488
|
-
(0,
|
|
1489
|
-
(0,
|
|
1486
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[1].variableDeclarations[0].type).instanceof(IntegerType_1.IntegerType);
|
|
1487
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[2].variableDeclarations).to.be.length(1);
|
|
1488
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[2].variableDeclarations[0]).to.deep.include({
|
|
1490
1489
|
lineIndex: 7,
|
|
1491
1490
|
name: 'name'
|
|
1492
1491
|
});
|
|
1493
|
-
(0,
|
|
1492
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[2].variableDeclarations[0].type).instanceof(StringType_1.StringType);
|
|
1494
1493
|
});
|
|
1495
1494
|
it('finds variable declarations inside of if statements', () => {
|
|
1496
1495
|
file.parse(`
|
|
@@ -1501,8 +1500,8 @@ describe('BrsFile', () => {
|
|
|
1501
1500
|
end sub
|
|
1502
1501
|
`);
|
|
1503
1502
|
let scope = file.getFunctionScopeAtPosition(vscode_languageserver_1.Position.create(3, 0));
|
|
1504
|
-
(0,
|
|
1505
|
-
(0,
|
|
1503
|
+
(0, chai_config_spec_1.expect)(scope.variableDeclarations[0]).to.exist;
|
|
1504
|
+
(0, chai_config_spec_1.expect)(scope.variableDeclarations[0].name).to.equal('theLength');
|
|
1506
1505
|
});
|
|
1507
1506
|
it('finds value from global return', () => {
|
|
1508
1507
|
let file = program.setFile('source/main.brs', `
|
|
@@ -1514,12 +1513,12 @@ describe('BrsFile', () => {
|
|
|
1514
1513
|
return "bob"
|
|
1515
1514
|
end function
|
|
1516
1515
|
`);
|
|
1517
|
-
(0,
|
|
1518
|
-
(0,
|
|
1516
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations).to.be.length(1);
|
|
1517
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations[0]).to.deep.include({
|
|
1519
1518
|
lineIndex: 2,
|
|
1520
1519
|
name: 'myName'
|
|
1521
1520
|
});
|
|
1522
|
-
(0,
|
|
1521
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations[0].type).instanceof(StringType_1.StringType);
|
|
1523
1522
|
});
|
|
1524
1523
|
it('finds variable type from other variable', () => {
|
|
1525
1524
|
file.parse(`
|
|
@@ -1528,12 +1527,12 @@ describe('BrsFile', () => {
|
|
|
1528
1527
|
nameCopy = name
|
|
1529
1528
|
end sub
|
|
1530
1529
|
`);
|
|
1531
|
-
(0,
|
|
1532
|
-
(0,
|
|
1530
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations).to.be.length(2);
|
|
1531
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations[1]).to.deep.include({
|
|
1533
1532
|
lineIndex: 3,
|
|
1534
1533
|
name: 'nameCopy'
|
|
1535
1534
|
});
|
|
1536
|
-
(0,
|
|
1535
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].variableDeclarations[1].type).instanceof(StringType_1.StringType);
|
|
1537
1536
|
});
|
|
1538
1537
|
it('sets proper range for functions', () => {
|
|
1539
1538
|
file.parse(`
|
|
@@ -1543,40 +1542,40 @@ describe('BrsFile', () => {
|
|
|
1543
1542
|
end function
|
|
1544
1543
|
end sub
|
|
1545
1544
|
`);
|
|
1546
|
-
(0,
|
|
1547
|
-
(0,
|
|
1548
|
-
(0,
|
|
1545
|
+
(0, chai_config_spec_1.expect)(file.functionScopes).to.be.length(2);
|
|
1546
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 5, 23));
|
|
1547
|
+
(0, chai_config_spec_1.expect)(file.functionScopes[1].range).to.eql(vscode_languageserver_1.Range.create(2, 30, 4, 32));
|
|
1549
1548
|
});
|
|
1550
1549
|
});
|
|
1551
1550
|
it('handles mixed case `then` partions of conditionals', () => {
|
|
1552
|
-
let mainFile = program.setFile(
|
|
1551
|
+
let mainFile = program.setFile('source/main.brs', `
|
|
1553
1552
|
sub Main()
|
|
1554
1553
|
if true then
|
|
1555
1554
|
print "works"
|
|
1556
1555
|
end if
|
|
1557
1556
|
end sub
|
|
1558
1557
|
`);
|
|
1559
|
-
(0,
|
|
1560
|
-
mainFile = program.setFile(
|
|
1558
|
+
(0, chai_config_spec_1.expect)(mainFile.getDiagnostics()).to.be.lengthOf(0);
|
|
1559
|
+
mainFile = program.setFile('source/main.brs', `
|
|
1561
1560
|
sub Main()
|
|
1562
1561
|
if true Then
|
|
1563
1562
|
print "works"
|
|
1564
1563
|
end if
|
|
1565
1564
|
end sub
|
|
1566
1565
|
`);
|
|
1567
|
-
(0,
|
|
1568
|
-
mainFile = program.setFile(
|
|
1566
|
+
(0, chai_config_spec_1.expect)(mainFile.getDiagnostics()).to.be.lengthOf(0);
|
|
1567
|
+
mainFile = program.setFile('source/main.brs', `
|
|
1569
1568
|
sub Main()
|
|
1570
1569
|
if true THEN
|
|
1571
1570
|
print "works"
|
|
1572
1571
|
end if
|
|
1573
1572
|
end sub
|
|
1574
1573
|
`);
|
|
1575
|
-
(0,
|
|
1574
|
+
(0, chai_config_spec_1.expect)(mainFile.getDiagnostics()).to.be.lengthOf(0);
|
|
1576
1575
|
});
|
|
1577
1576
|
describe('getHover', () => {
|
|
1578
1577
|
it('works for param types', () => {
|
|
1579
|
-
let file = program.setFile(
|
|
1578
|
+
let file = program.setFile('source/main.brs', `
|
|
1580
1579
|
sub DoSomething(name as string)
|
|
1581
1580
|
name = 1
|
|
1582
1581
|
sayMyName = function(name as string)
|
|
@@ -1585,28 +1584,28 @@ describe('BrsFile', () => {
|
|
|
1585
1584
|
`);
|
|
1586
1585
|
//hover over the `name = 1` line
|
|
1587
1586
|
let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(2, 24))[0];
|
|
1588
|
-
(0,
|
|
1589
|
-
(0,
|
|
1587
|
+
(0, chai_config_spec_1.expect)(hover).to.exist;
|
|
1588
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 24));
|
|
1590
1589
|
//hover over the `name` parameter declaration
|
|
1591
1590
|
hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(1, 34))[0];
|
|
1592
|
-
(0,
|
|
1593
|
-
(0,
|
|
1591
|
+
(0, chai_config_spec_1.expect)(hover).to.exist;
|
|
1592
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(1, 32, 1, 36));
|
|
1594
1593
|
});
|
|
1595
1594
|
//ignore this for now...it's not a huge deal
|
|
1596
1595
|
it('does not match on keywords or data types', () => {
|
|
1597
|
-
let file = program.setFile(
|
|
1596
|
+
let file = program.setFile('source/main.brs', `
|
|
1598
1597
|
sub Main(name as string)
|
|
1599
1598
|
end sub
|
|
1600
1599
|
sub as()
|
|
1601
1600
|
end sub
|
|
1602
1601
|
`);
|
|
1603
1602
|
//hover over the `as`
|
|
1604
|
-
(0,
|
|
1603
|
+
(0, chai_config_spec_1.expect)(program.getHover(file.srcPath, vscode_languageserver_1.Position.create(1, 31))).to.be.empty;
|
|
1605
1604
|
//hover over the `string`
|
|
1606
|
-
(0,
|
|
1605
|
+
(0, chai_config_spec_1.expect)(program.getHover(file.srcPath, vscode_languageserver_1.Position.create(1, 36))).to.be.empty;
|
|
1607
1606
|
});
|
|
1608
1607
|
it('finds declared function', () => {
|
|
1609
|
-
let file = program.setFile(
|
|
1608
|
+
let file = program.setFile('source/main.brs', `
|
|
1610
1609
|
function Main(count = 1)
|
|
1611
1610
|
firstName = "bob"
|
|
1612
1611
|
age = 21
|
|
@@ -1614,16 +1613,16 @@ describe('BrsFile', () => {
|
|
|
1614
1613
|
end function
|
|
1615
1614
|
`);
|
|
1616
1615
|
let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(1, 28))[0];
|
|
1617
|
-
(0,
|
|
1618
|
-
(0,
|
|
1619
|
-
(0,
|
|
1616
|
+
(0, chai_config_spec_1.expect)(hover).to.exist;
|
|
1617
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(1, 25, 1, 29));
|
|
1618
|
+
(0, chai_config_spec_1.expect)(hover.contents).to.equal([
|
|
1620
1619
|
'```brightscript',
|
|
1621
1620
|
'function Main(count? as dynamic) as dynamic',
|
|
1622
1621
|
'```'
|
|
1623
1622
|
].join('\n'));
|
|
1624
1623
|
});
|
|
1625
1624
|
it('finds declared namespace function', () => {
|
|
1626
|
-
let file = program.setFile(
|
|
1625
|
+
let file = program.setFile('source/main.brs', `
|
|
1627
1626
|
namespace mySpace
|
|
1628
1627
|
function Main(count = 1)
|
|
1629
1628
|
firstName = "bob"
|
|
@@ -1633,16 +1632,16 @@ describe('BrsFile', () => {
|
|
|
1633
1632
|
end namespace
|
|
1634
1633
|
`);
|
|
1635
1634
|
let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(2, 28))[0];
|
|
1636
|
-
(0,
|
|
1637
|
-
(0,
|
|
1638
|
-
(0,
|
|
1635
|
+
(0, chai_config_spec_1.expect)(hover).to.exist;
|
|
1636
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 25, 2, 29));
|
|
1637
|
+
(0, chai_config_spec_1.expect)(hover.contents).to.equal([
|
|
1639
1638
|
'```brightscript',
|
|
1640
1639
|
'function Main(count? as dynamic) as dynamic',
|
|
1641
1640
|
'```'
|
|
1642
1641
|
].join('\n'));
|
|
1643
1642
|
});
|
|
1644
1643
|
it('finds variable function hover in same scope', () => {
|
|
1645
|
-
let file = program.setFile(
|
|
1644
|
+
let file = program.setFile('source/main.brs', `
|
|
1646
1645
|
sub Main()
|
|
1647
1646
|
sayMyName = sub(name as string)
|
|
1648
1647
|
end sub
|
|
@@ -1651,8 +1650,8 @@ describe('BrsFile', () => {
|
|
|
1651
1650
|
end sub
|
|
1652
1651
|
`);
|
|
1653
1652
|
let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(5, 24))[0];
|
|
1654
|
-
(0,
|
|
1655
|
-
(0,
|
|
1653
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(5, 20, 5, 29));
|
|
1654
|
+
(0, chai_config_spec_1.expect)(hover.contents).to.equal([
|
|
1656
1655
|
'```brightscript',
|
|
1657
1656
|
'sub sayMyName(name as string) as void',
|
|
1658
1657
|
'```'
|
|
@@ -1664,7 +1663,7 @@ describe('BrsFile', () => {
|
|
|
1664
1663
|
return ucase(text)
|
|
1665
1664
|
end function
|
|
1666
1665
|
`);
|
|
1667
|
-
(0,
|
|
1666
|
+
(0, chai_config_spec_1.expect)(program.getHover(file.srcPath, vscode_languageserver_1.Position.create(2, 30))[0].contents).to.equal([
|
|
1668
1667
|
'```brightscript',
|
|
1669
1668
|
'function UCase(s as string) as string',
|
|
1670
1669
|
'```'
|
|
@@ -1676,7 +1675,7 @@ describe('BrsFile', () => {
|
|
|
1676
1675
|
return url.instr(text)
|
|
1677
1676
|
end function
|
|
1678
1677
|
`);
|
|
1679
|
-
(0,
|
|
1678
|
+
(0, chai_config_spec_1.expect)(program.getHover(file.srcPath, vscode_languageserver_1.Position.create(2, 35))[0].contents).to.equal([
|
|
1680
1679
|
'```brightscript',
|
|
1681
1680
|
//TODO this really shouldn't be returning the global function, but it does...so make sure it doesn't crash right now.
|
|
1682
1681
|
'function Instr(start as integer, text as string, substring as string) as integer',
|
|
@@ -1684,7 +1683,7 @@ describe('BrsFile', () => {
|
|
|
1684
1683
|
].join('\n'));
|
|
1685
1684
|
});
|
|
1686
1685
|
it('finds function hover in file scope', () => {
|
|
1687
|
-
let file = program.setFile(
|
|
1686
|
+
let file = program.setFile('source/main.brs', `
|
|
1688
1687
|
sub Main()
|
|
1689
1688
|
sayMyName()
|
|
1690
1689
|
end sub
|
|
@@ -1694,15 +1693,15 @@ describe('BrsFile', () => {
|
|
|
1694
1693
|
end sub
|
|
1695
1694
|
`);
|
|
1696
1695
|
let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(2, 25))[0];
|
|
1697
|
-
(0,
|
|
1698
|
-
(0,
|
|
1696
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 29));
|
|
1697
|
+
(0, chai_config_spec_1.expect)(hover.contents).to.equal([
|
|
1699
1698
|
'```brightscript',
|
|
1700
1699
|
'sub sayMyName() as void',
|
|
1701
1700
|
'```'
|
|
1702
1701
|
].join('\n'));
|
|
1703
1702
|
});
|
|
1704
1703
|
it('finds namespace function hover in file scope', () => {
|
|
1705
|
-
let file = program.setFile(
|
|
1704
|
+
let file = program.setFile('source/main.brs', `
|
|
1706
1705
|
namespace mySpace
|
|
1707
1706
|
sub Main()
|
|
1708
1707
|
sayMyName()
|
|
@@ -1714,8 +1713,8 @@ describe('BrsFile', () => {
|
|
|
1714
1713
|
end namespace
|
|
1715
1714
|
`);
|
|
1716
1715
|
let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(3, 25))[0];
|
|
1717
|
-
(0,
|
|
1718
|
-
(0,
|
|
1716
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(3, 20, 3, 29));
|
|
1717
|
+
(0, chai_config_spec_1.expect)(hover.contents).to.equal([
|
|
1719
1718
|
'```brightscript',
|
|
1720
1719
|
'sub sayMyName() as void',
|
|
1721
1720
|
'```'
|
|
@@ -1726,20 +1725,20 @@ describe('BrsFile', () => {
|
|
|
1726
1725
|
program = new Program_1.Program({
|
|
1727
1726
|
rootDir: rootDir
|
|
1728
1727
|
});
|
|
1729
|
-
let mainFile = program.setFile(
|
|
1728
|
+
let mainFile = program.setFile('source/main.brs', `
|
|
1730
1729
|
sub Main()
|
|
1731
1730
|
sayMyName()
|
|
1732
1731
|
end sub
|
|
1733
1732
|
`);
|
|
1734
|
-
program.setFile(
|
|
1733
|
+
program.setFile('source/lib.brs', `
|
|
1735
1734
|
sub sayMyName(name as string)
|
|
1736
1735
|
|
|
1737
1736
|
end sub
|
|
1738
1737
|
`);
|
|
1739
1738
|
let hover = program.getHover(mainFile.srcPath, vscode_languageserver_1.Position.create(2, 25))[0];
|
|
1740
|
-
(0,
|
|
1741
|
-
(0,
|
|
1742
|
-
(0,
|
|
1739
|
+
(0, chai_config_spec_1.expect)(hover).to.exist;
|
|
1740
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 20, 2, 29));
|
|
1741
|
+
(0, chai_config_spec_1.expect)(hover.contents).to.equal([
|
|
1743
1742
|
'```brightscript',
|
|
1744
1743
|
'sub sayMyName(name as string) as void',
|
|
1745
1744
|
'```'
|
|
@@ -1750,21 +1749,21 @@ describe('BrsFile', () => {
|
|
|
1750
1749
|
program = new Program_1.Program({
|
|
1751
1750
|
rootDir: rootDir
|
|
1752
1751
|
});
|
|
1753
|
-
let mainFile = program.setFile(
|
|
1752
|
+
let mainFile = program.setFile('source/main.brs', `
|
|
1754
1753
|
sub Main()
|
|
1755
1754
|
mySpace.sayMyName()
|
|
1756
1755
|
end sub
|
|
1757
1756
|
`);
|
|
1758
|
-
program.setFile(
|
|
1757
|
+
program.setFile('source/lib.brs', `
|
|
1759
1758
|
namespace mySpace
|
|
1760
1759
|
sub sayMyName(name as string)
|
|
1761
1760
|
end sub
|
|
1762
1761
|
end namespace
|
|
1763
1762
|
`);
|
|
1764
1763
|
let hover = program.getHover(mainFile.srcPath, vscode_languageserver_1.Position.create(2, 34))[0];
|
|
1765
|
-
(0,
|
|
1766
|
-
(0,
|
|
1767
|
-
(0,
|
|
1764
|
+
(0, chai_config_spec_1.expect)(hover).to.exist;
|
|
1765
|
+
(0, chai_config_spec_1.expect)(hover.range).to.eql(vscode_languageserver_1.Range.create(2, 28, 2, 37));
|
|
1766
|
+
(0, chai_config_spec_1.expect)(hover.contents).to.equal([
|
|
1768
1767
|
'```brightscript',
|
|
1769
1768
|
'sub sayMyName(name as string) as void',
|
|
1770
1769
|
'```'
|
|
@@ -1792,7 +1791,7 @@ describe('BrsFile', () => {
|
|
|
1792
1791
|
end sub
|
|
1793
1792
|
`);
|
|
1794
1793
|
//hover over log("hello")
|
|
1795
|
-
(0,
|
|
1794
|
+
(0, chai_config_spec_1.expect)(program.getHover(file.srcPath, vscode_languageserver_1.Position.create(5, 22))[0].contents).to.equal([
|
|
1796
1795
|
'```brightscript',
|
|
1797
1796
|
'sub log(message as string) as void',
|
|
1798
1797
|
'```',
|
|
@@ -1803,7 +1802,7 @@ describe('BrsFile', () => {
|
|
|
1803
1802
|
''
|
|
1804
1803
|
].join('\n'));
|
|
1805
1804
|
//hover over sub ma|in()
|
|
1806
|
-
(0,
|
|
1805
|
+
(0, chai_config_spec_1.expect)((0, testHelpers_spec_1.trim)(program.getHover(file.srcPath, vscode_languageserver_1.Position.create(4, 22))[0].contents.toString())).to.equal((0, testHelpers_spec_1.trim) `
|
|
1807
1806
|
\`\`\`brightscript
|
|
1808
1807
|
sub main() as void
|
|
1809
1808
|
\`\`\`
|
|
@@ -1813,7 +1812,7 @@ describe('BrsFile', () => {
|
|
|
1813
1812
|
`);
|
|
1814
1813
|
});
|
|
1815
1814
|
it('handles mixed case `then` partions of conditionals', () => {
|
|
1816
|
-
let mainFile = program.setFile(
|
|
1815
|
+
let mainFile = program.setFile('source/main.brs', `
|
|
1817
1816
|
sub Main()
|
|
1818
1817
|
if true then
|
|
1819
1818
|
print "works"
|
|
@@ -1821,7 +1820,7 @@ describe('BrsFile', () => {
|
|
|
1821
1820
|
end sub
|
|
1822
1821
|
`);
|
|
1823
1822
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(mainFile);
|
|
1824
|
-
mainFile = program.setFile(
|
|
1823
|
+
mainFile = program.setFile('source/main.brs', `
|
|
1825
1824
|
sub Main()
|
|
1826
1825
|
if true Then
|
|
1827
1826
|
print "works"
|
|
@@ -1829,7 +1828,7 @@ describe('BrsFile', () => {
|
|
|
1829
1828
|
end sub
|
|
1830
1829
|
`);
|
|
1831
1830
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(mainFile);
|
|
1832
|
-
mainFile = program.setFile(
|
|
1831
|
+
mainFile = program.setFile('source/main.brs', `
|
|
1833
1832
|
sub Main()
|
|
1834
1833
|
if true THEN
|
|
1835
1834
|
print "works"
|
|
@@ -1840,7 +1839,7 @@ describe('BrsFile', () => {
|
|
|
1840
1839
|
});
|
|
1841
1840
|
});
|
|
1842
1841
|
it('does not throw when encountering incomplete import statement', () => {
|
|
1843
|
-
program.setFile(
|
|
1842
|
+
program.setFile('source/main.brs', `
|
|
1844
1843
|
import
|
|
1845
1844
|
sub main()
|
|
1846
1845
|
end sub
|
|
@@ -2264,12 +2263,12 @@ describe('BrsFile', () => {
|
|
|
2264
2263
|
return consumer.generatedPositionFor({
|
|
2265
2264
|
line: 3,
|
|
2266
2265
|
column: 0,
|
|
2267
|
-
source: (0, util_1.standardizePath) `${rootDir}/source/main.bs`,
|
|
2266
|
+
source: (0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/source/main.bs`,
|
|
2268
2267
|
bias: source_map_1.SourceMapConsumer.LEAST_UPPER_BOUND
|
|
2269
2268
|
});
|
|
2270
2269
|
});
|
|
2271
|
-
(0,
|
|
2272
|
-
(0,
|
|
2270
|
+
(0, chai_config_spec_1.expect)(location.line).to.eql(2);
|
|
2271
|
+
(0, chai_config_spec_1.expect)(location.column).eql(4);
|
|
2273
2272
|
});
|
|
2274
2273
|
it('computes correct locations for sourcemap', async () => {
|
|
2275
2274
|
let source = `function abc(name)\n firstName = name\nend function`;
|
|
@@ -2297,7 +2296,7 @@ describe('BrsFile', () => {
|
|
|
2297
2296
|
originalPosition.line - 1, originalPosition.column)
|
|
2298
2297
|
};
|
|
2299
2298
|
});
|
|
2300
|
-
(0,
|
|
2299
|
+
(0, chai_config_spec_1.expect)(sourcemapResult).to.eql(tokenResult);
|
|
2301
2300
|
});
|
|
2302
2301
|
});
|
|
2303
2302
|
it('handles empty if block', () => {
|
|
@@ -2353,6 +2352,18 @@ describe('BrsFile', () => {
|
|
|
2353
2352
|
end sub
|
|
2354
2353
|
`);
|
|
2355
2354
|
});
|
|
2355
|
+
it('handles else block with a leading comment', () => {
|
|
2356
|
+
testTranspile(`
|
|
2357
|
+
sub main()
|
|
2358
|
+
if true then
|
|
2359
|
+
print "if"
|
|
2360
|
+
else
|
|
2361
|
+
' leading comment
|
|
2362
|
+
print "else"
|
|
2363
|
+
end if
|
|
2364
|
+
end sub
|
|
2365
|
+
`);
|
|
2366
|
+
});
|
|
2356
2367
|
it('works for function parameters', () => {
|
|
2357
2368
|
testTranspile(`
|
|
2358
2369
|
function DoSomething(name, age as integer, text as string)
|
|
@@ -2503,7 +2514,7 @@ describe('BrsFile', () => {
|
|
|
2503
2514
|
`);
|
|
2504
2515
|
file.needsTranspiled = false;
|
|
2505
2516
|
const { code } = file.transpile();
|
|
2506
|
-
(0,
|
|
2517
|
+
(0, chai_config_spec_1.expect)(code.endsWith(`'//# sourceMappingURL=./logger.brs.map`)).to.be.true;
|
|
2507
2518
|
});
|
|
2508
2519
|
it('AST generated files include a reference to the source map', () => {
|
|
2509
2520
|
let file = program.setFile('source/logger.brs', (0, testHelpers_spec_1.trim) `
|
|
@@ -2512,7 +2523,7 @@ describe('BrsFile', () => {
|
|
|
2512
2523
|
`);
|
|
2513
2524
|
file.needsTranspiled = true;
|
|
2514
2525
|
const { code } = file.transpile();
|
|
2515
|
-
(0,
|
|
2526
|
+
(0, chai_config_spec_1.expect)(code.endsWith(`'//# sourceMappingURL=./logger.brs.map`)).to.be.true;
|
|
2516
2527
|
});
|
|
2517
2528
|
it('replaces custom types in parameter types and return types', () => {
|
|
2518
2529
|
program.setFile('source/SomeKlass.bs', `
|
|
@@ -2590,34 +2601,34 @@ describe('BrsFile', () => {
|
|
|
2590
2601
|
name: 'transform callback',
|
|
2591
2602
|
afterFileParse: onParsed
|
|
2592
2603
|
});
|
|
2593
|
-
file = program.setFile(
|
|
2604
|
+
file = program.setFile(`source/file${ext}`, `
|
|
2594
2605
|
sub Sum()
|
|
2595
2606
|
print "hello world"
|
|
2596
2607
|
end sub
|
|
2597
2608
|
`);
|
|
2598
|
-
(0,
|
|
2609
|
+
(0, chai_config_spec_1.expect)(file.extension).to.equal(ext);
|
|
2599
2610
|
return file;
|
|
2600
2611
|
}
|
|
2601
2612
|
it('called for BRS file', () => {
|
|
2602
2613
|
const onParsed = sinon.spy();
|
|
2603
2614
|
parseFileWithCallback('.brs', onParsed);
|
|
2604
|
-
(0,
|
|
2615
|
+
(0, chai_config_spec_1.expect)(onParsed.callCount).to.equal(1);
|
|
2605
2616
|
});
|
|
2606
2617
|
it('called for BR file', () => {
|
|
2607
2618
|
const onParsed = sinon.spy();
|
|
2608
2619
|
parseFileWithCallback('.bs', onParsed);
|
|
2609
|
-
(0,
|
|
2620
|
+
(0, chai_config_spec_1.expect)(onParsed.callCount).to.equal(1);
|
|
2610
2621
|
});
|
|
2611
2622
|
});
|
|
2612
2623
|
describe('typedefKey', () => {
|
|
2613
2624
|
it('works for .brs files', () => {
|
|
2614
|
-
(0,
|
|
2625
|
+
(0, chai_config_spec_1.expect)((0, util_1.standardizePath)((program.setFile('source/main.brs', '')).typedefKey)).to.equal((0, util_1.standardizePath) `${testHelpers_spec_2.rootDir.toLowerCase()}/source/main.d.bs`);
|
|
2615
2626
|
});
|
|
2616
2627
|
it('returns undefined for files that should not have a typedef', () => {
|
|
2617
|
-
(0,
|
|
2618
|
-
(0,
|
|
2628
|
+
(0, chai_config_spec_1.expect)((program.setFile('source/main.bs', '')).typedefKey).to.be.undefined;
|
|
2629
|
+
(0, chai_config_spec_1.expect)((program.setFile('source/main.d.bs', '')).typedefKey).to.be.undefined;
|
|
2619
2630
|
const xmlFile = program.setFile('components/comp.xml', '');
|
|
2620
|
-
(0,
|
|
2631
|
+
(0, chai_config_spec_1.expect)(xmlFile.typedefKey).to.be.undefined;
|
|
2621
2632
|
});
|
|
2622
2633
|
});
|
|
2623
2634
|
describe('type definitions', () => {
|
|
@@ -2635,8 +2646,8 @@ describe('BrsFile', () => {
|
|
|
2635
2646
|
`);
|
|
2636
2647
|
const sourceScope = program.getScopeByName('source');
|
|
2637
2648
|
const functionNames = sourceScope.getAllCallables().map(x => x.callable.name);
|
|
2638
|
-
(0,
|
|
2639
|
-
(0,
|
|
2649
|
+
(0, chai_config_spec_1.expect)(functionNames).to.include('main');
|
|
2650
|
+
(0, chai_config_spec_1.expect)(functionNames).not.to.include('speak');
|
|
2640
2651
|
});
|
|
2641
2652
|
it('reacts to typedef file changes', () => {
|
|
2642
2653
|
let file = program.setFile('source/main.brs', `
|
|
@@ -2645,14 +2656,14 @@ describe('BrsFile', () => {
|
|
|
2645
2656
|
sub speak()
|
|
2646
2657
|
end sub
|
|
2647
2658
|
`);
|
|
2648
|
-
(0,
|
|
2649
|
-
(0,
|
|
2659
|
+
(0, chai_config_spec_1.expect)(file.hasTypedef).to.be.false;
|
|
2660
|
+
(0, chai_config_spec_1.expect)(file.typedefFile).not.to.exist;
|
|
2650
2661
|
program.setFile('source/main.d.bs', `
|
|
2651
2662
|
sub main()
|
|
2652
2663
|
end sub
|
|
2653
2664
|
`);
|
|
2654
|
-
(0,
|
|
2655
|
-
(0,
|
|
2665
|
+
(0, chai_config_spec_1.expect)(file.hasTypedef).to.be.true;
|
|
2666
|
+
(0, chai_config_spec_1.expect)(file.typedefFile).to.exist;
|
|
2656
2667
|
//add replace file, does it still find the typedef
|
|
2657
2668
|
file = program.setFile('source/main.brs', `
|
|
2658
2669
|
sub main()
|
|
@@ -2660,47 +2671,47 @@ describe('BrsFile', () => {
|
|
|
2660
2671
|
sub speak()
|
|
2661
2672
|
end sub
|
|
2662
2673
|
`);
|
|
2663
|
-
(0,
|
|
2664
|
-
(0,
|
|
2665
|
-
program.removeFile((0, util_1.standardizePath) `${rootDir}/source/main.d.bs`);
|
|
2666
|
-
(0,
|
|
2667
|
-
(0,
|
|
2674
|
+
(0, chai_config_spec_1.expect)(file.hasTypedef).to.be.true;
|
|
2675
|
+
(0, chai_config_spec_1.expect)(file.typedefFile).to.exist;
|
|
2676
|
+
program.removeFile((0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/source/main.d.bs`);
|
|
2677
|
+
(0, chai_config_spec_1.expect)(file.hasTypedef).to.be.false;
|
|
2678
|
+
(0, chai_config_spec_1.expect)(file.typedefFile).not.to.exist;
|
|
2668
2679
|
});
|
|
2669
2680
|
});
|
|
2670
2681
|
describe('typedef', () => {
|
|
2671
2682
|
it('sets typedef path properly', () => {
|
|
2672
|
-
(0,
|
|
2673
|
-
(0,
|
|
2674
|
-
(0,
|
|
2683
|
+
(0, chai_config_spec_1.expect)((program.setFile('source/main1.brs', '')).typedefKey).to.equal((0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/source/main1.d.bs`.toLowerCase());
|
|
2684
|
+
(0, chai_config_spec_1.expect)((program.setFile('source/main2.d.bs', '')).typedefKey).to.equal(undefined);
|
|
2685
|
+
(0, chai_config_spec_1.expect)((program.setFile('source/main3.bs', '')).typedefKey).to.equal(undefined);
|
|
2675
2686
|
//works for dest with `.brs` extension
|
|
2676
|
-
(0,
|
|
2687
|
+
(0, chai_config_spec_1.expect)((program.setFile({ src: 'source/main4.bs', dest: 'source/main4.brs' }, '')).typedefKey).to.equal(undefined);
|
|
2677
2688
|
});
|
|
2678
2689
|
it('does not link when missing from program', () => {
|
|
2679
2690
|
const file = program.setFile('source/main.brs', ``);
|
|
2680
|
-
(0,
|
|
2691
|
+
(0, chai_config_spec_1.expect)(file.typedefFile).not.to.exist;
|
|
2681
2692
|
});
|
|
2682
2693
|
it('links typedef when added BEFORE .brs file', () => {
|
|
2683
2694
|
const typedef = program.setFile('source/main.d.bs', ``);
|
|
2684
2695
|
const file = program.setFile('source/main.brs', ``);
|
|
2685
|
-
(0,
|
|
2696
|
+
(0, chai_config_spec_1.expect)(file.typedefFile).to.equal(typedef);
|
|
2686
2697
|
});
|
|
2687
2698
|
it('links typedef when added AFTER .brs file', () => {
|
|
2688
2699
|
const file = program.setFile('source/main.brs', ``);
|
|
2689
2700
|
const typedef = program.setFile('source/main.d.bs', ``);
|
|
2690
|
-
(0,
|
|
2701
|
+
(0, chai_config_spec_1.expect)(file.typedefFile).to.eql(typedef);
|
|
2691
2702
|
});
|
|
2692
2703
|
it('removes typedef link when typedef is removed', () => {
|
|
2693
2704
|
const typedef = program.setFile('source/main.d.bs', ``);
|
|
2694
2705
|
const file = program.setFile('source/main.brs', ``);
|
|
2695
2706
|
program.removeFile(typedef.srcPath);
|
|
2696
|
-
(0,
|
|
2707
|
+
(0, chai_config_spec_1.expect)(file.typedefFile).to.be.undefined;
|
|
2697
2708
|
});
|
|
2698
2709
|
});
|
|
2699
2710
|
describe('getTypedef', () => {
|
|
2700
2711
|
function testTypedef(original, expected) {
|
|
2701
2712
|
let file = program.setFile('source/main.brs', original);
|
|
2702
2713
|
program.validate();
|
|
2703
|
-
(0,
|
|
2714
|
+
(0, chai_config_spec_1.expect)(file.getTypedef().trimEnd()).to.eql(expected);
|
|
2704
2715
|
}
|
|
2705
2716
|
it('includes namespace on extend class names', () => {
|
|
2706
2717
|
testTypedef(`
|
|
@@ -2989,9 +3000,9 @@ describe('BrsFile', () => {
|
|
|
2989
3000
|
file['_parser'] = undefined;
|
|
2990
3001
|
//force the file to get a new instance of parser
|
|
2991
3002
|
const newParser = file.parser;
|
|
2992
|
-
(0,
|
|
3003
|
+
(0, chai_config_spec_1.expect)(newParser).to.exist.and.to.not.equal(parser);
|
|
2993
3004
|
//reference shouldn't change in subsequent accesses
|
|
2994
|
-
(0,
|
|
3005
|
+
(0, chai_config_spec_1.expect)(file.parser).to.equal(newParser);
|
|
2995
3006
|
});
|
|
2996
3007
|
it('call parse when previously skipped', () => {
|
|
2997
3008
|
program.setFile('source/main.d.bs', `'typedef
|
|
@@ -3003,11 +3014,11 @@ describe('BrsFile', () => {
|
|
|
3003
3014
|
end sub
|
|
3004
3015
|
`);
|
|
3005
3016
|
//no functions should be found since the parser was skipped
|
|
3006
|
-
(0,
|
|
3017
|
+
(0, chai_config_spec_1.expect)(file['_parser']).to.not.exist;
|
|
3007
3018
|
const stub = sinon.stub(file, 'parse').callThrough();
|
|
3008
3019
|
//`file.parser` is a getter, so that should force the parse to occur
|
|
3009
|
-
(0,
|
|
3010
|
-
(0,
|
|
3020
|
+
(0, chai_config_spec_1.expect)(file.parser.references.functionStatements).to.be.lengthOf(1);
|
|
3021
|
+
(0, chai_config_spec_1.expect)(stub.called).to.be.true;
|
|
3011
3022
|
//parse should have been called
|
|
3012
3023
|
});
|
|
3013
3024
|
});
|
|
@@ -3016,7 +3027,7 @@ describe('BrsFile', () => {
|
|
|
3016
3027
|
let idx = 1;
|
|
3017
3028
|
beforeEach(() => {
|
|
3018
3029
|
pluginFileName = `plugin-${idx++}.js`;
|
|
3019
|
-
fsExtra.outputFileSync((0, util_1.standardizePath) `${tempDir}/plugins/${pluginFileName}`, `
|
|
3030
|
+
fsExtra.outputFileSync((0, util_1.standardizePath) `${testHelpers_spec_2.tempDir}/plugins/${pluginFileName}`, `
|
|
3020
3031
|
function plugin() {
|
|
3021
3032
|
return {
|
|
3022
3033
|
name: 'lower-file-name',
|
|
@@ -3029,18 +3040,18 @@ describe('BrsFile', () => {
|
|
|
3029
3040
|
`);
|
|
3030
3041
|
});
|
|
3031
3042
|
it('can load an absolute plugin which receives callbacks', () => {
|
|
3032
|
-
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins(tempDir, [
|
|
3033
|
-
(0, util_1.standardizePath) `${tempDir}/plugins/${pluginFileName}`
|
|
3043
|
+
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins(testHelpers_spec_2.tempDir, [
|
|
3044
|
+
(0, util_1.standardizePath) `${testHelpers_spec_2.tempDir}/plugins/${pluginFileName}`
|
|
3034
3045
|
]), new Logger_1.Logger());
|
|
3035
3046
|
const file = program.setFile('source/MAIN.brs', '');
|
|
3036
|
-
(0,
|
|
3047
|
+
(0, chai_config_spec_1.expect)(file._customProp).to.exist;
|
|
3037
3048
|
});
|
|
3038
3049
|
it('can load a relative plugin which receives callbacks', () => {
|
|
3039
|
-
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins(tempDir, [
|
|
3050
|
+
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins(testHelpers_spec_2.tempDir, [
|
|
3040
3051
|
`./plugins/${pluginFileName}`
|
|
3041
3052
|
]), new Logger_1.Logger());
|
|
3042
3053
|
const file = program.setFile('source/MAIN.brs', '');
|
|
3043
|
-
(0,
|
|
3054
|
+
(0, chai_config_spec_1.expect)(file._customProp).to.exist;
|
|
3044
3055
|
});
|
|
3045
3056
|
});
|
|
3046
3057
|
describe('getDefinition', () => {
|
|
@@ -3055,11 +3066,47 @@ describe('BrsFile', () => {
|
|
|
3055
3066
|
`);
|
|
3056
3067
|
program.validate();
|
|
3057
3068
|
//print alpha.beta.char|lie
|
|
3058
|
-
(0,
|
|
3069
|
+
(0, chai_config_spec_1.expect)(program.getDefinition(file.srcPath, vscode_languageserver_1.Position.create(2, 41))).to.eql([{
|
|
3059
3070
|
uri: vscode_uri_1.URI.file(file.srcPath).toString(),
|
|
3060
3071
|
range: util_1.default.createRange(5, 26, 5, 33)
|
|
3061
3072
|
}]);
|
|
3062
3073
|
});
|
|
3074
|
+
it('returns enum locations', () => {
|
|
3075
|
+
const file = program.setFile('source/main.bs', `
|
|
3076
|
+
sub main()
|
|
3077
|
+
print alpha.beta.people.charlie
|
|
3078
|
+
end sub
|
|
3079
|
+
namespace alpha.beta
|
|
3080
|
+
enum people
|
|
3081
|
+
charlie = "charles"
|
|
3082
|
+
end enum
|
|
3083
|
+
end namespace
|
|
3084
|
+
`);
|
|
3085
|
+
program.validate();
|
|
3086
|
+
//print alpha.beta.char|lie
|
|
3087
|
+
(0, chai_config_spec_1.expect)(program.getDefinition(file.srcPath, vscode_languageserver_1.Position.create(2, 40))).to.eql([{
|
|
3088
|
+
uri: vscode_uri_1.URI.file(file.srcPath).toString(),
|
|
3089
|
+
range: util_1.default.createRange(5, 25, 5, 31)
|
|
3090
|
+
}]);
|
|
3091
|
+
});
|
|
3092
|
+
it('returns enum member locations', () => {
|
|
3093
|
+
const file = program.setFile('source/main.bs', `
|
|
3094
|
+
sub main()
|
|
3095
|
+
print alpha.beta.people.charlie
|
|
3096
|
+
end sub
|
|
3097
|
+
namespace alpha.beta
|
|
3098
|
+
enum people
|
|
3099
|
+
charlie = "charles"
|
|
3100
|
+
end enum
|
|
3101
|
+
end namespace
|
|
3102
|
+
`);
|
|
3103
|
+
program.validate();
|
|
3104
|
+
//print alpha.beta.char|lie
|
|
3105
|
+
(0, chai_config_spec_1.expect)(program.getDefinition(file.srcPath, vscode_languageserver_1.Position.create(2, 48))).to.eql([{
|
|
3106
|
+
uri: vscode_uri_1.URI.file(file.srcPath).toString(),
|
|
3107
|
+
range: util_1.default.createRange(6, 24, 6, 31)
|
|
3108
|
+
}]);
|
|
3109
|
+
});
|
|
3063
3110
|
});
|
|
3064
3111
|
});
|
|
3065
3112
|
//# sourceMappingURL=BrsFile.spec.js.map
|