brighterscript 1.0.0-alpha.24 → 1.0.0-alpha.26

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 (536) hide show
  1. package/CHANGELOG.md +521 -233
  2. package/README.md +45 -139
  3. package/bsconfig.schema.json +46 -0
  4. package/dist/ActionPipeline.d.ts +10 -0
  5. package/dist/ActionPipeline.js +40 -0
  6. package/dist/ActionPipeline.js.map +1 -0
  7. package/dist/AstValidationSegmenter.d.ts +25 -0
  8. package/dist/AstValidationSegmenter.js +152 -0
  9. package/dist/AstValidationSegmenter.js.map +1 -0
  10. package/dist/BsConfig.d.ts +40 -4
  11. package/dist/BusyStatusTracker.d.ts +31 -0
  12. package/dist/BusyStatusTracker.js +83 -0
  13. package/dist/BusyStatusTracker.js.map +1 -0
  14. package/dist/Cache.js +3 -3
  15. package/dist/Cache.js.map +1 -1
  16. package/dist/CacheVerifier.d.ts +7 -0
  17. package/dist/CacheVerifier.js +20 -0
  18. package/dist/CacheVerifier.js.map +1 -0
  19. package/dist/CodeActionUtil.d.ts +3 -3
  20. package/dist/CodeActionUtil.js.map +1 -1
  21. package/dist/CommentFlagProcessor.d.ts +3 -2
  22. package/dist/CommentFlagProcessor.js +5 -4
  23. package/dist/CommentFlagProcessor.js.map +1 -1
  24. package/dist/DependencyGraph.d.ts +3 -2
  25. package/dist/DependencyGraph.js +11 -10
  26. package/dist/DependencyGraph.js.map +1 -1
  27. package/dist/DiagnosticCollection.js +9 -5
  28. package/dist/DiagnosticCollection.js.map +1 -1
  29. package/dist/DiagnosticFilterer.d.ts +1 -0
  30. package/dist/DiagnosticFilterer.js +5 -3
  31. package/dist/DiagnosticFilterer.js.map +1 -1
  32. package/dist/DiagnosticMessages.d.ts +61 -13
  33. package/dist/DiagnosticMessages.js +116 -19
  34. package/dist/DiagnosticMessages.js.map +1 -1
  35. package/dist/DiagnosticSeverityAdjuster.d.ts +7 -0
  36. package/dist/DiagnosticSeverityAdjuster.js +41 -0
  37. package/dist/DiagnosticSeverityAdjuster.js.map +1 -0
  38. package/dist/FunctionScope.d.ts +28 -0
  39. package/dist/FunctionScope.js +52 -0
  40. package/dist/FunctionScope.js.map +1 -0
  41. package/dist/KeyedThrottler.d.ts +3 -3
  42. package/dist/KeyedThrottler.js +3 -3
  43. package/dist/KeyedThrottler.js.map +1 -1
  44. package/dist/LanguageServer.d.ts +23 -11
  45. package/dist/LanguageServer.js +150 -69
  46. package/dist/LanguageServer.js.map +1 -1
  47. package/dist/Logger.d.ts +3 -2
  48. package/dist/Logger.js +11 -3
  49. package/dist/Logger.js.map +1 -1
  50. package/dist/PluginInterface.d.ts +21 -3
  51. package/dist/PluginInterface.js +74 -6
  52. package/dist/PluginInterface.js.map +1 -1
  53. package/dist/Program.d.ts +158 -79
  54. package/dist/Program.js +841 -706
  55. package/dist/Program.js.map +1 -1
  56. package/dist/ProgramBuilder.d.ts +22 -12
  57. package/dist/ProgramBuilder.js +130 -103
  58. package/dist/ProgramBuilder.js.map +1 -1
  59. package/dist/Scope.d.ts +86 -137
  60. package/dist/Scope.js +453 -519
  61. package/dist/Scope.js.map +1 -1
  62. package/dist/Stopwatch.js +1 -1
  63. package/dist/Stopwatch.js.map +1 -1
  64. package/dist/SymbolTable.d.ts +89 -34
  65. package/dist/SymbolTable.js +239 -114
  66. package/dist/SymbolTable.js.map +1 -1
  67. package/dist/Throttler.d.ts +12 -0
  68. package/dist/Throttler.js +39 -0
  69. package/dist/Throttler.js.map +1 -1
  70. package/dist/Watcher.d.ts +0 -3
  71. package/dist/Watcher.js +0 -3
  72. package/dist/Watcher.js.map +1 -1
  73. package/dist/XmlScope.d.ts +4 -11
  74. package/dist/XmlScope.js +75 -88
  75. package/dist/XmlScope.js.map +1 -1
  76. package/dist/astUtils/CachedLookups.d.ts +48 -0
  77. package/dist/astUtils/CachedLookups.js +323 -0
  78. package/dist/astUtils/CachedLookups.js.map +1 -0
  79. package/dist/astUtils/{AstEditor.d.ts → Editor.d.ts} +9 -5
  80. package/dist/astUtils/{AstEditor.js → Editor.js} +10 -4
  81. package/dist/astUtils/Editor.js.map +1 -0
  82. package/dist/astUtils/{AstEditor.spec.js → Editor.spec.js} +69 -65
  83. package/dist/astUtils/Editor.spec.js.map +1 -0
  84. package/dist/astUtils/creators.d.ts +10 -10
  85. package/dist/astUtils/creators.js +54 -24
  86. package/dist/astUtils/creators.js.map +1 -1
  87. package/dist/astUtils/creators.spec.js +5 -5
  88. package/dist/astUtils/creators.spec.js.map +1 -1
  89. package/dist/astUtils/reflection.d.ts +132 -104
  90. package/dist/astUtils/reflection.js +220 -174
  91. package/dist/astUtils/reflection.js.map +1 -1
  92. package/dist/astUtils/reflection.spec.js +256 -157
  93. package/dist/astUtils/reflection.spec.js.map +1 -1
  94. package/dist/astUtils/stackedVisitor.spec.js +12 -12
  95. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  96. package/dist/astUtils/visitors.d.ts +53 -35
  97. package/dist/astUtils/visitors.js +29 -3
  98. package/dist/astUtils/visitors.js.map +1 -1
  99. package/dist/astUtils/visitors.spec.js +208 -52
  100. package/dist/astUtils/visitors.spec.js.map +1 -1
  101. package/dist/astUtils/xml.d.ts +9 -9
  102. package/dist/astUtils/xml.js +9 -9
  103. package/dist/astUtils/xml.js.map +1 -1
  104. package/dist/bscPlugin/BscPlugin.d.ts +11 -2
  105. package/dist/bscPlugin/BscPlugin.js +37 -3
  106. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  107. package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
  108. package/dist/bscPlugin/CallExpressionInfo.js +131 -0
  109. package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
  110. package/dist/bscPlugin/FileWriter.d.ts +6 -0
  111. package/dist/bscPlugin/FileWriter.js +24 -0
  112. package/dist/bscPlugin/FileWriter.js.map +1 -0
  113. package/dist/bscPlugin/SignatureHelpUtil.d.ts +10 -0
  114. package/dist/bscPlugin/SignatureHelpUtil.js +136 -0
  115. package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
  116. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +16 -13
  117. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  118. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +16 -16
  119. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  120. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +52 -1
  121. package/dist/bscPlugin/completions/CompletionsProcessor.js +517 -26
  122. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
  123. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +1909 -0
  124. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
  125. package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
  126. package/dist/bscPlugin/definition/DefinitionProvider.js +210 -0
  127. package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
  128. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +88 -0
  129. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
  130. package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
  131. package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
  132. package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
  133. package/dist/bscPlugin/hover/HoverProcessor.d.ts +7 -7
  134. package/dist/bscPlugin/hover/HoverProcessor.js +123 -125
  135. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
  136. package/dist/bscPlugin/hover/HoverProcessor.spec.js +371 -53
  137. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
  138. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +2 -1
  139. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +83 -23
  140. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  141. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +83 -6
  142. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
  143. package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
  144. package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
  145. package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
  146. package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
  147. package/dist/bscPlugin/serialize/BslibManager.js +40 -0
  148. package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
  149. package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
  150. package/dist/bscPlugin/serialize/FileSerializer.js +72 -0
  151. package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
  152. package/dist/bscPlugin/transpile/{BrsFilePreTranspileProcessor.d.ts → BrsFileTranspileProcessor.d.ts} +4 -2
  153. package/dist/bscPlugin/transpile/{BrsFilePreTranspileProcessor.js → BrsFileTranspileProcessor.js} +38 -12
  154. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
  155. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
  156. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +41 -0
  157. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
  158. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
  159. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
  160. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
  161. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +13 -5
  162. package/dist/bscPlugin/validation/BrsFileValidator.js +262 -52
  163. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  164. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +230 -14
  165. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
  166. package/dist/bscPlugin/validation/ProgramValidator.d.ts +10 -0
  167. package/dist/bscPlugin/validation/ProgramValidator.js +32 -0
  168. package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
  169. package/dist/bscPlugin/validation/ScopeValidator.d.ts +58 -27
  170. package/dist/bscPlugin/validation/ScopeValidator.js +514 -286
  171. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  172. package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
  173. package/dist/bscPlugin/validation/ScopeValidator.spec.js +2527 -0
  174. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
  175. package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
  176. package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
  177. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
  178. package/dist/cli.js +104 -13
  179. package/dist/cli.js.map +1 -1
  180. package/dist/deferred.d.ts +3 -3
  181. package/dist/deferred.js.map +1 -1
  182. package/dist/diagnosticUtils.d.ts +8 -2
  183. package/dist/diagnosticUtils.js +47 -17
  184. package/dist/diagnosticUtils.js.map +1 -1
  185. package/dist/examples/plugins/removePrint.js +8 -10
  186. package/dist/examples/plugins/removePrint.js.map +1 -1
  187. package/dist/files/AssetFile.d.ts +26 -0
  188. package/dist/files/AssetFile.js +26 -0
  189. package/dist/files/AssetFile.js.map +1 -0
  190. package/dist/files/BrsFile.Class.spec.js +523 -493
  191. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  192. package/dist/files/BrsFile.d.ts +111 -117
  193. package/dist/files/BrsFile.js +684 -1142
  194. package/dist/files/BrsFile.js.map +1 -1
  195. package/dist/files/BrsFile.spec.js +1783 -1233
  196. package/dist/files/BrsFile.spec.js.map +1 -1
  197. package/dist/files/BscFile.d.ts +104 -0
  198. package/dist/files/BscFile.js +16 -0
  199. package/dist/files/BscFile.js.map +1 -0
  200. package/dist/files/Factory.d.ts +25 -0
  201. package/dist/files/Factory.js +22 -0
  202. package/dist/files/Factory.js.map +1 -0
  203. package/dist/files/LazyFileData.d.ts +20 -0
  204. package/dist/files/LazyFileData.js +54 -0
  205. package/dist/files/LazyFileData.js.map +1 -0
  206. package/dist/files/LazyFileData.spec.d.ts +1 -0
  207. package/dist/files/LazyFileData.spec.js +27 -0
  208. package/dist/files/LazyFileData.spec.js.map +1 -0
  209. package/dist/files/XmlFile.d.ts +70 -32
  210. package/dist/files/XmlFile.js +106 -118
  211. package/dist/files/XmlFile.js.map +1 -1
  212. package/dist/files/XmlFile.spec.js +325 -262
  213. package/dist/files/XmlFile.spec.js.map +1 -1
  214. package/dist/files/tests/imports.spec.js +48 -40
  215. package/dist/files/tests/imports.spec.js.map +1 -1
  216. package/dist/files/tests/optionalChaning.spec.js +84 -24
  217. package/dist/files/tests/optionalChaning.spec.js.map +1 -1
  218. package/dist/globalCallables.js +16 -21
  219. package/dist/globalCallables.js.map +1 -1
  220. package/dist/index.d.ts +12 -1
  221. package/dist/index.js +12 -1
  222. package/dist/index.js.map +1 -1
  223. package/dist/interfaces.d.ts +421 -162
  224. package/dist/interfaces.js +27 -0
  225. package/dist/interfaces.js.map +1 -1
  226. package/dist/lexer/Character.spec.js +5 -5
  227. package/dist/lexer/Character.spec.js.map +1 -1
  228. package/dist/lexer/Lexer.d.ts +12 -5
  229. package/dist/lexer/Lexer.js +28 -13
  230. package/dist/lexer/Lexer.js.map +1 -1
  231. package/dist/lexer/Lexer.spec.js +181 -135
  232. package/dist/lexer/Lexer.spec.js.map +1 -1
  233. package/dist/lexer/Token.d.ts +9 -1
  234. package/dist/lexer/Token.js +9 -1
  235. package/dist/lexer/Token.js.map +1 -1
  236. package/dist/lexer/TokenKind.d.ts +8 -0
  237. package/dist/lexer/TokenKind.js +24 -4
  238. package/dist/lexer/TokenKind.js.map +1 -1
  239. package/dist/parser/AstNode.d.ts +162 -0
  240. package/dist/parser/AstNode.js +225 -0
  241. package/dist/parser/AstNode.js.map +1 -0
  242. package/dist/parser/AstNode.spec.d.ts +1 -0
  243. package/dist/parser/AstNode.spec.js +165 -0
  244. package/dist/parser/AstNode.spec.js.map +1 -0
  245. package/dist/parser/BrsTranspileState.d.ts +4 -7
  246. package/dist/parser/BrsTranspileState.js +4 -12
  247. package/dist/parser/BrsTranspileState.js.map +1 -1
  248. package/dist/parser/Expression.d.ts +376 -283
  249. package/dist/parser/Expression.js +742 -585
  250. package/dist/parser/Expression.js.map +1 -1
  251. package/dist/parser/Parser.Class.spec.js +151 -145
  252. package/dist/parser/Parser.Class.spec.js.map +1 -1
  253. package/dist/parser/Parser.d.ts +48 -201
  254. package/dist/parser/Parser.js +705 -1026
  255. package/dist/parser/Parser.js.map +1 -1
  256. package/dist/parser/Parser.spec.d.ts +3 -1
  257. package/dist/parser/Parser.spec.js +861 -848
  258. package/dist/parser/Parser.spec.js.map +1 -1
  259. package/dist/parser/SGParser.d.ts +9 -8
  260. package/dist/parser/SGParser.js +10 -8
  261. package/dist/parser/SGParser.js.map +1 -1
  262. package/dist/parser/SGParser.spec.js +27 -38
  263. package/dist/parser/SGParser.spec.js.map +1 -1
  264. package/dist/parser/SGTypes.d.ts +98 -35
  265. package/dist/parser/SGTypes.js +169 -99
  266. package/dist/parser/SGTypes.js.map +1 -1
  267. package/dist/parser/Statement.d.ts +468 -272
  268. package/dist/parser/Statement.js +904 -631
  269. package/dist/parser/Statement.js.map +1 -1
  270. package/dist/parser/Statement.spec.js +47 -23
  271. package/dist/parser/Statement.spec.js.map +1 -1
  272. package/dist/parser/TranspileState.d.ts +1 -1
  273. package/dist/parser/TranspileState.js +7 -12
  274. package/dist/parser/TranspileState.js.map +1 -1
  275. package/dist/parser/tests/Parser.spec.js +3 -2
  276. package/dist/parser/tests/Parser.spec.js.map +1 -1
  277. package/dist/parser/tests/controlFlow/For.spec.js +33 -23
  278. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  279. package/dist/parser/tests/controlFlow/ForEach.spec.js +25 -20
  280. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  281. package/dist/parser/tests/controlFlow/If.spec.js +96 -94
  282. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  283. package/dist/parser/tests/controlFlow/While.spec.js +22 -16
  284. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  285. package/dist/parser/tests/expression/Additive.spec.js +8 -8
  286. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  287. package/dist/parser/tests/expression/ArrayLiterals.spec.js +58 -21
  288. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  289. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +62 -21
  290. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  291. package/dist/parser/tests/expression/Boolean.spec.js +8 -8
  292. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  293. package/dist/parser/tests/expression/Call.spec.js +129 -21
  294. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  295. package/dist/parser/tests/expression/Exponential.spec.js +5 -5
  296. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  297. package/dist/parser/tests/expression/Function.spec.js +36 -36
  298. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  299. package/dist/parser/tests/expression/Indexing.spec.js +92 -22
  300. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  301. package/dist/parser/tests/expression/Multiplicative.spec.js +9 -9
  302. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  303. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +59 -59
  304. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  305. package/dist/parser/tests/expression/PrefixUnary.spec.js +12 -12
  306. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  307. package/dist/parser/tests/expression/Primary.spec.js +12 -12
  308. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  309. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +10 -10
  310. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
  311. package/dist/parser/tests/expression/Relational.spec.js +13 -13
  312. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  313. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +24 -24
  314. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  315. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +96 -57
  316. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  317. package/dist/parser/tests/expression/TernaryExpression.spec.js +89 -89
  318. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  319. package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
  320. package/dist/parser/tests/expression/TypeExpression.spec.js +127 -0
  321. package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
  322. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
  323. package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
  324. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
  325. package/dist/parser/tests/statement/AssignmentOperators.spec.js +15 -15
  326. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  327. package/dist/parser/tests/statement/ConstStatement.spec.js +82 -33
  328. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
  329. package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
  330. package/dist/parser/tests/statement/Continue.spec.js +119 -0
  331. package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
  332. package/dist/parser/tests/statement/Declaration.spec.js +19 -19
  333. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  334. package/dist/parser/tests/statement/Dim.spec.js +22 -22
  335. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  336. package/dist/parser/tests/statement/Enum.spec.js +98 -302
  337. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  338. package/dist/parser/tests/statement/For.spec.js +9 -10
  339. package/dist/parser/tests/statement/For.spec.js.map +1 -1
  340. package/dist/parser/tests/statement/ForEach.spec.js +8 -9
  341. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
  342. package/dist/parser/tests/statement/Function.spec.js +44 -35
  343. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  344. package/dist/parser/tests/statement/Goto.spec.js +5 -5
  345. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  346. package/dist/parser/tests/statement/Increment.spec.js +20 -20
  347. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  348. package/dist/parser/tests/statement/InterfaceStatement.spec.js +30 -196
  349. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
  350. package/dist/parser/tests/statement/LibraryStatement.spec.js +11 -11
  351. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  352. package/dist/parser/tests/statement/Misc.spec.js +16 -78
  353. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  354. package/dist/parser/tests/statement/PrintStatement.spec.js +36 -34
  355. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  356. package/dist/parser/tests/statement/ReturnStatement.spec.js +14 -12
  357. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  358. package/dist/parser/tests/statement/Set.spec.js +48 -35
  359. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  360. package/dist/parser/tests/statement/Stop.spec.js +6 -6
  361. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  362. package/dist/parser/tests/statement/Throw.spec.js +6 -6
  363. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  364. package/dist/parser/tests/statement/TryCatch.spec.js +18 -16
  365. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  366. package/dist/preprocessor/Manifest.d.ts +1 -1
  367. package/dist/preprocessor/Manifest.js +2 -2
  368. package/dist/preprocessor/Manifest.js.map +1 -1
  369. package/dist/preprocessor/Manifest.spec.js +8 -8
  370. package/dist/preprocessor/Manifest.spec.js.map +1 -1
  371. package/dist/preprocessor/Preprocessor.d.ts +5 -6
  372. package/dist/preprocessor/Preprocessor.js +5 -5
  373. package/dist/preprocessor/Preprocessor.js.map +1 -1
  374. package/dist/preprocessor/Preprocessor.spec.js +25 -25
  375. package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
  376. package/dist/preprocessor/PreprocessorParser.d.ts +1 -1
  377. package/dist/preprocessor/PreprocessorParser.js +7 -1
  378. package/dist/preprocessor/PreprocessorParser.js.map +1 -1
  379. package/dist/preprocessor/PreprocessorParser.spec.js +13 -13
  380. package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
  381. package/dist/roku-types/data.json +5892 -10081
  382. package/dist/roku-types/index.d.ts +622 -1719
  383. package/dist/types/ArrayType.d.ts +10 -9
  384. package/dist/types/ArrayType.js +65 -60
  385. package/dist/types/ArrayType.js.map +1 -1
  386. package/dist/types/ArrayType.spec.js +36 -68
  387. package/dist/types/ArrayType.spec.js.map +1 -1
  388. package/dist/types/AssociativeArrayType.d.ts +11 -0
  389. package/dist/types/AssociativeArrayType.js +52 -0
  390. package/dist/types/AssociativeArrayType.js.map +1 -0
  391. package/dist/types/BaseFunctionType.d.ts +9 -0
  392. package/dist/types/BaseFunctionType.js +25 -0
  393. package/dist/types/BaseFunctionType.js.map +1 -0
  394. package/dist/types/BooleanType.d.ts +8 -5
  395. package/dist/types/BooleanType.js +14 -7
  396. package/dist/types/BooleanType.js.map +1 -1
  397. package/dist/types/BooleanType.spec.js +10 -6
  398. package/dist/types/BooleanType.spec.js.map +1 -1
  399. package/dist/types/BscType.d.ts +32 -21
  400. package/dist/types/BscType.js +118 -21
  401. package/dist/types/BscType.js.map +1 -1
  402. package/dist/types/BscTypeKind.d.ts +25 -0
  403. package/dist/types/BscTypeKind.js +30 -0
  404. package/dist/types/BscTypeKind.js.map +1 -0
  405. package/dist/types/BuiltInInterfaceAdder.d.ts +23 -0
  406. package/dist/types/BuiltInInterfaceAdder.js +171 -0
  407. package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
  408. package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
  409. package/dist/types/BuiltInInterfaceAdder.spec.js +116 -0
  410. package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
  411. package/dist/types/ClassType.d.ts +17 -0
  412. package/dist/types/ClassType.js +58 -0
  413. package/dist/types/ClassType.js.map +1 -0
  414. package/dist/types/ClassType.spec.d.ts +1 -0
  415. package/dist/types/ClassType.spec.js +77 -0
  416. package/dist/types/ClassType.spec.js.map +1 -0
  417. package/dist/types/ComponentType.d.ts +26 -0
  418. package/dist/types/ComponentType.js +83 -0
  419. package/dist/types/ComponentType.js.map +1 -0
  420. package/dist/types/DoubleType.d.ts +8 -5
  421. package/dist/types/DoubleType.js +18 -16
  422. package/dist/types/DoubleType.js.map +1 -1
  423. package/dist/types/DoubleType.spec.js +12 -6
  424. package/dist/types/DoubleType.spec.js.map +1 -1
  425. package/dist/types/DynamicType.d.ts +9 -5
  426. package/dist/types/DynamicType.js +15 -4
  427. package/dist/types/DynamicType.js.map +1 -1
  428. package/dist/types/DynamicType.spec.js +16 -5
  429. package/dist/types/DynamicType.spec.js.map +1 -1
  430. package/dist/types/EnumType.d.ts +30 -12
  431. package/dist/types/EnumType.js +43 -17
  432. package/dist/types/EnumType.js.map +1 -1
  433. package/dist/types/EnumType.spec.d.ts +1 -0
  434. package/dist/types/EnumType.spec.js +33 -0
  435. package/dist/types/EnumType.spec.js.map +1 -0
  436. package/dist/types/FloatType.d.ts +8 -5
  437. package/dist/types/FloatType.js +18 -16
  438. package/dist/types/FloatType.js.map +1 -1
  439. package/dist/types/FloatType.spec.js +4 -6
  440. package/dist/types/FloatType.spec.js.map +1 -1
  441. package/dist/types/FunctionType.d.ts +13 -8
  442. package/dist/types/FunctionType.js +30 -14
  443. package/dist/types/FunctionType.js.map +1 -1
  444. package/dist/types/InheritableType.d.ts +28 -0
  445. package/dist/types/InheritableType.js +152 -0
  446. package/dist/types/InheritableType.js.map +1 -0
  447. package/dist/types/IntegerType.d.ts +8 -5
  448. package/dist/types/IntegerType.js +18 -16
  449. package/dist/types/IntegerType.js.map +1 -1
  450. package/dist/types/IntegerType.spec.js +8 -6
  451. package/dist/types/IntegerType.spec.js.map +1 -1
  452. package/dist/types/InterfaceType.d.ts +12 -13
  453. package/dist/types/InterfaceType.js +20 -48
  454. package/dist/types/InterfaceType.js.map +1 -1
  455. package/dist/types/InterfaceType.spec.js +90 -56
  456. package/dist/types/InterfaceType.spec.js.map +1 -1
  457. package/dist/types/InvalidType.d.ts +7 -5
  458. package/dist/types/InvalidType.js +13 -7
  459. package/dist/types/InvalidType.js.map +1 -1
  460. package/dist/types/InvalidType.spec.js +8 -6
  461. package/dist/types/InvalidType.spec.js.map +1 -1
  462. package/dist/types/LongIntegerType.d.ts +8 -5
  463. package/dist/types/LongIntegerType.js +17 -15
  464. package/dist/types/LongIntegerType.js.map +1 -1
  465. package/dist/types/LongIntegerType.spec.js +10 -6
  466. package/dist/types/LongIntegerType.spec.js.map +1 -1
  467. package/dist/types/NamespaceType.d.ts +12 -0
  468. package/dist/types/NamespaceType.js +28 -0
  469. package/dist/types/NamespaceType.js.map +1 -0
  470. package/dist/types/ObjectType.d.ts +9 -8
  471. package/dist/types/ObjectType.js +21 -11
  472. package/dist/types/ObjectType.js.map +1 -1
  473. package/dist/types/ObjectType.spec.js +3 -3
  474. package/dist/types/ObjectType.spec.js.map +1 -1
  475. package/dist/types/ReferenceType.d.ts +63 -0
  476. package/dist/types/ReferenceType.js +423 -0
  477. package/dist/types/ReferenceType.js.map +1 -0
  478. package/dist/types/ReferenceType.spec.d.ts +1 -0
  479. package/dist/types/ReferenceType.spec.js +137 -0
  480. package/dist/types/ReferenceType.spec.js.map +1 -0
  481. package/dist/types/StringType.d.ts +11 -5
  482. package/dist/types/StringType.js +18 -7
  483. package/dist/types/StringType.js.map +1 -1
  484. package/dist/types/StringType.spec.js +3 -5
  485. package/dist/types/StringType.spec.js.map +1 -1
  486. package/dist/types/TypedFunctionType.d.ts +22 -17
  487. package/dist/types/TypedFunctionType.js +78 -60
  488. package/dist/types/TypedFunctionType.js.map +1 -1
  489. package/dist/types/TypedFunctionType.spec.js +105 -20
  490. package/dist/types/TypedFunctionType.spec.js.map +1 -1
  491. package/dist/types/UninitializedType.d.ts +8 -6
  492. package/dist/types/UninitializedType.js +13 -7
  493. package/dist/types/UninitializedType.js.map +1 -1
  494. package/dist/types/UnionType.d.ts +20 -0
  495. package/dist/types/UnionType.js +123 -0
  496. package/dist/types/UnionType.js.map +1 -0
  497. package/dist/types/UnionType.spec.d.ts +1 -0
  498. package/dist/types/UnionType.spec.js +130 -0
  499. package/dist/types/UnionType.spec.js.map +1 -0
  500. package/dist/types/VoidType.d.ts +8 -5
  501. package/dist/types/VoidType.js +14 -7
  502. package/dist/types/VoidType.js.map +1 -1
  503. package/dist/types/VoidType.spec.js +3 -3
  504. package/dist/types/VoidType.spec.js.map +1 -1
  505. package/dist/types/helper.spec.d.ts +1 -0
  506. package/dist/types/helper.spec.js +145 -0
  507. package/dist/types/helper.spec.js.map +1 -0
  508. package/dist/types/helpers.d.ts +19 -37
  509. package/dist/types/helpers.js +159 -99
  510. package/dist/types/helpers.js.map +1 -1
  511. package/dist/types/index.d.ts +22 -0
  512. package/dist/types/index.js +39 -0
  513. package/dist/types/index.js.map +1 -0
  514. package/dist/util.d.ts +143 -139
  515. package/dist/util.js +864 -385
  516. package/dist/util.js.map +1 -1
  517. package/dist/validators/ClassValidator.d.ts +8 -25
  518. package/dist/validators/ClassValidator.js +99 -179
  519. package/dist/validators/ClassValidator.js.map +1 -1
  520. package/package.json +165 -152
  521. package/dist/astUtils/AstEditor.js.map +0 -1
  522. package/dist/astUtils/AstEditor.spec.js.map +0 -1
  523. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +0 -1
  524. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -32
  525. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
  526. package/dist/parser/SGTypes.spec.js +0 -351
  527. package/dist/parser/SGTypes.spec.js.map +0 -1
  528. package/dist/types/CustomType.d.ts +0 -12
  529. package/dist/types/CustomType.js +0 -44
  530. package/dist/types/CustomType.js.map +0 -1
  531. package/dist/types/LazyType.d.ts +0 -16
  532. package/dist/types/LazyType.js +0 -44
  533. package/dist/types/LazyType.js.map +0 -1
  534. /package/dist/astUtils/{AstEditor.spec.d.ts → Editor.spec.d.ts} +0 -0
  535. /package/dist/bscPlugin/{transpile/BrsFilePreTranspileProcessor.spec.d.ts → completions/CompletionsProcessor.spec.d.ts} +0 -0
  536. /package/dist/{parser/SGTypes.spec.d.ts → bscPlugin/definition/DefinitionProvider.spec.d.ts} +0 -0
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const sinonImport = require("sinon");
4
4
  const Program_1 = require("../Program");
