brighterscript 1.0.0-alpha.24 → 1.0.0-alpha.25

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 (530) hide show
  1. package/CHANGELOG.md +493 -233
  2. package/README.md +45 -139
  3. package/bsconfig.schema.json +41 -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 +39 -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 +831 -695
  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 +87 -133
  60. package/dist/Scope.js +450 -510
  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 -6
  74. package/dist/XmlScope.js +74 -69
  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} +68 -64
  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 +26 -16
  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 +208 -126
  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 +178 -33
  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 +10 -2
  105. package/dist/bscPlugin/BscPlugin.js +33 -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 +135 -0
  115. package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
  116. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +14 -11
  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/fileProviders/FileProvider.d.ts +9 -0
  126. package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
  127. package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
  128. package/dist/bscPlugin/hover/HoverProcessor.d.ts +7 -7
  129. package/dist/bscPlugin/hover/HoverProcessor.js +123 -125
  130. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
  131. package/dist/bscPlugin/hover/HoverProcessor.spec.js +371 -53
  132. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
  133. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +2 -1
  134. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +85 -23
  135. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  136. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +83 -6
  137. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
  138. package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
  139. package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
  140. package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
  141. package/dist/bscPlugin/serialize/BslibManager.js +40 -0
  142. package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
  143. package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
  144. package/dist/bscPlugin/serialize/FileSerializer.js +72 -0
  145. package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
  146. package/dist/bscPlugin/transpile/{BrsFilePreTranspileProcessor.d.ts → BrsFileTranspileProcessor.d.ts} +4 -2
  147. package/dist/bscPlugin/transpile/{BrsFilePreTranspileProcessor.js → BrsFileTranspileProcessor.js} +33 -9
  148. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
  149. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
  150. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +41 -0
  151. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
  152. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
  153. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
  154. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
  155. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +13 -5
  156. package/dist/bscPlugin/validation/BrsFileValidator.js +259 -49
  157. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  158. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +230 -14
  159. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
  160. package/dist/bscPlugin/validation/ProgramValidator.d.ts +10 -0
  161. package/dist/bscPlugin/validation/ProgramValidator.js +32 -0
  162. package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
  163. package/dist/bscPlugin/validation/ScopeValidator.d.ts +54 -27
  164. package/dist/bscPlugin/validation/ScopeValidator.js +483 -286
  165. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  166. package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
  167. package/dist/bscPlugin/validation/ScopeValidator.spec.js +2454 -0
  168. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
  169. package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
  170. package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
  171. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
  172. package/dist/cli.js +104 -13
  173. package/dist/cli.js.map +1 -1
  174. package/dist/deferred.d.ts +3 -3
  175. package/dist/deferred.js.map +1 -1
  176. package/dist/diagnosticUtils.d.ts +8 -2
  177. package/dist/diagnosticUtils.js +47 -17
  178. package/dist/diagnosticUtils.js.map +1 -1
  179. package/dist/examples/plugins/removePrint.js +8 -10
  180. package/dist/examples/plugins/removePrint.js.map +1 -1
  181. package/dist/files/AssetFile.d.ts +26 -0
  182. package/dist/files/AssetFile.js +26 -0
  183. package/dist/files/AssetFile.js.map +1 -0
  184. package/dist/files/BrsFile.Class.spec.js +523 -493
  185. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  186. package/dist/files/BrsFile.d.ts +112 -111
  187. package/dist/files/BrsFile.js +741 -1032
  188. package/dist/files/BrsFile.js.map +1 -1
  189. package/dist/files/BrsFile.spec.js +1728 -1232
  190. package/dist/files/BrsFile.spec.js.map +1 -1
  191. package/dist/files/BscFile.d.ts +104 -0
  192. package/dist/files/BscFile.js +16 -0
  193. package/dist/files/BscFile.js.map +1 -0
  194. package/dist/files/Factory.d.ts +25 -0
  195. package/dist/files/Factory.js +22 -0
  196. package/dist/files/Factory.js.map +1 -0
  197. package/dist/files/LazyFileData.d.ts +20 -0
  198. package/dist/files/LazyFileData.js +54 -0
  199. package/dist/files/LazyFileData.js.map +1 -0
  200. package/dist/files/LazyFileData.spec.d.ts +1 -0
  201. package/dist/files/LazyFileData.spec.js +27 -0
  202. package/dist/files/LazyFileData.spec.js.map +1 -0
  203. package/dist/files/XmlFile.d.ts +70 -32
  204. package/dist/files/XmlFile.js +106 -118
  205. package/dist/files/XmlFile.js.map +1 -1
  206. package/dist/files/XmlFile.spec.js +325 -262
  207. package/dist/files/XmlFile.spec.js.map +1 -1
  208. package/dist/files/tests/imports.spec.js +48 -40
  209. package/dist/files/tests/imports.spec.js.map +1 -1
  210. package/dist/files/tests/optionalChaning.spec.js +84 -24
  211. package/dist/files/tests/optionalChaning.spec.js.map +1 -1
  212. package/dist/globalCallables.js +16 -21
  213. package/dist/globalCallables.js.map +1 -1
  214. package/dist/index.d.ts +12 -1
  215. package/dist/index.js +12 -1
  216. package/dist/index.js.map +1 -1
  217. package/dist/interfaces.d.ts +389 -161
  218. package/dist/interfaces.js +27 -0
  219. package/dist/interfaces.js.map +1 -1
  220. package/dist/lexer/Character.spec.js +5 -5
  221. package/dist/lexer/Character.spec.js.map +1 -1
  222. package/dist/lexer/Lexer.d.ts +12 -5
  223. package/dist/lexer/Lexer.js +28 -13
  224. package/dist/lexer/Lexer.js.map +1 -1
  225. package/dist/lexer/Lexer.spec.js +181 -135
  226. package/dist/lexer/Lexer.spec.js.map +1 -1
  227. package/dist/lexer/Token.d.ts +9 -1
  228. package/dist/lexer/Token.js +9 -1
  229. package/dist/lexer/Token.js.map +1 -1
  230. package/dist/lexer/TokenKind.d.ts +8 -0
  231. package/dist/lexer/TokenKind.js +24 -4
  232. package/dist/lexer/TokenKind.js.map +1 -1
  233. package/dist/parser/AstNode.d.ts +162 -0
  234. package/dist/parser/AstNode.js +225 -0
  235. package/dist/parser/AstNode.js.map +1 -0
  236. package/dist/parser/AstNode.spec.d.ts +1 -0
  237. package/dist/parser/AstNode.spec.js +165 -0
  238. package/dist/parser/AstNode.spec.js.map +1 -0
  239. package/dist/parser/BrsTranspileState.d.ts +4 -7
  240. package/dist/parser/BrsTranspileState.js +4 -12
  241. package/dist/parser/BrsTranspileState.js.map +1 -1
  242. package/dist/parser/Expression.d.ts +126 -176
  243. package/dist/parser/Expression.js +523 -405
  244. package/dist/parser/Expression.js.map +1 -1
  245. package/dist/parser/Parser.Class.spec.js +151 -145
  246. package/dist/parser/Parser.Class.spec.js.map +1 -1
  247. package/dist/parser/Parser.d.ts +43 -201
  248. package/dist/parser/Parser.js +446 -962
  249. package/dist/parser/Parser.js.map +1 -1
  250. package/dist/parser/Parser.spec.d.ts +3 -1
  251. package/dist/parser/Parser.spec.js +1002 -846
  252. package/dist/parser/Parser.spec.js.map +1 -1
  253. package/dist/parser/SGParser.d.ts +9 -8
  254. package/dist/parser/SGParser.js +10 -8
  255. package/dist/parser/SGParser.js.map +1 -1
  256. package/dist/parser/SGParser.spec.js +27 -38
  257. package/dist/parser/SGParser.spec.js.map +1 -1
  258. package/dist/parser/SGTypes.d.ts +98 -35
  259. package/dist/parser/SGTypes.js +169 -99
  260. package/dist/parser/SGTypes.js.map +1 -1
  261. package/dist/parser/Statement.d.ts +183 -131
  262. package/dist/parser/Statement.js +549 -387
  263. package/dist/parser/Statement.js.map +1 -1
  264. package/dist/parser/Statement.spec.js +45 -21
  265. package/dist/parser/Statement.spec.js.map +1 -1
  266. package/dist/parser/TranspileState.d.ts +1 -1
  267. package/dist/parser/TranspileState.js +7 -12
  268. package/dist/parser/TranspileState.js.map +1 -1
  269. package/dist/parser/tests/Parser.spec.js +3 -2
  270. package/dist/parser/tests/Parser.spec.js.map +1 -1
  271. package/dist/parser/tests/controlFlow/For.spec.js +33 -23
  272. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  273. package/dist/parser/tests/controlFlow/ForEach.spec.js +25 -20
  274. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  275. package/dist/parser/tests/controlFlow/If.spec.js +96 -94
  276. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  277. package/dist/parser/tests/controlFlow/While.spec.js +22 -16
  278. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  279. package/dist/parser/tests/expression/Additive.spec.js +8 -8
  280. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  281. package/dist/parser/tests/expression/ArrayLiterals.spec.js +58 -21
  282. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  283. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +61 -20
  284. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  285. package/dist/parser/tests/expression/Boolean.spec.js +8 -8
  286. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  287. package/dist/parser/tests/expression/Call.spec.js +129 -21
  288. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  289. package/dist/parser/tests/expression/Exponential.spec.js +5 -5
  290. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  291. package/dist/parser/tests/expression/Function.spec.js +36 -36
  292. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  293. package/dist/parser/tests/expression/Indexing.spec.js +67 -22
  294. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  295. package/dist/parser/tests/expression/Multiplicative.spec.js +9 -9
  296. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  297. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +59 -59
  298. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  299. package/dist/parser/tests/expression/PrefixUnary.spec.js +12 -12
  300. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  301. package/dist/parser/tests/expression/Primary.spec.js +12 -12
  302. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  303. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +10 -10
  304. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
  305. package/dist/parser/tests/expression/Relational.spec.js +13 -13
  306. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  307. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +24 -24
  308. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  309. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +96 -57
  310. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  311. package/dist/parser/tests/expression/TernaryExpression.spec.js +89 -89
  312. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  313. package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
  314. package/dist/parser/tests/expression/TypeExpression.spec.js +127 -0
  315. package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
  316. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
  317. package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
  318. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
  319. package/dist/parser/tests/statement/AssignmentOperators.spec.js +15 -15
  320. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  321. package/dist/parser/tests/statement/ConstStatement.spec.js +82 -33
  322. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
  323. package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
  324. package/dist/parser/tests/statement/Continue.spec.js +119 -0
  325. package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
  326. package/dist/parser/tests/statement/Declaration.spec.js +19 -19
  327. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  328. package/dist/parser/tests/statement/Dim.spec.js +22 -22
  329. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  330. package/dist/parser/tests/statement/Enum.spec.js +98 -302
  331. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  332. package/dist/parser/tests/statement/For.spec.js +9 -10
  333. package/dist/parser/tests/statement/For.spec.js.map +1 -1
  334. package/dist/parser/tests/statement/ForEach.spec.js +8 -9
  335. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
  336. package/dist/parser/tests/statement/Function.spec.js +44 -35
  337. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  338. package/dist/parser/tests/statement/Goto.spec.js +5 -5
  339. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  340. package/dist/parser/tests/statement/Increment.spec.js +20 -20
  341. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  342. package/dist/parser/tests/statement/InterfaceStatement.spec.js +30 -196
  343. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
  344. package/dist/parser/tests/statement/LibraryStatement.spec.js +11 -11
  345. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  346. package/dist/parser/tests/statement/Misc.spec.js +16 -78
  347. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  348. package/dist/parser/tests/statement/PrintStatement.spec.js +35 -33
  349. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  350. package/dist/parser/tests/statement/ReturnStatement.spec.js +14 -12
  351. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  352. package/dist/parser/tests/statement/Set.spec.js +48 -35
  353. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  354. package/dist/parser/tests/statement/Stop.spec.js +6 -6
  355. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  356. package/dist/parser/tests/statement/Throw.spec.js +6 -6
  357. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  358. package/dist/parser/tests/statement/TryCatch.spec.js +18 -16
  359. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  360. package/dist/preprocessor/Manifest.d.ts +1 -1
  361. package/dist/preprocessor/Manifest.js +2 -2
  362. package/dist/preprocessor/Manifest.js.map +1 -1
  363. package/dist/preprocessor/Manifest.spec.js +8 -8
  364. package/dist/preprocessor/Manifest.spec.js.map +1 -1
  365. package/dist/preprocessor/Preprocessor.d.ts +5 -6
  366. package/dist/preprocessor/Preprocessor.js +5 -5
  367. package/dist/preprocessor/Preprocessor.js.map +1 -1
  368. package/dist/preprocessor/Preprocessor.spec.js +25 -25
  369. package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
  370. package/dist/preprocessor/PreprocessorParser.d.ts +1 -1
  371. package/dist/preprocessor/PreprocessorParser.js +7 -1
  372. package/dist/preprocessor/PreprocessorParser.js.map +1 -1
  373. package/dist/preprocessor/PreprocessorParser.spec.js +13 -13
  374. package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
  375. package/dist/roku-types/data.json +5892 -10081
  376. package/dist/roku-types/index.d.ts +622 -1719
  377. package/dist/types/ArrayType.d.ts +10 -9
  378. package/dist/types/ArrayType.js +65 -60
  379. package/dist/types/ArrayType.js.map +1 -1
  380. package/dist/types/ArrayType.spec.js +36 -68
  381. package/dist/types/ArrayType.spec.js.map +1 -1
  382. package/dist/types/AssociativeArrayType.d.ts +11 -0
  383. package/dist/types/AssociativeArrayType.js +52 -0
  384. package/dist/types/AssociativeArrayType.js.map +1 -0
  385. package/dist/types/BaseFunctionType.d.ts +9 -0
  386. package/dist/types/BaseFunctionType.js +25 -0
  387. package/dist/types/BaseFunctionType.js.map +1 -0
  388. package/dist/types/BooleanType.d.ts +8 -5
  389. package/dist/types/BooleanType.js +14 -7
  390. package/dist/types/BooleanType.js.map +1 -1
  391. package/dist/types/BooleanType.spec.js +10 -6
  392. package/dist/types/BooleanType.spec.js.map +1 -1
  393. package/dist/types/BscType.d.ts +32 -21
  394. package/dist/types/BscType.js +118 -21
  395. package/dist/types/BscType.js.map +1 -1
  396. package/dist/types/BscTypeKind.d.ts +25 -0
  397. package/dist/types/BscTypeKind.js +30 -0
  398. package/dist/types/BscTypeKind.js.map +1 -0
  399. package/dist/types/BuiltInInterfaceAdder.d.ts +23 -0
  400. package/dist/types/BuiltInInterfaceAdder.js +164 -0
  401. package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
  402. package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
  403. package/dist/types/BuiltInInterfaceAdder.spec.js +116 -0
  404. package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
  405. package/dist/types/ClassType.d.ts +17 -0
  406. package/dist/types/ClassType.js +58 -0
  407. package/dist/types/ClassType.js.map +1 -0
  408. package/dist/types/ClassType.spec.d.ts +1 -0
  409. package/dist/types/ClassType.spec.js +77 -0
  410. package/dist/types/ClassType.spec.js.map +1 -0
  411. package/dist/types/ComponentType.d.ts +26 -0
  412. package/dist/types/ComponentType.js +83 -0
  413. package/dist/types/ComponentType.js.map +1 -0
  414. package/dist/types/DoubleType.d.ts +8 -5
  415. package/dist/types/DoubleType.js +18 -16
  416. package/dist/types/DoubleType.js.map +1 -1
  417. package/dist/types/DoubleType.spec.js +12 -6
  418. package/dist/types/DoubleType.spec.js.map +1 -1
  419. package/dist/types/DynamicType.d.ts +9 -5
  420. package/dist/types/DynamicType.js +15 -4
  421. package/dist/types/DynamicType.js.map +1 -1
  422. package/dist/types/DynamicType.spec.js +16 -5
  423. package/dist/types/DynamicType.spec.js.map +1 -1
  424. package/dist/types/EnumType.d.ts +30 -12
  425. package/dist/types/EnumType.js +43 -17
  426. package/dist/types/EnumType.js.map +1 -1
  427. package/dist/types/EnumType.spec.d.ts +1 -0
  428. package/dist/types/EnumType.spec.js +33 -0
  429. package/dist/types/EnumType.spec.js.map +1 -0
  430. package/dist/types/FloatType.d.ts +8 -5
  431. package/dist/types/FloatType.js +18 -16
  432. package/dist/types/FloatType.js.map +1 -1
  433. package/dist/types/FloatType.spec.js +4 -6
  434. package/dist/types/FloatType.spec.js.map +1 -1
  435. package/dist/types/FunctionType.d.ts +13 -8
  436. package/dist/types/FunctionType.js +30 -14
  437. package/dist/types/FunctionType.js.map +1 -1
  438. package/dist/types/InheritableType.d.ts +28 -0
  439. package/dist/types/InheritableType.js +152 -0
  440. package/dist/types/InheritableType.js.map +1 -0
  441. package/dist/types/IntegerType.d.ts +8 -5
  442. package/dist/types/IntegerType.js +18 -16
  443. package/dist/types/IntegerType.js.map +1 -1
  444. package/dist/types/IntegerType.spec.js +8 -6
  445. package/dist/types/IntegerType.spec.js.map +1 -1
  446. package/dist/types/InterfaceType.d.ts +12 -13
  447. package/dist/types/InterfaceType.js +20 -48
  448. package/dist/types/InterfaceType.js.map +1 -1
  449. package/dist/types/InterfaceType.spec.js +90 -56
  450. package/dist/types/InterfaceType.spec.js.map +1 -1
  451. package/dist/types/InvalidType.d.ts +7 -5
  452. package/dist/types/InvalidType.js +13 -7
  453. package/dist/types/InvalidType.js.map +1 -1
  454. package/dist/types/InvalidType.spec.js +8 -6
  455. package/dist/types/InvalidType.spec.js.map +1 -1
  456. package/dist/types/LongIntegerType.d.ts +8 -5
  457. package/dist/types/LongIntegerType.js +17 -15
  458. package/dist/types/LongIntegerType.js.map +1 -1
  459. package/dist/types/LongIntegerType.spec.js +10 -6
  460. package/dist/types/LongIntegerType.spec.js.map +1 -1
  461. package/dist/types/NamespaceType.d.ts +12 -0
  462. package/dist/types/NamespaceType.js +28 -0
  463. package/dist/types/NamespaceType.js.map +1 -0
  464. package/dist/types/ObjectType.d.ts +9 -8
  465. package/dist/types/ObjectType.js +21 -11
  466. package/dist/types/ObjectType.js.map +1 -1
  467. package/dist/types/ObjectType.spec.js +3 -3
  468. package/dist/types/ObjectType.spec.js.map +1 -1
  469. package/dist/types/ReferenceType.d.ts +63 -0
  470. package/dist/types/ReferenceType.js +423 -0
  471. package/dist/types/ReferenceType.js.map +1 -0
  472. package/dist/types/ReferenceType.spec.d.ts +1 -0
  473. package/dist/types/ReferenceType.spec.js +137 -0
  474. package/dist/types/ReferenceType.spec.js.map +1 -0
  475. package/dist/types/StringType.d.ts +11 -5
  476. package/dist/types/StringType.js +18 -7
  477. package/dist/types/StringType.js.map +1 -1
  478. package/dist/types/StringType.spec.js +3 -5
  479. package/dist/types/StringType.spec.js.map +1 -1
  480. package/dist/types/TypedFunctionType.d.ts +22 -17
  481. package/dist/types/TypedFunctionType.js +78 -60
  482. package/dist/types/TypedFunctionType.js.map +1 -1
  483. package/dist/types/TypedFunctionType.spec.js +105 -20
  484. package/dist/types/TypedFunctionType.spec.js.map +1 -1
  485. package/dist/types/UninitializedType.d.ts +8 -6
  486. package/dist/types/UninitializedType.js +13 -7
  487. package/dist/types/UninitializedType.js.map +1 -1
  488. package/dist/types/UnionType.d.ts +20 -0
  489. package/dist/types/UnionType.js +123 -0
  490. package/dist/types/UnionType.js.map +1 -0
  491. package/dist/types/UnionType.spec.d.ts +1 -0
  492. package/dist/types/UnionType.spec.js +130 -0
  493. package/dist/types/UnionType.spec.js.map +1 -0
  494. package/dist/types/VoidType.d.ts +8 -5
  495. package/dist/types/VoidType.js +14 -7
  496. package/dist/types/VoidType.js.map +1 -1
  497. package/dist/types/VoidType.spec.js +3 -3
  498. package/dist/types/VoidType.spec.js.map +1 -1
  499. package/dist/types/helper.spec.d.ts +1 -0
  500. package/dist/types/helper.spec.js +145 -0
  501. package/dist/types/helper.spec.js.map +1 -0
  502. package/dist/types/helpers.d.ts +19 -37
  503. package/dist/types/helpers.js +159 -99
  504. package/dist/types/helpers.js.map +1 -1
  505. package/dist/types/index.d.ts +22 -0
  506. package/dist/types/index.js +39 -0
  507. package/dist/types/index.js.map +1 -0
  508. package/dist/util.d.ts +132 -137
  509. package/dist/util.js +796 -362
  510. package/dist/util.js.map +1 -1
  511. package/dist/validators/ClassValidator.d.ts +8 -25
  512. package/dist/validators/ClassValidator.js +96 -176
  513. package/dist/validators/ClassValidator.js.map +1 -1
  514. package/package.json +165 -152
  515. package/dist/astUtils/AstEditor.js.map +0 -1
  516. package/dist/astUtils/AstEditor.spec.js.map +0 -1
  517. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +0 -1
  518. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -32
  519. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
  520. package/dist/parser/SGTypes.spec.js +0 -351
  521. package/dist/parser/SGTypes.spec.js.map +0 -1
  522. package/dist/types/CustomType.d.ts +0 -12
  523. package/dist/types/CustomType.js +0 -44
  524. package/dist/types/CustomType.js.map +0 -1
  525. package/dist/types/LazyType.d.ts +0 -16
  526. package/dist/types/LazyType.js +0 -44
  527. package/dist/types/LazyType.js.map +0 -1
  528. /package/dist/astUtils/{AstEditor.spec.d.ts → Editor.spec.d.ts} +0 -0
  529. /package/dist/bscPlugin/{transpile/BrsFilePreTranspileProcessor.spec.d.ts → completions/CompletionsProcessor.spec.d.ts} +0 -0
  530. /package/dist/{parser/SGTypes.spec.d.ts → bscPlugin/serialize/BslibInjector.spec.d.ts} +0 -0
