brighterscript 1.0.0-alpha.27 → 1.0.0-alpha.29

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.
Files changed (168) hide show
  1. package/CHANGELOG.md +71 -0
  2. package/README.md +1 -1
  3. package/dist/AstValidationSegmenter.d.ts +12 -2
  4. package/dist/AstValidationSegmenter.js +74 -16
  5. package/dist/AstValidationSegmenter.js.map +1 -1
  6. package/dist/DependencyGraph.d.ts +4 -0
  7. package/dist/DependencyGraph.js +19 -0
  8. package/dist/DependencyGraph.js.map +1 -1
  9. package/dist/DiagnosticFilterer.d.ts +7 -4
  10. package/dist/DiagnosticFilterer.js +67 -37
  11. package/dist/DiagnosticFilterer.js.map +1 -1
  12. package/dist/DiagnosticMessages.d.ts +1 -1
  13. package/dist/PluginInterface.js +1 -1
  14. package/dist/PluginInterface.js.map +1 -1
  15. package/dist/Program.d.ts +19 -15
  16. package/dist/Program.js +153 -88
  17. package/dist/Program.js.map +1 -1
  18. package/dist/Scope.d.ts +27 -28
  19. package/dist/Scope.js +174 -361
  20. package/dist/Scope.js.map +1 -1
  21. package/dist/Stopwatch.d.ts +4 -0
  22. package/dist/Stopwatch.js +7 -0
  23. package/dist/Stopwatch.js.map +1 -1
  24. package/dist/SymbolTable.d.ts +2 -1
  25. package/dist/SymbolTable.js +26 -0
  26. package/dist/SymbolTable.js.map +1 -1
  27. package/dist/{SymbolTableFlag.js → SymbolTypeFlag.js} +1 -1
  28. package/dist/SymbolTypeFlag.js.map +1 -0
  29. package/dist/XmlScope.d.ts +0 -8
  30. package/dist/XmlScope.js +0 -77
  31. package/dist/XmlScope.js.map +1 -1
  32. package/dist/astUtils/CachedLookups.js +4 -8
  33. package/dist/astUtils/CachedLookups.js.map +1 -1
  34. package/dist/astUtils/creators.d.ts +1 -0
  35. package/dist/astUtils/creators.js +3 -2
  36. package/dist/astUtils/creators.js.map +1 -1
  37. package/dist/astUtils/creators.spec.js +0 -10
  38. package/dist/astUtils/creators.spec.js.map +1 -1
  39. package/dist/astUtils/reflection.d.ts +4 -4
  40. package/dist/astUtils/reflection.js +8 -7
  41. package/dist/astUtils/reflection.js.map +1 -1
  42. package/dist/astUtils/reflection.spec.js +10 -15
  43. package/dist/astUtils/reflection.spec.js.map +1 -1
  44. package/dist/astUtils/visitors.d.ts +1 -2
  45. package/dist/astUtils/visitors.js.map +1 -1
  46. package/dist/astUtils/visitors.spec.js +1 -5
  47. package/dist/astUtils/visitors.spec.js.map +1 -1
  48. package/dist/bscPlugin/BscPlugin.d.ts +3 -1
  49. package/dist/bscPlugin/BscPlugin.js +10 -0
  50. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  51. package/dist/bscPlugin/SignatureHelpUtil.js +4 -3
  52. package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -1
  53. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +1 -0
  54. package/dist/bscPlugin/completions/CompletionsProcessor.js +31 -11
  55. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
  56. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +39 -0
  57. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -1
  58. package/dist/bscPlugin/hover/HoverProcessor.js +5 -5
  59. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
  60. package/dist/bscPlugin/hover/HoverProcessor.spec.js +51 -5
  61. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
  62. package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
  63. package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
  64. package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
  65. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
  66. package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
  67. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
  68. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +1 -1
  69. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -1
  70. package/dist/bscPlugin/validation/BrsFileAfterValidatior.d.ts +7 -0
  71. package/dist/bscPlugin/validation/BrsFileAfterValidatior.js +18 -0
  72. package/dist/bscPlugin/validation/BrsFileAfterValidatior.js.map +1 -0
  73. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +1 -0
  74. package/dist/bscPlugin/validation/BrsFileValidator.js +17 -10
  75. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  76. package/dist/bscPlugin/validation/ScopeValidator.d.ts +37 -1
  77. package/dist/bscPlugin/validation/ScopeValidator.js +434 -25
  78. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  79. package/dist/bscPlugin/validation/ScopeValidator.spec.js +91 -4
  80. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -1
  81. package/dist/files/BrsFile.Class.spec.js +11 -4
  82. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  83. package/dist/files/BrsFile.d.ts +23 -5
  84. package/dist/files/BrsFile.js +189 -51
  85. package/dist/files/BrsFile.js.map +1 -1
  86. package/dist/files/BrsFile.spec.js +589 -97
  87. package/dist/files/BrsFile.spec.js.map +1 -1
  88. package/dist/files/BscFile.d.ts +2 -1
  89. package/dist/files/BscFile.js.map +1 -1
  90. package/dist/files/XmlFile.d.ts +2 -2
  91. package/dist/files/XmlFile.js +2 -2
  92. package/dist/files/XmlFile.js.map +1 -1
  93. package/dist/index.d.ts +1 -0
  94. package/dist/index.js +1 -0
  95. package/dist/index.js.map +1 -1
  96. package/dist/interfaces.d.ts +43 -4
  97. package/dist/interfaces.js.map +1 -1
  98. package/dist/lexer/Lexer.d.ts +9 -3
  99. package/dist/lexer/Lexer.js +36 -15
  100. package/dist/lexer/Lexer.js.map +1 -1
  101. package/dist/lexer/Lexer.spec.js +76 -38
  102. package/dist/lexer/Lexer.spec.js.map +1 -1
  103. package/dist/lexer/Token.js +1 -1
  104. package/dist/lexer/Token.js.map +1 -1
  105. package/dist/lexer/TokenKind.d.ts +1 -0
  106. package/dist/lexer/TokenKind.js +4 -1
  107. package/dist/lexer/TokenKind.js.map +1 -1
  108. package/dist/parser/AstNode.d.ts +1 -2
  109. package/dist/parser/AstNode.js +0 -1
  110. package/dist/parser/AstNode.js.map +1 -1
  111. package/dist/parser/BrsTranspileState.d.ts +1 -1
  112. package/dist/parser/Expression.d.ts +77 -47
  113. package/dist/parser/Expression.js +162 -88
  114. package/dist/parser/Expression.js.map +1 -1
  115. package/dist/parser/Parser.d.ts +7 -2
  116. package/dist/parser/Parser.js +40 -90
  117. package/dist/parser/Parser.js.map +1 -1
  118. package/dist/parser/Parser.spec.js +21 -44
  119. package/dist/parser/Parser.spec.js.map +1 -1
  120. package/dist/parser/SGTypes.js +5 -5
  121. package/dist/parser/SGTypes.js.map +1 -1
  122. package/dist/parser/Statement.d.ts +92 -84
  123. package/dist/parser/Statement.js +199 -133
  124. package/dist/parser/Statement.js.map +1 -1
  125. package/dist/parser/Statement.spec.js +0 -13
  126. package/dist/parser/Statement.spec.js.map +1 -1
  127. package/dist/parser/TranspileState.d.ts +17 -8
  128. package/dist/parser/TranspileState.js +67 -8
  129. package/dist/parser/TranspileState.js.map +1 -1
  130. package/dist/parser/tests/Parser.spec.d.ts +1 -1
  131. package/dist/parser/tests/Parser.spec.js +1 -2
  132. package/dist/parser/tests/Parser.spec.js.map +1 -1
  133. package/dist/parser/tests/controlFlow/If.spec.js +1 -1
  134. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  135. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +1 -3
  136. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  137. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +44 -0
  138. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  139. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +6 -6
  140. package/dist/parser/tests/expression/TernaryExpression.spec.js +47 -0
  141. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  142. package/dist/parser/tests/statement/ConstStatement.spec.js +2 -2
  143. package/dist/parser/tests/statement/InterfaceStatement.spec.js +8 -1
  144. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
  145. package/dist/parser/tests/statement/Misc.spec.js +25 -5
  146. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  147. package/dist/preprocessor/Chunk.js +1 -2
  148. package/dist/preprocessor/Chunk.js.map +1 -1
  149. package/dist/preprocessor/PreprocessorParser.js +2 -1
  150. package/dist/preprocessor/PreprocessorParser.js.map +1 -1
  151. package/dist/types/AssociativeArrayType.d.ts +3 -0
  152. package/dist/types/AssociativeArrayType.js +9 -0
  153. package/dist/types/AssociativeArrayType.js.map +1 -1
  154. package/dist/types/BscType.d.ts +1 -1
  155. package/dist/types/BscType.js +1 -0
  156. package/dist/types/BscType.js.map +1 -1
  157. package/dist/types/ComponentType.d.ts +1 -1
  158. package/dist/types/ReferenceType.d.ts +9 -1
  159. package/dist/types/ReferenceType.js +45 -1
  160. package/dist/types/ReferenceType.js.map +1 -1
  161. package/dist/types/ReferenceType.spec.js +15 -0
  162. package/dist/types/ReferenceType.spec.js.map +1 -1
  163. package/dist/util.d.ts +23 -9
  164. package/dist/util.js +115 -21
  165. package/dist/util.js.map +1 -1
  166. package/package.json +6 -3
  167. package/dist/SymbolTableFlag.js.map +0 -1
  168. /package/dist/{SymbolTableFlag.d.ts → SymbolTypeFlag.d.ts} +0 -0
