brighterscript 0.41.2 → 1.0.0-alpha.12
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 +112 -0
- package/README.md +2 -2
- package/dist/DiagnosticCollection.js +2 -2
- package/dist/DiagnosticCollection.js.map +1 -1
- package/dist/DiagnosticFilterer.js +2 -2
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +6 -1
- package/dist/DiagnosticMessages.js +5 -0
- package/dist/DiagnosticMessages.js.map +1 -1
- package/dist/LanguageServer.d.ts +8 -2
- package/dist/LanguageServer.js +50 -44
- package/dist/LanguageServer.js.map +1 -1
- package/dist/Program.d.ts +61 -45
- package/dist/Program.js +305 -188
- package/dist/Program.js.map +1 -1
- package/dist/ProgramBuilder.d.ts +7 -7
- package/dist/ProgramBuilder.js +60 -51
- package/dist/ProgramBuilder.js.map +1 -1
- package/dist/Scope.d.ts +42 -19
- package/dist/Scope.js +261 -129
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +73 -0
- package/dist/SymbolTable.js +157 -0
- package/dist/SymbolTable.js.map +1 -0
- package/dist/XmlScope.d.ts +5 -0
- package/dist/XmlScope.js +66 -28
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/creators.d.ts +15 -1
- package/dist/astUtils/creators.js +39 -9
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +28 -16
- package/dist/astUtils/reflection.js +52 -30
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +3 -3
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +12 -13
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/astUtils/xml.d.ts +3 -3
- package/dist/astUtils/xml.js +2 -2
- package/dist/astUtils/xml.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +5 -6
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +24 -22
- package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +2 -2
- package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +1 -1
- package/dist/examples/plugins/removePrint.js +1 -1
- package/dist/examples/plugins/removePrint.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +356 -41
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +55 -37
- package/dist/files/BrsFile.js +430 -399
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +199 -158
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.d.ts +20 -9
- package/dist/files/XmlFile.js +36 -31
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/files/XmlFile.spec.js +113 -113
- package/dist/files/XmlFile.spec.js.map +1 -1
- package/dist/files/tests/imports.spec.js +32 -32
- package/dist/files/tests/imports.spec.js.map +1 -1
- package/dist/globalCallables.js +17 -6
- package/dist/globalCallables.js.map +1 -1
- package/dist/interfaces.d.ts +155 -39
- package/dist/parser/BrsTranspileState.d.ts +7 -0
- package/dist/parser/BrsTranspileState.js +10 -1
- package/dist/parser/BrsTranspileState.js.map +1 -1
- package/dist/parser/Expression.d.ts +23 -12
- package/dist/parser/Expression.js +45 -30
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.Class.spec.js +100 -1
- package/dist/parser/Parser.Class.spec.js.map +1 -1
- package/dist/parser/Parser.d.ts +118 -5
- package/dist/parser/Parser.js +398 -37
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +404 -7
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGParser.d.ts +41 -4
- package/dist/parser/SGParser.js +185 -174
- package/dist/parser/SGParser.js.map +1 -1
- package/dist/parser/SGParser.spec.js +17 -4
- package/dist/parser/SGParser.spec.js.map +1 -1
- package/dist/parser/SGTypes.d.ts +203 -38
- package/dist/parser/SGTypes.js +464 -160
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/SGTypes.spec.d.ts +1 -0
- package/dist/parser/SGTypes.spec.js +351 -0
- package/dist/parser/SGTypes.spec.js.map +1 -0
- package/dist/parser/Statement.d.ts +37 -26
- package/dist/parser/Statement.js +81 -20
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +5 -5
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +1 -1
- package/dist/parser/TranspileState.js +15 -7
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/controlFlow/ForEach.spec.js +5 -4
- package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +1 -1
- package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js +1 -1
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/types/ArrayType.d.ts +1 -0
- package/dist/types/ArrayType.js +23 -19
- package/dist/types/ArrayType.js.map +1 -1
- package/dist/types/BooleanType.d.ts +3 -2
- package/dist/types/BooleanType.js +6 -3
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/BscType.d.ts +19 -4
- package/dist/types/BscType.js +9 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/CustomType.d.ts +8 -5
- package/dist/types/CustomType.js +12 -12
- package/dist/types/CustomType.js.map +1 -1
- package/dist/types/DoubleType.d.ts +1 -0
- package/dist/types/DoubleType.js +11 -11
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DynamicType.d.ts +1 -0
- package/dist/types/DynamicType.js +4 -0
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/FloatType.d.ts +2 -1
- package/dist/types/FloatType.js +11 -11
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/FunctionType.d.ts +13 -10
- package/dist/types/FunctionType.js +34 -18
- package/dist/types/FunctionType.js.map +1 -1
- package/dist/types/FunctionType.spec.js +8 -2
- package/dist/types/FunctionType.spec.js.map +1 -1
- package/dist/types/IntegerType.d.ts +2 -1
- package/dist/types/IntegerType.js +11 -11
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/InvalidType.d.ts +3 -2
- package/dist/types/InvalidType.js +7 -4
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/LazyType.d.ts +17 -0
- package/dist/types/LazyType.js +44 -0
- package/dist/types/LazyType.js.map +1 -0
- package/dist/types/LongIntegerType.d.ts +2 -1
- package/dist/types/LongIntegerType.js +11 -11
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/ObjectType.d.ts +6 -2
- package/dist/types/ObjectType.js +9 -3
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/StringType.d.ts +3 -2
- package/dist/types/StringType.js +6 -3
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/UninitializedType.d.ts +4 -2
- package/dist/types/UninitializedType.js +8 -3
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.d.ts +3 -2
- package/dist/types/VoidType.js +6 -3
- package/dist/types/VoidType.js.map +1 -1
- package/dist/types/helpers.d.ts +42 -0
- package/dist/types/helpers.js +113 -0
- package/dist/types/helpers.js.map +1 -0
- package/dist/util.d.ts +68 -15
- package/dist/util.js +193 -45
- package/dist/util.js.map +1 -1
- package/dist/validators/ClassValidator.d.ts +5 -1
- package/dist/validators/ClassValidator.js +31 -17
- package/dist/validators/ClassValidator.js.map +1 -1
- package/package.json +1 -1
- package/dist/FunctionScope.d.ts +0 -27
- package/dist/FunctionScope.js +0 -49
- package/dist/FunctionScope.js.map +0 -1
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const chai_1 = require("chai");
|
|
4
|
-
const path = require("path");
|
|
5
4
|
const sinonImport = require("sinon");
|
|
6
5
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
7
6
|
const fsExtra = require("fs-extra");
|
|
8
7
|
const DiagnosticMessages_1 = require("../DiagnosticMessages");
|
|
9
8
|
const Program_1 = require("../Program");
|
|
10
|
-
const BrsFile_1 = require("./BrsFile");
|
|
11
9
|
const XmlFile_1 = require("./XmlFile");
|
|
12
10
|
const util_1 = require("../util");
|
|
13
11
|
const testHelpers_spec_1 = require("../testHelpers.spec");
|
|
@@ -34,14 +32,13 @@ describe('XmlFile', () => {
|
|
|
34
32
|
describe('parse', () => {
|
|
35
33
|
it('allows modifying the parsed XML model', () => {
|
|
36
34
|
const expected = 'OtherName';
|
|
37
|
-
file = new XmlFile_1.XmlFile('abs', 'rel', program);
|
|
38
35
|
program.plugins.add({
|
|
39
36
|
name: 'allows modifying the parsed XML model',
|
|
40
|
-
afterFileParse: () => {
|
|
41
|
-
file.parser.ast.root.attributes[0].value.text = expected;
|
|
37
|
+
afterFileParse: (event) => {
|
|
38
|
+
event.file.parser.ast.root.attributes[0].tokens.value.text = expected;
|
|
42
39
|
}
|
|
43
40
|
});
|
|
44
|
-
file.
|
|
41
|
+
file = program.setFile('components/ChildScene.xml', (0, testHelpers_spec_1.trim) `
|
|
45
42
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
46
43
|
<component name="ChildScene" extends="Scene">
|
|
47
44
|
<script type="text/brightscript" uri="ChildScene1.brs" /> <script type="text/brightscript" uri="ChildScene2.brs" /> <script type="text/brightscript" uri="ChildScene3.brs" />
|
|
@@ -54,13 +51,13 @@ describe('XmlFile', () => {
|
|
|
54
51
|
program.plugins.add({
|
|
55
52
|
name: 'allows modifying the parsed XML model',
|
|
56
53
|
afterFileParse: () => {
|
|
57
|
-
let child = file.parser.ast.component.children.
|
|
54
|
+
let child = file.parser.ast.component.children.childNodes[0];
|
|
58
55
|
(0, chai_1.expect)(child.attributes).to.have.lengthOf(4);
|
|
59
|
-
child.
|
|
60
|
-
(0, chai_1.expect)(child.
|
|
56
|
+
child.setAttributeValue('text', undefined);
|
|
57
|
+
(0, chai_1.expect)(child.id).to.equal('one');
|
|
61
58
|
(0, chai_1.expect)(child.attributes).to.have.lengthOf(3);
|
|
62
|
-
child.
|
|
63
|
-
(0, chai_1.expect)(child.
|
|
59
|
+
child.setAttributeValue('text3', undefined);
|
|
60
|
+
(0, chai_1.expect)(child.id).to.equal('one');
|
|
64
61
|
(0, chai_1.expect)(child.attributes).to.have.lengthOf(2);
|
|
65
62
|
}
|
|
66
63
|
});
|
|
@@ -79,17 +76,17 @@ describe('XmlFile', () => {
|
|
|
79
76
|
`);
|
|
80
77
|
});
|
|
81
78
|
it('supports importing BrighterScript files', () => {
|
|
82
|
-
file = program.
|
|
79
|
+
file = program.setFile({ src: `${rootDir}/components/custom.xml`, dest: 'components/custom.xml' }, (0, testHelpers_spec_1.trim) `
|
|
83
80
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
84
81
|
<component name="ChildScene" extends="Scene">
|
|
85
82
|
<script type="text/brightscript" uri="ChildScene.bs" />
|
|
86
83
|
</component>
|
|
87
84
|
`);
|
|
88
|
-
(0, chai_1.expect)(file.scriptTagImports.map(x => x.pkgPath)[0]).to.equal(
|
|
85
|
+
(0, chai_1.expect)(file.scriptTagImports.map(x => x.pkgPath)[0]).to.equal('pkg:/components/ChildScene.bs');
|
|
89
86
|
});
|
|
90
87
|
it('does not include commented-out script imports', () => {
|
|
91
88
|
var _a, _b;
|
|
92
|
-
file = program.
|
|
89
|
+
file = program.setFile({ src: `${rootDir}/components/custom.xml`, dest: 'components/custom.xml' }, (0, testHelpers_spec_1.trim) `
|
|
93
90
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
94
91
|
<component name="ChildScene" extends="Scene">
|
|
95
92
|
<script type="text/brightscript" uri="ChildScene.brs" />
|
|
@@ -98,7 +95,7 @@ describe('XmlFile', () => {
|
|
|
98
95
|
-->
|
|
99
96
|
</component>
|
|
100
97
|
`);
|
|
101
|
-
(0, chai_1.expect)((_b = (_a = file.scriptTagImports) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.pkgPath).to.eql(
|
|
98
|
+
(0, chai_1.expect)((_b = (_a = file.scriptTagImports) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.pkgPath).to.eql('pkg:/components/ChildScene.brs');
|
|
102
99
|
});
|
|
103
100
|
it('finds scripts when more than one per line', () => {
|
|
104
101
|
file = new XmlFile_1.XmlFile('abs', 'rel', program);
|
|
@@ -163,20 +160,20 @@ describe('XmlFile', () => {
|
|
|
163
160
|
(0, chai_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) }));
|
|
164
161
|
});
|
|
165
162
|
it('Adds error when no component is declared in xml', () => {
|
|
166
|
-
file =
|
|
167
|
-
|
|
163
|
+
file = program.setFile('components/file.xml', '<script type="text/brightscript" uri="ChildScene.brs" />');
|
|
164
|
+
program.validate();
|
|
168
165
|
(0, chai_1.expect)(file.diagnostics).to.be.lengthOf(2);
|
|
169
166
|
(0, chai_1.expect)(file.diagnostics[0]).to.deep.include(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.xmlUnexpectedTag('script')), { range: vscode_languageserver_1.Range.create(0, 1, 0, 7) }));
|
|
170
167
|
(0, chai_1.expect)(file.diagnostics[1]).to.deep.include(DiagnosticMessages_1.DiagnosticMessages.xmlComponentMissingComponentDeclaration());
|
|
171
168
|
});
|
|
172
169
|
it('adds error when component does not declare a name', () => {
|
|
173
|
-
file =
|
|
174
|
-
file.parse((0, testHelpers_spec_1.trim) `
|
|
170
|
+
file = program.setFile('components/ParentScene.xml', (0, testHelpers_spec_1.trim) `
|
|
175
171
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
176
172
|
<component extends="ParentScene">
|
|
177
173
|
<script type="text/brightscript" uri="ChildScene.brs" />
|
|
178
174
|
</component>
|
|
179
175
|
`);
|
|
176
|
+
program.validate();
|
|
180
177
|
(0, chai_1.expect)(file.diagnostics).to.be.lengthOf(1);
|
|
181
178
|
(0, chai_1.expect)(file.diagnostics[0]).to.deep.include({
|
|
182
179
|
message: DiagnosticMessages_1.DiagnosticMessages.xmlComponentMissingNameAttribute().message,
|
|
@@ -184,12 +181,12 @@ describe('XmlFile', () => {
|
|
|
184
181
|
});
|
|
185
182
|
});
|
|
186
183
|
it('catches xml parse errors', () => {
|
|
187
|
-
file =
|
|
188
|
-
file.parse((0, testHelpers_spec_1.trim) `
|
|
184
|
+
file = program.setFile('components/ParentScene.xml', (0, testHelpers_spec_1.trim) `
|
|
189
185
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
190
186
|
<component 1extends="ParentScene">
|
|
191
187
|
</component>
|
|
192
188
|
`);
|
|
189
|
+
program.validate();
|
|
193
190
|
(0, chai_1.expect)(file.diagnostics).to.be.lengthOf(2);
|
|
194
191
|
(0, chai_1.expect)(file.diagnostics[0].code).to.equal(DiagnosticMessages_1.DiagnosticMessages.xmlGenericParseError('').code); //unexpected character '1'
|
|
195
192
|
(0, chai_1.expect)(file.diagnostics[1]).to.deep.include({
|
|
@@ -209,7 +206,7 @@ describe('XmlFile', () => {
|
|
|
209
206
|
(0, chai_1.expect)(file.scriptTagImports[0]).to.deep.include({
|
|
210
207
|
sourceFile: file,
|
|
211
208
|
text: 'pkg:/components/cmp1.brs',
|
|
212
|
-
pkgPath: `components
|
|
209
|
+
pkgPath: `pkg:/components/cmp1.brs`,
|
|
213
210
|
filePathRange: vscode_languageserver_1.Range.create(2, 42, 2, 66)
|
|
214
211
|
});
|
|
215
212
|
});
|
|
@@ -225,7 +222,7 @@ describe('XmlFile', () => {
|
|
|
225
222
|
}
|
|
226
223
|
});
|
|
227
224
|
it('resolves relative paths', () => {
|
|
228
|
-
file = program.
|
|
225
|
+
file = program.setFile({
|
|
229
226
|
src: `${rootDir}/components/comp1.xml`,
|
|
230
227
|
dest: 'components/comp1.xml'
|
|
231
228
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -237,12 +234,12 @@ describe('XmlFile', () => {
|
|
|
237
234
|
(0, chai_1.expect)(file.scriptTagImports.length).to.equal(1);
|
|
238
235
|
(0, chai_1.expect)(file.scriptTagImports[0]).to.deep.include({
|
|
239
236
|
text: 'cmp1.brs',
|
|
240
|
-
pkgPath: `components
|
|
237
|
+
pkgPath: `pkg:/components/cmp1.brs`
|
|
241
238
|
});
|
|
242
239
|
});
|
|
243
240
|
it('finds correct position for empty uri in script tag', () => {
|
|
244
241
|
var _a;
|
|
245
|
-
file = program.
|
|
242
|
+
file = program.setFile({
|
|
246
243
|
src: `${rootDir}/components/comp1.xml`,
|
|
247
244
|
dest: 'components/comp1.xml'
|
|
248
245
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -257,7 +254,7 @@ describe('XmlFile', () => {
|
|
|
257
254
|
});
|
|
258
255
|
describe('doesReferenceFile', () => {
|
|
259
256
|
it('compares case insensitive', () => {
|
|
260
|
-
let xmlFile = program.
|
|
257
|
+
let xmlFile = program.setFile({
|
|
261
258
|
src: `${rootDir}/components/comp1.xml`,
|
|
262
259
|
dest: 'components/comp1.xml'
|
|
263
260
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -266,7 +263,7 @@ describe('XmlFile', () => {
|
|
|
266
263
|
<script type="text/brightscript" uri="HeroGrid.brs" />
|
|
267
264
|
</component>
|
|
268
265
|
`);
|
|
269
|
-
let brsFile = program.
|
|
266
|
+
let brsFile = program.setFile({
|
|
270
267
|
src: `${rootDir}/components/HEROGRID.brs`,
|
|
271
268
|
dest: `components/HEROGRID.brs`
|
|
272
269
|
}, ``);
|
|
@@ -275,17 +272,17 @@ describe('XmlFile', () => {
|
|
|
275
272
|
});
|
|
276
273
|
describe('autoImportComponentScript', () => {
|
|
277
274
|
it('is not enabled by default', () => {
|
|
278
|
-
program.
|
|
275
|
+
program.setFile({ src: `${rootDir}/components/comp1.xml`, dest: 'components/comp1.xml' }, (0, testHelpers_spec_1.trim) `
|
|
279
276
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
280
277
|
<component name="ParentScene" extends="GrandparentScene">
|
|
281
278
|
<script type="text/brightscript" uri="./lib.brs" />
|
|
282
279
|
</component>
|
|
283
280
|
`);
|
|
284
|
-
program.
|
|
281
|
+
program.setFile({ src: `${rootDir}/components/lib.brs`, dest: 'components/lib.brs' }, `
|
|
285
282
|
function libFunc()
|
|
286
283
|
end function
|
|
287
284
|
`);
|
|
288
|
-
program.
|
|
285
|
+
program.setFile({ src: `${rootDir}/components/comp1.bs`, dest: 'components/comp1.bs' }, `
|
|
289
286
|
function init()
|
|
290
287
|
libFunc()
|
|
291
288
|
end function
|
|
@@ -298,17 +295,17 @@ describe('XmlFile', () => {
|
|
|
298
295
|
rootDir: rootDir,
|
|
299
296
|
autoImportComponentScript: true
|
|
300
297
|
});
|
|
301
|
-
program.
|
|
298
|
+
program.setFile({ src: `${rootDir}/components/comp1.xml`, dest: 'components/comp1.xml' }, (0, testHelpers_spec_1.trim) `
|
|
302
299
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
303
300
|
<component name="ParentScene" extends="GrandparentScene">
|
|
304
301
|
<script type="text/brightscript" uri="./lib.brs" />
|
|
305
302
|
</component>
|
|
306
303
|
`);
|
|
307
|
-
program.
|
|
304
|
+
program.setFile({ src: `${rootDir}/components/lib.brs`, dest: 'components/lib.brs' }, `
|
|
308
305
|
function libFunc()
|
|
309
306
|
end function
|
|
310
307
|
`);
|
|
311
|
-
program.
|
|
308
|
+
program.setFile({ src: `${rootDir}/components/comp1.bs`, dest: 'components/comp1.bs' }, `
|
|
312
309
|
function init()
|
|
313
310
|
libFunc()
|
|
314
311
|
end function
|
|
@@ -320,11 +317,14 @@ describe('XmlFile', () => {
|
|
|
320
317
|
});
|
|
321
318
|
describe('getCompletions', () => {
|
|
322
319
|
it('formats completion paths with proper slashes', () => {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
320
|
+
program.setFile('pkg:/components/component1/component1.brs', '');
|
|
321
|
+
const xmlFile = program.setFile('components/component1/component1.xml', (0, testHelpers_spec_1.trim) `
|
|
322
|
+
<?xml version="1.0" encoding="utf-8" ?>
|
|
323
|
+
<component name="Component1" extends="Group">
|
|
324
|
+
</component
|
|
325
|
+
`);
|
|
326
326
|
xmlFile.parser.references.scriptTagImports.push({
|
|
327
|
-
pkgPath:
|
|
327
|
+
pkgPath: 'pkg:/components/component1/component1.brs',
|
|
328
328
|
text: 'component1.brs',
|
|
329
329
|
filePathRange: vscode_languageserver_1.Range.create(1, 1, 1, 1)
|
|
330
330
|
});
|
|
@@ -338,37 +338,37 @@ describe('XmlFile', () => {
|
|
|
338
338
|
});
|
|
339
339
|
});
|
|
340
340
|
it('returns empty set when out of range', () => {
|
|
341
|
-
program.
|
|
341
|
+
program.setFile({ src: `${rootDir}/components/Component1.brs`, dest: 'components/component1.brs' }, ``);
|
|
342
342
|
(0, chai_1.expect)(file.getCompletions(vscode_languageserver_1.Position.create(99, 99))).to.be.empty;
|
|
343
343
|
});
|
|
344
344
|
//TODO - refine this test once cdata scripts are supported
|
|
345
345
|
it('prevents scope completions entirely', () => {
|
|
346
|
-
program.
|
|
347
|
-
let xmlFile = program.
|
|
346
|
+
program.setFile({ src: `${rootDir}/components/Component1.brs`, dest: 'components/component1.brs' }, ``);
|
|
347
|
+
let xmlFile = program.setFile({ src: `${rootDir}/components/Component1.xml`, dest: 'components/component1.xml' }, (0, testHelpers_spec_1.trim) `
|
|
348
348
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
349
349
|
<component name="ParentScene" extends="GrandparentScene">
|
|
350
350
|
<script type="text/brightscript" uri="./Component1.brs" />
|
|
351
351
|
</component>
|
|
352
352
|
`);
|
|
353
|
-
(0, chai_1.expect)(program.getCompletions(xmlFile.
|
|
353
|
+
(0, chai_1.expect)(program.getCompletions(xmlFile.srcPath, vscode_languageserver_1.Position.create(1, 1))).to.be.empty;
|
|
354
354
|
});
|
|
355
355
|
});
|
|
356
356
|
describe('getAllDependencies', () => {
|
|
357
357
|
it('returns own imports', () => {
|
|
358
|
-
file = program.
|
|
358
|
+
file = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
359
359
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
360
360
|
<component name="ChildScene" extends="BaseScene">
|
|
361
361
|
<script type="text/brightscript" uri="pkg:/source/lib.brs" />
|
|
362
362
|
</component>
|
|
363
363
|
`);
|
|
364
364
|
(0, chai_1.expect)(file.getOwnDependencies().sort()).to.eql([
|
|
365
|
-
|
|
366
|
-
|
|
365
|
+
'pkg:/source/lib.brs',
|
|
366
|
+
'pkg:/source/lib.d.bs'
|
|
367
367
|
]);
|
|
368
368
|
});
|
|
369
369
|
});
|
|
370
370
|
it('invalidates dependent scopes on change', () => {
|
|
371
|
-
let xmlFile = program.
|
|
371
|
+
let xmlFile = program.setFile({
|
|
372
372
|
src: `${rootDir}/components/comp1.xml`,
|
|
373
373
|
dest: `components/comp1.xml`
|
|
374
374
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -382,7 +382,7 @@ describe('XmlFile', () => {
|
|
|
382
382
|
//scope should be validated
|
|
383
383
|
(0, chai_1.expect)(scope.isValidated);
|
|
384
384
|
//add lib1
|
|
385
|
-
program.
|
|
385
|
+
program.setFile({
|
|
386
386
|
src: `${rootDir}/source/lib.bs`,
|
|
387
387
|
dest: `source/lib.bs`
|
|
388
388
|
}, ``);
|
|
@@ -391,7 +391,7 @@ describe('XmlFile', () => {
|
|
|
391
391
|
program.validate();
|
|
392
392
|
(0, chai_1.expect)(scope.isValidated).to.be.true;
|
|
393
393
|
//update lib1 to include an import
|
|
394
|
-
program.
|
|
394
|
+
program.setFile({
|
|
395
395
|
src: `${rootDir}/source/lib.bs`,
|
|
396
396
|
dest: `source/lib.bs`
|
|
397
397
|
}, `
|
|
@@ -402,7 +402,7 @@ describe('XmlFile', () => {
|
|
|
402
402
|
program.validate();
|
|
403
403
|
(0, chai_1.expect)(scope.isValidated).to.be.true;
|
|
404
404
|
//add the lib2 imported from lib
|
|
405
|
-
program.
|
|
405
|
+
program.setFile({
|
|
406
406
|
src: `${rootDir}/source/lib2.bs`,
|
|
407
407
|
dest: `source/lib2.bs`
|
|
408
408
|
}, ``);
|
|
@@ -414,7 +414,7 @@ describe('XmlFile', () => {
|
|
|
414
414
|
(0, chai_1.expect)(scope.isValidated).to.be.false;
|
|
415
415
|
});
|
|
416
416
|
it('does not invalidate unrelated scopes on change', () => {
|
|
417
|
-
let xmlFile1 = program.
|
|
417
|
+
let xmlFile1 = program.setFile({
|
|
418
418
|
src: `${rootDir}/components/comp1.xml`,
|
|
419
419
|
dest: `components/comp1.xml`
|
|
420
420
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -423,7 +423,7 @@ describe('XmlFile', () => {
|
|
|
423
423
|
<script type="text/brightscript" uri="pkg:/source/lib.brs" />
|
|
424
424
|
</component>
|
|
425
425
|
`);
|
|
426
|
-
let xmlFile2 = program.
|
|
426
|
+
let xmlFile2 = program.setFile({
|
|
427
427
|
src: `${rootDir}/components/comp2.xml`,
|
|
428
428
|
dest: `components/comp2.xml`
|
|
429
429
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -436,7 +436,7 @@ describe('XmlFile', () => {
|
|
|
436
436
|
(0, chai_1.expect)(program.getScopesForFile(xmlFile1)[0].isValidated).to.be.true;
|
|
437
437
|
(0, chai_1.expect)(program.getScopesForFile(xmlFile2)[0].isValidated).to.be.true;
|
|
438
438
|
//add the lib file
|
|
439
|
-
program.
|
|
439
|
+
program.setFile({
|
|
440
440
|
src: `${rootDir}/source/lib.brs`,
|
|
441
441
|
dest: `source/lib.brs`
|
|
442
442
|
}, ``);
|
|
@@ -455,7 +455,7 @@ describe('XmlFile', () => {
|
|
|
455
455
|
});
|
|
456
456
|
describe('component extends', () => {
|
|
457
457
|
it('works for single-line', () => {
|
|
458
|
-
file = program.
|
|
458
|
+
file = program.setFile({
|
|
459
459
|
src: `${rootDir}/components/comp1.xml`,
|
|
460
460
|
dest: `components/comp1.xml`
|
|
461
461
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -466,7 +466,7 @@ describe('XmlFile', () => {
|
|
|
466
466
|
(0, chai_1.expect)(file.parentComponentName.range).to.eql(vscode_languageserver_1.Range.create(1, 38, 1, 47));
|
|
467
467
|
});
|
|
468
468
|
it('works for multi-line', () => {
|
|
469
|
-
file = program.
|
|
469
|
+
file = program.setFile({
|
|
470
470
|
src: `${rootDir}/components/comp1.xml`,
|
|
471
471
|
dest: `components/comp1.xml`
|
|
472
472
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -478,7 +478,7 @@ describe('XmlFile', () => {
|
|
|
478
478
|
(0, chai_1.expect)(file.parentComponentName.range).to.eql(vscode_languageserver_1.Range.create(2, 13, 2, 22));
|
|
479
479
|
});
|
|
480
480
|
it('does not throw when unable to find extends', () => {
|
|
481
|
-
file = program.
|
|
481
|
+
file = program.setFile({
|
|
482
482
|
src: `${rootDir}/components/comp1.xml`,
|
|
483
483
|
dest: `components/comp1.xml`
|
|
484
484
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -489,7 +489,7 @@ describe('XmlFile', () => {
|
|
|
489
489
|
(0, chai_1.expect)(file.parentComponentName).to.not.exist;
|
|
490
490
|
});
|
|
491
491
|
it('adds warning when no "extends" attribute is found', () => {
|
|
492
|
-
file = program.
|
|
492
|
+
file = program.setFile({
|
|
493
493
|
src: `${rootDir}/components/comp1.xml`,
|
|
494
494
|
dest: `components/comp1.xml`
|
|
495
495
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -497,6 +497,7 @@ describe('XmlFile', () => {
|
|
|
497
497
|
<component name="ChildScene">
|
|
498
498
|
</component>
|
|
499
499
|
`);
|
|
500
|
+
program.validate();
|
|
500
501
|
(0, chai_1.expect)(file.getDiagnostics()[0]).to.include({
|
|
501
502
|
severity: vscode_languageserver_1.DiagnosticSeverity.Warning,
|
|
502
503
|
message: DiagnosticMessages_1.DiagnosticMessages.xmlComponentMissingExtendsAttribute().message
|
|
@@ -509,11 +510,11 @@ describe('XmlFile', () => {
|
|
|
509
510
|
autoImportComponentScript: true,
|
|
510
511
|
rootDir: rootDir
|
|
511
512
|
});
|
|
512
|
-
program.
|
|
513
|
+
program.setFile({
|
|
513
514
|
src: `${rootDir}/components/SimpleScene.bs`,
|
|
514
515
|
dest: `components/SimpleScene.bs`
|
|
515
516
|
}, '');
|
|
516
|
-
program.
|
|
517
|
+
program.setFile({
|
|
517
518
|
src: `${rootDir}/components/SimpleScene.xml`,
|
|
518
519
|
dest: `components/SimpleScene.xml`
|
|
519
520
|
}, (0, testHelpers_spec_1.trim) `
|
|
@@ -529,12 +530,12 @@ describe('XmlFile', () => {
|
|
|
529
530
|
it(`honors the 'needsTranspiled' flag when set in 'afterFileParse'`, () => {
|
|
530
531
|
program.plugins.add({
|
|
531
532
|
name: 'test',
|
|
532
|
-
afterFileParse: (
|
|
533
|
+
afterFileParse: (event) => {
|
|
533
534
|
//enable transpile for every file
|
|
534
|
-
file.needsTranspiled = true;
|
|
535
|
+
event.file.needsTranspiled = true;
|
|
535
536
|
}
|
|
536
537
|
});
|
|
537
|
-
const file = program.
|
|
538
|
+
const file = program.setFile('components/file.xml', (0, testHelpers_spec_1.trim) `
|
|
538
539
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
539
540
|
<component name="Comp" extends="Group">
|
|
540
541
|
</component>
|
|
@@ -567,8 +568,8 @@ describe('XmlFile', () => {
|
|
|
567
568
|
`, 'none', 'components/child.xml');
|
|
568
569
|
});
|
|
569
570
|
it('does not include bslib script if already there from ropm', () => {
|
|
570
|
-
program.
|
|
571
|
-
program.
|
|
571
|
+
program.setFile('source/roku_modules/bslib/bslib.brs', ``);
|
|
572
|
+
program.setFile('source/lib.bs', ``);
|
|
572
573
|
//include a bs file to force transpile for the xml file
|
|
573
574
|
testTranspile((0, testHelpers_spec_1.trim) `
|
|
574
575
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
@@ -585,7 +586,7 @@ describe('XmlFile', () => {
|
|
|
585
586
|
`, 'none', 'components/child.xml');
|
|
586
587
|
});
|
|
587
588
|
it('does not transpile xml file when bslib script is already present', () => {
|
|
588
|
-
const file = program.
|
|
589
|
+
const file = program.setFile('components/comp.xml', (0, testHelpers_spec_1.trim) `
|
|
589
590
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
590
591
|
<component name="Comp" extends="Group">
|
|
591
592
|
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
|
|
@@ -599,8 +600,8 @@ describe('XmlFile', () => {
|
|
|
599
600
|
* 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
|
|
600
601
|
*/
|
|
601
602
|
it('does not mangle scripts on multiple transpile', async () => {
|
|
602
|
-
program.
|
|
603
|
-
program.
|
|
603
|
+
program.setFile('components/SimpleScene.bs', ``);
|
|
604
|
+
program.setFile(`components/SimpleScene.xml`, (0, testHelpers_spec_1.trim) `
|
|
604
605
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
605
606
|
<component name="SimpleScene" extends="Scene">
|
|
606
607
|
<script type="text/brightscript" uri="SimpleScene.bs" />
|
|
@@ -621,7 +622,7 @@ describe('XmlFile', () => {
|
|
|
621
622
|
(0, chai_1.expect)(fsExtra.readFileSync(`${stagingDir}/components/SimpleScene.xml`).toString()).to.eql(expected);
|
|
622
623
|
});
|
|
623
624
|
it('keeps all content of the XML', () => {
|
|
624
|
-
program.
|
|
625
|
+
program.setFile(`components/SimpleScene.bs`, `
|
|
625
626
|
sub b()
|
|
626
627
|
end sub
|
|
627
628
|
`);
|
|
@@ -651,20 +652,20 @@ describe('XmlFile', () => {
|
|
|
651
652
|
<function name="b" />
|
|
652
653
|
</interface>
|
|
653
654
|
<script type="text/brightscript" uri="SimpleScene.brs" />
|
|
654
|
-
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
|
|
655
655
|
<children>
|
|
656
656
|
<aa id="aa">
|
|
657
657
|
<bb id="bb" />
|
|
658
658
|
</aa>
|
|
659
659
|
</children>
|
|
660
|
+
<script type="text/brightscript" uri="pkg:/source/bslib.brs" />
|
|
660
661
|
</component>
|
|
661
662
|
`, 'none', 'components/SimpleScene.xml');
|
|
662
663
|
});
|
|
663
664
|
it('changes file extensions from bs to brs', () => {
|
|
664
|
-
program.
|
|
665
|
+
program.setFile(`components/SimpleScene.bs`, `
|
|
665
666
|
import "pkg:/source/lib.bs"
|
|
666
667
|
`);
|
|
667
|
-
program.
|
|
668
|
+
program.setFile('source/lib.bs', ``);
|
|
668
669
|
testTranspile((0, testHelpers_spec_1.trim) `
|
|
669
670
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
670
671
|
<component name="SimpleScene" extends="Scene">
|
|
@@ -680,7 +681,7 @@ describe('XmlFile', () => {
|
|
|
680
681
|
`, 'none', 'components/SimpleScene.xml');
|
|
681
682
|
});
|
|
682
683
|
it('does not fail on missing script type', () => {
|
|
683
|
-
program.
|
|
684
|
+
program.setFile('components/SimpleScene.brs', '');
|
|
684
685
|
testTranspile((0, testHelpers_spec_1.trim) `
|
|
685
686
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
686
687
|
<component name="SimpleScene" extends="Scene">
|
|
@@ -695,7 +696,7 @@ describe('XmlFile', () => {
|
|
|
695
696
|
`, null, 'components/comp.xml');
|
|
696
697
|
});
|
|
697
698
|
it('returns the XML unmodified if needsTranspiled is false', () => {
|
|
698
|
-
let file = program.
|
|
699
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
699
700
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
700
701
|
<!-- should stay as-is -->
|
|
701
702
|
<component name="SimpleScene" extends="Scene" >
|
|
@@ -713,7 +714,7 @@ describe('XmlFile', () => {
|
|
|
713
714
|
`);
|
|
714
715
|
});
|
|
715
716
|
it('needsTranspiled is false by default', () => {
|
|
716
|
-
let file = program.
|
|
717
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
717
718
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
718
719
|
<component name="SimpleScene" extends="Scene" >
|
|
719
720
|
</component>
|
|
@@ -721,17 +722,18 @@ describe('XmlFile', () => {
|
|
|
721
722
|
(0, chai_1.expect)(file.needsTranspiled).to.be.false;
|
|
722
723
|
});
|
|
723
724
|
it('needsTranspiled is true if an import is brighterscript', () => {
|
|
724
|
-
let file = program.
|
|
725
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
725
726
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
726
727
|
<component name="SimpleScene" extends="Scene" >
|
|
727
728
|
<script type="text/brightscript" uri="SimpleScene.bs"/>
|
|
728
729
|
</component>
|
|
729
730
|
`);
|
|
731
|
+
program.validate();
|
|
730
732
|
(0, chai_1.expect)(file.needsTranspiled).to.be.true;
|
|
731
733
|
});
|
|
732
734
|
it('simple source mapping includes sourcemap reference', () => {
|
|
733
735
|
program.options.sourceMap = true;
|
|
734
|
-
let file = program.
|
|
736
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
735
737
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
736
738
|
<component name="SimpleScene" extends="Scene">
|
|
737
739
|
</component>
|
|
@@ -743,7 +745,7 @@ describe('XmlFile', () => {
|
|
|
743
745
|
});
|
|
744
746
|
it('AST-based source mapping includes sourcemap reference', () => {
|
|
745
747
|
program.options.sourceMap = true;
|
|
746
|
-
let file = program.
|
|
748
|
+
let file = program.setFile('components/SimpleScene.xml', (0, testHelpers_spec_1.trim) `
|
|
747
749
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
748
750
|
<component name="SimpleScene" extends="Scene">
|
|
749
751
|
</component>
|
|
@@ -759,17 +761,15 @@ describe('XmlFile', () => {
|
|
|
759
761
|
const program = new Program_1.Program({
|
|
760
762
|
rootDir: rootDir
|
|
761
763
|
});
|
|
762
|
-
file = new XmlFile_1.XmlFile('abs', 'rel', program);
|
|
763
764
|
program.plugins.add({
|
|
764
765
|
name: 'Transform plugins',
|
|
765
|
-
afterFileParse: () => validateXml(file)
|
|
766
|
+
afterFileParse: (event) => validateXml(event.file)
|
|
766
767
|
});
|
|
767
|
-
|
|
768
|
+
return program.setFile('components/Cmp1.xml', (0, testHelpers_spec_1.trim) `
|
|
768
769
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
769
770
|
<component name="Cmp1" extends="Scene">
|
|
770
771
|
</component>
|
|
771
772
|
`);
|
|
772
|
-
return file;
|
|
773
773
|
}
|
|
774
774
|
it('Calls XML file validation plugins', () => {
|
|
775
775
|
const validateXml = sinon.spy();
|
|
@@ -781,8 +781,8 @@ describe('XmlFile', () => {
|
|
|
781
781
|
it('plugin diagnostics work for xml files', () => {
|
|
782
782
|
program.plugins.add({
|
|
783
783
|
name: 'Xml diagnostic test',
|
|
784
|
-
afterFileParse: (file) => {
|
|
785
|
-
if (file.
|
|
784
|
+
afterFileParse: ({ file }) => {
|
|
785
|
+
if (file.srcPath.endsWith('.xml')) {
|
|
786
786
|
file.addDiagnostics([{
|
|
787
787
|
file: file,
|
|
788
788
|
message: 'Test diagnostic',
|
|
@@ -792,7 +792,7 @@ describe('XmlFile', () => {
|
|
|
792
792
|
}
|
|
793
793
|
}
|
|
794
794
|
});
|
|
795
|
-
program.
|
|
795
|
+
program.setFile('components/comp.xml', (0, testHelpers_spec_1.trim) `
|
|
796
796
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
797
797
|
<component name="Cmp1" extends="Scene">
|
|
798
798
|
</component>
|
|
@@ -806,40 +806,40 @@ describe('XmlFile', () => {
|
|
|
806
806
|
describe('typedef', () => {
|
|
807
807
|
it('loads d.bs files from parent scope', () => {
|
|
808
808
|
var _a;
|
|
809
|
-
program.
|
|
809
|
+
program.setFile('components/ParentComponent.xml', (0, testHelpers_spec_1.trim) `
|
|
810
810
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
811
811
|
<component name="ParentComponent" extends="Scene">
|
|
812
812
|
<script uri="ParentComponent.brs" />
|
|
813
813
|
</component>
|
|
814
814
|
`);
|
|
815
|
-
program.
|
|
815
|
+
program.setFile('components/ParentComponent.d.bs', `
|
|
816
816
|
import "Lib.brs"
|
|
817
817
|
namespace Parent
|
|
818
818
|
sub log()
|
|
819
819
|
end sub
|
|
820
820
|
end namespace
|
|
821
821
|
`);
|
|
822
|
-
program.
|
|
822
|
+
program.setFile('components/ParentComponent.brs', `
|
|
823
823
|
sub Parent_log()
|
|
824
824
|
end sub
|
|
825
825
|
`);
|
|
826
|
-
program.
|
|
826
|
+
program.setFile('components/Lib.d.bs', `
|
|
827
827
|
namespace Lib
|
|
828
828
|
sub log()
|
|
829
829
|
end sub
|
|
830
830
|
end namespace
|
|
831
831
|
`);
|
|
832
|
-
program.
|
|
832
|
+
program.setFile('components/Lib.brs', `
|
|
833
833
|
sub Lib_log()
|
|
834
834
|
end sub
|
|
835
835
|
`);
|
|
836
|
-
program.
|
|
836
|
+
program.setFile('components/ChildComponent.xml', (0, testHelpers_spec_1.trim) `
|
|
837
837
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
838
838
|
<component name="ChildComponent" extends="ParentComponent">
|
|
839
839
|
<script uri="ChildComponent.bs" />
|
|
840
840
|
</component>
|
|
841
841
|
`);
|
|
842
|
-
program.
|
|
842
|
+
program.setFile('components/ChildComponent.bs', `
|
|
843
843
|
sub init()
|
|
844
844
|
Parent.log()
|
|
845
845
|
Lib.log()
|
|
@@ -854,28 +854,28 @@ describe('XmlFile', () => {
|
|
|
854
854
|
]);
|
|
855
855
|
});
|
|
856
856
|
it('loads `d.bs` files into scope', () => {
|
|
857
|
-
const xmlFile = program.
|
|
857
|
+
const xmlFile = program.setFile('components/Component1.xml', (0, testHelpers_spec_1.trim) `
|
|
858
858
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
859
859
|
<component name="Component1" extends="Scene">
|
|
860
860
|
<script uri="Component1.brs" />
|
|
861
861
|
</component>
|
|
862
862
|
`);
|
|
863
|
-
program.
|
|
863
|
+
program.setFile('components/Component1.d.bs', `
|
|
864
864
|
sub logInfo()
|
|
865
865
|
end sub
|
|
866
866
|
`);
|
|
867
867
|
(0, chai_1.expect)(program.getScopesForFile(xmlFile)[0].getAllCallables().map(x => x.callable.name)).to.include('logInfo');
|
|
868
868
|
});
|
|
869
869
|
it('does not include `d.bs` script during transpile', () => {
|
|
870
|
-
program.
|
|
870
|
+
program.setFile('source/logger.d.bs', `
|
|
871
871
|
sub logInfo()
|
|
872
872
|
end sub
|
|
873
873
|
`);
|
|
874
|
-
program.
|
|
874
|
+
program.setFile('source/logger.brs', `
|
|
875
875
|
sub logInfo()
|
|
876
876
|
end sub
|
|
877
877
|
`);
|
|
878
|
-
program.
|
|
878
|
+
program.setFile('components/Component1.bs', `
|
|
879
879
|
import "pkg:/source/logger.brs"
|
|
880
880
|
sub init()
|
|
881
881
|
end sub
|
|
@@ -895,7 +895,7 @@ describe('XmlFile', () => {
|
|
|
895
895
|
`, 'none', 'components/Component1.xml');
|
|
896
896
|
});
|
|
897
897
|
it('does not load .brs information into scope if related d.bs is in scope', () => {
|
|
898
|
-
const xmlFile = program.
|
|
898
|
+
const xmlFile = program.setFile('components/Component1.xml', (0, testHelpers_spec_1.trim) `
|
|
899
899
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
900
900
|
<component name="Component1" extends="Scene">
|
|
901
901
|
<script uri="Component1.brs" />
|
|
@@ -903,7 +903,7 @@ describe('XmlFile', () => {
|
|
|
903
903
|
`);
|
|
904
904
|
const scope = program.getScopesForFile(xmlFile)[0];
|
|
905
905
|
//load brs file
|
|
906
|
-
program.
|
|
906
|
+
program.setFile('components/Component1.brs', `
|
|
907
907
|
sub logInfo()
|
|
908
908
|
end sub
|
|
909
909
|
sub logWarning()
|
|
@@ -913,7 +913,7 @@ describe('XmlFile', () => {
|
|
|
913
913
|
(0, chai_1.expect)(functionNames).to.include('logInfo');
|
|
914
914
|
(0, chai_1.expect)(functionNames).to.include('logWarning');
|
|
915
915
|
//load d.bs file, which should shadow out the .brs file
|
|
916
|
-
program.
|
|
916
|
+
program.setFile('components/Component1.d.bs', `
|
|
917
917
|
sub logError()
|
|
918
918
|
end sub
|
|
919
919
|
`);
|
|
@@ -923,7 +923,7 @@ describe('XmlFile', () => {
|
|
|
923
923
|
(0, chai_1.expect)(functionNames).not.to.include('logWarning');
|
|
924
924
|
});
|
|
925
925
|
it('updates xml scope when typedef disappears', () => {
|
|
926
|
-
const xmlFile = program.
|
|
926
|
+
const xmlFile = program.setFile('components/Component1.xml', (0, testHelpers_spec_1.trim) `
|
|
927
927
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
928
928
|
<component name="Component1" extends="Scene">
|
|
929
929
|
<script uri="Component1.brs" />
|
|
@@ -931,12 +931,12 @@ describe('XmlFile', () => {
|
|
|
931
931
|
`);
|
|
932
932
|
const scope = program.getScopesForFile(xmlFile)[0];
|
|
933
933
|
//load brs file
|
|
934
|
-
program.
|
|
934
|
+
program.setFile('components/Component1.brs', `
|
|
935
935
|
sub logBrs()
|
|
936
936
|
end sub
|
|
937
937
|
`);
|
|
938
938
|
//load d.bs file, which should shadow out the .brs file
|
|
939
|
-
const typedef = program.
|
|
939
|
+
const typedef = program.setFile('components/Component1.d.bs', `
|
|
940
940
|
sub logTypedef()
|
|
941
941
|
end sub
|
|
942
942
|
`);
|
|
@@ -945,7 +945,7 @@ describe('XmlFile', () => {
|
|
|
945
945
|
(0, chai_1.expect)(functionNames).to.include('logTypedef');
|
|
946
946
|
(0, chai_1.expect)(functionNames).not.to.include('logBrs');
|
|
947
947
|
//remove the typdef file
|
|
948
|
-
program.removeFile(typedef.
|
|
948
|
+
program.removeFile(typedef.srcPath);
|
|
949
949
|
program.validate();
|
|
950
950
|
functionNames = scope.getOwnCallables().map(x => x.callable.name);
|
|
951
951
|
(0, chai_1.expect)(functionNames).not.to.include('logTypedef');
|
|
@@ -954,7 +954,7 @@ describe('XmlFile', () => {
|
|
|
954
954
|
});
|
|
955
955
|
it('finds script imports for single-quoted script tags', () => {
|
|
956
956
|
var _a;
|
|
957
|
-
const file = program.
|
|
957
|
+
const file = program.setFile('components/file.xml', (0, testHelpers_spec_1.trim) `
|
|
958
958
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
959
959
|
<component name="Cmp1" extends="Scene">
|
|
960
960
|
<script uri='SingleQuotedFile.brs' />
|
|
@@ -965,7 +965,7 @@ describe('XmlFile', () => {
|
|
|
965
965
|
describe('commentFlags', () => {
|
|
966
966
|
it('ignores warning from previous line comment', () => {
|
|
967
967
|
//component without a name attribute
|
|
968
|
-
program.
|
|
968
|
+
program.setFile('components/file.xml', (0, testHelpers_spec_1.trim) `
|
|
969
969
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
970
970
|
<!--bs:disable-next-line-->
|
|
971
971
|
<component>
|
|
@@ -976,7 +976,7 @@ describe('XmlFile', () => {
|
|
|
976
976
|
});
|
|
977
977
|
it('ignores warning from previous line just for the specified code', () => {
|
|
978
978
|
//component without a name attribute
|
|
979
|
-
program.
|
|
979
|
+
program.setFile('components/file.xml', (0, testHelpers_spec_1.trim) `
|
|
980
980
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
981
981
|
<!--bs:disable-next-line 1006-->
|
|
982
982
|
<component>
|
|
@@ -989,7 +989,7 @@ describe('XmlFile', () => {
|
|
|
989
989
|
});
|
|
990
990
|
it('ignores warning from previous line comment', () => {
|
|
991
991
|
//component without a name attribute
|
|
992
|
-
program.
|
|
992
|
+
program.setFile('components/file.xml', (0, testHelpers_spec_1.trim) `
|
|
993
993
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
994
994
|
<component> <!--bs:disable-line-->
|
|
995
995
|
</component>
|
|
@@ -999,7 +999,7 @@ describe('XmlFile', () => {
|
|
|
999
999
|
});
|
|
1000
1000
|
it('ignores warning from previous line just for the specified code', () => {
|
|
1001
1001
|
//component without a name attribute
|
|
1002
|
-
program.
|
|
1002
|
+
program.setFile('components/file.xml', (0, testHelpers_spec_1.trim) `
|
|
1003
1003
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1004
1004
|
<component> <!--bs:disable-line 1006-->
|
|
1005
1005
|
</component>
|
|
@@ -1012,16 +1012,16 @@ describe('XmlFile', () => {
|
|
|
1012
1012
|
});
|
|
1013
1013
|
describe('duplicate components', () => {
|
|
1014
1014
|
it('more gracefully handles multiple components with the same name', () => {
|
|
1015
|
-
program.
|
|
1016
|
-
program.
|
|
1015
|
+
program.setFile('components/comp1.brs', ``);
|
|
1016
|
+
program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
1017
1017
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1018
1018
|
<component name="comp1" extends="Group">
|
|
1019
1019
|
<script uri="comp1.brs" />
|
|
1020
1020
|
</component>
|
|
1021
1021
|
`);
|
|
1022
1022
|
//add another component with the same name
|
|
1023
|
-
program.
|
|
1024
|
-
program.
|
|
1023
|
+
program.setFile('components/comp2.brs', ``);
|
|
1024
|
+
program.setFile('components/comp2.xml', (0, testHelpers_spec_1.trim) `
|
|
1025
1025
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1026
1026
|
<component name="comp1" extends="Group">
|
|
1027
1027
|
<script uri="comp2.brs" />
|
|
@@ -1035,14 +1035,14 @@ describe('XmlFile', () => {
|
|
|
1035
1035
|
});
|
|
1036
1036
|
it('maintains consistent component selection', () => {
|
|
1037
1037
|
//add comp2 first
|
|
1038
|
-
const comp2 = program.
|
|
1038
|
+
const comp2 = program.setFile('components/comp2.xml', (0, testHelpers_spec_1.trim) `
|
|
1039
1039
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1040
1040
|
<component name="comp1">
|
|
1041
1041
|
</component>
|
|
1042
1042
|
`);
|
|
1043
1043
|
(0, chai_1.expect)(program.getComponent('comp1').file.pkgPath).to.equal(comp2.pkgPath);
|
|
1044
1044
|
//add comp1. it should become the main component with this name
|
|
1045
|
-
const comp1 = program.
|
|
1045
|
+
const comp1 = program.setFile('components/comp1.xml', (0, testHelpers_spec_1.trim) `
|
|
1046
1046
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1047
1047
|
<component name="comp1" extends="Group">
|
|
1048
1048
|
</component>
|
|
@@ -1052,7 +1052,7 @@ describe('XmlFile', () => {
|
|
|
1052
1052
|
program.removeFile((0, util_1.standardizePath) `${rootDir}/components/comp1.xml`);
|
|
1053
1053
|
(0, chai_1.expect)(program.getComponent('comp1').file.pkgPath).to.equal(comp2.pkgPath);
|
|
1054
1054
|
//add comp3
|
|
1055
|
-
program.
|
|
1055
|
+
program.setFile('components/comp3.xml', (0, testHelpers_spec_1.trim) `
|
|
1056
1056
|
<?xml version="1.0" encoding="utf-8" ?>
|
|
1057
1057
|
<component name="comp1">
|
|
1058
1058
|
</component>
|