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 path = require("path");
|
|
5
5
|
const sinonImport = require("sinon");
|
|
6
6
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
@@ -14,21 +14,18 @@ const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
|
14
14
|
const ProgramBuilder_1 = require("../ProgramBuilder");
|
|
15
15
|
const Logger_1 = require("../Logger");
|
|
16
16
|
const reflection_1 = require("../astUtils/reflection");
|
|
17
|
+
const testHelpers_spec_2 = require("../testHelpers.spec");
|
|
17
18
|
describe('XmlFile', () => {
|
|
18
|
-
const tempDir = (0, util_1.standardizePath) `${process.cwd()}/.tmp`;
|
|
19
|
-
const rootDir = (0, util_1.standardizePath) `${tempDir}/rootDir`;
|
|
20
|
-
const stagingDir = (0, util_1.standardizePath) `${tempDir}/stagingDir`;
|
|
21
19
|
let program;
|
|
22
20
|
let sinon = sinonImport.createSandbox();
|
|
23
21
|
let file;
|
|
24
|
-
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, rootDir]);
|
|
22
|
+
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, testHelpers_spec_2.rootDir]);
|
|
25
23
|
beforeEach(() => {
|
|
26
|
-
fsExtra.
|
|
27
|
-
fsExtra.
|
|
28
|
-
fsExtra.ensureDirSync(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
file = new XmlFile_1.XmlFile(`${rootDir}/components/MainComponent.xml`, 'components/MainComponent.xml', program);
|
|
24
|
+
fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
|
|
25
|
+
fsExtra.ensureDirSync(testHelpers_spec_2.rootDir);
|
|
26
|
+
fsExtra.ensureDirSync(testHelpers_spec_2.stagingDir);
|
|
27
|
+
program = new Program_1.Program({ rootDir: testHelpers_spec_2.rootDir });
|
|
28
|
+
file = new XmlFile_1.XmlFile(`${testHelpers_spec_2.rootDir}/components/MainComponent.xml`, 'components/MainComponent.xml', program);
|
|
32
29
|
});
|
|
33
30
|
afterEach(() => {
|
|
34
31
|
sinon.restore();
|
|
@@ -51,7 +48,7 @@ describe('XmlFile', () => {
|
|
|
51
48
|
<component name="ChildScene" extends="Scene">
|
|
52
49
|
</component>
|
|
53
50
|
`);
|
|
54
|
-
(0,
|
|
51
|
+
(0, chai_config_spec_1.expect)(file.componentName.text).to.equal(expected);
|
|
55
52
|
});
|
|
56
53
|
it('only removes specified attribute when calling setAttribute', () => {
|
|
57
54
|
file = new XmlFile_1.XmlFile('abs', 'rel', program);
|
|
@@ -59,13 +56,13 @@ describe('XmlFile', () => {
|
|
|
59
56
|
name: 'allows modifying the parsed XML model',
|
|
60
57
|
afterFileParse: () => {
|
|
61
58
|
let child = file.parser.ast.component.children.children[0];
|
|
62
|
-
(0,
|
|
59
|
+
(0, chai_config_spec_1.expect)(child.attributes).to.have.lengthOf(4);
|
|
63
60
|
child.setAttribute('text', undefined);
|
|
64
|
-
(0,
|
|
65
|
-
(0,
|
|
61
|
+
(0, chai_config_spec_1.expect)(child.getAttribute('id').value.text).to.equal('one');
|
|
62
|
+
(0, chai_config_spec_1.expect)(child.attributes).to.have.lengthOf(3);
|
|
66
63
|
child.setAttribute('text3', undefined);
|
|
67
|
-
(0,
|
|
68
|
-
(0,
|
|
64
|
+
(0, chai_config_spec_1.expect)(child.getAttribute('id').value.text).to.equal('one');
|
|
65
|
+
(0, chai_config_spec_1.expect)(child.attributes).to.have.lengthOf(2);
|
|
69
66
|
}
|
|
70
67
|
});
|
|
71
68
|
file.parse((0, testHelpers_spec_1.trim) `
|
|
@@ -83,17 +80,17 @@ describe('XmlFile', () => {
|
|
|
83
80
|
`);
|
|
84
81
|
});
|
|
85
82
|
it('supports importing BrighterScript files', () => {
|
|
86
|
-
file = program.setFile(
|
|
83
|
+
file = program.setFile('components/custom.xml', (0, testHelpers_spec_1.trim) `
|
|
87
84
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
88
85
|
<component name="ChildScene" extends="Scene">
|
|
89
86
|
<script type="text/brightscript" uri="ChildScene.bs" />
|
|
90
87
|
</component>
|
|
91
88
|
`);
|
|
92
|
-
(0,
|
|
89
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports.map(x => x.pkgPath)[0]).to.equal((0, util_1.standardizePath) `components/ChildScene.bs`);
|
|
93
90
|
});
|
|
94
91
|
it('does not include commented-out script imports', () => {
|
|
95
92
|
var _a, _b;
|
|
96
|
-
file = program.setFile(
|
|
93
|
+
file = program.setFile('components/custom.xml', (0, testHelpers_spec_1.trim) `
|
|
97
94
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
98
95
|
<component name="ChildScene" extends="Scene">
|
|
99
96
|
<script type="text/brightscript" uri="ChildScene.brs" />
|
|
@@ -102,7 +99,7 @@ describe('XmlFile', () => {
|
|
|
102
99
|
-->
|
|
103
100
|
</component>
|
|
104
101
|
`);
|
|
105
|
-
(0,
|
|
102
|
+
(0, chai_config_spec_1.expect)((_b = (_a = file.scriptTagImports) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.pkgPath).to.eql((0, util_1.standardizePath) `components/ChildScene.brs`);
|
|
106
103
|
});
|
|
107
104
|
it('finds scripts when more than one per line', () => {
|
|
108
105
|
file = new XmlFile_1.XmlFile('abs', 'rel', program);
|
|
@@ -112,16 +109,16 @@ describe('XmlFile', () => {
|
|
|
112
109
|
<script type="text/brightscript" uri="ChildScene1.brs" /> <script type="text/brightscript" uri="ChildScene2.brs" /> <script type="text/brightscript" uri="ChildScene3.brs" />
|
|
113
110
|
</component>
|
|
114
111
|
`);
|
|
115
|
-
(0,
|
|
116
|
-
(0,
|
|
112
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports).to.be.lengthOf(3);
|
|
113
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports[0]).to.deep.include({
|
|
117
114
|
text: 'ChildScene1.brs',
|
|
118
115
|
filePathRange: vscode_languageserver_1.Range.create(2, 42, 2, 57)
|
|
119
116
|
});
|
|
120
|
-
(0,
|
|
117
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports[1]).to.deep.include({
|
|
121
118
|
text: 'ChildScene2.brs',
|
|
122
119
|
filePathRange: vscode_languageserver_1.Range.create(2, 100, 2, 115)
|
|
123
120
|
});
|
|
124
|
-
(0,
|
|
121
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports[2]).to.deep.include({
|
|
125
122
|
text: 'ChildScene3.brs',
|
|
126
123
|
filePathRange: vscode_languageserver_1.Range.create(2, 158, 2, 173)
|
|
127
124
|
});
|
|
@@ -134,8 +131,8 @@ describe('XmlFile', () => {
|
|
|
134
131
|
<script type="text/brightscript" uri="ChildScene.brs" />
|
|
135
132
|
</component>
|
|
136
133
|
`);
|
|
137
|
-
(0,
|
|
138
|
-
(0,
|
|
134
|
+
(0, chai_config_spec_1.expect)(file.parentComponentName.text).to.equal('ParentScene');
|
|
135
|
+
(0, chai_config_spec_1.expect)(file.componentName.text).to.equal('ChildScene');
|
|
139
136
|
});
|
|
140
137
|
it('Adds error when whitespace appears before the prolog', () => {
|
|
141
138
|
file = new XmlFile_1.XmlFile('abs', 'rel', program);
|
|
@@ -144,12 +141,12 @@ describe('XmlFile', () => {
|
|
|
144
141
|
<component name="ChildScene" extends="ParentScene">
|
|
145
142
|
<script type="text/brightscript" uri="ChildScene.brs" />
|
|
146
143
|
</component>`);
|
|
147
|
-
(0,
|
|
148
|
-
(0,
|
|
144
|
+
(0, chai_config_spec_1.expect)(file.diagnostics).to.be.lengthOf(2);
|
|
145
|
+
(0, chai_config_spec_1.expect)(file.diagnostics[0]).to.deep.include({
|
|
149
146
|
code: DiagnosticMessages_1.DiagnosticMessages.xmlGenericParseError('').code,
|
|
150
147
|
range: vscode_languageserver_1.Range.create(1, 16, 1, 22)
|
|
151
148
|
});
|
|
152
|
-
(0,
|
|
149
|
+
(0, chai_config_spec_1.expect)(file.diagnostics[1]).to.deep.include(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlGenericParseError('Syntax error: whitespace found before the XML prolog')), { range: vscode_languageserver_1.Range.create(0, 0, 1, 16) }));
|
|
153
150
|
});
|
|
154
151
|
it('Adds error when an unknown tag is found in xml', () => {
|
|
155
152
|
file = new XmlFile_1.XmlFile('abs', 'rel', program);
|
|
@@ -162,9 +159,9 @@ describe('XmlFile', () => {
|
|
|
162
159
|
<unexpectedToo />
|
|
163
160
|
</component>
|
|
164
161
|
`);
|
|
165
|
-
(0,
|
|
166
|
-
(0,
|
|
167
|
-
(0,
|
|
162
|
+
(0, chai_config_spec_1.expect)(file.diagnostics).to.be.lengthOf(2);
|
|
163
|
+
(0, chai_config_spec_1.expect)(file.diagnostics[0]).to.deep.include(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlUnexpectedTag('unexpected')), { range: vscode_languageserver_1.Range.create(3, 9, 3, 19) }));
|
|
164
|
+
(0, chai_config_spec_1.expect)(file.diagnostics[1]).to.deep.include(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlUnexpectedTag('unexpectedToo')), { range: vscode_languageserver_1.Range.create(5, 5, 5, 18) }));
|
|
168
165
|
});
|
|
169
166
|
it('Adds error when no component is declared in xml', () => {
|
|
170
167
|
program.setFile('components/comp.xml', '<script type="text/brightscript" uri="ChildScene.brs" />');
|
|
@@ -182,8 +179,8 @@ describe('XmlFile', () => {
|
|
|
182
179
|
</component>
|
|
183
180
|
`);
|
|
184
181
|
program.validate();
|
|
185
|
-
(0,
|
|
186
|
-
(0,
|
|
182
|
+
(0, chai_config_spec_1.expect)(file.diagnostics).to.be.lengthOf(1);
|
|
183
|
+
(0, chai_config_spec_1.expect)(file.diagnostics[0]).to.deep.include({
|
|
187
184
|
message: DiagnosticMessages_1.DiagnosticMessages.xmlComponentMissingNameAttribute().message,
|
|
188
185
|
range: vscode_languageserver_1.Range.create(1, 1, 1, 10)
|
|
189
186
|
});
|
|
@@ -195,9 +192,9 @@ describe('XmlFile', () => {
|
|
|
195
192
|
</component>
|
|
196
193
|
`);
|
|
197
194
|
program.validate();
|
|
198
|
-
(0,
|
|
199
|
-
(0,
|
|
200
|
-
(0,
|
|
195
|
+
(0, chai_config_spec_1.expect)(file.diagnostics).to.be.lengthOf(2);
|
|
196
|
+
(0, chai_config_spec_1.expect)(file.diagnostics[0].code).to.equal(DiagnosticMessages_1.DiagnosticMessages.xmlGenericParseError('').code); //unexpected character '1'
|
|
197
|
+
(0, chai_config_spec_1.expect)(file.diagnostics[1]).to.deep.include({
|
|
201
198
|
code: DiagnosticMessages_1.DiagnosticMessages.xmlComponentMissingNameAttribute().code,
|
|
202
199
|
range: vscode_languageserver_1.Range.create(1, 1, 1, 10)
|
|
203
200
|
});
|
|
@@ -210,8 +207,8 @@ describe('XmlFile', () => {
|
|
|
210
207
|
<script type="text/brightscript" uri="pkg:/components/cmp1.brs" />
|
|
211
208
|
</component>
|
|
212
209
|
`);
|
|
213
|
-
(0,
|
|
214
|
-
(0,
|
|
210
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports.length).to.equal(1);
|
|
211
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports[0]).to.deep.include({
|
|
215
212
|
sourceFile: file,
|
|
216
213
|
text: 'pkg:/components/cmp1.brs',
|
|
217
214
|
pkgPath: `components${path.sep}cmp1.brs`,
|
|
@@ -223,74 +220,62 @@ describe('XmlFile', () => {
|
|
|
223
220
|
file.parse('a comment');
|
|
224
221
|
try {
|
|
225
222
|
file.parse(`'a new comment`);
|
|
226
|
-
|
|
223
|
+
chai_config_spec_1.assert.fail(null, null, 'Should have thrown an exception, but did not');
|
|
227
224
|
}
|
|
228
225
|
catch (e) {
|
|
229
226
|
//test passes
|
|
230
227
|
}
|
|
231
228
|
});
|
|
232
229
|
it('resolves relative paths', () => {
|
|
233
|
-
file = program.setFile(
|
|
234
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
235
|
-
dest: 'components/comp1.xml'
|
|
236
|
-
}, (0, testHelpers_spec_1.trim) `
|
|
230
|
+
file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
237
231
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
238
232
|
<component name="Cmp1" extends="Scene">
|
|
239
233
|
<script type="text/brightscript" uri="cmp1.brs" />
|
|
240
234
|
</component>
|
|
241
235
|
`);
|
|
242
|
-
(0,
|
|
243
|
-
(0,
|
|
236
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports.length).to.equal(1);
|
|
237
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports[0]).to.deep.include({
|
|
244
238
|
text: 'cmp1.brs',
|
|
245
239
|
pkgPath: `components${path.sep}cmp1.brs`
|
|
246
240
|
});
|
|
247
241
|
});
|
|
248
242
|
it('finds correct position for empty uri in script tag', () => {
|
|
249
243
|
var _a;
|
|
250
|
-
file = program.setFile(
|
|
251
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
252
|
-
dest: 'components/comp1.xml'
|
|
253
|
-
}, (0, testHelpers_spec_1.trim) `
|
|
244
|
+
file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
254
245
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
255
246
|
<component name="Cmp1" extends="Scene">
|
|
256
247
|
<script type="text/brightscript" uri="" />
|
|
257
248
|
</component>
|
|
258
249
|
`);
|
|
259
|
-
(0,
|
|
260
|
-
(0,
|
|
250
|
+
(0, chai_config_spec_1.expect)(file.scriptTagImports.length).to.equal(1);
|
|
251
|
+
(0, chai_config_spec_1.expect)((_a = file.scriptTagImports[0]) === null || _a === void 0 ? void 0 : _a.filePathRange).to.eql(vscode_languageserver_1.Range.create(2, 42, 2, 42));
|
|
261
252
|
});
|
|
262
253
|
});
|
|
263
254
|
describe('doesReferenceFile', () => {
|
|
264
255
|
it('compares case insensitive', () => {
|
|
265
|
-
let xmlFile = program.setFile(
|
|
266
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
267
|
-
dest: 'components/comp1.xml'
|
|
268
|
-
}, (0, testHelpers_spec_1.trim) `
|
|
256
|
+
let xmlFile = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
269
257
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
270
258
|
<component name="Cmp1" extends="Scene">
|
|
271
259
|
<script type="text/brightscript" uri="HeroGrid.brs" />
|
|
272
260
|
</component>
|
|
273
261
|
`);
|
|
274
|
-
let brsFile = program.setFile(
|
|
275
|
-
|
|
276
|
-
dest: `components/HEROGRID.brs`
|
|
277
|
-
}, ``);
|
|
278
|
-
(0, chai_1.expect)(xmlFile.doesReferenceFile(brsFile)).to.be.true;
|
|
262
|
+
let brsFile = program.setFile(`components/HEROGRID.brs`, ``);
|
|
263
|
+
(0, chai_config_spec_1.expect)(xmlFile.doesReferenceFile(brsFile)).to.be.true;
|
|
279
264
|
});
|
|
280
265
|
});
|
|
281
266
|
describe('autoImportComponentScript', () => {
|
|
282
267
|
it('is not enabled by default', () => {
|
|
283
|
-
program.setFile(
|
|
268
|
+
program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
284
269
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
285
270
|
<component name="ParentScene" extends="GrandparentScene">
|
|
286
271
|
<script type="text/brightscript" uri="./lib.brs" />
|
|
287
272
|
</component>
|
|
288
273
|
`);
|
|
289
|
-
program.setFile(
|
|
274
|
+
program.setFile('components/lib.brs', `
|
|
290
275
|
function libFunc()
|
|
291
276
|
end function
|
|
292
277
|
`);
|
|
293
|
-
program.setFile(
|
|
278
|
+
program.setFile('components/comp1.bs', `
|
|
294
279
|
function init()
|
|
295
280
|
libFunc()
|
|
296
281
|
end function
|
|
@@ -302,20 +287,20 @@ describe('XmlFile', () => {
|
|
|
302
287
|
});
|
|
303
288
|
it('is not enabled by default', () => {
|
|
304
289
|
program = new Program_1.Program({
|
|
305
|
-
rootDir: rootDir,
|
|
290
|
+
rootDir: testHelpers_spec_2.rootDir,
|
|
306
291
|
autoImportComponentScript: true
|
|
307
292
|
});
|
|
308
|
-
program.setFile(
|
|
293
|
+
program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
309
294
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
310
295
|
<component name="ParentScene" extends="GrandparentScene">
|
|
311
296
|
<script type="text/brightscript" uri="./lib.brs" />
|
|
312
297
|
</component>
|
|
313
298
|
`);
|
|
314
|
-
program.setFile(
|
|
299
|
+
program.setFile('components/lib.brs', `
|
|
315
300
|
function libFunc()
|
|
316
301
|
end function
|
|
317
302
|
`);
|
|
318
|
-
program.setFile(
|
|
303
|
+
program.setFile('components/comp1.bs', `
|
|
319
304
|
function init()
|
|
320
305
|
libFunc()
|
|
321
306
|
end function
|
|
@@ -329,35 +314,35 @@ describe('XmlFile', () => {
|
|
|
329
314
|
it('formats completion paths with proper slashes', () => {
|
|
330
315
|
let scriptPath = (0, util_1.standardizePath) `C:/app/components/component1/component1.brs`;
|
|
331
316
|
program.files[scriptPath] = new BrsFile_1.BrsFile(scriptPath, (0, util_1.standardizePath) `components/component1/component1.brs`, program);
|
|
332
|
-
let xmlFile = new XmlFile_1.XmlFile((0, util_1.standardizePath) `${rootDir}/components/component1/component1.xml`, (0, util_1.standardizePath) `components/component1/component1.xml`, program);
|
|
317
|
+
let xmlFile = new XmlFile_1.XmlFile((0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/components/component1/component1.xml`, (0, util_1.standardizePath) `components/component1/component1.xml`, program);
|
|
333
318
|
xmlFile.parser.references.scriptTagImports.push({
|
|
334
319
|
pkgPath: (0, util_1.standardizePath) `components/component1/component1.brs`,
|
|
335
320
|
text: 'component1.brs',
|
|
336
321
|
filePathRange: vscode_languageserver_1.Range.create(1, 1, 1, 1)
|
|
337
322
|
});
|
|
338
|
-
(0,
|
|
323
|
+
(0, chai_config_spec_1.expect)(xmlFile.getCompletions(vscode_languageserver_1.Position.create(1, 1))[0]).to.include({
|
|
339
324
|
label: 'component1.brs',
|
|
340
325
|
kind: vscode_languageserver_1.CompletionItemKind.File
|
|
341
326
|
});
|
|
342
|
-
(0,
|
|
327
|
+
(0, chai_config_spec_1.expect)(xmlFile.getCompletions(vscode_languageserver_1.Position.create(1, 1))[1]).to.include({
|
|
343
328
|
label: 'pkg:/components/component1/component1.brs',
|
|
344
329
|
kind: vscode_languageserver_1.CompletionItemKind.File
|
|
345
330
|
});
|
|
346
331
|
});
|
|
347
332
|
it('returns empty set when out of range', () => {
|
|
348
|
-
program.setFile(
|
|
349
|
-
(0,
|
|
333
|
+
program.setFile('components/component1.brs', ``);
|
|
334
|
+
(0, chai_config_spec_1.expect)(file.getCompletions(vscode_languageserver_1.Position.create(99, 99))).to.be.empty;
|
|
350
335
|
});
|
|
351
336
|
//TODO - refine this test once cdata scripts are supported
|
|
352
337
|
it('prevents scope completions entirely', () => {
|
|
353
|
-
program.setFile(
|
|
354
|
-
let xmlFile = program.setFile(
|
|
338
|
+
program.setFile('components/component1.brs', ``);
|
|
339
|
+
let xmlFile = program.setFile('components/component1.xml', (0, testHelpers_spec_1.trim) `
|
|
355
340
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
356
341
|
<component name="ParentScene" extends="GrandparentScene">
|
|
357
342
|
<script type="text/brightscript" uri="./Component1.brs" />
|
|
358
343
|
</component>
|
|
359
344
|
`);
|
|
360
|
-
(0,
|
|
345
|
+
(0, chai_config_spec_1.expect)(program.getCompletions(xmlFile.srcPath, vscode_languageserver_1.Position.create(1, 1))).to.be.empty;
|
|
361
346
|
});
|
|
362
347
|
});
|
|
363
348
|
describe('getAllDependencies', () => {
|
|
@@ -368,7 +353,7 @@ describe('XmlFile', () => {
|
|
|
368
353
|
<script type="text/brightscript" uri="pkg:/source/lib.brs" />
|
|
369
354
|
</component>
|
|
370
355
|
`);
|
|
371
|
-
(0,
|
|
356
|
+
(0, chai_config_spec_1.expect)(file.getOwnDependencies().sort()).to.eql([
|
|
372
357
|
(0, util_1.standardizePath) `source/lib.brs`,
|
|
373
358
|
(0, util_1.standardizePath) `source/lib.d.bs`
|
|
374
359
|
]);
|
|
@@ -376,7 +361,7 @@ describe('XmlFile', () => {
|
|
|
376
361
|
});
|
|
377
362
|
it('invalidates dependent scopes on change', () => {
|
|
378
363
|
let xmlFile = program.setFile({
|
|
379
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
364
|
+
src: `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
|
|
380
365
|
dest: `components/comp1.xml`
|
|
381
366
|
}, (0, testHelpers_spec_1.trim) `
|
|
382
367
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
@@ -387,42 +372,33 @@ describe('XmlFile', () => {
|
|
|
387
372
|
program.validate();
|
|
388
373
|
let scope = program.getScopesForFile(xmlFile)[0];
|
|
389
374
|
//scope should be validated
|
|
390
|
-
(0,
|
|
375
|
+
(0, chai_config_spec_1.expect)(scope.isValidated);
|
|
391
376
|
//add lib1
|
|
392
|
-
program.setFile(
|
|
393
|
-
src: `${rootDir}/source/lib.bs`,
|
|
394
|
-
dest: `source/lib.bs`
|
|
395
|
-
}, ``);
|
|
377
|
+
program.setFile(`source/lib.bs`, ``);
|
|
396
378
|
//adding a dependent file should have invalidated the scope
|
|
397
|
-
(0,
|
|
379
|
+
(0, chai_config_spec_1.expect)(scope.isValidated).to.be.false;
|
|
398
380
|
program.validate();
|
|
399
|
-
(0,
|
|
381
|
+
(0, chai_config_spec_1.expect)(scope.isValidated).to.be.true;
|
|
400
382
|
//update lib1 to include an import
|
|
401
|
-
program.setFile(
|
|
402
|
-
src: `${rootDir}/source/lib.bs`,
|
|
403
|
-
dest: `source/lib.bs`
|
|
404
|
-
}, `
|
|
383
|
+
program.setFile(`source/lib.bs`, `
|
|
405
384
|
import "lib2.bs"
|
|
406
385
|
`);
|
|
407
386
|
//scope should have been invalidated again
|
|
408
|
-
(0,
|
|
387
|
+
(0, chai_config_spec_1.expect)(scope.isValidated).to.be.false;
|
|
409
388
|
program.validate();
|
|
410
|
-
(0,
|
|
389
|
+
(0, chai_config_spec_1.expect)(scope.isValidated).to.be.true;
|
|
411
390
|
//add the lib2 imported from lib
|
|
412
|
-
program.setFile(
|
|
413
|
-
src: `${rootDir}/source/lib2.bs`,
|
|
414
|
-
dest: `source/lib2.bs`
|
|
415
|
-
}, ``);
|
|
391
|
+
program.setFile(`source/lib2.bs`, ``);
|
|
416
392
|
//scope should have been invalidated again because of chained dependency
|
|
417
|
-
(0,
|
|
393
|
+
(0, chai_config_spec_1.expect)(scope.isValidated).to.be.false;
|
|
418
394
|
program.validate();
|
|
419
|
-
(0,
|
|
420
|
-
program.removeFile(`${rootDir}/source/lib.bs`);
|
|
421
|
-
(0,
|
|
395
|
+
(0, chai_config_spec_1.expect)(scope.isValidated).to.be.true;
|
|
396
|
+
program.removeFile(`${testHelpers_spec_2.rootDir}/source/lib.bs`);
|
|
397
|
+
(0, chai_config_spec_1.expect)(scope.isValidated).to.be.false;
|
|
422
398
|
});
|
|
423
399
|
it('does not invalidate unrelated scopes on change', () => {
|
|
424
400
|
let xmlFile1 = program.setFile({
|
|
425
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
401
|
+
src: `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
|
|
426
402
|
dest: `components/comp1.xml`
|
|
427
403
|
}, (0, testHelpers_spec_1.trim) `
|
|
428
404
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
@@ -431,7 +407,7 @@ describe('XmlFile', () => {
|
|
|
431
407
|
</component>
|
|
432
408
|
`);
|
|
433
409
|
let xmlFile2 = program.setFile({
|
|
434
|
-
src: `${rootDir}/components/comp2.xml`,
|
|
410
|
+
src: `${testHelpers_spec_2.rootDir}/components/comp2.xml`,
|
|
435
411
|
dest: `components/comp2.xml`
|
|
436
412
|
}, (0, testHelpers_spec_1.trim) `
|
|
437
413
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
@@ -440,15 +416,12 @@ describe('XmlFile', () => {
|
|
|
440
416
|
`);
|
|
441
417
|
program.validate();
|
|
442
418
|
//scope should be validated
|
|
443
|
-
(0,
|
|
444
|
-
(0,
|
|
419
|
+
(0, chai_config_spec_1.expect)(program.getScopesForFile(xmlFile1)[0].isValidated).to.be.true;
|
|
420
|
+
(0, chai_config_spec_1.expect)(program.getScopesForFile(xmlFile2)[0].isValidated).to.be.true;
|
|
445
421
|
//add the lib file
|
|
446
|
-
program.setFile(
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
}, ``);
|
|
450
|
-
(0, chai_1.expect)(program.getScopesForFile(xmlFile1)[0].isValidated).to.be.false;
|
|
451
|
-
(0, chai_1.expect)(program.getScopesForFile(xmlFile2)[0].isValidated).to.be.true;
|
|
422
|
+
program.setFile(`source/lib.brs`, ``);
|
|
423
|
+
(0, chai_config_spec_1.expect)(program.getScopesForFile(xmlFile1)[0].isValidated).to.be.false;
|
|
424
|
+
(0, chai_config_spec_1.expect)(program.getScopesForFile(xmlFile2)[0].isValidated).to.be.true;
|
|
452
425
|
});
|
|
453
426
|
it('allows adding diagnostics', () => {
|
|
454
427
|
const expected = [{
|
|
@@ -462,18 +435,18 @@ describe('XmlFile', () => {
|
|
|
462
435
|
describe('component extends', () => {
|
|
463
436
|
it('works for single-line', () => {
|
|
464
437
|
file = program.setFile({
|
|
465
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
438
|
+
src: `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
|
|
466
439
|
dest: `components/comp1.xml`
|
|
467
440
|
}, (0, testHelpers_spec_1.trim) `
|
|
468
441
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
469
442
|
<component name="ChildScene" extends="BaseScene">
|
|
470
443
|
</component>
|
|
471
444
|
`);
|
|
472
|
-
(0,
|
|
445
|
+
(0, chai_config_spec_1.expect)(file.parentComponentName.range).to.eql(vscode_languageserver_1.Range.create(1, 38, 1, 47));
|
|
473
446
|
});
|
|
474
447
|
it('works for multi-line', () => {
|
|
475
448
|
file = program.setFile({
|
|
476
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
449
|
+
src: `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
|
|
477
450
|
dest: `components/comp1.xml`
|
|
478
451
|
}, (0, testHelpers_spec_1.trim) `
|
|
479
452
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
@@ -481,22 +454,22 @@ describe('XmlFile', () => {
|
|
|
481
454
|
extends="BaseScene">
|
|
482
455
|
</component>
|
|
483
456
|
`);
|
|
484
|
-
(0,
|
|
457
|
+
(0, chai_config_spec_1.expect)(file.parentComponentName.range).to.eql(vscode_languageserver_1.Range.create(2, 13, 2, 22));
|
|
485
458
|
});
|
|
486
459
|
it('does not throw when unable to find extends', () => {
|
|
487
460
|
file = program.setFile({
|
|
488
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
461
|
+
src: `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
|
|
489
462
|
dest: `components/comp1.xml`
|
|
490
463
|
}, (0, testHelpers_spec_1.trim) `
|
|
491
464
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
492
465
|
<component name="ChildScene">
|
|
493
466
|
</component>
|
|
494
467
|
`);
|
|
495
|
-
(0,
|
|
468
|
+
(0, chai_config_spec_1.expect)(file.parentComponentName).to.not.exist;
|
|
496
469
|
});
|
|
497
470
|
it('adds warning when no "extends" attribute is found', () => {
|
|
498
471
|
program.setFile({
|
|
499
|
-
src: `${rootDir}/components/comp1.xml`,
|
|
472
|
+
src: `${testHelpers_spec_2.rootDir}/components/comp1.xml`,
|
|
500
473
|
dest: `components/comp1.xml`
|
|
501
474
|
}, (0, testHelpers_spec_1.trim) `
|
|
502
475
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
@@ -512,16 +485,10 @@ describe('XmlFile', () => {
|
|
|
512
485
|
it('detects when importing the codebehind file unnecessarily', () => {
|
|
513
486
|
program = new Program_1.Program({
|
|
514
487
|
autoImportComponentScript: true,
|
|
515
|
-
rootDir: rootDir
|
|
488
|
+
rootDir: testHelpers_spec_2.rootDir
|
|
516
489
|
});
|
|
517
|
-
program.setFile(
|
|
518
|
-
|
|
519
|
-
dest: `components/SimpleScene.bs`
|
|
520
|
-
}, '');
|
|
521
|
-
program.setFile({
|
|
522
|
-
src: `${rootDir}/components/SimpleScene.xml`,
|
|
523
|
-
dest: `components/SimpleScene.xml`
|
|
524
|
-
}, (0, testHelpers_spec_1.trim) `
|
|
490
|
+
program.setFile(`components/SimpleScene.bs`, '');
|
|
491
|
+
program.setFile(`components/SimpleScene.xml`, (0, testHelpers_spec_1.trim) `
|
|
525
492
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
526
493
|
<component name="SimpleScene" extends="Scene">
|
|
527
494
|
<script type="text/brighterscript" uri="SimpleScene.bs" />
|
|
@@ -552,9 +519,9 @@ describe('XmlFile', () => {
|
|
|
552
519
|
`, 'none', 'components/Comp.xml');
|
|
553
520
|
});
|
|
554
521
|
it('supports instantresume <customization> elements', async () => {
|
|
555
|
-
fsExtra.outputFileSync(`${rootDir}/manifest`, '');
|
|
556
|
-
fsExtra.outputFileSync(`${rootDir}/source/main.brs`, `sub main()\nend sub`);
|
|
557
|
-
fsExtra.outputFileSync(`${rootDir}/components/MainScene.xml`, (0, testHelpers_spec_1.trim) `
|
|
522
|
+
fsExtra.outputFileSync(`${testHelpers_spec_2.rootDir}/manifest`, '');
|
|
523
|
+
fsExtra.outputFileSync(`${testHelpers_spec_2.rootDir}/source/main.brs`, `sub main()\nend sub`);
|
|
524
|
+
fsExtra.outputFileSync(`${testHelpers_spec_2.rootDir}/components/MainScene.xml`, (0, testHelpers_spec_1.trim) `
|
|
558
525
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
559
526
|
<component name="MainScene" extends="Scene">
|
|
560
527
|
<customization resumehandler="customResume" />
|
|
@@ -566,12 +533,12 @@ describe('XmlFile', () => {
|
|
|
566
533
|
`);
|
|
567
534
|
const builder = new ProgramBuilder_1.ProgramBuilder();
|
|
568
535
|
await builder.run({
|
|
569
|
-
cwd: rootDir,
|
|
570
|
-
|
|
571
|
-
|
|
536
|
+
cwd: testHelpers_spec_2.rootDir,
|
|
537
|
+
retainStagingDir: true,
|
|
538
|
+
stagingDir: testHelpers_spec_2.stagingDir,
|
|
572
539
|
logLevel: Logger_1.LogLevel.off
|
|
573
540
|
});
|
|
574
|
-
(0,
|
|
541
|
+
(0, chai_config_spec_1.expect)((0, testHelpers_spec_1.trim)(fsExtra.readFileSync(`${testHelpers_spec_2.stagingDir}/components/MainScene.xml`).toString())).to.eql((0, testHelpers_spec_1.trim) `
|
|
575
542
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
576
543
|
<component name="MainScene" extends="Scene">
|
|
577
544
|
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
|
|
@@ -596,7 +563,7 @@ describe('XmlFile', () => {
|
|
|
596
563
|
<component name="Comp" extends="Group">
|
|
597
564
|
</component>
|
|
598
565
|
`);
|
|
599
|
-
(0,
|
|
566
|
+
(0, chai_config_spec_1.expect)(file.needsTranspiled).to.be.true;
|
|
600
567
|
});
|
|
601
568
|
it('includes bslib script', () => {
|
|
602
569
|
testTranspile((0, testHelpers_spec_1.trim) `
|
|
@@ -650,7 +617,7 @@ describe('XmlFile', () => {
|
|
|
650
617
|
`);
|
|
651
618
|
program.validate();
|
|
652
619
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
653
|
-
(0,
|
|
620
|
+
(0, chai_config_spec_1.expect)(file.needsTranspiled).to.be.false;
|
|
654
621
|
});
|
|
655
622
|
/**
|
|
656
623
|
* There was a bug that would incorrectly replace one of the script paths on the second or third transpile, so this test verifies it doesn't do that anymore
|
|
@@ -670,12 +637,12 @@ describe('XmlFile', () => {
|
|
|
670
637
|
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
|
|
671
638
|
</component>
|
|
672
639
|
`;
|
|
673
|
-
await program.transpile([], stagingDir);
|
|
674
|
-
(0,
|
|
640
|
+
await program.transpile([], testHelpers_spec_2.stagingDir);
|
|
641
|
+
(0, chai_config_spec_1.expect)((0, testHelpers_spec_1.trim)(fsExtra.readFileSync(`${testHelpers_spec_2.stagingDir}/components/SimpleScene.xml`).toString())).to.eql(expected);
|
|
675
642
|
//clear the output folder
|
|
676
|
-
fsExtra.emptyDirSync(stagingDir);
|
|
677
|
-
await program.transpile([], stagingDir);
|
|
678
|
-
(0,
|
|
643
|
+
fsExtra.emptyDirSync(testHelpers_spec_2.stagingDir);
|
|
644
|
+
await program.transpile([], testHelpers_spec_2.stagingDir);
|
|
645
|
+
(0, chai_config_spec_1.expect)((0, testHelpers_spec_1.trim)(fsExtra.readFileSync(`${testHelpers_spec_2.stagingDir}/components/SimpleScene.xml`).toString())).to.eql(expected);
|
|
679
646
|
});
|
|
680
647
|
it('keeps all content of the XML', () => {
|
|
681
648
|
program.setFile(`components/SimpleScene.bs`, `
|
|
@@ -752,7 +719,7 @@ describe('XmlFile', () => {
|
|
|
752
719
|
`, null, 'components/comp.xml');
|
|
753
720
|
});
|
|
754
721
|
it('returns the XML unmodified if needsTranspiled is false', () => {
|
|
755
|
-
let file = program.setFile(
|
|
722
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
756
723
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
757
724
|
<!-- should stay as-is -->
|
|
758
725
|
<component name="SimpleScene" extends="Scene" >
|
|
@@ -761,7 +728,7 @@ describe('XmlFile', () => {
|
|
|
761
728
|
`);
|
|
762
729
|
//prevent the default auto-imports to ensure no transpilation from AST
|
|
763
730
|
file.getMissingImportsForTranspile = () => [];
|
|
764
|
-
(0,
|
|
731
|
+
(0, chai_config_spec_1.expect)((0, testHelpers_spec_1.trimMap)(file.transpile().code)).to.equal((0, testHelpers_spec_1.trim) `
|
|
765
732
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
766
733
|
<!-- should stay as-is -->
|
|
767
734
|
<component name="SimpleScene" extends="Scene" >
|
|
@@ -770,25 +737,25 @@ describe('XmlFile', () => {
|
|
|
770
737
|
`);
|
|
771
738
|
});
|
|
772
739
|
it('needsTranspiled is false by default', () => {
|
|
773
|
-
let file = program.setFile(
|
|
740
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
774
741
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
775
742
|
<component name="SimpleScene" extends="Scene" >
|
|
776
743
|
</component>
|
|
777
744
|
`);
|
|
778
|
-
(0,
|
|
745
|
+
(0, chai_config_spec_1.expect)(file.needsTranspiled).to.be.false;
|
|
779
746
|
});
|
|
780
747
|
it('needsTranspiled is true if an import is brighterscript', () => {
|
|
781
|
-
let file = program.setFile(
|
|
748
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
782
749
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
783
750
|
<component name="SimpleScene" extends="Scene" >
|
|
784
751
|
<script type="text/brightscript" uri="SimpleScene.bs"/>
|
|
785
752
|
</component>
|
|
786
753
|
`);
|
|
787
|
-
(0,
|
|
754
|
+
(0, chai_config_spec_1.expect)(file.needsTranspiled).to.be.true;
|
|
788
755
|
});
|
|
789
756
|
it('simple source mapping includes sourcemap reference', () => {
|
|
790
757
|
program.options.sourceMap = true;
|
|
791
|
-
let file = program.setFile(
|
|
758
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
792
759
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
793
760
|
<component name="SimpleScene" extends="Scene">
|
|
794
761
|
</component>
|
|
@@ -796,18 +763,18 @@ describe('XmlFile', () => {
|
|
|
796
763
|
//prevent the default auto-imports to ensure no transpilation from AST
|
|
797
764
|
file.getMissingImportsForTranspile = () => [];
|
|
798
765
|
const code = file.transpile().code;
|
|
799
|
-
(0,
|
|
766
|
+
(0, chai_config_spec_1.expect)(code.endsWith(`<!--//# sourceMappingURL=./SimpleScene.xml.map -->`)).to.be.true;
|
|
800
767
|
});
|
|
801
768
|
it('AST-based source mapping includes sourcemap reference', () => {
|
|
802
769
|
program.options.sourceMap = true;
|
|
803
|
-
let file = program.setFile(
|
|
770
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
804
771
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
805
772
|
<component name="SimpleScene" extends="Scene">
|
|
806
773
|
</component>
|
|
807
774
|
`);
|
|
808
775
|
file.needsTranspiled = true;
|
|
809
776
|
const code = file.transpile().code;
|
|
810
|
-
(0,
|
|
777
|
+
(0, chai_config_spec_1.expect)(code.endsWith(`<!--//# sourceMappingURL=./SimpleScene.xml.map -->`)).to.be.true;
|
|
811
778
|
});
|
|
812
779
|
});
|
|
813
780
|
describe('Transform plugins', () => {
|
|
@@ -831,8 +798,8 @@ describe('XmlFile', () => {
|
|
|
831
798
|
it('Calls XML file validation plugins', () => {
|
|
832
799
|
const validateXml = sinon.spy();
|
|
833
800
|
const file = parseFileWithPlugins(validateXml);
|
|
834
|
-
(0,
|
|
835
|
-
(0,
|
|
801
|
+
(0, chai_config_spec_1.expect)(validateXml.callCount).to.be.greaterThan(0);
|
|
802
|
+
(0, chai_config_spec_1.expect)(validateXml.getCalls().flatMap(x => x.args)).to.include(file);
|
|
836
803
|
});
|
|
837
804
|
});
|
|
838
805
|
it('plugin diagnostics work for xml files', () => {
|
|
@@ -904,7 +871,7 @@ describe('XmlFile', () => {
|
|
|
904
871
|
program.validate();
|
|
905
872
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
906
873
|
const scope = program.getComponentScope('ChildComponent');
|
|
907
|
-
(0,
|
|
874
|
+
(0, chai_config_spec_1.expect)([...scope.namespaceLookup.keys()].sort()).to.eql([
|
|
908
875
|
'lib',
|
|
909
876
|
'parent'
|
|
910
877
|
]);
|
|
@@ -920,7 +887,7 @@ describe('XmlFile', () => {
|
|
|
920
887
|
sub logInfo()
|
|
921
888
|
end sub
|
|
922
889
|
`);
|
|
923
|
-
(0,
|
|
890
|
+
(0, chai_config_spec_1.expect)(program.getScopesForFile(xmlFile)[0].getAllCallables().map(x => x.callable.name)).to.include('logInfo');
|
|
924
891
|
});
|
|
925
892
|
it('does not include `d.bs` script during transpile', () => {
|
|
926
893
|
program.setFile('source/logger.d.bs', `
|
|
@@ -966,17 +933,17 @@ describe('XmlFile', () => {
|
|
|
966
933
|
end sub
|
|
967
934
|
`);
|
|
968
935
|
let functionNames = scope.getAllCallables().map(x => x.callable.name);
|
|
969
|
-
(0,
|
|
970
|
-
(0,
|
|
936
|
+
(0, chai_config_spec_1.expect)(functionNames).to.include('logInfo');
|
|
937
|
+
(0, chai_config_spec_1.expect)(functionNames).to.include('logWarning');
|
|
971
938
|
//load d.bs file, which should shadow out the .brs file
|
|
972
939
|
program.setFile('components/Component1.d.bs', `
|
|
973
940
|
sub logError()
|
|
974
941
|
end sub
|
|
975
942
|
`);
|
|
976
943
|
functionNames = scope.getAllCallables().map(x => x.callable.name);
|
|
977
|
-
(0,
|
|
978
|
-
(0,
|
|
979
|
-
(0,
|
|
944
|
+
(0, chai_config_spec_1.expect)(functionNames).to.include('logError');
|
|
945
|
+
(0, chai_config_spec_1.expect)(functionNames).not.to.include('logInfo');
|
|
946
|
+
(0, chai_config_spec_1.expect)(functionNames).not.to.include('logWarning');
|
|
980
947
|
});
|
|
981
948
|
it('updates xml scope when typedef disappears', () => {
|
|
982
949
|
const xmlFile = program.setFile('components/Component1.xml', (0, testHelpers_spec_1.trim) `
|
|
@@ -998,14 +965,14 @@ describe('XmlFile', () => {
|
|
|
998
965
|
`);
|
|
999
966
|
program.validate();
|
|
1000
967
|
let functionNames = scope.getOwnCallables().map(x => x.callable.name);
|
|
1001
|
-
(0,
|
|
1002
|
-
(0,
|
|
968
|
+
(0, chai_config_spec_1.expect)(functionNames).to.include('logTypedef');
|
|
969
|
+
(0, chai_config_spec_1.expect)(functionNames).not.to.include('logBrs');
|
|
1003
970
|
//remove the typdef file
|
|
1004
971
|
program.removeFile(typedef.srcPath);
|
|
1005
972
|
program.validate();
|
|
1006
973
|
functionNames = scope.getOwnCallables().map(x => x.callable.name);
|
|
1007
|
-
(0,
|
|
1008
|
-
(0,
|
|
974
|
+
(0, chai_config_spec_1.expect)(functionNames).not.to.include('logTypedef');
|
|
975
|
+
(0, chai_config_spec_1.expect)(functionNames).to.include('logBrs');
|
|
1009
976
|
});
|
|
1010
977
|
});
|
|
1011
978
|
it('finds script imports for single-quoted script tags', () => {
|
|
@@ -1016,7 +983,7 @@ describe('XmlFile', () => {
|
|
|
1016
983
|
<script uri='SingleQuotedFile.brs' />
|
|
1017
984
|
</component>
|
|
1018
985
|
`);
|
|
1019
|
-
(0,
|
|
986
|
+
(0, chai_config_spec_1.expect)((_a = file.scriptTagImports[0]) === null || _a === void 0 ? void 0 : _a.text).to.eql('SingleQuotedFile.brs');
|
|
1020
987
|
});
|
|
1021
988
|
describe('commentFlags', () => {
|
|
1022
989
|
it('ignores warning from previous line comment', () => {
|
|
@@ -1096,17 +1063,17 @@ describe('XmlFile', () => {
|
|
|
1096
1063
|
<component name="comp1">
|
|
1097
1064
|
</component>
|
|
1098
1065
|
`);
|
|
1099
|
-
(0,
|
|
1066
|
+
(0, chai_config_spec_1.expect)(program.getComponent('comp1').file.pkgPath).to.equal(comp2.pkgPath);
|
|
1100
1067
|
//add comp1. it should become the main component with this name
|
|
1101
1068
|
const comp1 = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
1102
1069
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1103
1070
|
<component name="comp1" extends="Group">
|
|
1104
1071
|
</component>
|
|
1105
1072
|
`);
|
|
1106
|
-
(0,
|
|
1073
|
+
(0, chai_config_spec_1.expect)(program.getComponent('comp1').file.pkgPath).to.equal(comp1.pkgPath);
|
|
1107
1074
|
//remove comp1, comp2 should be the primary again
|
|
1108
|
-
program.removeFile((0, util_1.standardizePath) `${rootDir}/components/comp1.xml`);
|
|
1109
|
-
(0,
|
|
1075
|
+
program.removeFile((0, util_1.standardizePath) `${testHelpers_spec_2.rootDir}/components/comp1.xml`);
|
|
1076
|
+
(0, chai_config_spec_1.expect)(program.getComponent('comp1').file.pkgPath).to.equal(comp2.pkgPath);
|
|
1110
1077
|
//add comp3
|
|
1111
1078
|
program.setFile('components/comp3.xml', (0, testHelpers_spec_1.trim) `
|
|
1112
1079
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
@@ -1114,7 +1081,7 @@ describe('XmlFile', () => {
|
|
|
1114
1081
|
</component>
|
|
1115
1082
|
`);
|
|
1116
1083
|
//...the 2nd file should still be main
|
|
1117
|
-
(0,
|
|
1084
|
+
(0, chai_config_spec_1.expect)(program.getComponent('comp1').file.pkgPath).to.equal(comp2.pkgPath);
|
|
1118
1085
|
});
|
|
1119
1086
|
});
|
|
1120
1087
|
});
|