@@ -1,42 +1,35 @@
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");
10
- const VoidType_1 = require("../types/VoidType");
11
- const DynamicType_1 = require("../types/DynamicType");
11
+ const interfaces_1 = require("../interfaces");
12
12
  const SymbolTable_1 = require("../SymbolTable");
13
- const ArrayType_1 = require("../types/ArrayType");
14
- const ObjectType_1 = require("../types/ObjectType");
15
13
  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 {
14
+ const AstNode_1 = require("./AstNode");
15
+ const SymbolTable_2 = require("../SymbolTable");
16
+ const source_map_1 = require("source-map");
17
+ const StringType_1 = require("../types/StringType");
18
+ const DynamicType_1 = require("../types/DynamicType");
19
+ const VoidType_1 = require("../types/VoidType");
20
+ const ReferenceType_1 = require("../types/ReferenceType");
21
+ const UnionType_1 = require("../types/UnionType");
22
+ const types_1 = require("../types");
23
+ const AssociativeArrayType_1 = require("../types/AssociativeArrayType");
24
+ const creators_1 = require("../astUtils/creators");
25
+ class BinaryExpression extends AstNode_1.Expression {
34
26
  constructor(left, operator, right) {
35
27
  super();
36
28
  this.left = left;
37
29
  this.operator = operator;
38
30
  this.right = right;
39
- this.range = util_1.default.createBoundingRange(this.left, this.right);
31
+ this.kind = AstNode_1.AstNodeKind.BinaryExpression;
32
+ this.range = util_1.default.createRangeFromPositions(this.left.range.start, this.right.range.end);
40
33
  }
41
34
  transpile(state) {
42
35
  return [
@@ -48,30 +41,41 @@ class BinaryExpression extends Expression {
48
41
  ];
49
42
  }
50
43
  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);
44
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
45
+ (0, visitors_2.walk)(this, 'left', visitor, options);
46
+ (0, visitors_2.walk)(this, 'right', visitor, options);
47
+ }
48
+ }
49
+ getType(options) {
50
+ const operatorKind = this.operator.kind;
51
+ if (options.flags & SymbolTable_1.SymbolTypeFlag.typetime) {
52
+ // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
53
+ switch (operatorKind) {
54
+ case TokenKind_1.TokenKind.Or:
55
+ return new UnionType_1.UnionType([this.left.getType(options), this.right.getType(options)]);
56
+ //TODO: Intersection Types?, eg. case TokenKind.And:
57
+ }
58
+ }
59
+ else if (options.flags & SymbolTable_1.SymbolTypeFlag.runtime) {
60
+ return util_1.default.binaryOperatorResultType(this.left.getType(options), this.operator, this.right.getType(options));
54
61
  }
62
+ return DynamicType_1.DynamicType.instance;
55
63
  }
