brighterscript 1.0.0-alpha.23 → 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 (536) hide show
  1. package/CHANGELOG.md +585 -218
  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 +79 -15
  33. package/dist/DiagnosticMessages.js +134 -21
  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 +222 -87
  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 +162 -81
  54. package/dist/Program.js +903 -732
  55. package/dist/Program.js.map +1 -1
  56. package/dist/ProgramBuilder.d.ts +22 -12
  57. package/dist/ProgramBuilder.js +132 -104
  58. package/dist/ProgramBuilder.js.map +1 -1
  59. package/dist/Scope.d.ts +95 -134
  60. package/dist/Scope.js +477 -551
  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 +95 -29
  65. package/dist/SymbolTable.js +256 -102
  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 -68
  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 -100
  90. package/dist/astUtils/reflection.js +225 -166
  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 +54 -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 +12 -2
  105. package/dist/bscPlugin/BscPlugin.js +41 -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.d.ts +1 -1
  117. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +21 -12
  118. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  119. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +86 -12
  120. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  121. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +57 -0
  122. package/dist/bscPlugin/completions/CompletionsProcessor.js +544 -0
  123. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
  124. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +1909 -0
  125. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
  126. package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
  127. package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
  128. package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
  129. package/dist/bscPlugin/hover/HoverProcessor.d.ts +17 -0
  130. package/dist/bscPlugin/hover/HoverProcessor.js +188 -0
  131. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
  132. package/dist/bscPlugin/hover/HoverProcessor.spec.js +513 -0
  133. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
  134. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +3 -1
  135. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +102 -29
  136. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  137. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +167 -6
  138. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
  139. package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
  140. package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
  141. package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
  142. package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
  143. package/dist/bscPlugin/serialize/BslibManager.js +40 -0
  144. package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
  145. package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
  146. package/dist/bscPlugin/serialize/FileSerializer.js +72 -0
  147. package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
  148. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +16 -0
  149. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +123 -0
  150. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
  151. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
  152. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +41 -0
  153. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
  154. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
  155. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
  156. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
  157. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +22 -1
  158. package/dist/bscPlugin/validation/BrsFileValidator.js +316 -29
  159. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  160. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
  161. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +264 -0
  162. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
  163. package/dist/bscPlugin/validation/ProgramValidator.d.ts +10 -0
  164. package/dist/bscPlugin/validation/ProgramValidator.js +32 -0
  165. package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
  166. package/dist/bscPlugin/validation/ScopeValidator.d.ts +56 -8
  167. package/dist/bscPlugin/validation/ScopeValidator.js +514 -116
  168. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  169. package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
  170. package/dist/bscPlugin/validation/ScopeValidator.spec.js +2454 -0
  171. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
  172. package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
  173. package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
  174. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
  175. package/dist/cli.js +107 -8
  176. package/dist/cli.js.map +1 -1
  177. package/dist/deferred.d.ts +3 -3
  178. package/dist/deferred.js.map +1 -1
  179. package/dist/diagnosticUtils.d.ts +8 -2
  180. package/dist/diagnosticUtils.js +47 -17
  181. package/dist/diagnosticUtils.js.map +1 -1
  182. package/dist/examples/plugins/removePrint.js +8 -10
  183. package/dist/examples/plugins/removePrint.js.map +1 -1
  184. package/dist/files/AssetFile.d.ts +26 -0
  185. package/dist/files/AssetFile.js +26 -0
  186. package/dist/files/AssetFile.js.map +1 -0
  187. package/dist/files/BrsFile.Class.spec.js +529 -486
  188. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  189. package/dist/files/BrsFile.d.ts +124 -112
  190. package/dist/files/BrsFile.js +819 -1131
  191. package/dist/files/BrsFile.js.map +1 -1
  192. package/dist/files/BrsFile.spec.js +1869 -1277
  193. package/dist/files/BrsFile.spec.js.map +1 -1
  194. package/dist/files/BscFile.d.ts +104 -0
  195. package/dist/files/BscFile.js +16 -0
  196. package/dist/files/BscFile.js.map +1 -0
  197. package/dist/files/Factory.d.ts +25 -0
  198. package/dist/files/Factory.js +22 -0
  199. package/dist/files/Factory.js.map +1 -0
  200. package/dist/files/LazyFileData.d.ts +20 -0
  201. package/dist/files/LazyFileData.js +54 -0
  202. package/dist/files/LazyFileData.js.map +1 -0
  203. package/dist/files/LazyFileData.spec.d.ts +1 -0
  204. package/dist/files/LazyFileData.spec.js +27 -0
  205. package/dist/files/LazyFileData.spec.js.map +1 -0
  206. package/dist/files/XmlFile.d.ts +70 -32
  207. package/dist/files/XmlFile.js +106 -117
  208. package/dist/files/XmlFile.js.map +1 -1
  209. package/dist/files/XmlFile.spec.js +325 -262
  210. package/dist/files/XmlFile.spec.js.map +1 -1
  211. package/dist/files/tests/imports.spec.js +49 -41
  212. package/dist/files/tests/imports.spec.js.map +1 -1
  213. package/dist/files/tests/optionalChaning.spec.js +104 -40
  214. package/dist/files/tests/optionalChaning.spec.js.map +1 -1
  215. package/dist/globalCallables.js +16 -18
  216. package/dist/globalCallables.js.map +1 -1
  217. package/dist/index.d.ts +13 -2
  218. package/dist/index.js +15 -2
  219. package/dist/index.js.map +1 -1
  220. package/dist/interfaces.d.ts +440 -150
  221. package/dist/interfaces.js +27 -0
  222. package/dist/interfaces.js.map +1 -1
  223. package/dist/lexer/Character.spec.js +5 -5
  224. package/dist/lexer/Character.spec.js.map +1 -1
  225. package/dist/lexer/Lexer.d.ts +12 -5
  226. package/dist/lexer/Lexer.js +28 -13
  227. package/dist/lexer/Lexer.js.map +1 -1
  228. package/dist/lexer/Lexer.spec.js +187 -134
  229. package/dist/lexer/Lexer.spec.js.map +1 -1
  230. package/dist/lexer/Token.d.ts +9 -1
  231. package/dist/lexer/Token.js +9 -1
  232. package/dist/lexer/Token.js.map +1 -1
  233. package/dist/lexer/TokenKind.d.ts +9 -0
  234. package/dist/lexer/TokenKind.js +30 -5
  235. package/dist/lexer/TokenKind.js.map +1 -1
  236. package/dist/parser/AstNode.d.ts +162 -0
  237. package/dist/parser/AstNode.js +225 -0
  238. package/dist/parser/AstNode.js.map +1 -0
  239. package/dist/parser/AstNode.spec.d.ts +1 -0
  240. package/dist/parser/AstNode.spec.js +165 -0
  241. package/dist/parser/AstNode.spec.js.map +1 -0
  242. package/dist/parser/BrsTranspileState.d.ts +4 -7
  243. package/dist/parser/BrsTranspileState.js +4 -12
  244. package/dist/parser/BrsTranspileState.js.map +1 -1
  245. package/dist/parser/Expression.d.ts +126 -167
  246. package/dist/parser/Expression.js +524 -394
  247. package/dist/parser/Expression.js.map +1 -1
  248. package/dist/parser/Parser.Class.spec.js +152 -146
  249. package/dist/parser/Parser.Class.spec.js.map +1 -1
  250. package/dist/parser/Parser.d.ts +45 -196
  251. package/dist/parser/Parser.js +470 -926
  252. package/dist/parser/Parser.js.map +1 -1
  253. package/dist/parser/Parser.spec.d.ts +3 -1
  254. package/dist/parser/Parser.spec.js +1034 -805
  255. package/dist/parser/Parser.spec.js.map +1 -1
  256. package/dist/parser/SGParser.d.ts +9 -8
  257. package/dist/parser/SGParser.js +10 -8
  258. package/dist/parser/SGParser.js.map +1 -1
  259. package/dist/parser/SGParser.spec.js +27 -38
  260. package/dist/parser/SGParser.spec.js.map +1 -1
  261. package/dist/parser/SGTypes.d.ts +98 -35
  262. package/dist/parser/SGTypes.js +169 -99
  263. package/dist/parser/SGTypes.js.map +1 -1
  264. package/dist/parser/Statement.d.ts +208 -122
  265. package/dist/parser/Statement.js +599 -364
  266. package/dist/parser/Statement.js.map +1 -1
  267. package/dist/parser/Statement.spec.js +45 -21
  268. package/dist/parser/Statement.spec.js.map +1 -1
  269. package/dist/parser/TranspileState.d.ts +1 -1
  270. package/dist/parser/TranspileState.js +7 -12
  271. package/dist/parser/TranspileState.js.map +1 -1
  272. package/dist/parser/tests/Parser.spec.js +3 -2
  273. package/dist/parser/tests/Parser.spec.js.map +1 -1
  274. package/dist/parser/tests/controlFlow/For.spec.js +33 -23
  275. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  276. package/dist/parser/tests/controlFlow/ForEach.spec.js +25 -20
  277. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  278. package/dist/parser/tests/controlFlow/If.spec.js +96 -94
  279. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  280. package/dist/parser/tests/controlFlow/While.spec.js +22 -16
  281. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  282. package/dist/parser/tests/expression/Additive.spec.js +8 -8
  283. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  284. package/dist/parser/tests/expression/ArrayLiterals.spec.js +58 -21
  285. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  286. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +61 -20
  287. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  288. package/dist/parser/tests/expression/Boolean.spec.js +8 -8
  289. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  290. package/dist/parser/tests/expression/Call.spec.js +129 -21
  291. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  292. package/dist/parser/tests/expression/Exponential.spec.js +5 -5
  293. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  294. package/dist/parser/tests/expression/Function.spec.js +36 -36
  295. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  296. package/dist/parser/tests/expression/Indexing.spec.js +67 -22
  297. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  298. package/dist/parser/tests/expression/Multiplicative.spec.js +9 -9
  299. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  300. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +123 -81
  301. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  302. package/dist/parser/tests/expression/PrefixUnary.spec.js +12 -12
  303. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  304. package/dist/parser/tests/expression/Primary.spec.js +12 -12
  305. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  306. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +10 -10
  307. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
  308. package/dist/parser/tests/expression/Relational.spec.js +13 -13
  309. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  310. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +24 -24
  311. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  312. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +221 -81
  313. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  314. package/dist/parser/tests/expression/TernaryExpression.spec.js +287 -105
  315. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  316. package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
  317. package/dist/parser/tests/expression/TypeExpression.spec.js +127 -0
  318. package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
  319. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
  320. package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
  321. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
  322. package/dist/parser/tests/statement/AssignmentOperators.spec.js +15 -15
  323. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  324. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
  325. package/dist/parser/tests/statement/ConstStatement.spec.js +262 -0
  326. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
  327. package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
  328. package/dist/parser/tests/statement/Continue.spec.js +119 -0
  329. package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
  330. package/dist/parser/tests/statement/Declaration.spec.js +19 -19
  331. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  332. package/dist/parser/tests/statement/Dim.spec.js +22 -22
  333. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  334. package/dist/parser/tests/statement/Enum.spec.js +111 -300
  335. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  336. package/dist/parser/tests/statement/For.spec.js +9 -10
  337. package/dist/parser/tests/statement/For.spec.js.map +1 -1
  338. package/dist/parser/tests/statement/ForEach.spec.js +8 -9
  339. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
  340. package/dist/parser/tests/statement/Function.spec.js +44 -35
  341. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  342. package/dist/parser/tests/statement/Goto.spec.js +5 -5
  343. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  344. package/dist/parser/tests/statement/Increment.spec.js +20 -20
  345. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  346. package/dist/parser/tests/statement/InterfaceStatement.spec.js +30 -196
  347. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
  348. package/dist/parser/tests/statement/LibraryStatement.spec.js +11 -11
  349. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  350. package/dist/parser/tests/statement/Misc.spec.js +16 -78
  351. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  352. package/dist/parser/tests/statement/PrintStatement.spec.js +107 -90
  353. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  354. package/dist/parser/tests/statement/ReturnStatement.spec.js +14 -12
  355. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  356. package/dist/parser/tests/statement/Set.spec.js +48 -35
  357. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  358. package/dist/parser/tests/statement/Stop.spec.js +6 -6
  359. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  360. package/dist/parser/tests/statement/Throw.spec.js +6 -6
  361. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  362. package/dist/parser/tests/statement/TryCatch.spec.js +18 -16
  363. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  364. package/dist/preprocessor/Manifest.d.ts +1 -1
  365. package/dist/preprocessor/Manifest.js +3 -3
  366. package/dist/preprocessor/Manifest.js.map +1 -1
  367. package/dist/preprocessor/Manifest.spec.js +8 -8
  368. package/dist/preprocessor/Manifest.spec.js.map +1 -1
  369. package/dist/preprocessor/Preprocessor.d.ts +5 -6
  370. package/dist/preprocessor/Preprocessor.js +15 -11
  371. package/dist/preprocessor/Preprocessor.js.map +1 -1
  372. package/dist/preprocessor/Preprocessor.spec.js +25 -25
  373. package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
  374. package/dist/preprocessor/PreprocessorParser.d.ts +1 -1
  375. package/dist/preprocessor/PreprocessorParser.js +7 -1
  376. package/dist/preprocessor/PreprocessorParser.js.map +1 -1
  377. package/dist/preprocessor/PreprocessorParser.spec.js +13 -13
  378. package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
  379. package/dist/roku-types/data.json +6544 -10519
  380. package/dist/roku-types/index.d.ts +662 -1934
  381. package/dist/types/ArrayType.d.ts +10 -9
  382. package/dist/types/ArrayType.js +65 -60
  383. package/dist/types/ArrayType.js.map +1 -1
  384. package/dist/types/ArrayType.spec.js +36 -68
  385. package/dist/types/ArrayType.spec.js.map +1 -1
  386. package/dist/types/AssociativeArrayType.d.ts +11 -0
  387. package/dist/types/AssociativeArrayType.js +52 -0
  388. package/dist/types/AssociativeArrayType.js.map +1 -0
  389. package/dist/types/BaseFunctionType.d.ts +9 -0
  390. package/dist/types/BaseFunctionType.js +25 -0
  391. package/dist/types/BaseFunctionType.js.map +1 -0
  392. package/dist/types/BooleanType.d.ts +8 -5
  393. package/dist/types/BooleanType.js +14 -7
  394. package/dist/types/BooleanType.js.map +1 -1
  395. package/dist/types/BooleanType.spec.js +10 -6
  396. package/dist/types/BooleanType.spec.js.map +1 -1
  397. package/dist/types/BscType.d.ts +32 -21
  398. package/dist/types/BscType.js +118 -21
  399. package/dist/types/BscType.js.map +1 -1
  400. package/dist/types/BscTypeKind.d.ts +25 -0
  401. package/dist/types/BscTypeKind.js +30 -0
  402. package/dist/types/BscTypeKind.js.map +1 -0
  403. package/dist/types/BuiltInInterfaceAdder.d.ts +23 -0
  404. package/dist/types/BuiltInInterfaceAdder.js +164 -0
  405. package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
  406. package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
  407. package/dist/types/BuiltInInterfaceAdder.spec.js +116 -0
  408. package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
  409. package/dist/types/ClassType.d.ts +17 -0
  410. package/dist/types/ClassType.js +58 -0
  411. package/dist/types/ClassType.js.map +1 -0
  412. package/dist/types/ClassType.spec.d.ts +1 -0
  413. package/dist/types/ClassType.spec.js +77 -0
  414. package/dist/types/ClassType.spec.js.map +1 -0
  415. package/dist/types/ComponentType.d.ts +26 -0
  416. package/dist/types/ComponentType.js +83 -0
  417. package/dist/types/ComponentType.js.map +1 -0
  418. package/dist/types/DoubleType.d.ts +8 -5
  419. package/dist/types/DoubleType.js +18 -16
  420. package/dist/types/DoubleType.js.map +1 -1
  421. package/dist/types/DoubleType.spec.js +12 -6
  422. package/dist/types/DoubleType.spec.js.map +1 -1
  423. package/dist/types/DynamicType.d.ts +10 -5
  424. package/dist/types/DynamicType.js +16 -4
  425. package/dist/types/DynamicType.js.map +1 -1
  426. package/dist/types/DynamicType.spec.js +16 -5
  427. package/dist/types/DynamicType.spec.js.map +1 -1
  428. package/dist/types/EnumType.d.ts +30 -12
  429. package/dist/types/EnumType.js +43 -17
  430. package/dist/types/EnumType.js.map +1 -1
  431. package/dist/types/EnumType.spec.d.ts +1 -0
  432. package/dist/types/EnumType.spec.js +33 -0
  433. package/dist/types/EnumType.spec.js.map +1 -0
  434. package/dist/types/FloatType.d.ts +8 -5
  435. package/dist/types/FloatType.js +18 -16
  436. package/dist/types/FloatType.js.map +1 -1
  437. package/dist/types/FloatType.spec.js +4 -6
  438. package/dist/types/FloatType.spec.js.map +1 -1
  439. package/dist/types/FunctionType.d.ts +13 -8
  440. package/dist/types/FunctionType.js +30 -14
  441. package/dist/types/FunctionType.js.map +1 -1
  442. package/dist/types/InheritableType.d.ts +28 -0
  443. package/dist/types/InheritableType.js +152 -0
  444. package/dist/types/InheritableType.js.map +1 -0
  445. package/dist/types/IntegerType.d.ts +8 -5
  446. package/dist/types/IntegerType.js +18 -16
  447. package/dist/types/IntegerType.js.map +1 -1
  448. package/dist/types/IntegerType.spec.js +8 -6
  449. package/dist/types/IntegerType.spec.js.map +1 -1
  450. package/dist/types/InterfaceType.d.ts +12 -13
  451. package/dist/types/InterfaceType.js +20 -48
  452. package/dist/types/InterfaceType.js.map +1 -1
  453. package/dist/types/InterfaceType.spec.js +90 -56
  454. package/dist/types/InterfaceType.spec.js.map +1 -1
  455. package/dist/types/InvalidType.d.ts +7 -5
  456. package/dist/types/InvalidType.js +13 -7
  457. package/dist/types/InvalidType.js.map +1 -1
  458. package/dist/types/InvalidType.spec.js +8 -6
  459. package/dist/types/InvalidType.spec.js.map +1 -1
  460. package/dist/types/LongIntegerType.d.ts +8 -5
  461. package/dist/types/LongIntegerType.js +17 -15
  462. package/dist/types/LongIntegerType.js.map +1 -1
  463. package/dist/types/LongIntegerType.spec.js +10 -6
  464. package/dist/types/LongIntegerType.spec.js.map +1 -1
  465. package/dist/types/NamespaceType.d.ts +12 -0
  466. package/dist/types/NamespaceType.js +28 -0
  467. package/dist/types/NamespaceType.js.map +1 -0
  468. package/dist/types/ObjectType.d.ts +9 -8
  469. package/dist/types/ObjectType.js +21 -11
  470. package/dist/types/ObjectType.js.map +1 -1
  471. package/dist/types/ObjectType.spec.js +3 -3
  472. package/dist/types/ObjectType.spec.js.map +1 -1
  473. package/dist/types/ReferenceType.d.ts +63 -0
  474. package/dist/types/ReferenceType.js +423 -0
  475. package/dist/types/ReferenceType.js.map +1 -0
  476. package/dist/types/ReferenceType.spec.d.ts +1 -0
  477. package/dist/types/ReferenceType.spec.js +137 -0
  478. package/dist/types/ReferenceType.spec.js.map +1 -0
  479. package/dist/types/StringType.d.ts +11 -5
  480. package/dist/types/StringType.js +18 -7
  481. package/dist/types/StringType.js.map +1 -1
  482. package/dist/types/StringType.spec.js +3 -5
  483. package/dist/types/StringType.spec.js.map +1 -1
  484. package/dist/types/TypedFunctionType.d.ts +22 -17
  485. package/dist/types/TypedFunctionType.js +78 -60
  486. package/dist/types/TypedFunctionType.js.map +1 -1
  487. package/dist/types/TypedFunctionType.spec.js +105 -20
  488. package/dist/types/TypedFunctionType.spec.js.map +1 -1
  489. package/dist/types/UninitializedType.d.ts +8 -6
  490. package/dist/types/UninitializedType.js +13 -7
  491. package/dist/types/UninitializedType.js.map +1 -1
  492. package/dist/types/UnionType.d.ts +20 -0
  493. package/dist/types/UnionType.js +123 -0
  494. package/dist/types/UnionType.js.map +1 -0
  495. package/dist/types/UnionType.spec.d.ts +1 -0
  496. package/dist/types/UnionType.spec.js +130 -0
  497. package/dist/types/UnionType.spec.js.map +1 -0
  498. package/dist/types/VoidType.d.ts +8 -5
  499. package/dist/types/VoidType.js +14 -7
  500. package/dist/types/VoidType.js.map +1 -1
  501. package/dist/types/VoidType.spec.js +3 -3
  502. package/dist/types/VoidType.spec.js.map +1 -1
  503. package/dist/types/helper.spec.d.ts +1 -0
  504. package/dist/types/helper.spec.js +145 -0
  505. package/dist/types/helper.spec.js.map +1 -0
  506. package/dist/types/helpers.d.ts +19 -37
  507. package/dist/types/helpers.js +159 -99
  508. package/dist/types/helpers.js.map +1 -1
  509. package/dist/types/index.d.ts +22 -0
  510. package/dist/types/index.js +39 -0
  511. package/dist/types/index.js.map +1 -0
  512. package/dist/util.d.ts +167 -131
  513. package/dist/util.js +890 -350
  514. package/dist/util.js.map +1 -1
  515. package/dist/validators/ClassValidator.d.ts +7 -25
  516. package/dist/validators/ClassValidator.js +103 -194
  517. package/dist/validators/ClassValidator.js.map +1 -1
  518. package/package.json +165 -149
  519. package/dist/astUtils/AstEditor.js.map +0 -1
  520. package/dist/astUtils/AstEditor.spec.js.map +0 -1
  521. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +0 -8
  522. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +0 -40
  523. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +0 -1
  524. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -32
  525. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
  526. package/dist/parser/SGTypes.spec.js +0 -351
  527. package/dist/parser/SGTypes.spec.js.map +0 -1
  528. package/dist/types/CustomType.d.ts +0 -12
  529. package/dist/types/CustomType.js +0 -44
  530. package/dist/types/CustomType.js.map +0 -1
  531. package/dist/types/LazyType.d.ts +0 -16
  532. package/dist/types/LazyType.js +0 -44
  533. package/dist/types/LazyType.js.map +0 -1
  534. /package/dist/astUtils/{AstEditor.spec.d.ts → Editor.spec.d.ts} +0 -0
  535. /package/dist/bscPlugin/{transpile/BrsFilePreTranspileProcessor.spec.d.ts → completions/CompletionsProcessor.spec.d.ts} +0 -0
  536. /package/dist/{parser/SGTypes.spec.d.ts → bscPlugin/hover/HoverProcessor.spec.d.ts} +0 -0