@@ -23,6 +23,8 @@ 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");
27
+ const reflection_1 = require("../astUtils/reflection");
26
28
  let sinon = sinonImport.createSandbox();
27
29
  describe('BrsFile', () => {
28
30
  let program;
@@ -31,6 +33,14 @@ describe('BrsFile', () => {
31
33
  let file;
32
34
  let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, testHelpers_spec_2.rootDir]);
33
35
  let testGetTypedef = (0, testHelpers_spec_1.getTestGetTypedef)(() => [program, testHelpers_spec_2.rootDir]);
36
+ function validateFile(...files) {
37
+ for (const file of files) {
38
+ program.plugins.emit('onFileValidate', { program: program, file: file });
39
+ }
40
+ for (const file of files) {
41
+ program.plugins.emit('afterFileValidate', { program: program, file: file });
42
+ }
43
+ }
34
44
  beforeEach(() => {
35
45
  fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
36
46
  program = new Program_1.Program({ rootDir: testHelpers_spec_2.rootDir, sourceMap: true });
@@ -505,6 +515,27 @@ describe('BrsFile', () => {
505
515
  (0, testHelpers_spec_1.expectZeroDiagnostics)(file);
506
516
  });
507
517
  describe('conditional compile', () => {
518
+ it('supports whitespace-separated directives', async () => {
519
+ const file = program.setFile('source/main.bs', `
520
+ sub main()
521
+ #\t const thing=true
522
+ #\t if thing
523
+ print "if"
524
+ #\t elseif false
525
+ print "elseif"
526
+ #\t error crash
527
+ #\t else
528
+ print "else"
529
+ #\t endif
530
+ end sub
531
+ `);
532
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
533
+ await testTranspile(file.fileContents, `
534
+ sub main()
535
+ print "if"
536
+ end sub
537
+ `);
538
+ });
508
539
  it('supports case-insensitive bs_const variables', () => {
509
540
  fsExtra.outputFileSync(`${testHelpers_spec_2.rootDir}/manifest`, (0, undent_1.default) `
510
541
  bs_const=SomeKey=true
@@ -1490,6 +1521,245 @@ describe('BrsFile', () => {
1490
1521
  //this test will throw an exception if something went wrong
1491
1522
  });
1492
1523
  describe('transpile', () => {
1524
+ it('does not crash when AA is missing closing curly token', async () => {
1525
+ const file = program.setFile('source/main.bs', `
1526
+ sub main()
1527
+ aa = {}
1528
+ end sub
1529
+ `);
1530
+ //delete the ending token `}`
1531
+ const aa = file.ast.findChild(reflection_1.isAALiteralExpression);
1532
+ delete aa.tokens.close;
1533
+ await testTranspile(file, `
1534
+ sub main()
1535
+ aa = {}
1536
+ end sub
1537
+ `, undefined, undefined, false);
1538
+ });
1539
+ describe('null tokens', () => {
1540
+ it('succeeds when token locations are omitted', () => {
1541
+ doTest(`
1542
+ library "something" 'comment before func
1543
+ sub main(arg0, arg1 as string, arg2 = invalid)
1544
+ 'comment
1545
+ aa = {
1546
+ 'comment
1547
+ one: 1
1548
+ "two": 2
1549
+ }
1550
+ arr = [
1551
+ 'comment
1552
+ 1
1553
+ 'comment
1554
+ 2
1555
+ ]
1556
+ val = + m.val
1557
+ print "hello"
1558
+ 'comment after print
1559
+ num = 1
1560
+ num++
1561
+ num += 2
1562
+ num = +num
1563
+ test(num)
1564
+ for i = 0 to 10 step 1
1565
+ exit for
1566
+ end for
1567
+ while true
1568
+ exit while
1569
+ end while
1570
+ if true then
1571
+ print 1
1572
+ else if true
1573
+ print 1
1574
+ else
1575
+ print 1
1576
+ end if
1577
+ dim thing[1, 2]
1578
+ label1:
1579
+ goto label1
1580
+ end
1581
+ stop
1582
+ stuff = [
1583
+ 1
1584
+ 2
1585
+ 3
1586
+ ]
1587
+ for each item in stuff
1588
+ print item
1589
+ end for
1590
+ m.thing = 1
1591
+ m.thing += 1
1592
+ m[1] = 1
1593
+ m[1] += 1
1594
+ m[1, 2] = 2
1595
+ try
1596
+ print m.b.c
1597
+ catch e
1598
+ print e
1599
+ end try
1600
+ throw "crash"
1601
+ for i = 0 to 10
1602
+ continue
1603
+ end for
1604
+ print m@name
1605
+ print (1 + 2)
1606
+ end sub
1607
+
1608
+ sub test(p1)
1609
+ return p1
1610
+ end sub
1611
+ `);
1612
+ });
1613
+ it('works for bs content', () => {
1614
+ program.setFile('source/lib.bs', ``);
1615
+ doTest(`
1616
+ import "pkg:/source/lib.bs"
1617
+ @annotation()
1618
+ sub test()
1619
+ two = 2
1620
+ print \`1\${two}\${3}\n\`
1621
+ print (1 as integer)
1622
+ print SOURCE_LINE_NUM
1623
+ print FUNCTION_NAME
1624
+ print SOURCE_FUNCTION_NAME
1625
+ print PKG_LOCATION
1626
+ print PKG_PATH
1627
+ print LINE_NUM
1628
+ print new Person()
1629
+ m@.someCallfunc()
1630
+ m@.someCallfunc(1, 2)
1631
+ print tag\`stuff\${LINE_NUM}\${LINE_NUM}\`
1632
+ print 1 = 1 ? 1 : 2
1633
+ print 1 = 1 ? m.one : m.two
1634
+ print 1 ?? 2
1635
+ print m.one ?? m.two
1636
+ print /123/gi
1637
+ end sub
1638
+ function tag(param1, param2)
1639
+ end function
1640
+ const a = 1
1641
+ namespace alpha
1642
+ function beta()
1643
+ throw "An error has occurred"
1644
+ end function
1645
+ function charlie()
1646
+ end function
1647
+ end namespace
1648
+ sub test2()
1649
+ ' alpha.charlie()
1650
+ end sub
1651
+
1652
+ enum Direction
1653
+ up = "up"
1654
+ end enum
1655
+
1656
+ class Person
1657
+ name as string
1658
+ sub new()
1659
+ print m.name
1660
+ end sub
1661
+
1662
+ sub test()
1663
+ end sub
1664
+ end class
1665
+
1666
+ interface Beta
1667
+ name as string
1668
+ end interface
1669
+ `, `
1670
+ 'import "pkg:/source/lib.bs"
1671
+
1672
+ sub test()
1673
+ two = 2
1674
+ print ("1" + bslib_toString(two) + bslib_toString(3) + chr(10))
1675
+ print 1
1676
+ print -1
1677
+ print "test"
1678
+ print "test"
1679
+ print "pkg:/source/main.brs:" + str(LINE_NUM)
1680
+ print "pkg:/source/main.brs"
1681
+ print LINE_NUM
1682
+ print Person()
1683
+ m.callfunc("someCallfunc")
1684
+ m.callfunc("someCallfunc", 1, 2)
1685
+ print tag(["stuff", "", ""], [LINE_NUM, LINE_NUM])
1686
+ print bslib_ternary(1 = 1, 1, 2)
1687
+ print (function(__bsCondition, m)
1688
+ if __bsCondition then
1689
+ return m.one
1690
+ else
1691
+ return m.two
1692
+ end if
1693
+ end function)(1 = 1, m)
1694
+ print bslib_coalesce(1, 2)
1695
+ print (function(m)
1696
+ __bsConsequent = m.one
1697
+ if __bsConsequent <> invalid then
1698
+ return __bsConsequent
1699
+ else
1700
+ return m.two
1701
+ end if
1702
+ end function)(m)
1703
+ print CreateObject("roRegex", "123", "gi")
1704
+ end sub
1705
+
1706
+ function tag(param1, param2)
1707
+ end function
1708
+
1709
+ function alpha_beta()
1710
+ throw "An error has occurred"
1711
+ end function
1712
+
1713
+ function alpha_charlie()
1714
+ end function
1715
+
1716
+ sub test2()
1717
+ ' alpha.charlie()
1718
+ end sub
1719
+
1720
+ function __Person_builder()
1721
+ instance = {}
1722
+ instance.new = sub()
1723
+ m.name = invalid
1724
+ print m.name
1725
+ end sub
1726
+ instance.test = sub()
1727
+ end sub
1728
+ return instance
1729
+ end function
1730
+ function Person()
1731
+ instance = __Person_builder()
1732
+ instance.new()
1733
+ return instance
1734
+ end function
1735
+ `);
1736
+ });
1737
+ it('handles source literals properly', () => {
1738
+ const pathUrl = fileUrl(testHelpers_spec_2.rootDir);
1739
+ let text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}`;
1740
+ doTest(`
1741
+ sub test()
1742
+ print SOURCE_FILE_PATH
1743
+ print SOURCE_LOCATION
1744
+ end sub
1745
+ `, `
1746
+ sub test()
1747
+ print ${text}/source/main.bs"
1748
+ print ${text}/source/main.bs:-1"
1749
+ end sub
1750
+ `);
1751
+ });
1752
+ function doTest(source, expected = source) {
1753
+ const file = program.setFile('source/main.bs', '');
1754
+ //override the parser with our locationless parser
1755
+ file['_parser'] = Parser_1.Parser.parse(source, { mode: Parser_1.ParseMode.BrighterScript, trackLocations: false });
1756
+ program.getScopesForFile(file).forEach(x => x['cache'].clear());
1757
+ program.validate();
1758
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1759
+ const result = file.transpile();
1760
+ (0, chai_config_spec_1.expect)((0, testHelpers_spec_1.trimMap)((0, undent_1.default)(result.code))).to.eql((0, undent_1.default)(expected));
1761
+ }
1762
+ });
1493
1763
  it('transpilies libpkg:/ paths when encountered', async () => {
1494
1764
  program.setFile('source/lib.bs', `
1495
1765
  import "libpkg:/source/numbers.bs"
@@ -1657,6 +1927,24 @@ describe('BrsFile', () => {
1657
1927
  end sub
1658
1928
  `);
1659
1929
  });
1930
+ it('transpiles empty throw with "User-specified exception"', async () => {
1931
+ await testTranspile(`
1932
+ sub main()
1933
+ try
1934
+ throw 'bs:disable-line
1935
+ catch e
1936
+ end try
1937
+ end sub
1938
+ `, `
1939
+ sub main()
1940
+ try
1941
+ throw "User-specified exception"
1942
+ 'bs:disable-line
1943
+ catch e
1944
+ end try
1945
+ end sub
1946
+ `);
1947
+ });
1660
1948
  });
1661
1949
  describe('try/catch', () => {
1662
1950
  it('transpiles properly', async () => {
@@ -1946,6 +2234,7 @@ describe('BrsFile', () => {
1946
2234
  function DoSomething()
1947
2235
  'lots of empty white space
1948
2236
  'that will be removed during transpile
2237
+ 'since there are newlines below this comment one newline will be preserved
1949
2238
 
1950
2239
 
1951
2240
 
@@ -1954,6 +2243,8 @@ describe('BrsFile', () => {
1954
2243
  function DoSomething()
1955
2244
  'lots of empty white space
1956
2245
  'that will be removed during transpile
2246
+ 'since there are newlines below this comment one newline will be preserved
2247
+
1957
2248
  end function
1958
2249
  `);
1959
2250
  });
@@ -1968,6 +2259,26 @@ describe('BrsFile', () => {
1968
2259
  it('does not add leading or trailing newlines', async () => {
1969
2260
  await testTranspile(`function abc()\nend function`, undefined, 'none');
1970
2261
  });
2262
+ it('generates proper sourcemap comment', () => {
2263
+ program.options.sourceMap = true;
2264
+ const file = program.setFile('source/main.bs', `
2265
+ sub main()
2266
+ end sub
2267
+ `);
2268
+ (0, chai_config_spec_1.expect)(file.transpile().code).to.eql((0, undent_1.default) `
2269
+ sub main()
2270
+ end sub
2271
+ '//# sourceMappingURL=./main.brs.map
2272
+ `);
2273
+ });
2274
+ it('includes sourcemap.name property', () => {
2275
+ program.options.sourceMap = true;
2276
+ const file = program.setFile('source/main.bs', `
2277
+ sub main()
2278
+ end sub
2279
+ `);
2280
+ (0, chai_config_spec_1.expect)(file.transpile().map.toJSON().file).to.eql('main.brs');
2281
+ });
1971
2282
  it('handles sourcemap edge case', async () => {
1972
2283
  let source = 'sub main()\n' +
1973
2284
  '\n' +
@@ -2139,6 +2450,25 @@ describe('BrsFile', () => {
2139
2450
  end sub
2140
2451
  `);
2141
2452
  });
2453
+ it('keeps spaces in between comments when a statement ends in a comment ', async () => {
2454
+ await testTranspile(`
2455
+ sub foo()
2456
+ end sub 'comment
2457
+
2458
+ 'a function that does something
2459
+ sub foo2()
2460
+ end sub
2461
+ `);
2462
+ });
2463
+ it('keeps comment in correct place in empty function', async () => {
2464
+ await testTranspile(`
2465
+ sub noop1()
2466
+ end sub
2467
+
2468
+ sub noop2() 'comment in empty function
2469
+ end sub
2470
+ `);
2471
+ });
2142
2472
  it('works for a complex function with comments all over the place', async () => {
2143
2473
  await testTranspile(`
2144
2474
  'import some library
@@ -2330,7 +2660,7 @@ describe('BrsFile', () => {
2330
2660
  program.setFile('source/main.bs', `
2331
2661
  sub test()
2332
2662
  someNode = createObject("roSGNode", "Rectangle")
2333
- someNode@.someFunction(test.value)
2663
+ someNode@.someFunction({test: "value"})
2334
2664
  end sub
2335
2665
  `);
2336
2666
  program.validate();
@@ -3078,16 +3408,36 @@ describe('BrsFile', () => {
3078
3408
  return arg.getTwo()
3079
3409
  end function
3080
3410
  `);
3081
- const validateFileEvent = {
3082
- program: program,
3083
- file: mainFile
3084
- };
3085
- program.plugins.emit('onFileValidate', validateFileEvent);
3411
+ validateFile(mainFile);
3086
3412
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(2);
3087
3413
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.map(x => x.typeChain[0].name)).to.have.same.members([
3088
3414
  'TwoType', 'OneType'
3089
3415
  ]);
3090
3416
  });
3417
+ it('allows built-in types for interface members', () => {
3418
+ program.setFile('source/main.bs', `
3419
+ interface MyBase
3420
+ regex as roRegex
3421
+ node as roSGNodeLabel
3422
+ sub outputMatches(textInput as string)
3423
+ function getLabelParent() as roSGNode
3424
+ end interface
3425
+ `);
3426
+ program.validate();
3427
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
3428
+ });
3429
+ it('allows extends on interfaces', async () => {
3430
+ await testTranspile(`
3431
+ interface MyBase
3432
+ url as string
3433
+ end interface
3434
+
3435
+ interface MyExtends extends MyBase
3436
+ method as string
3437
+ end interface
3438
+ `, `
3439
+ `);
3440
+ });
3091
3441
  it('should include unknown param and return types on class methods', () => {
3092
3442
  const mainFile = program.setFile('source/main.bs', `
3093
3443
  class Klass
@@ -3096,11 +3446,7 @@ describe('BrsFile', () => {
3096
3446
  end function
3097
3447
  end class
3098
3448
  `);
3099
- const validateFileEvent = {
3100
- program: program,
3101
- file: mainFile
3102
- };
3103
- program.plugins.emit('onFileValidate', validateFileEvent);
3449
+ validateFile(mainFile);
3104
3450
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(2);
3105
3451
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.map(x => x.typeChain[0].name)).to.have.same.members([
3106
3452
  'TwoType', 'OneType'
@@ -3113,11 +3459,7 @@ describe('BrsFile', () => {
3113
3459
  print x+1
3114
3460
  end sub
3115
3461
  `);
3116
- const validateFileEvent = {
3117
- program: program,
3118
- file: mainFile
3119
- };
3120
- program.plugins.emit('onFileValidate', validateFileEvent);
3462
+ validateFile(mainFile);
3121
3463
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(1);
3122
3464
  // x and arg are assigned.. they are not included in the required symbols
3123
3465
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols[0].typeChain[0].name).to.equal('SomeOtherType');
@@ -3136,11 +3478,7 @@ describe('BrsFile', () => {
3136
3478
  return y-otherFileFunc4()
3137
3479
  end function
3138
3480
  `);
3139
- const validateFileEvent = {
3140
- program: program,
3141
- file: mainFile
3142
- };
3143
- program.plugins.emit('onFileValidate', validateFileEvent);
3481
+ validateFile(mainFile);
3144
3482
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(4);
3145
3483
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.map(x => x.typeChain[0].name)).to.have.same.members([
3146
3484
  'otherFileFunc1', 'otherFileFunc2', 'otherFileFunc3', 'otherFileFunc4'
@@ -3153,11 +3491,7 @@ describe('BrsFile', () => {
3153
3491
  return other.getThing(x)
3154
3492
  end function
3155
3493
  `);
3156
- const validateFileEvent = {
3157
- program: program,
3158
- file: mainFile
3159
- };
3160
- program.plugins.emit('onFileValidate', validateFileEvent);
3494
+ validateFile(mainFile);
3161
3495
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(3);
3162
3496
  const requiredTypeChains = mainFile.requiredSymbols.map(x => x.typeChain.map(tc => tc.name).join('.'));
3163
3497
  (0, chai_config_spec_1.expect)(requiredTypeChains).to.have.same.members([
@@ -3180,11 +3514,7 @@ describe('BrsFile', () => {
3180
3514
  end if
3181
3515
  end sub
3182
3516
  `);
3183
- const validateFileEvent = {
3184
- program: program,
3185
- file: mainFile
3186
- };
3187
- program.plugins.emit('onFileValidate', validateFileEvent);
3517
+ validateFile(mainFile);
3188
3518
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(4);
3189
3519
  const requiredTypeChains = mainFile.requiredSymbols.map(x => x.typeChain.map(tc => tc.name).join('.'));
3190
3520
  (0, chai_config_spec_1.expect)(requiredTypeChains).to.have.same.members([
@@ -3210,11 +3540,7 @@ describe('BrsFile', () => {
3210
3540
  end function
3211
3541
  end class
3212
3542
  `);
3213
- const validateFileEvent = {
3214
- program: program,
3215
- file: mainFile
3216
- };
3217
- program.plugins.emit('onFileValidate', validateFileEvent);
3543
+ validateFile(mainFile);
3218
3544
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(5);
3219
3545
  const requiredTypeChains = mainFile.requiredSymbols.map(x => x.typeChain.map(tc => tc.name).join('.'));
3220
3546
  (0, chai_config_spec_1.expect)(requiredTypeChains).to.have.same.members([
@@ -3243,11 +3569,7 @@ describe('BrsFile', () => {
3243
3569
  end namespace
3244
3570
  end namespace
3245
3571
  `);
3246
- const validateFileEvent = {
3247
- program: program,
3248
- file: mainFile
3249
- };
3250
- program.plugins.emit('onFileValidate', validateFileEvent);
3572
+ validateFile(mainFile);
3251
3573
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(2);
3252
3574
  const requiredTypeChains = mainFile.requiredSymbols.map(x => x.typeChain.map(tc => tc.name).join('.'));
3253
3575
  (0, chai_config_spec_1.expect)(requiredTypeChains).to.have.same.members([
@@ -3268,7 +3590,7 @@ describe('BrsFile', () => {
3268
3590
  end namespace
3269
3591
  end namespace
3270
3592
  `);
3271
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3593
+ validateFile(mainFile);
3272
3594
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
3273
3595
  });
3274
3596
  it('should put types from typecasts as typetime required', () => {
@@ -3277,10 +3599,104 @@ describe('BrsFile', () => {
3277
3599
  return (z as MyInterface).name
3278
3600
  end function
3279
3601
  `);
3280
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3602
+ validateFile(mainFile);
3281
3603
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(1);
3282
3604
  (0, chai_config_spec_1.expect)(mainFile.requiredSymbols[0].flags).to.eq(2 /* SymbolTypeFlag.typetime */);
3283
3605
  });
3606
+ it('should not include symbols in same namespace', () => {
3607
+ const mainFile = program.setFile('source/main.bs', `
3608
+ namespace alpha
3609
+ const PI = 3.14
3610
+ function area(r as float) as float
3611
+ return alpha.PI * r * r
3612
+ end function
3613
+ end namespace
3614
+ `);
3615
+ validateFile(mainFile);
3616
+ (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
3617
+ });
3618
+ it('should not include symbols in same namespace, but different statements', () => {
3619
+ const mainFile = program.setFile('source/main.bs', `
3620
+ namespace alpha
3621
+ function area(r as float) as float
3622
+ return alpha.PI * r * r
3623
+ end function
3624
+ end namespace
3625
+
3626
+ namespace alpha
3627
+ const PI = 3.14
3628
+ end namespace
3629
+ `);
3630
+ validateFile(mainFile);
3631
+ (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
3632
+ });
3633
+ it('should not include symbols in imported file', () => {
3634
+ const otherFile = program.setFile('source/other.bs', `
3635
+ namespace alpha
3636
+ const PI = 3.14
3637
+ end namespace
3638
+ `);
3639
+ const mainFile = program.setFile('source/main.bs', `
3640
+ import "pkg:/source/other.bs"
3641
+ namespace alpha
3642
+ function area(r as float) as float
3643
+ return alpha.PI * r * r
3644
+ end function
3645
+ end namespace
3646
+ `);
3647
+ validateFile(otherFile, mainFile);
3648
+ (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
3649
+ });
3650
+ it('should not include symbols in imported file of imported file', () => {
3651
+ const deepFile = program.setFile('source/deep.bs', `
3652
+ namespace alpha
3653
+ const SOME_VALUE = 2
3654
+ end namespace
3655
+ `);
3656
+ const otherFile = program.setFile('source/other.bs', `
3657
+ import "pkg:/source/deep.bs"
3658
+ namespace alpha
3659
+ const PI = 3.14
3660
+ end namespace
3661
+ `);
3662
+ const mainFile = program.setFile('source/main.bs', `
3663
+ import "pkg:/source/other.bs"
3664
+ namespace alpha
3665
+ function area(r as float) as float
3666
+ return alpha.PI * r * r * alpha.SOME_VALUE
3667
+ end function
3668
+ end namespace
3669
+ `);
3670
+ validateFile(otherFile, mainFile, deepFile);
3671
+ (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
3672
+ });
3673
+ it('should not have problems with circular references of imports', () => {
3674
+ const deepFile = program.setFile('source/deep.bs', `
3675
+ import "pkg:/source/main.bs"
3676
+ namespace alpha
3677
+ function getMyValue()
3678
+ return alpha.MY_VALUE
3679
+ end function
3680
+ end namespace
3681
+ `);
3682
+ const otherFile = program.setFile('source/other.bs', `
3683
+ import "pkg:/source/deep.bs"
3684
+ namespace alpha
3685
+ const PI = 3.14
3686
+ end namespace
3687
+ `);
3688
+ const mainFile = program.setFile('source/main.bs', `
3689
+ import "pkg:/source/other.bs"
3690
+ namespace alpha
3691
+ function area(r as float) as float
3692
+ return alpha.PI * r * r * alpha.getMyValue()
3693
+ end function
3694
+ const MY_VALUE = 2
3695
+ end namespace
3696
+ `);
3697
+ validateFile(otherFile, mainFile, deepFile);
3698
+ (0, chai_config_spec_1.expect)(mainFile.requiredSymbols.length).to.eq(0);
3699
+ });
3284
3700
  });
3285
3701
  describe('providedSymbols', () => {
3286
3702
  it('includes functions defined in the file', () => {
@@ -3293,11 +3709,7 @@ describe('BrsFile', () => {
3293
3709
  return 2.3
3294
3710
  end function
3295
3711
  `);
3296
- const validateFileEvent = {
3297
- program: program,
3298
- file: mainFile
3299
- };
3300
- program.plugins.emit('onFileValidate', validateFileEvent);
3712
+ validateFile(mainFile);
3301
3713
  const runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3302
3714
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
3303
3715
  const someFuncType = runtimeSymbols.get('somefunc').type;
@@ -3311,11 +3723,7 @@ describe('BrsFile', () => {
3311
3723
  return new OtherFileType()
3312
3724
  end function
3313
3725
  `);
3314
- const validateFileEvent = {
3315
- program: program,
3316
- file: mainFile
3317
- };
3318
- program.plugins.emit('onFileValidate', validateFileEvent);
3726
+ validateFile(mainFile);
3319
3727
  const runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3320
3728
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3321
3729
  const someFuncType = runtimeSymbols.get('somefunc').type;
@@ -3343,11 +3751,7 @@ describe('BrsFile', () => {
3343
3751
  propClass = new Klass2()
3344
3752
  end class
3345
3753
  `);
3346
- const validateFileEvent = {
3347
- program: program,
3348
- file: mainFile
3349
- };
3350
- program.plugins.emit('onFileValidate', validateFileEvent);
3754
+ validateFile(mainFile);
3351
3755
  const runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3352
3756
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(3);
3353
3757
  (0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('klass').type, types_1.ClassType);
@@ -3374,11 +3778,7 @@ describe('BrsFile', () => {
3374
3778
  const MyConst = 3.14
3375
3779
  end namespace
3376
3780
  `);
3377
- const validateFileEvent = {
3378
- program: program,
3379
- file: mainFile
3380
- };
3381
- program.plugins.emit('onFileValidate', validateFileEvent);
3781
+ validateFile(mainFile);
3382
3782
  const runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3383
3783
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
3384
3784
  (0, testHelpers_spec_1.expectTypeToBe)(runtimeSymbols.get('myenum').type, types_1.EnumType);
@@ -3395,7 +3795,7 @@ describe('BrsFile', () => {
3395
3795
  print 1
3396
3796
  end sub
3397
3797
  `);
3398
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3798
+ validateFile(mainFile);
3399
3799
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3400
3800
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3401
3801
  mainFile = program.setFile('source/main.bs', `
@@ -3407,7 +3807,7 @@ describe('BrsFile', () => {
3407
3807
  print 2
3408
3808
  end sub
3409
3809
  `);
3410
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3810
+ validateFile(mainFile);
3411
3811
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3412
3812
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
3413
3813
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3424,7 +3824,7 @@ describe('BrsFile', () => {
3424
3824
  print 2
3425
3825
  end sub
3426
3826
  `);
3427
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3827
+ validateFile(mainFile);
3428
3828
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3429
3829
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
3430
3830
  mainFile = program.setFile('source/main.bs', `
@@ -3432,7 +3832,7 @@ describe('BrsFile', () => {
3432
3832
  print 1
3433
3833
  end sub
3434
3834
  `);
3435
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3835
+ validateFile(mainFile);
3436
3836
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3437
3837
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3438
3838
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3444,7 +3844,7 @@ describe('BrsFile', () => {
3444
3844
  namespace Alpha
3445
3845
  end namespace
3446
3846
  `);
3447
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3847
+ validateFile(mainFile);
3448
3848
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3449
3849
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(0);
3450
3850
  mainFile = program.setFile('source/main.bs', `
@@ -3452,7 +3852,7 @@ describe('BrsFile', () => {
3452
3852
  const ABC = "abc"
3453
3853
  end namespace
3454
3854
  `);
3455
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3855
+ validateFile(mainFile);
3456
3856
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3457
3857
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3458
3858
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3469,7 +3869,7 @@ describe('BrsFile', () => {
3469
3869
  const PI = 3.14
3470
3870
  end namespace
3471
3871
  `);
3472
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3872
+ validateFile(mainFile);
3473
3873
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3474
3874
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
3475
3875
  mainFile = program.setFile('source/main.bs', `
@@ -3481,7 +3881,7 @@ describe('BrsFile', () => {
3481
3881
  const PI = 3.14159
3482
3882
  end namespace
3483
3883
  `);
3484
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3884
+ validateFile(mainFile);
3485
3885
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3486
3886
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
3487
3887
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3493,7 +3893,7 @@ describe('BrsFile', () => {
3493
3893
  return x
3494
3894
  end function
3495
3895
  `);
3496
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3896
+ validateFile(mainFile);
3497
3897
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3498
3898
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3499
3899
  mainFile = program.setFile('source/main.bs', `
@@ -3501,7 +3901,7 @@ describe('BrsFile', () => {
3501
3901
  return x+y
3502
3902
  end function
3503
3903
  `);
3504
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3904
+ validateFile(mainFile);
3505
3905
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3506
3906
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3507
3907
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3517,7 +3917,7 @@ describe('BrsFile', () => {
3517
3917
  end function
3518
3918
  end class
3519
3919
  `);
3520
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3920
+ validateFile(mainFile);
3521
3921
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3522
3922
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3523
3923
  mainFile = program.setFile('source/main.bs', `
@@ -3528,7 +3928,7 @@ describe('BrsFile', () => {
3528
3928
  end function
3529
3929
  end class
3530
3930
  `);
3531
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3931
+ validateFile(mainFile);
3532
3932
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3533
3933
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3534
3934
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3545,7 +3945,7 @@ describe('BrsFile', () => {
3545
3945
  function doStuff() as float
3546
3946
  end interface
3547
3947
  `);
3548
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3948
+ validateFile(mainFile);
3549
3949
  let typetimeSymbols = mainFile.providedSymbols.symbolMap.get(2 /* SymbolTypeFlag.typetime */);
3550
3950
  (0, chai_config_spec_1.expect)(typetimeSymbols.size).to.eq(1);
3551
3951
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
@@ -3557,7 +3957,7 @@ describe('BrsFile', () => {
3557
3957
  function doStuff() as float
3558
3958
  end interface
3559
3959
  `);
3560
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3960
+ validateFile(mainFile);
3561
3961
  typetimeSymbols = mainFile.providedSymbols.symbolMap.get(2 /* SymbolTypeFlag.typetime */);
3562
3962
  (0, chai_config_spec_1.expect)(typetimeSymbols.size).to.eq(1);
3563
3963
  let typeTimeChanges = mainFile.providedSymbols.changes.get(2 /* SymbolTypeFlag.typetime */);
@@ -3575,7 +3975,7 @@ describe('BrsFile', () => {
3575
3975
  west = 1
3576
3976
  end enum
3577
3977
  `);
3578
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3978
+ validateFile(mainFile);
3579
3979
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3580
3980
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3581
3981
  mainFile = program.setFile('source/main.bs', `
@@ -3586,7 +3986,7 @@ describe('BrsFile', () => {
3586
3986
  west = 4
3587
3987
  end enum
3588
3988
  `);
3589
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
3989
+ validateFile(mainFile);
3590
3990
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3591
3991
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3592
3992
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3617,7 +4017,7 @@ describe('BrsFile', () => {
3617
4017
  purple
3618
4018
  end enum
3619
4019
  `);
3620
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4020
+ validateFile(mainFile);
3621
4021
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3622
4022
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(3);
3623
4023
  mainFile = program.setFile('source/main.bs', `
@@ -3640,7 +4040,7 @@ describe('BrsFile', () => {
3640
4040
  green
3641
4041
  end enum
3642
4042
  `);
3643
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4043
+ validateFile(mainFile);
3644
4044
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3645
4045
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(3);
3646
4046
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3657,7 +4057,7 @@ describe('BrsFile', () => {
3657
4057
  west = 4
3658
4058
  end enum
3659
4059
  `);
3660
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4060
+ validateFile(mainFile);
3661
4061
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3662
4062
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3663
4063
  mainFile = program.setFile('source/main.bs', `
@@ -3681,7 +4081,7 @@ describe('BrsFile', () => {
3681
4081
  const PI = 3.14
3682
4082
  end namespace
3683
4083
  `);
3684
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4084
+ validateFile(mainFile);
3685
4085
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3686
4086
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3687
4087
  mainFile = program.setFile('source/main.bs', `
@@ -3689,7 +4089,7 @@ describe('BrsFile', () => {
3689
4089
  const PI = "lemon chiffon"
3690
4090
  end namespace
3691
4091
  `);
3692
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4092
+ validateFile(mainFile);
3693
4093
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3694
4094
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(1);
3695
4095
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3709,12 +4109,12 @@ describe('BrsFile', () => {
3709
4109
  print myLabel.getChildren(0, -1)
3710
4110
  end sub
3711
4111
  `);
3712
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4112
+ validateFile(mainFile);
3713
4113
  let runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3714
4114
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
3715
4115
  mainFile = program.setFile('source/main.bs', `
3716
4116
  function func1(p as string) as integer
3717
- return len(p)+1
4117
+ return len(p) + 1
3718
4118
  end function
3719
4119
 
3720
4120
  sub displayModelTypeInLabel(myLabel as roSgNodeLabel)
@@ -3724,7 +4124,7 @@ describe('BrsFile', () => {
3724
4124
  print myLabel.getChildren(0, -1)
3725
4125
  end sub
3726
4126
  `);
3727
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4127
+ validateFile(mainFile);
3728
4128
  runtimeSymbols = mainFile.providedSymbols.symbolMap.get(1 /* SymbolTypeFlag.runtime */);
3729
4129
  (0, chai_config_spec_1.expect)(runtimeSymbols.size).to.eq(2);
3730
4130
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
@@ -3739,10 +4139,10 @@ describe('BrsFile', () => {
3739
4139
  end class
3740
4140
  `;
3741
4141
  let mainFile = program.setFile('source/class.bs', classFileContent);
3742
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4142
+ validateFile(mainFile);
3743
4143
  // No changes!
3744
4144
  mainFile = program.setFile('source/class.bs', classFileContent);
3745
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4145
+ validateFile(mainFile);
3746
4146
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
3747
4147
  (0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
3748
4148
  });
@@ -3765,21 +4165,20 @@ describe('BrsFile', () => {
3765
4165
  end namespace
3766
4166
  `;
3767
4167
  let mainFile = program.setFile('source/class.bs', fileContent);
3768
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4168
+ validateFile(mainFile);
3769
4169
  // No changes!
3770
4170
  mainFile = program.setFile('source/class.bs', fileContent);
3771
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4171
+ validateFile(mainFile);
3772
4172
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
3773
4173
  (0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
3774
4174
  });
3775
4175
  it('functions in a namespace that have class params show change properly', () => {
3776
4176
  const fileContent = `
3777
4177
  namespace Alpha.Beta
3778
-
3779
4178
  class SomeKlass
3780
4179
  name as string
3781
4180
  function combineName(klass as SomeKlass)
3782
- m.name = m.name+klass.name
4181
+ m.name = m.name + klass.name
3783
4182
  end function
3784
4183
  end class
3785
4184
 
@@ -3790,10 +4189,29 @@ describe('BrsFile', () => {
3790
4189
  end namespace
3791
4190
  `;
3792
4191
  let mainFile = program.setFile('source/class.bs', fileContent);
3793
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4192
+ validateFile(mainFile);
3794
4193
  // No changes!
3795
4194
  mainFile = program.setFile('source/class.bs', fileContent);
3796
- program.plugins.emit('onFileValidate', { program: program, file: mainFile });
4195
+ validateFile(mainFile);
4196
+ let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
4197
+ (0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
4198
+ });
4199
+ it('should not include namespaces in changes if no symbols in namespace changed', () => {
4200
+ const fileContent = `
4201
+ namespace Alpha.Beta
4202
+ const PI = 3.14
4203
+ end namespace
4204
+ `;
4205
+ const fileContentWithComment = `
4206
+ namespace Alpha.Beta
4207
+ const PI = 3.14 ' comment
4208
+ end namespace
4209
+ `;
4210
+ let mainFile = program.setFile('source/namespace.bs', fileContent);
4211
+ validateFile(mainFile);
4212
+ // Just added a comment!
4213
+ mainFile = program.setFile('source/namespace.bs', fileContentWithComment);
4214
+ validateFile(mainFile);
3797
4215
  let runtimeChanges = mainFile.providedSymbols.changes.get(1 /* SymbolTypeFlag.runtime */);
3798
4216
  (0, chai_config_spec_1.expect)(runtimeChanges.size).to.eq(0);
3799
4217
  });
@@ -3806,7 +4224,7 @@ describe('BrsFile', () => {
3806
4224
  aa1 = {
3807
4225
  "sprop1": 0,
3808
4226
  prop1: 1
3809
- prop2: {
4227
+ prop2: {
3810
4228
  prop3: 2
3811
4229
  }
3812
4230
  }
@@ -3840,7 +4258,7 @@ describe('BrsFile', () => {
3840
4258
  aa1 = {
3841
4259
  "constructor": 0,
3842
4260
  constructor: 1
3843
- valueOf: {
4261
+ valueOf: {
3844
4262
  toString: 2
3845
4263
  }
3846
4264
  }
@@ -3854,6 +4272,80 @@ describe('BrsFile', () => {
3854
4272
  const { propertyHints } = file['_cachedLookups'];
3855
4273
  (0, chai_config_spec_1.expect)(Object.keys(propertyHints).sort()).to.deep.equal(expected, 'Initial hints');
3856
4274
  });
4275
+ it('allows built-in types for class members', () => {
4276
+ program.setFile('source/main.bs', `
4277
+ class MyBase
4278
+ regex as roRegex
4279
+ node as roSGNodeLabel
4280
+
4281
+ sub outputMatches(textInput as string)
4282
+ matches = m.regex.match(textInput)
4283
+ if matches.count() > 1
4284
+ m.node.text = matches[1]
4285
+ else
4286
+ m.node.text = "no match"
4287
+ end if
4288
+ end sub
4289
+
4290
+ function getLabelParent() as roSGNode
4291
+ return m.node.getParent()
4292
+ end function
4293
+ end class
4294
+ `);
4295
+ program.validate();
4296
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
4297
+ });
4298
+ it('allows types on lhs of assignments', async () => {
4299
+ await testTranspile(`
4300
+ sub foo(node as roSGNode)
4301
+ nodeParent as roSGNode = node.getParent()
4302
+ text as string = nodeParent.id
4303
+ print text
4304
+ end sub
4305
+ `, `
4306
+ sub foo(node as dynamic)
4307
+ nodeParent = node.getParent()
4308
+ text = nodeParent.id
4309
+ print text
4310
+ end sub
4311
+ `);
4312
+ });
4313
+ //fails at the specific length of statement including leading tabs and spaces
4314
+ it('allows long statements', () => {
4315
+ program.setFile('source/main.bs', `function request()\r\nhzzzzandleInterceptedScreenDataaaaaaaaaaainterceptedScreenData() 'bs:disable-line \r\nend function`);
4316
+ program.validate();
4317
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
4318
+ program.setFile('source/main.bs', `function request()\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\thandleInterceptedScreenDataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(m._aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaainterceptedScreenData) 'bs:disable-line \r\nend function`);
4319
+ program.validate();
4320
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
4321
+ program.setFile('source/main.bs', `function request()\r\n\t\t\t\thandleInterceptedScreenData(m._aaaaaaainterceptedScreenData) 'bs:disable-line 1001\r\nend function`);
4322
+ program.validate();
4323
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
4324
+ });
4325
+ });
4326
+ it('allows up to 63 function params', () => {
4327
+ program.setFile('source/main.bs', `
4328
+ function test(p1 = 1, p2 = 2, p3 = 3, p4 = 4, p5 = 5, p6 = 6, p7 = 7, p8 = 8, p9 = 9, p10 = 10, p11 = 11, p12 = 12, p13 = 13, p14 = 14, p15 = 15, p16 = 16, p17 = 17, p18 = 18, p19 = 19, p20 = 20, p21 = 21, p22 = 22, p23 = 23, p24 = 24, p25 = 25, p26 = 26, p27 = 27, p28 = 28, p29 = 29, p30 = 30, p31 = 31, p32 = 32, p33 = 33, p34 = 34, p35 = 35, p36 = 36, p37 = 37, p38 = 38, p39 = 39, p40 = 40, p41 = 41, p42 = 42, p43 = 43, p44 = 44, p45 = 45, p46 = 46, p47 = 47, p48 = 48, p49 = 49, p50 = 50, p51 = 51, p52 = 52, p53 = 53, p54 = 54, p55 = 55, p56 = 56, p57 = 57, p58 = 58, p59 = 59, p60 = 60, p61 = 61, p62 = 62, p63 = 63)
4329
+ end function
4330
+ `);
4331
+ program.validate();
4332
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
4333
+ });
4334
+ it('flags functions having 64 parameters', () => {
4335
+ program.setFile('source/main.bs', `
4336
+ function test(p1 = 1, p2 = 2, p3 = 3, p4 = 4, p5 = 5, p6 = 6, p7 = 7, p8 = 8, p9 = 9, p10 = 10, p11 = 11, p12 = 12, p13 = 13, p14 = 14, p15 = 15, p16 = 16, p17 = 17, p18 = 18, p19 = 19, p20 = 20, p21 = 21, p22 = 22, p23 = 23, p24 = 24, p25 = 25, p26 = 26, p27 = 27, p28 = 28, p29 = 29, p30 = 30, p31 = 31, p32 = 32, p33 = 33, p34 = 34, p35 = 35, p36 = 36, p37 = 37, p38 = 38, p39 = 39, p40 = 40, p41 = 41, p42 = 42, p43 = 43, p44 = 44, p45 = 45, p46 = 46, p47 = 47, p48 = 48, p49 = 49, p50 = 50, p51 = 51, p52 = 52, p53 = 53, p54 = 54, p55 = 55, p56 = 56, p57 = 57, p58 = 58, p59 = 59, p60 = 60, p61 = 61, p62 = 62, p63 = 63, p64 = 64)
4337
+ end function
4338
+ `);
4339
+ program.validate();
4340
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.tooManyCallableParameters(64, 63)), { range: util_1.default.createRange(1, 638, 1, 641) })]);
4341
+ });
4342
+ it('flags functions having 65 parameters', () => {
4343
+ program.setFile('source/main.bs', `
4344
+ function test(p1 = 1, p2 = 2, p3 = 3, p4 = 4, p5 = 5, p6 = 6, p7 = 7, p8 = 8, p9 = 9, p10 = 10, p11 = 11, p12 = 12, p13 = 13, p14 = 14, p15 = 15, p16 = 16, p17 = 17, p18 = 18, p19 = 19, p20 = 20, p21 = 21, p22 = 22, p23 = 23, p24 = 24, p25 = 25, p26 = 26, p27 = 27, p28 = 28, p29 = 29, p30 = 30, p31 = 31, p32 = 32, p33 = 33, p34 = 34, p35 = 35, p36 = 36, p37 = 37, p38 = 38, p39 = 39, p40 = 40, p41 = 41, p42 = 42, p43 = 43, p44 = 44, p45 = 45, p46 = 46, p47 = 47, p48 = 48, p49 = 49, p50 = 50, p51 = 51, p52 = 52, p53 = 53, p54 = 54, p55 = 55, p56 = 56, p57 = 57, p58 = 58, p59 = 59, p60 = 60, p61 = 61, p62 = 62, p63 = 63, p64 = 64, p65 = 65)
4345
+ end function
4346
+ `);
4347
+ program.validate();
4348
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.tooManyCallableParameters(65, 63)), { range: util_1.default.createRange(1, 638, 1, 641) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.tooManyCallableParameters(65, 63)), { range: util_1.default.createRange(1, 648, 1, 651) })]);
3857
4349
  });
3858
4350
  });
3859
4351
  //# sourceMappingURL=BrsFile.spec.js.map