56
64
  }
57
65
  exports.BinaryExpression = BinaryExpression;
58
- class CallExpression extends Expression {
66
+ class CallExpression extends AstNode_1.Expression {
59
67
  constructor(callee,
60
68
  /**
61
69
  * Can either be `(`, or `?(` for optional chaining
62
70
  */
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) {
71
+ openingParen, closingParen, args, unused) {
68
72
  super();
69
73
  this.callee = callee;
70
74
  this.openingParen = openingParen;
71
75
  this.closingParen = closingParen;
72
76
  this.args = args;
73
- this.namespaceName = namespaceName;
74
- this.range = util_1.default.createBoundingRange(this.callee, this.closingParen);
77
+ this.kind = AstNode_1.AstNodeKind.CallExpression;
78
+ this.range = util_1.default.createBoundingRange(this.callee, this.openingParen, ...args, this.closingParen);
75
79
  }
76
80
  transpile(state, nameOverride) {
77
81
  let result = [];
@@ -91,24 +95,39 @@ class CallExpression extends Expression {
91
95
  let arg = this.args[i];
92
96
  result.push(...arg.transpile(state));
93
97
  }
94
- result.push(state.transpileToken(this.closingParen));
98
+ if (this.closingParen) {
99
+ result.push(state.transpileToken(this.closingParen));
100
+ }
95
101
  return result;
96
102
  }
97
103
  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);
104
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
105
+ (0, visitors_2.walk)(this, 'callee', visitor, options);
106
+ (0, visitors_2.walkArray)(this.args, visitor, options, this);
101
107
  }
102
108
  }
109
+ getType(options) {
110
+ var _a, _b;
111
+ const calleeType = this.callee.getType(options);
112
+ if (options.ignoreCall) {
113
+ return calleeType;
114
+ }
115
+ if ((0, reflection_1.isNewExpression)(this.parent)) {
116
+ return calleeType;
117
+ }
118
+ if ((0, reflection_1.isCallableType)(calleeType) && (!(0, reflection_1.isReferenceType)(calleeType.returnType) || ((_a = calleeType.returnType) === null || _a === void 0 ? void 0 : _a.isResolvable()))) {
119
+ return calleeType.returnType;
120
+ }
121
+ if (!(0, reflection_1.isReferenceType)(calleeType) && ((_b = calleeType.returnType) === null || _b === void 0 ? void 0 : _b.isResolvable())) {
122
+ return calleeType.returnType;
123
+ }
124
+ return new ReferenceType_1.TypePropertyReferenceType(calleeType, 'returnType');
125
+ }
103
126
  }