@@ -1,35 +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
13
  const TypedFunctionType_1 = require("../types/TypedFunctionType");
14
- const ObjectType_1 = require("../types/ObjectType");
15
- const ArrayType_1 = require("../types/ArrayType");
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
- exports.Expression = Expression;
26
- 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 {
27
26
  constructor(left, operator, right) {
28
27
  super();
29
28
  this.left = left;
30
29
  this.operator = operator;
31
30
  this.right = right;
32
- 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);
33
33
  }
34
34
  transpile(state) {
35
35
  return [
@@ -41,30 +41,41 @@ class BinaryExpression extends Expression {
41
41
  ];
42
42
  }
43
43
  walk(visitor, options) {
44
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
45
- (0, visitors_1.walk)(this, 'left', visitor, options);
46
- (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));
47
61
  }
62
+ return DynamicType_1.DynamicType.instance;
48
63
  }
49
64
  }
50
65
  exports.BinaryExpression = BinaryExpression;
51
- class CallExpression extends Expression {
66
+ class CallExpression extends AstNode_1.Expression {
52
67
  constructor(callee,
53
68
  /**
54
69
  * Can either be `(`, or `?(` for optional chaining
55
70
  */
56
- openingParen, closingParen, args,
57
- /**
58
- * 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.
59
- */
60
- namespaceName) {
71
+ openingParen, closingParen, args, unused) {
61
72
  super();
62
73
  this.callee = callee;
63
74
  this.openingParen = openingParen;
64
75
  this.closingParen = closingParen;
65
76
  this.args = args;
66
- this.namespaceName = namespaceName;
67
- 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);
68
79
  }
69
80
  transpile(state, nameOverride) {
70
81
  let result = [];
@@ -84,24 +95,39 @@ class CallExpression extends Expression {
84
95
  let arg = this.args[i];
85
96
  result.push(...arg.transpile(state));
86
97
  }
87
- result.push(state.transpileToken(this.closingParen));
98
+ if (this.closingParen) {
99
+ result.push(state.transpileToken(this.closingParen));
100
+ }
88
101
  return result;
89
102
  }
90
103
  walk(visitor, options) {
91
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
92
- (0, visitors_1.walk)(this, 'callee', visitor, options);
93
- (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);
94
107
  }
95
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
+ }
96
126
  }
