brighterscript 0.45.5 → 0.45.6
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 +11 -0
- package/README.md +21 -6
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +7 -3
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -1
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +1 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
- package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
- package/dist/files/BrsFile.Class.spec.js +1 -1
- package/dist/files/BrsFile.spec.js +129 -53
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/parser/Statement.js +3 -5
- package/dist/parser/Statement.js.map +1 -1
- package/dist/types/BooleanType.d.ts +2 -0
- package/dist/types/BooleanType.js +5 -1
- package/dist/types/BooleanType.js.map +1 -1
- package/dist/types/DoubleType.d.ts +2 -0
- package/dist/types/DoubleType.js +5 -1
- package/dist/types/DoubleType.js.map +1 -1
- package/dist/types/DynamicType.d.ts +2 -0
- package/dist/types/DynamicType.js +5 -1
- package/dist/types/DynamicType.js.map +1 -1
- package/dist/types/FloatType.d.ts +2 -0
- package/dist/types/FloatType.js +5 -1
- package/dist/types/FloatType.js.map +1 -1
- package/dist/types/IntegerType.d.ts +2 -0
- package/dist/types/IntegerType.js +5 -1
- package/dist/types/IntegerType.js.map +1 -1
- package/dist/types/InvalidType.d.ts +2 -0
- package/dist/types/InvalidType.js +5 -1
- package/dist/types/InvalidType.js.map +1 -1
- package/dist/types/LongIntegerType.d.ts +2 -0
- package/dist/types/LongIntegerType.js +5 -1
- package/dist/types/LongIntegerType.js.map +1 -1
- package/dist/types/ObjectType.d.ts +2 -0
- package/dist/types/ObjectType.js +5 -1
- package/dist/types/ObjectType.js.map +1 -1
- package/dist/types/StringType.d.ts +2 -0
- package/dist/types/StringType.js +5 -1
- package/dist/types/StringType.js.map +1 -1
- package/dist/types/UninitializedType.js.map +1 -1
- package/dist/types/VoidType.d.ts +2 -0
- package/dist/types/VoidType.js +5 -1
- package/dist/types/VoidType.js.map +1 -1
- package/dist/util.js +21 -15
- package/dist/util.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
|
+
## [0.45.6](https://github.com/rokucommunity/brighterscript/compare/v0.45.5...v0.45.6) - 2022-03-17
|
|
10
|
+
### Changed
|
|
11
|
+
- upgrade to [roku-deploy@3.5.4](https://github.com/rokucommunity/roku-deploy/blob/master/CHANGELOG.md#354---2022-03-17) which fixed significant performance issues during globbing. ([roku-deploy#86](https://github.com/rokucommunity/roku-deploy/pull/86))
|
|
12
|
+
### Fixed
|
|
13
|
+
- crash when checking for enums to transpile [#539](https://github.com/rokucommunity/brighterscript/pull/539)
|
|
14
|
+
- Transpile if statements as written [#537](https://github.com/rokucommunity/brighterscript/pull/537)
|
|
15
|
+
- Keep the original type case when transpiling. [#536](https://github.com/rokucommunity/brighterscript/pull/536)
|
|
16
|
+
- Show cli usage in plugins documentation
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
9
20
|
## [0.45.5](https://github.com/rokucommunity/brighterscript/compare/v0.45.4...v0.45.5) - 2022-03-10
|
|
10
21
|
### Fixed
|
|
11
22
|
- bug with typedefs and auto-generated class constructor functions [#535](https://github.com/rokucommunity/brighterscript/pull/535)
|
package/README.md
CHANGED
|
@@ -61,12 +61,27 @@ BrighterScript adds several new features to the BrightScript language such as Na
|
|
|
61
61
|
- And if it's not enough, the [plugin API](https://github.com/rokucommunity/brighterscript/blob/master/docs/plugins.md) allows extending the compiler to provide extra diagnostics or transformations.
|
|
62
62
|
|
|
63
63
|
## Who uses Brighterscript?
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
<br/>
|
|
65
|
+
<p align="center">
|
|
66
|
+
<a href="https://www.applicaster.com/">
|
|
67
|
+
<img src="https://user-images.githubusercontent.com/2544493/96571912-377af280-129a-11eb-8295-49eb12e54aeb.png">
|
|
68
|
+
</a>
|
|
69
|
+
<a href="https://www.miraclechannel.ca/corcoplus">
|
|
70
|
+
<img src="https://user-images.githubusercontent.com/2544493/157429644-ba0d574a-d3c3-425f-8e68-98103fb8f707.png">
|
|
71
|
+
</a>
|
|
72
|
+
<a href="https://www.nba.com/">
|
|
73
|
+
<img src="https://user-images.githubusercontent.com/2544493/157430017-a27b62d0-63de-4e87-a6df-8448007bd24d.png">
|
|
74
|
+
</a>
|
|
75
|
+
<a href="https://github.com/georgejecook/rooibos/blob/master/docs/index.md">
|
|
76
|
+
<img src="https://user-images.githubusercontent.com/2544493/157430331-20913e84-f3f4-447a-b093-8780cd1241e6.png">
|
|
77
|
+
</a>
|
|
78
|
+
</p>
|
|
79
|
+
<br/>
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
The BrighterScript project is used to power the popular [Brightscript Language](https://marketplace.visualstudio.com/items?itemName=rokucommunity.brightscript) VSCode extension, the [maestro framework](https://github.com/georgejecook/maestro/blob/master/docs/index.md), and more.
|
|
83
|
+
|
|
84
|
+
[Contact us](https://github.com/rokucommunity/brighterscript/issues/new) if you use BrighterScript on your project and would like your logo listed above. More projects are adopting BrighterScript all the time, from using the new BrighterScript language features to simply using the compiler in their build pipeline.
|
|
70
85
|
|
|
71
86
|
## What's with the name?
|
|
72
87
|
The name BrighterScript is a compliment to everything that is great about Roku's awesome BrightScript language. Naming things is hard, and discoverability and recognizability are both very important. Here are the reasons we chose this name:
|
|
@@ -11,18 +11,22 @@ class BrsFilePreTranspileProcessor {
|
|
|
11
11
|
this.replaceEnumValues();
|
|
12
12
|
}
|
|
13
13
|
replaceEnumValues() {
|
|
14
|
-
var _a, _b, _c;
|
|
14
|
+
var _a, _b, _c, _d;
|
|
15
15
|
const membersByEnum = new Cache_1.Cache();
|
|
16
16
|
const enumLookup = (_a = this.event.file.program.getFirstScopeForFile(this.event.file)) === null || _a === void 0 ? void 0 : _a.getEnumMap();
|
|
17
|
+
//skip this logic if current scope has no enums
|
|
18
|
+
if (((_b = enumLookup === null || enumLookup === void 0 ? void 0 : enumLookup.size) !== null && _b !== void 0 ? _b : 0) === 0) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
17
21
|
for (const expression of this.event.file.parser.references.expressions) {
|
|
18
|
-
const parts = (
|
|
22
|
+
const parts = (_c = util_1.default.getAllDottedGetParts(expression)) === null || _c === void 0 ? void 0 : _c.map(x => x.toLowerCase());
|
|
19
23
|
if (parts) {
|
|
20
24
|
//get the name of the enum member
|
|
21
25
|
const memberName = parts.pop();
|
|
22
26
|
//get the name of the enum (including leading namespace if applicable)
|
|
23
27
|
const enumName = parts.join('.');
|
|
24
28
|
const lowerEnumName = enumName.toLowerCase();
|
|
25
|
-
const theEnum = (
|
|
29
|
+
const theEnum = (_d = enumLookup.get(lowerEnumName)) === null || _d === void 0 ? void 0 : _d.item;
|
|
26
30
|
if (theEnum) {
|
|
27
31
|
const members = membersByEnum.getOrAdd(lowerEnumName, () => theEnum.getMemberValueMap());
|
|
28
32
|
const value = members === null || members === void 0 ? void 0 : members.get(memberName);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BrsFilePreTranspileProcessor.js","sourceRoot":"","sources":["../../../src/bscPlugin/transpile/BrsFilePreTranspileProcessor.ts"],"names":[],"mappings":";;;AAAA,uCAAoC;AAGpC,qCAA8B;AAE9B,MAAa,4BAA4B;IACrC,YACY,KAAwC;QAAxC,UAAK,GAAL,KAAK,CAAmC;IAEpD,CAAC;IAEM,OAAO;QACV,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IAEO,iBAAiB;;QACrB,MAAM,aAAa,GAAG,IAA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BAAiB,EAAE,CAAC,CAAC;oBACzF,MAAM,KAAK,GAAG,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,GAAG,CAAC,UAAU,CAAC,CAAC;oBACvC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;iBAChE;aACJ;SACJ;IACL,CAAC;CACJ;AAnCD,oEAmCC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sinon_1 = require("sinon");
|
|
4
|
+
const fsExtra = require("fs-extra");
|
|
5
|
+
const Program_1 = require("../../Program");
|
|
6
|
+
const util_1 = require("../../util");
|
|
7
|
+
const sinon = (0, sinon_1.createSandbox)();
|
|
8
|
+
describe('BrsFile', () => {
|
|
9
|
+
const tempDir = (0, util_1.standardizePath) `${process.cwd()}/.tmp`;
|
|
10
|
+
const rootDir = (0, util_1.standardizePath) `${tempDir}/rootDir`;
|
|
11
|
+
let program;
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
fsExtra.emptyDirSync(tempDir);
|
|
14
|
+
program = new Program_1.Program({ rootDir: rootDir, sourceMap: true });
|
|
15
|
+
});
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
sinon.restore();
|
|
18
|
+
program.dispose();
|
|
19
|
+
});
|
|
20
|
+
describe('BrsFilePreTranspileProcessor', () => {
|
|
21
|
+
it('does not crash when operating on a file not included by any scope', async () => {
|
|
22
|
+
program.setFile('components/lib.brs', `
|
|
23
|
+
sub doSomething()
|
|
24
|
+
a = { b: "c"}
|
|
25
|
+
print a.b
|
|
26
|
+
end sub
|
|
27
|
+
`);
|
|
28
|
+
await program.transpile([], (0, util_1.standardizePath) `${tempDir}/out`);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=BrsFilePreTranspileProcessor.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrsFilePreTranspileProcessor.spec.js","sourceRoot":"","sources":["../../../src/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.ts"],"names":[],"mappings":";;AAAA,iCAAsC;AACtC,oCAAoC;AACpC,2CAAwC;AACxC,qCAAkD;AAClD,MAAM,KAAK,GAAG,IAAA,qBAAa,GAAE,CAAC;AAE9B,QAAQ,CAAC,SAAS,EAAE,GAAG,EAAE;IACrB,MAAM,OAAO,GAAG,IAAA,sBAAC,EAAA,GAAG,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC;IACzC,MAAM,OAAO,GAAG,IAAA,sBAAC,EAAA,GAAG,OAAO,UAAU,CAAC;IACtC,IAAI,OAAgB,CAAC;IAErB,UAAU,CAAC,GAAG,EAAE;QACZ,OAAO,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAC9B,OAAO,GAAG,IAAI,iBAAO,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IACjE,CAAC,CAAC,CAAC;IACH,SAAS,CAAC,GAAG,EAAE;QACX,KAAK,CAAC,OAAO,EAAE,CAAC;QAChB,OAAO,CAAC,OAAO,EAAE,CAAC;IACtB,CAAC,CAAC,CAAC;IAEH,QAAQ,CAAC,8BAA8B,EAAE,GAAG,EAAE;QAC1C,EAAE,CAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;YAC/E,OAAO,CAAC,OAAO,CAAC,oBAAoB,EAAE;;;;;aAKrC,CAAC,CAAC;YACH,MAAM,OAAO,CAAC,SAAS,CAAC,EAAE,EAAE,IAAA,sBAAC,EAAA,GAAG,OAAO,MAAM,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
|
|
@@ -429,7 +429,7 @@ describe('BrsFile BrighterScript classes', () => {
|
|
|
429
429
|
instance.super0_sayHello = instance.sayHello
|
|
430
430
|
instance.sayHello = function(text)
|
|
431
431
|
text = "The duck says " + text
|
|
432
|
-
if text <> invalid
|
|
432
|
+
if text <> invalid
|
|
433
433
|
m.super0_sayHello(text)
|
|
434
434
|
end if
|
|
435
435
|
end function
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const chai_1 = require("chai");
|
|
4
4
|
const sinonImport = require("sinon");
|
|
5
|
-
const path = require("path");
|
|
6
5
|
const vscode_languageserver_1 = require("vscode-languageserver");
|
|
7
6
|
const Program_1 = require("../Program");
|
|
8
7
|
const BooleanType_1 = require("../types/BooleanType");
|
|
@@ -22,15 +21,18 @@ const Parser_1 = require("../parser/Parser");
|
|
|
22
21
|
const Logger_1 = require("../Logger");
|
|
23
22
|
const Statement_1 = require("../parser/Statement");
|
|
24
23
|
const creators_1 = require("../astUtils/creators");
|
|
24
|
+
const fsExtra = require("fs-extra");
|
|
25
25
|
let sinon = sinonImport.createSandbox();
|
|
26
26
|
describe('BrsFile', () => {
|
|
27
|
-
let
|
|
27
|
+
let tempDir = (0, util_1.standardizePath) `${process.cwd()}/.tmp`;
|
|
28
|
+
let rootDir = (0, util_1.standardizePath) `${tempDir}/rootDir`;
|
|
28
29
|
let program;
|
|
29
30
|
let srcPath = (0, util_1.standardizePath) `${rootDir}/source/main.brs`;
|
|
30
31
|
let destPath = 'source/main.brs';
|
|
31
32
|
let file;
|
|
32
33
|
let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, rootDir]);
|
|
33
34
|
beforeEach(() => {
|
|
35
|
+
fsExtra.emptyDirSync(tempDir);
|
|
34
36
|
program = new Program_1.Program({ rootDir: rootDir, sourceMap: true });
|
|
35
37
|
file = new BrsFile_1.BrsFile(srcPath, destPath, program);
|
|
36
38
|
});
|
|
@@ -1652,6 +1654,106 @@ describe('BrsFile', () => {
|
|
|
1652
1654
|
//this test will throw an exception if something went wrong
|
|
1653
1655
|
});
|
|
1654
1656
|
describe('transpile', () => {
|
|
1657
|
+
it('transpiles if statement keywords as provided', () => {
|
|
1658
|
+
const code = `
|
|
1659
|
+
If True Then
|
|
1660
|
+
Print True
|
|
1661
|
+
Else If True Then
|
|
1662
|
+
print True
|
|
1663
|
+
Else If False Then
|
|
1664
|
+
Print False
|
|
1665
|
+
Else
|
|
1666
|
+
Print False
|
|
1667
|
+
End If
|
|
1668
|
+
`;
|
|
1669
|
+
testTranspile(code);
|
|
1670
|
+
testTranspile(code.toLowerCase());
|
|
1671
|
+
testTranspile(code.toUpperCase());
|
|
1672
|
+
});
|
|
1673
|
+
it('does not transpile `then` tokens', () => {
|
|
1674
|
+
const code = `
|
|
1675
|
+
if true
|
|
1676
|
+
print true
|
|
1677
|
+
else if true
|
|
1678
|
+
print false
|
|
1679
|
+
end if
|
|
1680
|
+
`;
|
|
1681
|
+
testTranspile(code);
|
|
1682
|
+
});
|
|
1683
|
+
it('honors spacing between multi-word tokens', () => {
|
|
1684
|
+
testTranspile(`
|
|
1685
|
+
if true
|
|
1686
|
+
print true
|
|
1687
|
+
elseif true
|
|
1688
|
+
print false
|
|
1689
|
+
endif
|
|
1690
|
+
`);
|
|
1691
|
+
});
|
|
1692
|
+
it('handles when only some of the statements have `then`', () => {
|
|
1693
|
+
testTranspile(`
|
|
1694
|
+
if true
|
|
1695
|
+
else if true then
|
|
1696
|
+
else if true
|
|
1697
|
+
else if true then
|
|
1698
|
+
if true then
|
|
1699
|
+
return true
|
|
1700
|
+
end if
|
|
1701
|
+
end if
|
|
1702
|
+
`);
|
|
1703
|
+
});
|
|
1704
|
+
it('retains casing of parameter types', () => {
|
|
1705
|
+
function test(type) {
|
|
1706
|
+
testTranspile(`
|
|
1707
|
+
sub one(a as ${type}, b as ${type.toUpperCase()}, c as ${type.toLowerCase()})
|
|
1708
|
+
end sub
|
|
1709
|
+
`);
|
|
1710
|
+
}
|
|
1711
|
+
test('Boolean');
|
|
1712
|
+
test('Double');
|
|
1713
|
+
test('Dynamic');
|
|
1714
|
+
test('Float');
|
|
1715
|
+
test('Integer');
|
|
1716
|
+
test('LongInteger');
|
|
1717
|
+
test('Object');
|
|
1718
|
+
test('String');
|
|
1719
|
+
});
|
|
1720
|
+
it('retains casing of return types', () => {
|
|
1721
|
+
function test(type) {
|
|
1722
|
+
testTranspile(`
|
|
1723
|
+
sub one() as ${type}
|
|
1724
|
+
end sub
|
|
1725
|
+
|
|
1726
|
+
sub two() as ${type.toLowerCase()}
|
|
1727
|
+
end sub
|
|
1728
|
+
|
|
1729
|
+
sub three() as ${type.toUpperCase()}
|
|
1730
|
+
end sub
|
|
1731
|
+
`);
|
|
1732
|
+
}
|
|
1733
|
+
test('Boolean');
|
|
1734
|
+
test('Double');
|
|
1735
|
+
test('Dynamic');
|
|
1736
|
+
test('Float');
|
|
1737
|
+
test('Integer');
|
|
1738
|
+
test('LongInteger');
|
|
1739
|
+
test('Object');
|
|
1740
|
+
test('String');
|
|
1741
|
+
test('Void');
|
|
1742
|
+
});
|
|
1743
|
+
it('retains casing of literal types', () => {
|
|
1744
|
+
function test(type) {
|
|
1745
|
+
testTranspile(`
|
|
1746
|
+
sub main()
|
|
1747
|
+
thing = ${type}
|
|
1748
|
+
thing = ${type.toLowerCase()}
|
|
1749
|
+
thing = ${type.toUpperCase()}
|
|
1750
|
+
end sub
|
|
1751
|
+
`);
|
|
1752
|
+
}
|
|
1753
|
+
test('Invalid');
|
|
1754
|
+
test('True');
|
|
1755
|
+
test('False');
|
|
1756
|
+
});
|
|
1655
1757
|
describe('throwStatement', () => {
|
|
1656
1758
|
it('transpiles properly', () => {
|
|
1657
1759
|
testTranspile(`
|
|
@@ -1900,29 +2002,6 @@ describe('BrsFile', () => {
|
|
|
1900
2002
|
end sub
|
|
1901
2003
|
`, null, 'trim');
|
|
1902
2004
|
});
|
|
1903
|
-
it('adds `then` when missing', () => {
|
|
1904
|
-
testTranspile(`
|
|
1905
|
-
sub a()
|
|
1906
|
-
if true
|
|
1907
|
-
print "true"
|
|
1908
|
-
else if true
|
|
1909
|
-
print "true"
|
|
1910
|
-
else
|
|
1911
|
-
print "true"
|
|
1912
|
-
end if
|
|
1913
|
-
end sub
|
|
1914
|
-
`, `
|
|
1915
|
-
sub a()
|
|
1916
|
-
if true then
|
|
1917
|
-
print "true"
|
|
1918
|
-
else if true then
|
|
1919
|
-
print "true"
|
|
1920
|
-
else
|
|
1921
|
-
print "true"
|
|
1922
|
-
end if
|
|
1923
|
-
end sub
|
|
1924
|
-
`, 'trim');
|
|
1925
|
-
});
|
|
1926
2005
|
it('does not add leading or trailing newlines', () => {
|
|
1927
2006
|
testTranspile(`function abc()\nend function`, undefined, 'none');
|
|
1928
2007
|
});
|
|
@@ -2675,38 +2754,35 @@ describe('BrsFile', () => {
|
|
|
2675
2754
|
});
|
|
2676
2755
|
});
|
|
2677
2756
|
describe('Plugins', () => {
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
it('can use a plugin object which transforms the AST', () => {
|
|
2694
|
-
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins('', [
|
|
2695
|
-
require.resolve('../examples/plugins/removePrint')
|
|
2696
|
-
]), new Logger_1.Logger());
|
|
2697
|
-
testPluginTranspile();
|
|
2757
|
+
let pluginFileName;
|
|
2758
|
+
let idx = 1;
|
|
2759
|
+
beforeEach(() => {
|
|
2760
|
+
pluginFileName = `plugin-${idx++}.js`;
|
|
2761
|
+
fsExtra.outputFileSync((0, util_1.standardizePath) `${tempDir}/plugins/${pluginFileName}`, `
|
|
2762
|
+
function plugin() {
|
|
2763
|
+
return {
|
|
2764
|
+
name: 'lower-file-name',
|
|
2765
|
+
afterFileParse: (evt) => {
|
|
2766
|
+
evt._customProp = true;
|
|
2767
|
+
}
|
|
2768
|
+
};
|
|
2769
|
+
}
|
|
2770
|
+
exports.default = plugin;
|
|
2771
|
+
`);
|
|
2698
2772
|
});
|
|
2699
|
-
it('can load an absolute plugin which
|
|
2700
|
-
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins(
|
|
2701
|
-
|
|
2773
|
+
it('can load an absolute plugin which receives callbacks', () => {
|
|
2774
|
+
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins(tempDir, [
|
|
2775
|
+
(0, util_1.standardizePath) `${tempDir}/plugins/${pluginFileName}`
|
|
2702
2776
|
]), new Logger_1.Logger());
|
|
2703
|
-
|
|
2777
|
+
const file = program.setFile('source/MAIN.brs', '');
|
|
2778
|
+
(0, chai_1.expect)(file._customProp).to.exist;
|
|
2704
2779
|
});
|
|
2705
|
-
it('can load a relative plugin which
|
|
2706
|
-
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins(
|
|
2707
|
-
|
|
2780
|
+
it('can load a relative plugin which receives callbacks', () => {
|
|
2781
|
+
program.plugins = new PluginInterface_1.default(util_1.default.loadPlugins(tempDir, [
|
|
2782
|
+
`./plugins/${pluginFileName}`
|
|
2708
2783
|
]), new Logger_1.Logger());
|
|
2709
|
-
|
|
2784
|
+
const file = program.setFile('source/MAIN.brs', '');
|
|
2785
|
+
(0, chai_1.expect)(file._customProp).to.exist;
|
|
2710
2786
|
});
|
|
2711
2787
|
});
|
|
2712
2788
|
});
|