5
- const chai_1 = require("chai");
5
+ const chai_config_spec_1 = require("../chai-config.spec");
6
6
  const DiagnosticMessages_1 = require("../DiagnosticMessages");
7
7
  const vscode_languageserver_1 = require("vscode-languageserver");
8
8
  const Parser_1 = require("../parser/Parser");
@@ -11,30 +11,29 @@ const util_1 = require("../util");
11
11
  const fsExtra = require("fs-extra");
12
12
  const BrsTranspileState_1 = require("../parser/BrsTranspileState");
13
13
  const assert_1 = require("assert");
14
+ const testHelpers_spec_2 = require("../testHelpers.spec");
14
15
  const reflection_1 = require("../astUtils/reflection");
16
+ const visitors_1 = require("../astUtils/visitors");
15
17
  let sinon = sinonImport.createSandbox();
16
18
  describe('BrsFile BrighterScript classes', () => {
17
- let tmpPath = (0, util_1.standardizePath) `${process.cwd()}/.tmp`;
18
- let rootDir = (0, util_1.standardizePath) `${tmpPath}/rootDir`;
19
- const stagingDir = (0, util_1.standardizePath) `${tmpPath}/staging`;
20
19
  let program;
21
- let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, rootDir]);
20
+ let testTranspile = (0, testHelpers_spec_1.getTestTranspile)(() => [program, testHelpers_spec_2.rootDir]);
22
21
  beforeEach(() => {
23
- fsExtra.ensureDirSync(rootDir);
24
- fsExtra.emptyDirSync(tmpPath);
25
- program = new Program_1.Program({ rootDir: rootDir, stagingFolderPath: stagingDir });
22
+ fsExtra.ensureDirSync(testHelpers_spec_2.rootDir);
23
+ fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
24
+ program = new Program_1.Program({ rootDir: testHelpers_spec_2.rootDir, stagingDir: testHelpers_spec_2.stagingDir });
26
25
  });