97
127
  exports.CallExpression = CallExpression;
98
- CallExpression.MaximumArguments = util_1.MAX_PARAM_COUNT;
99
- class FunctionExpression extends Expression {
100
- constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnType,
101
- /**
102
- * If this function is enclosed within another function, this will reference that parent function
103
- */
104
- parentFunction, namespaceName, parentSymbolTable) {
128
+ CallExpression.MaximumArguments = 32;
129
+ class FunctionExpression extends AstNode_1.Expression {
130
+ constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeExpression) {
105
131
  super();
106
132
  this.parameters = parameters;
107
133
  this.body = body;
@@ -110,60 +136,29 @@ class FunctionExpression extends Expression {
110
136
  this.leftParen = leftParen;
111
137
  this.rightParen = rightParen;
112
138
  this.asToken = asToken;
113
- this.returnType = returnType;
114
- this.parentFunction = parentFunction;
115
- this.namespaceName = namespaceName;
116
- this.parentSymbolTable = parentSymbolTable;
117
- this.labelStatements = [];
139
+ this.returnTypeExpression = returnTypeExpression;
140
+ this.kind = AstNode_1.AstNodeKind.FunctionExpression;
118
141
  /**
119
142
  * The list of function calls that are declared within this function scope. This excludes CallExpressions
120
143
  * declared in child functions
121
144
  */
122
145
  this.callExpressions = [];
123
- /**
124
- * A list of all child functions declared directly within this function
125
- */
126
- this.childFunctionExpressions = [];
127
- if (this.returnType) {
128
- this._returnType = this.returnType.type;
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`);
129
149
  }
130
- else if (this.functionType.text.toLowerCase() === 'sub') {
131
- this._returnType = new VoidType_1.VoidType();
132
- }
133
- else {
134
- this._returnType = new DynamicType_1.DynamicType();
135
- }
136
- this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
137
- for (let param of parameters) {
138
- this.symbolTable.addSymbol(param.name.text, param.name.range, param.getType());
139
- }
140
- }
141
- get range() {
142
- 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(); });
143
151
  }
144
- /**
145
- * The range of the function
146
- */
147
- cacheRange() {
148
- var _a;
149
- if (!this._range) {
150
- 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);
151
- }
152
- 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 : [];
153
155
  }
154
156
  /**
155
- * 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'
156
159
  */
157
- getReturnType() {
158
- return this._returnType;
159
- }
160
- /**
161
- * 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),
162
- * and ending with the last character in the returnTypeToken, or the 's' in 'as', or the rightParen
163
- */
164
- get functionDeclarationRange() {
165
- var _a;
166
- 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);
167
162
  }
168
163
  transpile(state, name, includeBody = true) {
169
164
  let results = [];
@@ -188,12 +183,12 @@ class FunctionExpression extends Expression {
188
183
  //right paren
189
184
  results.push(state.transpileToken(this.rightParen));
190
185
  //as [Type]
191
- if (this.asToken) {
186
+ if (this.asToken && !state.options.removeParameterTypes && this.returnTypeExpression) {
192
187
  results.push(' ',
193
188
  //as
194
189
  state.transpileToken(this.asToken), ' ',
195
190
  //return type
196
- state.sourceNode(this.returnType, this.getReturnType().toTypeString(state.typeContext)));
191
+ ...this.returnTypeExpression.transpile(state));
197
192
  }
198
193
  if (includeBody) {
199
194
  state.lineage.unshift(this);
@@ -201,52 +196,107 @@ class FunctionExpression extends Expression {
201
196
  state.lineage.shift();
202
197
  results.push(...body);
203
198
  }
204
- if (this.end) {
205
- results.push('\n');
206
- //'end sub'|'end function'
207
- results.push(state.indent(), state.transpileToken(this.end));
208
- }
199
+ results.push('\n');
200
+ //'end sub'|'end function'
201
+ results.push(state.indent(), state.transpileToken(this.end));
209
202
  return results;
210
203
  }
211
- getTypedef(state, name) {
212
- 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;
213
234
  }
214
235
  walk(visitor, options) {
215
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
216
- (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);
217
239
  //This is the core of full-program walking...it allows us to step into sub functions
218
- if (options.walkMode & visitors_1.InternalWalkMode.recurseChildFunctions) {
219
- (0, visitors_1.walk)(this, 'returnType', visitor, options);
220
- (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);
221
242
  }
222
243
  }
223
244
  }
224
- getFunctionType() {
225
- let functionType = new TypedFunctionType_1.TypedFunctionType(this.getReturnType());
226
- 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;
227
256
  for (let param of this.parameters) {
228
- 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);
270
+ }
271
+ if (funcName) {
272
+ resultType.setName(funcName);
229
273
  }
230
- return functionType;
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;
231
276
  }
232
277
  }
233
278
  exports.FunctionExpression = FunctionExpression;
234
- class FunctionParameterExpression extends Expression {
235
- constructor(name, typeInContext, equalsToken, defaultValue, asToken, type, namespaceName) {
279
+ class FunctionParameterExpression extends AstNode_1.Expression {
280
+ constructor(name, equalToken, defaultValue, asToken, typeExpression) {
236
281
  super();
237
282
  this.name = name;
238
- this.typeInContext = typeInContext;
239
- this.equalsToken = equalsToken;
283
+ this.equalToken = equalToken;
240
284
  this.defaultValue = defaultValue;
241
285
  this.asToken = asToken;
242
- this.type = type;
243
- this.namespaceName = namespaceName;
244
- 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;
245
288
  }
246
- getType() {
247
- return this.typeInContext;
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;
294
+ }
295
+ get range() {
296
+ return util_1.default.createBoundingRange(this.name, this.asToken, this.typeExpression, this.defaultValue);
248
297
  }
249
298
  transpile(state) {
299
+ var _a, _b;
250
300
  let result = [
251
301
  //name
252
302
  state.transpileToken(this.name)
@@ -257,70 +307,41 @@ class FunctionParameterExpression extends Expression {
257
307
  result.push(this.defaultValue.transpile(state));
258
308
  }
259
309
  //type declaration
260
- if (this.asToken) {
310
+ if (this.asToken && !state.options.removeParameterTypes) {
261
311
  result.push(' ');
262
312
  result.push(state.transpileToken(this.asToken));
263
313
  result.push(' ');
264
- 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 : []));
265
315
  }
266
316
  return result;
267
317
  }
268
- walk(visitor, options) {
269
- // eslint-disable-next-line no-bitwise
270
- if (this.defaultValue && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
271
- (0, visitors_1.walk)(this, 'defaultValue', visitor, options);
272
- (0, visitors_1.walk)(this, 'type', visitor, options);
273
- }
274
- }
275
- get isOptional() {
276
- return !!this.defaultValue;
277
- }
278
- }
279
- exports.FunctionParameterExpression = FunctionParameterExpression;
280
- class NamespacedVariableNameExpression extends Expression {
281
- constructor(
282
- //if this is a `DottedGetExpression`, it must be comprised only of `VariableExpression`s
283
- expression) {
284
- super();
285
- this.expression = expression;
286
- this.range = expression.range;
287
- }
288
- transpile(state) {
318
+ getTypedef(state) {
319
+ var _a, _b;
289
320
  return [
290
- 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
+ ] : [])
291
333
  ];
292
334
  }
293
- getNameParts() {
294
- let parts = [];
295
- if ((0, reflection_1.isVariableExpression)(this.expression)) {
296
- parts.push(this.expression.name.text);
297
- }
298
- else {
299
- let expr = this.expression;
300
- parts.push(expr.name.text);
301
- while ((0, reflection_1.isVariableExpression)(expr) === false) {
302
- expr = expr.obj;
303
- parts.unshift(expr.name.text);
304
- }
305
- }
306
- return parts;
307
- }
308
- getName(parseMode = Parser_1.ParseMode.BrighterScript) {
309
- if (parseMode === Parser_1.ParseMode.BrighterScript) {
310
- return this.getNameParts().join('.');
311
- }
312
- else {
313
- return this.getNameParts().join('_');
314
- }
315
- }
316
335
  walk(visitor, options) {
317
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
318
- (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);
319
340
  }
320
341
  }
321
342
  }
322
- exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
323
- class DottedGetExpression extends Expression {
343
+ exports.FunctionParameterExpression = FunctionParameterExpression;
344
+ class DottedGetExpression extends AstNode_1.Expression {
324
345
  constructor(obj, name,
325
346
  /**
326
347
  * Can either be `.`, or `?.` for optional chaining
@@ -330,12 +351,15 @@ class DottedGetExpression extends Expression {
330
351
  this.obj = obj;
331
352
  this.name = name;
332
353
  this.dot = dot;
354
+ this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
333
355
  this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
334
356
  }
335
357
  transpile(state) {
336
358
  //if the callee starts with a namespace name, transpile the name
337
359
  if (state.file.calleeStartsWithNamespace(this)) {
338
- return new NamespacedVariableNameExpression(this).transpile(state);
360
+ return [
361
+ state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
362
+ ];
339
363
  }
340
364
  else {
341
365
  return [
@@ -346,13 +370,29 @@ class DottedGetExpression extends Expression {
346
370
  }
347
371
  }
348
372
  walk(visitor, options) {
349
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
350
- (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;
351
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);
352
392
  }
353
393
  }
354
394
  exports.DottedGetExpression = DottedGetExpression;
355
- class XmlAttributeGetExpression extends Expression {
395
+ class XmlAttributeGetExpression extends AstNode_1.Expression {
356
396
  constructor(obj, name,
357
397
  /**
358
398
  * Can either be `@`, or `?@` for optional chaining
@@ -362,6 +402,7 @@ class XmlAttributeGetExpression extends Expression {
362
402
  this.obj = obj;
363
403
  this.name = name;
364
404
  this.at = at;
405
+ this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
365
406
  this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
366
407
  }
367
408
  transpile(state) {
@@ -372,13 +413,13 @@ class XmlAttributeGetExpression extends Expression {
372
413
  ];
373
414
  }
374
415
  walk(visitor, options) {
375
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
376
- (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);
377
418
  }
378
419
  }
379
420
  }
380
421
  exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
381
- class IndexedGetExpression extends Expression {
422
+ class IndexedGetExpression extends AstNode_1.Expression {
382
423
  constructor(obj, index,
383
424
  /**
384
425
  * Can either be `[` or `?[`. If `?.[` is used, this will be `[` and `optionalChainingToken` will be `?.`
@@ -391,33 +432,47 @@ class IndexedGetExpression extends Expression {
391
432
  this.openingSquare = openingSquare;
392
433
  this.closingSquare = closingSquare;
393
434
  this.questionDotToken = questionDotToken;
435
+ this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
394
436
  this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.questionDotToken, this.openingSquare, this.index, this.closingSquare);
395
437
  }
396
438
  transpile(state) {
439
+ var _a, _b;
397
440
  return [
398
441
  ...this.obj.transpile(state),
399
442
  this.questionDotToken ? state.transpileToken(this.questionDotToken) : '',
400
443
  state.transpileToken(this.openingSquare),
401
- ...this.index.transpile(state),
402
- 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) : ''
403
446
  ];
404
447
  }
405
448
  walk(visitor, options) {
406
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
407
- (0, visitors_1.walk)(this, 'obj', visitor, options);
408
- (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);
409
452
  }
410
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;
459
+ }
460
+ return super.getType(options);
461
+ }
411
462
  }
412
463
  exports.IndexedGetExpression = IndexedGetExpression;
413
- class GroupingExpression extends Expression {
464
+ class GroupingExpression extends AstNode_1.Expression {
414
465
  constructor(tokens, expression) {
415
466
  super();
416
467
  this.tokens = tokens;
417
468
  this.expression = expression;
469
+ this.kind = AstNode_1.AstNodeKind.GroupingExpression;
418
470
  this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
419
471
  }
420
472
  transpile(state) {
473
+ if ((0, reflection_1.isTypeCastExpression)(this.expression)) {
474
+ return this.expression.transpile(state);
475
+ }
421
476
  return [
422
477
  state.transpileToken(this.tokens.left),
423
478
  ...this.expression.transpile(state),
@@ -425,18 +480,26 @@ class GroupingExpression extends Expression {
425
480
  ];
426
481
  }
427
482
  walk(visitor, options) {
428
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
429
- (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);
430
485
  }
431
486
  }
487
+ getType(options) {
488
+ return this.expression.getType(options);
489
+ }
432
490
  }
433
491
  exports.GroupingExpression = GroupingExpression;
434
- class LiteralExpression extends Expression {
492
+ class LiteralExpression extends AstNode_1.Expression {
435
493
  constructor(token) {
436
494
  super();
437
495
  this.token = token;
438
- this.range = this.token.range;
439
- 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);
440
503
  }
441
504
  transpile(state) {
442
505
  let text;
@@ -444,7 +507,7 @@ class LiteralExpression extends Expression {
444
507
  //wrap quasis with quotes (and escape inner quotemarks)
445
508
  text = `"${this.token.text.replace(/"/g, '""')}"`;
446
509
  }
447
- else if ((0, reflection_1.isStringType)(this.type)) {
510
+ else if (this.token.kind === TokenKind_1.TokenKind.StringLiteral) {
448
511
  text = this.token.text;
449
512
  //add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
450
513
  if (text.endsWith('"') === false) {
@@ -467,10 +530,11 @@ exports.LiteralExpression = LiteralExpression;
467
530
  * This is a special expression only used within template strings. It exists so we can prevent producing lots of empty strings
468
531
  * during template string transpile by identifying these expressions explicitly and skipping the bslib_toString around them
469
532
  */
470
- class EscapedCharCodeLiteralExpression extends Expression {
533
+ class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
471
534
  constructor(token) {
472
535
  super();
473
536
  this.token = token;
537
+ this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
474
538
  this.range = token.range;
475
539
  }
476
540
  transpile(state) {
@@ -483,15 +547,15 @@ class EscapedCharCodeLiteralExpression extends Expression {
483
547
  }
484
548
  }
485
549
  exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
486
- class ArrayLiteralExpression extends Expression {
550
+ class ArrayLiteralExpression extends AstNode_1.Expression {
487
551
  constructor(elements, open, close, hasSpread = false) {
488
- var _a;
489
552
  super();
490
553
  this.elements = elements;
491
554
  this.open = open;
492
555
  this.close = close;
493
556
  this.hasSpread = hasSpread;
494
- 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);
495
559
  }
496
560
  transpile(state) {
497
561
  let result = [];
@@ -524,25 +588,31 @@ class ArrayLiteralExpression extends Expression {
524
588
  result.push('\n');
525
589
  result.push(state.indent());
526
590
  }
527
- result.push(state.transpileToken(this.close));
591
+ if (this.close) {
592
+ result.push(state.transpileToken(this.close));
593
+ }
528
594
  return result;
529
595
  }
530
596
  walk(visitor, options) {
531
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
532
- (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);
533
599
  }
534
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
+ }
535
605
  }
536
606
  exports.ArrayLiteralExpression = ArrayLiteralExpression;
537
- class AAMemberExpression extends Expression {
607
+ class AAMemberExpression extends AstNode_1.Expression {
538
608
  constructor(keyToken, colonToken,
539
609
  /** The expression evaluated to determine the member's initial value. */
540
- value, type) {
610
+ value) {
541
611
  super();
542
612
  this.keyToken = keyToken;
543
613
  this.colonToken = colonToken;
544
614
  this.value = value;
545
- this.type = type;
615
+ this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
546
616
  this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
547
617
  }
548
618
  transpile(state) {
@@ -550,31 +620,21 @@ class AAMemberExpression extends Expression {
550
620
  return [];
551
621
  }
552
622
  walk(visitor, options) {
553
- (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);
554
627
  }
555
628
  }
556
629
  exports.AAMemberExpression = AAMemberExpression;
557
- class AALiteralExpression extends Expression {
558
- constructor(elements, open, close, functionExpression) {
559
- var _a;
630
+ class AALiteralExpression extends AstNode_1.Expression {
631
+ constructor(elements, open, close) {
560
632
  super();
561
633
  this.elements = elements;
562
634
  this.open = open;
563
635
  this.close = close;
564
- this.functionExpression = functionExpression;
565
- this.symbolTable = new SymbolTable_1.SymbolTable();
566
- this.memberTable = new SymbolTable_1.SymbolTable();
567
- this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
568
- this.buildSymbolTable();
569
- }
570
- buildSymbolTable() {
571
- this.symbolTable.clear();
572
- this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType('object', this.memberTable));
573
- for (const element of this.elements) {
574
- if ((0, reflection_1.isAAMemberExpression)(element)) {
575
- this.memberTable.addSymbol(element.keyToken.text, element.keyToken.range, (0, Parser_1.getBscTypeFromExpression)(element.value, this.functionExpression));
576
- }
577
- }
636
+ this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
637
+ this.range = util_1.default.createBoundingRange(this.open, ...this.elements, this.close);
578
638
  }
579
639
  transpile(state) {
580
640
  let result = [];
@@ -625,54 +685,80 @@ class AALiteralExpression extends Expression {
625
685
  result.push(state.indent());
626
686
  }
627
687
  //close curly
628
- result.push(state.transpileToken(this.close));
688
+ if (this.close) {
689
+ result.push(state.transpileToken(this.close));
690
+ }
629
691
  return result;
630
692
  }
631
693
  walk(visitor, options) {
632
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
633
- (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
+ }
634
704
  }
705
+ return resultType;
635
706
  }
636
707
  }
637
708
  exports.AALiteralExpression = AALiteralExpression;
638
- class UnaryExpression extends Expression {
709
+ class UnaryExpression extends AstNode_1.Expression {
639
710
  constructor(operator, right) {
640
711
  super();
641
712
  this.operator = operator;
642
713
  this.right = right;
714
+ this.kind = AstNode_1.AstNodeKind.UnaryExpression;
643
715
  this.range = util_1.default.createBoundingRange(this.operator, this.right);
644
716
  }
645
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
+ }
646
728
  return [
647
729
  state.transpileToken(this.operator),
648
- ' ',
730
+ separatingWhitespace,
649
731
  ...this.right.transpile(state)
650
732
  ];
651
733
  }
652
734
  walk(visitor, options) {
653
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
654
- (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);
655
737
  }
656
738
  }
739
+ getType(options) {
740
+ return util_1.default.unaryOperatorResultType(this.operator, this.right.getType(options));
741
+ }
657
742
  }
658
743
  exports.UnaryExpression = UnaryExpression;
659
- class VariableExpression extends Expression {
660
- constructor(name, namespaceName) {
744
+ class VariableExpression extends AstNode_1.Expression {
745
+ constructor(name) {
746
+ var _a;
661
747
  super();
662
748
  this.name = name;
663
- this.namespaceName = namespaceName;
664
- 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;
665
751
  }
666
752
  getName(parseMode) {
667
- return parseMode === Parser_1.ParseMode.BrightScript ? this.name.text : this.name.text;
753
+ return this.name.text;
668
754
  }
669
755
  transpile(state) {
670
- var _a;
671
756
  let result = [];
757
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
672
758
  //if the callee is the name of a known namespace function
673
- 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))) {
674
760
  result.push(state.sourceNode(this, [
675
- this.namespaceName.getName(Parser_1.ParseMode.BrightScript),
761
+ namespace.getName(Parser_1.ParseMode.BrightScript),
676
762
  '_',
677
763
  this.getName(Parser_1.ParseMode.BrightScript)
678
764
  ]));
@@ -686,24 +772,54 @@ class VariableExpression extends Expression {
686
772
  walk(visitor, options) {
687
773
  //nothing to walk
688
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
+ }
689
786
  }
690
787
  exports.VariableExpression = VariableExpression;
691
- class SourceLiteralExpression extends Expression {
788
+ class SourceLiteralExpression extends AstNode_1.Expression {
692
789
  constructor(token) {
693
790
  super();
694
791
  this.token = token;
695
- 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;
696
811
  }
697
812
  getFunctionName(state, parseMode) {
698
- let functionExpression = state.file.getFunctionExpressionAtPosition(this.token.range.start);
813
+ let func = state.file.getFunctionScopeAtPosition(this.token.range.start).func;
699
814
  let nameParts = [];
700
- while (functionExpression.parentFunction) {
701
- 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);
702
818
  nameParts.unshift(`anon${index}`);
703
- functionExpression = functionExpression.parentFunction;
819
+ func = parentFunction;
704
820
  }
705
821
  //get the index of this function in its parent
706
- nameParts.unshift(functionExpression.functionStatement.getName(parseMode));
822
+ nameParts.unshift(func.functionStatement.getName(parseMode));
707
823
  return nameParts.join('$');
708
824
  }
709
825
  transpile(state) {
@@ -727,10 +843,10 @@ class SourceLiteralExpression extends Expression {
727
843
  text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
728
844
  break;
729
845
  case TokenKind_1.TokenKind.PkgPathLiteral:
730
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}"`;
846
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
731
847
  break;
732
848
  case TokenKind_1.TokenKind.PkgLocationLiteral:
733
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}:" + str(LINE_NUM)`;
849
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}:" + str(LINE_NUM)`;
734
850
  break;
735
851
  case TokenKind_1.TokenKind.LineNumLiteral:
736
852
  default:
@@ -752,11 +868,12 @@ exports.SourceLiteralExpression = SourceLiteralExpression;
752
868
  * except we need to uniquely identify these statements so we can
753
869
  * do more type checking.
754
870
  */
755
- class NewExpression extends Expression {
871
+ class NewExpression extends AstNode_1.Expression {
756
872
  constructor(newKeyword, call) {
757
873
  super();
758
874
  this.newKeyword = newKeyword;
759
875
  this.call = call;
876
+ this.kind = AstNode_1.AstNodeKind.NewExpression;
760
877
  this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
761
878
  }
762
879
  /**
@@ -764,29 +881,29 @@ class NewExpression extends Expression {
764
881
  */
765
882
  get className() {
766
883
  //the parser guarantees the callee of a new statement's call object will be
767
- //a NamespacedVariableNameExpression
884
+ //either a VariableExpression or a DottedGet
768
885
  return this.call.callee;
769
886
  }
770
- get namespaceName() {
771
- return this.call.namespaceName;
772
- }
773
887
  transpile(state) {
774
- var _a, _b;
775
- 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;
776
891
  //new statements within a namespace block can omit the leading namespace if the class resides in that same namespace.
777
892
  //So we need to figure out if this is a namespace-omitted class, or if this class exists without a namespace.
778
893
  return this.call.transpile(state, cls === null || cls === void 0 ? void 0 : cls.getName(Parser_1.ParseMode.BrightScript));
779
894
  }
780
895
  walk(visitor, options) {
781
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
782
- (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);
783
898
  }
784
899
  }
900
+ getType(options) {
901
+ return this.call.getType(options);
902
+ }
785
903
  }
786
904
  exports.NewExpression = NewExpression;
787
- class CallfuncExpression extends Expression {
905
+ class CallfuncExpression extends AstNode_1.Expression {
788
906
  constructor(callee, operator, methodName, openingParen, args, closingParen) {
789
- var _a;
790
907
  super();
791
908
  this.callee = callee;
792
909
  this.operator = operator;
@@ -794,7 +911,8 @@ class CallfuncExpression extends Expression {
794
911
  this.openingParen = openingParen;
795
912
  this.args = args;
796
913
  this.closingParen = closingParen;
797
- 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);
798
916
  }
799
917
  transpile(state) {
800
918
  let result = [];
@@ -820,10 +938,37 @@ class CallfuncExpression extends Expression {
820
938
  return result;
821
939
  }
822
940
  walk(visitor, options) {
823
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
824
- (0, visitors_1.walk)(this, 'callee', visitor, options);
825
- (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
+ */
826
970
  }
971
+ return result;
827
972
  }
828
973
  }
829
974
  exports.CallfuncExpression = CallfuncExpression;
@@ -831,12 +976,12 @@ exports.CallfuncExpression = CallfuncExpression;
831
976
  * Since template strings can contain newlines, we need to concatenate multiple strings together with chr() calls.
832
977
  * This is a single expression that represents the string contatenation of all parts of a single quasi.
833
978
  */
834
- class TemplateStringQuasiExpression extends Expression {
979
+ class TemplateStringQuasiExpression extends AstNode_1.Expression {
835
980
  constructor(expressions) {
836
- var _a;
837
981
  super();
838
982
  this.expressions = expressions;
839
- 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);
840
985
  }
841
986
  transpile(state, skipEmptyStrings = true) {
842
987
  let result = [];
@@ -853,28 +998,30 @@ class TemplateStringQuasiExpression extends Expression {
853
998
  return result;
854
999
  }
855
1000
  walk(visitor, options) {
856
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
857
- (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);
858
1003
  }
859
1004
  }
860
1005
  }
861
1006
  exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
862
- class TemplateStringExpression extends Expression {
1007
+ class TemplateStringExpression extends AstNode_1.Expression {
863
1008
  constructor(openingBacktick, quasis, expressions, closingBacktick) {
864
- var _a;
865
1009
  super();
866
1010
  this.openingBacktick = openingBacktick;
867
1011
  this.quasis = quasis;
868
1012
  this.expressions = expressions;
869
1013
  this.closingBacktick = closingBacktick;
870
- //the expression always starts and ends with a quasi, so we don't need to consider the expression locations
871
- 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;
872
1019
  }
873
1020
  transpile(state) {
874
1021
  if (this.quasis.length === 1 && this.expressions.length === 0) {
875
1022
  return this.quasis[0].transpile(state);
876
1023
  }
877
- let result = [];
1024
+ let result = ['('];
878
1025
  let plus = '';
879
1026
  //helper function to figure out when to include the plus
880
1027
  function add(...items) {
@@ -893,7 +1040,7 @@ class TemplateStringExpression extends Expression {
893
1040
  if (expression) {
894
1041
  //skip the toString wrapper around certain expressions
895
1042
  if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
896
- ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.type))) {
1043
+ ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.getType()))) {
897
1044
  add(...expression.transpile(state));
898
1045
  //wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
899
1046
  }
@@ -902,33 +1049,34 @@ class TemplateStringExpression extends Expression {
902
1049
  }
903
1050
  }
904
1051
  }
1052
+ //the expression should be wrapped in parens so it can be used line a single expression at runtime
1053
+ result.push(')');
905
1054
  return result;
906
1055
  }
907
1056
  walk(visitor, options) {
908
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1057
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
909
1058
  //walk the quasis and expressions in left-to-right order
910
1059
  for (let i = 0; i < this.quasis.length; i++) {
911
- (0, visitors_1.walk)(this.quasis, i, visitor, options, this);
1060
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
912
1061
  //this skips the final loop iteration since we'll always have one more quasi than expression
913
1062
  if (this.expressions[i]) {
914
- (0, visitors_1.walk)(this.expressions, i, visitor, options, this);
1063
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
915
1064
  }
916
1065
  }
917
1066
  }
918
1067
  }
919
1068
  }
920
1069
  exports.TemplateStringExpression = TemplateStringExpression;
921
- class TaggedTemplateStringExpression extends Expression {
1070
+ class TaggedTemplateStringExpression extends AstNode_1.Expression {
922
1071
  constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
923
- var _a;
924
1072
  super();
925
1073
  this.tagName = tagName;
926
1074
  this.openingBacktick = openingBacktick;
927
1075
  this.quasis = quasis;
928
1076
  this.expressions = expressions;
929
1077
  this.closingBacktick = closingBacktick;
930
- //the expression always starts and ends with a quasi, so we don't need to consider the expression locations
931
- 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);
932
1080
  }
933
1081
  transpile(state) {
934
1082
  let result = [];
@@ -955,34 +1103,29 @@ class TaggedTemplateStringExpression extends Expression {
955
1103
  return result;
956
1104
  }
957
1105
  walk(visitor, options) {
958
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1106
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
959
1107
  //walk the quasis and expressions in left-to-right order
960
1108
  for (let i = 0; i < this.quasis.length; i++) {
961
- (0, visitors_1.walk)(this.quasis, i, visitor, options, this);
1109
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
962
1110
  //this skips the final loop iteration since we'll always have one more quasi than expression
963
1111
  if (this.expressions[i]) {
964
- (0, visitors_1.walk)(this.expressions, i, visitor, options, this);
1112
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
965
1113
  }
966
1114
  }
967
1115
  }
968
1116
  }
969
1117
  }
970
1118
  exports.TaggedTemplateStringExpression = TaggedTemplateStringExpression;
971
- class AnnotationExpression extends Expression {
1119
+ class AnnotationExpression extends AstNode_1.Expression {
972
1120
  constructor(atToken, nameToken) {
973
1121
  super();
974
1122
  this.atToken = atToken;
975
1123
  this.nameToken = nameToken;
1124
+ this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
976
1125
  this.name = nameToken.text;
977
1126
  }
978
1127
  get range() {
979
- return this.cacheRange();
980
- }
981
- cacheRange() {
982
- if (!this._range) {
983
- this._range = util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
984
- }
985
- return this._range;
1128
+ return util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
986
1129
  }
987
1130
  /**
988
1131
  * Convert annotation arguments to JavaScript types
@@ -994,6 +1137,9 @@ class AnnotationExpression extends Expression {
994
1137
  }
995
1138
  return this.call.args.map(e => expressionToValue(e, strict));
996
1139
  }
1140
+ getLeadingTrivia() {
1141
+ return this.atToken.leadingTrivia;
1142
+ }
997
1143
  transpile(state) {
998
1144
  return [];
999
1145
  }
@@ -1010,7 +1156,7 @@ class AnnotationExpression extends Expression {
1010
1156
  }
1011
1157
  }
1012
1158
  exports.AnnotationExpression = AnnotationExpression;
1013
- class TernaryExpression extends Expression {
1159
+ class TernaryExpression extends AstNode_1.Expression {
1014
1160
  constructor(test, questionMarkToken, consequent, colonToken, alternate) {
1015
1161
  super();
1016
1162
  this.test = test;
@@ -1018,7 +1164,8 @@ class TernaryExpression extends Expression {
1018
1164
  this.consequent = consequent;
1019
1165
  this.colonToken = colonToken;
1020
1166
  this.alternate = alternate;
1021
- 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);
1022
1169
  }
1023
1170
  transpile(state) {
1024
1171
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
@@ -1046,21 +1193,22 @@ class TernaryExpression extends Expression {
1046
1193
  return result;
1047
1194
  }
1048
1195
  walk(visitor, options) {
1049
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1050
- (0, visitors_1.walk)(this, 'test', visitor, options);
1051
- (0, visitors_1.walk)(this, 'consequent', visitor, options);
1052
- (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);
1053
1200
  }
1054
1201
  }
1055
1202
  }
1056
1203
  exports.TernaryExpression = TernaryExpression;
1057
- class NullCoalescingExpression extends Expression {
1204
+ class NullCoalescingExpression extends AstNode_1.Expression {
1058
1205
  constructor(consequent, questionQuestionToken, alternate) {
1059
1206
  super();
1060
1207
  this.consequent = consequent;
1061
1208
  this.questionQuestionToken = questionQuestionToken;
1062
1209
  this.alternate = alternate;
1063
- 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);
1064
1212
  }
1065
1213
  transpile(state) {
1066
1214
  let result = [];
@@ -1089,18 +1237,22 @@ class NullCoalescingExpression extends Expression {
1089
1237
  return result;
1090
1238
  }
1091
1239
  walk(visitor, options) {
1092
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1093
- (0, visitors_1.walk)(this, 'consequent', visitor, options);
1094
- (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);
1095
1243
  }
1096
1244
  }
1097
1245
  }
1098
1246
  exports.NullCoalescingExpression = NullCoalescingExpression;
1099
- class RegexLiteralExpression extends Expression {
1247
+ class RegexLiteralExpression extends AstNode_1.Expression {
1100
1248
  constructor(tokens) {
1101
1249
  super();
1102
1250
  this.tokens = tokens;
1103
- 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;
1104
1256
  }
1105
1257
  transpile(state) {
1106
1258
  var _a, _b;
@@ -1131,109 +1283,6 @@ class RegexLiteralExpression extends Expression {
1131
1283
  }
1132
1284
  }
1133
1285
  exports.RegexLiteralExpression = RegexLiteralExpression;
1134
- class TypeExpression extends Expression {
1135
- constructor(tokens, namespaceName) {
1136
- super();
1137
- this.tokens = tokens;
1138
- this.namespaceName = namespaceName;
1139
- this.range = util_1.default.createBoundingRange(this.tokens.type);
1140
- }
1141
- /**
1142
- * The this TypeExpression refers to
1143
- */
1144
- get type() {
1145
- if (this._type) {
1146
- return this._type;
1147
- }
1148
- this._type = this.getType(Parser_1.ParseMode.BrighterScript);
1149
- return this._type;
1150
- }
1151
- /**
1152
- * Derive a BscType from the type token
1153
- * Can deal with multiple brackets to make multidimensional arrays, eg. float[][]
1154
- * Defaults to `DynamicType`
1155
- */
1156
- getType(parseMode = Parser_1.ParseMode.BrighterScript) {
1157
- let exprType = this.tokens.type
1158
- ? util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName)
1159
- : new DynamicType_1.DynamicType();
1160
- return exprType;
1161
- }
1162
- /**
1163
- * Is this a valid, (eg. known) type?
1164
- */
1165
- isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
1166
- return !!util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName);
1167
- }
1168
- /**
1169
- * Gives a human readable string that says the type
1170
- * @returns text to display to show the type
1171
- */
1172
- getText() {
1173
- let result = this.tokens.type.text;
1174
- return result;
1175
- }
1176
- transpile(state) {
1177
- let result = [];
1178
- //type declaration
1179
- result.push(state.sourceNode({ range: this.range }, this.type.toTypeString(state.typeContext)));
1180
- return result;
1181
- }
1182
- walk(visitor, options) {
1183
- //nothing to walk
1184
- }
1185
- }
1186
- exports.TypeExpression = TypeExpression;
1187
- class ArrayTypeExpression extends TypeExpression {
1188
- constructor(innerTypes, // this is an array so that in the future when we support union types
1189
- bracketTokens, namespaceName) {
1190
- super({}, namespaceName);
1191
- this.innerTypes = innerTypes;
1192
- this.bracketTokens = bracketTokens;
1193
- this.namespaceName = namespaceName;
1194
- this.range = util_1.default.createBoundingRange(this.bracketTokens.leftBracket, this.bracketTokens.rightBracket, ...this.innerTypes);
1195
- }
1196
- /*
1197
- * TODO - Support union types
1198
- */
1199
- get defaultTypeExpression() {
1200
- return this.innerTypes[0];
1201
- }
1202
- /**
1203
- * Derive a BscType from the type token
1204
- * Returns an array type with the inner types based on the inner type expressions
1205
- */
1206
- getType(parseMode = Parser_1.ParseMode.BrighterScript) {
1207
- const innerBscTypes = this.innerTypes.map(inner => inner.getType(parseMode));
1208
- return new ArrayType_1.ArrayType(...innerBscTypes);
1209
- }
1210
- /**
1211
- * Is this a valid, (eg. known) type?
1212
- */
1213
- isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
1214
- if (parseMode === Parser_1.ParseMode.BrighterScript) {
1215
- return this.innerTypes.reduce((validSoFar, innerType) => {
1216
- return validSoFar && innerType.isValidType(parseMode);
1217
- }, true);
1218
- }
1219
- return false;
1220
- }
1221
- /**
1222
- * Gives a human readable string that says the type
1223
- * @returns text to display to show the type
1224
- */
1225
- getText() {
1226
- return this.defaultTypeExpression.getText() + '[]';
1227
- }
1228
- walk(visitor, options) {
1229
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1230
- for (let i = 0; i < this.innerTypes.length; i++) {
1231
- (0, visitors_1.walk)(this.innerTypes, i, visitor, options, this);
1232
- }
1233
- }
1234
- }
1235
- }
1236
- exports.ArrayTypeExpression = ArrayTypeExpression;
1237
1286
  function expressionToValue(expr, strict) {
1238
1287
  if (!expr) {
1239
1288
  return null;
@@ -1267,11 +1316,92 @@ function expressionToValue(expr, strict) {
1267
1316
  return strict ? null : expr;
1268
1317
  }
1269
1318
  function numberExpressionToValue(expr, operator = '') {
1270
- 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())) {
1271
1320
  return parseInt(operator + expr.token.text);
1272
1321
  }
1273
1322
  else {
1274
1323
  return parseFloat(operator + expr.token.text);
1275
1324
  }
1276
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;
1277
1407
  //# sourceMappingURL=Expression.js.map