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
@@ -1,77 +1,82 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayTypeExpression = 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.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = exports.Expression = void 0;
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;
4
4
  const TokenKind_1 = require("../lexer/TokenKind");
5
5
  const util_1 = require("../util");
6
6
  const Parser_1 = require("./Parser");
7
7
  const fileUrl = require("file-url");
8
8
  const visitors_1 = require("../astUtils/visitors");
9
+ const visitors_2 = require("../astUtils/visitors");
9
10
  const reflection_1 = require("../astUtils/reflection");
11
+ const interfaces_1 = require("../interfaces");
10
12
  const VoidType_1 = require("../types/VoidType");
11
13
  const DynamicType_1 = require("../types/DynamicType");
12
14
  const SymbolTable_1 = require("../SymbolTable");
13
- const ArrayType_1 = require("../types/ArrayType");
14
- const ObjectType_1 = require("../types/ObjectType");
15
15
  const TypedFunctionType_1 = require("../types/TypedFunctionType");
16
- /** A BrightScript expression */
17
- class Expression {
18
- constructor() {
19
- /**
20
- * When being considered by the walk visitor, this describes what type of element the current class is.
21
- */
22
- this.visitMode = visitors_1.InternalWalkMode.visitExpressions;
23
- }
24
- /**
25
- * Get the closest symbol table for this node. Should be overridden in children that directly contain a symbol table
26
- */
27
- getSymbolTable() {
28
- var _a;
29
- return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable();
30
- }
31
- }
32
- exports.Expression = Expression;
33
- class BinaryExpression extends Expression {
34
- constructor(left, operator, right) {
16
+ const AstNode_1 = require("./AstNode");
17
+ const SymbolTable_2 = require("../SymbolTable");
18
+ const source_map_1 = require("source-map");
19
+ const StringType_1 = require("../types/StringType");
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
+ class BinaryExpression extends AstNode_1.Expression {
26
+ constructor(options) {
35
27
  super();
36
- this.left = left;
37
- this.operator = operator;
38
- this.right = right;
39
- this.range = util_1.default.createBoundingRange(this.left, this.right);
28
+ this.kind = AstNode_1.AstNodeKind.BinaryExpression;
29
+ this.tokens = {
30
+ operator: options.operator
31
+ };
32
+ this.left = options.left;
33
+ this.right = options.right;
34
+ this.range = util_1.default.createBoundingRange(this.left, this.tokens.operator, this.right);
40
35
  }
41
36
  transpile(state) {
42
37
  return [
43
38
  state.sourceNode(this.left, this.left.transpile(state)),
44
39
  ' ',
45
- state.transpileToken(this.operator),
40
+ state.transpileToken(this.tokens.operator),
46
41
  ' ',
47
42
  state.sourceNode(this.right, this.right.transpile(state))
48
43
  ];
49
44
  }
50
45
  walk(visitor, options) {
51
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
52
- (0, visitors_1.walk)(this, 'left', visitor, options);
53
- (0, visitors_1.walk)(this, 'right', visitor, options);
46
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
47
+ (0, visitors_2.walk)(this, 'left', visitor, options);
48
+ (0, visitors_2.walk)(this, 'right', visitor, options);
49
+ }
50
+ }
51
+ getType(options) {
52
+ const operatorKind = this.tokens.operator.kind;
53
+ if (options.flags & SymbolTable_1.SymbolTypeFlag.typetime) {
54
+ // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
55
+ switch (operatorKind) {
56
+ case TokenKind_1.TokenKind.Or:
57
+ return new UnionType_1.UnionType([this.left.getType(options), this.right.getType(options)]);
58
+ //TODO: Intersection Types?, eg. case TokenKind.And:
59
+ }
60
+ }
61
+ else if (options.flags & SymbolTable_1.SymbolTypeFlag.runtime) {
62
+ return util_1.default.binaryOperatorResultType(this.left.getType(options), this.tokens.operator, this.right.getType(options));
54
63
  }
64
+ return DynamicType_1.DynamicType.instance;
55
65
  }
56
66
  }
57
67
  exports.BinaryExpression = BinaryExpression;
58
- class CallExpression extends Expression {
59
- constructor(callee,
60
- /**
61
- * Can either be `(`, or `?(` for optional chaining
62
- */
63
- openingParen, closingParen, args,
64
- /**
65
- * The namespace that currently wraps this call expression. This is NOT the namespace of the callee...that will be represented in the callee expression itself.
66
- */
67
- namespaceName) {
68
+ class CallExpression extends AstNode_1.Expression {
69
+ constructor(options) {
70
+ var _a;
68
71
  super();
69
- this.callee = callee;
70
- this.openingParen = openingParen;
71
- this.closingParen = closingParen;
72
- this.args = args;
73
- this.namespaceName = namespaceName;
74
- this.range = util_1.default.createBoundingRange(this.callee, this.closingParen);
72
+ this.kind = AstNode_1.AstNodeKind.CallExpression;
73
+ this.tokens = {
74
+ openingParen: options.openingParen,
75
+ closingParen: options.closingParen
76
+ };
77
+ this.callee = options.callee;
78
+ this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
79
+ this.range = util_1.default.createBoundingRange(this.callee, this.tokens.openingParen, ...this.args, this.tokens.closingParen);
75
80
  }
76
81
  transpile(state, nameOverride) {
77
82
  let result = [];
@@ -82,7 +87,7 @@ class CallExpression extends Expression {
82
87
  else {
83
88
  result.push(...this.callee.transpile(state));
84
89
  }
85
- result.push(state.transpileToken(this.openingParen));
90
+ result.push(state.transpileToken(this.tokens.openingParen, '('));
86
91
  for (let i = 0; i < this.args.length; i++) {
87
92
  //add comma between args
88
93
  if (i > 0) {
@@ -91,100 +96,85 @@ class CallExpression extends Expression {
91
96
  let arg = this.args[i];
92
97
  result.push(...arg.transpile(state));
93
98
  }
94
- result.push(state.transpileToken(this.closingParen));
99
+ if (this.tokens.closingParen) {
100
+ result.push(state.transpileToken(this.tokens.closingParen));
101
+ }
95
102
  return result;
96
103
  }
97
104
  walk(visitor, options) {
98
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
99
- (0, visitors_1.walk)(this, 'callee', visitor, options);
100
- (0, visitors_1.walkArray)(this.args, visitor, options, this);
105
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
106
+ (0, visitors_2.walk)(this, 'callee', visitor, options);
107
+ (0, visitors_2.walkArray)(this.args, visitor, options, this);
101
108
  }
102
109
  }
110
+ getType(options) {
111
+ var _a, _b;
112
+ const calleeType = this.callee.getType(options);
113
+ if (options.ignoreCall) {
114
+ return calleeType;
115
+ }
116
+ if ((0, reflection_1.isNewExpression)(this.parent)) {
117
+ return calleeType;
118
+ }
119
+ if ((0, reflection_1.isCallableType)(calleeType) && (!(0, reflection_1.isReferenceType)(calleeType.returnType) || ((_a = calleeType.returnType) === null || _a === void 0 ? void 0 : _a.isResolvable()))) {
120
+ return calleeType.returnType;
121
+ }
122
+ if (!(0, reflection_1.isReferenceType)(calleeType) && ((_b = calleeType.returnType) === null || _b === void 0 ? void 0 : _b.isResolvable())) {
123
+ return calleeType.returnType;
124
+ }
125
+ return new ReferenceType_1.TypePropertyReferenceType(calleeType, 'returnType');
126
+ }
103
127
  }
104
128
  exports.CallExpression = CallExpression;
105
- CallExpression.MaximumArguments = util_1.MAX_PARAM_COUNT;
106
- class FunctionExpression extends Expression {
107
- constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnType,
108
- /**
109
- * If this function is enclosed within another function, this will reference that parent function
110
- */
111
- parentFunction, namespaceName, parentSymbolTable) {
129
+ CallExpression.MaximumArguments = 32;
130
+ class FunctionExpression extends AstNode_1.Expression {
131
+ constructor(options) {
132
+ var _a;
112
133
  super();
113
- this.parameters = parameters;
114
- this.body = body;
115
- this.functionType = functionType;
116
- this.end = end;
117
- this.leftParen = leftParen;
118
- this.rightParen = rightParen;
119
- this.asToken = asToken;
120
- this.returnType = returnType;
121
- this.parentFunction = parentFunction;
122
- this.namespaceName = namespaceName;
123
- this.parentSymbolTable = parentSymbolTable;
124
- this.labelStatements = [];
134
+ this.kind = AstNode_1.AstNodeKind.FunctionExpression;
125
135
  /**
126
136
  * The list of function calls that are declared within this function scope. This excludes CallExpressions
127
137
  * declared in child functions
128
138
  */
129
139
  this.callExpressions = [];
130
- /**
131
- * A list of all child functions declared directly within this function
132
- */
133
- this.childFunctionExpressions = [];
134
- if (this.returnType) {
135
- this._returnType = this.returnType.type;
136
- }
137
- else if (this.functionType.text.toLowerCase() === 'sub') {
138
- this._returnType = new VoidType_1.VoidType();
139
- }
140
- else {
141
- this._returnType = new DynamicType_1.DynamicType();
142
- }
143
- this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable, `Function`);
144
- for (let param of parameters) {
145
- this.symbolTable.addSymbol(param.name.text, param.name.range, param.getType());
146
- }
147
- }
148
- getSymbolTable() {
149
- return this.symbolTable;
150
- }
151
- get range() {
152
- return this.cacheRange();
153
- }
154
- /**
155
- * The range of the function
156
- */
157
- cacheRange() {
158
- var _a;
159
- if (!this._range) {
160
- this._range = util_1.default.createBoundingRange(this.functionType, this.leftParen, ...((_a = this.parameters) !== null && _a !== void 0 ? _a : []), this.rightParen, this.asToken, this.returnType, this.body, this.end);
161
- }
162
- return this._range;
140
+ this.tokens = {
141
+ functionType: options.functionType,
142
+ leftParen: options.leftParen,
143
+ rightParen: options.rightParen,
144
+ as: options.as,
145
+ endFunctionType: options.endFunctionType
146
+ };
147
+ this.parameters = (_a = options.parameters) !== null && _a !== void 0 ? _a : [];
148
+ this.body = options.body;
149
+ this.returnTypeExpression = options.returnTypeExpression;
150
+ //if there's a body, and it doesn't have a SymbolTable, assign one
151
+ if (this.body && !this.body.symbolTable) {
152
+ this.body.symbolTable = new SymbolTable_2.SymbolTable(`Function Body`);
153
+ }
154
+ this.symbolTable = new SymbolTable_2.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
155
+ }
156
+ getLeadingTrivia() {
157
+ var _a, _b;
158
+ return (_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
163
159
  }
164
160
  /**
165
- * The type this function returns
161
+ * The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
162
+ * and ending with the last n' in 'end function' or 'b' in 'end sub'
166
163
  */
167
- getReturnType() {
168
- return this._returnType;
169
- }
170
- /**
171
- * The range of the function declaration, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
172
- * and ending with the last character in the returnTypeToken, or the 's' in 'as', or the rightParen
173
- */
174
- get functionDeclarationRange() {
175
- var _a;
176
- return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...((_a = this.parameters) !== null && _a !== void 0 ? _a : []), this.rightParen, this.asToken, this.returnType);
164
+ get range() {
165
+ return util_1.default.createBoundingRange(this.tokens.functionType, this.tokens.leftParen, ...this.parameters, this.tokens.rightParen, this.tokens.as, this.returnTypeExpression, this.tokens.endFunctionType);
177
166
  }
178
167
  transpile(state, name, includeBody = true) {
168
+ var _a;
179
169
  let results = [];
180
170
  //'function'|'sub'
181
- results.push(state.transpileToken(this.functionType));
171
+ results.push(state.transpileToken(this.tokens.functionType, 'function'));
182
172
  //functionName?
183
173
  if (name) {
184
174
  results.push(' ', state.transpileToken(name));
185
175
  }
186
176
  //leftParen
187
- results.push(state.transpileToken(this.leftParen));
177
+ results.push(state.transpileToken(this.tokens.leftParen));
188
178
  //parameters
189
179
  for (let i = 0; i < this.parameters.length; i++) {
190
180
  let param = this.parameters[i];
@@ -196,14 +186,14 @@ class FunctionExpression extends Expression {
196
186
  results.push(param.transpile(state));
197
187
  }
198
188
  //right paren
199
- results.push(state.transpileToken(this.rightParen));
189
+ results.push(state.transpileToken(this.tokens.rightParen));
200
190
  //as [Type]
201
- if (this.asToken) {
191
+ if (!state.options.removeParameterTypes && this.returnTypeExpression) {
202
192
  results.push(' ',
203
193
  //as
204
- state.transpileToken(this.asToken), ' ',
194
+ state.transpileToken(this.tokens.as, 'as'), ' ',
205
195
  //return type
206
- state.sourceNode(this.returnType, this.getReturnType().toTypeString(state.typeContext)));
196
+ ...this.returnTypeExpression.transpile(state));
207
197
  }
208
198
  if (includeBody) {
209
199
  state.lineage.unshift(this);
@@ -211,55 +201,114 @@ class FunctionExpression extends Expression {
211
201
  state.lineage.shift();
212
202
  results.push(...body);
213
203
  }
214
- if (this.end) {
215
- results.push('\n');
216
- //'end sub'|'end function'
217
- results.push(state.indent(), state.transpileToken(this.end));
218
- }
204
+ results.push('\n');
205
+ //'end sub'|'end function'
206
+ results.push(state.indent(), state.transpileToken(this.tokens.endFunctionType, `end ${(_a = this.tokens.functionType) !== null && _a !== void 0 ? _a : 'function'}`));
219
207
  return results;
220
208
  }
221
- getTypedef(state, name) {
222
- return this.transpile(state, name, false);
209
+ getTypedef(state) {
210
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
211
+ let results = [
212
+ new source_map_1.SourceNode(1, 0, null, [
213
+ //'function'|'sub'
214
+ (_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'function',
215
+ //functionName?
216
+ ...((0, reflection_1.isFunctionStatement)(this.parent) || (0, reflection_1.isMethodStatement)(this.parent) ? [' ', (_d = (_c = this.parent.tokens.name) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : ''] : []),
217
+ //leftParen
218
+ '(',
219
+ //parameters
220
+ ...((_f = (_e = this.parameters) === null || _e === void 0 ? void 0 : _e.map((param, i) => ([
221
+ //separating comma
222
+ i > 0 ? ', ' : '',
223
+ ...param.getTypedef(state)
224
+ ]))) !== null && _f !== void 0 ? _f : []),
225
+ //right paren
226
+ ')',
227
+ //as <ReturnType>
228
+ ...(this.returnTypeExpression ? [
229
+ ' ',
230
+ (_h = (_g = this.tokens.as) === null || _g === void 0 ? void 0 : _g.text) !== null && _h !== void 0 ? _h : 'as',
231
+ ' ',
232
+ ...this.returnTypeExpression.getTypedef(state)
233
+ ] : []),
234
+ '\n',
235
+ state.indent(),
236
+ //'end sub'|'end function'
237
+ (_k = (_j = this.tokens.endFunctionType) === null || _j === void 0 ? void 0 : _j.text) !== null && _k !== void 0 ? _k : `end ${(_l = this.tokens.functionType) !== null && _l !== void 0 ? _l : 'function'}`
238
+ ])
239
+ ];
240
+ return results;
223
241
  }
224
242
  walk(visitor, options) {
225
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
226
- (0, visitors_1.walkArray)(this.parameters, visitor, options, this);
243
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
244
+ (0, visitors_2.walkArray)(this.parameters, visitor, options, this);
245
+ (0, visitors_2.walk)(this, 'returnTypeExpression', visitor, options);
227
246
  //This is the core of full-program walking...it allows us to step into sub functions
228
- if (options.walkMode & visitors_1.InternalWalkMode.recurseChildFunctions) {
229
- (0, visitors_1.walk)(this, 'returnType', visitor, options);
230
- (0, visitors_1.walk)(this, 'body', visitor, options);
247
+ if (options.walkMode & visitors_2.InternalWalkMode.recurseChildFunctions) {
248
+ (0, visitors_2.walk)(this, 'body', visitor, options);
231
249
  }
232
250
  }
233
251
  }
234
- getFunctionType() {
235
- let functionType = new TypedFunctionType_1.TypedFunctionType(this.getReturnType());
236
- functionType.isSub = this.functionType.text === 'sub';
252
+ getType(options) {
253
+ var _a, _b, _c, _d;
254
+ //if there's a defined return type, use that
255
+ let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
256
+ const isSub = ((_b = this.tokens.functionType) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Sub;
257
+ //if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
258
+ if (!returnType) {
259
+ returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
260
+ }
261
+ const resultType = new TypedFunctionType_1.TypedFunctionType(returnType);
262
+ resultType.isSub = isSub;
237
263
  for (let param of this.parameters) {
238
- functionType.addParameter(param.name.text, param.getType(), param.isOptional);
264
+ resultType.addParameter(param.tokens.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
265
+ }
266
+ // Figure out this function's name if we can
267
+ let funcName = '';
268
+ if ((0, reflection_1.isMethodStatement)(this.parent) || (0, reflection_1.isInterfaceMethodStatement)(this.parent)) {
269
+ funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
270
+ if (options.typeChain) {
271
+ // Get the typechain info from the parent class
272
+ (_c = this.parent.parent) === null || _c === void 0 ? void 0 : _c.getType(options);
273
+ }
274
+ }
275
+ else if ((0, reflection_1.isFunctionStatement)(this.parent)) {
276
+ funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
239
277
  }
240
- return functionType;
278
+ if (funcName) {
279
+ resultType.setName(funcName);
280
+ }
281
+ (_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry(funcName, resultType, options.data, this.range));
282
+ return resultType;
241
283
  }
242
284
  }
243
285
  exports.FunctionExpression = FunctionExpression;
244
- class FunctionParameterExpression extends Expression {
245
- constructor(name, typeInContext, equalsToken, defaultValue, asToken, type, namespaceName) {
286
+ class FunctionParameterExpression extends AstNode_1.Expression {
287
+ constructor(options) {
246
288
  super();
247
- this.name = name;
248
- this.typeInContext = typeInContext;
249
- this.equalsToken = equalsToken;
250
- this.defaultValue = defaultValue;
251
- this.asToken = asToken;
252
- this.type = type;
253
- this.namespaceName = namespaceName;
254
- this.range = util_1.default.createBoundingRange(this.name, this.equalsToken, this.defaultValue, this.asToken, this.type);
255
- }
256
- getType() {
257
- return this.typeInContext;
289
+ this.kind = AstNode_1.AstNodeKind.FunctionParameterExpression;
290
+ this.tokens = {
291
+ name: options.name,
292
+ equals: options.equals,
293
+ as: options.as
294
+ };
295
+ this.defaultValue = options.defaultValue;
296
+ this.typeExpression = options.typeExpression;
297
+ }
298
+ getType(options) {
299
+ var _a, _b, _c, _d, _e;
300
+ 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;
301
+ (_e = options.typeChain) === null || _e === void 0 ? void 0 : _e.push(new interfaces_1.TypeChainEntry(this.tokens.name.text, paramType, options.data, this.range));
302
+ return paramType;
303
+ }
304
+ get range() {
305
+ return util_1.default.createBoundingRange(this.tokens.name, this.tokens.as, this.typeExpression, this.tokens.equals, this.defaultValue);
258
306
  }
259
307
  transpile(state) {
308
+ var _a, _b;
260
309
  let result = [
261
310
  //name
262
- state.transpileToken(this.name)
311
+ state.transpileToken(this.tokens.name)
263
312
  ];
264
313
  //default value
265
314
  if (this.defaultValue) {
@@ -267,202 +316,215 @@ class FunctionParameterExpression extends Expression {
267
316
  result.push(this.defaultValue.transpile(state));
268
317
  }
269
318
  //type declaration
270
- if (this.asToken) {
319
+ if (this.typeExpression && !state.options.removeParameterTypes) {
271
320
  result.push(' ');
272
- result.push(state.transpileToken(this.asToken));
321
+ result.push(state.transpileToken(this.tokens.as, 'as'));
273
322
  result.push(' ');
274
- result.push(state.sourceNode(this.type, this.getType().toTypeString(state.typeContext)));
323
+ result.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []));
275
324
  }
276
325
  return result;
277
326
  }
278
- walk(visitor, options) {
279
- // eslint-disable-next-line no-bitwise
280
- if (this.defaultValue && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
281
- (0, visitors_1.walk)(this, 'defaultValue', visitor, options);
282
- (0, visitors_1.walk)(this, 'type', visitor, options);
283
- }
284
- }
285
- get isOptional() {
286
- return !!this.defaultValue;
287
- }
288
- }
289
- exports.FunctionParameterExpression = FunctionParameterExpression;
290
- class NamespacedVariableNameExpression extends Expression {
291
- constructor(
292
- //if this is a `DottedGetExpression`, it must be comprised only of `VariableExpression`s
293
- expression) {
294
- super();
295
- this.expression = expression;
296
- this.range = expression.range;
297
- }
298
- transpile(state) {
327
+ getTypedef(state) {
328
+ var _a, _b;
299
329
  return [
300
- state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
330
+ //name
331
+ this.tokens.name.text,
332
+ //default value
333
+ ...(this.defaultValue ? [
334
+ ' = ',
335
+ ...this.defaultValue.transpile(state)
336
+ ] : []),
337
+ //type declaration
338
+ ...(this.typeExpression ? [
339
+ ' as ',
340
+ ...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getTypedef(state)) !== null && _b !== void 0 ? _b : [''])
341
+ ] : [])
301
342
  ];
302
343
  }
303
- getNameParts() {
304
- let parts = [];
305
- if ((0, reflection_1.isVariableExpression)(this.expression)) {
306
- parts.push(this.expression.name.text);
307
- }
308
- else {
309
- let expr = this.expression;
310
- parts.push(expr.name.text);
311
- while ((0, reflection_1.isVariableExpression)(expr) === false) {
312
- expr = expr.obj;
313
- parts.unshift(expr.name.text);
314
- }
315
- }
316
- return parts;
317
- }
318
- getName(parseMode = Parser_1.ParseMode.BrighterScript) {
319
- if (parseMode === Parser_1.ParseMode.BrighterScript) {
320
- return this.getNameParts().join('.');
321
- }
322
- else {
323
- return this.getNameParts().join('_');
324
- }
325
- }
326
344
  walk(visitor, options) {
327
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
328
- (0, visitors_1.walk)(this, 'expression', visitor, options);
345
+ // eslint-disable-next-line no-bitwise
346
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
347
+ (0, visitors_2.walk)(this, 'defaultValue', visitor, options);
348
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
329
349
  }
330
350
  }
331
351
  }
332
- exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
333
- class DottedGetExpression extends Expression {
334
- constructor(obj, name,
335
- /**
336
- * Can either be `.`, or `?.` for optional chaining
337
- */
338
- dot) {
352
+ exports.FunctionParameterExpression = FunctionParameterExpression;
353
+ class DottedGetExpression extends AstNode_1.Expression {
354
+ constructor(options) {
339
355
  super();
340
- this.obj = obj;
341
- this.name = name;
342
- this.dot = dot;
343
- this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
356
+ this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
357
+ this.tokens = {
358
+ name: options.name,
359
+ dot: options.dot
360
+ };
361
+ this.obj = options.obj;
362
+ this.range = util_1.default.createBoundingRange(this.obj, this.tokens.dot, this.tokens.name);
344
363
  }
345
364
  transpile(state) {
346
365
  //if the callee starts with a namespace name, transpile the name
347
366
  if (state.file.calleeStartsWithNamespace(this)) {
348
- return new NamespacedVariableNameExpression(this).transpile(state);
367
+ return [
368
+ state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
369
+ ];
349
370
  }
350
371
  else {
351
372
  return [
352
373
  ...this.obj.transpile(state),
353
- state.transpileToken(this.dot),
354
- state.transpileToken(this.name)
374
+ state.transpileToken(this.tokens.dot, '.'),
375
+ state.transpileToken(this.tokens.name)
355
376
  ];
356
377
  }
357
378
  }
358
379
  walk(visitor, options) {
359
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
360
- (0, visitors_1.walk)(this, 'obj', visitor, options);
380
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
381
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
361
382
  }
362
383
  }
384
+ getType(options) {
385
+ var _a, _b, _c, _d, _e, _f;
386
+ const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
387
+ const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text, options);
388
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry((_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text, result, options.data, (_f = (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range));
389
+ if (result || options.flags & SymbolTable_1.SymbolTypeFlag.typetime) {
390
+ // All types should be known at typetime
391
+ return result;
392
+ }
393
+ // It is possible at runtime that a value has been added dynamically to an object, or something
394
+ // TODO: maybe have a strict flag on this?
395
+ return DynamicType_1.DynamicType.instance;
396
+ }
397
+ getName(parseMode) {
398
+ return util_1.default.getAllDottedGetPartsAsString(this, parseMode);
399
+ }
363
400
  }
364
401
  exports.DottedGetExpression = DottedGetExpression;
365
- class XmlAttributeGetExpression extends Expression {
366
- constructor(obj, name,
367
- /**
368
- * Can either be `@`, or `?@` for optional chaining
369
- */
370
- at) {
402
+ class XmlAttributeGetExpression extends AstNode_1.Expression {
403
+ constructor(options) {
371
404
  super();
372
- this.obj = obj;
373
- this.name = name;
374
- this.at = at;
375
- this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
405
+ this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
406
+ this.obj = options.obj;
407
+ this.tokens = { at: options.at, name: options.name };
408
+ this.range = util_1.default.createBoundingRange(this.obj, this.tokens.at, this.tokens.name);
376
409
  }
377
410
  transpile(state) {
378
411
  return [
379
412
  ...this.obj.transpile(state),
380
- state.transpileToken(this.at),
381
- state.transpileToken(this.name)
413
+ state.transpileToken(this.tokens.at, '@'),
414
+ state.transpileToken(this.tokens.name)
382
415
  ];
383
416
  }
384
417
  walk(visitor, options) {
385
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
386
- (0, visitors_1.walk)(this, 'obj', visitor, options);
418
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
419
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
387
420
  }
388
421
  }
389
422
  }
390
423
  exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
391
- class IndexedGetExpression extends Expression {
392
- constructor(obj, index,
393
- /**
394
- * Can either be `[` or `?[`. If `?.[` is used, this will be `[` and `optionalChainingToken` will be `?.`
395
- */
396
- openingSquare, closingSquare, questionDotToken // ? or ?.
397
- ) {
424
+ class IndexedGetExpression extends AstNode_1.Expression {
425
+ constructor(options) {
398
426
  super();
399
- this.obj = obj;
400
- this.index = index;
401
- this.openingSquare = openingSquare;
402
- this.closingSquare = closingSquare;
403
- this.questionDotToken = questionDotToken;
404
- this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.questionDotToken, this.openingSquare, this.index, this.closingSquare);
427
+ this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
428
+ this.tokens = {
429
+ openingSquare: options.openingSquare,
430
+ closingSquare: options.closingSquare,
431
+ questionDot: options.questionDot
432
+ };
433
+ this.obj = options.obj;
434
+ this.indexes = options.indexes;
435
+ this.range = util_1.default.createBoundingRange(this.obj, this.tokens.openingSquare, this.tokens.questionDot, this.tokens.openingSquare, ...this.indexes, this.tokens.closingSquare);
405
436
  }
406
437
  transpile(state) {
407
- return [
408
- ...this.obj.transpile(state),
409
- this.questionDotToken ? state.transpileToken(this.questionDotToken) : '',
410
- state.transpileToken(this.openingSquare),
411
- ...this.index.transpile(state),
412
- state.transpileToken(this.closingSquare)
413
- ];
438
+ var _a;
439
+ const result = [];
440
+ result.push(...this.obj.transpile(state), this.tokens.questionDot ? state.transpileToken(this.tokens.questionDot) : '', state.transpileToken(this.tokens.openingSquare, '['));
441
+ for (let i = 0; i < this.indexes.length; i++) {
442
+ //add comma between indexes
443
+ if (i > 0) {
444
+ result.push(', ');
445
+ }
446
+ let index = this.indexes[i];
447
+ result.push(...((_a = index === null || index === void 0 ? void 0 : index.transpile(state)) !== null && _a !== void 0 ? _a : []));
448
+ }
449
+ result.push(state.transpileToken(this.tokens.closingSquare, ']'));
450
+ return result;
414
451
  }
415
452
  walk(visitor, options) {
416
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
417
- (0, visitors_1.walk)(this, 'obj', visitor, options);
418
- (0, visitors_1.walk)(this, 'index', visitor, options);
453
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
454
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
455
+ (0, visitors_2.walkArray)(this.indexes, visitor, options, this);
456
+ }
457
+ }
458
+ getType(options) {
459
+ const objType = this.obj.getType(options);
460
+ if ((0, reflection_1.isArrayType)(objType)) {
461
+ // This is used on an array. What is the default type of that array?
462
+ return objType.defaultType;
419
463
  }
464
+ return super.getType(options);
420
465
  }
421
466
  }
422
467
  exports.IndexedGetExpression = IndexedGetExpression;
423
- class GroupingExpression extends Expression {
424
- constructor(tokens, expression) {
468
+ class GroupingExpression extends AstNode_1.Expression {
469
+ constructor(options) {
425
470
  super();
426
- this.tokens = tokens;
427
- this.expression = expression;
428
- this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
471
+ this.kind = AstNode_1.AstNodeKind.GroupingExpression;
472
+ this.tokens = {
473
+ rightParen: options.rightParen,
474
+ leftParen: options.leftParen
475
+ };
476
+ this.expression = options.expression;
477
+ this.range = util_1.default.createBoundingRange(this.tokens.leftParen, this.expression, this.tokens.rightParen);
429
478
  }
430
479
  transpile(state) {
480
+ if ((0, reflection_1.isTypeCastExpression)(this.expression)) {
481
+ return this.expression.transpile(state);
482
+ }
431
483
  return [
432
- state.transpileToken(this.tokens.left),
484
+ state.transpileToken(this.tokens.leftParen),
433
485
  ...this.expression.transpile(state),
434
- state.transpileToken(this.tokens.right)
486
+ state.transpileToken(this.tokens.rightParen)
435
487
  ];
436
488
  }
437
489
  walk(visitor, options) {
438
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
439
- (0, visitors_1.walk)(this, 'expression', visitor, options);
490
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
491
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
440
492
  }
441
493
  }
494
+ getType(options) {
495
+ return this.expression.getType(options);
496
+ }
442
497
  }
443
498
  exports.GroupingExpression = GroupingExpression;
444
- class LiteralExpression extends Expression {
445
- constructor(token) {
499
+ class LiteralExpression extends AstNode_1.Expression {
500
+ constructor(options) {
446
501
  super();
447
- this.token = token;
448
- this.range = this.token.range;
449
- this.type = util_1.default.tokenToBscType(token);
502
+ this.kind = AstNode_1.AstNodeKind.LiteralExpression;
503
+ this.tokens = {
504
+ value: options.value
505
+ };
506
+ }
507
+ get range() {
508
+ return this.tokens.value.range;
509
+ }
510
+ getType(options) {
511
+ return util_1.default.tokenToBscType(this.tokens.value);
450
512
  }
451
513
  transpile(state) {
452
514
  let text;
453
- if (this.token.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
515
+ if (this.tokens.value.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
454
516
  //wrap quasis with quotes (and escape inner quotemarks)
455
- text = `"${this.token.text.replace(/"/g, '""')}"`;
517
+ text = `"${this.tokens.value.text.replace(/"/g, '""')}"`;
456
518
  }
457
- else if ((0, reflection_1.isStringType)(this.type)) {
458
- text = this.token.text;
519
+ else if (this.tokens.value.kind === TokenKind_1.TokenKind.StringLiteral) {
520
+ text = this.tokens.value.text;
459
521
  //add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
460
522
  if (text.endsWith('"') === false) {
461
523
  text += '"';
462
524
  }
463
525
  }
464
526
  else {
465
- text = this.token.text;
527
+ text = this.tokens.value.text;
466
528
  }
467
529
  return [
468
530
  state.sourceNode(this, text)
@@ -477,15 +539,16 @@ exports.LiteralExpression = LiteralExpression;
477
539
  * This is a special expression only used within template strings. It exists so we can prevent producing lots of empty strings
478
540
  * during template string transpile by identifying these expressions explicitly and skipping the bslib_toString around them
479
541
  */
480
- class EscapedCharCodeLiteralExpression extends Expression {
481
- constructor(token) {
542
+ class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
543
+ constructor(options) {
482
544
  super();
483
- this.token = token;
484
- this.range = token.range;
545
+ this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
546
+ this.tokens = { value: options.value };
547
+ this.range = this.tokens.value.range;
485
548
  }
486
549
  transpile(state) {
487
550
  return [
488
- state.sourceNode(this, `chr(${this.token.charCode})`)
551
+ state.sourceNode(this, `chr(${this.tokens.value.charCode})`)
489
552
  ];
490
553
  }
491
554
  walk(visitor, options) {
@@ -493,19 +556,20 @@ class EscapedCharCodeLiteralExpression extends Expression {
493
556
  }
494
557
  }
495
558
  exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
496
- class ArrayLiteralExpression extends Expression {
497
- constructor(elements, open, close, hasSpread = false) {
498
- var _a;
559
+ class ArrayLiteralExpression extends AstNode_1.Expression {
560
+ constructor(options) {
499
561
  super();
500
- this.elements = elements;
501
- this.open = open;
502
- this.close = close;
503
- this.hasSpread = hasSpread;
504
- this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
562
+ this.kind = AstNode_1.AstNodeKind.ArrayLiteralExpression;
563
+ this.tokens = {
564
+ open: options.open,
565
+ close: options.close
566
+ };
567
+ this.elements = options.elements;
568
+ this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
505
569
  }
506
570
  transpile(state) {
507
571
  let result = [];
508
- result.push(state.transpileToken(this.open));
572
+ result.push(state.transpileToken(this.tokens.open, '['));
509
573
  let hasChildren = this.elements.length > 0;
510
574
  state.blockDepth++;
511
575
  for (let i = 0; i < this.elements.length; i++) {
@@ -513,7 +577,7 @@ class ArrayLiteralExpression extends Expression {
513
577
  let element = this.elements[i];
514
578
  if ((0, reflection_1.isCommentStatement)(element)) {
515
579
  //if the comment is on the same line as opening square or previous statement, don't add newline
516
- if (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element)) {
580
+ if (util_1.default.linesTouch(this.tokens.open, element) || util_1.default.linesTouch(previousElement, element)) {
517
581
  result.push(' ');
518
582
  }
519
583
  else {
@@ -534,67 +598,64 @@ class ArrayLiteralExpression extends Expression {
534
598
  result.push('\n');
535
599
  result.push(state.indent());
536
600
  }
537
- result.push(state.transpileToken(this.close));
601
+ if (this.tokens.close) {
602
+ result.push(state.transpileToken(this.tokens.close));
603
+ }
538
604
  return result;
539
605
  }
540
606
  walk(visitor, options) {
541
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
542
- (0, visitors_1.walkArray)(this.elements, visitor, options, this);
607
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
608
+ (0, visitors_2.walkArray)(this.elements, visitor, options, this);
543
609
  }
544
610
  }
611
+ getType(options) {
612
+ const innerTypes = this.elements.filter(x => !(0, reflection_1.isCommentStatement)(x)).map(expr => expr.getType(options));
613
+ return new types_1.ArrayType(...innerTypes);
614
+ }
545
615
  }
546
616
  exports.ArrayLiteralExpression = ArrayLiteralExpression;
547
- class AAMemberExpression extends Expression {
548
- constructor(keyToken, colonToken,
549
- /** The expression evaluated to determine the member's initial value. */
550
- value, type) {
617
+ class AAMemberExpression extends AstNode_1.Expression {
618
+ constructor(options) {
551
619
  super();
552
- this.keyToken = keyToken;
553
- this.colonToken = colonToken;
554
- this.value = value;
555
- this.type = type;
556
- this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
620
+ this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
621
+ this.tokens = {
622
+ key: options.key,
623
+ colon: options.colon,
624
+ comma: options.comma
625
+ };
626
+ this.value = options.value;
627
+ this.range = util_1.default.createBoundingRange(this.tokens.key, this.tokens.colon, this.value);
557
628
  }
558
629
  transpile(state) {
559
630
  //TODO move the logic from AALiteralExpression loop into this function
560
631
  return [];
561
632
  }
562
633
  walk(visitor, options) {
563
- (0, visitors_1.walk)(this, 'value', visitor, options);
634
+ (0, visitors_2.walk)(this, 'value', visitor, options);
635
+ }
636
+ getType(options) {
637
+ return this.value.getType(options);
564
638
  }
565
639
  }
566
640
  exports.AAMemberExpression = AAMemberExpression;
567
- class AALiteralExpression extends Expression {
568
- constructor(elements, open, close, functionExpression) {
569
- var _a;
641
+ class AALiteralExpression extends AstNode_1.Expression {
642
+ constructor(options) {
570
643
  super();
571
- this.elements = elements;
572
- this.open = open;
573
- this.close = close;
574
- this.functionExpression = functionExpression;
575
- this.symbolTable = new SymbolTable_1.SymbolTable();
576
- this.memberTable = new SymbolTable_1.SymbolTable();
577
- this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
578
- this.buildSymbolTable();
579
- }
580
- buildSymbolTable() {
581
- this.symbolTable.name = `AALiteral (symbols)`;
582
- this.memberTable.name = `AALiteral (members)`;
583
- this.symbolTable.clear();
584
- this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType('object', this.memberTable));
585
- for (const element of this.elements) {
586
- if ((0, reflection_1.isAAMemberExpression)(element)) {
587
- this.memberTable.addSymbol(element.keyToken.text, element.keyToken.range, (0, Parser_1.getBscTypeFromExpression)(element.value, this.functionExpression));
588
- }
589
- }
644
+ this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
645
+ this.tokens = {
646
+ open: options.open,
647
+ close: options.close
648
+ };
649
+ this.elements = options.elements;
650
+ this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
590
651
  }
591
652
  transpile(state) {
592
653
  let result = [];
593
654
  //open curly
594
- result.push(state.transpileToken(this.open));
655
+ result.push(state.transpileToken(this.tokens.open, '{'));
595
656
  let hasChildren = this.elements.length > 0;
596
657
  //add newline if the object has children and the first child isn't a comment starting on the same line as opening curly
597
- if (hasChildren && ((0, reflection_1.isCommentStatement)(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.open))) {
658
+ if (hasChildren && ((0, reflection_1.isCommentStatement)(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.tokens.open))) {
598
659
  result.push('\n');
599
660
  }
600
661
  state.blockDepth++;
@@ -604,7 +665,7 @@ class AALiteralExpression extends Expression {
604
665
  let nextElement = this.elements[i + 1];
605
666
  //don't indent if comment is same-line
606
667
  if ((0, reflection_1.isCommentStatement)(element) &&
607
- (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element))) {
668
+ (util_1.default.linesTouch(this.tokens.open, element) || util_1.default.linesTouch(previousElement, element))) {
608
669
  result.push(' ');
609
670
  //indent line
610
671
  }
@@ -617,9 +678,9 @@ class AALiteralExpression extends Expression {
617
678
  }
618
679
  else {
619
680
  //key
620
- result.push(state.transpileToken(element.keyToken));
681
+ result.push(state.transpileToken(element.tokens.key));
621
682
  //colon
622
- result.push(state.transpileToken(element.colonToken), ' ');
683
+ result.push(state.transpileToken(element.tokens.colon, ':'), ' ');
623
684
  //value
624
685
  result.push(...element.value.transpile(state));
625
686
  }
@@ -637,96 +698,157 @@ class AALiteralExpression extends Expression {
637
698
  result.push(state.indent());
638
699
  }
639
700
  //close curly
640
- result.push(state.transpileToken(this.close));
701
+ result.push(state.transpileToken(this.tokens.close, '}'));
641
702
  return result;
642
703
  }
643
704
  walk(visitor, options) {
644
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
645
- (0, visitors_1.walkArray)(this.elements, visitor, options, this);
705
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
706
+ (0, visitors_2.walkArray)(this.elements, visitor, options, this);
646
707
  }
647
708
  }
709
+ getType(options) {
710
+ const resultType = new AssociativeArrayType_1.AssociativeArrayType();
711
+ for (const element of this.elements) {
712
+ if ((0, reflection_1.isAAMemberExpression)(element)) {
713
+ resultType.addMember(element.tokens.key.text, { definingNode: element }, element.getType(options), SymbolTable_1.SymbolTypeFlag.runtime);
714
+ }
715
+ }
716
+ return resultType;
717
+ }
648
718
  }
649
719
  exports.AALiteralExpression = AALiteralExpression;
650
- class UnaryExpression extends Expression {
651
- constructor(operator, right) {
720
+ class UnaryExpression extends AstNode_1.Expression {
721
+ constructor(options) {
652
722
  super();
653
- this.operator = operator;
654
- this.right = right;
655
- this.range = util_1.default.createBoundingRange(this.operator, this.right);
723
+ this.kind = AstNode_1.AstNodeKind.UnaryExpression;
724
+ this.tokens = {
725
+ operator: options.operator
726
+ };
727
+ this.right = options.right;
728
+ this.range = util_1.default.createBoundingRange(this.tokens.operator, this.right);
656
729
  }
657
730
  transpile(state) {
731
+ let separatingWhitespace;
732
+ if ((0, reflection_1.isVariableExpression)(this.right)) {
733
+ separatingWhitespace = this.right.tokens.name.leadingWhitespace;
734
+ }
735
+ else if ((0, reflection_1.isLiteralExpression)(this.right)) {
736
+ separatingWhitespace = this.right.tokens.value.leadingWhitespace;
737
+ }
738
+ else {
739
+ separatingWhitespace = ' ';
740
+ }
658
741
  return [
659
- state.transpileToken(this.operator),
660
- ' ',
742
+ state.transpileToken(this.tokens.operator),
743
+ separatingWhitespace,
661
744
  ...this.right.transpile(state)
662
745
  ];
663
746
  }
664
747
  walk(visitor, options) {
665
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
666
- (0, visitors_1.walk)(this, 'right', visitor, options);
748
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
749
+ (0, visitors_2.walk)(this, 'right', visitor, options);
667
750
  }
668
751
  }
752
+ getType(options) {
753
+ return util_1.default.unaryOperatorResultType(this.tokens.operator, this.right.getType(options));
754
+ }
669
755
  }
670
756
  exports.UnaryExpression = UnaryExpression;
671
- class VariableExpression extends Expression {
672
- constructor(name, namespaceName) {
757
+ class VariableExpression extends AstNode_1.Expression {
758
+ constructor(options) {
759
+ var _a;
673
760
  super();
674
- this.name = name;
675
- this.namespaceName = namespaceName;
676
- this.range = this.name.range;
761
+ this.kind = AstNode_1.AstNodeKind.VariableExpression;
762
+ this.tokens = {
763
+ name: options.name
764
+ };
765
+ this.range = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.range;
677
766
  }
678
767
  getName(parseMode) {
679
- return this.name.text;
768
+ return this.tokens.name.text;
680
769
  }
681
770
  transpile(state) {
682
- var _a;
683
771
  let result = [];
772
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
684
773
  //if the callee is the name of a known namespace function
685
- if (state.file.calleeIsKnownNamespaceFunction(this, (_a = this.namespaceName) === null || _a === void 0 ? void 0 : _a.getName(Parser_1.ParseMode.BrighterScript))) {
774
+ if (state.file.calleeIsKnownNamespaceFunction(this, namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) {
686
775
  result.push(state.sourceNode(this, [
687
- this.namespaceName.getName(Parser_1.ParseMode.BrightScript),
776
+ namespace.getName(Parser_1.ParseMode.BrightScript),
688
777
  '_',
689
778
  this.getName(Parser_1.ParseMode.BrightScript)
690
779
  ]));
691
780
  //transpile normally
692
781
  }
693
782
  else {
694
- result.push(state.transpileToken(this.name));
783
+ result.push(state.transpileToken(this.tokens.name));
695
784
  }
696
785
  return result;
697
786
  }
698
787
  walk(visitor, options) {
699
788
  //nothing to walk
700
789
  }
790
+ getType(options) {
791
+ var _a;
792
+ let resultType = util_1.default.tokenToBscType(this.tokens.name);
793
+ const nameKey = this.getName();
794
+ if (!resultType) {
795
+ const symbolTable = this.getSymbolTable();
796
+ resultType = symbolTable === null || symbolTable === void 0 ? void 0 : symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
797
+ }
798
+ (_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry(nameKey, resultType, options.data, this.range));
799
+ return resultType;
800
+ }
701
801
  }
702
802
  exports.VariableExpression = VariableExpression;
703
- class SourceLiteralExpression extends Expression {
704
- constructor(token) {
803
+ class SourceLiteralExpression extends AstNode_1.Expression {
804
+ constructor(options) {
805
+ var _a;
705
806
  super();
706
- this.token = token;
707
- this.range = token.range;
807
+ this.kind = AstNode_1.AstNodeKind.SourceLiteralExpression;
808
+ this.tokens = {
809
+ value: options.value
810
+ };
811
+ this.range = (_a = this.tokens.value) === null || _a === void 0 ? void 0 : _a.range;
812
+ }
813
+ /**
814
+ * Find the index of the function in its parent
815
+ */
816
+ findFunctionIndex(parentFunction, func) {
817
+ let index = -1;
818
+ parentFunction.findChild((node) => {
819
+ if ((0, reflection_1.isFunctionExpression)(node)) {
820
+ index++;
821
+ if (node === func) {
822
+ return true;
823
+ }
824
+ }
825
+ }, {
826
+ walkMode: visitors_1.WalkMode.visitAllRecursive
827
+ });
828
+ return index;
708
829
  }
709
830
  getFunctionName(state, parseMode) {
710
- let functionExpression = state.file.getFunctionExpressionAtPosition(this.token.range.start);
831
+ let func = state.file.getFunctionScopeAtPosition(this.tokens.value.range.start).func;
711
832
  let nameParts = [];
712
- while (functionExpression.parentFunction) {
713
- let index = functionExpression.parentFunction.childFunctionExpressions.indexOf(functionExpression);
833
+ let parentFunction;
834
+ while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
835
+ let index = this.findFunctionIndex(parentFunction, func);
714
836
  nameParts.unshift(`anon${index}`);
715
- functionExpression = functionExpression.parentFunction;
837
+ func = parentFunction;
716
838
  }
717
839
  //get the index of this function in its parent
718
- nameParts.unshift(functionExpression.functionStatement.getName(parseMode));
840
+ nameParts.unshift(func.functionStatement.getName(parseMode));
719
841
  return nameParts.join('$');
720
842
  }
721
843
  transpile(state) {
722
844
  let text;
723
- switch (this.token.kind) {
845
+ switch (this.tokens.value.kind) {
724
846
  case TokenKind_1.TokenKind.SourceFilePathLiteral:
725
847
  const pathUrl = fileUrl(state.srcPath);
726
848
  text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
727
849
  break;
728
850
  case TokenKind_1.TokenKind.SourceLineNumLiteral:
729
- text = `${this.token.range.start.line + 1}`;
851
+ text = `${this.tokens.value.range.start.line + 1}`;
730
852
  break;
731
853
  case TokenKind_1.TokenKind.FunctionNameLiteral:
732
854
  text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
@@ -736,18 +858,18 @@ class SourceLiteralExpression extends Expression {
736
858
  break;
737
859
  case TokenKind_1.TokenKind.SourceLocationLiteral:
738
860
  const locationUrl = fileUrl(state.srcPath);
739
- text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
861
+ text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.tokens.value.range.start.line + 1}"`;
740
862
  break;
741
863
  case TokenKind_1.TokenKind.PkgPathLiteral:
742
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}"`;
864
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
743
865
  break;
744
866
  case TokenKind_1.TokenKind.PkgLocationLiteral:
745
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}:" + str(LINE_NUM)`;
867
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}:" + str(LINE_NUM)`;
746
868
  break;
747
869
  case TokenKind_1.TokenKind.LineNumLiteral:
748
870
  default:
749
871
  //use the original text (because it looks like a variable)
750
- text = this.token.text;
872
+ text = this.tokens.value.text;
751
873
  break;
752
874
  }
753
875
  return [
@@ -764,61 +886,66 @@ exports.SourceLiteralExpression = SourceLiteralExpression;
764
886
  * except we need to uniquely identify these statements so we can
765
887
  * do more type checking.
766
888
  */
767
- class NewExpression extends Expression {
768
- constructor(newKeyword, call) {
889
+ class NewExpression extends AstNode_1.Expression {
890
+ constructor(options) {
769
891
  super();
770
- this.newKeyword = newKeyword;
771
- this.call = call;
772
- this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
892
+ this.kind = AstNode_1.AstNodeKind.NewExpression;
893
+ this.tokens = {
894
+ new: options.new
895
+ };
896
+ this.call = options.call;
897
+ this.range = util_1.default.createBoundingRange(this.tokens.new, this.call);
773
898
  }
774
899
  /**
775
900
  * The name of the class to initialize (with optional namespace prefixed)
776
901
  */
777
902
  get className() {
778
903
  //the parser guarantees the callee of a new statement's call object will be
779
- //a NamespacedVariableNameExpression
904
+ //either a VariableExpression or a DottedGet
780
905
  return this.call.callee;
781
906
  }
782
- get namespaceName() {
783
- return this.call.namespaceName;
784
- }
785
907
  transpile(state) {
786
- var _a, _b;
787
- const cls = (_b = state.file.getClassFileLink(this.className.getName(Parser_1.ParseMode.BrighterScript), (_a = this.namespaceName) === null || _a === void 0 ? void 0 : _a.getName(Parser_1.ParseMode.BrighterScript))) === null || _b === void 0 ? void 0 : _b.item;
908
+ var _a;
909
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
910
+ const cls = (_a = state.file.getClassFileLink(this.className.getName(Parser_1.ParseMode.BrighterScript), namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) === null || _a === void 0 ? void 0 : _a.item;
788
911
  //new statements within a namespace block can omit the leading namespace if the class resides in that same namespace.
789
912
  //So we need to figure out if this is a namespace-omitted class, or if this class exists without a namespace.
790
913
  return this.call.transpile(state, cls === null || cls === void 0 ? void 0 : cls.getName(Parser_1.ParseMode.BrightScript));
791
914
  }
792
915
  walk(visitor, options) {
793
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
794
- (0, visitors_1.walk)(this, 'call', visitor, options);
916
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
917
+ (0, visitors_2.walk)(this, 'call', visitor, options);
795
918
  }
796
919
  }
920
+ getType(options) {
921
+ return this.call.getType(options);
922
+ }
797
923
  }
798
924
  exports.NewExpression = NewExpression;
799
- class CallfuncExpression extends Expression {
800
- constructor(callee, operator, methodName, openingParen, args, closingParen) {
925
+ class CallfuncExpression extends AstNode_1.Expression {
926
+ constructor(options) {
801
927
  var _a;
802
928
  super();
803
- this.callee = callee;
804
- this.operator = operator;
805
- this.methodName = methodName;
806
- this.openingParen = openingParen;
807
- this.args = args;
808
- this.closingParen = closingParen;
809
- this.range = util_1.default.createBoundingRange(this.callee, this.operator, this.methodName, this.openingParen, ...((_a = this.args) !== null && _a !== void 0 ? _a : []), this.closingParen);
929
+ this.kind = AstNode_1.AstNodeKind.CallfuncExpression;
930
+ this.tokens = {
931
+ operator: options.operator,
932
+ methodName: options.methodName,
933
+ openingParen: options.openingParen,
934
+ closingParen: options.closingParen
935
+ };
936
+ this.callee = options.callee;
937
+ this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
938
+ this.range = util_1.default.createBoundingRange(this.callee, this.tokens.operator, this.tokens.methodName, this.tokens.openingParen, ...this.args, this.tokens.closingParen);
810
939
  }
811
940
  transpile(state) {
941
+ var _a;
812
942
  let result = [];
813
- result.push(...this.callee.transpile(state), state.sourceNode(this.operator, '.callfunc'), state.transpileToken(this.openingParen),
943
+ result.push(...this.callee.transpile(state), state.sourceNode(this.tokens.operator, '.callfunc'), state.transpileToken(this.tokens.openingParen, '('),
814
944
  //the name of the function
815
- state.sourceNode(this.methodName, ['"', this.methodName.text, '"']), ', ');
816
- //transpile args
817
- //callfunc with zero args never gets called, so pass invalid as the first parameter if there are no args
818
- if (this.args.length === 0) {
819
- result.push('invalid');
820
- }
821
- else {
945
+ state.sourceNode(this.tokens.methodName, ['"', this.tokens.methodName.text, '"']));
946
+ if (((_a = this.args) === null || _a === void 0 ? void 0 : _a.length) > 0) {
947
+ result.push(', ');
948
+ //transpile args
822
949
  for (let i = 0; i < this.args.length; i++) {
823
950
  //add comma between args
824
951
  if (i > 0) {
@@ -828,14 +955,44 @@ class CallfuncExpression extends Expression {
828
955
  result.push(...arg.transpile(state));
829
956
  }
830
957
  }
831
- result.push(state.transpileToken(this.closingParen));
958
+ else if (state.options.legacyCallfuncHandling) {
959
+ result.push(', ', 'invalid');
960
+ }
961
+ result.push(state.transpileToken(this.tokens.closingParen, ')'));
832
962
  return result;
833
963
  }
834
964
  walk(visitor, options) {
835
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
836
- (0, visitors_1.walk)(this, 'callee', visitor, options);
837
- (0, visitors_1.walkArray)(this.args, visitor, options, this);
965
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
966
+ (0, visitors_2.walk)(this, 'callee', visitor, options);
967
+ (0, visitors_2.walkArray)(this.args, visitor, options, this);
968
+ }
969
+ }
970
+ getType(options) {
971
+ var _a, _b, _c;
972
+ let result = DynamicType_1.DynamicType.instance;
973
+ // a little hacky here with checking options.ignoreCall because callFuncExpression has the method name
974
+ // It's nicer for CallExpression, because it's a call on any expression.
975
+ const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.runtime }));
976
+ if ((0, reflection_1.isComponentType)(calleeType) || (0, reflection_1.isReferenceType)(calleeType)) {
977
+ const funcType = (_b = (_a = calleeType).getCallFuncType) === null || _b === void 0 ? void 0 : _b.call(_a, this.tokens.methodName.text, options);
978
+ if (funcType) {
979
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry(this.tokens.methodName.text, funcType, options.data, this.tokens.methodName.range, (0, creators_1.createToken)(TokenKind_1.TokenKind.Callfunc)));
980
+ if (options.ignoreCall) {
981
+ result = funcType;
982
+ }
983
+ }
984
+ /* TODO:
985
+ make callfunc return types work
986
+ else if (isCallableType(funcType) && (!isReferenceType(funcType.returnType) || funcType.returnType.isResolvable())) {
987
+ result = funcType.returnType;
988
+ } else if (!isReferenceType(funcType) && (funcType as any)?.returnType?.isResolvable()) {
989
+ result = (funcType as any).returnType;
990
+ } else {
991
+ return new TypePropertyReferenceType(funcType, 'returnType');
992
+ }
993
+ */
838
994
  }
995
+ return result;
839
996
  }
840
997
  }
841
998
  exports.CallfuncExpression = CallfuncExpression;
@@ -843,12 +1000,12 @@ exports.CallfuncExpression = CallfuncExpression;
843
1000
  * Since template strings can contain newlines, we need to concatenate multiple strings together with chr() calls.
844
1001
  * This is a single expression that represents the string contatenation of all parts of a single quasi.
845
1002
  */
846
- class TemplateStringQuasiExpression extends Expression {
847
- constructor(expressions) {
848
- var _a;
1003
+ class TemplateStringQuasiExpression extends AstNode_1.Expression {
1004
+ constructor(options) {
849
1005
  super();
850
- this.expressions = expressions;
851
- this.range = util_1.default.createBoundingRange(...((_a = this.expressions) !== null && _a !== void 0 ? _a : []));
1006
+ this.kind = AstNode_1.AstNodeKind.TemplateStringQuasiExpression;
1007
+ this.expressions = options.expressions;
1008
+ this.range = util_1.default.createBoundingRange(...this.expressions);
852
1009
  }
853
1010
  transpile(state, skipEmptyStrings = true) {
854
1011
  let result = [];
@@ -856,7 +1013,7 @@ class TemplateStringQuasiExpression extends Expression {
856
1013
  for (let expression of this.expressions) {
857
1014
  //skip empty strings
858
1015
  //TODO what does an empty string literal expression look like?
859
- if (expression.token.text === '' && skipEmptyStrings === true) {
1016
+ if (expression.tokens.value.text === '' && skipEmptyStrings === true) {
860
1017
  continue;
861
1018
  }
862
1019
  result.push(plus, ...expression.transpile(state));
@@ -865,28 +1022,32 @@ class TemplateStringQuasiExpression extends Expression {
865
1022
  return result;
866
1023
  }
867
1024
  walk(visitor, options) {
868
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
869
- (0, visitors_1.walkArray)(this.expressions, visitor, options, this);
1025
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1026
+ (0, visitors_2.walkArray)(this.expressions, visitor, options, this);
870
1027
  }
871
1028
  }
872
1029
  }
873
1030
  exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
874
- class TemplateStringExpression extends Expression {
875
- constructor(openingBacktick, quasis, expressions, closingBacktick) {
876
- var _a;
1031
+ class TemplateStringExpression extends AstNode_1.Expression {
1032
+ constructor(options) {
877
1033
  super();
878
- this.openingBacktick = openingBacktick;
879
- this.quasis = quasis;
880
- this.expressions = expressions;
881
- this.closingBacktick = closingBacktick;
882
- //the expression always starts and ends with a quasi, so we don't need to consider the expression locations
883
- this.range = util_1.default.createBoundingRange(this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
1034
+ this.kind = AstNode_1.AstNodeKind.TemplateStringExpression;
1035
+ this.tokens = {
1036
+ openingBacktick: options.openingBacktick,
1037
+ closingBacktick: options.closingBacktick
1038
+ };
1039
+ this.quasis = options.quasis;
1040
+ this.expressions = options.expressions;
1041
+ this.range = util_1.default.createBoundingRange(this.tokens.openingBacktick, this.quasis[0], this.quasis[this.quasis.length - 1], this.tokens.closingBacktick);
1042
+ }
1043
+ getType(options) {
1044
+ return StringType_1.StringType.instance;
884
1045
  }
885
1046
  transpile(state) {
886
1047
  if (this.quasis.length === 1 && this.expressions.length === 0) {
887
1048
  return this.quasis[0].transpile(state);
888
1049
  }
889
- let result = [];
1050
+ let result = ['('];
890
1051
  let plus = '';
891
1052
  //helper function to figure out when to include the plus
892
1053
  function add(...items) {
@@ -905,7 +1066,7 @@ class TemplateStringExpression extends Expression {
905
1066
  if (expression) {
906
1067
  //skip the toString wrapper around certain expressions
907
1068
  if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
908
- ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.type))) {
1069
+ ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.getType()))) {
909
1070
  add(...expression.transpile(state));
910
1071
  //wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
911
1072
  }
@@ -914,37 +1075,40 @@ class TemplateStringExpression extends Expression {
914
1075
  }
915
1076
  }
916
1077
  }
1078
+ //the expression should be wrapped in parens so it can be used line a single expression at runtime
1079
+ result.push(')');
917
1080
  return result;
918
1081
  }
919
1082
  walk(visitor, options) {
920
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1083
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
921
1084
  //walk the quasis and expressions in left-to-right order
922
1085
  for (let i = 0; i < this.quasis.length; i++) {
923
- (0, visitors_1.walk)(this.quasis, i, visitor, options, this);
1086
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
924
1087
  //this skips the final loop iteration since we'll always have one more quasi than expression
925
1088
  if (this.expressions[i]) {
926
- (0, visitors_1.walk)(this.expressions, i, visitor, options, this);
1089
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
927
1090
  }
928
1091
  }
929
1092
  }
930
1093
  }
931
1094
  }
932
1095
  exports.TemplateStringExpression = TemplateStringExpression;
933
- class TaggedTemplateStringExpression extends Expression {
934
- constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
935
- var _a;
1096
+ class TaggedTemplateStringExpression extends AstNode_1.Expression {
1097
+ constructor(options) {
936
1098
  super();
937
- this.tagName = tagName;
938
- this.openingBacktick = openingBacktick;
939
- this.quasis = quasis;
940
- this.expressions = expressions;
941
- this.closingBacktick = closingBacktick;
942
- //the expression always starts and ends with a quasi, so we don't need to consider the expression locations
943
- this.range = util_1.default.createBoundingRange(this.tagName, this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
1099
+ this.kind = AstNode_1.AstNodeKind.TaggedTemplateStringExpression;
1100
+ this.tokens = {
1101
+ tagName: options.tagName,
1102
+ openingBacktick: options.openingBacktick,
1103
+ closingBacktick: options.closingBacktick
1104
+ };
1105
+ this.quasis = options.quasis;
1106
+ this.expressions = options.expressions;
1107
+ this.range = util_1.default.createBoundingRange(this.tokens.tagName, this.tokens.openingBacktick, this.quasis[0], this.quasis[this.quasis.length - 1], this.tokens.closingBacktick);
944
1108
  }
945
1109
  transpile(state) {
946
1110
  let result = [];
947
- result.push(state.transpileToken(this.tagName), '([');
1111
+ result.push(state.transpileToken(this.tokens.tagName), '([');
948
1112
  //add quasis as the first array
949
1113
  for (let i = 0; i < this.quasis.length; i++) {
950
1114
  let quasi = this.quasis[i];
@@ -963,38 +1127,36 @@ class TaggedTemplateStringExpression extends Expression {
963
1127
  }
964
1128
  result.push(...expression.transpile(state));
965
1129
  }
966
- result.push(state.sourceNode(this.closingBacktick, '])'));
1130
+ result.push(state.sourceNode(this.tokens.closingBacktick, '])'));
967
1131
  return result;
968
1132
  }
969
1133
  walk(visitor, options) {
970
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1134
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
971
1135
  //walk the quasis and expressions in left-to-right order
972
1136
  for (let i = 0; i < this.quasis.length; i++) {
973
- (0, visitors_1.walk)(this.quasis, i, visitor, options, this);
1137
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
974
1138
  //this skips the final loop iteration since we'll always have one more quasi than expression
975
1139
  if (this.expressions[i]) {
976
- (0, visitors_1.walk)(this.expressions, i, visitor, options, this);
1140
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
977
1141
  }
978
1142
  }
979
1143
  }
980
1144
  }
981
1145
  }
982
1146
  exports.TaggedTemplateStringExpression = TaggedTemplateStringExpression;
983
- class AnnotationExpression extends Expression {
984
- constructor(atToken, nameToken) {
1147
+ class AnnotationExpression extends AstNode_1.Expression {
1148
+ constructor(options) {
985
1149
  super();
986
- this.atToken = atToken;
987
- this.nameToken = nameToken;
988
- this.name = nameToken.text;
1150
+ this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
1151
+ this.tokens = {
1152
+ at: options.at,
1153
+ name: options.name
1154
+ };
1155
+ this.call = options.call;
1156
+ this.name = this.tokens.name.text;
989
1157
  }
990
1158
  get range() {
991
- return this.cacheRange();
992
- }
993
- cacheRange() {
994
- if (!this._range) {
995
- this._range = util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
996
- }
997
- return this._range;
1159
+ return util_1.default.createBoundingRange(this.tokens.at, this.tokens.name, this.call);
998
1160
  }
999
1161
  /**
1000
1162
  * Convert annotation arguments to JavaScript types
@@ -1006,6 +1168,10 @@ class AnnotationExpression extends Expression {
1006
1168
  }
1007
1169
  return this.call.args.map(e => expressionToValue(e, strict));
1008
1170
  }
1171
+ getLeadingTrivia() {
1172
+ var _a;
1173
+ return (_a = this.tokens.at) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1174
+ }
1009
1175
  transpile(state) {
1010
1176
  return [];
1011
1177
  }
@@ -1022,15 +1188,18 @@ class AnnotationExpression extends Expression {
1022
1188
  }
1023
1189
  }
1024
1190
  exports.AnnotationExpression = AnnotationExpression;
1025
- class TernaryExpression extends Expression {
1026
- constructor(test, questionMarkToken, consequent, colonToken, alternate) {
1191
+ class TernaryExpression extends AstNode_1.Expression {
1192
+ constructor(options) {
1027
1193
  super();
1028
- this.test = test;
1029
- this.questionMarkToken = questionMarkToken;
1030
- this.consequent = consequent;
1031
- this.colonToken = colonToken;
1032
- this.alternate = alternate;
1033
- this.range = util_1.default.createBoundingRange(this.test, this.questionMarkToken, this.consequent, this.colonToken, this.alternate);
1194
+ this.kind = AstNode_1.AstNodeKind.TernaryExpression;
1195
+ this.tokens = {
1196
+ questionMark: options.questionMark,
1197
+ colon: options.colon
1198
+ };
1199
+ this.test = options.test;
1200
+ this.consequent = options.consequent;
1201
+ this.alternate = options.alternate;
1202
+ this.range = util_1.default.createBoundingRange(this.test, this.tokens.questionMark, this.consequent, this.tokens.colon, this.alternate);
1034
1203
  }
1035
1204
  transpile(state) {
1036
1205
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
@@ -1044,12 +1213,12 @@ class TernaryExpression extends Expression {
1044
1213
  ...alternateInfo.expressions
1045
1214
  ].filter(e => e instanceof CallExpression || e instanceof CallfuncExpression || e instanceof DottedGetExpression);
1046
1215
  if (mutatingExpressions.length > 0) {
1047
- result.push(state.sourceNode(this.questionMarkToken,
1216
+ result.push(state.sourceNode(this.tokens.questionMark,
1048
1217
  //write all the scope variables as parameters.
1049
1218
  //TODO handle when there are more than 31 parameters
1050
1219
  `(function(__bsCondition, ${allUniqueVarNames.join(', ')})`), state.newline,
1051
1220
  //double indent so our `end function` line is still indented one at the end
1052
- 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(', ')})`));
1221
+ 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.tokens.questionMark, 'return '), ...(_c = (_b = this.consequent) === null || _b === void 0 ? void 0 : _b.transpile(state)) !== null && _c !== void 0 ? _c : [state.sourceNode(this.tokens.questionMark, 'invalid')], state.newline, state.indent(-1), state.sourceNode((_d = this.consequent) !== null && _d !== void 0 ? _d : this.tokens.questionMark, 'else'), state.newline, state.indent(1), state.sourceNode((_e = this.consequent) !== null && _e !== void 0 ? _e : this.tokens.questionMark, '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.tokens.questionMark, 'invalid')], state.newline, state.indent(-1), state.sourceNode(this.tokens.questionMark, 'end if'), state.newline, state.indent(-1), state.sourceNode(this.tokens.questionMark, 'end function)('), ...this.test.transpile(state), state.sourceNode(this.tokens.questionMark, `, ${allUniqueVarNames.join(', ')})`));
1053
1222
  state.blockDepth--;
1054
1223
  }
1055
1224
  else {
@@ -1058,21 +1227,24 @@ class TernaryExpression extends Expression {
1058
1227
  return result;
1059
1228
  }
1060
1229
  walk(visitor, options) {
1061
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1062
- (0, visitors_1.walk)(this, 'test', visitor, options);
1063
- (0, visitors_1.walk)(this, 'consequent', visitor, options);
1064
- (0, visitors_1.walk)(this, 'alternate', visitor, options);
1230
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1231
+ (0, visitors_2.walk)(this, 'test', visitor, options);
1232
+ (0, visitors_2.walk)(this, 'consequent', visitor, options);
1233
+ (0, visitors_2.walk)(this, 'alternate', visitor, options);
1065
1234
  }
1066
1235
  }
1067
1236
  }
1068
1237
  exports.TernaryExpression = TernaryExpression;
1069
- class NullCoalescingExpression extends Expression {
1070
- constructor(consequent, questionQuestionToken, alternate) {
1238
+ class NullCoalescingExpression extends AstNode_1.Expression {
1239
+ constructor(options) {
1071
1240
  super();
1072
- this.consequent = consequent;
1073
- this.questionQuestionToken = questionQuestionToken;
1074
- this.alternate = alternate;
1075
- this.range = util_1.default.createBoundingRange(this.consequent, this.questionQuestionToken, this.alternate);
1241
+ this.kind = AstNode_1.AstNodeKind.NullCoalescingExpression;
1242
+ this.tokens = {
1243
+ questionQuestion: options.questionQuestion
1244
+ };
1245
+ this.consequent = options.consequent;
1246
+ this.alternate = options.alternate;
1247
+ this.range = util_1.default.createBoundingRange(this.consequent, this.tokens.questionQuestion, this.alternate);
1076
1248
  }
1077
1249
  transpile(state) {
1078
1250
  let result = [];
@@ -1101,18 +1273,24 @@ class NullCoalescingExpression extends Expression {
1101
1273
  return result;
1102
1274
  }
1103
1275
  walk(visitor, options) {
1104
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1105
- (0, visitors_1.walk)(this, 'consequent', visitor, options);
1106
- (0, visitors_1.walk)(this, 'alternate', visitor, options);
1276
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1277
+ (0, visitors_2.walk)(this, 'consequent', visitor, options);
1278
+ (0, visitors_2.walk)(this, 'alternate', visitor, options);
1107
1279
  }
1108
1280
  }
1109
1281
  }
1110
1282
  exports.NullCoalescingExpression = NullCoalescingExpression;
1111
- class RegexLiteralExpression extends Expression {
1112
- constructor(tokens) {
1283
+ class RegexLiteralExpression extends AstNode_1.Expression {
1284
+ constructor(options) {
1113
1285
  super();
1114
- this.tokens = tokens;
1115
- this.range = this.tokens.regexLiteral.range;
1286
+ this.kind = AstNode_1.AstNodeKind.RegexLiteralExpression;
1287
+ this.tokens = {
1288
+ regexLiteral: options.regexLiteral
1289
+ };
1290
+ }
1291
+ get range() {
1292
+ var _a, _b;
1293
+ return (_b = (_a = this.tokens) === null || _a === void 0 ? void 0 : _a.regexLiteral) === null || _b === void 0 ? void 0 : _b.range;
1116
1294
  }
1117
1295
  transpile(state) {
1118
1296
  var _a, _b;
@@ -1143,125 +1321,22 @@ class RegexLiteralExpression extends Expression {
1143
1321
  }
1144
1322
  }
1145
1323
  exports.RegexLiteralExpression = RegexLiteralExpression;
1146
- class TypeExpression extends Expression {
1147
- constructor(tokens, namespaceName) {
1148
- super();
1149
- this.tokens = tokens;
1150
- this.namespaceName = namespaceName;
1151
- this.range = util_1.default.createBoundingRange(this.tokens.type);
1152
- }
1153
- /**
1154
- * The this TypeExpression refers to
1155
- */
1156
- get type() {
1157
- if (this._type) {
1158
- return this._type;
1159
- }
1160
- this._type = this.getType(Parser_1.ParseMode.BrighterScript);
1161
- return this._type;
1162
- }
1163
- /**
1164
- * Derive a BscType from the type token
1165
- * Can deal with multiple brackets to make multidimensional arrays, eg. float[][]
1166
- * Defaults to `DynamicType`
1167
- */
1168
- getType(parseMode = Parser_1.ParseMode.BrighterScript) {
1169
- let exprType = this.tokens.type
1170
- ? util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName)
1171
- : new DynamicType_1.DynamicType();
1172
- return exprType;
1173
- }
1174
- /**
1175
- * Is this a valid, (eg. known) type?
1176
- */
1177
- isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
1178
- return !!util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName);
1179
- }
1180
- /**
1181
- * Gives a human readable string that says the type
1182
- * @returns text to display to show the type
1183
- */
1184
- getText() {
1185
- let result = this.tokens.type.text;
1186
- return result;
1187
- }
1188
- transpile(state) {
1189
- let result = [];
1190
- //type declaration
1191
- result.push(state.sourceNode({ range: this.range }, this.type.toTypeString(state.typeContext)));
1192
- return result;
1193
- }
1194
- walk(visitor, options) {
1195
- //nothing to walk
1196
- }
1197
- }
1198
- exports.TypeExpression = TypeExpression;
1199
- class ArrayTypeExpression extends TypeExpression {
1200
- constructor(innerTypes, // this is an array so that in the future when we support union types
1201
- bracketTokens, namespaceName) {
1202
- super({}, namespaceName);
1203
- this.innerTypes = innerTypes;
1204
- this.bracketTokens = bracketTokens;
1205
- this.namespaceName = namespaceName;
1206
- this.range = util_1.default.createBoundingRange(this.bracketTokens.leftBracket, this.bracketTokens.rightBracket, ...this.innerTypes);
1207
- }
1208
- /*
1209
- * TODO - Support union types
1210
- */
1211
- get defaultTypeExpression() {
1212
- return this.innerTypes[0];
1213
- }
1214
- /**
1215
- * Derive a BscType from the type token
1216
- * Returns an array type with the inner types based on the inner type expressions
1217
- */
1218
- getType(parseMode = Parser_1.ParseMode.BrighterScript) {
1219
- const innerBscTypes = this.innerTypes.map(inner => inner.getType(parseMode));
1220
- return new ArrayType_1.ArrayType(...innerBscTypes);
1221
- }
1222
- /**
1223
- * Is this a valid, (eg. known) type?
1224
- */
1225
- isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
1226
- if (parseMode === Parser_1.ParseMode.BrighterScript) {
1227
- return this.innerTypes.reduce((validSoFar, innerType) => {
1228
- return validSoFar && innerType.isValidType(parseMode);
1229
- }, true);
1230
- }
1231
- return false;
1232
- }
1233
- /**
1234
- * Gives a human readable string that says the type
1235
- * @returns text to display to show the type
1236
- */
1237
- getText() {
1238
- return this.defaultTypeExpression.getText() + '[]';
1239
- }
1240
- walk(visitor, options) {
1241
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1242
- for (let i = 0; i < this.innerTypes.length; i++) {
1243
- (0, visitors_1.walk)(this.innerTypes, i, visitor, options, this);
1244
- }
1245
- }
1246
- }
1247
- }
1248
- exports.ArrayTypeExpression = ArrayTypeExpression;
1249
1324
  function expressionToValue(expr, strict) {
1250
1325
  if (!expr) {
1251
1326
  return null;
1252
1327
  }
1253
1328
  if ((0, reflection_1.isUnaryExpression)(expr) && (0, reflection_1.isLiteralNumber)(expr.right)) {
1254
- return numberExpressionToValue(expr.right, expr.operator.text);
1329
+ return numberExpressionToValue(expr.right, expr.tokens.operator.text);
1255
1330
  }
1256
1331
  if ((0, reflection_1.isLiteralString)(expr)) {
1257
1332
  //remove leading and trailing quotes
1258
- return expr.token.text.replace(/^"/, '').replace(/"$/, '');
1333
+ return expr.tokens.value.text.replace(/^"/, '').replace(/"$/, '');
1259
1334
  }
1260
1335
  if ((0, reflection_1.isLiteralNumber)(expr)) {
1261
1336
  return numberExpressionToValue(expr);
1262
1337
  }
1263
1338
  if ((0, reflection_1.isLiteralBoolean)(expr)) {
1264
- return expr.token.text.toLowerCase() === 'true';
1339
+ return expr.tokens.value.text.toLowerCase() === 'true';
1265
1340
  }
1266
1341
  if ((0, reflection_1.isArrayLiteralExpression)(expr)) {
1267
1342
  return expr.elements
@@ -1271,7 +1346,7 @@ function expressionToValue(expr, strict) {
1271
1346
  if ((0, reflection_1.isAALiteralExpression)(expr)) {
1272
1347
  return expr.elements.reduce((acc, e) => {
1273
1348
  if (!(0, reflection_1.isCommentStatement)(e)) {
1274
- acc[e.keyToken.text] = expressionToValue(e.value, strict);
1349
+ acc[e.tokens.key.text] = expressionToValue(e.value, strict);
1275
1350
  }
1276
1351
  return acc;
1277
1352
  }, {});
@@ -1279,11 +1354,93 @@ function expressionToValue(expr, strict) {
1279
1354
  return strict ? null : expr;
1280
1355
  }
1281
1356
  function numberExpressionToValue(expr, operator = '') {
1282
- if ((0, reflection_1.isIntegerType)(expr.type) || (0, reflection_1.isLongIntegerType)(expr.type)) {
1283
- return parseInt(operator + expr.token.text);
1357
+ if ((0, reflection_1.isIntegerType)(expr.getType()) || (0, reflection_1.isLongIntegerType)(expr.getType())) {
1358
+ return parseInt(operator + expr.tokens.value.text);
1284
1359
  }
1285
1360
  else {
1286
- return parseFloat(operator + expr.token.text);
1361
+ return parseFloat(operator + expr.tokens.value.text);
1362
+ }
1363
+ }
1364
+ class TypeExpression extends AstNode_1.Expression {
1365
+ constructor(options) {
1366
+ var _a;
1367
+ super();
1368
+ this.kind = AstNode_1.AstNodeKind.TypeExpression;
1369
+ this.expression = options.expression;
1370
+ this.range = (_a = this.expression) === null || _a === void 0 ? void 0 : _a.range;
1371
+ }
1372
+ transpile(state) {
1373
+ return [this.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime }).toTypeString()];
1374
+ }
1375
+ walk(visitor, options) {
1376
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1377
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
1378
+ }
1379
+ }
1380
+ getType(options) {
1381
+ return this.expression.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.typetime }));
1382
+ }
1383
+ getTypedef(state) {
1384
+ // TypeDefs should pass through any valid type names
1385
+ return this.expression.transpile(state);
1386
+ }
1387
+ getName(parseMode = Parser_1.ParseMode.BrighterScript) {
1388
+ //TODO: this may not support Complex Types, eg. generics or Unions
1389
+ return util_1.default.getAllDottedGetPartsAsString(this.expression, parseMode);
1390
+ }
1391
+ getNameParts() {
1392
+ //TODO: really, this code is only used to get Namespaces. It could be more clear.
1393
+ return util_1.default.getAllDottedGetParts(this.expression).map(x => x.text);
1394
+ }
1395
+ }
1396
+ exports.TypeExpression = TypeExpression;
1397
+ class TypeCastExpression extends AstNode_1.Expression {
1398
+ constructor(options) {
1399
+ super();
1400
+ this.kind = AstNode_1.AstNodeKind.TypeCastExpression;
1401
+ this.tokens = {
1402
+ as: options.as
1403
+ };
1404
+ this.obj = options.obj;
1405
+ this.typeExpression = options.typeExpression;
1406
+ this.range = util_1.default.createBoundingRange(this.obj, this.tokens.as, this.typeExpression);
1407
+ }
1408
+ transpile(state) {
1409
+ return this.obj.transpile(state);
1410
+ }
1411
+ walk(visitor, options) {
1412
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1413
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
1414
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
1415
+ }
1416
+ }
1417
+ getType(options) {
1418
+ return this.typeExpression.getType(options);
1419
+ }
1420
+ }
1421
+ exports.TypeCastExpression = TypeCastExpression;
1422
+ class TypedArrayExpression extends AstNode_1.Expression {
1423
+ constructor(options) {
1424
+ super();
1425
+ this.kind = AstNode_1.AstNodeKind.TypedArrayExpression;
1426
+ this.tokens = {
1427
+ leftBracket: options.leftBracket,
1428
+ rightBracket: options.rightBracket
1429
+ };
1430
+ this.innerType = options.innerType;
1431
+ this.range = util_1.default.createBoundingRange(this.innerType, this.tokens.leftBracket, this.tokens.rightBracket);
1432
+ }
1433
+ transpile(state) {
1434
+ return [this.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime }).toTypeString()];
1435
+ }
1436
+ walk(visitor, options) {
1437
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1438
+ (0, visitors_2.walk)(this, 'innerType', visitor, options);
1439
+ }
1440
+ }
1441
+ getType(options) {
1442
+ return new types_1.ArrayType(this.innerType.getType(options));
1287
1443
  }
1288
1444
  }
1445
+ exports.TypedArrayExpression = TypedArrayExpression;
1289
1446
  //# sourceMappingURL=Expression.js.map