27
26
  afterEach(() => {
28
27
  sinon.restore();
29
28
  program.dispose();
30
- fsExtra.ensureDirSync(tmpPath);
31
- fsExtra.emptyDirSync(tmpPath);
29
+ fsExtra.ensureDirSync(testHelpers_spec_2.tempDir);
30
+ fsExtra.emptyDirSync(testHelpers_spec_2.tempDir);
32
31
  });
33
32
  function addFile(relativePath, text) {
34
- return program.setFile({ src: `${rootDir}/${relativePath}`, dest: relativePath }, text);
33
+ return program.setFile({ src: `${testHelpers_spec_2.rootDir}/${relativePath}`, dest: relativePath }, text);
35
34
  }
36
35
  it('detects all classes after parse', () => {
37
- let file = program.setFile({ src: `${rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
36
+ let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.brs`, dest: 'source/main.brs' }, `
38
37
  class Animal
39
38
  end class
40
39
  class Duck
@@ -42,17 +41,18 @@ describe('BrsFile BrighterScript classes', () => {
42
41
 
43
42
  end class
44
43
  `);
45
- (0, chai_1.expect)(file.parser.references.classStatements.map(x => x.getName(Parser_1.ParseMode.BrighterScript)).sort()).to.eql(['Animal', 'Duck']);
44
+ const classStatements = file.ast.findChildren(reflection_1.isClassStatement);
45
+ (0, chai_config_spec_1.expect)(classStatements.map(x => x.getName(Parser_1.ParseMode.BrighterScript)).sort()).to.eql(['Animal', 'Duck']);
46
46
  });
