brighterscript 0.66.0-alpha.9 → 0.67.1

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 (472) hide show
  1. package/CHANGELOG.md +123 -73
  2. package/README.md +14 -418
  3. package/dist/BsConfig.d.ts +25 -2
  4. package/dist/Cache.js +3 -3
  5. package/dist/Cache.js.map +1 -1
  6. package/dist/CodeActionUtil.d.ts +3 -3
  7. package/dist/CodeActionUtil.js.map +1 -1
  8. package/dist/CommentFlagProcessor.d.ts +3 -4
  9. package/dist/CommentFlagProcessor.js +4 -3
  10. package/dist/CommentFlagProcessor.js.map +1 -1
  11. package/dist/DependencyGraph.js +8 -8
  12. package/dist/DependencyGraph.js.map +1 -1
  13. package/dist/DiagnosticFilterer.d.ts +8 -4
  14. package/dist/DiagnosticFilterer.js +71 -38
  15. package/dist/DiagnosticFilterer.js.map +1 -1
  16. package/dist/DiagnosticMessages.d.ts +15 -36
  17. package/dist/DiagnosticMessages.js +15 -61
  18. package/dist/DiagnosticMessages.js.map +1 -1
  19. package/dist/DiagnosticSeverityAdjuster.js +3 -0
  20. package/dist/DiagnosticSeverityAdjuster.js.map +1 -1
  21. package/dist/FunctionScope.d.ts +2 -3
  22. package/dist/FunctionScope.js +0 -3
  23. package/dist/FunctionScope.js.map +1 -1
  24. package/dist/LanguageServer.d.ts +1 -2
  25. package/dist/LanguageServer.js +31 -35
  26. package/dist/LanguageServer.js.map +1 -1
  27. package/dist/Logger.d.ts +5 -9
  28. package/dist/Logger.js +18 -22
  29. package/dist/Logger.js.map +1 -1
  30. package/dist/PluginInterface.d.ts +13 -15
  31. package/dist/PluginInterface.js +16 -70
  32. package/dist/PluginInterface.js.map +1 -1
  33. package/dist/Program.d.ts +105 -138
  34. package/dist/Program.js +479 -702
  35. package/dist/Program.js.map +1 -1
  36. package/dist/ProgramBuilder.d.ts +8 -19
  37. package/dist/ProgramBuilder.js +85 -89
  38. package/dist/ProgramBuilder.js.map +1 -1
  39. package/dist/Scope.d.ts +56 -46
  40. package/dist/Scope.js +281 -217
  41. package/dist/Scope.js.map +1 -1
  42. package/dist/Stopwatch.js +1 -1
  43. package/dist/Stopwatch.js.map +1 -1
  44. package/dist/SymbolTable.d.ts +12 -68
  45. package/dist/SymbolTable.js +28 -213
  46. package/dist/SymbolTable.js.map +1 -1
  47. package/dist/XmlScope.d.ts +5 -7
  48. package/dist/XmlScope.js +36 -76
  49. package/dist/XmlScope.js.map +1 -1
  50. package/dist/astUtils/{Editor.d.ts → AstEditor.d.ts} +1 -6
  51. package/dist/astUtils/{Editor.js → AstEditor.js} +3 -9
  52. package/dist/astUtils/AstEditor.js.map +1 -0
  53. package/dist/astUtils/{Editor.spec.js → AstEditor.spec.js} +6 -10
  54. package/dist/astUtils/AstEditor.spec.js.map +1 -0
  55. package/dist/astUtils/creators.d.ts +8 -19
  56. package/dist/astUtils/creators.js +22 -54
  57. package/dist/astUtils/creators.js.map +1 -1
  58. package/dist/astUtils/creators.spec.js +0 -10
  59. package/dist/astUtils/creators.spec.js.map +1 -1
  60. package/dist/astUtils/reflection.d.ts +45 -81
  61. package/dist/astUtils/reflection.js +157 -220
  62. package/dist/astUtils/reflection.js.map +1 -1
  63. package/dist/astUtils/reflection.spec.js +19 -96
  64. package/dist/astUtils/reflection.spec.js.map +1 -1
  65. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  66. package/dist/astUtils/visitors.d.ts +14 -18
  67. package/dist/astUtils/visitors.js +9 -22
  68. package/dist/astUtils/visitors.js.map +1 -1
  69. package/dist/astUtils/visitors.spec.js +9 -62
  70. package/dist/astUtils/visitors.spec.js.map +1 -1
  71. package/dist/astUtils/xml.d.ts +9 -9
  72. package/dist/astUtils/xml.js +6 -6
  73. package/dist/astUtils/xml.js.map +1 -1
  74. package/dist/bscPlugin/BscPlugin.d.ts +8 -11
  75. package/dist/bscPlugin/BscPlugin.js +21 -29
  76. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  77. package/dist/bscPlugin/CallExpressionInfo.d.ts +6 -5
  78. package/dist/bscPlugin/CallExpressionInfo.js +2 -2
  79. package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
  80. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +11 -11
  81. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  82. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +4 -4
  83. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  84. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +1 -49
  85. package/dist/bscPlugin/completions/CompletionsProcessor.js +23 -424
  86. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
  87. package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
  88. package/dist/bscPlugin/definition/DefinitionProvider.js +200 -0
  89. package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
  90. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +87 -0
  91. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
  92. package/dist/bscPlugin/hover/HoverProcessor.d.ts +3 -7
  93. package/dist/bscPlugin/hover/HoverProcessor.js +88 -128
  94. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
  95. package/dist/bscPlugin/hover/HoverProcessor.spec.js +24 -336
  96. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
  97. package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
  98. package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
  99. package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
  100. package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
  101. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
  102. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +0 -1
  103. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +5 -49
  104. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  105. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -22
  106. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
  107. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.d.ts +7 -0
  108. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js +22 -0
  109. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js.map +1 -0
  110. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +290 -0
  111. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +1 -0
  112. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.d.ts +7 -0
  113. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js +26 -0
  114. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js.map +1 -0
  115. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +245 -0
  116. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +1 -0
  117. package/dist/bscPlugin/symbols/symbolUtils.d.ts +5 -0
  118. package/dist/bscPlugin/symbols/symbolUtils.js +140 -0
  119. package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -0
  120. package/dist/bscPlugin/transpile/{BrsFileTranspileProcessor.d.ts → BrsFilePreTranspileProcessor.d.ts} +2 -4
  121. package/dist/bscPlugin/transpile/{BrsFileTranspileProcessor.js → BrsFilePreTranspileProcessor.js} +15 -36
  122. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
  123. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +46 -0
  124. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
  125. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +1 -0
  126. package/dist/bscPlugin/validation/BrsFileValidator.js +30 -41
  127. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  128. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +2 -2
  129. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
  130. package/dist/bscPlugin/validation/ProgramValidator.d.ts +3 -3
  131. package/dist/bscPlugin/validation/ProgramValidator.js +6 -6
  132. package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -1
  133. package/dist/bscPlugin/validation/ScopeValidator.d.ts +6 -28
  134. package/dist/bscPlugin/validation/ScopeValidator.js +166 -387
  135. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  136. package/dist/bscPlugin/validation/XmlFileValidator.js +9 -9
  137. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -1
  138. package/dist/diagnosticUtils.d.ts +2 -3
  139. package/dist/diagnosticUtils.js +5 -5
  140. package/dist/diagnosticUtils.js.map +1 -1
  141. package/dist/examples/plugins/removePrint.js +1 -1
  142. package/dist/examples/plugins/removePrint.js.map +1 -1
  143. package/dist/files/BrsFile.Class.spec.js +143 -114
  144. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  145. package/dist/files/BrsFile.d.ts +61 -83
  146. package/dist/files/BrsFile.js +559 -612
  147. package/dist/files/BrsFile.js.map +1 -1
  148. package/dist/files/BrsFile.spec.js +1365 -1201
  149. package/dist/files/BrsFile.spec.js.map +1 -1
  150. package/dist/files/XmlFile.d.ts +28 -56
  151. package/dist/files/XmlFile.js +103 -89
  152. package/dist/files/XmlFile.js.map +1 -1
  153. package/dist/files/XmlFile.spec.js +179 -122
  154. package/dist/files/XmlFile.spec.js.map +1 -1
  155. package/dist/files/tests/imports.spec.js +19 -29
  156. package/dist/files/tests/imports.spec.js.map +1 -1
  157. package/dist/files/tests/optionalChaning.spec.js +14 -14
  158. package/dist/files/tests/optionalChaning.spec.js.map +1 -1
  159. package/dist/globalCallables.js +83 -88
  160. package/dist/globalCallables.js.map +1 -1
  161. package/dist/index.d.ts +1 -9
  162. package/dist/index.js +1 -9
  163. package/dist/index.js.map +1 -1
  164. package/dist/interfaces.d.ts +173 -423
  165. package/dist/interfaces.js +0 -24
  166. package/dist/interfaces.js.map +1 -1
  167. package/dist/lexer/Lexer.d.ts +9 -15
  168. package/dist/lexer/Lexer.js +35 -46
  169. package/dist/lexer/Lexer.js.map +1 -1
  170. package/dist/lexer/Lexer.spec.js +48 -40
  171. package/dist/lexer/Lexer.spec.js.map +1 -1
  172. package/dist/lexer/Token.d.ts +1 -5
  173. package/dist/lexer/Token.js +1 -1
  174. package/dist/lexer/Token.js.map +1 -1
  175. package/dist/lexer/TokenKind.d.ts +0 -6
  176. package/dist/lexer/TokenKind.js +2 -14
  177. package/dist/lexer/TokenKind.js.map +1 -1
  178. package/dist/logging.d.ts +9 -0
  179. package/dist/logging.js +16 -0
  180. package/dist/logging.js.map +1 -0
  181. package/dist/parser/AstNode.d.ts +6 -90
  182. package/dist/parser/AstNode.js +5 -96
  183. package/dist/parser/AstNode.js.map +1 -1
  184. package/dist/parser/AstNode.spec.js.map +1 -1
  185. package/dist/parser/BrsTranspileState.d.ts +3 -4
  186. package/dist/parser/BrsTranspileState.js +2 -3
  187. package/dist/parser/BrsTranspileState.js.map +1 -1
  188. package/dist/parser/Expression.d.ts +114 -137
  189. package/dist/parser/Expression.js +244 -373
  190. package/dist/parser/Expression.js.map +1 -1
  191. package/dist/parser/Parser.Class.spec.js +19 -46
  192. package/dist/parser/Parser.Class.spec.js.map +1 -1
  193. package/dist/parser/Parser.d.ts +18 -14
  194. package/dist/parser/Parser.js +196 -175
  195. package/dist/parser/Parser.js.map +1 -1
  196. package/dist/parser/Parser.spec.d.ts +0 -2
  197. package/dist/parser/Parser.spec.js +10 -674
  198. package/dist/parser/Parser.spec.js.map +1 -1
  199. package/dist/parser/SGParser.d.ts +6 -44
  200. package/dist/parser/SGParser.js +198 -194
  201. package/dist/parser/SGParser.js.map +1 -1
  202. package/dist/parser/SGParser.spec.js +11 -14
  203. package/dist/parser/SGParser.spec.js.map +1 -1
  204. package/dist/parser/SGTypes.d.ts +52 -280
  205. package/dist/parser/SGTypes.js +185 -562
  206. package/dist/parser/SGTypes.js.map +1 -1
  207. package/dist/parser/Statement.d.ts +140 -172
  208. package/dist/parser/Statement.js +201 -337
  209. package/dist/parser/Statement.js.map +1 -1
  210. package/dist/parser/Statement.spec.js.map +1 -1
  211. package/dist/parser/TranspileState.d.ts +3 -2
  212. package/dist/parser/TranspileState.js +8 -10
  213. package/dist/parser/TranspileState.js.map +1 -1
  214. package/dist/parser/tests/Parser.spec.js +3 -5
  215. package/dist/parser/tests/Parser.spec.js.map +1 -1
  216. package/dist/parser/tests/controlFlow/For.spec.js +8 -16
  217. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  218. package/dist/parser/tests/controlFlow/ForEach.spec.js +6 -12
  219. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  220. package/dist/parser/tests/controlFlow/While.spec.js +4 -8
  221. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  222. package/dist/parser/tests/expression/Call.spec.js +4 -4
  223. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  224. package/dist/parser/tests/expression/Indexing.spec.js +25 -0
  225. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  226. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +73 -29
  227. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  228. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +10 -10
  229. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
  230. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +24 -24
  231. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  232. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +47 -35
  233. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  234. package/dist/parser/tests/expression/TernaryExpression.spec.js +83 -36
  235. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  236. package/dist/parser/tests/expression/UnaryExpression.spec.js +2 -2
  237. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -1
  238. package/dist/parser/tests/statement/ConstStatement.spec.js +26 -27
  239. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
  240. package/dist/parser/tests/statement/Continue.spec.js +2 -2
  241. package/dist/parser/tests/statement/Continue.spec.js.map +1 -1
  242. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  243. package/dist/parser/tests/statement/Enum.spec.js +393 -90
  244. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  245. package/dist/parser/tests/statement/For.spec.js +6 -6
  246. package/dist/parser/tests/statement/For.spec.js.map +1 -1
  247. package/dist/parser/tests/statement/ForEach.spec.js +4 -4
  248. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
  249. package/dist/parser/tests/statement/Function.spec.js +1 -1
  250. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  251. package/dist/parser/tests/statement/InterfaceStatement.spec.js +18 -18
  252. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
  253. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  254. package/dist/parser/tests/statement/PrintStatement.spec.js +13 -16
  255. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  256. package/dist/parser/tests/statement/ReturnStatement.spec.js +3 -5
  257. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  258. package/dist/parser/tests/statement/Set.spec.js +13 -26
  259. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  260. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  261. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  262. package/dist/preprocessor/Chunk.js +1 -2
  263. package/dist/preprocessor/Chunk.js.map +1 -1
  264. package/dist/preprocessor/Preprocessor.d.ts +3 -4
  265. package/dist/preprocessor/Preprocessor.js +3 -3
  266. package/dist/preprocessor/Preprocessor.js.map +1 -1
  267. package/dist/preprocessor/PreprocessorParser.js +8 -1
  268. package/dist/preprocessor/PreprocessorParser.js.map +1 -1
  269. package/dist/roku-types/data.json +293 -243
  270. package/dist/roku-types/index.d.ts +38 -17
  271. package/dist/types/ArrayType.d.ts +4 -9
  272. package/dist/types/ArrayType.js +24 -72
  273. package/dist/types/ArrayType.js.map +1 -1
  274. package/dist/types/ArrayType.spec.js +10 -39
  275. package/dist/types/ArrayType.spec.js.map +1 -1
  276. package/dist/types/BooleanType.d.ts +4 -8
  277. package/dist/types/BooleanType.js +8 -19
  278. package/dist/types/BooleanType.js.map +1 -1
  279. package/dist/types/BooleanType.spec.js +3 -9
  280. package/dist/types/BooleanType.spec.js.map +1 -1
  281. package/dist/types/BscType.d.ts +2 -29
  282. package/dist/types/BscType.js +0 -113
  283. package/dist/types/BscType.js.map +1 -1
  284. package/dist/types/CustomType.d.ts +9 -0
  285. package/dist/types/CustomType.js +32 -0
  286. package/dist/types/CustomType.js.map +1 -0
  287. package/dist/types/DoubleType.d.ts +4 -8
  288. package/dist/types/DoubleType.js +20 -23
  289. package/dist/types/DoubleType.js.map +1 -1
  290. package/dist/types/DoubleType.spec.js +3 -11
  291. package/dist/types/DoubleType.spec.js.map +1 -1
  292. package/dist/types/DynamicType.d.ts +3 -9
  293. package/dist/types/DynamicType.js +2 -18
  294. package/dist/types/DynamicType.js.map +1 -1
  295. package/dist/types/DynamicType.spec.js +4 -15
  296. package/dist/types/DynamicType.spec.js.map +1 -1
  297. package/dist/types/FloatType.d.ts +4 -8
  298. package/dist/types/FloatType.js +20 -23
  299. package/dist/types/FloatType.js.map +1 -1
  300. package/dist/types/FloatType.spec.js +3 -3
  301. package/dist/types/FloatType.spec.js.map +1 -1
  302. package/dist/types/FunctionType.d.ts +20 -10
  303. package/dist/types/FunctionType.js +52 -27
  304. package/dist/types/FunctionType.js.map +1 -1
  305. package/dist/types/FunctionType.spec.js +23 -0
  306. package/dist/types/FunctionType.spec.js.map +1 -0
  307. package/dist/types/IntegerType.d.ts +4 -8
  308. package/dist/types/IntegerType.js +20 -23
  309. package/dist/types/IntegerType.js.map +1 -1
  310. package/dist/types/IntegerType.spec.js +3 -7
  311. package/dist/types/IntegerType.spec.js.map +1 -1
  312. package/dist/types/InterfaceType.d.ts +10 -12
  313. package/dist/types/InterfaceType.js +48 -23
  314. package/dist/types/InterfaceType.js.map +1 -1
  315. package/dist/types/InterfaceType.spec.js +45 -82
  316. package/dist/types/InterfaceType.spec.js.map +1 -1
  317. package/dist/types/InvalidType.d.ts +4 -7
  318. package/dist/types/InvalidType.js +8 -18
  319. package/dist/types/InvalidType.js.map +1 -1
  320. package/dist/types/InvalidType.spec.js +3 -7
  321. package/dist/types/InvalidType.spec.js.map +1 -1
  322. package/dist/types/LongIntegerType.d.ts +4 -8
  323. package/dist/types/LongIntegerType.js +20 -23
  324. package/dist/types/LongIntegerType.js.map +1 -1
  325. package/dist/types/LongIntegerType.spec.js +3 -9
  326. package/dist/types/LongIntegerType.spec.js.map +1 -1
  327. package/dist/types/ObjectType.d.ts +4 -8
  328. package/dist/types/ObjectType.js +7 -21
  329. package/dist/types/ObjectType.js.map +1 -1
  330. package/dist/types/ObjectType.spec.js +2 -2
  331. package/dist/types/ObjectType.spec.js.map +1 -1
  332. package/dist/types/StringType.d.ts +4 -11
  333. package/dist/types/StringType.js +8 -23
  334. package/dist/types/StringType.js.map +1 -1
  335. package/dist/types/StringType.spec.js +2 -2
  336. package/dist/types/StringType.spec.js.map +1 -1
  337. package/dist/types/UninitializedType.d.ts +3 -7
  338. package/dist/types/UninitializedType.js +3 -14
  339. package/dist/types/UninitializedType.js.map +1 -1
  340. package/dist/types/VoidType.d.ts +4 -8
  341. package/dist/types/VoidType.js +8 -18
  342. package/dist/types/VoidType.js.map +1 -1
  343. package/dist/types/VoidType.spec.js +2 -2
  344. package/dist/types/VoidType.spec.js.map +1 -1
  345. package/dist/util.d.ts +43 -104
  346. package/dist/util.js +243 -640
  347. package/dist/util.js.map +1 -1
  348. package/dist/validators/ClassValidator.d.ts +6 -1
  349. package/dist/validators/ClassValidator.js +61 -20
  350. package/dist/validators/ClassValidator.js.map +1 -1
  351. package/package.json +13 -11
  352. package/dist/ActionPipeline.d.ts +0 -10
  353. package/dist/ActionPipeline.js +0 -40
  354. package/dist/ActionPipeline.js.map +0 -1
  355. package/dist/AstValidationSegmenter.d.ts +0 -25
  356. package/dist/AstValidationSegmenter.js +0 -150
  357. package/dist/AstValidationSegmenter.js.map +0 -1
  358. package/dist/CacheVerifier.d.ts +0 -7
  359. package/dist/CacheVerifier.js +0 -20
  360. package/dist/CacheVerifier.js.map +0 -1
  361. package/dist/astUtils/Editor.js.map +0 -1
  362. package/dist/astUtils/Editor.spec.js.map +0 -1
  363. package/dist/bscPlugin/FileWriter.d.ts +0 -6
  364. package/dist/bscPlugin/FileWriter.js +0 -24
  365. package/dist/bscPlugin/FileWriter.js.map +0 -1
  366. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +0 -1658
  367. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +0 -1
  368. package/dist/bscPlugin/fileProviders/FileProvider.d.ts +0 -9
  369. package/dist/bscPlugin/fileProviders/FileProvider.js +0 -51
  370. package/dist/bscPlugin/fileProviders/FileProvider.js.map +0 -1
  371. package/dist/bscPlugin/serialize/BslibInjector.spec.js +0 -19
  372. package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +0 -1
  373. package/dist/bscPlugin/serialize/BslibManager.d.ts +0 -9
  374. package/dist/bscPlugin/serialize/BslibManager.js +0 -40
  375. package/dist/bscPlugin/serialize/BslibManager.js.map +0 -1
  376. package/dist/bscPlugin/serialize/FileSerializer.d.ts +0 -9
  377. package/dist/bscPlugin/serialize/FileSerializer.js +0 -72
  378. package/dist/bscPlugin/serialize/FileSerializer.js.map +0 -1
  379. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +0 -1
  380. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +0 -41
  381. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +0 -1
  382. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +0 -11
  383. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +0 -53
  384. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +0 -1
  385. package/dist/bscPlugin/validation/ScopeValidator.spec.js +0 -2004
  386. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +0 -1
  387. package/dist/files/AssetFile.d.ts +0 -26
  388. package/dist/files/AssetFile.js +0 -26
  389. package/dist/files/AssetFile.js.map +0 -1
  390. package/dist/files/Factory.d.ts +0 -25
  391. package/dist/files/Factory.js +0 -22
  392. package/dist/files/Factory.js.map +0 -1
  393. package/dist/files/File.d.ts +0 -106
  394. package/dist/files/File.js +0 -16
  395. package/dist/files/File.js.map +0 -1
  396. package/dist/files/LazyFileData.d.ts +0 -20
  397. package/dist/files/LazyFileData.js +0 -54
  398. package/dist/files/LazyFileData.js.map +0 -1
  399. package/dist/files/LazyFileData.spec.js +0 -27
  400. package/dist/files/LazyFileData.spec.js.map +0 -1
  401. package/dist/parser/tests/expression/TypeExpression.spec.js +0 -127
  402. package/dist/parser/tests/expression/TypeExpression.spec.js.map +0 -1
  403. package/dist/types/AssociativeArrayType.d.ts +0 -11
  404. package/dist/types/AssociativeArrayType.js +0 -52
  405. package/dist/types/AssociativeArrayType.js.map +0 -1
  406. package/dist/types/BaseFunctionType.d.ts +0 -9
  407. package/dist/types/BaseFunctionType.js +0 -25
  408. package/dist/types/BaseFunctionType.js.map +0 -1
  409. package/dist/types/BscTypeKind.d.ts +0 -25
  410. package/dist/types/BscTypeKind.js +0 -30
  411. package/dist/types/BscTypeKind.js.map +0 -1
  412. package/dist/types/BuiltInInterfaceAdder.d.ts +0 -23
  413. package/dist/types/BuiltInInterfaceAdder.js +0 -160
  414. package/dist/types/BuiltInInterfaceAdder.js.map +0 -1
  415. package/dist/types/BuiltInInterfaceAdder.spec.d.ts +0 -1
  416. package/dist/types/BuiltInInterfaceAdder.spec.js +0 -116
  417. package/dist/types/BuiltInInterfaceAdder.spec.js.map +0 -1
  418. package/dist/types/ClassType.d.ts +0 -17
  419. package/dist/types/ClassType.js +0 -58
  420. package/dist/types/ClassType.js.map +0 -1
  421. package/dist/types/ClassType.spec.d.ts +0 -1
  422. package/dist/types/ClassType.spec.js +0 -77
  423. package/dist/types/ClassType.spec.js.map +0 -1
  424. package/dist/types/ComponentType.d.ts +0 -26
  425. package/dist/types/ComponentType.js +0 -83
  426. package/dist/types/ComponentType.js.map +0 -1
  427. package/dist/types/EnumType.d.ts +0 -40
  428. package/dist/types/EnumType.js +0 -81
  429. package/dist/types/EnumType.js.map +0 -1
  430. package/dist/types/EnumType.spec.d.ts +0 -1
  431. package/dist/types/EnumType.spec.js +0 -33
  432. package/dist/types/EnumType.spec.js.map +0 -1
  433. package/dist/types/InheritableType.d.ts +0 -28
  434. package/dist/types/InheritableType.js +0 -152
  435. package/dist/types/InheritableType.js.map +0 -1
  436. package/dist/types/NamespaceType.d.ts +0 -12
  437. package/dist/types/NamespaceType.js +0 -28
  438. package/dist/types/NamespaceType.js.map +0 -1
  439. package/dist/types/ReferenceType.d.ts +0 -63
  440. package/dist/types/ReferenceType.js +0 -423
  441. package/dist/types/ReferenceType.js.map +0 -1
  442. package/dist/types/ReferenceType.spec.d.ts +0 -1
  443. package/dist/types/ReferenceType.spec.js +0 -137
  444. package/dist/types/ReferenceType.spec.js.map +0 -1
  445. package/dist/types/TypedFunctionType.d.ts +0 -33
  446. package/dist/types/TypedFunctionType.js +0 -106
  447. package/dist/types/TypedFunctionType.js.map +0 -1
  448. package/dist/types/TypedFunctionType.spec.d.ts +0 -1
  449. package/dist/types/TypedFunctionType.spec.js +0 -122
  450. package/dist/types/TypedFunctionType.spec.js.map +0 -1
  451. package/dist/types/UnionType.d.ts +0 -20
  452. package/dist/types/UnionType.js +0 -123
  453. package/dist/types/UnionType.js.map +0 -1
  454. package/dist/types/UnionType.spec.d.ts +0 -1
  455. package/dist/types/UnionType.spec.js +0 -130
  456. package/dist/types/UnionType.spec.js.map +0 -1
  457. package/dist/types/helper.spec.d.ts +0 -1
  458. package/dist/types/helper.spec.js +0 -145
  459. package/dist/types/helper.spec.js.map +0 -1
  460. package/dist/types/helpers.d.ts +0 -24
  461. package/dist/types/helpers.js +0 -178
  462. package/dist/types/helpers.js.map +0 -1
  463. package/dist/types/index.d.ts +0 -22
  464. package/dist/types/index.js +0 -39
  465. package/dist/types/index.js.map +0 -1
  466. /package/dist/astUtils/{Editor.spec.d.ts → AstEditor.spec.d.ts} +0 -0
  467. /package/dist/bscPlugin/{completions/CompletionsProcessor.spec.d.ts → definition/DefinitionProvider.spec.d.ts} +0 -0
  468. /package/dist/bscPlugin/{serialize/BslibInjector.spec.d.ts → references/ReferencesProvider.spec.d.ts} +0 -0
  469. /package/dist/bscPlugin/{transpile/BrsFileTranspileProcessor.spec.d.ts → symbols/DocumentSymbolProcessor.spec.d.ts} +0 -0
  470. /package/dist/bscPlugin/{validation/ScopeValidator.spec.d.ts → symbols/WorkspaceSymbolProcessor.spec.d.ts} +0 -0
  471. /package/dist/{files/LazyFileData.spec.d.ts → bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts} +0 -0
  472. /package/dist/{parser/tests/expression/TypeExpression.spec.d.ts → types/FunctionType.spec.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TypedArrayExpression = exports.TypeCastExpression = exports.TypeExpression = exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = void 0;
3
+ exports.TypeCastExpression = exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = void 0;
4
4
  const TokenKind_1 = require("../lexer/TokenKind");
5
5
  const util_1 = require("../util");
6
6
  const Parser_1 = require("./Parser");
@@ -8,28 +8,19 @@ const fileUrl = require("file-url");
8
8
  const visitors_1 = require("../astUtils/visitors");
9
9
  const visitors_2 = require("../astUtils/visitors");
10
10
  const reflection_1 = require("../astUtils/reflection");
11
- const interfaces_1 = require("../interfaces");
12
- const SymbolTable_1 = require("../SymbolTable");
13
- const TypedFunctionType_1 = require("../types/TypedFunctionType");
11
+ const VoidType_1 = require("../types/VoidType");
12
+ const DynamicType_1 = require("../types/DynamicType");
13
+ const FunctionType_1 = require("../types/FunctionType");
14
14
  const AstNode_1 = require("./AstNode");
15
- const SymbolTable_2 = require("../SymbolTable");
15
+ const SymbolTable_1 = require("../SymbolTable");
16
16
  const source_map_1 = require("source-map");
17
- const StringType_1 = require("../types/StringType");
18
- const DynamicType_1 = require("../types/DynamicType");
19
- const VoidType_1 = require("../types/VoidType");
20
- const ReferenceType_1 = require("../types/ReferenceType");
21
- const UnionType_1 = require("../types/UnionType");
22
- const types_1 = require("../types");
23
- const AssociativeArrayType_1 = require("../types/AssociativeArrayType");
24
- const creators_1 = require("../astUtils/creators");
25
17
  class BinaryExpression extends AstNode_1.Expression {
26
18
  constructor(left, operator, right) {
27
19
  super();
28
20
  this.left = left;
29
21
  this.operator = operator;
30
22
  this.right = right;
31
- this.kind = AstNode_1.AstNodeKind.BinaryExpression;
32
- this.range = util_1.default.createRangeFromPositions(this.left.range.start, this.right.range.end);
23
+ this.range = util_1.default.createBoundingRange(this.left, this.operator, this.right);
33
24
  }
34
25
  transpile(state) {
35
26
  return [
@@ -46,21 +37,6 @@ class BinaryExpression extends AstNode_1.Expression {
46
37
  (0, visitors_2.walk)(this, 'right', visitor, options);
47
38
  }
48
39
  }
49
- getType(options) {
50
- const operatorKind = this.operator.kind;
51
- if (options.flags & SymbolTable_1.SymbolTypeFlag.typetime) {
52
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
53
- switch (operatorKind) {
54
- case TokenKind_1.TokenKind.Or:
55
- return new UnionType_1.UnionType([this.left.getType(options), this.right.getType(options)]);
56
- //TODO: Intersection Types?, eg. case TokenKind.And:
57
- }
58
- }
59
- else if (options.flags & SymbolTable_1.SymbolTypeFlag.runtime) {
60
- return util_1.default.binaryOperatorResultType(this.left.getType(options), this.operator, this.right.getType(options));
61
- }
62
- return DynamicType_1.DynamicType.instance;
63
- }
64
40
  }
65
41
  exports.BinaryExpression = BinaryExpression;
66
42
  class CallExpression extends AstNode_1.Expression {
@@ -74,9 +50,16 @@ class CallExpression extends AstNode_1.Expression {
74
50
  this.openingParen = openingParen;
75
51
  this.closingParen = closingParen;
76
52
  this.args = args;
77
- this.kind = AstNode_1.AstNodeKind.CallExpression;
78
53
  this.range = util_1.default.createBoundingRange(this.callee, this.openingParen, ...args, this.closingParen);
79
54
  }
55
+ /**
56
+ * Get the name of the wrapping namespace (if it exists)
57
+ * @deprecated use `.findAncestor(isNamespaceStatement)` instead.
58
+ */
59
+ get namespaceName() {
60
+ var _a;
61
+ return (_a = this.findAncestor(reflection_1.isNamespaceStatement)) === null || _a === void 0 ? void 0 : _a.nameExpression;
62
+ }
80
63
  transpile(state, nameOverride) {
81
64
  let result = [];
82
65
  //transpile the name
@@ -106,28 +89,18 @@ class CallExpression extends AstNode_1.Expression {
106
89
  (0, visitors_2.walkArray)(this.args, visitor, options, this);
107
90
  }
108
91
  }
109
- getType(options) {
110
- var _a, _b;
111
- const calleeType = this.callee.getType(options);
112
- if (options.ignoreCall) {
113
- return calleeType;
114
- }
115
- if ((0, reflection_1.isNewExpression)(this.parent)) {
116
- return calleeType;
117
- }
118
- if ((0, reflection_1.isCallableType)(calleeType) && (!(0, reflection_1.isReferenceType)(calleeType.returnType) || ((_a = calleeType.returnType) === null || _a === void 0 ? void 0 : _a.isResolvable()))) {
119
- return calleeType.returnType;
120
- }
121
- if (!(0, reflection_1.isReferenceType)(calleeType) && ((_b = calleeType.returnType) === null || _b === void 0 ? void 0 : _b.isResolvable())) {
122
- return calleeType.returnType;
123
- }
124
- return new ReferenceType_1.TypePropertyReferenceType(calleeType, 'returnType');
125
- }
126
92
  }
127
93
  exports.CallExpression = CallExpression;
128
- CallExpression.MaximumArguments = 32;
94
+ /**
95
+ * Number of parameters that can be defined on a function
96
+ *
97
+ * Prior to Roku OS 11.5, this was 32
98
+ * As of Roku OS 11.5, this is 63
99
+ */
100
+ CallExpression.MaximumArguments = 63;
129
101
  class FunctionExpression extends AstNode_1.Expression {
130
- constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeExpression) {
102
+ constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeToken) {
103
+ var _a;
131
104
  super();
132
105
  this.parameters = parameters;
133
106
  this.body = body;
@@ -136,29 +109,63 @@ class FunctionExpression extends AstNode_1.Expression {
136
109
  this.leftParen = leftParen;
137
110
  this.rightParen = rightParen;
138
111
  this.asToken = asToken;
139
- this.returnTypeExpression = returnTypeExpression;
140
- this.kind = AstNode_1.AstNodeKind.FunctionExpression;
112
+ this.returnTypeToken = returnTypeToken;
141
113
  /**
142
114
  * The list of function calls that are declared within this function scope. This excludes CallExpressions
143
115
  * declared in child functions
144
116
  */
145
117
  this.callExpressions = [];
118
+ if (this.returnTypeToken) {
119
+ this.returnType = util_1.default.tokenToBscType(this.returnTypeToken);
120
+ }
121
+ else if (((_a = this.functionType) === null || _a === void 0 ? void 0 : _a.text.toLowerCase()) === 'sub') {
122
+ this.returnType = new VoidType_1.VoidType();
123
+ }
124
+ else {
125
+ this.returnType = DynamicType_1.DynamicType.instance;
126
+ }
146
127
  //if there's a body, and it doesn't have a SymbolTable, assign one
147
128
  if (this.body && !this.body.symbolTable) {
148
- this.body.symbolTable = new SymbolTable_2.SymbolTable(`Function Body`);
129
+ this.body.symbolTable = new SymbolTable_1.SymbolTable(`Function Body`);
149
130
  }
150
- this.symbolTable = new SymbolTable_2.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
131
+ this.symbolTable = new SymbolTable_1.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
151
132
  }
152
- getLeadingTrivia() {
153
- var _a, _b;
154
- return (_b = (_a = this.functionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
133
+ /**
134
+ * Get the name of the wrapping namespace (if it exists)
135
+ * @deprecated use `.findAncestor(isNamespaceStatement)` instead.
136
+ */
137
+ get namespaceName() {
138
+ var _a;
139
+ return (_a = this.findAncestor(reflection_1.isNamespaceStatement)) === null || _a === void 0 ? void 0 : _a.nameExpression;
140
+ }
141
+ /**
142
+ * Get the name of the wrapping namespace (if it exists)
143
+ * @deprecated use `.findAncestor(isFunctionExpression)` instead.
144
+ */
145
+ get parentFunction() {
146
+ return this.findAncestor(reflection_1.isFunctionExpression);
147
+ }
148
+ /**
149
+ * A list of all child functions declared directly within this function
150
+ * @deprecated use `.walk(createVisitor({ FunctionExpression: ()=>{}), { walkMode: WalkMode.visitAllRecursive })` instead
151
+ */
152
+ get childFunctionExpressions() {
153
+ const expressions = [];
154
+ this.walk((0, visitors_1.createVisitor)({
155
+ FunctionExpression: (expression) => {
156
+ expressions.push(expression);
157
+ }
158
+ }), {
159
+ walkMode: visitors_1.WalkMode.visitAllRecursive
160
+ });
161
+ return expressions;
155
162
  }
156
163
  /**
157
164
  * The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
158
165
  * and ending with the last n' in 'end function' or 'b' in 'end sub'
159
166
  */
160
167
  get range() {
161
- return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...this.parameters, this.rightParen, this.asToken, this.returnTypeExpression, this.end);
168
+ return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...this.parameters, this.rightParen, this.asToken, this.returnTypeToken, this.end);
162
169
  }
163
170
  transpile(state, name, includeBody = true) {
164
171
  let results = [];
@@ -183,12 +190,12 @@ class FunctionExpression extends AstNode_1.Expression {
183
190
  //right paren
184
191
  results.push(state.transpileToken(this.rightParen));
185
192
  //as [Type]
186
- if (this.asToken && !state.options.removeParameterTypes && this.returnTypeExpression) {
193
+ if (this.asToken && !state.options.removeParameterTypes) {
187
194
  results.push(' ',
188
195
  //as
189
196
  state.transpileToken(this.asToken), ' ',
190
197
  //return type
191
- ...this.returnTypeExpression.transpile(state));
198
+ state.sourceNode(this.returnTypeToken, this.returnType.toTypeString()));
192
199
  }
193
200
  if (includeBody) {
194
201
  state.lineage.unshift(this);
@@ -202,7 +209,7 @@ class FunctionExpression extends AstNode_1.Expression {
202
209
  return results;
203
210
  }
204
211
  getTypedef(state) {
205
- var _a, _b, _c, _d, _e;
212
+ var _a, _b, _c, _d, _e, _f;
206
213
  let results = [
207
214
  new source_map_1.SourceNode(1, 0, null, [
208
215
  //'function'|'sub'
@@ -222,7 +229,7 @@ class FunctionExpression extends AstNode_1.Expression {
222
229
  //as <ReturnType>
223
230
  ...(this.asToken ? [
224
231
  ' as ',
225
- ...this.returnTypeExpression.getTypedef(state)
232
+ (_f = this.returnTypeToken) === null || _f === void 0 ? void 0 : _f.text
226
233
  ] : []),
227
234
  '\n',
228
235
  state.indent(),
@@ -235,68 +242,41 @@ class FunctionExpression extends AstNode_1.Expression {
235
242
  walk(visitor, options) {
236
243
  if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
237
244
  (0, visitors_2.walkArray)(this.parameters, visitor, options, this);
238
- (0, visitors_2.walk)(this, 'returnTypeExpression', visitor, options);
239
245
  //This is the core of full-program walking...it allows us to step into sub functions
240
246
  if (options.walkMode & visitors_2.InternalWalkMode.recurseChildFunctions) {
241
247
  (0, visitors_2.walk)(this, 'body', visitor, options);
242
248
  }
243
249
  }
244
250
  }
245
- getType(options) {
246
- var _a, _b, _c;
247
- //if there's a defined return type, use that
248
- let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
249
- const isSub = this.functionType.kind === TokenKind_1.TokenKind.Sub;
250
- //if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
251
- if (!returnType) {
252
- returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
253
- }
254
- const resultType = new TypedFunctionType_1.TypedFunctionType(returnType);
255
- resultType.isSub = isSub;
251
+ getFunctionType() {
252
+ var _a;
253
+ let functionType = new FunctionType_1.FunctionType(this.returnType);
254
+ functionType.isSub = ((_a = this.functionType) === null || _a === void 0 ? void 0 : _a.text) === 'sub';
256
255
  for (let param of this.parameters) {
257
- resultType.addParameter(param.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
258
- }
259
- // Figure out this function's name if we can
260
- let funcName = '';
261
- if ((0, reflection_1.isMethodStatement)(this.parent) || (0, reflection_1.isInterfaceMethodStatement)(this.parent)) {
262
- funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
263
- if (options.typeChain) {
264
- // Get the typechain info from the parent class
265
- (_b = this.parent.parent) === null || _b === void 0 ? void 0 : _b.getType(options);
266
- }
267
- }
268
- else if ((0, reflection_1.isFunctionStatement)(this.parent)) {
269
- funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
270
- }
271
- if (funcName) {
272
- resultType.setName(funcName);
256
+ functionType.addParameter(param.name.text, param.type, !!param.typeToken);
273
257
  }
274
- (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry(funcName, resultType, options.flags, this.range));
275
- return resultType;
258
+ return functionType;
276
259
  }
277
260
  }
278
261
  exports.FunctionExpression = FunctionExpression;
279
262
  class FunctionParameterExpression extends AstNode_1.Expression {
280
- constructor(name, equalToken, defaultValue, asToken, typeExpression) {
263
+ constructor(name, typeToken, defaultValue, asToken) {
281
264
  super();
282
265
  this.name = name;
283
- this.equalToken = equalToken;
266
+ this.typeToken = typeToken;
284
267
  this.defaultValue = defaultValue;
285
268
  this.asToken = asToken;
286
- this.typeExpression = typeExpression;
287
- this.kind = AstNode_1.AstNodeKind.FunctionParameterExpression;
288
- }
289
- getType(options) {
290
- var _a, _b, _c, _d, _e;
291
- const paramType = (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.typetime, typeChain: undefined }))) !== null && _b !== void 0 ? _b : (_c = this.defaultValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.runtime, typeChain: undefined }))) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
292
- (_e = options.typeChain) === null || _e === void 0 ? void 0 : _e.push(new interfaces_1.TypeChainEntry(this.name.text, paramType, options.flags, this.range));
293
- return paramType;
269
+ if (typeToken) {
270
+ this.type = util_1.default.tokenToBscType(typeToken);
271
+ }
272
+ else {
273
+ this.type = new DynamicType_1.DynamicType();
274
+ }
294
275
  }
295
276
  get range() {
296
- return util_1.default.createBoundingRange(this.name, this.asToken, this.typeExpression, this.defaultValue);
277
+ return util_1.default.createBoundingRange(this.name, this.asToken, this.typeToken, this.defaultValue);
297
278
  }
298
279
  transpile(state) {
299
- var _a, _b;
300
280
  let result = [
301
281
  //name
302
282
  state.transpileToken(this.name)
@@ -311,36 +291,78 @@ class FunctionParameterExpression extends AstNode_1.Expression {
311
291
  result.push(' ');
312
292
  result.push(state.transpileToken(this.asToken));
313
293
  result.push(' ');
314
- result.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []));
294
+ result.push(state.sourceNode(this.typeToken, this.type.toTypeString()));
315
295
  }
316
296
  return result;
317
297
  }
318
298
  getTypedef(state) {
319
- var _a, _b;
320
- return [
321
- //name
322
- this.name.text,
323
- //default value
324
- ...(this.defaultValue ? [
325
- ' = ',
326
- ...this.defaultValue.transpile(state)
327
- ] : []),
328
- //type declaration
329
- ...(this.asToken ? [
330
- ' as ',
331
- ...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getTypedef(state)) !== null && _b !== void 0 ? _b : [''])
332
- ] : [])
333
- ];
299
+ const results = [this.name.text];
300
+ if (this.defaultValue) {
301
+ results.push(' = ', ...this.defaultValue.transpile(state));
302
+ }
303
+ if (this.asToken) {
304
+ results.push(' as ');
305
+ // TODO: Is this conditional needed? Will typeToken always exist
306
+ // so long as `asToken` exists?
307
+ if (this.typeToken) {
308
+ results.push(this.typeToken.text);
309
+ }
310
+ }
311
+ return results;
334
312
  }
335
313
  walk(visitor, options) {
336
314
  // eslint-disable-next-line no-bitwise
337
- if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
315
+ if (this.defaultValue && options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
338
316
  (0, visitors_2.walk)(this, 'defaultValue', visitor, options);
339
- (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
340
317
  }
341
318
  }
342
319
  }
343
320
  exports.FunctionParameterExpression = FunctionParameterExpression;
321
+ class NamespacedVariableNameExpression extends AstNode_1.Expression {
322
+ constructor(
323
+ //if this is a `DottedGetExpression`, it must be comprised only of `VariableExpression`s
324
+ expression) {
325
+ super();
326
+ this.expression = expression;
327
+ this.range = expression.range;
328
+ }
329
+ transpile(state) {
330
+ return [
331
+ state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
332
+ ];
333
+ }
334
+ getNameParts() {
335
+ let parts = [];
336
+ if ((0, reflection_1.isVariableExpression)(this.expression)) {
337
+ parts.push(this.expression.name.text);
338
+ }
339
+ else {
340
+ let expr = this.expression;
341
+ parts.push(expr.name.text);
342
+ while ((0, reflection_1.isVariableExpression)(expr) === false) {
343
+ expr = expr.obj;
344
+ parts.unshift(expr.name.text);
345
+ }
346
+ }
347
+ return parts;
348
+ }
349
+ getName(parseMode) {
350
+ if (parseMode === Parser_1.ParseMode.BrighterScript) {
351
+ return this.getNameParts().join('.');
352
+ }
353
+ else {
354
+ return this.getNameParts().join('_');
355
+ }
356
+ }
357
+ walk(visitor, options) {
358
+ var _a;
359
+ (_a = this.expression) === null || _a === void 0 ? void 0 : _a.link();
360
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
361
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
362
+ }
363
+ }
364
+ }
365
+ exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
344
366
  class DottedGetExpression extends AstNode_1.Expression {
345
367
  constructor(obj, name,
346
368
  /**
@@ -351,15 +373,12 @@ class DottedGetExpression extends AstNode_1.Expression {
351
373
  this.obj = obj;
352
374
  this.name = name;
353
375
  this.dot = dot;
354
- this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
355
376
  this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
356
377
  }
357
378
  transpile(state) {
358
379
  //if the callee starts with a namespace name, transpile the name
359
380
  if (state.file.calleeStartsWithNamespace(this)) {
360
- return [
361
- state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
362
- ];
381
+ return new NamespacedVariableNameExpression(this).transpile(state);
363
382
  }
364
383
  else {
365
384
  return [
@@ -374,22 +393,6 @@ class DottedGetExpression extends AstNode_1.Expression {
374
393
  (0, visitors_2.walk)(this, 'obj', visitor, options);
375
394
  }
376
395
  }
377
- getType(options) {
378
- var _a, _b, _c, _d, _e, _f;
379
- const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
380
- const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.name) === null || _b === void 0 ? void 0 : _b.text, options);
381
- (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry((_d = this.name) === null || _d === void 0 ? void 0 : _d.text, result, options.flags, (_f = (_e = this.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range));
382
- if (result || options.flags & SymbolTable_1.SymbolTypeFlag.typetime) {
383
- // All types should be known at typetime
384
- return result;
385
- }
386
- // It is possible at runtime that a value has been added dynamically to an object, or something
387
- // TODO: maybe have a strict flag on this?
388
- return DynamicType_1.DynamicType.instance;
389
- }
390
- getName(parseMode) {
391
- return util_1.default.getAllDottedGetPartsAsString(this, parseMode);
392
- }
393
396
  }
394
397
  exports.DottedGetExpression = DottedGetExpression;
395
398
  class XmlAttributeGetExpression extends AstNode_1.Expression {
@@ -402,7 +405,6 @@ class XmlAttributeGetExpression extends AstNode_1.Expression {
402
405
  this.obj = obj;
403
406
  this.name = name;
404
407
  this.at = at;
405
- this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
406
408
  this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
407
409
  }
408
410
  transpile(state) {
@@ -424,41 +426,45 @@ class IndexedGetExpression extends AstNode_1.Expression {
424
426
  /**
425
427
  * Can either be `[` or `?[`. If `?.[` is used, this will be `[` and `optionalChainingToken` will be `?.`
426
428
  */
427
- openingSquare, closingSquare, questionDotToken // ? or ?.
428
- ) {
429
+ openingSquare, closingSquare, questionDotToken, // ? or ?.
430
+ /**
431
+ * More indexes, separated by commas
432
+ */
433
+ additionalIndexes) {
434
+ var _a;
429
435
  super();
430
436
  this.obj = obj;
431
437
  this.index = index;
432
438
  this.openingSquare = openingSquare;
433
439
  this.closingSquare = closingSquare;
434
440
  this.questionDotToken = questionDotToken;
435
- this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
441
+ this.additionalIndexes = additionalIndexes;
436
442
  this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.questionDotToken, this.openingSquare, this.index, this.closingSquare);
443
+ (_a = this.additionalIndexes) !== null && _a !== void 0 ? _a : (this.additionalIndexes = []);
437
444
  }
438
445
  transpile(state) {
439
446
  var _a, _b;
440
- return [
441
- ...this.obj.transpile(state),
442
- this.questionDotToken ? state.transpileToken(this.questionDotToken) : '',
443
- state.transpileToken(this.openingSquare),
444
- ...((_b = (_a = this.index) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []),
445
- this.closingSquare ? state.transpileToken(this.closingSquare) : ''
446
- ];
447
+ const result = [];
448
+ result.push(...this.obj.transpile(state), this.questionDotToken ? state.transpileToken(this.questionDotToken) : '', state.transpileToken(this.openingSquare));
449
+ const indexes = [this.index, ...(_a = this.additionalIndexes) !== null && _a !== void 0 ? _a : []];
450
+ for (let i = 0; i < indexes.length; i++) {
451
+ //add comma between indexes
452
+ if (i > 0) {
453
+ result.push(', ');
454
+ }
455
+ let index = indexes[i];
456
+ result.push(...((_b = index === null || index === void 0 ? void 0 : index.transpile(state)) !== null && _b !== void 0 ? _b : []));
457
+ }
458
+ result.push(this.closingSquare ? state.transpileToken(this.closingSquare) : '');
459
+ return result;
447
460
  }
448
461
  walk(visitor, options) {
449
462
  if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
450
463
  (0, visitors_2.walk)(this, 'obj', visitor, options);
451
464
  (0, visitors_2.walk)(this, 'index', visitor, options);
465
+ (0, visitors_2.walkArray)(this.additionalIndexes, visitor, options, this);
452
466
  }
453
467
  }
454
- getType(options) {
455
- const objType = this.obj.getType(options);
456
- if ((0, reflection_1.isArrayType)(objType)) {
457
- // This is used on an array. What is the default type of that array?
458
- return objType.defaultType;
459
- }
460
- return super.getType(options);
461
- }
462
468
  }
463
469
  exports.IndexedGetExpression = IndexedGetExpression;
464
470
  class GroupingExpression extends AstNode_1.Expression {
@@ -466,10 +472,12 @@ class GroupingExpression extends AstNode_1.Expression {
466
472
  super();
467
473
  this.tokens = tokens;
468
474
  this.expression = expression;
469
- this.kind = AstNode_1.AstNodeKind.GroupingExpression;
470
475
  this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
471
476
  }
472
477
  transpile(state) {
478
+ if ((0, reflection_1.isTypeCastExpression)(this.expression)) {
479
+ return this.expression.transpile(state);
480
+ }
473
481
  return [
474
482
  state.transpileToken(this.tokens.left),
475
483
  ...this.expression.transpile(state),
@@ -481,30 +489,24 @@ class GroupingExpression extends AstNode_1.Expression {
481
489
  (0, visitors_2.walk)(this, 'expression', visitor, options);
482
490
  }
483
491
  }
484
- getType(options) {
485
- return this.expression.getType(options);
486
- }
487
492
  }
488
493
  exports.GroupingExpression = GroupingExpression;
489
494
  class LiteralExpression extends AstNode_1.Expression {
490
495
  constructor(token) {
491
496
  super();
492
497
  this.token = token;
493
- this.kind = AstNode_1.AstNodeKind.LiteralExpression;
498
+ this.type = util_1.default.tokenToBscType(token);
494
499
  }
495
500
  get range() {
496
501
  return this.token.range;
497
502
  }
498
- getType(options) {
499
- return util_1.default.tokenToBscType(this.token);
500
- }
501
503
  transpile(state) {
502
504
  let text;
503
505
  if (this.token.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
504
506
  //wrap quasis with quotes (and escape inner quotemarks)
505
507
  text = `"${this.token.text.replace(/"/g, '""')}"`;
506
508
  }
507
- else if (this.token.kind === TokenKind_1.TokenKind.StringLiteral) {
509
+ else if ((0, reflection_1.isStringType)(this.type)) {
508
510
  text = this.token.text;
509
511
  //add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
510
512
  if (text.endsWith('"') === false) {
@@ -531,7 +533,6 @@ class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
531
533
  constructor(token) {
532
534
  super();
533
535
  this.token = token;
534
- this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
535
536
  this.range = token.range;
536
537
  }
537
538
  transpile(state) {
@@ -551,7 +552,6 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
551
552
  this.open = open;
552
553
  this.close = close;
553
554
  this.hasSpread = hasSpread;
554
- this.kind = AstNode_1.AstNodeKind.ArrayLiteralExpression;
555
555
  this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
556
556
  }
557
557
  transpile(state) {
@@ -595,10 +595,6 @@ class ArrayLiteralExpression extends AstNode_1.Expression {
595
595
  (0, visitors_2.walkArray)(this.elements, visitor, options, this);
596
596
  }
597
597
  }
598
- getType(options) {
599
- const innerTypes = this.elements.filter(x => !(0, reflection_1.isCommentStatement)(x)).map(expr => expr.getType(options));
600
- return new types_1.ArrayType(...innerTypes);
601
- }
602
598
  }
603
599
  exports.ArrayLiteralExpression = ArrayLiteralExpression;
604
600
  class AAMemberExpression extends AstNode_1.Expression {
@@ -609,7 +605,6 @@ class AAMemberExpression extends AstNode_1.Expression {
609
605
  this.keyToken = keyToken;
610
606
  this.colonToken = colonToken;
611
607
  this.value = value;
612
- this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
613
608
  this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
614
609
  }
615
610
  transpile(state) {
@@ -619,9 +614,6 @@ class AAMemberExpression extends AstNode_1.Expression {
619
614
  walk(visitor, options) {
620
615
  (0, visitors_2.walk)(this, 'value', visitor, options);
621
616
  }
622
- getType(options) {
623
- return this.value.getType(options);
624
- }
625
617
  }
626
618
  exports.AAMemberExpression = AAMemberExpression;
627
619
  class AALiteralExpression extends AstNode_1.Expression {
@@ -630,10 +622,10 @@ class AALiteralExpression extends AstNode_1.Expression {
630
622
  this.elements = elements;
631
623
  this.open = open;
632
624
  this.close = close;
633
- this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
634
625
  this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
635
626
  }
636
627
  transpile(state) {
628
+ var _a, _b;
637
629
  let result = [];
638
630
  //open curly
639
631
  result.push(state.transpileToken(this.open));
@@ -669,7 +661,7 @@ class AALiteralExpression extends AstNode_1.Expression {
669
661
  result.push(...element.value.transpile(state));
670
662
  }
671
663
  //if next element is a same-line comment, skip the newline
672
- if (nextElement && (0, reflection_1.isCommentStatement)(nextElement) && nextElement.range.start.line === element.range.start.line) {
664
+ if (nextElement && (0, reflection_1.isCommentStatement)(nextElement) && ((_a = nextElement.range) === null || _a === void 0 ? void 0 : _a.start.line) === ((_b = element.range) === null || _b === void 0 ? void 0 : _b.start.line)) {
673
665
  //add a newline between statements
674
666
  }
675
667
  else {
@@ -692,15 +684,6 @@ class AALiteralExpression extends AstNode_1.Expression {
692
684
  (0, visitors_2.walkArray)(this.elements, visitor, options, this);
693
685
  }
694
686
  }
695
- getType(options) {
696
- const resultType = new AssociativeArrayType_1.AssociativeArrayType();
697
- for (const element of this.elements) {
698
- if ((0, reflection_1.isAAMemberExpression)(element)) {
699
- resultType.addMember(element.keyToken.text, { definingNode: element }, element.getType(options), SymbolTable_1.SymbolTypeFlag.runtime);
700
- }
701
- }
702
- return resultType;
703
- }
704
687
  }
705
688
  exports.AALiteralExpression = AALiteralExpression;
706
689
  class UnaryExpression extends AstNode_1.Expression {
@@ -708,7 +691,6 @@ class UnaryExpression extends AstNode_1.Expression {
708
691
  super();
709
692
  this.operator = operator;
710
693
  this.right = right;
711
- this.kind = AstNode_1.AstNodeKind.UnaryExpression;
712
694
  this.range = util_1.default.createBoundingRange(this.operator, this.right);
713
695
  }
714
696
  transpile(state) {
@@ -719,12 +701,9 @@ class UnaryExpression extends AstNode_1.Expression {
719
701
  else if ((0, reflection_1.isLiteralExpression)(this.right)) {
720
702
  separatingWhitespace = this.right.token.leadingWhitespace;
721
703
  }
722
- else {
723
- separatingWhitespace = ' ';
724
- }
725
704
  return [
726
705
  state.transpileToken(this.operator),
727
- separatingWhitespace,
706
+ separatingWhitespace !== null && separatingWhitespace !== void 0 ? separatingWhitespace : ' ',
728
707
  ...this.right.transpile(state)
729
708
  ];
730
709
  }
@@ -733,9 +712,6 @@ class UnaryExpression extends AstNode_1.Expression {
733
712
  (0, visitors_2.walk)(this, 'right', visitor, options);
734
713
  }
735
714
  }
736
- getType(options) {
737
- return util_1.default.unaryOperatorResultType(this.operator, this.right.getType(options));
738
- }
739
715
  }
740
716
  exports.UnaryExpression = UnaryExpression;
741
717
  class VariableExpression extends AstNode_1.Expression {
@@ -743,7 +719,6 @@ class VariableExpression extends AstNode_1.Expression {
743
719
  var _a;
744
720
  super();
745
721
  this.name = name;
746
- this.kind = AstNode_1.AstNodeKind.VariableExpression;
747
722
  this.range = (_a = this.name) === null || _a === void 0 ? void 0 : _a.range;
748
723
  }
749
724
  getName(parseMode) {
@@ -753,7 +728,7 @@ class VariableExpression extends AstNode_1.Expression {
753
728
  let result = [];
754
729
  const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
755
730
  //if the callee is the name of a known namespace function
756
- if (state.file.calleeIsKnownNamespaceFunction(this, namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) {
731
+ if (namespace && state.file.calleeIsKnownNamespaceFunction(this, namespace.getName(Parser_1.ParseMode.BrighterScript))) {
757
732
  result.push(state.sourceNode(this, [
758
733
  namespace.getName(Parser_1.ParseMode.BrightScript),
759
734
  '_',
@@ -769,56 +744,39 @@ class VariableExpression extends AstNode_1.Expression {
769
744
  walk(visitor, options) {
770
745
  //nothing to walk
771
746
  }
772
- getType(options) {
773
- var _a;
774
- let resultType = util_1.default.tokenToBscType(this.name);
775
- const nameKey = this.name.text;
776
- if (!resultType) {
777
- const symbolTable = this.getSymbolTable();
778
- resultType = symbolTable === null || symbolTable === void 0 ? void 0 : symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
779
- }
780
- (_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry(nameKey, resultType, options.flags, this.range));
781
- return resultType;
782
- }
783
747
  }
784
748
  exports.VariableExpression = VariableExpression;
785
749
  class SourceLiteralExpression extends AstNode_1.Expression {
786
750
  constructor(token) {
787
751
  super();
788
752
  this.token = token;
789
- this.kind = AstNode_1.AstNodeKind.SourceLiteralExpression;
790
753
  this.range = token === null || token === void 0 ? void 0 : token.range;
791
754
  }
792
- /**
793
- * Find the index of the function in its parent
794
- */
795
- findFunctionIndex(parentFunction, func) {
796
- let index = -1;
797
- parentFunction.findChild((node) => {
798
- if ((0, reflection_1.isFunctionExpression)(node)) {
799
- index++;
800
- if (node === func) {
801
- return true;
802
- }
803
- }
804
- }, {
805
- walkMode: visitors_1.WalkMode.visitAllRecursive
806
- });
807
- return index;
808
- }
809
755
  getFunctionName(state, parseMode) {
810
- let func = state.file.getFunctionScopeAtPosition(this.token.range.start).func;
756
+ let func = this.findAncestor(reflection_1.isFunctionExpression);
811
757
  let nameParts = [];
812
- let parentFunction;
813
- while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
814
- let index = this.findFunctionIndex(parentFunction, func);
758
+ while (func.parentFunction) {
759
+ let index = func.parentFunction.childFunctionExpressions.indexOf(func);
815
760
  nameParts.unshift(`anon${index}`);
816
- func = parentFunction;
761
+ func = func.parentFunction;
817
762
  }
818
763
  //get the index of this function in its parent
819
764
  nameParts.unshift(func.functionStatement.getName(parseMode));
820
765
  return nameParts.join('$');
821
766
  }
767
+ /**
768
+ * Get the line number from our token or from the closest ancestor that has a range
769
+ */
770
+ getClosestLineNumber() {
771
+ let node = this;
772
+ while (node) {
773
+ if (node.range) {
774
+ return node.range.start.line + 1;
775
+ }
776
+ node = node.parent;
777
+ }
778
+ return -1;
779
+ }
822
780
  transpile(state) {
823
781
  let text;
824
782
  switch (this.token.kind) {
@@ -827,7 +785,8 @@ class SourceLiteralExpression extends AstNode_1.Expression {
827
785
  text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
828
786
  break;
829
787
  case TokenKind_1.TokenKind.SourceLineNumLiteral:
830
- text = `${this.token.range.start.line + 1}`;
788
+ //TODO find first parent that has range, or default to -1
789
+ text = `${this.getClosestLineNumber()}`;
831
790
  break;
832
791
  case TokenKind_1.TokenKind.FunctionNameLiteral:
833
792
  text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
@@ -837,13 +796,20 @@ class SourceLiteralExpression extends AstNode_1.Expression {
837
796
  break;
838
797
  case TokenKind_1.TokenKind.SourceLocationLiteral:
839
798
  const locationUrl = fileUrl(state.srcPath);
840
- text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
799
+ //TODO find first parent that has range, or default to -1
800
+ text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.getClosestLineNumber()}"`;
841
801
  break;
842
802
  case TokenKind_1.TokenKind.PkgPathLiteral:
843
- text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
803
+ let pkgPath1 = `pkg:/${state.file.pkgPath}`
804
+ .replace(/\\/g, '/')
805
+ .replace(/\.bs$/i, '.brs');
806
+ text = `"${pkgPath1}"`;
844
807
  break;
845
808
  case TokenKind_1.TokenKind.PkgLocationLiteral:
846
- text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}:" + str(LINE_NUM)`;
809
+ let pkgPath2 = `pkg:/${state.file.pkgPath}`
810
+ .replace(/\\/g, '/')
811
+ .replace(/\.bs$/i, '.brs');
812
+ text = `"${pkgPath2}:" + str(LINE_NUM)`;
847
813
  break;
848
814
  case TokenKind_1.TokenKind.LineNumLiteral:
849
815
  default:
@@ -870,7 +836,6 @@ class NewExpression extends AstNode_1.Expression {
870
836
  super();
871
837
  this.newKeyword = newKeyword;
872
838
  this.call = call;
873
- this.kind = AstNode_1.AstNodeKind.NewExpression;
874
839
  this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
875
840
  }
876
841
  /**
@@ -878,7 +843,7 @@ class NewExpression extends AstNode_1.Expression {
878
843
  */
879
844
  get className() {
880
845
  //the parser guarantees the callee of a new statement's call object will be
881
- //either a VariableExpression or a DottedGet
846
+ //a NamespacedVariableNameExpression
882
847
  return this.call.callee;
883
848
  }
884
849
  transpile(state) {
@@ -894,9 +859,6 @@ class NewExpression extends AstNode_1.Expression {
894
859
  (0, visitors_2.walk)(this, 'call', visitor, options);
895
860
  }
896
861
  }
897
- getType(options) {
898
- return this.call.getType(options);
899
- }
900
862
  }
901
863
  exports.NewExpression = NewExpression;
902
864
  class CallfuncExpression extends AstNode_1.Expression {
@@ -908,9 +870,16 @@ class CallfuncExpression extends AstNode_1.Expression {
908
870
  this.openingParen = openingParen;
909
871
  this.args = args;
910
872
  this.closingParen = closingParen;
911
- this.kind = AstNode_1.AstNodeKind.CallfuncExpression;
912
873
  this.range = util_1.default.createBoundingRange(callee, operator, methodName, openingParen, ...args, closingParen);
913
874
  }
875
+ /**
876
+ * Get the name of the wrapping namespace (if it exists)
877
+ * @deprecated use `.findAncestor(isNamespaceStatement)` instead.
878
+ */
879
+ get namespaceName() {
880
+ var _a;
881
+ return (_a = this.findAncestor(reflection_1.isNamespaceStatement)) === null || _a === void 0 ? void 0 : _a.nameExpression;
882
+ }
914
883
  transpile(state) {
915
884
  let result = [];
916
885
  result.push(...this.callee.transpile(state), state.sourceNode(this.operator, '.callfunc'), state.transpileToken(this.openingParen),
@@ -940,31 +909,6 @@ class CallfuncExpression extends AstNode_1.Expression {
940
909
  (0, visitors_2.walkArray)(this.args, visitor, options, this);
941
910
  }
942
911
  }
943
- getType(options) {
944
- var _a;
945
- let result = DynamicType_1.DynamicType.instance;
946
- // a little hacky here with checking options.ignoreCall because callFuncExpression has the method name
947
- // It's nicer for CallExpression, because it's a call on any expression.
948
- const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.runtime }));
949
- if ((0, reflection_1.isComponentType)(calleeType) || (0, reflection_1.isReferenceType)(calleeType)) {
950
- const funcType = calleeType.getCallFuncType(this.methodName.text, options);
951
- (_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry(this.methodName.text, funcType, options.flags, this.methodName.range, (0, creators_1.createToken)(TokenKind_1.TokenKind.Callfunc)));
952
- if (options.ignoreCall) {
953
- result = funcType;
954
- }
955
- /* TODO:
956
- make callfunc return types work
957
- else if (isCallableType(funcType) && (!isReferenceType(funcType.returnType) || funcType.returnType.isResolvable())) {
958
- result = funcType.returnType;
959
- } else if (!isReferenceType(funcType) && (funcType as any)?.returnType?.isResolvable()) {
960
- result = (funcType as any).returnType;
961
- } else {
962
- return new TypePropertyReferenceType(funcType, 'returnType');
963
- }
964
- */
965
- }
966
- return result;
967
- }
968
912
  }
969
913
  exports.CallfuncExpression = CallfuncExpression;
970
914
  /**
@@ -975,7 +919,6 @@ class TemplateStringQuasiExpression extends AstNode_1.Expression {
975
919
  constructor(expressions) {
976
920
  super();
977
921
  this.expressions = expressions;
978
- this.kind = AstNode_1.AstNodeKind.TemplateStringQuasiExpression;
979
922
  this.range = util_1.default.createBoundingRange(...expressions);
980
923
  }
981
924
  transpile(state, skipEmptyStrings = true) {
@@ -1006,12 +949,8 @@ class TemplateStringExpression extends AstNode_1.Expression {
1006
949
  this.quasis = quasis;
1007
950
  this.expressions = expressions;
1008
951
  this.closingBacktick = closingBacktick;
1009
- this.kind = AstNode_1.AstNodeKind.TemplateStringExpression;
1010
952
  this.range = util_1.default.createBoundingRange(openingBacktick, quasis[0], quasis[quasis.length - 1], closingBacktick);
1011
953
  }
1012
- getType(options) {
1013
- return StringType_1.StringType.instance;
1014
- }
1015
954
  transpile(state) {
1016
955
  if (this.quasis.length === 1 && this.expressions.length === 0) {
1017
956
  return this.quasis[0].transpile(state);
@@ -1035,7 +974,7 @@ class TemplateStringExpression extends AstNode_1.Expression {
1035
974
  if (expression) {
1036
975
  //skip the toString wrapper around certain expressions
1037
976
  if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
1038
- ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.getType()))) {
977
+ ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.type))) {
1039
978
  add(...expression.transpile(state));
1040
979
  //wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
1041
980
  }
@@ -1070,7 +1009,6 @@ class TaggedTemplateStringExpression extends AstNode_1.Expression {
1070
1009
  this.quasis = quasis;
1071
1010
  this.expressions = expressions;
1072
1011
  this.closingBacktick = closingBacktick;
1073
- this.kind = AstNode_1.AstNodeKind.TaggedTemplateStringExpression;
1074
1012
  this.range = util_1.default.createBoundingRange(tagName, openingBacktick, quasis[0], quasis[quasis.length - 1], closingBacktick);
1075
1013
  }
1076
1014
  transpile(state) {
@@ -1116,9 +1054,10 @@ class AnnotationExpression extends AstNode_1.Expression {
1116
1054
  super();
1117
1055
  this.atToken = atToken;
1118
1056
  this.nameToken = nameToken;
1119
- this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
1120
1057
  this.name = nameToken.text;
1121
- this.range = util_1.default.createBoundingRange(atToken, nameToken);
1058
+ }
1059
+ get range() {
1060
+ return util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
1122
1061
  }
1123
1062
  /**
1124
1063
  * Convert annotation arguments to JavaScript types
@@ -1130,9 +1069,6 @@ class AnnotationExpression extends AstNode_1.Expression {
1130
1069
  }
1131
1070
  return this.call.args.map(e => expressionToValue(e, strict));
1132
1071
  }
1133
- getLeadingTrivia() {
1134
- return this.atToken.leadingTrivia;
1135
- }
1136
1072
  transpile(state) {
1137
1073
  return [];
1138
1074
  }
@@ -1157,14 +1093,14 @@ class TernaryExpression extends AstNode_1.Expression {
1157
1093
  this.consequent = consequent;
1158
1094
  this.colonToken = colonToken;
1159
1095
  this.alternate = alternate;
1160
- this.kind = AstNode_1.AstNodeKind.TernaryExpression;
1161
1096
  this.range = util_1.default.createBoundingRange(test, questionMarkToken, consequent, colonToken, alternate);
1162
1097
  }
1163
1098
  transpile(state) {
1164
1099
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
1165
1100
  let result = [];
1166
- let consequentInfo = util_1.default.getExpressionInfo(this.consequent);
1167
- let alternateInfo = util_1.default.getExpressionInfo(this.alternate);
1101
+ const file = state.file;
1102
+ let consequentInfo = util_1.default.getExpressionInfo(this.consequent, file);
1103
+ let alternateInfo = util_1.default.getExpressionInfo(this.alternate, file);
1168
1104
  //get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
1169
1105
  let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
1170
1106
  let mutatingExpressions = [
@@ -1175,9 +1111,9 @@ class TernaryExpression extends AstNode_1.Expression {
1175
1111
  result.push(state.sourceNode(this.questionMarkToken,
1176
1112
  //write all the scope variables as parameters.
1177
1113
  //TODO handle when there are more than 31 parameters
1178
- `(function(__bsCondition, ${allUniqueVarNames.join(', ')})`), state.newline,
1114
+ `(function(${['__bsCondition', ...allUniqueVarNames].join(', ')})`), state.newline,
1179
1115
  //double indent so our `end function` line is still indented one at the end
1180
- state.indent(2), state.sourceNode(this.test, `if __bsCondition then`), state.newline, state.indent(1), state.sourceNode((_a = this.consequent) !== null && _a !== void 0 ? _a : this.questionMarkToken, 'return '), ...(_c = (_b = this.consequent) === null || _b === void 0 ? void 0 : _b.transpile(state)) !== null && _c !== void 0 ? _c : [state.sourceNode(this.questionMarkToken, 'invalid')], state.newline, state.indent(-1), state.sourceNode((_d = this.consequent) !== null && _d !== void 0 ? _d : this.questionMarkToken, 'else'), state.newline, state.indent(1), state.sourceNode((_e = this.consequent) !== null && _e !== void 0 ? _e : this.questionMarkToken, 'return '), ...(_g = (_f = this.alternate) === null || _f === void 0 ? void 0 : _f.transpile(state)) !== null && _g !== void 0 ? _g : [state.sourceNode((_h = this.consequent) !== null && _h !== void 0 ? _h : this.questionMarkToken, 'invalid')], state.newline, state.indent(-1), state.sourceNode(this.questionMarkToken, 'end if'), state.newline, state.indent(-1), state.sourceNode(this.questionMarkToken, 'end function)('), ...this.test.transpile(state), state.sourceNode(this.questionMarkToken, `, ${allUniqueVarNames.join(', ')})`));
1116
+ state.indent(2), state.sourceNode(this.test, `if __bsCondition then`), state.newline, state.indent(1), state.sourceNode((_a = this.consequent) !== null && _a !== void 0 ? _a : this.questionMarkToken, 'return '), ...(_c = (_b = this.consequent) === null || _b === void 0 ? void 0 : _b.transpile(state)) !== null && _c !== void 0 ? _c : [state.sourceNode(this.questionMarkToken, 'invalid')], state.newline, state.indent(-1), state.sourceNode((_d = this.consequent) !== null && _d !== void 0 ? _d : this.questionMarkToken, 'else'), state.newline, state.indent(1), state.sourceNode((_e = this.consequent) !== null && _e !== void 0 ? _e : this.questionMarkToken, 'return '), ...(_g = (_f = this.alternate) === null || _f === void 0 ? void 0 : _f.transpile(state)) !== null && _g !== void 0 ? _g : [state.sourceNode((_h = this.consequent) !== null && _h !== void 0 ? _h : this.questionMarkToken, 'invalid')], state.newline, state.indent(-1), state.sourceNode(this.questionMarkToken, 'end if'), state.newline, state.indent(-1), state.sourceNode(this.questionMarkToken, 'end function)('), ...this.test.transpile(state), state.sourceNode(this.questionMarkToken, `${['', ...allUniqueVarNames].join(', ')})`));
1181
1117
  state.blockDepth--;
1182
1118
  }
1183
1119
  else {
@@ -1200,13 +1136,12 @@ class NullCoalescingExpression extends AstNode_1.Expression {
1200
1136
  this.consequent = consequent;
1201
1137
  this.questionQuestionToken = questionQuestionToken;
1202
1138
  this.alternate = alternate;
1203
- this.kind = AstNode_1.AstNodeKind.NullCoalescingExpression;
1204
1139
  this.range = util_1.default.createBoundingRange(consequent, questionQuestionToken, alternate);
1205
1140
  }
1206
1141
  transpile(state) {
1207
1142
  let result = [];
1208
- let consequentInfo = util_1.default.getExpressionInfo(this.consequent);
1209
- let alternateInfo = util_1.default.getExpressionInfo(this.alternate);
1143
+ let consequentInfo = util_1.default.getExpressionInfo(this.consequent, state.file);
1144
+ let alternateInfo = util_1.default.getExpressionInfo(this.alternate, state.file);
1210
1145
  //get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
1211
1146
  let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
1212
1147
  let hasMutatingExpression = [
@@ -1241,7 +1176,6 @@ class RegexLiteralExpression extends AstNode_1.Expression {
1241
1176
  constructor(tokens) {
1242
1177
  super();
1243
1178
  this.tokens = tokens;
1244
- this.kind = AstNode_1.AstNodeKind.RegexLiteralExpression;
1245
1179
  }
1246
1180
  get range() {
1247
1181
  var _a, _b;
@@ -1276,6 +1210,24 @@ class RegexLiteralExpression extends AstNode_1.Expression {
1276
1210
  }
1277
1211
  }
1278
1212
  exports.RegexLiteralExpression = RegexLiteralExpression;
1213
+ class TypeCastExpression extends AstNode_1.Expression {
1214
+ constructor(obj, asToken, typeToken) {
1215
+ super();
1216
+ this.obj = obj;
1217
+ this.asToken = asToken;
1218
+ this.typeToken = typeToken;
1219
+ this.range = util_1.default.createBoundingRange(this.obj, this.asToken, this.typeToken);
1220
+ }
1221
+ transpile(state) {
1222
+ return this.obj.transpile(state);
1223
+ }
1224
+ walk(visitor, options) {
1225
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1226
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
1227
+ }
1228
+ }
1229
+ }
1230
+ exports.TypeCastExpression = TypeCastExpression;
1279
1231
  function expressionToValue(expr, strict) {
1280
1232
  if (!expr) {
1281
1233
  return null;
@@ -1309,92 +1261,11 @@ function expressionToValue(expr, strict) {
1309
1261
  return strict ? null : expr;
1310
1262
  }
1311
1263
  function numberExpressionToValue(expr, operator = '') {
1312
- if ((0, reflection_1.isIntegerType)(expr.getType()) || (0, reflection_1.isLongIntegerType)(expr.getType())) {
1264
+ if ((0, reflection_1.isIntegerType)(expr.type) || (0, reflection_1.isLongIntegerType)(expr.type)) {
1313
1265
  return parseInt(operator + expr.token.text);
1314
1266
  }
1315
1267
  else {
1316
1268
  return parseFloat(operator + expr.token.text);
1317
1269
  }
1318
1270
  }
1319
- class TypeExpression extends AstNode_1.Expression {
1320
- constructor(
1321
- /**
1322
- * The standard AST expression that represents the type for this TypeExpression.
1323
- */
1324
- expression) {
1325
- super();
1326
- this.expression = expression;
1327
- this.kind = AstNode_1.AstNodeKind.TypeExpression;
1328
- this.range = expression === null || expression === void 0 ? void 0 : expression.range;
1329
- }
1330
- transpile(state) {
1331
- return [this.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime }).toTypeString()];
1332
- }
1333
- walk(visitor, options) {
1334
- if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1335
- (0, visitors_2.walk)(this, 'expression', visitor, options);
1336
- }
1337
- }
1338
- getType(options) {
1339
- return this.expression.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.typetime }));
1340
- }
1341
- getTypedef(state) {
1342
- // TypeDefs should pass through any valid type names
1343
- return this.expression.transpile(state);
1344
- }
1345
- getName(parseMode = Parser_1.ParseMode.BrighterScript) {
1346
- //TODO: this may not support Complex Types, eg. generics or Unions
1347
- return util_1.default.getAllDottedGetPartsAsString(this.expression, parseMode);
1348
- }
1349
- getNameParts() {
1350
- //TODO: really, this code is only used to get Namespaces. It could be more clear.
1351
- return util_1.default.getAllDottedGetParts(this.expression).map(x => x.text);
1352
- }
1353
- }
1354
- exports.TypeExpression = TypeExpression;
1355
- class TypeCastExpression extends AstNode_1.Expression {
1356
- constructor(obj, asToken, typeExpression) {
1357
- super();
1358
- this.obj = obj;
1359
- this.asToken = asToken;
1360
- this.typeExpression = typeExpression;
1361
- this.kind = AstNode_1.AstNodeKind.TypeCastExpression;
1362
- this.range = util_1.default.createBoundingRange(this.obj, this.asToken, this.typeExpression);
1363
- }
1364
- transpile(state) {
1365
- return this.obj.transpile(state);
1366
- }
1367
- walk(visitor, options) {
1368
- if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1369
- (0, visitors_2.walk)(this, 'obj', visitor, options);
1370
- (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
1371
- }
1372
- }
1373
- getType(options) {
1374
- return this.typeExpression.getType(options);
1375
- }
1376
- }
1377
- exports.TypeCastExpression = TypeCastExpression;
1378
- class TypedArrayExpression extends AstNode_1.Expression {
1379
- constructor(innerType, leftBracket, rightBracket) {
1380
- super();
1381
- this.innerType = innerType;
1382
- this.leftBracket = leftBracket;
1383
- this.rightBracket = rightBracket;
1384
- this.kind = AstNode_1.AstNodeKind.TypedArrayExpression;
1385
- this.range = util_1.default.createBoundingRange(this.innerType, this.leftBracket, this.rightBracket);
1386
- }
1387
- transpile(state) {
1388
- return [this.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime }).toTypeString()];
1389
- }
1390
- walk(visitor, options) {
1391
- if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1392
- (0, visitors_2.walk)(this, 'innerType', visitor, options);
1393
- }
1394
- }
1395
- getType(options) {
1396
- return new types_1.ArrayType(this.innerType.getType(options));
1397
- }
1398
- }
1399
- exports.TypedArrayExpression = TypedArrayExpression;
1400
1271
  //# sourceMappingURL=Expression.js.map