104
127
  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) {
128
+ CallExpression.MaximumArguments = 32;
129
+ class FunctionExpression extends AstNode_1.Expression {
130
+ constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeExpression) {
112
131
  super();
113
132
  this.parameters = parameters;
114
133
  this.body = body;
@@ -117,63 +136,29 @@ class FunctionExpression extends Expression {
117
136
  this.leftParen = leftParen;
118
137
  this.rightParen = rightParen;
119
138
  this.asToken = asToken;
120
- this.returnType = returnType;
121
- this.parentFunction = parentFunction;
122
- this.namespaceName = namespaceName;
123
- this.parentSymbolTable = parentSymbolTable;
124
- this.labelStatements = [];
139
+ this.returnTypeExpression = returnTypeExpression;
140
+ this.kind = AstNode_1.AstNodeKind.FunctionExpression;
125
141
  /**
126
142
  * The list of function calls that are declared within this function scope. This excludes CallExpressions
127
143
  * declared in child functions
128
144
  */
129
145
  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();
146
+ //if there's a body, and it doesn't have a SymbolTable, assign one
147
+ if (this.body && !this.body.symbolTable) {
148
+ this.body.symbolTable = new SymbolTable_2.SymbolTable(`Function Body`);
139
149
  }
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();
150
+ this.symbolTable = new SymbolTable_2.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
153
151
  }
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;
152
+ getLeadingTrivia() {
153
+ var _a, _b;
154
+ return (_b = (_a = this.functionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
163
155
  }
164
156
  /**
165
- * The type this function returns
157
+ * The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
158
+ * and ending with the last n' in 'end function' or 'b' in 'end sub'
166
159
  */
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);
160
+ get range() {
161
+ return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...this.parameters, this.rightParen, this.asToken, this.returnTypeExpression, this.end);
177
162
  }
178
163
  transpile(state, name, includeBody = true) {
179
164
  let results = [];
@@ -198,12 +183,12 @@ class FunctionExpression extends Expression {
198
183
  //right paren
199
184
  results.push(state.transpileToken(this.rightParen));
200
185
  //as [Type]
201
- if (this.asToken) {
186
+ if (this.asToken && !state.options.removeParameterTypes && this.returnTypeExpression) {
202
187
  results.push(' ',
203
188
  //as
204
189
  state.transpileToken(this.asToken), ' ',
205
190
  //return type
206
- state.sourceNode(this.returnType, this.getReturnType().toTypeString(state.typeContext)));
191
+ ...this.returnTypeExpression.transpile(state));
207
192
  }
208
193
  if (includeBody) {
209
194
  state.lineage.unshift(this);
@@ -211,52 +196,107 @@ class FunctionExpression extends Expression {
211
196
  state.lineage.shift();
212
197
  results.push(...body);
213
198
  }
214
- if (this.end) {
215
- results.push('\n');
216
- //'end sub'|'end function'
217
- results.push(state.indent(), state.transpileToken(this.end));
218
- }
199
+ results.push('\n');
200
+ //'end sub'|'end function'
201
+ results.push(state.indent(), state.transpileToken(this.end));
219
202
  return results;
220
203
  }
221
- getTypedef(state, name) {
222
- return this.transpile(state, name, false);
204
+ getTypedef(state) {
205
+ var _a, _b, _c, _d, _e;
206
+ let results = [
207
+ new source_map_1.SourceNode(1, 0, null, [
208
+ //'function'|'sub'
209
+ (_a = this.functionType) === null || _a === void 0 ? void 0 : _a.text,
210
+ //functionName?
211
+ ...((0, reflection_1.isFunctionStatement)(this.parent) || (0, reflection_1.isMethodStatement)(this.parent) ? [' ', (_c = (_b = this.parent.name) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : ''] : []),
212
+ //leftParen
213
+ '(',
214
+ //parameters
215
+ ...((_e = (_d = this.parameters) === null || _d === void 0 ? void 0 : _d.map((param, i) => ([
216
+ //separating comma
217
+ i > 0 ? ', ' : '',
218
+ ...param.getTypedef(state)
219
+ ]))) !== null && _e !== void 0 ? _e : []),
220
+ //right paren
221
+ ')',
222
+ //as <ReturnType>
223
+ ...(this.asToken ? [
224
+ ' as ',
225
+ ...this.returnTypeExpression.getTypedef(state)
226
+ ] : []),
227
+ '\n',
228
+ state.indent(),
229
+ //'end sub'|'end function'
230
+ this.end.text
231
+ ])
232
+ ];
233
+ return results;
223
234
  }
224
235
  walk(visitor, options) {
225
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
226
- (0, visitors_1.walkArray)(this.parameters, visitor, options, this);
236
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
237
+ (0, visitors_2.walkArray)(this.parameters, visitor, options, this);
238
+ (0, visitors_2.walk)(this, 'returnTypeExpression', visitor, options);
227
239
  //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);
240
+ if (options.walkMode & visitors_2.InternalWalkMode.recurseChildFunctions) {
241
+ (0, visitors_2.walk)(this, 'body', visitor, options);
231
242
  }
232
243
  }
233
244
  }
234
- getFunctionType() {
235
- let functionType = new TypedFunctionType_1.TypedFunctionType(this.getReturnType());
236
- functionType.isSub = this.functionType.text === 'sub';
245
+ getType(options) {
246
+ var _a, _b, _c;
247
+ //if there's a defined return type, use that
248
+ let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
249
+ const isSub = this.functionType.kind === TokenKind_1.TokenKind.Sub;
250
+ //if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
251
+ if (!returnType) {
252
+ returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
253
+ }
254
+ const resultType = new TypedFunctionType_1.TypedFunctionType(returnType);
255
+ resultType.isSub = isSub;
237
256
  for (let param of this.parameters) {
238
- functionType.addParameter(param.name.text, param.getType(), param.isOptional);
257
+ resultType.addParameter(param.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
258
+ }
259
+ // Figure out this function's name if we can
260
+ let funcName = '';
261
+ if ((0, reflection_1.isMethodStatement)(this.parent) || (0, reflection_1.isInterfaceMethodStatement)(this.parent)) {
262
+ funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
263
+ if (options.typeChain) {
264
+ // Get the typechain info from the parent class
265
+ (_b = this.parent.parent) === null || _b === void 0 ? void 0 : _b.getType(options);
266
+ }
267
+ }
268
+ else if ((0, reflection_1.isFunctionStatement)(this.parent)) {
269
+ funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
239
270
  }
240
- return functionType;
271
+ if (funcName) {
272
+ resultType.setName(funcName);
273
+ }
274
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry(funcName, resultType, options.data, this.range));
275
+ return resultType;
241
276
  }
242
277
  }
243
278
  exports.FunctionExpression = FunctionExpression;
244
- class FunctionParameterExpression extends Expression {
245
- constructor(name, typeInContext, equalsToken, defaultValue, asToken, type, namespaceName) {
279
+ class FunctionParameterExpression extends AstNode_1.Expression {
280
+ constructor(name, equalToken, defaultValue, asToken, typeExpression) {
246
281
  super();
247
282
  this.name = name;
248
- this.typeInContext = typeInContext;
249
- this.equalsToken = equalsToken;
283
+ this.equalToken = equalToken;
250
284
  this.defaultValue = defaultValue;
251
285
  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);
286
+ this.typeExpression = typeExpression;
287
+ this.kind = AstNode_1.AstNodeKind.FunctionParameterExpression;
288
+ }
289
+ getType(options) {
290
+ var _a, _b, _c, _d, _e;
291
+ const paramType = (_d = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.typetime, typeChain: undefined }))) !== null && _b !== void 0 ? _b : (_c = this.defaultValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.runtime, typeChain: undefined }))) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
292
+ (_e = options.typeChain) === null || _e === void 0 ? void 0 : _e.push(new interfaces_1.TypeChainEntry(this.name.text, paramType, options.data, this.range));
293
+ return paramType;
255
294
  }
256
- getType() {
257
- return this.typeInContext;
295
+ get range() {
296
+ return util_1.default.createBoundingRange(this.name, this.asToken, this.typeExpression, this.defaultValue);
258
297
  }
259
298
  transpile(state) {
299
+ var _a, _b;
260
300
  let result = [
261
301
  //name
262
302
  state.transpileToken(this.name)
@@ -267,70 +307,41 @@ class FunctionParameterExpression extends Expression {
267
307
  result.push(this.defaultValue.transpile(state));
268
308
  }
269
309
  //type declaration
270
- if (this.asToken) {
310
+ if (this.asToken && !state.options.removeParameterTypes) {
271
311
  result.push(' ');
272
312
  result.push(state.transpileToken(this.asToken));
273
313
  result.push(' ');
274
- result.push(state.sourceNode(this.type, this.getType().toTypeString(state.typeContext)));
314
+ result.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []));
275
315
  }
276
316
  return result;
277
317
  }
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) {
318
+ getTypedef(state) {
319
+ var _a, _b;
299
320
  return [
300
- state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
321
+ //name
322
+ this.name.text,
323
+ //default value
324
+ ...(this.defaultValue ? [
325
+ ' = ',
326
+ ...this.defaultValue.transpile(state)
327
+ ] : []),
328
+ //type declaration
329
+ ...(this.asToken ? [
330
+ ' as ',
331
+ ...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getTypedef(state)) !== null && _b !== void 0 ? _b : [''])
332
+ ] : [])
301
333
  ];
302
334
  }
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
335
  walk(visitor, options) {
327
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
328
- (0, visitors_1.walk)(this, 'expression', visitor, options);
336
+ // eslint-disable-next-line no-bitwise
337
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
338
+ (0, visitors_2.walk)(this, 'defaultValue', visitor, options);
339
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
329
340
  }