47
47
  it('does not cause errors with incomplete class statement', () => {
48
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
48
+ program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
49
49
  class
50
50
  `);
51
51
  program.validate();
52
52
  //if no exception was thrown, this test passes
53
53
  });
54
54
  it('catches child class missing super call in constructor', () => {
55
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
55
+ program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
56
56
  class Person
57
57
  sub new()
58
58
  end sub
@@ -67,8 +67,29 @@ describe('BrsFile BrighterScript classes', () => {
67
67
  DiagnosticMessages_1.DiagnosticMessages.classConstructorMissingSuperCall()
68
68
  ]);
69
69
  });
70
+ it('allows class named `optional`', () => {
71
+ program.setFile('source/main.bs', `
72
+ class optional
73
+ thing = 1
74
+ end class
75
+ `);
76
+ program.validate();
77
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
78
+ });
79
+ it('supports optional fields', () => {
80
+ program.setFile('source/main.bs', `
81
+ class Movie
82
+ name as string
83
+ optional subtitles as string
84
+ public optional isRepeatEnabled as boolean
85
+ private optional wasPlayed
86
+ end class
87
+ `);
88
+ program.validate();
89
+ (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
90
+ });
70
91
  it('access modifier is option for override', () => {
71
- let file = program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
92
+ let file = program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
72
93
  class Animal
73
94
  sub move()
74
95
  end sub
@@ -81,12 +102,12 @@ describe('BrsFile BrighterScript classes', () => {
81
102
  `);
82
103
  program.validate();
83
104
  (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
84
- let duckClass = file.parser.references.classStatements.find(x => x.name.text.toLowerCase() === 'duck');
85
- (0, chai_1.expect)(duckClass).to.exist;
86
- (0, chai_1.expect)(duckClass.memberMap['move']).to.exist;
105
+ let duckClass = file.ast.findChildren(reflection_1.isClassStatement, { walkMode: visitors_1.WalkMode.visitStatements }).find(x => x.tokens.name.text.toLowerCase() === 'duck');
106
+ (0, chai_config_spec_1.expect)(duckClass).to.exist;
107
+ (0, chai_config_spec_1.expect)(duckClass.memberMap['move']).to.exist;
87
108
  });
88
109
  it('supports various namespace configurations', () => {
89
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
110
+ program.setFile({ src: `${testHelpers_spec_2.rootDir}/source/main.bs`, dest: 'source/main.bs' }, `
90
111
  class Animal
91
112
  sub new()
92
113
  bigBird = new Birds.Bird()
@@ -146,7 +167,7 @@ describe('BrsFile BrighterScript classes', () => {
146
167
  end sub
147
168
  end class
148
169
  class Duck extends Bird
149
- sub new()
170
+ sub new(name)
150
171
  thing = { m: "m"}
151
172
  print thing.m
152
173
  name = "Donald" + "Duck"
@@ -160,18 +181,20 @@ describe('BrsFile BrighterScript classes', () => {
160
181
  it('allows non-`m` expressions and statements before the super call', () => {
161
182
  program.setFile('source/main.bs', `
162
183
  class Bird
163
- sub new(name)
184
+ name as string
185
+ sub new(name as string)
186
+ m.name = name
164
187
  end sub
165
188
  end class
166
189
  class Duck extends Bird
167
190
  sub new()
168
191
  m.name = m.name + "Duck"
169
- super(m.name)
192
+ super("Flappy")
170
193
  end sub
171
194
  end class
172
195
  `);
173
196
  program.validate();
174
- (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(7, 24, 7, 25) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(7, 33, 7, 34) })]);
197
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(9, 24, 9, 25) }), Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.classConstructorIllegalUseOfMBeforeSuperCall()), { range: vscode_languageserver_1.Range.create(9, 33, 9, 34) })]);
175
198
  });
176
199
  });
177
200
  describe('transpile', () => {
@@ -186,23 +209,23 @@ describe('BrsFile BrighterScript classes', () => {
186
209
  end sub
187
210
  end class
188
211
  `);
189
- (0, chai_1.expect)(file.ast.statements[1].body[0].func.body.statements[0].expression.callee.name.text).to.eql('super');
190
- await program.transpile([], stagingDir);
191
- (0, chai_1.expect)(file.ast.statements[1].body[0].func.body.statements[0].expression.callee.name.text).to.eql('super');
212
+ (0, chai_config_spec_1.expect)(file.ast.statements[1].body[0].func.body.statements[0].expression.callee.tokens.name.text).to.eql('super');
213
+ await program.getTranspiledFileContents(file.srcPath);
214
+ (0, chai_config_spec_1.expect)(file.ast.statements[1].body[0].func.body.statements[0].expression.callee.tokens.name.text).to.eql('super');
192
215
  });
