brighterscript 1.0.0-alpha.27 → 1.0.0-alpha.28
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 +61 -0
- package/README.md +1 -1
- package/dist/AstValidationSegmenter.d.ts +1 -1
- package/dist/AstValidationSegmenter.js +2 -2
- package/dist/AstValidationSegmenter.js.map +1 -1
- package/dist/DiagnosticFilterer.d.ts +7 -4
- package/dist/DiagnosticFilterer.js +67 -37
- package/dist/DiagnosticFilterer.js.map +1 -1
- package/dist/DiagnosticMessages.d.ts +1 -1
- package/dist/PluginInterface.js +1 -1
- package/dist/PluginInterface.js.map +1 -1
- package/dist/Program.d.ts +1 -1
- package/dist/Program.js +10 -6
- package/dist/Program.js.map +1 -1
- package/dist/Scope.d.ts +6 -27
- package/dist/Scope.js +40 -298
- package/dist/Scope.js.map +1 -1
- package/dist/SymbolTable.d.ts +1 -1
- package/dist/{SymbolTableFlag.js → SymbolTypeFlag.js} +1 -1
- package/dist/SymbolTypeFlag.js.map +1 -0
- package/dist/XmlScope.d.ts +0 -8
- package/dist/XmlScope.js +0 -77
- package/dist/XmlScope.js.map +1 -1
- package/dist/astUtils/CachedLookups.js +4 -8
- package/dist/astUtils/CachedLookups.js.map +1 -1
- package/dist/astUtils/creators.d.ts +1 -0
- package/dist/astUtils/creators.js +3 -2
- package/dist/astUtils/creators.js.map +1 -1
- package/dist/astUtils/creators.spec.js +0 -10
- package/dist/astUtils/creators.spec.js.map +1 -1
- package/dist/astUtils/reflection.d.ts +1 -2
- package/dist/astUtils/reflection.js +3 -7
- package/dist/astUtils/reflection.js.map +1 -1
- package/dist/astUtils/reflection.spec.js +10 -15
- package/dist/astUtils/reflection.spec.js.map +1 -1
- package/dist/astUtils/visitors.d.ts +1 -2
- package/dist/astUtils/visitors.js.map +1 -1
- package/dist/astUtils/visitors.spec.js +1 -5
- package/dist/astUtils/visitors.spec.js.map +1 -1
- package/dist/bscPlugin/BscPlugin.d.ts +2 -1
- package/dist/bscPlugin/BscPlugin.js +4 -0
- package/dist/bscPlugin/BscPlugin.js.map +1 -1
- package/dist/bscPlugin/SignatureHelpUtil.js +4 -3
- package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +1 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.js +26 -9
- package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +39 -0
- package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.js +5 -5
- package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
- package/dist/bscPlugin/hover/HoverProcessor.spec.js +51 -5
- package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
- package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
- package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
- package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
- package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
- package/dist/bscPlugin/validation/BrsFileValidator.js +1 -6
- package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.d.ts +28 -1
- package/dist/bscPlugin/validation/ScopeValidator.js +365 -7
- package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
- package/dist/bscPlugin/validation/ScopeValidator.spec.js +89 -3
- package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
- package/dist/files/BrsFile.Class.spec.js +11 -4
- package/dist/files/BrsFile.Class.spec.js.map +1 -1
- package/dist/files/BrsFile.d.ts +12 -2
- package/dist/files/BrsFile.js +64 -38
- package/dist/files/BrsFile.js.map +1 -1
- package/dist/files/BrsFile.spec.js +373 -6
- package/dist/files/BrsFile.spec.js.map +1 -1
- package/dist/files/XmlFile.js +1 -1
- package/dist/files/XmlFile.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +41 -3
- package/dist/interfaces.js.map +1 -1
- package/dist/lexer/Lexer.d.ts +9 -3
- package/dist/lexer/Lexer.js +36 -15
- package/dist/lexer/Lexer.js.map +1 -1
- package/dist/lexer/Lexer.spec.js +76 -38
- package/dist/lexer/Lexer.spec.js.map +1 -1
- package/dist/lexer/Token.js +1 -1
- package/dist/lexer/Token.js.map +1 -1
- package/dist/lexer/TokenKind.d.ts +1 -0
- package/dist/lexer/TokenKind.js +4 -1
- package/dist/lexer/TokenKind.js.map +1 -1
- package/dist/parser/AstNode.d.ts +1 -2
- package/dist/parser/AstNode.js +0 -1
- package/dist/parser/AstNode.js.map +1 -1
- package/dist/parser/BrsTranspileState.d.ts +1 -1
- package/dist/parser/Expression.d.ts +71 -47
- package/dist/parser/Expression.js +155 -87
- package/dist/parser/Expression.js.map +1 -1
- package/dist/parser/Parser.d.ts +7 -2
- package/dist/parser/Parser.js +40 -87
- package/dist/parser/Parser.js.map +1 -1
- package/dist/parser/Parser.spec.js +21 -44
- package/dist/parser/Parser.spec.js.map +1 -1
- package/dist/parser/SGTypes.js +5 -5
- package/dist/parser/SGTypes.js.map +1 -1
- package/dist/parser/Statement.d.ts +92 -84
- package/dist/parser/Statement.js +199 -133
- package/dist/parser/Statement.js.map +1 -1
- package/dist/parser/Statement.spec.js +0 -13
- package/dist/parser/Statement.spec.js.map +1 -1
- package/dist/parser/TranspileState.d.ts +17 -8
- package/dist/parser/TranspileState.js +64 -6
- package/dist/parser/TranspileState.js.map +1 -1
- package/dist/parser/tests/Parser.spec.d.ts +1 -1
- package/dist/parser/tests/Parser.spec.js +1 -2
- package/dist/parser/tests/Parser.spec.js.map +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js +1 -1
- package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +1 -3
- package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +44 -0
- package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
- package/dist/parser/tests/expression/TemplateStringExpression.spec.js +6 -6
- package/dist/parser/tests/expression/TernaryExpression.spec.js +47 -0
- package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
- package/dist/parser/tests/statement/ConstStatement.spec.js +2 -2
- package/dist/parser/tests/statement/InterfaceStatement.spec.js +8 -1
- package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
- package/dist/parser/tests/statement/Misc.spec.js +25 -5
- package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
- package/dist/preprocessor/Chunk.js +1 -2
- package/dist/preprocessor/Chunk.js.map +1 -1
- package/dist/preprocessor/PreprocessorParser.js +2 -1
- package/dist/preprocessor/PreprocessorParser.js.map +1 -1
- package/dist/types/AssociativeArrayType.d.ts +3 -0
- package/dist/types/AssociativeArrayType.js +9 -0
- package/dist/types/AssociativeArrayType.js.map +1 -1
- package/dist/types/BscType.d.ts +1 -1
- package/dist/types/BscType.js +1 -0
- package/dist/types/BscType.js.map +1 -1
- package/dist/types/ComponentType.d.ts +1 -1
- package/dist/types/ReferenceType.d.ts +1 -1
- package/dist/util.d.ts +18 -8
- package/dist/util.js +96 -18
- package/dist/util.js.map +1 -1
- package/package.json +6 -3
- package/dist/SymbolTableFlag.js.map +0 -1
- /package/dist/{SymbolTableFlag.d.ts → SymbolTypeFlag.d.ts} +0 -0
|
@@ -23,6 +23,7 @@ const vscode_uri_1 = require("vscode-uri");
|
|
|
23
23
|
const undent_1 = require("undent");
|
|
24
24
|
const testHelpers_spec_2 = require("../testHelpers.spec");
|
|
25
25
|
const types_1 = require("../types");
|
|
26
|
+
const fileUrl = require("file-url");
|
|
26
27
|
let sinon = sinonImport.createSandbox();
|
|
27
28
|
describe('BrsFile', () => {
|
|
28
29
|
let program;
|
|
@@ -505,6 +506,27 @@ describe('BrsFile', () => {
|
|
|
505
506
|
(0, testHelpers_spec_1.expectZeroDiagnostics)(file);
|
|
506
507
|
});
|
|
507
508
|
describe('conditional compile', () => {
|
|
509
|
+
it('supports whitespace-separated directives', async () => {
|
|
510
|
+
const file = program.setFile('source/main.bs', `
|
|
511
|
+
sub main()
|
|
512
|
+
#\t const thing=true
|
|
513
|
+
#\t if thing
|
|
514
|
+
print "if"
|
|
515
|
+
#\t elseif false
|
|
516
|
+
print "elseif"
|
|
517
|
+
#\t error crash
|
|
518
|
+
#\t else
|
|
519
|
+
print "else"
|
|
520
|
+
#\t endif
|
|
521
|
+
end sub
|
|
522
|
+
`);
|
|
523
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
524
|
+
await testTranspile(file.fileContents, `
|
|
525
|
+
sub main()
|
|
526
|
+
print "if"
|
|
527
|
+
end sub
|
|
528
|
+
`);
|
|
529
|
+
});
|
|
508
530
|
it('supports case-insensitive bs_const variables', () => {
|
|
509
531
|
fsExtra.outputFileSync(`${testHelpers_spec_2.rootDir}/manifest`, (0, undent_1.default) `
|
|
510
532
|
bs_const=SomeKey=true
|
|
@@ -1490,6 +1512,230 @@ describe('BrsFile', () => {
|
|
|
1490
1512
|
//this test will throw an exception if something went wrong
|
|
1491
1513
|
});
|
|
1492
1514
|
describe('transpile', () => {
|
|
1515
|
+
describe('null tokens', () => {
|
|
1516
|
+
it('succeeds when token locations are omitted', () => {
|
|
1517
|
+
doTest(`
|
|
1518
|
+
library "something" 'comment before func
|
|
1519
|
+
sub main(arg0, arg1 as string, arg2 = invalid)
|
|
1520
|
+
'comment
|
|
1521
|
+
aa = {
|
|
1522
|
+
'comment
|
|
1523
|
+
one: 1
|
|
1524
|
+
"two": 2
|
|
1525
|
+
}
|
|
1526
|
+
arr = [
|
|
1527
|
+
'comment
|
|
1528
|
+
1
|
|
1529
|
+
'comment
|
|
1530
|
+
2
|
|
1531
|
+
]
|
|
1532
|
+
val = + m.val
|
|
1533
|
+
print "hello"
|
|
1534
|
+
'comment after print
|
|
1535
|
+
num = 1
|
|
1536
|
+
num++
|
|
1537
|
+
num += 2
|
|
1538
|
+
num = +num
|
|
1539
|
+
test(num)
|
|
1540
|
+
for i = 0 to 10 step 1
|
|
1541
|
+
exit for
|
|
1542
|
+
end for
|
|
1543
|
+
while true
|
|
1544
|
+
exit while
|
|
1545
|
+
end while
|
|
1546
|
+
if true then
|
|
1547
|
+
print 1
|
|
1548
|
+
else if true
|
|
1549
|
+
print 1
|
|
1550
|
+
else
|
|
1551
|
+
print 1
|
|
1552
|
+
end if
|
|
1553
|
+
dim thing[1, 2]
|
|
1554
|
+
label1:
|
|
1555
|
+
goto label1
|
|
1556
|
+
end
|
|
1557
|
+
stop
|
|
1558
|
+
stuff = [
|
|
1559
|
+
1
|
|
1560
|
+
2
|
|
1561
|
+
3
|
|
1562
|
+
]
|
|
1563
|
+
for each item in stuff
|
|
1564
|
+
print item
|
|
1565
|
+
end for
|
|
1566
|
+
m.thing = 1
|
|
1567
|
+
m.thing += 1
|
|
1568
|
+
m[1] = 1
|
|
1569
|
+
m[1] += 1
|
|
1570
|
+
m[1, 2] = 2
|
|
1571
|
+
try
|
|
1572
|
+
print m.b.c
|
|
1573
|
+
catch e
|
|
1574
|
+
print e
|
|
1575
|
+
end try
|
|
1576
|
+
throw "crash"
|
|
1577
|
+
for i = 0 to 10
|
|
1578
|
+
continue
|
|
1579
|
+
end for
|
|
1580
|
+
print m@name
|
|
1581
|
+
print (1 + 2)
|
|
1582
|
+
end sub
|
|
1583
|
+
|
|
1584
|
+
sub test(p1)
|
|
1585
|
+
return p1
|
|
1586
|
+
end sub
|
|
1587
|
+
`);
|
|
1588
|
+
});
|
|
1589
|
+
it('works for bs content', () => {
|
|
1590
|
+
program.setFile('source/lib.bs', ``);
|
|
1591
|
+
doTest(`
|
|
1592
|
+
import "pkg:/source/lib.bs"
|
|
1593
|
+
@annotation()
|
|
1594
|
+
sub test()
|
|
1595
|
+
two = 2
|
|
1596
|
+
print \`1\${two}\${3}\n\`
|
|
1597
|
+
print (1 as integer)
|
|
1598
|
+
print SOURCE_LINE_NUM
|
|
1599
|
+
print FUNCTION_NAME
|
|
1600
|
+
print SOURCE_FUNCTION_NAME
|
|
1601
|
+
print PKG_LOCATION
|
|
1602
|
+
print PKG_PATH
|
|
1603
|
+
print LINE_NUM
|
|
1604
|
+
print new Person()
|
|
1605
|
+
m@.someCallfunc()
|
|
1606
|
+
m@.someCallfunc(1, 2)
|
|
1607
|
+
print tag\`stuff\${LINE_NUM}\${LINE_NUM}\`
|
|
1608
|
+
print 1 = 1 ? 1 : 2
|
|
1609
|
+
print 1 = 1 ? m.one : m.two
|
|
1610
|
+
print 1 ?? 2
|
|
1611
|
+
print m.one ?? m.two
|
|
1612
|
+
print /123/gi
|
|
1613
|
+
end sub
|
|
1614
|
+
function tag(param1, param2)
|
|
1615
|
+
end function
|
|
1616
|
+
const a = 1
|
|
1617
|
+
namespace alpha
|
|
1618
|
+
function beta()
|
|
1619
|
+
throw "An error has occurred"
|
|
1620
|
+
end function
|
|
1621
|
+
function charlie()
|
|
1622
|
+
end function
|
|
1623
|
+
end namespace
|
|
1624
|
+
sub test2()
|
|
1625
|
+
' alpha.charlie()
|
|
1626
|
+
end sub
|
|
1627
|
+
|
|
1628
|
+
enum Direction
|
|
1629
|
+
up = "up"
|
|
1630
|
+
end enum
|
|
1631
|
+
|
|
1632
|
+
class Person
|
|
1633
|
+
name as string
|
|
1634
|
+
sub new()
|
|
1635
|
+
print m.name
|
|
1636
|
+
end sub
|
|
1637
|
+
|
|
1638
|
+
sub test()
|
|
1639
|
+
end sub
|
|
1640
|
+
end class
|
|
1641
|
+
|
|
1642
|
+
interface Beta
|
|
1643
|
+
name as string
|
|
1644
|
+
end interface
|
|
1645
|
+
`, `
|
|
1646
|
+
'import "pkg:/source/lib.bs"
|
|
1647
|
+
|
|
1648
|
+
sub test()
|
|
1649
|
+
two = 2
|
|
1650
|
+
print ("1" + bslib_toString(two) + bslib_toString(3) + chr(10))
|
|
1651
|
+
print 1
|
|
1652
|
+
print -1
|
|
1653
|
+
print "test"
|
|
1654
|
+
print "test"
|
|
1655
|
+
print "pkg:/source/main.brs:" + str(LINE_NUM)
|
|
1656
|
+
print "pkg:/source/main.brs"
|
|
1657
|
+
print LINE_NUM
|
|
1658
|
+
print Person()
|
|
1659
|
+
m.callfunc("someCallfunc")
|
|
1660
|
+
m.callfunc("someCallfunc", 1, 2)
|
|
1661
|
+
print tag(["stuff", "", ""], [LINE_NUM, LINE_NUM])
|
|
1662
|
+
print bslib_ternary(1 = 1, 1, 2)
|
|
1663
|
+
print (function(__bsCondition, m)
|
|
1664
|
+
if __bsCondition then
|
|
1665
|
+
return m.one
|
|
1666
|
+
else
|
|
1667
|
+
return m.two
|
|
1668
|
+
end if
|
|
1669
|
+
end function)(1 = 1, m)
|
|
1670
|
+
print bslib_coalesce(1, 2)
|
|
1671
|
+
print (function(m)
|
|
1672
|
+
__bsConsequent = m.one
|
|
1673
|
+
if __bsConsequent <> invalid then
|
|
1674
|
+
return __bsConsequent
|
|
1675
|
+
else
|
|
1676
|
+
return m.two
|
|
1677
|
+
end if
|
|
1678
|
+
end function)(m)
|
|
1679
|
+
print CreateObject("roRegex", "123", "gi")
|
|
1680
|
+
end sub
|
|
1681
|
+
|
|
1682
|
+
function tag(param1, param2)
|
|
1683
|
+
end function
|
|
1684
|
+
|
|
1685
|
+
function alpha_beta()
|
|
1686
|
+
throw "An error has occurred"
|
|
1687
|
+
end function
|
|
1688
|
+
|
|
1689
|
+
function alpha_charlie()
|
|
1690
|
+
end function
|
|
1691
|
+
|
|
1692
|
+
sub test2()
|
|
1693
|
+
' alpha.charlie()
|
|
1694
|
+
end sub
|
|
1695
|
+
|
|
1696
|
+
function __Person_builder()
|
|
1697
|
+
instance = {}
|
|
1698
|
+
instance.new = sub()
|
|
1699
|
+
m.name = invalid
|
|
1700
|
+
print m.name
|
|
1701
|
+
end sub
|
|
1702
|
+
instance.test = sub()
|
|
1703
|
+
end sub
|
|
1704
|
+
return instance
|
|
1705
|
+
end function
|
|
1706
|
+
function Person()
|
|
1707
|
+
instance = __Person_builder()
|
|
1708
|
+
instance.new()
|
|
1709
|
+
return instance
|
|
1710
|
+
end function
|
|
1711
|
+
`);
|
|
1712
|
+
});
|
|
1713
|
+
it('handles source literals properly', () => {
|
|
1714
|
+
const pathUrl = fileUrl(testHelpers_spec_2.rootDir);
|
|
1715
|
+
let text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}`;
|
|
1716
|
+
doTest(`
|
|
1717
|
+
sub test()
|
|
1718
|
+
print SOURCE_FILE_PATH
|
|
1719
|
+
print SOURCE_LOCATION
|
|
1720
|
+
end sub
|
|
1721
|
+
`, `
|
|
1722
|
+
sub test()
|
|
1723
|
+
print ${text}/source/main.bs"
|
|
1724
|
+
print ${text}/source/main.bs:-1"
|
|
1725
|
+
end sub
|
|
1726
|
+
`);
|
|
1727
|
+
});
|
|
1728
|
+
function doTest(source, expected = source) {
|
|
1729
|
+
const file = program.setFile('source/main.bs', '');
|
|
1730
|
+
//override the parser with our locationless parser
|
|
1731
|
+
file['_parser'] = Parser_1.Parser.parse(source, { mode: Parser_1.ParseMode.BrighterScript, trackLocations: false });
|
|
1732
|
+
program.getScopesForFile(file).forEach(x => x['cache'].clear());
|
|
1733
|
+
program.validate();
|
|
1734
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
1735
|
+
const result = file.transpile();
|
|
1736
|
+
(0, chai_config_spec_1.expect)((0, testHelpers_spec_1.trimMap)((0, undent_1.default)(result.code))).to.eql((0, undent_1.default)(expected));
|
|
1737
|
+
}
|
|
1738
|
+
});
|
|
1493
1739
|
it('transpilies libpkg:/ paths when encountered', async () => {
|
|
1494
1740
|
program.setFile('source/lib.bs', `
|
|
1495
1741
|
import "libpkg:/source/numbers.bs"
|
|
@@ -1657,6 +1903,24 @@ describe('BrsFile', () => {
|
|
|
1657
1903
|
end sub
|
|
1658
1904
|
`);
|
|
1659
1905
|
});
|
|
1906
|
+
it('transpiles empty throw with "User-specified exception"', async () => {
|
|
1907
|
+
await testTranspile(`
|
|
1908
|
+
sub main()
|
|
1909
|
+
try
|
|
1910
|
+
throw 'bs:disable-line
|
|
1911
|
+
catch e
|
|
1912
|
+
end try
|
|
1913
|
+
end sub
|
|
1914
|
+
`, `
|
|
1915
|
+
sub main()
|
|
1916
|
+
try
|
|
1917
|
+
throw "User-specified exception"
|
|
1918
|
+
'bs:disable-line
|
|
1919
|
+
catch e
|
|
1920
|
+
end try
|
|
1921
|
+
end sub
|
|
1922
|
+
`);
|
|
1923
|
+
});
|
|
1660
1924
|
});
|
|
1661
1925
|
describe('try/catch', () => {
|
|
1662
1926
|
it('transpiles properly', async () => {
|
|
@@ -1946,6 +2210,7 @@ describe('BrsFile', () => {
|
|
|
1946
2210
|
function DoSomething()
|
|
1947
2211
|
'lots of empty white space
|
|
1948
2212
|
'that will be removed during transpile
|
|
2213
|
+
'since there are newlines below this comment one newline will be preserved
|
|
1949
2214
|
|
|
1950
2215
|
|
|
1951
2216
|
|
|
@@ -1954,6 +2219,8 @@ describe('BrsFile', () => {
|
|
|
1954
2219
|
function DoSomething()
|
|
1955
2220
|
'lots of empty white space
|
|
1956
2221
|
'that will be removed during transpile
|
|
2222
|
+
'since there are newlines below this comment one newline will be preserved
|
|
2223
|
+
|
|
1957
2224
|
end function
|
|
1958
2225
|
`);
|
|
1959
2226
|
});
|
|
@@ -1968,6 +2235,26 @@ describe('BrsFile', () => {
|
|
|
1968
2235
|
it('does not add leading or trailing newlines', async () => {
|
|
1969
2236
|
await testTranspile(`function abc()\nend function`, undefined, 'none');
|
|
1970
2237
|
});
|
|
2238
|
+
it('generates proper sourcemap comment', () => {
|
|
2239
|
+
program.options.sourceMap = true;
|
|
2240
|
+
const file = program.setFile('source/main.bs', `
|
|
2241
|
+
sub main()
|
|
2242
|
+
end sub
|
|
2243
|
+
`);
|
|
2244
|
+
(0, chai_config_spec_1.expect)(file.transpile().code).to.eql((0, undent_1.default) `
|
|
2245
|
+
sub main()
|
|
2246
|
+
end sub
|
|
2247
|
+
'//# sourceMappingURL=./main.brs.map
|
|
2248
|
+
`);
|
|
2249
|
+
});
|
|
2250
|
+
it('includes sourcemap.name property', () => {
|
|
2251
|
+
program.options.sourceMap = true;
|
|
2252
|
+
const file = program.setFile('source/main.bs', `
|
|
2253
|
+
sub main()
|
|
2254
|
+
end sub
|
|
2255
|
+
`);
|
|
2256
|
+
(0, chai_config_spec_1.expect)(file.transpile().map.toJSON().file).to.eql('main.brs');
|
|
2257
|
+
});
|
|
1971
2258
|
it('handles sourcemap edge case', async () => {
|
|
1972
2259
|
let source = 'sub main()\n' +
|
|
1973
2260
|
'\n' +
|
|
@@ -2139,6 +2426,25 @@ describe('BrsFile', () => {
|
|
|
2139
2426
|
end sub
|
|
2140
2427
|
`);
|
|
2141
2428
|
});
|
|
2429
|
+
it('keeps spaces in between comments when a statement ends in a comment ', async () => {
|
|
2430
|
+
await testTranspile(`
|
|
2431
|
+
sub foo()
|
|
2432
|
+
end sub 'comment
|
|
2433
|
+
|
|
2434
|
+
'a function that does something
|
|
2435
|
+
sub foo2()
|
|
2436
|
+
end sub
|
|
2437
|
+
`);
|
|
2438
|
+
});
|
|
2439
|
+
it('keeps comment in correct place in empty function', async () => {
|
|
2440
|
+
await testTranspile(`
|
|
2441
|
+
sub noop1()
|
|
2442
|
+
end sub
|
|
2443
|
+
|
|
2444
|
+
sub noop2() 'comment in empty function
|
|
2445
|
+
end sub
|
|
2446
|
+
`);
|
|
2447
|
+
});
|
|
2142
2448
|
it('works for a complex function with comments all over the place', async () => {
|
|
2143
2449
|
await testTranspile(`
|
|
2144
2450
|
'import some library
|
|
@@ -2330,7 +2636,7 @@ describe('BrsFile', () => {
|
|
|
2330
2636
|
program.setFile('source/main.bs', `
|
|
2331
2637
|
sub test()
|
|
2332
2638
|
someNode = createObject("roSGNode", "Rectangle")
|
|
2333
|
-
someNode@.someFunction(test
|
|
2639
|
+
someNode@.someFunction({test: "value"})
|
|
2334
2640
|
end sub
|
|
2335
2641
|
`);
|
|
2336
2642
|
program.validate();
|
|
@@ -3088,6 +3394,30 @@ describe('BrsFile', () => {
|
|
|
3088
3394
|
'TwoType', 'OneType'
|
|
3089
3395
|
]);
|
|
3090
3396
|
});
|
|
3397
|
+
it('allows built-in types for interface members', () => {
|
|
3398
|
+
program.setFile('source/main.bs', `
|
|
3399
|
+
interface MyBase
|
|
3400
|
+
regex as roRegex
|
|
3401
|
+
node as roSGNodeLabel
|
|
3402
|
+
sub outputMatches(textInput as string)
|
|
3403
|
+
function getLabelParent() as roSGNode
|
|
3404
|
+
end interface
|
|
3405
|
+
`);
|
|
3406
|
+
program.validate();
|
|
3407
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
3408
|
+
});
|
|
3409
|
+
it('allows extends on interfaces', async () => {
|
|
3410
|
+
await testTranspile(`
|
|
3411
|
+
interface MyBase
|
|
3412
|
+
url as string
|
|
3413
|
+
end interface
|
|
3414
|
+
|
|
3415
|
+
interface MyExtends extends MyBase
|
|
3416
|
+
method as string
|
|
3417
|
+
end interface
|
|
3418
|
+
`, `
|
|
3419
|
+
`);
|
|
3420
|
+
});
|
|
3091
3421
|
it('should include unknown param and return types on class methods', () => {
|
|
3092
3422
|
const mainFile = program.setFile('source/main.bs', `
|
|
3093
3423
|
class Klass
|
|
@@ -3714,7 +4044,7 @@ describe('BrsFile', () => {
|
|
|
3714
4044
|
(0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
|
|
3715
4045
|
mainFile = program.setFile('source/main.bs', `
|
|
3716
4046
|
function func1(p as string) as integer
|
|
3717
|
-
return len(p)+1
|
|
4047
|
+
return len(p) + 1
|
|
3718
4048
|
end function
|
|
3719
4049
|
|
|
3720
4050
|
sub displayModelTypeInLabel(myLabel as roSgNodeLabel)
|
|
@@ -3775,11 +4105,10 @@ describe('BrsFile', () => {
|
|
|
3775
4105
|
it('functions in a namespace that have class params show change properly', () => {
|
|
3776
4106
|
const fileContent = `
|
|
3777
4107
|
namespace Alpha.Beta
|
|
3778
|
-
|
|
3779
4108
|
class SomeKlass
|
|
3780
4109
|
name as string
|
|
3781
4110
|
function combineName(klass as SomeKlass)
|
|
3782
|
-
m.name = m.name+klass.name
|
|
4111
|
+
m.name = m.name + klass.name
|
|
3783
4112
|
end function
|
|
3784
4113
|
end class
|
|
3785
4114
|
|
|
@@ -3806,7 +4135,7 @@ describe('BrsFile', () => {
|
|
|
3806
4135
|
aa1 = {
|
|
3807
4136
|
"sprop1": 0,
|
|
3808
4137
|
prop1: 1
|
|
3809
|
-
|
|
4138
|
+
prop2: {
|
|
3810
4139
|
prop3: 2
|
|
3811
4140
|
}
|
|
3812
4141
|
}
|
|
@@ -3840,7 +4169,7 @@ describe('BrsFile', () => {
|
|
|
3840
4169
|
aa1 = {
|
|
3841
4170
|
"constructor": 0,
|
|
3842
4171
|
constructor: 1
|
|
3843
|
-
|
|
4172
|
+
valueOf: {
|
|
3844
4173
|
toString: 2
|
|
3845
4174
|
}
|
|
3846
4175
|
}
|
|
@@ -3854,6 +4183,44 @@ describe('BrsFile', () => {
|
|
|
3854
4183
|
const { propertyHints } = file['_cachedLookups'];
|
|
3855
4184
|
(0, chai_config_spec_1.expect)(Object.keys(propertyHints).sort()).to.deep.equal(expected, 'Initial hints');
|
|
3856
4185
|
});
|
|
4186
|
+
it('allows built-in types for class members', () => {
|
|
4187
|
+
program.setFile('source/main.bs', `
|
|
4188
|
+
class MyBase
|
|
4189
|
+
regex as roRegex
|
|
4190
|
+
node as roSGNodeLabel
|
|
4191
|
+
|
|
4192
|
+
sub outputMatches(textInput as string)
|
|
4193
|
+
matches = m.regex.match(textInput)
|
|
4194
|
+
if matches.count() > 1
|
|
4195
|
+
m.node.text = matches[1]
|
|
4196
|
+
else
|
|
4197
|
+
m.node.text = "no match"
|
|
4198
|
+
end if
|
|
4199
|
+
end sub
|
|
4200
|
+
|
|
4201
|
+
function getLabelParent() as roSGNode
|
|
4202
|
+
return m.node.getParent()
|
|
4203
|
+
end function
|
|
4204
|
+
end class
|
|
4205
|
+
`);
|
|
4206
|
+
program.validate();
|
|
4207
|
+
(0, testHelpers_spec_1.expectZeroDiagnostics)(program);
|
|
4208
|
+
});
|
|
4209
|
+
it('allows types on lhs of assignments', async () => {
|
|
4210
|
+
await testTranspile(`
|
|
4211
|
+
sub foo(node as roSGNode)
|
|
4212
|
+
nodeParent as roSGNode = node.getParent()
|
|
4213
|
+
text as string = nodeParent.id
|
|
4214
|
+
print text
|
|
4215
|
+
end sub
|
|
4216
|
+
`, `
|
|
4217
|
+
sub foo(node as dynamic)
|
|
4218
|
+
nodeParent = node.getParent()
|
|
4219
|
+
text = nodeParent.id
|
|
4220
|
+
print text
|
|
4221
|
+
end sub
|
|
4222
|
+
`);
|
|
4223
|
+
});
|
|
3857
4224
|
});
|
|
3858
4225
|
});
|
|
3859
4226
|
//# sourceMappingURL=BrsFile.spec.js.map
|