330
341
  }
331
342
  }
332
- exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
333
- class DottedGetExpression extends Expression {
343
+ exports.FunctionParameterExpression = FunctionParameterExpression;
344
+ class DottedGetExpression extends AstNode_1.Expression {
334
345
  constructor(obj, name,
335
346
  /**
336
347
  * Can either be `.`, or `?.` for optional chaining
@@ -340,12 +351,15 @@ class DottedGetExpression extends Expression {
340
351
  this.obj = obj;
341
352
  this.name = name;
342
353
  this.dot = dot;
354
+ this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
343
355
  this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
344
356
  }
345
357
  transpile(state) {
346
358
  //if the callee starts with a namespace name, transpile the name
347
359
  if (state.file.calleeStartsWithNamespace(this)) {
348
- return new NamespacedVariableNameExpression(this).transpile(state);
360
+ return [
361
+ state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
362
+ ];
349
363
  }
350
364
  else {
351
365
  return [
@@ -356,13 +370,29 @@ class DottedGetExpression extends Expression {
356
370
  }
357
371
  }
358
372
  walk(visitor, options) {
359
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
360
- (0, visitors_1.walk)(this, 'obj', visitor, options);
373
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
374
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
375
+ }
376
+ }
377
+ getType(options) {
378
+ var _a, _b, _c, _d, _e, _f;
379
+ const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
380
+ const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.name) === null || _b === void 0 ? void 0 : _b.text, options);
381
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry((_d = this.name) === null || _d === void 0 ? void 0 : _d.text, result, options.data, (_f = (_e = this.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range));
382
+ if (result || options.flags & SymbolTable_1.SymbolTypeFlag.typetime) {
383
+ // All types should be known at typetime
384
+ return result;
361
385
  }
386
+ // It is possible at runtime that a value has been added dynamically to an object, or something
387
+ // TODO: maybe have a strict flag on this?
388
+ return DynamicType_1.DynamicType.instance;
389
+ }
390
+ getName(parseMode) {
391
+ return util_1.default.getAllDottedGetPartsAsString(this, parseMode);
362
392
  }
363
393
  }
364
394
  exports.DottedGetExpression = DottedGetExpression;
365
- class XmlAttributeGetExpression extends Expression {
395
+ class XmlAttributeGetExpression extends AstNode_1.Expression {
366
396
  constructor(obj, name,
367
397
  /**
368
398
  * Can either be `@`, or `?@` for optional chaining
@@ -372,6 +402,7 @@ class XmlAttributeGetExpression extends Expression {
372
402
  this.obj = obj;
373
403
  this.name = name;
374
404
  this.at = at;
405
+ this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
375
406
  this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
376
407
  }
377
408
  transpile(state) {
@@ -382,13 +413,13 @@ class XmlAttributeGetExpression extends Expression {
382
413
  ];
383
414
  }
384
415
  walk(visitor, options) {
385
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
386
- (0, visitors_1.walk)(this, 'obj', visitor, options);
416
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
417
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
387
418
  }
388
419
  }
389
420
  }
390
421
  exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
391
- class IndexedGetExpression extends Expression {
422
+ class IndexedGetExpression extends AstNode_1.Expression {
392
423
  constructor(obj, index,
393
424
  /**
394
425
  * Can either be `[` or `?[`. If `?.[` is used, this will be `[` and `optionalChainingToken` will be `?.`
@@ -401,33 +432,47 @@ class IndexedGetExpression extends Expression {
401
432
  this.openingSquare = openingSquare;
402
433
  this.closingSquare = closingSquare;
403
434
  this.questionDotToken = questionDotToken;
435
+ this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
404
436
  this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.questionDotToken, this.openingSquare, this.index, this.closingSquare);
405
437
  }
406
438
  transpile(state) {
439
+ var _a, _b;
407
440
  return [
408
441
  ...this.obj.transpile(state),
409
442
  this.questionDotToken ? state.transpileToken(this.questionDotToken) : '',
410
443
  state.transpileToken(this.openingSquare),
411
- ...this.index.transpile(state),
412
- state.transpileToken(this.closingSquare)
444
+ ...((_b = (_a = this.index) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []),
445
+ this.closingSquare ? state.transpileToken(this.closingSquare) : ''
413
446
  ];
414
447
  }
415
448
  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);
449
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
450
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
451
+ (0, visitors_2.walk)(this, 'index', visitor, options);
452
+ }
453
+ }
454
+ getType(options) {
455
+ const objType = this.obj.getType(options);
456
+ if ((0, reflection_1.isArrayType)(objType)) {
457
+ // This is used on an array. What is the default type of that array?
458
+ return objType.defaultType;
419
459
  }
460
+ return super.getType(options);
420
461
  }
421
462
  }
422
463
  exports.IndexedGetExpression = IndexedGetExpression;
423
- class GroupingExpression extends Expression {
464
+ class GroupingExpression extends AstNode_1.Expression {
424
465
  constructor(tokens, expression) {
425
466
  super();
426
467
  this.tokens = tokens;
427
468
  this.expression = expression;
469
+ this.kind = AstNode_1.AstNodeKind.GroupingExpression;
428
470
  this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
429
471
  }
430
472
  transpile(state) {
473
+ if ((0, reflection_1.isTypeCastExpression)(this.expression)) {
474
+ return this.expression.transpile(state);
475
+ }
431
476
  return [
432
477
  state.transpileToken(this.tokens.left),
433
478
  ...this.expression.transpile(state),
@@ -435,18 +480,26 @@ class GroupingExpression extends Expression {
435
480
  ];
436
481
  }
437
482
  walk(visitor, options) {
438
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
439
- (0, visitors_1.walk)(this, 'expression', visitor, options);
483
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
484
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
440
485
  }
441
486
  }
487
+ getType(options) {
488
+ return this.expression.getType(options);
489
+ }
442
490
  }
443
491
  exports.GroupingExpression = GroupingExpression;
444
- class LiteralExpression extends Expression {
492
+ class LiteralExpression extends AstNode_1.Expression {
445
493
  constructor(token) {
446
494
  super();
447
495
  this.token = token;
448
- this.range = this.token.range;
449
- this.type = util_1.default.tokenToBscType(token);
496
+ this.kind = AstNode_1.AstNodeKind.LiteralExpression;
497
+ }
498
+ get range() {
499
+ return this.token.range;
500
+ }
501
+ getType(options) {
502
+ return util_1.default.tokenToBscType(this.token);
450
503
  }
451
504
  transpile(state) {
452
505
  let text;
@@ -454,7 +507,7 @@ class LiteralExpression extends Expression {
454
507
  //wrap quasis with quotes (and escape inner quotemarks)
455
508
  text = `"${this.token.text.replace(/"/g, '""')}"`;
456
509
  }
457
- else if ((0, reflection_1.isStringType)(this.type)) {
510
+ else if (this.token.kind === TokenKind_1.TokenKind.StringLiteral) {
458
511
  text = this.token.text;
459
512
  //add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
460
513
  if (text.endsWith('"') === false) {
@@ -477,10 +530,11 @@ exports.LiteralExpression = LiteralExpression;
477
530
  * This is a special expression only used within template strings. It exists so we can prevent producing lots of empty strings
478
531
  * during template string transpile by identifying these expressions explicitly and skipping the bslib_toString around them
479
532
  */
480
- class EscapedCharCodeLiteralExpression extends Expression {
533
+ class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
481
534
  constructor(token) {
482
535
  super();
483
536
  this.token = token;
537
+ this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
484
538
  this.range = token.range;
485
539
  }
486
540
  transpile(state) {
@@ -493,15 +547,15 @@ class EscapedCharCodeLiteralExpression extends Expression {
493
547
  }
494
548
  }
495
549
  exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
496
- class ArrayLiteralExpression extends Expression {
550
+ class ArrayLiteralExpression extends AstNode_1.Expression {
497
551
  constructor(elements, open, close, hasSpread = false) {
498
- var _a;
499
552
  super();
500
553
  this.elements = elements;
501
554
  this.open = open;
502
555
  this.close = close;
503
556
  this.hasSpread = hasSpread;
504
- this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
557
+ this.kind = AstNode_1.AstNodeKind.ArrayLiteralExpression;
558
+ this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
505
559
  }
506
560
  transpile(state) {
507
561
  let result = [];
@@ -534,25 +588,31 @@ class ArrayLiteralExpression extends Expression {
534
588
  result.push('\n');
535
589
  result.push(state.indent());
536
590
  }
537
- result.push(state.transpileToken(this.close));
591
+ if (this.close) {
592
+ result.push(state.transpileToken(this.close));
593
+ }
538
594
  return result;
539
595
  }
540
596
  walk(visitor, options) {
541
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
542
- (0, visitors_1.walkArray)(this.elements, visitor, options, this);
597
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
598
+ (0, visitors_2.walkArray)(this.elements, visitor, options, this);
543
599
  }
544
600
  }
601
+ getType(options) {
602
+ const innerTypes = this.elements.filter(x => !(0, reflection_1.isCommentStatement)(x)).map(expr => expr.getType(options));
603
+ return new types_1.ArrayType(...innerTypes);
604
+ }
545
605
  }
546
606
  exports.ArrayLiteralExpression = ArrayLiteralExpression;
547
- class AAMemberExpression extends Expression {
607
+ class AAMemberExpression extends AstNode_1.Expression {
548
608
  constructor(keyToken, colonToken,
549
609
  /** The expression evaluated to determine the member's initial value. */
550
- value, type) {
610
+ value) {
551
611
  super();
552
612
  this.keyToken = keyToken;
553
613
  this.colonToken = colonToken;
554
614
  this.value = value;
555
- this.type = type;
615
+ this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
556
616
  this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
557
617
  }
558
618
  transpile(state) {
@@ -560,33 +620,21 @@ class AAMemberExpression extends Expression {
560
620
  return [];
561
621
  }
562
622
  walk(visitor, options) {
563
- (0, visitors_1.walk)(this, 'value', visitor, options);
623
+ (0, visitors_2.walk)(this, 'value', visitor, options);
624
+ }
625
+ getType(options) {
626
+ return this.value.getType(options);
564
627
  }
565
628
  }
566
629
  exports.AAMemberExpression = AAMemberExpression;
567
- class AALiteralExpression extends Expression {
568
- constructor(elements, open, close, functionExpression) {
569
- var _a;
630
+ class AALiteralExpression extends AstNode_1.Expression {
631
+ constructor(elements, open, close) {
570
632
  super();
571
633
  this.elements = elements;
572
634
  this.open = open;
573
635
  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
- }
636
+ this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
637
+ this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
590
638
  }
591
639
  transpile(state) {
592
640
  let result = [];
@@ -637,54 +685,80 @@ class AALiteralExpression extends Expression {
637
685
  result.push(state.indent());
638
686
  }
639
687
  //close curly
640
- result.push(state.transpileToken(this.close));
688
+ if (this.close) {
689
+ result.push(state.transpileToken(this.close));
690
+ }
641
691
  return result;
642
692
  }
643
693
  walk(visitor, options) {
644
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
645
- (0, visitors_1.walkArray)(this.elements, visitor, options, this);
694
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
695
+ (0, visitors_2.walkArray)(this.elements, visitor, options, this);
696
+ }
697
+ }
698
+ getType(options) {
699
+ const resultType = new AssociativeArrayType_1.AssociativeArrayType();
700
+ for (const element of this.elements) {
701
+ if ((0, reflection_1.isAAMemberExpression)(element)) {
702
+ resultType.addMember(element.keyToken.text, { definingNode: element }, element.getType(options), SymbolTable_1.SymbolTypeFlag.runtime);
703
+ }
646
704
  }
705
+ return resultType;
647
706
  }
648
707
  }
649
708
  exports.AALiteralExpression = AALiteralExpression;
650
- class UnaryExpression extends Expression {
709
+ class UnaryExpression extends AstNode_1.Expression {
651
710
  constructor(operator, right) {
652
711
  super();
653
712
  this.operator = operator;
654
713
  this.right = right;
714
+ this.kind = AstNode_1.AstNodeKind.UnaryExpression;
655
715
  this.range = util_1.default.createBoundingRange(this.operator, this.right);
656
716
  }
657
717
  transpile(state) {
718
+ let separatingWhitespace;
719
+ if ((0, reflection_1.isVariableExpression)(this.right)) {
720
+ separatingWhitespace = this.right.name.leadingWhitespace;
721
+ }
722
+ else if ((0, reflection_1.isLiteralExpression)(this.right)) {
723
+ separatingWhitespace = this.right.token.leadingWhitespace;
724
+ }
725
+ else {
726
+ separatingWhitespace = ' ';
727
+ }
658
728
  return [
659
729
  state.transpileToken(this.operator),
660
- ' ',
730
+ separatingWhitespace,
661
731
  ...this.right.transpile(state)
662
732
  ];
663
733
  }
664
734
  walk(visitor, options) {
665
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
666
- (0, visitors_1.walk)(this, 'right', visitor, options);
735
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
736
+ (0, visitors_2.walk)(this, 'right', visitor, options);
667
737
  }
668
738
  }
739
+ getType(options) {
740
+ return util_1.default.unaryOperatorResultType(this.operator, this.right.getType(options));
741
+ }
669
742
  }
670
743
  exports.UnaryExpression = UnaryExpression;
671
- class VariableExpression extends Expression {
672
- constructor(name, namespaceName) {
744
+ class VariableExpression extends AstNode_1.Expression {
745
+ constructor(name) {
746
+ var _a;
673
747
  super();
674
748
  this.name = name;
675
- this.namespaceName = namespaceName;
676
- this.range = this.name.range;
749
+ this.kind = AstNode_1.AstNodeKind.VariableExpression;
750
+ this.range = (_a = this.name) === null || _a === void 0 ? void 0 : _a.range;
677
751
  }
678
752
  getName(parseMode) {
679
753
  return this.name.text;
680
754
  }
681
755
  transpile(state) {
682
- var _a;
683
756
  let result = [];
757
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
684
758
  //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))) {
759
+ if (state.file.calleeIsKnownNamespaceFunction(this, namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) {
686
760
  result.push(state.sourceNode(this, [
687
- this.namespaceName.getName(Parser_1.ParseMode.BrightScript),
761
+ namespace.getName(Parser_1.ParseMode.BrightScript),
688
762
  '_',
689
763
  this.getName(Parser_1.ParseMode.BrightScript)
690
764
  ]));
@@ -698,24 +772,54 @@ class VariableExpression extends Expression {
698
772
  walk(visitor, options) {
699
773
  //nothing to walk
700
774
  }
775
+ getType(options) {
776
+ var _a;
777
+ let resultType = util_1.default.tokenToBscType(this.name);
778
+ const nameKey = this.name.text;
779
+ if (!resultType) {
780
+ const symbolTable = this.getSymbolTable();
781
+ resultType = symbolTable === null || symbolTable === void 0 ? void 0 : symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
782
+ }
783
+ (_a = options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry(nameKey, resultType, options.data, this.range));
784
+ return resultType;
785
+ }
701
786
  }
702
787
  exports.VariableExpression = VariableExpression;
703
- class SourceLiteralExpression extends Expression {
788
+ class SourceLiteralExpression extends AstNode_1.Expression {
704
789
  constructor(token) {
705
790
  super();
706
791
  this.token = token;
707
- this.range = token.range;
792
+ this.kind = AstNode_1.AstNodeKind.SourceLiteralExpression;
793
+ this.range = token === null || token === void 0 ? void 0 : token.range;
794
+ }
795
+ /**
796
+ * Find the index of the function in its parent
797
+ */
798
+ findFunctionIndex(parentFunction, func) {
799
+ let index = -1;
800
+ parentFunction.findChild((node) => {
801
+ if ((0, reflection_1.isFunctionExpression)(node)) {
802
+ index++;
803
+ if (node === func) {
804
+ return true;
805
+ }
806
+ }
807
+ }, {
808
+ walkMode: visitors_1.WalkMode.visitAllRecursive
809
+ });
810
+ return index;
708
811
  }
709
812
  getFunctionName(state, parseMode) {
710
- let functionExpression = state.file.getFunctionExpressionAtPosition(this.token.range.start);
813
+ let func = state.file.getFunctionScopeAtPosition(this.token.range.start).func;
711
814
  let nameParts = [];
712
- while (functionExpression.parentFunction) {
713
- let index = functionExpression.parentFunction.childFunctionExpressions.indexOf(functionExpression);
815
+ let parentFunction;
816
+ while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
817
+ let index = this.findFunctionIndex(parentFunction, func);
714
818
  nameParts.unshift(`anon${index}`);
715
- functionExpression = functionExpression.parentFunction;
819
+ func = parentFunction;
716
820
  }
717
821
  //get the index of this function in its parent
718
- nameParts.unshift(functionExpression.functionStatement.getName(parseMode));
822
+ nameParts.unshift(func.functionStatement.getName(parseMode));
719
823
  return nameParts.join('$');
720
824
  }
721
825
  transpile(state) {
@@ -739,10 +843,10 @@ class SourceLiteralExpression extends Expression {
739
843
  text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
740
844
  break;
741
845
  case TokenKind_1.TokenKind.PkgPathLiteral:
742
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}"`;
846
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
743
847
  break;
744
848
  case TokenKind_1.TokenKind.PkgLocationLiteral:
745
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}:" + str(LINE_NUM)`;
849
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}:" + str(LINE_NUM)`;
746
850
  break;
747
851
  case TokenKind_1.TokenKind.LineNumLiteral:
748
852
  default:
@@ -764,11 +868,12 @@ exports.SourceLiteralExpression = SourceLiteralExpression;
764
868
  * except we need to uniquely identify these statements so we can
765
869
  * do more type checking.
766
870
  */
767
- class NewExpression extends Expression {
871
+ class NewExpression extends AstNode_1.Expression {
768
872
  constructor(newKeyword, call) {
769
873
  super();
770
874
  this.newKeyword = newKeyword;
771
875
  this.call = call;
876
+ this.kind = AstNode_1.AstNodeKind.NewExpression;
772
877
  this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
773
878
  }
774
879
  /**
@@ -776,29 +881,29 @@ class NewExpression extends Expression {
776
881
  */
777
882
  get className() {
778
883
  //the parser guarantees the callee of a new statement's call object will be
779
- //a NamespacedVariableNameExpression
884
+ //either a VariableExpression or a DottedGet
780
885
  return this.call.callee;
781
886
  }
782
- get namespaceName() {
783
- return this.call.namespaceName;
784
- }
785
887
  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;
888
+ var _a;
889
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
890
+ 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
891
  //new statements within a namespace block can omit the leading namespace if the class resides in that same namespace.
789
892
  //So we need to figure out if this is a namespace-omitted class, or if this class exists without a namespace.
790
893
  return this.call.transpile(state, cls === null || cls === void 0 ? void 0 : cls.getName(Parser_1.ParseMode.BrightScript));
791
894
  }
792
895
  walk(visitor, options) {
793
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
794
- (0, visitors_1.walk)(this, 'call', visitor, options);
896
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
897
+ (0, visitors_2.walk)(this, 'call', visitor, options);
795
898
  }
796
899
  }
900
+ getType(options) {
901
+ return this.call.getType(options);
902
+ }
797
903
  }
798
904
  exports.NewExpression = NewExpression;
799
- class CallfuncExpression extends Expression {
905
+ class CallfuncExpression extends AstNode_1.Expression {
800
906
  constructor(callee, operator, methodName, openingParen, args, closingParen) {
801
- var _a;
802
907
  super();
803
908
  this.callee = callee;
804
909
  this.operator = operator;
@@ -806,7 +911,8 @@ class CallfuncExpression extends Expression {
806
911
  this.openingParen = openingParen;
807
912
  this.args = args;
808
913
  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);
914
+ this.kind = AstNode_1.AstNodeKind.CallfuncExpression;
915
+ this.range = util_1.default.createBoundingRange(callee, operator, methodName, openingParen, ...args, closingParen);
810
916
  }
811
917
  transpile(state) {
812
918
  let result = [];
@@ -832,10 +938,37 @@ class CallfuncExpression extends Expression {
832
938
  return result;
833
939
  }
834
940
  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);
941
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
942
+ (0, visitors_2.walk)(this, 'callee', visitor, options);
943
+ (0, visitors_2.walkArray)(this.args, visitor, options, this);
944
+ }
945
+ }
946
+ getType(options) {
947
+ var _a, _b, _c;
948
+ let result = DynamicType_1.DynamicType.instance;
949
+ // a little hacky here with checking options.ignoreCall because callFuncExpression has the method name
950
+ // It's nicer for CallExpression, because it's a call on any expression.
951
+ const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.runtime }));
952
+ if ((0, reflection_1.isComponentType)(calleeType) || (0, reflection_1.isReferenceType)(calleeType)) {
953
+ const funcType = (_b = (_a = calleeType).getCallFuncType) === null || _b === void 0 ? void 0 : _b.call(_a, this.methodName.text, options);
954
+ if (funcType) {
955
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry(this.methodName.text, funcType, options.data, this.methodName.range, (0, creators_1.createToken)(TokenKind_1.TokenKind.Callfunc)));
956
+ if (options.ignoreCall) {
957
+ result = funcType;
958
+ }
959
+ }
960
+ /* TODO:
961
+ make callfunc return types work
962
+ else if (isCallableType(funcType) && (!isReferenceType(funcType.returnType) || funcType.returnType.isResolvable())) {
963
+ result = funcType.returnType;
964
+ } else if (!isReferenceType(funcType) && (funcType as any)?.returnType?.isResolvable()) {
965
+ result = (funcType as any).returnType;
966
+ } else {
967
+ return new TypePropertyReferenceType(funcType, 'returnType');
968
+ }
969
+ */
838
970
  }
971
+ return result;
839
972
  }
840
973
  }
841
974
  exports.CallfuncExpression = CallfuncExpression;
@@ -843,12 +976,12 @@ exports.CallfuncExpression = CallfuncExpression;
843
976
  * Since template strings can contain newlines, we need to concatenate multiple strings together with chr() calls.
844
977
  * This is a single expression that represents the string contatenation of all parts of a single quasi.
845
978
  */
846
- class TemplateStringQuasiExpression extends Expression {
979
+ class TemplateStringQuasiExpression extends AstNode_1.Expression {
847
980
  constructor(expressions) {
848
- var _a;
849
981
  super();
850
982
  this.expressions = expressions;
851
- this.range = util_1.default.createBoundingRange(...((_a = this.expressions) !== null && _a !== void 0 ? _a : []));
983
+ this.kind = AstNode_1.AstNodeKind.TemplateStringQuasiExpression;
984
+ this.range = util_1.default.createBoundingRange(...expressions);
852
985
  }
853
986
  transpile(state, skipEmptyStrings = true) {
854
987
  let result = [];
@@ -865,28 +998,30 @@ class TemplateStringQuasiExpression extends Expression {
865
998
  return result;
866
999
  }
867
1000
  walk(visitor, options) {
868
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
869
- (0, visitors_1.walkArray)(this.expressions, visitor, options, this);
1001
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1002
+ (0, visitors_2.walkArray)(this.expressions, visitor, options, this);
870
1003
  }
871
1004
  }
872
1005
  }
873
1006
  exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
874
- class TemplateStringExpression extends Expression {
1007
+ class TemplateStringExpression extends AstNode_1.Expression {
875
1008
  constructor(openingBacktick, quasis, expressions, closingBacktick) {
876
- var _a;
877
1009
  super();
878
1010
  this.openingBacktick = openingBacktick;
879
1011
  this.quasis = quasis;
880
1012
  this.expressions = expressions;
881
1013
  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);
1014
+ this.kind = AstNode_1.AstNodeKind.TemplateStringExpression;
1015
+ this.range = util_1.default.createBoundingRange(openingBacktick, quasis[0], quasis[quasis.length - 1], closingBacktick);
1016
+ }
1017
+ getType(options) {
1018
+ return StringType_1.StringType.instance;
884
1019
  }
885
1020
  transpile(state) {
886
1021
  if (this.quasis.length === 1 && this.expressions.length === 0) {
887
1022
  return this.quasis[0].transpile(state);
888
1023
  }
889
- let result = [];
1024
+ let result = ['('];
890
1025
  let plus = '';
891
1026
  //helper function to figure out when to include the plus
892
1027
  function add(...items) {
@@ -905,7 +1040,7 @@ class TemplateStringExpression extends Expression {
905
1040
  if (expression) {
906
1041
  //skip the toString wrapper around certain expressions
907
1042
  if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
908
- ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.type))) {
1043
+ ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.getType()))) {
909
1044
  add(...expression.transpile(state));
910
1045
  //wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
911
1046
  }
@@ -914,33 +1049,34 @@ class TemplateStringExpression extends Expression {
914
1049
  }
915
1050
  }
916
1051
  }
1052
+ //the expression should be wrapped in parens so it can be used line a single expression at runtime
1053
+ result.push(')');
917
1054
  return result;
918
1055
  }
919
1056
  walk(visitor, options) {
920
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1057
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
921
1058
  //walk the quasis and expressions in left-to-right order
922
1059
  for (let i = 0; i < this.quasis.length; i++) {
923
- (0, visitors_1.walk)(this.quasis, i, visitor, options, this);
1060
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
924
1061
  //this skips the final loop iteration since we'll always have one more quasi than expression
925
1062
  if (this.expressions[i]) {
926
- (0, visitors_1.walk)(this.expressions, i, visitor, options, this);
1063
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
927
1064
  }
928
1065
  }
929
1066
  }
930
1067
  }
931
1068
  }
932
1069
  exports.TemplateStringExpression = TemplateStringExpression;
933
- class TaggedTemplateStringExpression extends Expression {
1070
+ class TaggedTemplateStringExpression extends AstNode_1.Expression {
934
1071
  constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
935
- var _a;
936
1072
  super();
937
1073
  this.tagName = tagName;
938
1074
  this.openingBacktick = openingBacktick;
939
1075
  this.quasis = quasis;
940
1076
  this.expressions = expressions;
941
1077
  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);
1078
+ this.kind = AstNode_1.AstNodeKind.TaggedTemplateStringExpression;
1079
+ this.range = util_1.default.createBoundingRange(tagName, openingBacktick, quasis[0], quasis[quasis.length - 1], closingBacktick);
944
1080
  }
945
1081
  transpile(state) {
946
1082
  let result = [];
@@ -967,34 +1103,29 @@ class TaggedTemplateStringExpression extends Expression {
967
1103
  return result;
968
1104
  }
969
1105
  walk(visitor, options) {
970
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1106
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
971
1107
  //walk the quasis and expressions in left-to-right order
972
1108
  for (let i = 0; i < this.quasis.length; i++) {
973
- (0, visitors_1.walk)(this.quasis, i, visitor, options, this);
1109
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
974
1110
  //this skips the final loop iteration since we'll always have one more quasi than expression
975
1111
  if (this.expressions[i]) {
976
- (0, visitors_1.walk)(this.expressions, i, visitor, options, this);
1112
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
977
1113
  }
978
1114
  }
979
1115
  }
980
1116
  }
981
1117
  }
982
1118
  exports.TaggedTemplateStringExpression = TaggedTemplateStringExpression;
983
- class AnnotationExpression extends Expression {
1119
+ class AnnotationExpression extends AstNode_1.Expression {
984
1120
  constructor(atToken, nameToken) {
985
1121
  super();
986
1122
  this.atToken = atToken;
987
1123
  this.nameToken = nameToken;
1124
+ this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
988
1125
  this.name = nameToken.text;
989
1126
  }
990
1127
  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;
1128
+ return util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
998
1129
  }
999
1130
  /**
1000
1131
  * Convert annotation arguments to JavaScript types
@@ -1006,6 +1137,9 @@ class AnnotationExpression extends Expression {
1006
1137
  }
1007
1138
  return this.call.args.map(e => expressionToValue(e, strict));
1008
1139
  }
1140
+ getLeadingTrivia() {
1141
+ return this.atToken.leadingTrivia;
1142
+ }
1009
1143
  transpile(state) {
1010
1144
  return [];
1011
1145
  }
@@ -1022,7 +1156,7 @@ class AnnotationExpression extends Expression {
1022
1156
  }
1023
1157
  }
1024
1158
  exports.AnnotationExpression = AnnotationExpression;
1025
- class TernaryExpression extends Expression {
1159
+ class TernaryExpression extends AstNode_1.Expression {
1026
1160
  constructor(test, questionMarkToken, consequent, colonToken, alternate) {
1027
1161
  super();
1028
1162
  this.test = test;
@@ -1030,7 +1164,8 @@ class TernaryExpression extends Expression {
1030
1164
  this.consequent = consequent;
1031
1165
  this.colonToken = colonToken;
1032
1166
  this.alternate = alternate;
1033
- this.range = util_1.default.createBoundingRange(this.test, this.questionMarkToken, this.consequent, this.colonToken, this.alternate);
1167
+ this.kind = AstNode_1.AstNodeKind.TernaryExpression;
1168
+ this.range = util_1.default.createBoundingRange(test, questionMarkToken, consequent, colonToken, alternate);
1034
1169
  }
1035
1170
  transpile(state) {
1036
1171
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
@@ -1058,21 +1193,22 @@ class TernaryExpression extends Expression {
1058
1193
  return result;
1059
1194
  }
1060
1195
  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);
1196
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1197
+ (0, visitors_2.walk)(this, 'test', visitor, options);
1198
+ (0, visitors_2.walk)(this, 'consequent', visitor, options);
1199
+ (0, visitors_2.walk)(this, 'alternate', visitor, options);
1065
1200
  }
1066
1201
  }
1067
1202
  }
1068
1203
  exports.TernaryExpression = TernaryExpression;
1069
- class NullCoalescingExpression extends Expression {
1204
+ class NullCoalescingExpression extends AstNode_1.Expression {
1070
1205
  constructor(consequent, questionQuestionToken, alternate) {
1071
1206
  super();
1072
1207
  this.consequent = consequent;
1073
1208
  this.questionQuestionToken = questionQuestionToken;
1074
1209
  this.alternate = alternate;
1075
- this.range = util_1.default.createBoundingRange(this.consequent, this.questionQuestionToken, this.alternate);
1210
+ this.kind = AstNode_1.AstNodeKind.NullCoalescingExpression;
1211
+ this.range = util_1.default.createBoundingRange(consequent, questionQuestionToken, alternate);
1076
1212
  }
1077
1213
  transpile(state) {
1078
1214
  let result = [];
@@ -1101,18 +1237,22 @@ class NullCoalescingExpression extends Expression {
1101
1237
  return result;
1102
1238
  }
1103
1239
  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);
1240
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1241
+ (0, visitors_2.walk)(this, 'consequent', visitor, options);
1242
+ (0, visitors_2.walk)(this, 'alternate', visitor, options);
1107
1243
  }
1108
1244
  }
1109
1245
  }
1110
1246
  exports.NullCoalescingExpression = NullCoalescingExpression;
1111
- class RegexLiteralExpression extends Expression {
1247
+ class RegexLiteralExpression extends AstNode_1.Expression {
1112
1248
  constructor(tokens) {
1113
1249
  super();
1114
1250
  this.tokens = tokens;
1115
- this.range = this.tokens.regexLiteral.range;
1251
+ this.kind = AstNode_1.AstNodeKind.RegexLiteralExpression;
1252
+ }
1253
+ get range() {
1254
+ var _a, _b;
1255
+ return (_b = (_a = this.tokens) === null || _a === void 0 ? void 0 : _a.regexLiteral) === null || _b === void 0 ? void 0 : _b.range;
1116
1256
  }
1117
1257
  transpile(state) {
1118
1258
  var _a, _b;
@@ -1143,109 +1283,6 @@ class RegexLiteralExpression extends Expression {
1143
1283
  }
1144
1284
  }
1145
1285
  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
1286
  function expressionToValue(expr, strict) {
1250
1287
  if (!expr) {
1251
1288
  return null;
@@ -1279,11 +1316,92 @@ function expressionToValue(expr, strict) {
1279
1316
  return strict ? null : expr;
1280
1317
  }
1281
1318
  function numberExpressionToValue(expr, operator = '') {
1282
- if ((0, reflection_1.isIntegerType)(expr.type) || (0, reflection_1.isLongIntegerType)(expr.type)) {
1319
+ if ((0, reflection_1.isIntegerType)(expr.getType()) || (0, reflection_1.isLongIntegerType)(expr.getType())) {
1283
1320
  return parseInt(operator + expr.token.text);
1284
1321
  }
1285
1322
  else {
1286
1323
  return parseFloat(operator + expr.token.text);
1287
1324
  }
1288
1325
  }
1326
+ class TypeExpression extends AstNode_1.Expression {
1327
+ constructor(
1328
+ /**
1329
+ * The standard AST expression that represents the type for this TypeExpression.
1330
+ */
1331
+ expression) {
1332
+ super();
1333
+ this.expression = expression;
1334
+ this.kind = AstNode_1.AstNodeKind.TypeExpression;
1335
+ this.range = expression === null || expression === void 0 ? void 0 : expression.range;
1336
+ }
1337
+ transpile(state) {
1338
+ return [this.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime }).toTypeString()];
1339
+ }
1340
+ walk(visitor, options) {
1341
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1342
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
1343
+ }
1344
+ }
1345
+ getType(options) {
1346
+ return this.expression.getType(Object.assign(Object.assign({}, options), { flags: SymbolTable_1.SymbolTypeFlag.typetime }));
1347
+ }
1348
+ getTypedef(state) {
1349
+ // TypeDefs should pass through any valid type names
1350
+ return this.expression.transpile(state);
1351
+ }
1352
+ getName(parseMode = Parser_1.ParseMode.BrighterScript) {
1353
+ //TODO: this may not support Complex Types, eg. generics or Unions
1354
+ return util_1.default.getAllDottedGetPartsAsString(this.expression, parseMode);
1355
+ }
1356
+ getNameParts() {
1357
+ //TODO: really, this code is only used to get Namespaces. It could be more clear.
1358
+ return util_1.default.getAllDottedGetParts(this.expression).map(x => x.text);
1359
+ }
1360
+ }
1361
+ exports.TypeExpression = TypeExpression;
1362
+ class TypeCastExpression extends AstNode_1.Expression {
1363
+ constructor(obj, asToken, typeExpression) {
1364
+ super();
1365
+ this.obj = obj;
1366
+ this.asToken = asToken;
1367
+ this.typeExpression = typeExpression;
1368
+ this.kind = AstNode_1.AstNodeKind.TypeCastExpression;
1369
+ this.range = util_1.default.createBoundingRange(this.obj, this.asToken, this.typeExpression);
1370
+ }
1371
+ transpile(state) {
1372
+ return this.obj.transpile(state);
1373
+ }
1374
+ walk(visitor, options) {
1375
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1376
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
1377
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
1378
+ }
1379
+ }
1380
+ getType(options) {
1381
+ return this.typeExpression.getType(options);
1382
+ }
1383
+ }
1384
+ exports.TypeCastExpression = TypeCastExpression;
1385
+ class TypedArrayExpression extends AstNode_1.Expression {
1386
+ constructor(innerType, leftBracket, rightBracket) {
1387
+ super();
1388
+ this.innerType = innerType;
1389
+ this.leftBracket = leftBracket;
1390
+ this.rightBracket = rightBracket;
1391
+ this.kind = AstNode_1.AstNodeKind.TypedArrayExpression;
1392
+ this.range = util_1.default.createBoundingRange(this.innerType, this.leftBracket, this.rightBracket);
1393
+ }
1394
+ transpile(state) {
1395
+ return [this.getType({ flags: SymbolTable_1.SymbolTypeFlag.typetime }).toTypeString()];
1396
+ }
1397
+ walk(visitor, options) {
1398
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1399
+ (0, visitors_2.walk)(this, 'innerType', visitor, options);
1400
+ }
1401
+ }
1402
+ getType(options) {
1403
+ return new types_1.ArrayType(this.innerType.getType(options));
1404
+ }
1405
+ }
1406
+ exports.TypedArrayExpression = TypedArrayExpression;
1289
1407
  //# sourceMappingURL=Expression.js.map