193
- it('follows correct sequence for property initializers', () => {
194
- testTranspile(`
216
+ it('follows correct sequence for property initializers', async () => {
217
+ await testTranspile(`
195
218
  class Animal
196
219
  species1 = "Animal"
197
220
  sub new()
198
- print "From Animal: " + m.species
221
+ print "From Animal: " + m.species1
199
222
  end sub
200
223
  end class
201
224
  class Duck extends Animal
202
225
  species2 = "Duck"
203
226
  sub new()
204
227
  super()
205
- print "From Duck: " + m.species
228
+ print "From Duck: " + m.species2
206
229
  end sub
207
230
  end class
208
231
  `, `
@@ -210,7 +233,7 @@ describe('BrsFile BrighterScript classes', () => {
210
233
  instance = {}
211
234
  instance.new = sub()
212
235
  m.species1 = "Animal"
213
- print "From Animal: " + m.species
236
+ print "From Animal: " + m.species1
214
237
  end sub
215
238
  return instance
216
239
  end function
@@ -225,7 +248,7 @@ describe('BrsFile BrighterScript classes', () => {
225
248
  instance.new = sub()
226
249
  m.super0_new()
227
250
  m.species2 = "Duck"
228
- print "From Duck: " + m.species
251
+ print "From Duck: " + m.species2
229
252
  end sub
230
253
  return instance
231
254
  end function
@@ -236,8 +259,84 @@ describe('BrsFile BrighterScript classes', () => {
236
259
  end function
237
260
  `, 'trim', 'source/main.bs');
238
261
  });
239
- it('handles class inheritance inferred constructor calls', () => {
240
- testTranspile(`
262
+ it('allows comments as first line of constructor', async () => {
263
+ await testTranspile(`
264
+ class Animal
265
+ end class
266
+ class Duck extends Animal
267
+ sub new()
268
+ 'comment should not cause double super call
269
+ super()
270
+ end sub
271
+ end class
272
+ `, `
273
+ function __Animal_builder()
274
+ instance = {}
275
+ instance.new = sub()
276
+ end sub
277
+ return instance
278
+ end function
279
+ function Animal()
280
+ instance = __Animal_builder()
281
+ instance.new()
282
+ return instance
283
+ end function
284
+ function __Duck_builder()
285
+ instance = __Animal_builder()
286
+ instance.super0_new = instance.new
287
+ instance.new = sub()
288
+ 'comment should not cause double super call
289
+ m.super0_new()
290
+ end sub
291
+ return instance
292
+ end function
293
+ function Duck()
294
+ instance = __Duck_builder()
295
+ instance.new()
296
+ return instance
297
+ end function
298
+ `);
299
+ });
300
+ it('does not inject a call to super if one exists', async () => {
301
+ await testTranspile(`
302
+ class Animal
303
+ end class
304
+ class Duck extends Animal
305
+ sub new()
306
+ print "I am a statement which does not use m"
307
+ super()
308
+ end sub
309
+ end class
310
+ `, `
311
+ function __Animal_builder()
312
+ instance = {}
313
+ instance.new = sub()
314
+ end sub
315
+ return instance
316
+ end function
317
+ function Animal()
318
+ instance = __Animal_builder()
319
+ instance.new()
320
+ return instance
321
+ end function
322
+ function __Duck_builder()
323
+ instance = __Animal_builder()
324
+ instance.super0_new = instance.new
325
+ instance.new = sub()
326
+ print "I am a statement which does not use m"
327
+ m.super0_new()
328
+ end sub
329
+ return instance
330
+ end function
331
+ function Duck()
332
+ instance = __Duck_builder()
333
+ instance.new()
334
+ return instance
335
+ end function
336
+ `);
337
+ });
338
+ it('handles class inheritance inferred constructor calls', async () => {
339
+ await testTranspile(`
241
340
  class Animal
242
341
  className1 = "Animal"
243
342
  end class
@@ -290,8 +389,8 @@ describe('BrsFile BrighterScript classes', () => {
290
389
  end function
291
390
  `, undefined, 'source/main.bs');
292
391
  });
293
- it('works with namespaces', () => {
294
- testTranspile(`
392
+ it('works with namespaces', async () => {
393
+ await testTranspile(`
295
394
  namespace Birds.WaterFowl
296
395
  class Duck
297
396
  end class
@@ -325,8 +424,8 @@ describe('BrsFile BrighterScript classes', () => {
325
424
  end function
326
425
  `, undefined, 'source/main.bs');
327
426
  });
328
- it('works for simple class', () => {
329
- testTranspile(`
427
+ it('works for simple class', async () => {
428
+ await testTranspile(`
330
429
  class Duck
331
430
  end class
332
431
  `, `
@@ -343,8 +442,8 @@ describe('BrsFile BrighterScript classes', () => {
343
442
  end function
344
443
  `, undefined, 'source/main.bs');
345
444
  });
346
- it('registers the constructor and properly handles its parameters', () => {
347
- testTranspile(`
445
+ it('registers the constructor and properly handles its parameters', async () => {
446
+ await testTranspile(`
348
447
  class Duck
349
448
  sub new(name as string, age as integer)
350
449
  end sub
@@ -363,8 +462,8 @@ describe('BrsFile BrighterScript classes', () => {
363
462
  end function
364
463
  `, undefined, 'source/main.bs');
365
464
  });
366
- it('properly handles child class constructor override and super calls', () => {
367
- testTranspile(`
465
+ it('properly handles child class constructor override and super calls', async () => {
466
+ await testTranspile(`
368
467
  class Animal
369
468
  sub new(name as string)
370
469
  end sub
@@ -409,8 +508,8 @@ describe('BrsFile BrighterScript classes', () => {
409
508
  end function
410
509
  `, undefined, 'source/main.bs');
411
510
  });
412
- it('transpiles super in nested blocks', () => {
413
- testTranspile(`
511
+ it('transpiles super in nested blocks', async () => {
512
+ await testTranspile(`
414
513
  class Creature
415
514
  sub new(name as string)
416
515
  end sub
@@ -464,7 +563,7 @@ describe('BrsFile BrighterScript classes', () => {
464
563
  end function
465
564
  `, 'trim', 'source/main.bs');
466
565
  });
467
- it('properly transpiles classes from outside current namespace', () => {
566
+ it('properly transpiles classes from outside current namespace', async () => {
468
567
  addFile('source/Animals.bs', `
469
568
  namespace Animals
470
569
  class Duck
@@ -473,7 +572,7 @@ describe('BrsFile BrighterScript classes', () => {
473
572
  class Bird
474
573
  end class
475
574
  `);
476
- testTranspile(`
575
+ await testTranspile(`
477
576
  namespace Animals
478
577
  sub init()
479
578
  donaldDuck = new Duck()
@@ -489,8 +588,8 @@ describe('BrsFile BrighterScript classes', () => {
489
588
  end sub
490
589
  `, undefined, 'source/main.bs');
491
590
  });
492
- it('properly transpiles new statement for missing class ', () => {
493
- testTranspile(`
591
+ it('properly transpiles new statement for missing class ', async () => {
592
+ await testTranspile(`
494
593
  sub main()
495
594
  bob = new Human()
496
595
  end sub
@@ -500,14 +599,14 @@ describe('BrsFile BrighterScript classes', () => {
500
599
  end sub
501
600
  `, undefined, 'source/main.bs', false);
502
601
  });
503
- it('new keyword transpiles correctly', () => {
602
+ it('new keyword transpiles correctly', async () => {
504
603
  addFile('source/Animal.bs', `
505
604
  class Animal
506
605
  sub new(name as string)
507
606
  end sub
508
607
  end class
509
608
  `);
510
- testTranspile(`
609
+ await testTranspile(`
511
610
  sub main()
512
611
  a = new Animal("donald")
513
612
  end sub
@@ -517,8 +616,8 @@ describe('BrsFile BrighterScript classes', () => {
517
616
  end sub
518
617
  `, undefined, 'source/main.bs');
519
618
  });
520
- it('calls super ', () => {
521
- const { file } = testTranspile(`
619
+ it('calls super ', async () => {
620
+ const { file } = await testTranspile(`
522
621
  class Parent
523
622
  sub new()
524
623
  end sub
@@ -555,10 +654,10 @@ describe('BrsFile BrighterScript classes', () => {
555
654
  `, undefined, undefined, false);
556
655
  //the AST should not be permanently modified
557
656
  const constructor = file.ast.statements[0].body[0];
558
- (0, chai_1.expect)(constructor.func.body.statements).to.be.lengthOf(0);
657
+ (0, chai_config_spec_1.expect)(constructor.func.body.statements).to.be.lengthOf(0);
559
658
  });
560
- it('adds field initializers', () => {
561
- const { file } = testTranspile(`
659
+ it('adds field initializers', async () => {
660
+ const { file } = await testTranspile(`
562
661
  class Person
563
662
  sub new()
564
663
  end sub
@@ -580,10 +679,10 @@ describe('BrsFile BrighterScript classes', () => {
580
679
  `);
581
680
  //the AST should not be permanently modified
582
681
  const constructor = file.ast.statements[0].body[0];
583
- (0, chai_1.expect)(constructor.func.body.statements).to.be.lengthOf(0);
682
+ (0, chai_config_spec_1.expect)(constructor.func.body.statements).to.be.lengthOf(0);
584
683
  });
585
- it('does not screw up local variable references', () => {
586
- testTranspile(`
684
+ it('does not screw up local variable references', async () => {
685
+ await testTranspile(`
587
686
  class Animal
588
687
  sub new(name as string)
589
688
  m.name = name
@@ -690,8 +789,8 @@ describe('BrsFile BrighterScript classes', () => {
690
789
  end sub
691
790
  `, 'trim', 'source/main.bs');
692
791
  });
693
- it('calculates the proper super index', () => {
694
- testTranspile(`
792
+ it('calculates the proper super index', async () => {
793
+ await testTranspile(`
695
794
  class Duck
696
795
  public sub walk(meters as integer)
697
796
  print "Walked " + meters.ToStr() + " meters"
@@ -739,9 +838,308 @@ describe('BrsFile BrighterScript classes', () => {
739
838
  end function
740
839
  `, 'trim', 'source/main.bs');
741
840
  });
841
+ it('adds namespacing to constructors on field definitions', async () => {
842
+ await testTranspile(`
843
+ namespace MyNS
844
+ class KlassOne
845
+ other = new KlassTwo()
846
+ end class
847
+
848
+ class KlassTwo
849
+ end class
850
+ end namespace
851
+ `, `
852
+ function __MyNS_KlassOne_builder()
853
+ instance = {}
854
+ instance.new = sub()
855
+ m.other = MyNS_KlassTwo()
856
+ end sub
857
+ return instance
858
+ end function
859
+ function MyNS_KlassOne()
860
+ instance = __MyNS_KlassOne_builder()
861
+ instance.new()
862
+ return instance
863
+ end function
864
+ function __MyNS_KlassTwo_builder()
865
+ instance = {}
866
+ instance.new = sub()
867
+ end sub
868
+ return instance
869
+ end function
870
+ function MyNS_KlassTwo()
871
+ instance = __MyNS_KlassTwo_builder()
872
+ instance.new()
873
+ return instance
874
+ end function
875
+ `, 'trim', 'source/main.bs');
876
+ });
877
+ it('works with enums as field initial values inside a namespace', async () => {
878
+ await testTranspile(`
879
+ namespace MyNS
880
+ class HasEnumKlass
881
+ enumValue = MyEnum.A
882
+ end class
883
+ enum MyEnum
884
+ A = "A"
885
+ B = "B"
886
+ end enum
887
+ end namespace
888
+ `, `
889
+ function __MyNS_HasEnumKlass_builder()
890
+ instance = {}
891
+ instance.new = sub()
892
+ m.enumValue = "A"
893
+ end sub
894
+ return instance
895
+ end function
896
+ function MyNS_HasEnumKlass()
897
+ instance = __MyNS_HasEnumKlass_builder()
898
+ instance.new()
899
+ return instance
900
+ end function
901
+ `, 'trim', 'source/main.bs');
902
+ });
903
+ it('allows enums as super args inside a namespace', async () => {
904
+ await testTranspile(`
905
+ namespace MyNS
906
+ class SubKlass extends SuperKlass
907
+ sub new()
908
+ super(MyEnum.B)
909
+ end sub
910
+ end class
911
+
912
+ class SuperKlass
913
+ sub new(enumVal as MyEnum)
914
+ print enumVal
915
+ end sub
916
+ end class
917
+
918
+ enum MyEnum
919
+ A = "A"
920
+ B = "B"
921
+ end enum
922
+ end namespace
923
+ `, `
924
+ function __MyNS_SubKlass_builder()
925
+ instance = __MyNS_SuperKlass_builder()
926
+ instance.super0_new = instance.new
927
+ instance.new = sub()
928
+ m.super0_new("B")
929
+ end sub
930
+ return instance
931
+ end function
932
+ function MyNS_SubKlass()
933
+ instance = __MyNS_SubKlass_builder()
934
+ instance.new()
935
+ return instance
936
+ end function
937
+ function __MyNS_SuperKlass_builder()
938
+ instance = {}
939
+ instance.new = sub(enumVal as dynamic)
940
+ print enumVal
941
+ end sub
942
+ return instance
943
+ end function
944
+ function MyNS_SuperKlass(enumVal as dynamic)
945
+ instance = __MyNS_SuperKlass_builder()
946
+ instance.new(enumVal)
947
+ return instance
948
+ end function
949
+ `, 'trim', 'source/main.bs');
950
+ });
951
+ it('works with enums as values referenced in a namespace directly', async () => {
952
+ await testTranspile(`
953
+ namespace MyNS
954
+ class HasEnumKlass
955
+ myArray = [true, true] as boolean[]
956
+ sub new()
957
+ m.myArray[MyEnum.A] = true
958
+ m.myArray[MyEnum.B] = false
959
+ end sub
960
+ end class
961
+ enum MyEnum
962
+ A = 0
963
+ B = 1
964
+ end enum
965
+ end namespace
966
+ `, `
967
+ function __MyNS_HasEnumKlass_builder()
968
+ instance = {}
969
+ instance.new = sub()
970
+ m.myArray = [
971
+ true
972
+ true
973
+ ]
974
+ m.myArray[0] = true
975
+ m.myArray[1] = false
976
+ end sub
977
+ return instance
978
+ end function
979
+ function MyNS_HasEnumKlass()
980
+ instance = __MyNS_HasEnumKlass_builder()
981
+ instance.new()
982
+ return instance
983
+ end function
984
+ `, 'trim', 'source/main.bs');
985
+ });
986
+ it('works with enums as values referenced in a namespace with namespace', async () => {
987
+ await testTranspile(`
988
+ namespace MyNS
989
+ class HasEnumKlass
990
+ myArray = [true, true] as boolean[]
991
+ sub new()
992
+ m.myArray[MyNS.MyEnum.A] = true
993
+ m.myArray[MyNS.MyEnum.B] = false
994
+ end sub
995
+ end class
996
+ enum MyEnum
997
+ A = 0
998
+ B = 1
999
+ end enum
1000
+ end namespace
1001
+ `, `
1002
+ function __MyNS_HasEnumKlass_builder()
1003
+ instance = {}
1004
+ instance.new = sub()
1005
+ m.myArray = [
1006
+ true
1007
+ true
1008
+ ]
1009
+ m.myArray[0] = true
1010
+ m.myArray[1] = false
1011
+ end sub
1012
+ return instance
1013
+ end function
1014
+ function MyNS_HasEnumKlass()
1015
+ instance = __MyNS_HasEnumKlass_builder()
1016
+ instance.new()
1017
+ return instance
1018
+ end function
1019
+ `, 'trim', 'source/main.bs');
1020
+ });
1021
+ it('allows namespaced class function as function parameters', async () => {
1022
+ await testTranspile(`
1023
+ namespace Alpha
1024
+ function foo()
1025
+ return 1
1026
+ end function
1027
+
1028
+ function callSomeFunc(f as function)
1029
+ return f()
1030
+ end function
1031
+
1032
+ sub callFoo()
1033
+ callSomeFunc(foo)
1034
+ end sub
1035
+ end namespace
1036
+ `, `
1037
+ function Alpha_foo()
1038
+ return 1
1039
+ end function
1040
+
1041
+ function Alpha_callSomeFunc(f as function)
1042
+ return f()
1043
+ end function
1044
+
1045
+ sub Alpha_callFoo()
1046
+ Alpha_callSomeFunc(Alpha_foo)
1047
+ end sub
1048
+ `, 'trim', 'source/main.bs');
1049
+ });
1050
+ it('allows namespaced class constructors as function parameters', async () => {
1051
+ await testTranspile(`
1052
+ namespace Alpha
1053
+ class Button
1054
+ end class
1055
+
1056
+ function callSomeFunc(f as function)
1057
+ return f()
1058
+ end function
1059
+
1060
+ sub makeButton()
1061
+ callSomeFunc(Button)
1062
+ end sub
1063
+ end namespace
1064
+ `, `
1065
+ function __Alpha_Button_builder()
1066
+ instance = {}
1067
+ instance.new = sub()
1068
+ end sub
1069
+ return instance
1070
+ end function
1071
+ function Alpha_Button()
1072
+ instance = __Alpha_Button_builder()
1073
+ instance.new()
1074
+ return instance
1075
+ end function
1076
+
1077
+ function Alpha_callSomeFunc(f as function)
1078
+ return f()
1079
+ end function
1080
+
1081
+ sub Alpha_makeButton()
1082
+ Alpha_callSomeFunc(Alpha_Button)
1083
+ end sub
1084
+ `, 'trim', 'source/main.bs');
1085
+ });
1086
+ it('allows class constructors as functions in array', async () => {
1087
+ await testTranspile(`
1088
+ namespace Alpha
1089
+ class Button
1090
+ end class
1091
+
1092
+ class ButtonContainer
1093
+ private button = new Alpha.Button()
1094
+
1095
+ sub new()
1096
+ m.init()
1097
+ end sub
1098
+
1099
+ sub init()
1100
+ button = new Alpha.Button()
1101
+ items = [m.button, button, Alpha.Button]
1102
+ end sub
1103
+ end class
1104
+ end namespace
1105
+ `, `
1106
+ function __Alpha_Button_builder()
1107
+ instance = {}
1108
+ instance.new = sub()
1109
+ end sub
1110
+ return instance
1111
+ end function
1112
+ function Alpha_Button()
1113
+ instance = __Alpha_Button_builder()
1114
+ instance.new()
1115
+ return instance
1116
+ end function
1117
+ function __Alpha_ButtonContainer_builder()
1118
+ instance = {}
1119
+ instance.new = sub()
1120
+ m.button = Alpha_Button()
1121
+ m.init()
1122
+ end sub
1123
+ instance.init = sub()
1124
+ button = Alpha_Button()
1125
+ items = [
1126
+ m.button
1127
+ Alpha_button
1128
+ Alpha_Button
1129
+ ]
1130
+ end sub
1131
+ return instance
1132
+ end function
1133
+ function Alpha_ButtonContainer()
1134
+ instance = __Alpha_ButtonContainer_builder()
1135
+ instance.new()
1136
+ return instance
1137
+ end function
1138
+ `, 'trim', 'source/main.bs');
1139
+ });
742
1140
  });
743
1141
  it('detects using `new` keyword on non-classes', () => {
744
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
1142
+ program.setFile('source/main.bs', `
745
1143
  sub quack()
746
1144
  end sub
747
1145
  sub main()
@@ -754,13 +1152,13 @@ describe('BrsFile BrighterScript classes', () => {
754
1152
  ]);
755
1153
  });
756
1154
  it('detects missing call to super', () => {
757
- program.setFile({ src: `${rootDir}/source/main.bs`, dest: 'source/main.brs' }, `
1155
+ program.setFile('source/main.bs', `
758
1156
  class Animal
759
- sub new ()
1157
+ sub new()
760
1158
  end sub
761
1159
  end class
762
1160
  class Duck extends Animal
763
- sub new ()
1161
+ sub new()
764
1162
  end sub
765
1163
  end class
766
1164
  `);
@@ -770,9 +1168,9 @@ describe('BrsFile BrighterScript classes', () => {
770
1168
  ]);
771
1169
  });
772
1170
  it.skip('detects calls to unknown m methods', () => {
773
- program.setFile('source/main.brs', `
1171
+ program.setFile('source/main.bs', `
774
1172
  class Animal
775
- sub new ()
1173
+ sub new()
776
1174
  m.methodThatDoesNotExist()
777
1175
  end sub
778
1176
  end class
@@ -792,7 +1190,7 @@ describe('BrsFile BrighterScript classes', () => {
792
1190
  end class
793
1191
  `);
794
1192
  program.validate();
795
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
1193
+ (0, chai_config_spec_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
796
1194
  DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Child', 'Parent', 'Child'], 'source').message,
797
1195
  DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Parent', 'Child', 'Parent'], 'source').message
798
1196
  ]);
@@ -810,7 +1208,7 @@ describe('BrsFile BrighterScript classes', () => {
810
1208
  end class
811
1209
  `);
812
1210
  program.validate();
813
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
1211
+ (0, chai_config_spec_1.expect)(program.getDiagnostics().map(x => x.message).sort()).to.eql([
814
1212
  DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Child', 'Parent', 'Grandchild', 'Child'], 'source').message,
815
1213
  DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Grandchild', 'Child', 'Parent', 'Grandchild'], 'source').message,
816
1214
  DiagnosticMessages_1.DiagnosticMessages.circularReferenceDetected(['Parent', 'Grandchild', 'Child', 'Parent'], 'source').message
@@ -830,10 +1228,10 @@ describe('BrsFile BrighterScript classes', () => {
830
1228
  end function
831
1229
  end class
832
1230
  `);
833
- await program.transpile([], stagingDir);
834
- fsExtra.emptyDirSync(stagingDir);
835
- await program.transpile([], stagingDir);
836
- (0, chai_1.expect)(fsExtra.readFileSync((0, util_1.standardizePath) `${stagingDir}/source/lib.brs`).toString().trimEnd()).to.eql((0, testHelpers_spec_1.trim) `
1231
+ await program.build({ stagingDir: testHelpers_spec_2.stagingDir });
1232
+ fsExtra.emptyDirSync(testHelpers_spec_2.stagingDir);
1233
+ await program.build({ stagingDir: testHelpers_spec_2.stagingDir });
1234
+ (0, chai_config_spec_1.expect)(fsExtra.readFileSync((0, util_1.standardizePath) `${testHelpers_spec_2.stagingDir}/source/lib.brs`).toString().trimEnd()).to.eql((0, testHelpers_spec_1.trim) `
837
1235
  function __Being_builder()
838
1236
  instance = {}
839
1237
  instance.new = sub()
@@ -931,15 +1329,14 @@ describe('BrsFile BrighterScript classes', () => {
931
1329
  public owner as Person
932
1330
  end class
933
1331
  class Duck extends Bird
934
- public age = 12.2 'should be integer but is float
1332
+ public age = 12.2 'should be integer, but a float can be assigned to an int
935
1333
  public name = 12 'should be string but is integer
936
1334
  public owner as string
937
1335
  end class
938
1336
  `);
939
1337
  program.validate();
940
1338
  (0, testHelpers_spec_1.expectDiagnostics)(program, [
941
- DiagnosticMessages_1.DiagnosticMessages.cannotFindType('Person'),
942
- DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'age', 'float', 'integer'),
1339
+ DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Person'),
943
1340
  DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'name', 'integer', 'string'),
944
1341
  DiagnosticMessages_1.DiagnosticMessages.childFieldTypeNotAssignableToBaseProperty('Duck', 'Bird', 'owner', 'string', 'Person')
945
1342
  ]);
@@ -1016,11 +1413,11 @@ describe('BrsFile BrighterScript classes', () => {
1016
1413
  end sub
1017
1414
  end class
1018
1415
 
1019
- namespace Vertibrates
1416
+ namespace Vertibrates
1020
1417
  class Animal
1021
1418
  end class
1022
- end namespace
1023
- `);
1419
+ end namespace
1420
+ `);
1024
1421
  program.validate();
1025
1422
  (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Animal')), { range: vscode_languageserver_1.Range.create(1, 35, 1, 41) })]);
1026
1423
  });
@@ -1031,8 +1428,8 @@ describe('BrsFile BrighterScript classes', () => {
1031
1428
  sub speak()
1032
1429
  end sub
1033
1430
  end class
1034
- end namespace
1035
- `);
1431
+ end namespace
1432
+ `);
1036
1433
  program.validate();
1037
1434
  (0, testHelpers_spec_1.expectDiagnostics)(program, [
1038
1435
  DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Animal')
@@ -1043,7 +1440,7 @@ describe('BrsFile BrighterScript classes', () => {
1043
1440
  namespace Vertibrates
1044
1441
  class Animal
1045
1442
  end class
1046
- end namespace
1443
+ end namespace
1047
1444
 
1048
1445
  class Duck extends Animal
1049
1446
  sub speak()
@@ -1069,9 +1466,9 @@ describe('BrsFile BrighterScript classes', () => {
1069
1466
  end class
1070
1467
  `);
1071
1468
  program.validate();
1072
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1073
- DiagnosticMessages_1.DiagnosticMessages.cannotFindName('GroundedBird', 'Vertibrates.GroundedBird')
1074
- ]);
1469
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotFindName('GroundedBird', 'Vertibrates.GroundedBird')), { relatedInformation: [{
1470
+ message: `In scope 'source'`
1471
+ }] })]);
1075
1472
  });
1076
1473
  it('namespaced parent class from inside namespace', () => {
1077
1474
  program.setFile('source/vertibrates.bs', `
@@ -1089,9 +1486,9 @@ describe('BrsFile BrighterScript classes', () => {
1089
1486
  end namespace
1090
1487
  `);
1091
1488
  program.validate();
1092
- (0, testHelpers_spec_1.expectDiagnostics)(program, [Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.cannotFindName('GroundedBird', 'Vertibrates.GroundedBird')), { relatedInformation: [{
1093
- message: `Not defined in scope 'source'`
1094
- }] })]);
1489
+ (0, testHelpers_spec_1.expectDiagnostics)(program, [
1490
+ DiagnosticMessages_1.DiagnosticMessages.cannotFindName('GroundedBird', 'Vertibrates.GroundedBird').message
1491
+ ]);
1095
1492
  });
1096
1493
  });
1097
1494
  it('catches newable class without namespace name', () => {
@@ -1099,12 +1496,12 @@ describe('BrsFile BrighterScript classes', () => {
1099
1496
  namespace NameA.NameB
1100
1497
  class Duck
1101
1498
  end class
1102
- end namespace
1499
+ end namespace
1103
1500
  sub main()
1104
1501
  ' this should be an error because the proper name is NameA.NameB.Duck"
1105
1502
  d = new Duck()
1106
1503
  end sub
1107
- `);
1504
+ `);
1108
1505
  program.validate();
1109
1506
  (0, testHelpers_spec_1.expectDiagnostics)(program, [
1110
1507
  DiagnosticMessages_1.DiagnosticMessages.cannotFindName('Duck')
@@ -1115,11 +1512,11 @@ describe('BrsFile BrighterScript classes', () => {
1115
1512
  namespace NameA.NameB
1116
1513
  class Duck
1117
1514
  end class
1118
- sub main()
1515
+ sub main()
1119
1516
  d = new Duck()
1120
1517
  end sub
1121
1518
  end namespace
1122
- `);
1519
+ `);
1123
1520
  program.validate();
1124
1521
  (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1125
1522
  });
@@ -1144,8 +1541,8 @@ describe('BrsFile BrighterScript classes', () => {
1144
1541
  end class
1145
1542
  class Duck extends Animal
1146
1543
  end class
1147
- end namespace
1148
- `);
1544
+ end namespace
1545
+ `);
1149
1546
  program.validate();
1150
1547
  (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1151
1548
  });
@@ -1157,8 +1554,8 @@ describe('BrsFile BrighterScript classes', () => {
1157
1554
  end class
1158
1555
  `);
1159
1556
  program.validate();
1160
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1161
- DiagnosticMessages_1.DiagnosticMessages.duplicateClassDeclaration('source', 'Animal')
1557
+ (0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
1558
+ DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Class', 'Animal')
1162
1559
  ]);
1163
1560
  });
1164
1561
  it('catches duplicate namespace-level class declarations', () => {
@@ -1171,8 +1568,8 @@ describe('BrsFile BrighterScript classes', () => {
1171
1568
  end namespace
1172
1569
  `);
1173
1570
  program.validate();
1174
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1175
- DiagnosticMessages_1.DiagnosticMessages.duplicateClassDeclaration('source', 'NameA.NameB.Animal')
1571
+ (0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
1572
+ DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Class', 'Animal').message
1176
1573
  ]);
1177
1574
  });
1178
1575
  it('catches namespaced class name which is the same as a global class', () => {
@@ -1180,24 +1577,24 @@ describe('BrsFile BrighterScript classes', () => {
1180
1577
  namespace NameA.NameB
1181
1578
  class Animal
1182
1579
  end class
1183
- end namespace
1580
+ end namespace
1184
1581
  class Animal
1185
1582
  end class
1186
1583
  `);
1187
1584
  program.validate();
1188
1585
  (0, testHelpers_spec_1.expectDiagnostics)(program, [
1189
- DiagnosticMessages_1.DiagnosticMessages.namespacedClassCannotShareNamewithNonNamespacedClass('Animal').message
1586
+ DiagnosticMessages_1.DiagnosticMessages.nameCollision('Class', 'Class', 'Animal').message
1190
1587
  ]);
1191
1588
  });
1192
1589
  it('catches class with same name as function', () => {
1193
1590
  program.setFile('source/main.bs', `
1194
1591
  class Animal
1195
1592
  end class
1196
- sub Animal()
1593
+ sub Animal()
1197
1594
  end sub
1198
- `);
1595
+ `);
1199
1596
  program.validate();
1200
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1597
+ (0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
1201
1598
  DiagnosticMessages_1.DiagnosticMessages.functionCannotHaveSameNameAsClass('Animal').message
1202
1599
  ]);
1203
1600
  });
@@ -1205,11 +1602,11 @@ describe('BrsFile BrighterScript classes', () => {
1205
1602
  program.setFile('source/main.bs', `
1206
1603
  class ANIMAL
1207
1604
  end class
1208
- sub animal()
1605
+ sub animal()
1209
1606
  end sub
1210
- `);
1607
+ `);
1211
1608
  program.validate();
1212
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1609
+ (0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [
1213
1610
  DiagnosticMessages_1.DiagnosticMessages.functionCannotHaveSameNameAsClass('animal').message
1214
1611
  ]);
1215
1612
  });
@@ -1217,10 +1614,10 @@ describe('BrsFile BrighterScript classes', () => {
1217
1614
  program.setFile('source/main.bs', `
1218
1615
  class Animal
1219
1616
  end class
1220
- sub main()
1617
+ sub main()
1221
1618
  animal = new Animal()
1222
1619
  end sub
1223
- `);
1620
+ `);
1224
1621
  program.validate();
1225
1622
  (0, testHelpers_spec_1.expectDiagnostics)(program, [
1226
1623
  DiagnosticMessages_1.DiagnosticMessages.localVarSameNameAsClass('Animal').message
@@ -1232,21 +1629,21 @@ describe('BrsFile BrighterScript classes', () => {
1232
1629
  end class
1233
1630
 
1234
1631
  class Bar extends Foo
1235
- sub new ()
1632
+ sub new()
1236
1633
  super()
1237
1634
  end sub
1238
1635
  end class
1239
1636
  `);
1240
1637
  program.setFile('source/testclass_no_testdot.bs', `
1241
1638
  class BarNoDot extends Foo
1242
- sub new ()
1639
+ sub new()
1243
1640
  super()
1244
1641
  end sub
1245
1642
  end class
1246
1643
  `);
1247
1644
  program.setFile('source/testclass.dot.bs', `
1248
1645
  class BarDot extends Foo
1249
- sub new ()
1646
+ sub new()
1250
1647
  super()
1251
1648
  end sub
1252
1649
  end class
@@ -1254,7 +1651,7 @@ describe('BrsFile BrighterScript classes', () => {
1254
1651
  program.validate();
1255
1652
  (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1256
1653
  });
1257
- it('computes correct super index for grandchild class', () => {
1654
+ it('computes correct super index for grandchild class', async () => {
1258
1655
  program.setFile('source/main.bs', `
1259
1656
  sub Main()
1260
1657
  c = new App.ClassC()
@@ -1268,10 +1665,10 @@ describe('BrsFile BrighterScript classes', () => {
1268
1665
  end class
1269
1666
  end namespace
1270
1667
  `);
1271
- testTranspile(`
1668
+ await testTranspile(`
1272
1669
  namespace App
1273
1670
  class ClassC extends ClassB
1274
- sub new ()
1671
+ sub new()
1275
1672
  super()
1276
1673
  end sub
1277
1674
  end class
@@ -1292,17 +1689,17 @@ describe('BrsFile BrighterScript classes', () => {
1292
1689
  end function
1293
1690
  `, 'trim', 'source/App.ClassC.bs');
1294
1691
  });
1295
- it('computes correct super index for namespaced child class and global parent class', () => {
1692
+ it('computes correct super index for namespaced child class and global parent class', async () => {
1296
1693
  program.setFile('source/ClassA.bs', `
1297
1694
  class ClassA
1298
1695
  end class
1299
1696
  `);
1300
- testTranspile(`
1697
+ await testTranspile(`
1301
1698
  namespace App
1302
1699
  class ClassB extends ClassA
1303
1700
  end class
1304
1701
  end namespace
1305
- `, `
1702
+ `, `
1306
1703
  function __App_ClassB_builder()
1307
1704
  instance = __ClassA_builder()
1308
1705
  instance.super0_new = instance.new
@@ -1324,375 +1721,8 @@ describe('BrsFile BrighterScript classes', () => {
1324
1721
  end class
1325
1722
  `);
1326
1723
  (0, assert_1.doesNotThrow)(() => {
1327
- file.parser.references.classStatements[0]['getParentClassIndex'](new BrsTranspileState_1.BrsTranspileState(file));
1328
- });
1329
- });
1330
- describe('getHover', () => {
1331
- const animalClassCode = `
1332
- class Animal
1333
- kind as string
1334
- isHungry as boolean
1335
-
1336
- sub new (kind as string)
1337
- m.kind = kind
1338
- m.isHungry = true ' born hungry
1339
- end sub
1340
-
1341
- sub eat(foodAmount as integer)
1342
- if foodAmount > 100
1343
- m.isHungry = false
1344
- end if
1345
- end sub
1346
-
1347
- sub sleep()
1348
- m.isHungry = false
1349
- end sub
1350
-
1351
- end class
1352
-
1353
- class Dog extends Animal
1354
- breed as string
1355
- sub new (breed as string)
1356
- super("Dog")
1357
- m.breed = breed
1358
- end sub
1359
-
1360
- sub snooze()
1361
- m.sleep()
1362
- end sub
1363
- end class
1364
-
1365
- class DogHouse
1366
- puppy as Dog
1367
- sub new (pup as Dog)
1368
- m.puppy = pup
1369
- end sub
1370
- end class
1371
-
1372
- sub main()
1373
- snoopy = new Dog("Beagle")
1374
- biplane = new DogHouse(snoopy)
1375
- print snoopy.kind ' Dog
1376
- print snoopy.breed ' Beagle
1377
- print snoopy.isHungry ' true
1378
- feedAnimal(biplane.puppy)
1379
- print snoopy.isHungry ' false
1380
- end sub
1381
-
1382
- sub feedAnimal(beast as Animal)
1383
- beast.eat(100)
1384
- end sub
1385
- `;
1386
- it('correctly parses the file', () => {
1387
- program.setFile('source/animal.bs', animalClassCode);
1388
- program.validate();
1389
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1390
- });
1391
- it('gets the correct text for m', () => {
1392
- var _a, _b;
1393
- let animalCode = program.setFile('source/animal.bs', animalClassCode);
1394
- program.validate();
1395
- let hover = program.getHover(animalCode.srcPath, vscode_languageserver_1.Position.create(6, 21));
1396
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1397
- '```brightscript',
1398
- 'm as Animal',
1399
- '```'
1400
- ].join('\n'));
1401
- hover = program.getHover(animalCode.srcPath, vscode_languageserver_1.Position.create(26, 20));
1402
- (0, chai_1.expect)((_b = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _b === void 0 ? void 0 : _b.contents).to.equal([
1403
- '```brightscript',
1404
- 'm as Dog',
1405
- '```'
1406
- ].join('\n'));
1407
- });
1408
- it('gets the correct text for m.field', () => {
1409
- var _a, _b;
1410
- let animalCode = program.setFile('source/animal.bs', animalClassCode);
1411
- program.validate();
1412
- let hover = program.getHover(animalCode.srcPath, vscode_languageserver_1.Position.create(6, 26));
1413
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1414
- '```brightscript',
1415
- 'Animal.kind as string',
1416
- '```'
1417
- ].join('\n'));
1418
- hover = program.getHover(animalCode.srcPath, vscode_languageserver_1.Position.create(26, 25));
1419
- (0, chai_1.expect)((_b = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _b === void 0 ? void 0 : _b.contents).to.equal([
1420
- '```brightscript',
1421
- 'Dog.breed as string',
1422
- '```'
1423
- ].join('\n'));
1424
- });
1425
- it('gets the correct text for m.method', () => {
1426
- var _a;
1427
- let animalCode = program.setFile('source/animal.bs', animalClassCode);
1428
- program.validate();
1429
- let hover = program.getHover(animalCode.srcPath, vscode_languageserver_1.Position.create(30, 25));
1430
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1431
- '```brightscript',
1432
- 'sub Animal.sleep() as void',
1433
- '```'
1434
- ].join('\n'));
1435
- });
1436
- it('gets the correct text for obj.field', () => {
1437
- var _a;
1438
- let animalCode = program.setFile('source/animal.brs', animalClassCode);
1439
- program.validate();
1440
- let hover = program.getHover(animalCode.srcPath, vscode_languageserver_1.Position.create(46, 33));
1441
- (0, chai_1.expect)(hover).to.exist;
1442
- //TODO TYPES: This should probably say 'Animal.isHungry ...' because that field is defined in Animal
1443
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1444
- '```brightscript',
1445
- 'Dog.isHungry as boolean',
1446
- '```'
1447
- ].join('\n'));
1448
- });
1449
- it('gets the correct text for obj.method', () => {
1450
- var _a;
1451
- let animalCode = program.setFile('source/animal.bs', `
1452
- sub feedAnimal(beast as Animal)
1453
- beast.eat(100)
1454
- end sub
1455
- class Animal
1456
- sub eat(foodAmount as integer)
1457
- end sub
1458
- end class
1459
- `);
1460
- program.validate();
1461
- let hover = program.getHover(animalCode.srcPath, vscode_languageserver_1.Position.create(2, 29));
1462
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1463
- '```brightscript',
1464
- 'sub Animal.eat(foodAmount as integer) as void',
1465
- '```'
1466
- ].join('\n'));
1467
- });
1468
- });
1469
- describe('getHover class members', () => {
1470
- const testCode = `
1471
- class Foo
1472
- sub new (name as string)
1473
- end sub
1474
- end class
1475
-
1476
- class Bar
1477
- sub doSomething()
1478
- myFoo = new Foo()
1479
- end sub
1480
-
1481
- function getInt() as integer
1482
- return 1
1483
- end function
1484
- end class
1485
-
1486
- class Buz
1487
- myInt as integer
1488
- sub new (i as integer)
1489
- myInt = i
1490
- end sub
1491
- end class
1492
-
1493
- class Bee extends Buz
1494
- sub new (i as integer)
1495
- super(i)
1496
- end sub
1497
-
1498
- sub varSameNameAsMember()
1499
- myInt = 4567
1500
- print myInt ' should not print m.myInt
1501
- end sub
1502
- end class`;
1503
- it('correctly parses the file', () => {
1504
- program.setFile('source/fooBar.bs', testCode);
1505
- program.validate();
1506
- (0, chai_1.expect)(program.getDiagnostics().length).to.equal(0);
1507
- });
1508
- it('gets the correct text for new Class()', () => {
1509
- var _a;
1510
- let file = program.setFile('source/fooBar.bs', testCode);
1511
- program.validate();
1512
- let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(8, 34)); // new Foo("hello")
1513
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1514
- '```brightscript',
1515
- 'new Foo(name as string)',
1516
- '```'
1517
- ].join('\n'));
1518
- });
1519
- it('gets the correct text for created object', () => {
1520
- var _a;
1521
- let file = program.setFile('source/fooBar.bs', testCode);
1522
- program.validate();
1523
- let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(8, 23)); // myFoo
1524
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1525
- '```brightscript',
1526
- 'myFoo as Foo',
1527
- '```'
1528
- ].join('\n'));
1529
- });
1530
- it('gets the correct text for class declaration', () => {
1531
- var _a;
1532
- let file = program.setFile('source/fooBar.bs', testCode);
1533
- program.validate();
1534
- let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(6, 21)); // class Bar
1535
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1536
- '```brightscript',
1537
- 'class Bar',
1538
- '```'
1539
- ].join('\n'));
1540
- });
1541
- it('gets the correct text for class method declaration', () => {
1542
- var _a;
1543
- let file = program.setFile('source/fooBar.bs', testCode);
1544
- program.validate();
1545
- let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(11, 29)); // getInt
1546
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1547
- '```brightscript',
1548
- 'function Bar.getInt() as integer',
1549
- '```'
1550
- ].join('\n'));
1551
- });
1552
- it('gets the correct text for class field declaration', () => {
1553
- var _a;
1554
- let file = program.setFile('source/fooBar.bs', testCode);
1555
- program.validate();
1556
- let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(17, 20)); // myInt
1557
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1558
- '```brightscript',
1559
- 'Buz.myInt as integer',
1560
- '```'
1561
- ].join('\n'));
1562
- });
1563
- it('gets the correct text for super() call', () => {
1564
- var _a;
1565
- let file = program.setFile('source/fooBar.bs', testCode);
1566
- program.validate();
1567
- let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(25, 23)); // super() in Bee.new
1568
- (0, chai_1.expect)((_a = hover === null || hover === void 0 ? void 0 : hover[0]) === null || _a === void 0 ? void 0 : _a.contents).to.equal([
1569
- '```brightscript',
1570
- 'new Buz(i as integer)',
1571
- '```'
1572
- ].join('\n'));
1573
- });
1574
- it('gets the correct text for variable with same name as a member', () => {
1575
- let file = program.setFile('source/fooBar.bs', testCode);
1576
- program.validate();
1577
- let hover = program.getHover(file.srcPath, vscode_languageserver_1.Position.create(29, 23)); // myInt in Bee.varSameNameAsMember
1578
- (0, chai_1.expect)(hover === null || hover === void 0 ? void 0 : hover[0].contents).to.equal([
1579
- '```brightscript',
1580
- 'myInt as integer',
1581
- '```'
1582
- ].join('\n'));
1583
- });
1584
- });
1585
- describe('getSymbolTypeFromToken', () => {
1586
- const testClassCode = `
1587
- sub main()
1588
- c = new KlassC()
1589
- a = c.b.getA()
1590
- num = c.b.getA().getInt()
1591
- c.b.getA().printInt(num)
1592
- end sub
1593
- class KlassA
1594
- function getInt() as integer
1595
- return 1
1596
- end function
1597
-
1598
- sub printInt(i as integer)
1599
- print i
1600
- end sub
1601
- end class
1602
-
1603
- class KlassB
1604
-
1605
- function getA() as KlassA
1606
- return new KlassA()
1607
- end function
1608
- end class
1609
-
1610
- class KlassC
1611
- public b as KlassB
1612
-
1613
- sub new ()
1614
- m.b = new KlassB()
1615
- end sub
1616
- end class
1617
- `;
1618
- it('correctly parses the file', () => {
1619
- program.setFile('source/klassTest.bs', testClassCode);
1620
- program.validate();
1621
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1622
- });
1623
- describe('finding tokens', () => {
1624
- let klassCode;
1625
- let mainScope;
1626
- beforeEach(() => {
1627
- klassCode = program.setFile('source/klassTest.bs', testClassCode);
1628
- const scopes = program.getScopesForFile(klassCode);
1629
- (0, chai_1.expect)(scopes.length).to.eql(1);
1630
- mainScope = scopes[0];
1631
- mainScope.linkSymbolTable();
1632
- });
1633
- afterEach(() => {
1634
- mainScope.unlinkSymbolTable();
1635
- });
1636
- it('gets correct class for m', () => {
1637
- var _a;
1638
- const position = vscode_languageserver_1.Position.create(28, 20); // 'm' from m.b = new KlassB()
1639
- const token = klassCode.parser.getTokenAt(position);
1640
- (0, chai_1.expect)(token.text).to.equal('m');
1641
- const func = klassCode.getFunctionExpressionAtPosition(position);
1642
- let klass = (_a = klassCode.getClassFromToken(token, func, mainScope)) === null || _a === void 0 ? void 0 : _a.item;
1643
- (0, chai_1.expect)(klass).to.exist;
1644
- (0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassC');
1645
- });
1646
- it('gets correct class for fieldMember', () => {
1647
- var _a;
1648
- const position = vscode_languageserver_1.Position.create(28, 23); // 'b' from m.b = new KlassB()
1649
- const token = klassCode.parser.getTokenAt(position);
1650
- (0, chai_1.expect)(token.text).to.equal('b');
1651
- const func = klassCode.getFunctionExpressionAtPosition(position);
1652
- let klass = (_a = klassCode.getClassFromToken(token, func, mainScope)) === null || _a === void 0 ? void 0 : _a.item;
1653
- (0, chai_1.expect)(klass).to.exist;
1654
- (0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassB');
1655
- });
1656
- it('gets correct class for variable', () => {
1657
- var _a;
1658
- const position = vscode_languageserver_1.Position.create(4, 22); // 'c' from c.b.getA().getInt()
1659
- const token = klassCode.parser.getTokenAt(position);
1660
- (0, chai_1.expect)(token.text).to.equal('c');
1661
- const func = klassCode.getFunctionExpressionAtPosition(position);
1662
- let klass = (_a = klassCode.getClassFromToken(token, func, mainScope)) === null || _a === void 0 ? void 0 : _a.item;
1663
- (0, chai_1.expect)(klass).to.exist;
1664
- (0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassC');
1665
- });
1666
- it('gets correct class for variable field', () => {
1667
- var _a;
1668
- const position = vscode_languageserver_1.Position.create(3, 23); // 'b' from c.b.getA()
1669
- const token = klassCode.parser.getTokenAt(position);
1670
- (0, chai_1.expect)(token.text).to.equal('b');
1671
- const func = klassCode.getFunctionExpressionAtPosition(position);
1672
- let klass = (_a = klassCode.getClassFromToken(token, func, mainScope)) === null || _a === void 0 ? void 0 : _a.item;
1673
- (0, chai_1.expect)(klass).to.exist;
1674
- (0, chai_1.expect)(klass.getName(Parser_1.ParseMode.BrighterScript)).to.equal('KlassB');
1675
- });
1676
- it('gets type and return class for variable function field', () => {
1677
- const position = vscode_languageserver_1.Position.create(3, 28); // 'getA' from c.b.getA()
1678
- const token = klassCode.parser.getTokenAt(position);
1679
- (0, chai_1.expect)(token.text).to.equal('getA');
1680
- const func = klassCode.getFunctionExpressionAtPosition(position);
1681
- let { type, symbolContainer } = klassCode.getSymbolTypeFromToken(token, func, mainScope);
1682
- (0, chai_1.expect)((0, reflection_1.isTypedFunctionType)(type)).to.be.true;
1683
- (0, chai_1.expect)((0, reflection_1.isCustomType)(symbolContainer)).to.be.true;
1684
- (0, chai_1.expect)(symbolContainer.name).to.equal('KlassA');
1685
- });
1686
- it('gets type and class for field from return value of function', () => {
1687
- const position = vscode_languageserver_1.Position.create(4, 37); // 'getInt' from c.b.getA().getInt()
1688
- const token = klassCode.parser.getTokenAt(position);
1689
- (0, chai_1.expect)(token.text).to.equal('getInt');
1690
- const func = klassCode.getFunctionExpressionAtPosition(position);
1691
- let { type, symbolContainer } = klassCode.getSymbolTypeFromToken(token, func, mainScope);
1692
- (0, chai_1.expect)(type).to.exist;
1693
- (0, chai_1.expect)((0, reflection_1.isTypedFunctionType)(type)).to.be.true;
1694
- (0, chai_1.expect)(symbolContainer).to.be.undefined; // getInt() returns integer - no class reference at this point
1695
- });
1724
+ const classStatements = file.ast.findChildren(reflection_1.isClassStatement);
1725
+ classStatements[0]['getParentClassIndex'](new BrsTranspileState_1.BrsTranspileState(file));
1696
1726
  });
1697
1727
  });
1698
1728
  it('does not crash when child has field with same name as sub in parent', () => {
@@ -1700,7 +1730,7 @@ describe('BrsFile BrighterScript classes', () => {
1700
1730
  class Parent
1701
1731
  public function helloWorld()
1702
1732
  end function
1703
- end class
1733
+ end class
1704
1734
  class Child extends Parent
1705
1735
  public helloWorld as string
1706
1736
  end class
@@ -1715,28 +1745,28 @@ describe('BrsFile BrighterScript classes', () => {
1715
1745
  class Child extends Parent
1716
1746
  public function helloWorld()
1717
1747
  end function
1718
- end class
1748
+ end class
1719
1749
  `);
1720
1750
  program.validate();
1721
1751
  });
1722
- it.skip('detects calling class constructors with too many parameters', () => {
1752
+ it('detects calling class constructors with too many parameters', () => {
1723
1753
  program.setFile('source/main.bs', `
1724
1754
  class Parameterless
1725
- sub new ()
1755
+ sub new()
1726
1756
  end sub
1727
1757
  end class
1728
1758
 
1729
1759
  class OneParam
1730
- sub new (param1)
1760
+ sub new(param1)
1731
1761
  end sub
1732
1762
  end class
1733
1763
 
1734
- sub main()
1764
+ sub main()
1735
1765
  c1 = new Parameterless(1)
1736
1766
  c2 = new OneParam(1, 2)
1737
1767
  c2 = new OneParam()
1738
1768
  end sub
1739
- `);
1769
+ `);
1740
1770
  program.validate();
1741
1771
  (0, testHelpers_spec_1.expectDiagnostics)(program, [
1742
1772
  DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(0, 1),