brighterscript 1.0.0-alpha.5 → 1.0.0-alpha.50

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 (715) hide show
  1. package/README.md +76 -138
  2. package/bsconfig.schema.json +121 -5
  3. package/dist/ActionPipeline.d.ts +10 -0
  4. package/dist/ActionPipeline.js +40 -0
  5. package/dist/ActionPipeline.js.map +1 -0
  6. package/dist/AstValidationSegmenter.d.ts +45 -0
  7. package/dist/AstValidationSegmenter.js +322 -0
  8. package/dist/AstValidationSegmenter.js.map +1 -0
  9. package/dist/BsConfig.d.ts +72 -39
  10. package/dist/BusyStatusTracker.d.ts +61 -0
  11. package/dist/BusyStatusTracker.js +148 -0
  12. package/dist/BusyStatusTracker.js.map +1 -0
  13. package/dist/Cache.d.ts +3 -8
  14. package/dist/Cache.js +9 -14
  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 +12 -4
  20. package/dist/CodeActionUtil.js +22 -5
  21. package/dist/CodeActionUtil.js.map +1 -1
  22. package/dist/CommentFlagProcessor.d.ts +7 -6
  23. package/dist/CommentFlagProcessor.js +11 -8
  24. package/dist/CommentFlagProcessor.js.map +1 -1
  25. package/dist/CrossScopeValidator.d.ts +68 -0
  26. package/dist/CrossScopeValidator.js +642 -0
  27. package/dist/CrossScopeValidator.js.map +1 -0
  28. package/dist/DependencyGraph.d.ts +8 -3
  29. package/dist/DependencyGraph.js +49 -16
  30. package/dist/DependencyGraph.js.map +1 -1
  31. package/dist/DiagnosticCollection.d.ts +21 -5
  32. package/dist/DiagnosticCollection.js +77 -24
  33. package/dist/DiagnosticCollection.js.map +1 -1
  34. package/dist/DiagnosticFilterer.d.ts +27 -6
  35. package/dist/DiagnosticFilterer.js +273 -60
  36. package/dist/DiagnosticFilterer.js.map +1 -1
  37. package/dist/DiagnosticManager.d.ts +82 -0
  38. package/dist/DiagnosticManager.js +406 -0
  39. package/dist/DiagnosticManager.js.map +1 -0
  40. package/dist/DiagnosticMessages.d.ts +558 -196
  41. package/dist/DiagnosticMessages.js +870 -340
  42. package/dist/DiagnosticMessages.js.map +1 -1
  43. package/dist/DiagnosticSeverityAdjuster.d.ts +7 -0
  44. package/dist/DiagnosticSeverityAdjuster.js +45 -0
  45. package/dist/DiagnosticSeverityAdjuster.js.map +1 -0
  46. package/dist/FunctionScope.d.ts +28 -0
  47. package/dist/FunctionScope.js +52 -0
  48. package/dist/FunctionScope.js.map +1 -0
  49. package/dist/KeyedThrottler.d.ts +3 -3
  50. package/dist/KeyedThrottler.js +3 -3
  51. package/dist/KeyedThrottler.js.map +1 -1
  52. package/dist/LanguageServer.d.ts +100 -105
  53. package/dist/LanguageServer.js +444 -745
  54. package/dist/LanguageServer.js.map +1 -1
  55. package/dist/Logger.d.ts +17 -13
  56. package/dist/Logger.js +64 -34
  57. package/dist/Logger.js.map +1 -1
  58. package/dist/PluginInterface.d.ts +32 -10
  59. package/dist/PluginInterface.js +117 -7
  60. package/dist/PluginInterface.js.map +1 -1
  61. package/dist/Program.d.ts +241 -98
  62. package/dist/Program.js +1432 -717
  63. package/dist/Program.js.map +1 -1
  64. package/dist/ProgramBuilder.d.ts +47 -23
  65. package/dist/ProgramBuilder.js +224 -178
  66. package/dist/ProgramBuilder.js.map +1 -1
  67. package/dist/Scope.d.ts +149 -109
  68. package/dist/Scope.js +557 -550
  69. package/dist/Scope.js.map +1 -1
  70. package/dist/SemanticTokenUtils.js +5 -1
  71. package/dist/SemanticTokenUtils.js.map +1 -1
  72. package/dist/Stopwatch.d.ts +4 -0
  73. package/dist/Stopwatch.js +8 -1
  74. package/dist/Stopwatch.js.map +1 -1
  75. package/dist/SymbolTable.d.ts +136 -24
  76. package/dist/SymbolTable.js +565 -64
  77. package/dist/SymbolTable.js.map +1 -1
  78. package/dist/SymbolTypeFlag.d.ts +9 -0
  79. package/dist/SymbolTypeFlag.js +14 -0
  80. package/dist/SymbolTypeFlag.js.map +1 -0
  81. package/dist/Throttler.d.ts +12 -0
  82. package/dist/Throttler.js +39 -0
  83. package/dist/Throttler.js.map +1 -1
  84. package/dist/Watcher.d.ts +0 -3
  85. package/dist/Watcher.js +0 -3
  86. package/dist/Watcher.js.map +1 -1
  87. package/dist/XmlScope.d.ts +5 -15
  88. package/dist/XmlScope.js +34 -90
  89. package/dist/XmlScope.js.map +1 -1
  90. package/dist/astUtils/CachedLookups.d.ts +50 -0
  91. package/dist/astUtils/CachedLookups.js +334 -0
  92. package/dist/astUtils/CachedLookups.js.map +1 -0
  93. package/dist/astUtils/CachedLookups.spec.js +39 -0
  94. package/dist/astUtils/CachedLookups.spec.js.map +1 -0
  95. package/dist/astUtils/Editor.d.ts +69 -0
  96. package/dist/astUtils/Editor.js +245 -0
  97. package/dist/astUtils/Editor.js.map +1 -0
  98. package/dist/astUtils/Editor.spec.js +258 -0
  99. package/dist/astUtils/Editor.spec.js.map +1 -0
  100. package/dist/astUtils/creators.d.ts +54 -19
  101. package/dist/astUtils/creators.js +242 -42
  102. package/dist/astUtils/creators.js.map +1 -1
  103. package/dist/astUtils/creators.spec.js +5 -5
  104. package/dist/astUtils/creators.spec.js.map +1 -1
  105. package/dist/astUtils/reflection.d.ts +196 -85
  106. package/dist/astUtils/reflection.js +497 -144
  107. package/dist/astUtils/reflection.js.map +1 -1
  108. package/dist/astUtils/reflection.spec.js +267 -167
  109. package/dist/astUtils/reflection.spec.js.map +1 -1
  110. package/dist/astUtils/stackedVisitor.js.map +1 -1
  111. package/dist/astUtils/stackedVisitor.spec.js +14 -14
  112. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  113. package/dist/astUtils/visitors.d.ts +116 -53
  114. package/dist/astUtils/visitors.js +95 -15
  115. package/dist/astUtils/visitors.js.map +1 -1
  116. package/dist/astUtils/visitors.spec.js +629 -51
  117. package/dist/astUtils/visitors.spec.js.map +1 -1
  118. package/dist/astUtils/xml.d.ts +9 -8
  119. package/dist/astUtils/xml.js +12 -7
  120. package/dist/astUtils/xml.js.map +1 -1
  121. package/dist/bscPlugin/BscPlugin.d.ts +24 -4
  122. package/dist/bscPlugin/BscPlugin.js +88 -4
  123. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  124. package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
  125. package/dist/bscPlugin/CallExpressionInfo.js +143 -0
  126. package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
  127. package/dist/bscPlugin/FileWriter.d.ts +6 -0
  128. package/dist/bscPlugin/FileWriter.js +24 -0
  129. package/dist/bscPlugin/FileWriter.js.map +1 -0
  130. package/dist/bscPlugin/SignatureHelpUtil.d.ts +10 -0
  131. package/dist/bscPlugin/SignatureHelpUtil.js +137 -0
  132. package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
  133. package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +6 -5
  134. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +173 -27
  135. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  136. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +138 -21
  137. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  138. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +65 -0
  139. package/dist/bscPlugin/completions/CompletionsProcessor.js +633 -0
  140. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
  141. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +2512 -0
  142. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
  143. package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
  144. package/dist/bscPlugin/definition/DefinitionProvider.js +212 -0
  145. package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
  146. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +87 -0
  147. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
  148. package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
  149. package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
  150. package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
  151. package/dist/bscPlugin/hover/HoverProcessor.d.ts +18 -0
  152. package/dist/bscPlugin/hover/HoverProcessor.js +230 -0
  153. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
  154. package/dist/bscPlugin/hover/HoverProcessor.spec.js +991 -0
  155. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
  156. package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
  157. package/dist/bscPlugin/references/ReferencesProvider.js +57 -0
  158. package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
  159. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
  160. package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
  161. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
  162. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +14 -0
  163. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +164 -0
  164. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
  165. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
  166. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +564 -0
  167. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
  168. package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
  169. package/dist/bscPlugin/serialize/BslibInjector.spec.js +33 -0
  170. package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
  171. package/dist/bscPlugin/serialize/BslibManager.d.ts +12 -0
  172. package/dist/bscPlugin/serialize/BslibManager.js +46 -0
  173. package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
  174. package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
  175. package/dist/bscPlugin/serialize/FileSerializer.js +75 -0
  176. package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
  177. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.d.ts +7 -0
  178. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js +22 -0
  179. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js.map +1 -0
  180. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +1 -0
  181. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +291 -0
  182. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +1 -0
  183. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.d.ts +7 -0
  184. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js +26 -0
  185. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js.map +1 -0
  186. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +1 -0
  187. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +245 -0
  188. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +1 -0
  189. package/dist/bscPlugin/symbols/symbolUtils.d.ts +5 -0
  190. package/dist/bscPlugin/symbols/symbolUtils.js +141 -0
  191. package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -0
  192. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +27 -0
  193. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +418 -0
  194. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
  195. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
  196. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +75 -0
  197. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
  198. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
  199. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
  200. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
  201. package/dist/bscPlugin/validation/BrsFileAfterValidator.d.ts +7 -0
  202. package/dist/bscPlugin/validation/BrsFileAfterValidator.js +18 -0
  203. package/dist/bscPlugin/validation/BrsFileAfterValidator.js.map +1 -0
  204. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +37 -0
  205. package/dist/bscPlugin/validation/BrsFileValidator.js +638 -0
  206. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
  207. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
  208. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +1517 -0
  209. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
  210. package/dist/bscPlugin/validation/ProgramValidator.d.ts +11 -0
  211. package/dist/bscPlugin/validation/ProgramValidator.js +33 -0
  212. package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
  213. package/dist/bscPlugin/validation/ScopeValidator.d.ts +141 -0
  214. package/dist/bscPlugin/validation/ScopeValidator.js +1323 -0
  215. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
  216. package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
  217. package/dist/bscPlugin/validation/ScopeValidator.spec.js +6135 -0
  218. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
  219. package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
  220. package/dist/bscPlugin/validation/XmlFileValidator.js +36 -0
  221. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
  222. package/dist/cli.js +126 -27
  223. package/dist/cli.js.map +1 -1
  224. package/dist/common/Sequencer.d.ts +53 -0
  225. package/dist/common/Sequencer.js +233 -0
  226. package/dist/common/Sequencer.js.map +1 -0
  227. package/dist/common/Sequencer.spec.d.ts +1 -0
  228. package/dist/common/Sequencer.spec.js +75 -0
  229. package/dist/common/Sequencer.spec.js.map +1 -0
  230. package/dist/deferred.d.ts +5 -3
  231. package/dist/deferred.js +10 -0
  232. package/dist/deferred.js.map +1 -1
  233. package/dist/diagnosticUtils.d.ts +10 -3
  234. package/dist/diagnosticUtils.js +64 -25
  235. package/dist/diagnosticUtils.js.map +1 -1
  236. package/dist/examples/plugins/removePrint.d.ts +2 -2
  237. package/dist/examples/plugins/removePrint.js +8 -12
  238. package/dist/examples/plugins/removePrint.js.map +1 -1
  239. package/dist/files/AssetFile.d.ts +24 -0
  240. package/dist/files/AssetFile.js +25 -0
  241. package/dist/files/AssetFile.js.map +1 -0
  242. package/dist/files/BrsFile.Class.spec.js +1213 -259
  243. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  244. package/dist/files/BrsFile.d.ts +145 -87
  245. package/dist/files/BrsFile.js +836 -934
  246. package/dist/files/BrsFile.js.map +1 -1
  247. package/dist/files/BrsFile.spec.js +4226 -902
  248. package/dist/files/BrsFile.spec.js.map +1 -1
  249. package/dist/files/BscFile.d.ts +102 -0
  250. package/dist/files/BscFile.js +15 -0
  251. package/dist/files/BscFile.js.map +1 -0
  252. package/dist/files/Factory.d.ts +25 -0
  253. package/dist/files/Factory.js +22 -0
  254. package/dist/files/Factory.js.map +1 -0
  255. package/dist/files/LazyFileData.d.ts +21 -0
  256. package/dist/files/LazyFileData.js +54 -0
  257. package/dist/files/LazyFileData.js.map +1 -0
  258. package/dist/files/LazyFileData.spec.d.ts +1 -0
  259. package/dist/files/LazyFileData.spec.js +27 -0
  260. package/dist/files/LazyFileData.spec.js.map +1 -0
  261. package/dist/files/XmlFile.d.ts +80 -41
  262. package/dist/files/XmlFile.js +161 -137
  263. package/dist/files/XmlFile.js.map +1 -1
  264. package/dist/files/XmlFile.spec.js +444 -336
  265. package/dist/files/XmlFile.spec.js.map +1 -1
  266. package/dist/files/tests/imports.spec.js +62 -52
  267. package/dist/files/tests/imports.spec.js.map +1 -1
  268. package/dist/files/tests/optionalChaning.spec.d.ts +1 -0
  269. package/dist/files/tests/optionalChaning.spec.js +152 -0
  270. package/dist/files/tests/optionalChaning.spec.js.map +1 -0
  271. package/dist/globalCallables.d.ts +3 -1
  272. package/dist/globalCallables.js +424 -184
  273. package/dist/globalCallables.js.map +1 -1
  274. package/dist/index.d.ts +32 -4
  275. package/dist/index.js +54 -7
  276. package/dist/index.js.map +1 -1
  277. package/dist/interfaces.d.ts +942 -125
  278. package/dist/interfaces.js +21 -0
  279. package/dist/interfaces.js.map +1 -1
  280. package/dist/lexer/Character.spec.js +5 -5
  281. package/dist/lexer/Character.spec.js.map +1 -1
  282. package/dist/lexer/Lexer.d.ts +51 -12
  283. package/dist/lexer/Lexer.js +215 -65
  284. package/dist/lexer/Lexer.js.map +1 -1
  285. package/dist/lexer/Lexer.spec.js +812 -568
  286. package/dist/lexer/Lexer.spec.js.map +1 -1
  287. package/dist/lexer/Token.d.ts +27 -11
  288. package/dist/lexer/Token.js +10 -2
  289. package/dist/lexer/Token.js.map +1 -1
  290. package/dist/lexer/TokenKind.d.ts +40 -2
  291. package/dist/lexer/TokenKind.js +147 -10
  292. package/dist/lexer/TokenKind.js.map +1 -1
  293. package/dist/logging.d.ts +14 -0
  294. package/dist/logging.js +29 -0
  295. package/dist/logging.js.map +1 -0
  296. package/dist/lsp/ActionQueue.d.ts +35 -0
  297. package/dist/lsp/ActionQueue.js +115 -0
  298. package/dist/lsp/ActionQueue.js.map +1 -0
  299. package/dist/lsp/ActionQueue.spec.d.ts +1 -0
  300. package/dist/lsp/ActionQueue.spec.js +80 -0
  301. package/dist/lsp/ActionQueue.spec.js.map +1 -0
  302. package/dist/lsp/DocumentManager.d.ts +63 -0
  303. package/dist/lsp/DocumentManager.js +122 -0
  304. package/dist/lsp/DocumentManager.js.map +1 -0
  305. package/dist/lsp/DocumentManager.spec.d.ts +1 -0
  306. package/dist/lsp/DocumentManager.spec.js +103 -0
  307. package/dist/lsp/DocumentManager.spec.js.map +1 -0
  308. package/dist/lsp/LspProject.d.ts +239 -0
  309. package/dist/lsp/LspProject.js +3 -0
  310. package/dist/lsp/LspProject.js.map +1 -0
  311. package/dist/lsp/PathFilterer.d.ts +75 -0
  312. package/dist/lsp/PathFilterer.js +196 -0
  313. package/dist/lsp/PathFilterer.js.map +1 -0
  314. package/dist/lsp/PathFilterer.spec.d.ts +1 -0
  315. package/dist/lsp/PathFilterer.spec.js +182 -0
  316. package/dist/lsp/PathFilterer.spec.js.map +1 -0
  317. package/dist/lsp/Project.d.ts +168 -0
  318. package/dist/lsp/Project.js +437 -0
  319. package/dist/lsp/Project.js.map +1 -0
  320. package/dist/lsp/Project.spec.d.ts +1 -0
  321. package/dist/lsp/Project.spec.js +267 -0
  322. package/dist/lsp/Project.spec.js.map +1 -0
  323. package/dist/lsp/ProjectManager.d.ts +242 -0
  324. package/dist/lsp/ProjectManager.js +824 -0
  325. package/dist/lsp/ProjectManager.js.map +1 -0
  326. package/dist/lsp/ProjectManager.spec.d.ts +1 -0
  327. package/dist/lsp/ProjectManager.spec.js +913 -0
  328. package/dist/lsp/ProjectManager.spec.js.map +1 -0
  329. package/dist/lsp/ReaderWriterManager.d.ts +21 -0
  330. package/dist/lsp/ReaderWriterManager.js +60 -0
  331. package/dist/lsp/ReaderWriterManager.js.map +1 -0
  332. package/dist/lsp/worker/MessageHandler.d.ts +99 -0
  333. package/dist/lsp/worker/MessageHandler.js +138 -0
  334. package/dist/lsp/worker/MessageHandler.js.map +1 -0
  335. package/dist/lsp/worker/MessageHandler.spec.d.ts +1 -0
  336. package/dist/lsp/worker/MessageHandler.spec.js +64 -0
  337. package/dist/lsp/worker/MessageHandler.spec.js.map +1 -0
  338. package/dist/lsp/worker/WorkerPool.d.ts +38 -0
  339. package/dist/lsp/worker/WorkerPool.js +78 -0
  340. package/dist/lsp/worker/WorkerPool.js.map +1 -0
  341. package/dist/lsp/worker/WorkerPool.spec.d.ts +1 -0
  342. package/dist/lsp/worker/WorkerPool.spec.js +59 -0
  343. package/dist/lsp/worker/WorkerPool.spec.js.map +1 -0
  344. package/dist/lsp/worker/WorkerThreadProject.d.ts +143 -0
  345. package/dist/lsp/worker/WorkerThreadProject.js +189 -0
  346. package/dist/lsp/worker/WorkerThreadProject.js.map +1 -0
  347. package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +2 -0
  348. package/dist/lsp/worker/WorkerThreadProject.spec.js +71 -0
  349. package/dist/lsp/worker/WorkerThreadProject.spec.js.map +1 -0
  350. package/dist/lsp/worker/WorkerThreadProjectRunner.d.ts +15 -0
  351. package/dist/lsp/worker/WorkerThreadProjectRunner.js +58 -0
  352. package/dist/lsp/worker/WorkerThreadProjectRunner.js.map +1 -0
  353. package/dist/lsp/worker/run.d.ts +1 -0
  354. package/dist/lsp/worker/run.js +14 -0
  355. package/dist/lsp/worker/run.js.map +1 -0
  356. package/dist/parser/AstNode.d.ts +203 -0
  357. package/dist/parser/AstNode.js +303 -0
  358. package/dist/parser/AstNode.js.map +1 -0
  359. package/dist/parser/AstNode.spec.d.ts +1 -0
  360. package/dist/parser/AstNode.spec.js +1455 -0
  361. package/dist/parser/AstNode.spec.js.map +1 -0
  362. package/dist/parser/BrightScriptDocParser.d.ts +56 -0
  363. package/dist/parser/BrightScriptDocParser.js +294 -0
  364. package/dist/parser/BrightScriptDocParser.js.map +1 -0
  365. package/dist/parser/BrightScriptDocParser.spec.d.ts +1 -0
  366. package/dist/parser/BrightScriptDocParser.spec.js +310 -0
  367. package/dist/parser/BrightScriptDocParser.spec.js.map +1 -0
  368. package/dist/parser/BrsTranspileState.d.ts +22 -3
  369. package/dist/parser/BrsTranspileState.js +19 -0
  370. package/dist/parser/BrsTranspileState.js.map +1 -1
  371. package/dist/parser/Expression.d.ts +553 -221
  372. package/dist/parser/Expression.js +1414 -505
  373. package/dist/parser/Expression.js.map +1 -1
  374. package/dist/parser/Expression.spec.d.ts +1 -0
  375. package/dist/parser/Expression.spec.js +40 -0
  376. package/dist/parser/Expression.spec.js.map +1 -0
  377. package/dist/parser/Parser.Class.spec.js +255 -125
  378. package/dist/parser/Parser.Class.spec.js.map +1 -1
  379. package/dist/parser/Parser.d.ts +117 -124
  380. package/dist/parser/Parser.js +1669 -982
  381. package/dist/parser/Parser.js.map +1 -1
  382. package/dist/parser/Parser.spec.d.ts +3 -1
  383. package/dist/parser/Parser.spec.js +2111 -525
  384. package/dist/parser/Parser.spec.js.map +1 -1
  385. package/dist/parser/SGParser.d.ts +29 -13
  386. package/dist/parser/SGParser.js +85 -56
  387. package/dist/parser/SGParser.js.map +1 -1
  388. package/dist/parser/SGParser.spec.js +30 -45
  389. package/dist/parser/SGParser.spec.js.map +1 -1
  390. package/dist/parser/SGTypes.d.ts +134 -46
  391. package/dist/parser/SGTypes.js +206 -115
  392. package/dist/parser/SGTypes.js.map +1 -1
  393. package/dist/parser/Statement.d.ts +849 -267
  394. package/dist/parser/Statement.js +2412 -625
  395. package/dist/parser/Statement.js.map +1 -1
  396. package/dist/parser/Statement.spec.js +133 -36
  397. package/dist/parser/Statement.spec.js.map +1 -1
  398. package/dist/parser/TranspileState.d.ts +26 -12
  399. package/dist/parser/TranspileState.js +115 -24
  400. package/dist/parser/TranspileState.js.map +1 -1
  401. package/dist/parser/tests/Parser.spec.d.ts +3 -9
  402. package/dist/parser/tests/Parser.spec.js +7 -13
  403. package/dist/parser/tests/Parser.spec.js.map +1 -1
  404. package/dist/parser/tests/controlFlow/For.spec.js +83 -75
  405. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  406. package/dist/parser/tests/controlFlow/ForEach.spec.js +85 -51
  407. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  408. package/dist/parser/tests/controlFlow/If.spec.js +382 -239
  409. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  410. package/dist/parser/tests/controlFlow/While.spec.js +52 -45
  411. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  412. package/dist/parser/tests/expression/Additive.spec.js +51 -43
  413. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  414. package/dist/parser/tests/expression/ArrayLiterals.spec.js +192 -142
  415. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  416. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +236 -160
  417. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  418. package/dist/parser/tests/expression/Boolean.spec.js +41 -34
  419. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  420. package/dist/parser/tests/expression/Call.spec.js +173 -55
  421. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  422. package/dist/parser/tests/expression/Exponential.spec.js +20 -20
  423. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  424. package/dist/parser/tests/expression/Function.spec.js +291 -282
  425. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  426. package/dist/parser/tests/expression/Indexing.spec.js +193 -110
  427. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  428. package/dist/parser/tests/expression/Multiplicative.spec.js +42 -42
  429. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  430. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +260 -115
  431. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  432. package/dist/parser/tests/expression/PrefixUnary.spec.js +58 -52
  433. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  434. package/dist/parser/tests/expression/Primary.spec.js +76 -60
  435. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  436. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
  437. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +171 -0
  438. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
  439. package/dist/parser/tests/expression/Relational.spec.js +50 -50
  440. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  441. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +31 -31
  442. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  443. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +281 -94
  444. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  445. package/dist/parser/tests/expression/TernaryExpression.spec.js +747 -192
  446. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  447. package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
  448. package/dist/parser/tests/expression/TypeExpression.spec.js +126 -0
  449. package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
  450. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
  451. package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
  452. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
  453. package/dist/parser/tests/statement/AssignmentOperators.spec.js +44 -44
  454. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  455. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
  456. package/dist/parser/tests/statement/ConstStatement.spec.js +500 -0
  457. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
  458. package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
  459. package/dist/parser/tests/statement/Continue.spec.js +119 -0
  460. package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
  461. package/dist/parser/tests/statement/Declaration.spec.js +61 -55
  462. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  463. package/dist/parser/tests/statement/Dim.spec.js +29 -22
  464. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  465. package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
  466. package/dist/parser/tests/statement/Enum.spec.js +744 -0
  467. package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
  468. package/dist/parser/tests/statement/For.spec.d.ts +1 -0
  469. package/dist/parser/tests/statement/For.spec.js +45 -0
  470. package/dist/parser/tests/statement/For.spec.js.map +1 -0
  471. package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
  472. package/dist/parser/tests/statement/ForEach.spec.js +36 -0
  473. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
  474. package/dist/parser/tests/statement/Function.spec.js +226 -215
  475. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  476. package/dist/parser/tests/statement/Goto.spec.js +16 -15
  477. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  478. package/dist/parser/tests/statement/Increment.spec.js +64 -61
  479. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  480. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
  481. package/dist/parser/tests/statement/InterfaceStatement.spec.js +110 -0
  482. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
  483. package/dist/parser/tests/statement/LibraryStatement.spec.js +22 -22
  484. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  485. package/dist/parser/tests/statement/Misc.spec.js +127 -168
  486. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  487. package/dist/parser/tests/statement/PrintStatement.spec.js +133 -114
  488. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  489. package/dist/parser/tests/statement/ReturnStatement.spec.js +57 -54
  490. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  491. package/dist/parser/tests/statement/Set.spec.js +131 -117
  492. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  493. package/dist/parser/tests/statement/Stop.spec.js +14 -13
  494. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  495. package/dist/parser/tests/statement/Throw.spec.js +11 -8
  496. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  497. package/dist/parser/tests/statement/TryCatch.spec.js +26 -15
  498. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  499. package/dist/preprocessor/Manifest.d.ts +6 -6
  500. package/dist/preprocessor/Manifest.js +17 -38
  501. package/dist/preprocessor/Manifest.js.map +1 -1
  502. package/dist/preprocessor/Manifest.spec.d.ts +1 -0
  503. package/dist/preprocessor/Manifest.spec.js +78 -103
  504. package/dist/preprocessor/Manifest.spec.js.map +1 -1
  505. package/dist/roku-types/data.json +20347 -0
  506. package/dist/roku-types/index.d.ts +5726 -0
  507. package/dist/roku-types/index.js +11 -0
  508. package/dist/roku-types/index.js.map +1 -0
  509. package/dist/types/ArrayType.d.ts +12 -5
  510. package/dist/types/ArrayType.js +89 -24
  511. package/dist/types/ArrayType.js.map +1 -1
  512. package/dist/types/ArrayType.spec.js +39 -11
  513. package/dist/types/ArrayType.spec.js.map +1 -1
  514. package/dist/types/AssociativeArrayType.d.ts +15 -0
  515. package/dist/types/AssociativeArrayType.js +64 -0
  516. package/dist/types/AssociativeArrayType.js.map +1 -0
  517. package/dist/types/BaseFunctionType.d.ts +10 -0
  518. package/dist/types/BaseFunctionType.js +26 -0
  519. package/dist/types/BaseFunctionType.js.map +1 -0
  520. package/dist/types/BooleanType.d.ts +9 -5
  521. package/dist/types/BooleanType.js +19 -8
  522. package/dist/types/BooleanType.js.map +1 -1
  523. package/dist/types/BooleanType.spec.js +10 -4
  524. package/dist/types/BooleanType.spec.js.map +1 -1
  525. package/dist/types/BscType.d.ts +41 -3
  526. package/dist/types/BscType.js +152 -0
  527. package/dist/types/BscType.js.map +1 -1
  528. package/dist/types/BscTypeKind.d.ts +28 -0
  529. package/dist/types/BscTypeKind.js +33 -0
  530. package/dist/types/BscTypeKind.js.map +1 -0
  531. package/dist/types/BuiltInInterfaceAdder.d.ts +28 -0
  532. package/dist/types/BuiltInInterfaceAdder.js +212 -0
  533. package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
  534. package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
  535. package/dist/types/BuiltInInterfaceAdder.spec.js +115 -0
  536. package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
  537. package/dist/types/CallFuncableType.d.ts +24 -0
  538. package/dist/types/CallFuncableType.js +91 -0
  539. package/dist/types/CallFuncableType.js.map +1 -0
  540. package/dist/types/ClassType.d.ts +17 -0
  541. package/dist/types/ClassType.js +60 -0
  542. package/dist/types/ClassType.js.map +1 -0
  543. package/dist/types/ClassType.spec.d.ts +1 -0
  544. package/dist/types/ClassType.spec.js +76 -0
  545. package/dist/types/ClassType.spec.js.map +1 -0
  546. package/dist/types/ComponentType.d.ts +22 -0
  547. package/dist/types/ComponentType.js +107 -0
  548. package/dist/types/ComponentType.js.map +1 -0
  549. package/dist/types/DoubleType.d.ts +10 -5
  550. package/dist/types/DoubleType.js +21 -17
  551. package/dist/types/DoubleType.js.map +1 -1
  552. package/dist/types/DoubleType.spec.js +12 -4
  553. package/dist/types/DoubleType.spec.js.map +1 -1
  554. package/dist/types/DynamicType.d.ts +13 -5
  555. package/dist/types/DynamicType.js +26 -5
  556. package/dist/types/DynamicType.js.map +1 -1
  557. package/dist/types/DynamicType.spec.js +16 -5
  558. package/dist/types/DynamicType.spec.js.map +1 -1
  559. package/dist/types/EnumType.d.ts +42 -0
  560. package/dist/types/EnumType.js +98 -0
  561. package/dist/types/EnumType.js.map +1 -0
  562. package/dist/types/EnumType.spec.d.ts +1 -0
  563. package/dist/types/EnumType.spec.js +33 -0
  564. package/dist/types/EnumType.spec.js.map +1 -0
  565. package/dist/types/FloatType.d.ts +10 -5
  566. package/dist/types/FloatType.js +21 -17
  567. package/dist/types/FloatType.js.map +1 -1
  568. package/dist/types/FloatType.spec.js +4 -4
  569. package/dist/types/FloatType.spec.js.map +1 -1
  570. package/dist/types/FunctionType.d.ts +8 -22
  571. package/dist/types/FunctionType.js +25 -63
  572. package/dist/types/FunctionType.js.map +1 -1
  573. package/dist/types/InheritableType.d.ts +29 -0
  574. package/dist/types/InheritableType.js +173 -0
  575. package/dist/types/InheritableType.js.map +1 -0
  576. package/dist/types/InlineInterfaceType.d.ts +5 -0
  577. package/dist/types/InlineInterfaceType.js +17 -0
  578. package/dist/types/InlineInterfaceType.js.map +1 -0
  579. package/dist/types/IntegerType.d.ts +10 -5
  580. package/dist/types/IntegerType.js +21 -17
  581. package/dist/types/IntegerType.js.map +1 -1
  582. package/dist/types/IntegerType.spec.js +8 -4
  583. package/dist/types/IntegerType.spec.js.map +1 -1
  584. package/dist/types/InterfaceType.d.ts +14 -6
  585. package/dist/types/InterfaceType.js +30 -15
  586. package/dist/types/InterfaceType.js.map +1 -1
  587. package/dist/types/InterfaceType.spec.d.ts +1 -0
  588. package/dist/types/InterfaceType.spec.js +227 -0
  589. package/dist/types/InterfaceType.spec.js.map +1 -0
  590. package/dist/types/IntersectionType.d.ts +29 -0
  591. package/dist/types/IntersectionType.js +253 -0
  592. package/dist/types/IntersectionType.js.map +1 -0
  593. package/dist/types/IntersectionType.spec.d.ts +1 -0
  594. package/dist/types/IntersectionType.spec.js +150 -0
  595. package/dist/types/IntersectionType.spec.js.map +1 -0
  596. package/dist/types/InvalidType.d.ts +10 -5
  597. package/dist/types/InvalidType.js +21 -9
  598. package/dist/types/InvalidType.js.map +1 -1
  599. package/dist/types/InvalidType.spec.js +8 -4
  600. package/dist/types/InvalidType.spec.js.map +1 -1
  601. package/dist/types/LongIntegerType.d.ts +10 -5
  602. package/dist/types/LongIntegerType.js +21 -17
  603. package/dist/types/LongIntegerType.js.map +1 -1
  604. package/dist/types/LongIntegerType.spec.js +10 -4
  605. package/dist/types/LongIntegerType.spec.js.map +1 -1
  606. package/dist/types/NamespaceType.d.ts +12 -0
  607. package/dist/types/NamespaceType.js +28 -0
  608. package/dist/types/NamespaceType.js.map +1 -0
  609. package/dist/types/ObjectType.d.ts +12 -5
  610. package/dist/types/ObjectType.js +25 -8
  611. package/dist/types/ObjectType.js.map +1 -1
  612. package/dist/types/ObjectType.spec.js +3 -3
  613. package/dist/types/ObjectType.spec.js.map +1 -1
  614. package/dist/types/ReferenceType.d.ts +123 -0
  615. package/dist/types/ReferenceType.js +720 -0
  616. package/dist/types/ReferenceType.js.map +1 -0
  617. package/dist/types/ReferenceType.spec.d.ts +1 -0
  618. package/dist/types/ReferenceType.spec.js +151 -0
  619. package/dist/types/ReferenceType.spec.js.map +1 -0
  620. package/dist/types/StringType.d.ts +12 -5
  621. package/dist/types/StringType.js +23 -8
  622. package/dist/types/StringType.js.map +1 -1
  623. package/dist/types/StringType.spec.js +3 -3
  624. package/dist/types/StringType.spec.js.map +1 -1
  625. package/dist/types/TypeStatementType.d.ts +18 -0
  626. package/dist/types/TypeStatementType.js +45 -0
  627. package/dist/types/TypeStatementType.js.map +1 -0
  628. package/dist/types/TypedFunctionType.d.ts +34 -0
  629. package/dist/types/TypedFunctionType.js +147 -0
  630. package/dist/types/TypedFunctionType.js.map +1 -0
  631. package/dist/types/TypedFunctionType.spec.d.ts +1 -0
  632. package/dist/types/TypedFunctionType.spec.js +122 -0
  633. package/dist/types/TypedFunctionType.spec.js.map +1 -0
  634. package/dist/types/UninitializedType.d.ts +11 -6
  635. package/dist/types/UninitializedType.js +20 -11
  636. package/dist/types/UninitializedType.js.map +1 -1
  637. package/dist/types/UnionType.d.ts +27 -0
  638. package/dist/types/UnionType.js +193 -0
  639. package/dist/types/UnionType.js.map +1 -0
  640. package/dist/types/UnionType.spec.d.ts +1 -0
  641. package/dist/types/UnionType.spec.js +205 -0
  642. package/dist/types/UnionType.spec.js.map +1 -0
  643. package/dist/types/VoidType.d.ts +11 -5
  644. package/dist/types/VoidType.js +22 -8
  645. package/dist/types/VoidType.js.map +1 -1
  646. package/dist/types/VoidType.spec.js +3 -3
  647. package/dist/types/VoidType.spec.js.map +1 -1
  648. package/dist/types/helper.spec.d.ts +1 -0
  649. package/dist/types/helper.spec.js +174 -0
  650. package/dist/types/helper.spec.js.map +1 -0
  651. package/dist/types/helpers.d.ts +51 -0
  652. package/dist/types/helpers.js +323 -0
  653. package/dist/types/helpers.js.map +1 -0
  654. package/dist/types/index.d.ts +22 -0
  655. package/dist/types/index.js +39 -0
  656. package/dist/types/index.js.map +1 -0
  657. package/dist/types/roFunctionType.d.ts +11 -0
  658. package/dist/types/roFunctionType.js +37 -0
  659. package/dist/types/roFunctionType.js.map +1 -0
  660. package/dist/types/roFunctionType.spec.d.ts +1 -0
  661. package/dist/types/roFunctionType.spec.js +20 -0
  662. package/dist/types/roFunctionType.spec.js.map +1 -0
  663. package/dist/util.d.ts +288 -187
  664. package/dist/util.js +2018 -575
  665. package/dist/util.js.map +1 -1
  666. package/dist/validators/ClassValidator.d.ts +9 -15
  667. package/dist/validators/ClassValidator.js +93 -138
  668. package/dist/validators/ClassValidator.js.map +1 -1
  669. package/package.json +185 -138
  670. package/CHANGELOG.md +0 -1188
  671. package/dist/astUtils/index.d.ts +0 -7
  672. package/dist/astUtils/index.js +0 -26
  673. package/dist/astUtils/index.js.map +0 -1
  674. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +0 -7
  675. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js +0 -63
  676. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +0 -1
  677. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +0 -45
  678. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +0 -1
  679. package/dist/lexer/index.d.ts +0 -3
  680. package/dist/lexer/index.js +0 -17
  681. package/dist/lexer/index.js.map +0 -1
  682. package/dist/parser/SGTypes.spec.js +0 -351
  683. package/dist/parser/SGTypes.spec.js.map +0 -1
  684. package/dist/parser/index.d.ts +0 -3
  685. package/dist/parser/index.js +0 -16
  686. package/dist/parser/index.js.map +0 -1
  687. package/dist/preprocessor/Chunk.d.ts +0 -82
  688. package/dist/preprocessor/Chunk.js +0 -77
  689. package/dist/preprocessor/Chunk.js.map +0 -1
  690. package/dist/preprocessor/Preprocessor.d.ts +0 -60
  691. package/dist/preprocessor/Preprocessor.js +0 -156
  692. package/dist/preprocessor/Preprocessor.js.map +0 -1
  693. package/dist/preprocessor/Preprocessor.spec.js +0 -152
  694. package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
  695. package/dist/preprocessor/PreprocessorParser.d.ts +0 -61
  696. package/dist/preprocessor/PreprocessorParser.js +0 -194
  697. package/dist/preprocessor/PreprocessorParser.js.map +0 -1
  698. package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
  699. package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
  700. package/dist/preprocessor/index.d.ts +0 -3
  701. package/dist/preprocessor/index.js +0 -16
  702. package/dist/preprocessor/index.js.map +0 -1
  703. package/dist/types/CustomType.d.ts +0 -10
  704. package/dist/types/CustomType.js +0 -35
  705. package/dist/types/CustomType.js.map +0 -1
  706. package/dist/types/FunctionType.spec.js +0 -29
  707. package/dist/types/FunctionType.spec.js.map +0 -1
  708. package/dist/types/LazyType.d.ts +0 -15
  709. package/dist/types/LazyType.js +0 -32
  710. package/dist/types/LazyType.js.map +0 -1
  711. /package/dist/{bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts → astUtils/CachedLookups.spec.d.ts} +0 -0
  712. /package/dist/{parser/SGTypes.spec.d.ts → astUtils/Editor.spec.d.ts} +0 -0
  713. /package/dist/{preprocessor/Preprocessor.spec.d.ts → bscPlugin/completions/CompletionsProcessor.spec.d.ts} +0 -0
  714. /package/dist/{preprocessor/PreprocessorParser.spec.d.ts → bscPlugin/definition/DefinitionProvider.spec.d.ts} +0 -0
  715. /package/dist/{types/FunctionType.spec.d.ts → bscPlugin/hover/HoverProcessor.spec.d.ts} +0 -0
@@ -1,75 +1,113 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- 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;
4
- const lexer_1 = require("../lexer");
3
+ exports.InlineInterfaceMemberExpression = exports.InlineInterfaceExpression = 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.PrintSeparatorExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = void 0;
4
+ const TokenKind_1 = require("../lexer/TokenKind");
5
5
  const util_1 = require("../util");
6
6
  const Parser_1 = require("./Parser");
7
7
  const fileUrl = require("file-url");
8
8
  const visitors_1 = require("../astUtils/visitors");
9
+ const visitors_2 = require("../astUtils/visitors");
9
10
  const reflection_1 = require("../astUtils/reflection");
11
+ const interfaces_1 = require("../interfaces");
10
12
  const VoidType_1 = require("../types/VoidType");
11
13
  const DynamicType_1 = require("../types/DynamicType");
14
+ const AstNode_1 = require("./AstNode");
12
15
  const SymbolTable_1 = require("../SymbolTable");
16
+ const source_map_1 = require("source-map");
17
+ const StringType_1 = require("../types/StringType");
18
+ const ReferenceType_1 = require("../types/ReferenceType");
19
+ const UnionType_1 = require("../types/UnionType");
20
+ const ArrayType_1 = require("../types/ArrayType");
21
+ const AssociativeArrayType_1 = require("../types/AssociativeArrayType");
22
+ const TypedFunctionType_1 = require("../types/TypedFunctionType");
23
+ const InvalidType_1 = require("../types/InvalidType");
24
+ const UninitializedType_1 = require("../types/UninitializedType");
13
25
  const FunctionType_1 = require("../types/FunctionType");
14
- /** A BrightScript expression */
15
- class Expression {
16
- constructor() {
17
- /**
18
- * When being considered by the walk visitor, this describes what type of element the current class is.
19
- */
20
- this.visitMode = visitors_1.InternalWalkMode.visitExpressions;
21
- }
22
- }
23
- exports.Expression = Expression;
24
- class BinaryExpression extends Expression {
25
- constructor(left, operator, right) {
26
+ const BrightScriptDocParser_1 = require("./BrightScriptDocParser");
27
+ const InlineInterfaceType_1 = require("../types/InlineInterfaceType");
28
+ const IntersectionType_1 = require("../types/IntersectionType");
29
+ class BinaryExpression extends AstNode_1.Expression {
30
+ constructor(options) {
26
31
  super();
27
- this.left = left;
28
- this.operator = operator;
29
- this.right = right;
30
- this.range = util_1.default.createRangeFromPositions(this.left.range.start, this.right.range.end);
32
+ this.kind = AstNode_1.AstNodeKind.BinaryExpression;
33
+ this.tokens = {
34
+ operator: options.operator
35
+ };
36
+ this.left = options.left;
37
+ this.right = options.right;
38
+ this.location = util_1.default.createBoundingLocation(this.left, this.tokens.operator, this.right);
31
39
  }
32
40
  transpile(state) {
33
41
  return [
34
42
  state.sourceNode(this.left, this.left.transpile(state)),
35
43
  ' ',
36
- state.transpileToken(this.operator),
44
+ state.transpileToken(this.tokens.operator),
37
45
  ' ',
38
46
  state.sourceNode(this.right, this.right.transpile(state))
39
47
  ];
40
48
  }
41
49
  walk(visitor, options) {
42
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
43
- visitors_1.walk(this, 'left', visitor, options);
44
- visitors_1.walk(this, 'right', visitor, options);
50
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
51
+ (0, visitors_2.walk)(this, 'left', visitor, options);
52
+ (0, visitors_2.walk)(this, 'right', visitor, options);
45
53
  }
46
54
  }
55
+ getType(options) {
56
+ var _a;
57
+ const operatorKind = this.tokens.operator.kind;
58
+ if (options.flags & 2 /* SymbolTypeFlag.typetime */) {
59
+ // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
60
+ switch (operatorKind) {
61
+ case TokenKind_1.TokenKind.Or:
62
+ return new UnionType_1.UnionType([this.left.getType(options), this.right.getType(options)]);
63
+ case TokenKind_1.TokenKind.And:
64
+ return new IntersectionType_1.IntersectionType([this.left.getType(options), this.right.getType(options)]);
65
+ //TODO: Intersection Types?, eg. case TokenKind.And:
66
+ }
67
+ }
68
+ else if (options.flags & 1 /* SymbolTypeFlag.runtime */) {
69
+ return (_a = util_1.default.binaryOperatorResultType(this.left.getType(options), this.tokens.operator, this.right.getType(options))) !== null && _a !== void 0 ? _a : DynamicType_1.DynamicType.instance;
70
+ }
71
+ return DynamicType_1.DynamicType.instance;
72
+ }
73
+ get leadingTrivia() {
74
+ return this.left.leadingTrivia;
75
+ }
76
+ clone() {
77
+ var _a, _b;
78
+ return this.finalizeClone(new BinaryExpression({
79
+ left: (_a = this.left) === null || _a === void 0 ? void 0 : _a.clone(),
80
+ operator: util_1.default.cloneToken(this.tokens.operator),
81
+ right: (_b = this.right) === null || _b === void 0 ? void 0 : _b.clone()
82
+ }), ['left', 'right']);
83
+ }
47
84
  }
48
85
  exports.BinaryExpression = BinaryExpression;
49
- class CallExpression extends Expression {
50
- constructor(callee, openingParen, closingParen, args,
51
- /**
52
- * 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.
53
- */
54
- namespaceName) {
86
+ class CallExpression extends AstNode_1.Expression {
87
+ constructor(options) {
88
+ var _a, _b;
55
89
  super();
56
- this.callee = callee;
57
- this.openingParen = openingParen;
58
- this.closingParen = closingParen;
59
- this.args = args;
60
- this.namespaceName = namespaceName;
61
- this.range = util_1.default.createRangeFromPositions(this.callee.range.start, this.closingParen.range.end);
90
+ this.kind = AstNode_1.AstNodeKind.CallExpression;
91
+ this.tokens = {
92
+ openingParen: options.openingParen,
93
+ closingParen: options.closingParen
94
+ };
95
+ this.callee = options.callee;
96
+ this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
97
+ this.location = util_1.default.createBoundingLocation(this.callee, this.tokens.openingParen, ...(_b = this.args) !== null && _b !== void 0 ? _b : [], this.tokens.closingParen);
62
98
  }
63
99
  transpile(state, nameOverride) {
64
100
  let result = [];
65
101
  //transpile the name
66
102
  if (nameOverride) {
67
- result.push(state.sourceNode(this.callee, nameOverride));
103
+ result.push(
104
+ //transpile leading comments since we're bypassing callee.transpile (which would normally do this)
105
+ ...state.transpileLeadingCommentsForAstNode(this), state.sourceNode(this.callee, nameOverride));
68
106
  }
69
107
  else {
70
108
  result.push(...this.callee.transpile(state));
71
109
  }
72
- result.push(state.transpileToken(this.openingParen));
110
+ result.push(state.transpileToken(this.tokens.openingParen, '('));
73
111
  for (let i = 0; i < this.args.length; i++) {
74
112
  //add comma between args
75
113
  if (i > 0) {
@@ -78,80 +116,115 @@ class CallExpression extends Expression {
78
116
  let arg = this.args[i];
79
117
  result.push(...arg.transpile(state));
80
118
  }
81
- result.push(state.transpileToken(this.closingParen));
119
+ result.push(state.transpileToken(this.tokens.closingParen, ')'));
82
120
  return result;
83
121
  }
84
122
  walk(visitor, options) {
85
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
86
- visitors_1.walk(this, 'callee', visitor, options);
87
- for (let i = 0; i < this.args.length; i++) {
88
- visitors_1.walk(this.args, i, visitor, options, this);
123
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
124
+ (0, visitors_2.walk)(this, 'callee', visitor, options);
125
+ (0, visitors_2.walkArray)(this.args, visitor, options, this);
126
+ }
127
+ }
128
+ getType(options) {
129
+ var _a, _b, _c;
130
+ const calleeType = this.callee.getType(options);
131
+ if (options.ignoreCall) {
132
+ return calleeType;
133
+ }
134
+ if ((0, reflection_1.isNewExpression)(this.parent)) {
135
+ return calleeType;
136
+ }
137
+ const specialCaseReturnType = util_1.default.getSpecialCaseCallExpressionReturnType(this, options);
138
+ if (specialCaseReturnType) {
139
+ return specialCaseReturnType;
140
+ }
141
+ if ((0, reflection_1.isCallableType)(calleeType) && (!(0, reflection_1.isReferenceType)(calleeType.returnType) || ((_a = calleeType.returnType) === null || _a === void 0 ? void 0 : _a.isResolvable()))) {
142
+ if ((0, reflection_1.isVoidType)(calleeType.returnType)) {
143
+ if ((_b = options.data) === null || _b === void 0 ? void 0 : _b.isBuiltIn) {
144
+ // built in functions that return `as void` will not initialize the result
145
+ return UninitializedType_1.UninitializedType.instance;
146
+ }
147
+ // non-built in functions with return type`as void` actually return `invalid`
148
+ return InvalidType_1.InvalidType.instance;
89
149
  }
150
+ return calleeType.returnType;
151
+ }
152
+ if (util_1.default.isUnionOfFunctions(calleeType, true)) {
153
+ return util_1.default.getReturnTypeOfUnionOfFunctions(calleeType);
90
154
  }
155
+ if (!(0, reflection_1.isReferenceType)(calleeType) && ((_c = calleeType === null || calleeType === void 0 ? void 0 : calleeType.returnType) === null || _c === void 0 ? void 0 : _c.isResolvable())) {
156
+ return calleeType.returnType;
157
+ }
158
+ return new ReferenceType_1.TypePropertyReferenceType(calleeType, 'returnType');
159
+ }
160
+ get leadingTrivia() {
161
+ return this.callee.leadingTrivia;
162
+ }
163
+ clone() {
164
+ var _a, _b;
165
+ return this.finalizeClone(new CallExpression({
166
+ callee: (_a = this.callee) === null || _a === void 0 ? void 0 : _a.clone(),
167
+ openingParen: util_1.default.cloneToken(this.tokens.openingParen),
168
+ closingParen: util_1.default.cloneToken(this.tokens.closingParen),
169
+ args: (_b = this.args) === null || _b === void 0 ? void 0 : _b.map(e => e === null || e === void 0 ? void 0 : e.clone())
170
+ }), ['callee', 'args']);
91
171
  }
92
172
  }
93
173
  exports.CallExpression = CallExpression;
94
- CallExpression.MaximumArguments = 32;
95
- class FunctionExpression extends Expression {
96
- constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeToken,
97
- /**
98
- * If this function is enclosed within another function, this will reference that parent function
99
- */
100
- parentFunction, namespaceName, parentSymbolTable) {
174
+ /**
175
+ * Number of parameters that can be defined on a function
176
+ *
177
+ * Prior to Roku OS 11.5, this was 32
178
+ * As of Roku OS 11.5, this is 63
179
+ */
180
+ CallExpression.MaximumArguments = 63;
181
+ class FunctionExpression extends AstNode_1.Expression {
182
+ constructor(options) {
183
+ var _a;
101
184
  super();
102
- this.parameters = parameters;
103
- this.body = body;
104
- this.functionType = functionType;
105
- this.end = end;
106
- this.leftParen = leftParen;
107
- this.rightParen = rightParen;
108
- this.asToken = asToken;
109
- this.returnTypeToken = returnTypeToken;
110
- this.parentFunction = parentFunction;
111
- this.namespaceName = namespaceName;
112
- this.parentSymbolTable = parentSymbolTable;
113
- this.labelStatements = [];
114
- /**
115
- * The list of function calls that are declared within this function scope. This excludes CallExpressions
116
- * declared in child functions
117
- */
118
- this.callExpressions = [];
119
- /**
120
- * A list of all child functions declared directly within this function
121
- */
122
- this.childFunctionExpressions = [];
123
- if (this.returnTypeToken) {
124
- this.returnType = util_1.default.tokenToBscType(this.returnTypeToken);
125
- }
126
- else if (this.functionType.text.toLowerCase() === 'sub') {
127
- this.returnType = new VoidType_1.VoidType();
128
- }
129
- else {
130
- this.returnType = new DynamicType_1.DynamicType();
131
- }
132
- this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
133
- for (let param of parameters) {
134
- this.symbolTable.addSymbol(param.name.text, param.name.range, param.type);
185
+ this.kind = AstNode_1.AstNodeKind.FunctionExpression;
186
+ this.tokens = {
187
+ functionType: options.functionType,
188
+ leftParen: options.leftParen,
189
+ rightParen: options.rightParen,
190
+ as: options.as,
191
+ endFunctionType: options.endFunctionType
192
+ };
193
+ this.parameters = (_a = options.parameters) !== null && _a !== void 0 ? _a : [];
194
+ this.body = options.body;
195
+ this.returnTypeExpression = options.returnTypeExpression;
196
+ if (this.body) {
197
+ this.body.parent = this;
135
198
  }
199
+ this.symbolTable = new SymbolTable_1.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
200
+ }
201
+ get leadingTrivia() {
202
+ var _a;
203
+ return (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
204
+ }
205
+ get endTrivia() {
206
+ var _a;
207
+ return (_a = this.tokens.endFunctionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
136
208
  }
137
209
  /**
138
210
  * The range of the function, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
139
211
  * and ending with the last n' in 'end function' or 'b' in 'end sub'
140
212
  */
141
- get range() {
142
- var _a, _b, _c, _d, _e;
143
- return util_1.default.createRangeFromPositions(((_a = this.functionType) !== null && _a !== void 0 ? _a : this.leftParen).range.start, ((_e = (_d = (_c = (_b = this.end) !== null && _b !== void 0 ? _b : this.body) !== null && _c !== void 0 ? _c : this.returnTypeToken) !== null && _d !== void 0 ? _d : this.asToken) !== null && _e !== void 0 ? _e : this.rightParen).range.end);
213
+ get location() {
214
+ var _a;
215
+ return util_1.default.createBoundingLocation(this.tokens.functionType, this.tokens.leftParen, ...(_a = this.parameters) !== null && _a !== void 0 ? _a : [], this.tokens.rightParen, this.tokens.as, this.returnTypeExpression, this.tokens.endFunctionType);
144
216
  }
145
217
  transpile(state, name, includeBody = true) {
218
+ var _a, _b, _c;
146
219
  let results = [];
147
220
  //'function'|'sub'
148
- results.push(state.transpileToken(this.functionType));
221
+ results.push(state.transpileToken(this.tokens.functionType, 'function', false, state.skipLeadingComments));
149
222
  //functionName?
150
223
  if (name) {
151
224
  results.push(' ', state.transpileToken(name));
152
225
  }
153
226
  //leftParen
154
- results.push(state.transpileToken(this.leftParen));
227
+ results.push(state.transpileToken(this.tokens.leftParen, '('));
155
228
  //parameters
156
229
  for (let i = 0; i < this.parameters.length; i++) {
157
230
  let param = this.parameters[i];
@@ -163,71 +236,189 @@ class FunctionExpression extends Expression {
163
236
  results.push(param.transpile(state));
164
237
  }
165
238
  //right paren
166
- results.push(state.transpileToken(this.rightParen));
239
+ results.push(state.transpileToken(this.tokens.rightParen, ')'));
167
240
  //as [Type]
168
- if (this.asToken) {
241
+ if (this.tokens.as && this.returnTypeExpression && (this.requiresReturnType || !state.options.removeParameterTypes)) {
169
242
  results.push(' ',
170
243
  //as
171
- state.transpileToken(this.asToken), ' ',
244
+ state.transpileToken(this.tokens.as, 'as'), ' ',
172
245
  //return type
173
- state.sourceNode(this.returnTypeToken, this.returnType.toTypeString()));
246
+ ...this.returnTypeExpression.transpile(state));
174
247
  }
248
+ let hasBody = false;
175
249
  if (includeBody) {
176
250
  state.lineage.unshift(this);
177
251
  let body = this.body.transpile(state);
252
+ hasBody = body.length > 0;
178
253
  state.lineage.shift();
179
254
  results.push(...body);
180
255
  }
181
- results.push('\n');
182
- //'end sub'|'end function'
183
- results.push(state.indent(), state.transpileToken(this.end));
256
+ const lastLocatable = hasBody ? this.body : (_b = (_a = this.returnTypeExpression) !== null && _a !== void 0 ? _a : this.tokens.leftParen) !== null && _b !== void 0 ? _b : this.tokens.functionType;
257
+ results.push(...state.transpileEndBlockToken(lastLocatable, this.tokens.endFunctionType, `end ${(_c = this.tokens.functionType) !== null && _c !== void 0 ? _c : 'function'}`));
184
258
  return results;
185
259
  }
186
- getTypedef(state, name) {
187
- return this.transpile(state, name, false);
260
+ getTypedef(state) {
261
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
262
+ let results = [
263
+ new source_map_1.SourceNode(1, 0, null, [
264
+ //'function'|'sub'
265
+ (_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'function',
266
+ //functionName?
267
+ ...((0, reflection_1.isFunctionStatement)(this.parent) || (0, reflection_1.isMethodStatement)(this.parent) ? [' ', (_d = (_c = this.parent.tokens.name) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : ''] : []),
268
+ //leftParen
269
+ '(',
270
+ //parameters
271
+ ...((_f = (_e = this.parameters) === null || _e === void 0 ? void 0 : _e.map((param, i) => ([
272
+ //separating comma
273
+ i > 0 ? ', ' : '',
274
+ ...param.getTypedef(state)
275
+ ]))) !== null && _f !== void 0 ? _f : []),
276
+ //right paren
277
+ ')',
278
+ //as <ReturnType>
279
+ ...(this.returnTypeExpression ? [
280
+ ' ',
281
+ (_h = (_g = this.tokens.as) === null || _g === void 0 ? void 0 : _g.text) !== null && _h !== void 0 ? _h : 'as',
282
+ ' ',
283
+ ...this.returnTypeExpression.getTypedef(state)
284
+ ] : []),
285
+ '\n',
286
+ state.indent(),
287
+ //'end sub'|'end function'
288
+ (_k = (_j = this.tokens.endFunctionType) === null || _j === void 0 ? void 0 : _j.text) !== null && _k !== void 0 ? _k : `end ${(_l = this.tokens.functionType) !== null && _l !== void 0 ? _l : 'function'}`
289
+ ])
290
+ ];
291
+ return results;
188
292
  }
189
293
  walk(visitor, options) {
190
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
191
- for (let i = 0; i < this.parameters.length; i++) {
192
- visitors_1.walk(this.parameters, i, visitor, options, this);
193
- }
294
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
295
+ (0, visitors_2.walkArray)(this.parameters, visitor, options, this);
296
+ (0, visitors_2.walk)(this, 'returnTypeExpression', visitor, options);
194
297
  //This is the core of full-program walking...it allows us to step into sub functions
195
- if (options.walkMode & visitors_1.InternalWalkMode.recurseChildFunctions) {
196
- visitors_1.walk(this, 'body', visitor, options);
298
+ if (options.walkMode & visitors_2.InternalWalkMode.recurseChildFunctions) {
299
+ (0, visitors_2.walk)(this, 'body', visitor, options);
197
300
  }
198
301
  }
199
302
  }
200
- getFunctionType() {
201
- let functionType = new FunctionType_1.FunctionType(this.returnType);
202
- functionType.isSub = this.functionType.text === 'sub';
303
+ getType(options) {
304
+ var _a, _b, _c, _d;
305
+ //if there's a defined return type, use that
306
+ let returnType;
307
+ const docs = BrightScriptDocParser_1.brsDocParser.parseNode(this.findAncestor(reflection_1.isFunctionStatement));
308
+ returnType = util_1.default.chooseTypeFromCodeOrDocComment((_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), docs.getReturnBscType(Object.assign(Object.assign({}, options), { tableProvider: () => this.getSymbolTable() })), options);
309
+ const isSub = ((_b = this.tokens.functionType) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Sub;
310
+ //if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
311
+ if (!returnType) {
312
+ returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
313
+ }
314
+ const resultType = new TypedFunctionType_1.TypedFunctionType(returnType);
315
+ resultType.isSub = isSub;
203
316
  for (let param of this.parameters) {
204
- functionType.addParameter(param.name.text, param.type, param.isOptional);
317
+ resultType.addParameter(param.tokens.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
318
+ }
319
+ // Figure out this function's name if we can
320
+ let funcName = '';
321
+ if ((0, reflection_1.isMethodStatement)(this.parent) || (0, reflection_1.isInterfaceMethodStatement)(this.parent)) {
322
+ funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
323
+ if (options.typeChain) {
324
+ // Get the typechain info from the parent class
325
+ (_c = this.parent.parent) === null || _c === void 0 ? void 0 : _c.getType(options);
326
+ }
327
+ }
328
+ else if ((0, reflection_1.isFunctionStatement)(this.parent)) {
329
+ funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
330
+ }
331
+ if (funcName) {
332
+ resultType.setName(funcName);
205
333
  }
206
- return functionType;
334
+ (_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry({ name: funcName, type: resultType, data: options.data, astNode: this }));
335
+ return resultType;
336
+ }
337
+ get requiresReturnType() {
338
+ /**
339
+ * RokuOS methods can be written several different ways:
340
+ * 1. Function() : return withValue
341
+ * 2. Function() as type : return withValue
342
+ * 3. Function() as void : return
343
+ *
344
+ * 4. Sub() : return
345
+ * 5. Sub () as void : return
346
+ * 6. Sub() as type : return withValue
347
+ *
348
+ * Formats (1), (2), and (6) throw a compile error if there IS NOT a return value in the function body.
349
+ * Formats (3), (4), and (5) throw a compile error if there IS a return value in the function body.
350
+ *
351
+ * 7. Additionally, as a special case, the OS requires that `onKeyEvent()` be defined with `as boolean`
352
+ */
353
+ var _a, _b, _c, _d, _e;
354
+ if (((0, reflection_1.isFunctionStatement)(this.parent) || (0, reflection_1.isMethodStatement)(this.parent)) && ((_c = (_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.text.toLowerCase()) === 'onkeyevent') {
355
+ // onKeyEvent() requires 'as Boolean' otherwise RokuOS throws errors
356
+ return true;
357
+ }
358
+ const isSub = ((_d = this.tokens.functionType) === null || _d === void 0 ? void 0 : _d.text.toLowerCase()) === 'sub';
359
+ const returnType = (_e = this.returnTypeExpression) === null || _e === void 0 ? void 0 : _e.getType({ flags: 2 /* SymbolTypeFlag.typetime */ });
360
+ const isVoidReturnType = (0, reflection_1.isVoidType)(returnType);
361
+ if (isSub && !isVoidReturnType) { // format (6)
362
+ return true;
363
+ }
364
+ else if (isVoidReturnType) { // format (3)
365
+ return true;
366
+ }
367
+ return false;
368
+ }
369
+ clone() {
370
+ var _a, _b, _c;
371
+ return this.finalizeClone(new FunctionExpression({
372
+ parameters: (_a = this.parameters) === null || _a === void 0 ? void 0 : _a.map(e => e === null || e === void 0 ? void 0 : e.clone()),
373
+ body: (_b = this.body) === null || _b === void 0 ? void 0 : _b.clone(),
374
+ functionType: util_1.default.cloneToken(this.tokens.functionType),
375
+ endFunctionType: util_1.default.cloneToken(this.tokens.endFunctionType),
376
+ leftParen: util_1.default.cloneToken(this.tokens.leftParen),
377
+ rightParen: util_1.default.cloneToken(this.tokens.rightParen),
378
+ as: util_1.default.cloneToken(this.tokens.as),
379
+ returnTypeExpression: (_c = this.returnTypeExpression) === null || _c === void 0 ? void 0 : _c.clone()
380
+ }), ['body', 'returnTypeExpression']);
207
381
  }
208
382
  }
209
383
  exports.FunctionExpression = FunctionExpression;
210
- class FunctionParameterExpression extends Expression {
211
- constructor(name, type, equalsToken, defaultValue, asToken, typeToken, namespaceName) {
384
+ class FunctionParameterExpression extends AstNode_1.Expression {
385
+ constructor(options) {
212
386
  super();
213
- this.name = name;
214
- this.type = type;
215
- this.equalsToken = equalsToken;
216
- this.defaultValue = defaultValue;
217
- this.asToken = asToken;
218
- this.typeToken = typeToken;
219
- this.namespaceName = namespaceName;
220
- }
221
- get range() {
222
- return {
223
- start: this.name.range.start,
224
- end: this.typeToken ? this.typeToken.range.end : this.name.range.end
387
+ this.kind = AstNode_1.AstNodeKind.FunctionParameterExpression;
388
+ this.tokens = {
389
+ name: options.name,
390
+ equals: options.equals,
391
+ as: options.as
225
392
  };
393
+ this.defaultValue = options.defaultValue;
394
+ this.typeExpression = options.typeExpression;
395
+ }
396
+ getType(options) {
397
+ var _a, _b, _c, _d, _e, _f, _g;
398
+ const docs = BrightScriptDocParser_1.brsDocParser.parseNode(this.findAncestor(reflection_1.isFunctionStatement));
399
+ const paramName = this.tokens.name.text;
400
+ let paramTypeFromCode = (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */, typeChain: undefined }))) !== null && _b !== void 0 ? _b : util_1.default.getDefaultTypeFromValueType((_c = this.defaultValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */, typeChain: undefined })));
401
+ if ((0, reflection_1.isInvalidType)(paramTypeFromCode) || (0, reflection_1.isVoidType)(paramTypeFromCode)) {
402
+ paramTypeFromCode = undefined;
403
+ }
404
+ const paramTypeFromDoc = docs.getParamBscType(paramName, Object.assign(Object.assign({}, options), { fullName: paramName, typeChain: undefined, tableProvider: () => this.getSymbolTable() }));
405
+ const paramType = (_d = util_1.default.chooseTypeFromCodeOrDocComment(paramTypeFromCode, paramTypeFromDoc, options)) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
406
+ const docDescription = (_e = docs.getParam(paramName)) === null || _e === void 0 ? void 0 : _e.description;
407
+ if (docDescription) {
408
+ options.data = (_f = options.data) !== null && _f !== void 0 ? _f : {};
409
+ options.data.description = docDescription;
410
+ }
411
+ (_g = options.typeChain) === null || _g === void 0 ? void 0 : _g.push(new interfaces_1.TypeChainEntry({ name: paramName, type: paramType, data: options.data, astNode: this }));
412
+ return paramType;
413
+ }
414
+ get location() {
415
+ return util_1.default.createBoundingLocation(this.tokens.name, this.tokens.as, this.typeExpression, this.tokens.equals, this.defaultValue);
226
416
  }
227
417
  transpile(state) {
418
+ var _a, _b;
228
419
  let result = [
229
420
  //name
230
- state.transpileToken(this.name)
421
+ state.transpileToken(this.tokens.name)
231
422
  ];
232
423
  //default value
233
424
  if (this.defaultValue) {
@@ -235,313 +426,491 @@ class FunctionParameterExpression extends Expression {
235
426
  result.push(this.defaultValue.transpile(state));
236
427
  }
237
428
  //type declaration
238
- if (this.asToken) {
429
+ if (this.typeExpression && !state.options.removeParameterTypes) {
239
430
  result.push(' ');
240
- result.push(state.transpileToken(this.asToken));
431
+ result.push(state.transpileToken(this.tokens.as, 'as'));
241
432
  result.push(' ');
242
- result.push(state.sourceNode(this.typeToken, this.type.toTypeString()));
433
+ result.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []));
243
434
  }
244
435
  return result;
245
436
  }
246
- walk(visitor, options) {
247
- // eslint-disable-next-line no-bitwise
248
- if (this.defaultValue && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
249
- visitors_1.walk(this, 'defaultValue', visitor, options);
250
- }
251
- }
252
- get isOptional() {
253
- return !!this.defaultValue;
254
- }
255
- }
256
- exports.FunctionParameterExpression = FunctionParameterExpression;
257
- class NamespacedVariableNameExpression extends Expression {
258
- constructor(
259
- //if this is a `DottedGetExpression`, it must be comprised only of `VariableExpression`s
260
- expression) {
261
- super();
262
- this.expression = expression;
263
- this.range = expression.range;
264
- }
265
- transpile(state) {
266
- return [
267
- state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
268
- ];
269
- }
270
- getNameParts() {
271
- let parts = [];
272
- if (reflection_1.isVariableExpression(this.expression)) {
273
- parts.push(this.expression.name.text);
274
- }
275
- else {
276
- let expr = this.expression;
277
- parts.push(expr.name.text);
278
- while (reflection_1.isVariableExpression(expr) === false) {
279
- expr = expr.obj;
280
- parts.unshift(expr.name.text);
437
+ getTypedef(state) {
438
+ var _a, _b, _c;
439
+ const results = [this.tokens.name.text];
440
+ if (this.defaultValue) {
441
+ results.push(' = ', ...((_a = this.defaultValue.getTypedef(state)) !== null && _a !== void 0 ? _a : this.defaultValue.transpile(state)));
442
+ }
443
+ if (this.tokens.as) {
444
+ results.push(' as ');
445
+ // TODO: Is this conditional needed? Will typeToken always exist
446
+ // so long as `asToken` exists?
447
+ if (this.typeExpression) {
448
+ results.push(...((_c = (_b = this.typeExpression) === null || _b === void 0 ? void 0 : _b.getTypedef(state)) !== null && _c !== void 0 ? _c : ['']));
281
449
  }
282
450
  }
283
- return parts;
284
- }
285
- getName(parseMode) {
286
- if (parseMode === Parser_1.ParseMode.BrighterScript) {
287
- return this.getNameParts().join('.');
288
- }
289
- else {
290
- return this.getNameParts().join('_');
291
- }
451
+ return results;
292
452
  }
293
453
  walk(visitor, options) {
294
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
295
- visitors_1.walk(this, 'expression', visitor, options);
454
+ // eslint-disable-next-line no-bitwise
455
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
456
+ (0, visitors_2.walk)(this, 'defaultValue', visitor, options);
457
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
296
458
  }
297
459
  }
460
+ get leadingTrivia() {
461
+ return this.tokens.name.leadingTrivia;
462
+ }
463
+ clone() {
464
+ var _a, _b;
465
+ return this.finalizeClone(new FunctionParameterExpression({
466
+ name: util_1.default.cloneToken(this.tokens.name),
467
+ as: util_1.default.cloneToken(this.tokens.as),
468
+ typeExpression: (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.clone(),
469
+ equals: util_1.default.cloneToken(this.tokens.equals),
470
+ defaultValue: (_b = this.defaultValue) === null || _b === void 0 ? void 0 : _b.clone()
471
+ }), ['typeExpression', 'defaultValue']);
472
+ }
298
473
  }
299
- exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
300
- class DottedGetExpression extends Expression {
301
- constructor(obj, name, dot) {
474
+ exports.FunctionParameterExpression = FunctionParameterExpression;
475
+ class DottedGetExpression extends AstNode_1.Expression {
476
+ constructor(options) {
302
477
  super();
303
- this.obj = obj;
304
- this.name = name;
305
- this.dot = dot;
306
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.name.range.end);
478
+ this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
479
+ this.tokens = {
480
+ name: options.name,
481
+ dot: options.dot
482
+ };
483
+ this.obj = options.obj;
484
+ this.location = util_1.default.createBoundingLocation(this.obj, this.tokens.dot, this.tokens.name);
307
485
  }
308
486
  transpile(state) {
309
487
  //if the callee starts with a namespace name, transpile the name
310
488
  if (state.file.calleeStartsWithNamespace(this)) {
311
- return new NamespacedVariableNameExpression(this).transpile(state);
489
+ return [
490
+ ...state.transpileLeadingCommentsForAstNode(this),
491
+ state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
492
+ ];
312
493
  }
313
494
  else {
314
495
  return [
315
496
  ...this.obj.transpile(state),
316
- '.',
317
- state.transpileToken(this.name)
497
+ state.transpileToken(this.tokens.dot, '.'),
498
+ state.transpileToken(this.tokens.name)
318
499
  ];
319
500
  }
320
501
  }
502
+ getTypedef(state) {
503
+ //always transpile the dots for typedefs
504
+ return [
505
+ ...this.obj.transpile(state),
506
+ state.transpileToken(this.tokens.dot),
507
+ state.transpileToken(this.tokens.name)
508
+ ];
509
+ }
321
510
  walk(visitor, options) {
322
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
323
- visitors_1.walk(this, 'obj', visitor, options);
324
- }
511
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
512
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
513
+ }
514
+ }
515
+ getType(options) {
516
+ var _a, _b, _c, _d, _e, _f;
517
+ const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
518
+ let result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text, options);
519
+ if (util_1.default.isClassUsedAsFunction(result, this, options)) {
520
+ // treat this class constructor as a function
521
+ result = FunctionType_1.FunctionType.instance;
522
+ }
523
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
524
+ name: (_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text,
525
+ type: result,
526
+ data: options.data,
527
+ location: (_f = (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.location) !== null && _f !== void 0 ? _f : this.location,
528
+ astNode: this
529
+ }));
530
+ if (result ||
531
+ options.flags & 2 /* SymbolTypeFlag.typetime */ ||
532
+ ((0, reflection_1.isPrimitiveType)(objType) || (0, reflection_1.isCallableType)(objType))) {
533
+ // All types should be known at typeTime, or the obj is well known
534
+ return result;
535
+ }
536
+ // It is possible at runtime that a value has been added dynamically to an object, or something
537
+ // TODO: maybe have a strict flag on this?
538
+ return DynamicType_1.DynamicType.instance;
539
+ }
540
+ getName(parseMode) {
541
+ return util_1.default.getAllDottedGetPartsAsString(this, parseMode);
542
+ }
543
+ get leadingTrivia() {
544
+ return this.obj.leadingTrivia;
545
+ }
546
+ clone() {
547
+ var _a;
548
+ return this.finalizeClone(new DottedGetExpression({
549
+ obj: (_a = this.obj) === null || _a === void 0 ? void 0 : _a.clone(),
550
+ dot: util_1.default.cloneToken(this.tokens.dot),
551
+ name: util_1.default.cloneToken(this.tokens.name)
552
+ }), ['obj']);
325
553
  }
326
554
  }
327
555
  exports.DottedGetExpression = DottedGetExpression;
328
- class XmlAttributeGetExpression extends Expression {
329
- constructor(obj, name, at) {
556
+ class XmlAttributeGetExpression extends AstNode_1.Expression {
557
+ constructor(options) {
330
558
  super();
331
- this.obj = obj;
332
- this.name = name;
333
- this.at = at;
334
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.name.range.end);
559
+ this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
560
+ this.obj = options.obj;
561
+ this.tokens = { at: options.at, name: options.name };
562
+ this.location = util_1.default.createBoundingLocation(this.obj, this.tokens.at, this.tokens.name);
335
563
  }
336
564
  transpile(state) {
337
565
  return [
338
566
  ...this.obj.transpile(state),
339
- '@',
340
- state.transpileToken(this.name)
567
+ state.transpileToken(this.tokens.at, '@'),
568
+ state.transpileToken(this.tokens.name)
341
569
  ];
342
570
  }
343
571
  walk(visitor, options) {
344
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
345
- visitors_1.walk(this, 'obj', visitor, options);
572
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
573
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
346
574
  }
347
575
  }
576
+ get leadingTrivia() {
577
+ return this.obj.leadingTrivia;
578
+ }
579
+ clone() {
580
+ var _a;
581
+ return this.finalizeClone(new XmlAttributeGetExpression({
582
+ obj: (_a = this.obj) === null || _a === void 0 ? void 0 : _a.clone(),
583
+ at: util_1.default.cloneToken(this.tokens.at),
584
+ name: util_1.default.cloneToken(this.tokens.name)
585
+ }), ['obj']);
586
+ }
348
587
  }
349
588
  exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
350
- class IndexedGetExpression extends Expression {
351
- constructor(obj, index, openingSquare, closingSquare) {
589
+ class IndexedGetExpression extends AstNode_1.Expression {
590
+ constructor(options) {
591
+ var _a;
352
592
  super();
353
- this.obj = obj;
354
- this.index = index;
355
- this.openingSquare = openingSquare;
356
- this.closingSquare = closingSquare;
357
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.closingSquare.range.end);
593
+ this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
594
+ this.tokens = {
595
+ openingSquare: options.openingSquare,
596
+ closingSquare: options.closingSquare,
597
+ questionDot: options.questionDot
598
+ };
599
+ this.obj = options.obj;
600
+ this.indexes = options.indexes;
601
+ this.location = util_1.default.createBoundingLocation(this.obj, this.tokens.openingSquare, this.tokens.questionDot, this.tokens.openingSquare, ...(_a = this.indexes) !== null && _a !== void 0 ? _a : [], this.tokens.closingSquare);
358
602
  }
359
603
  transpile(state) {
360
- return [
361
- ...this.obj.transpile(state),
362
- state.transpileToken(this.openingSquare),
363
- ...this.index.transpile(state),
364
- state.transpileToken(this.closingSquare)
365
- ];
604
+ var _a;
605
+ const result = [];
606
+ result.push(...this.obj.transpile(state), this.tokens.questionDot ? state.transpileToken(this.tokens.questionDot) : '', state.transpileToken(this.tokens.openingSquare, '['));
607
+ for (let i = 0; i < this.indexes.length; i++) {
608
+ //add comma between indexes
609
+ if (i > 0) {
610
+ result.push(', ');
611
+ }
612
+ let index = this.indexes[i];
613
+ result.push(...((_a = index === null || index === void 0 ? void 0 : index.transpile(state)) !== null && _a !== void 0 ? _a : []));
614
+ }
615
+ result.push(state.transpileToken(this.tokens.closingSquare, ']'));
616
+ return result;
366
617
  }
367
618
  walk(visitor, options) {
368
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
369
- visitors_1.walk(this, 'obj', visitor, options);
370
- visitors_1.walk(this, 'index', visitor, options);
619
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
620
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
621
+ (0, visitors_2.walkArray)(this.indexes, visitor, options, this);
371
622
  }
372
623
  }
624
+ getType(options) {
625
+ const objType = this.obj.getType(options);
626
+ if ((0, reflection_1.isArrayType)(objType)) {
627
+ // This is used on an array. What is the default type of that array?
628
+ return objType.defaultType;
629
+ }
630
+ return super.getType(options);
631
+ }
632
+ get leadingTrivia() {
633
+ return this.obj.leadingTrivia;
634
+ }
635
+ clone() {
636
+ var _a, _b;
637
+ return this.finalizeClone(new IndexedGetExpression({
638
+ obj: (_a = this.obj) === null || _a === void 0 ? void 0 : _a.clone(),
639
+ questionDot: util_1.default.cloneToken(this.tokens.questionDot),
640
+ openingSquare: util_1.default.cloneToken(this.tokens.openingSquare),
641
+ indexes: (_b = this.indexes) === null || _b === void 0 ? void 0 : _b.map(x => x === null || x === void 0 ? void 0 : x.clone()),
642
+ closingSquare: util_1.default.cloneToken(this.tokens.closingSquare)
643
+ }), ['obj', 'indexes']);
644
+ }
373
645
  }
374
646
  exports.IndexedGetExpression = IndexedGetExpression;
375
- class GroupingExpression extends Expression {
376
- constructor(tokens, expression) {
647
+ class GroupingExpression extends AstNode_1.Expression {
648
+ constructor(options) {
377
649
  super();
378
- this.tokens = tokens;
379
- this.expression = expression;
380
- this.range = util_1.default.createRangeFromPositions(this.tokens.left.range.start, this.tokens.right.range.end);
650
+ this.kind = AstNode_1.AstNodeKind.GroupingExpression;
651
+ this.tokens = {
652
+ rightParen: options.rightParen,
653
+ leftParen: options.leftParen
654
+ };
655
+ this.expression = options.expression;
656
+ this.location = util_1.default.createBoundingLocation(this.tokens.leftParen, this.expression, this.tokens.rightParen);
381
657
  }
382
658
  transpile(state) {
659
+ if ((0, reflection_1.isTypecastExpression)(this.expression)) {
660
+ return this.expression.transpile(state);
661
+ }
383
662
  return [
384
- state.transpileToken(this.tokens.left),
663
+ state.transpileToken(this.tokens.leftParen, '('),
385
664
  ...this.expression.transpile(state),
386
- state.transpileToken(this.tokens.right)
665
+ state.transpileToken(this.tokens.rightParen, ')')
387
666
  ];
388
667
  }
389
668
  walk(visitor, options) {
390
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
391
- visitors_1.walk(this, 'expression', visitor, options);
669
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
670
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
392
671
  }
393
672
  }
673
+ getType(options) {
674
+ return this.expression.getType(options);
675
+ }
676
+ get leadingTrivia() {
677
+ var _a;
678
+ return (_a = this.tokens.leftParen) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
679
+ }
680
+ clone() {
681
+ var _a;
682
+ return this.finalizeClone(new GroupingExpression({
683
+ leftParen: util_1.default.cloneToken(this.tokens.leftParen),
684
+ expression: (_a = this.expression) === null || _a === void 0 ? void 0 : _a.clone(),
685
+ rightParen: util_1.default.cloneToken(this.tokens.rightParen)
686
+ }), ['expression']);
687
+ }
394
688
  }
395
689
  exports.GroupingExpression = GroupingExpression;
396
- class LiteralExpression extends Expression {
397
- constructor(token) {
690
+ class LiteralExpression extends AstNode_1.Expression {
691
+ constructor(options) {
398
692
  super();
399
- this.token = token;
400
- this.type = util_1.default.tokenToBscType(token);
693
+ this.kind = AstNode_1.AstNodeKind.LiteralExpression;
694
+ this.tokens = {
695
+ value: options.value
696
+ };
401
697
  }
402
- get range() {
403
- return this.token.range;
698
+ get location() {
699
+ return this.tokens.value.location;
700
+ }
701
+ getType(options) {
702
+ return util_1.default.tokenToBscType(this.tokens.value);
404
703
  }
405
704
  transpile(state) {
406
705
  let text;
407
- if (this.token.kind === lexer_1.TokenKind.TemplateStringQuasi) {
706
+ if (this.tokens.value.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
408
707
  //wrap quasis with quotes (and escape inner quotemarks)
409
- text = `"${this.token.text.replace(/"/g, '""')}"`;
708
+ text = `"${this.tokens.value.text.replace(/"/g, '""')}"`;
410
709
  }
411
- else if (reflection_1.isStringType(this.type)) {
412
- text = this.token.text;
710
+ else if (this.tokens.value.kind === TokenKind_1.TokenKind.StringLiteral) {
711
+ text = this.tokens.value.text;
413
712
  //add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
414
713
  if (text.endsWith('"') === false) {
415
714
  text += '"';
416
715
  }
417
716
  }
418
717
  else {
419
- text = this.token.text;
718
+ text = this.tokens.value.text;
420
719
  }
421
720
  return [
422
- state.sourceNode(this, text)
721
+ state.transpileToken(Object.assign(Object.assign({}, this.tokens.value), { text: text }))
423
722
  ];
424
723
  }
425
724
  walk(visitor, options) {
426
725
  //nothing to walk
427
726
  }
727
+ get leadingTrivia() {
728
+ return this.tokens.value.leadingTrivia;
729
+ }
730
+ clone() {
731
+ return this.finalizeClone(new LiteralExpression({
732
+ value: util_1.default.cloneToken(this.tokens.value)
733
+ }));
734
+ }
428
735
  }
429
736
  exports.LiteralExpression = LiteralExpression;
737
+ /**
738
+ * The print statement can have a mix of expressions and separators. These separators represent actual output to the screen,
739
+ * so this AstNode represents those separators (comma, semicolon, and whitespace)
740
+ */
741
+ class PrintSeparatorExpression extends AstNode_1.Expression {
742
+ constructor(options) {
743
+ super();
744
+ this.kind = AstNode_1.AstNodeKind.PrintSeparatorExpression;
745
+ this.tokens = {
746
+ separator: options.separator
747
+ };
748
+ this.location = this.tokens.separator.location;
749
+ }
750
+ transpile(state) {
751
+ var _a;
752
+ return [
753
+ ...(_a = this.tokens.separator.leadingWhitespace) !== null && _a !== void 0 ? _a : [],
754
+ ...state.transpileToken(this.tokens.separator)
755
+ ];
756
+ }
757
+ walk(visitor, options) {
758
+ //nothing to walk
759
+ }
760
+ get leadingTrivia() {
761
+ return this.tokens.separator.leadingTrivia;
762
+ }
763
+ clone() {
764
+ var _a;
765
+ return new PrintSeparatorExpression({
766
+ separator: util_1.default.cloneToken((_a = this.tokens) === null || _a === void 0 ? void 0 : _a.separator)
767
+ });
768
+ }
769
+ }
770
+ exports.PrintSeparatorExpression = PrintSeparatorExpression;
430
771
  /**
431
772
  * This is a special expression only used within template strings. It exists so we can prevent producing lots of empty strings
432
773
  * during template string transpile by identifying these expressions explicitly and skipping the bslib_toString around them
433
774
  */
434
- class EscapedCharCodeLiteralExpression extends Expression {
435
- constructor(token) {
775
+ class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
776
+ constructor(options) {
436
777
  super();
437
- this.token = token;
438
- this.range = token.range;
778
+ this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
779
+ this.tokens = { value: options.value };
780
+ this.location = util_1.default.cloneLocation(this.tokens.value.location);
439
781
  }
440
782
  transpile(state) {
441
783
  return [
442
- state.sourceNode(this, `chr(${this.token.charCode})`)
784
+ state.sourceNode(this, `chr(${this.tokens.value.charCode})`)
443
785
  ];
444
786
  }
445
787
  walk(visitor, options) {
446
788
  //nothing to walk
447
789
  }
790
+ clone() {
791
+ return this.finalizeClone(new EscapedCharCodeLiteralExpression({
792
+ value: util_1.default.cloneToken(this.tokens.value)
793
+ }));
794
+ }
448
795
  }
449
796
  exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
450
- class ArrayLiteralExpression extends Expression {
451
- constructor(elements, open, close, hasSpread = false) {
797
+ class ArrayLiteralExpression extends AstNode_1.Expression {
798
+ constructor(options) {
799
+ var _a;
452
800
  super();
453
- this.elements = elements;
454
- this.open = open;
455
- this.close = close;
456
- this.hasSpread = hasSpread;
457
- this.range = util_1.default.createRangeFromPositions(this.open.range.start, this.close.range.end);
801
+ this.kind = AstNode_1.AstNodeKind.ArrayLiteralExpression;
802
+ this.tokens = {
803
+ open: options.open,
804
+ close: options.close
805
+ };
806
+ this.elements = options.elements;
807
+ this.location = util_1.default.createBoundingLocation(this.tokens.open, ...(_a = this.elements) !== null && _a !== void 0 ? _a : [], this.tokens.close);
458
808
  }
459
809
  transpile(state) {
810
+ var _a;
460
811
  let result = [];
461
- result.push(state.transpileToken(this.open));
812
+ result.push(state.transpileToken(this.tokens.open, '['));
462
813
  let hasChildren = this.elements.length > 0;
463
814
  state.blockDepth++;
464
815
  for (let i = 0; i < this.elements.length; i++) {
465
816
  let previousElement = this.elements[i - 1];
466
817
  let element = this.elements[i];
467
- if (reflection_1.isCommentStatement(element)) {
468
- //if the comment is on the same line as opening square or previous statement, don't add newline
469
- if (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element)) {
470
- result.push(' ');
471
- }
472
- else {
473
- result.push('\n', state.indent());
474
- }
475
- state.lineage.unshift(this);
476
- result.push(element.transpile(state));
477
- state.lineage.shift();
818
+ if (util_1.default.isLeadingCommentOnSameLine(previousElement !== null && previousElement !== void 0 ? previousElement : this.tokens.open, element)) {
819
+ result.push(' ');
478
820
  }
479
821
  else {
480
- result.push('\n');
481
- result.push(state.indent(), ...element.transpile(state));
482
- //add a comma if we know there will be another non-comment statement after this
483
- for (let j = i + 1; j < this.elements.length; j++) {
484
- let el = this.elements[j];
485
- //add a comma if there will be another element after this
486
- if (reflection_1.isCommentStatement(el) === false) {
487
- result.push(',');
488
- break;
489
- }
490
- }
822
+ result.push('\n', state.indent());
491
823
  }
824
+ result.push(...element.transpile(state));
492
825
  }
493
826
  state.blockDepth--;
494
827
  //add a newline between open and close if there are elements
495
- if (hasChildren) {
496
- result.push('\n');
497
- result.push(state.indent());
498
- }
499
- result.push(state.transpileToken(this.close));
828
+ const lastLocatable = (_a = this.elements[this.elements.length - 1]) !== null && _a !== void 0 ? _a : this.tokens.open;
829
+ result.push(...state.transpileEndBlockToken(lastLocatable, this.tokens.close, ']', hasChildren));
500
830
  return result;
501
831
  }
502
832
  walk(visitor, options) {
503
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
504
- for (let i = 0; i < this.elements.length; i++) {
505
- visitors_1.walk(this.elements, i, visitor, options, this);
506
- }
833
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
834
+ (0, visitors_2.walkArray)(this.elements, visitor, options, this);
507
835
  }
508
836
  }
837
+ getType(options) {
838
+ const innerTypes = this.elements.map(expr => expr.getType(options));
839
+ return new ArrayType_1.ArrayType(...innerTypes);
840
+ }
841
+ get leadingTrivia() {
842
+ var _a;
843
+ return (_a = this.tokens.open) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
844
+ }
845
+ get endTrivia() {
846
+ var _a;
847
+ return (_a = this.tokens.close) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
848
+ }
849
+ clone() {
850
+ var _a;
851
+ return this.finalizeClone(new ArrayLiteralExpression({
852
+ elements: (_a = this.elements) === null || _a === void 0 ? void 0 : _a.map(e => e === null || e === void 0 ? void 0 : e.clone()),
853
+ open: util_1.default.cloneToken(this.tokens.open),
854
+ close: util_1.default.cloneToken(this.tokens.close)
855
+ }), ['elements']);
856
+ }
509
857
  }
510
858
  exports.ArrayLiteralExpression = ArrayLiteralExpression;
511
- class AAMemberExpression extends Expression {
512
- constructor(keyToken, colonToken,
513
- /** The expression evaluated to determine the member's initial value. */
514
- value) {
859
+ class AAMemberExpression extends AstNode_1.Expression {
860
+ constructor(options) {
515
861
  super();
516
- this.keyToken = keyToken;
517
- this.colonToken = colonToken;
518
- this.value = value;
519
- this.range = util_1.default.createRangeFromPositions(keyToken.range.start, this.value.range.end);
862
+ this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
863
+ this.tokens = {
864
+ key: options.key,
865
+ colon: options.colon,
866
+ comma: options.comma
867
+ };
868
+ this.value = options.value;
869
+ this.location = util_1.default.createBoundingLocation(this.tokens.key, this.tokens.colon, this.value);
520
870
  }
521
871
  transpile(state) {
522
872
  //TODO move the logic from AALiteralExpression loop into this function
523
873
  return [];
524
874
  }
525
875
  walk(visitor, options) {
526
- visitors_1.walk(this, 'value', visitor, options);
876
+ (0, visitors_2.walk)(this, 'value', visitor, options);
877
+ }
878
+ getType(options) {
879
+ return this.value.getType(options);
880
+ }
881
+ get leadingTrivia() {
882
+ return this.tokens.key.leadingTrivia;
883
+ }
884
+ clone() {
885
+ var _a;
886
+ return this.finalizeClone(new AAMemberExpression({
887
+ key: util_1.default.cloneToken(this.tokens.key),
888
+ colon: util_1.default.cloneToken(this.tokens.colon),
889
+ value: (_a = this.value) === null || _a === void 0 ? void 0 : _a.clone()
890
+ }), ['value']);
527
891
  }
528
892
  }
529
893
  exports.AAMemberExpression = AAMemberExpression;
530
- class AALiteralExpression extends Expression {
531
- constructor(elements, open, close) {
894
+ class AALiteralExpression extends AstNode_1.Expression {
895
+ constructor(options) {
896
+ var _a;
532
897
  super();
533
- this.elements = elements;
534
- this.open = open;
535
- this.close = close;
536
- this.range = util_1.default.createRangeFromPositions(this.open.range.start, this.close.range.end);
898
+ this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
899
+ this.tokens = {
900
+ open: options.open,
901
+ close: options.close
902
+ };
903
+ this.elements = options.elements;
904
+ this.location = util_1.default.createBoundingLocation(this.tokens.open, ...(_a = this.elements) !== null && _a !== void 0 ? _a : [], this.tokens.close);
537
905
  }
538
906
  transpile(state) {
907
+ var _a;
539
908
  let result = [];
540
909
  //open curly
541
- result.push(state.transpileToken(this.open));
910
+ result.push(state.transpileToken(this.tokens.open, '{'));
542
911
  let hasChildren = this.elements.length > 0;
543
912
  //add newline if the object has children and the first child isn't a comment starting on the same line as opening curly
544
- if (hasChildren && (reflection_1.isCommentStatement(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.open))) {
913
+ if (hasChildren && !util_1.default.isLeadingCommentOnSameLine(this.tokens.open, this.elements[0])) {
545
914
  result.push('\n');
546
915
  }
547
916
  state.blockDepth++;
@@ -550,170 +919,282 @@ class AALiteralExpression extends Expression {
550
919
  let previousElement = this.elements[i - 1];
551
920
  let nextElement = this.elements[i + 1];
552
921
  //don't indent if comment is same-line
553
- if (reflection_1.isCommentStatement(element) &&
554
- (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element))) {
922
+ if (util_1.default.isLeadingCommentOnSameLine(this.tokens.open, element) ||
923
+ util_1.default.isLeadingCommentOnSameLine(previousElement, element)) {
555
924
  result.push(' ');
556
- //indent line
557
925
  }
558
926
  else {
927
+ //indent line
559
928
  result.push(state.indent());
560
929
  }
561
- //render comments
562
- if (reflection_1.isCommentStatement(element)) {
563
- result.push(...element.transpile(state));
564
- }
565
- else {
566
- //key
567
- result.push(state.transpileToken(element.keyToken));
568
- //colon
569
- result.push(state.transpileToken(element.colonToken), ' ');
570
- //determine if comments are the only members left in the array
571
- let onlyCommentsRemaining = true;
572
- for (let j = i + 1; j < this.elements.length; j++) {
573
- if (reflection_1.isCommentStatement(this.elements[j]) === false) {
574
- onlyCommentsRemaining = false;
575
- break;
576
- }
577
- }
578
- //value
579
- result.push(...element.value.transpile(state));
580
- //add trailing comma if not final element (excluding comments)
581
- if (i !== this.elements.length - 1 && onlyCommentsRemaining === false) {
582
- result.push(',');
583
- }
584
- }
930
+ //key
931
+ result.push(state.transpileToken(element.tokens.key));
932
+ //colon
933
+ result.push(state.transpileToken(element.tokens.colon, ':'), ' ');
934
+ //value
935
+ result.push(...element.value.transpile(state));
585
936
  //if next element is a same-line comment, skip the newline
586
- if (nextElement && reflection_1.isCommentStatement(nextElement) && nextElement.range.start.line === element.range.start.line) {
937
+ if (nextElement && !util_1.default.isLeadingCommentOnSameLine(element, nextElement)) {
587
938
  //add a newline between statements
588
- }
589
- else {
590
939
  result.push('\n');
591
940
  }
592
941
  }
593
942
  state.blockDepth--;
594
- //only indent the closing curly if we have children
595
- if (hasChildren) {
596
- result.push(state.indent());
597
- }
598
- //close curly
599
- result.push(state.transpileToken(this.close));
943
+ const lastElement = (_a = this.elements[this.elements.length - 1]) !== null && _a !== void 0 ? _a : this.tokens.open;
944
+ result.push(...state.transpileEndBlockToken(lastElement, this.tokens.close, '}', hasChildren));
600
945
  return result;
601
946
  }
602
947
  walk(visitor, options) {
603
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
604
- for (let i = 0; i < this.elements.length; i++) {
605
- if (reflection_1.isCommentStatement(this.elements[i])) {
606
- visitors_1.walk(this.elements, i, visitor, options, this);
948
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
949
+ (0, visitors_2.walkArray)(this.elements, visitor, options, this);
950
+ }
951
+ }
952
+ getType(options) {
953
+ var _a, _b, _c;
954
+ const resultType = new AssociativeArrayType_1.AssociativeArrayType();
955
+ resultType.addBuiltInInterfaces();
956
+ for (const element of this.elements) {
957
+ if ((0, reflection_1.isAAMemberExpression)(element)) {
958
+ let memberName = (_c = (_b = (_a = element.tokens) === null || _a === void 0 ? void 0 : _a.key) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : '';
959
+ if (element.tokens.key.kind === TokenKind_1.TokenKind.StringLiteral) {
960
+ memberName = memberName.replace(/"/g, ''); // remove quotes if it was a stringLiteral
607
961
  }
608
- else {
609
- visitors_1.walk(this.elements, i, visitor, options, this);
962
+ if (memberName) {
963
+ resultType.addMember(memberName, { definingNode: element }, element.getType(options), 1 /* SymbolTypeFlag.runtime */);
610
964
  }
611
965
  }
612
966
  }
967
+ return resultType;
968
+ }
969
+ get leadingTrivia() {
970
+ var _a;
971
+ return (_a = this.tokens.open) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
972
+ }
973
+ get endTrivia() {
974
+ var _a;
975
+ return (_a = this.tokens.close) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
976
+ }
977
+ clone() {
978
+ var _a;
979
+ return this.finalizeClone(new AALiteralExpression({
980
+ elements: (_a = this.elements) === null || _a === void 0 ? void 0 : _a.map(e => e === null || e === void 0 ? void 0 : e.clone()),
981
+ open: util_1.default.cloneToken(this.tokens.open),
982
+ close: util_1.default.cloneToken(this.tokens.close)
983
+ }), ['elements']);
613
984
  }
614
985
  }
615
986
  exports.AALiteralExpression = AALiteralExpression;
616
- class UnaryExpression extends Expression {
617
- constructor(operator, right) {
987
+ class UnaryExpression extends AstNode_1.Expression {
988
+ constructor(options) {
618
989
  super();
619
- this.operator = operator;
620
- this.right = right;
621
- this.range = util_1.default.createRangeFromPositions(this.operator.range.start, this.right.range.end);
990
+ this.kind = AstNode_1.AstNodeKind.UnaryExpression;
991
+ this.tokens = {
992
+ operator: options.operator
993
+ };
994
+ this.right = options.right;
995
+ this.location = util_1.default.createBoundingLocation(this.tokens.operator, this.right);
622
996
  }
623
997
  transpile(state) {
998
+ let separatingWhitespace;
999
+ if ((0, reflection_1.isVariableExpression)(this.right)) {
1000
+ separatingWhitespace = this.right.tokens.name.leadingWhitespace;
1001
+ }
1002
+ else if ((0, reflection_1.isLiteralExpression)(this.right)) {
1003
+ separatingWhitespace = this.right.tokens.value.leadingWhitespace;
1004
+ }
1005
+ else {
1006
+ separatingWhitespace = ' ';
1007
+ }
624
1008
  return [
625
- state.transpileToken(this.operator),
626
- ' ',
1009
+ state.transpileToken(this.tokens.operator),
1010
+ separatingWhitespace,
627
1011
  ...this.right.transpile(state)
628
1012
  ];
629
1013
  }
630
1014
  walk(visitor, options) {
631
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
632
- visitors_1.walk(this, 'right', visitor, options);
1015
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1016
+ (0, visitors_2.walk)(this, 'right', visitor, options);
633
1017
  }
634
1018
  }
1019
+ getType(options) {
1020
+ return util_1.default.unaryOperatorResultType(this.tokens.operator, this.right.getType(options));
1021
+ }
1022
+ get leadingTrivia() {
1023
+ return this.tokens.operator.leadingTrivia;
1024
+ }
1025
+ clone() {
1026
+ var _a;
1027
+ return this.finalizeClone(new UnaryExpression({
1028
+ operator: util_1.default.cloneToken(this.tokens.operator),
1029
+ right: (_a = this.right) === null || _a === void 0 ? void 0 : _a.clone()
1030
+ }), ['right']);
1031
+ }
635
1032
  }
636
1033
  exports.UnaryExpression = UnaryExpression;
637
- class VariableExpression extends Expression {
638
- constructor(name, namespaceName) {
1034
+ class VariableExpression extends AstNode_1.Expression {
1035
+ constructor(options) {
1036
+ var _a;
639
1037
  super();
640
- this.name = name;
641
- this.namespaceName = namespaceName;
642
- this.range = this.name.range;
1038
+ this.kind = AstNode_1.AstNodeKind.VariableExpression;
1039
+ this.tokens = {
1040
+ name: options.name
1041
+ };
1042
+ this.location = util_1.default.cloneLocation((_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.location);
643
1043
  }
644
1044
  getName(parseMode) {
645
- return parseMode === Parser_1.ParseMode.BrightScript ? this.name.text : this.name.text;
1045
+ return this.tokens.name.text;
646
1046
  }
647
1047
  transpile(state) {
648
- var _a;
649
1048
  let result = [];
1049
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
650
1050
  //if the callee is the name of a known namespace function
651
- if (state.file.calleeIsKnownNamespaceFunction(this, (_a = this.namespaceName) === null || _a === void 0 ? void 0 : _a.getName(Parser_1.ParseMode.BrighterScript))) {
652
- result.push(state.sourceNode(this, [
653
- this.namespaceName.getName(Parser_1.ParseMode.BrightScript),
1051
+ if (namespace && util_1.default.isCalleeMemberOfNamespace(this.tokens.name.text, this, namespace)) {
1052
+ result.push(
1053
+ //transpile leading comments since the token isn't being transpiled directly
1054
+ ...state.transpileLeadingCommentsForAstNode(this), state.sourceNode(this, [
1055
+ namespace.getName(Parser_1.ParseMode.BrightScript),
654
1056
  '_',
655
1057
  this.getName(Parser_1.ParseMode.BrightScript)
656
1058
  ]));
657
1059
  //transpile normally
658
1060
  }
659
1061
  else {
660
- result.push(state.transpileToken(this.name));
1062
+ result.push(state.transpileToken(this.tokens.name));
661
1063
  }
662
1064
  return result;
663
1065
  }
1066
+ getTypedef(state) {
1067
+ return [
1068
+ state.transpileToken(this.tokens.name)
1069
+ ];
1070
+ }
664
1071
  walk(visitor, options) {
665
1072
  //nothing to walk
666
1073
  }
1074
+ getType(options) {
1075
+ var _a;
1076
+ let resultType = util_1.default.tokenToBscType(this.tokens.name);
1077
+ const nameKey = this.getName();
1078
+ if (!resultType) {
1079
+ const symbolTable = this.getSymbolTable();
1080
+ resultType = symbolTable === null || symbolTable === void 0 ? void 0 : symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { statementIndex: this.statementIndex, fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
1081
+ if (util_1.default.isClassUsedAsFunction(resultType, this, options)) {
1082
+ resultType = FunctionType_1.FunctionType.instance;
1083
+ }
1084
+ }
1085
+ (_a = options === null || options === void 0 ? void 0 : options.typeChain) === null || _a === void 0 ? void 0 : _a.push(new interfaces_1.TypeChainEntry({ name: nameKey, type: resultType, data: options.data, astNode: this }));
1086
+ return resultType;
1087
+ }
1088
+ get leadingTrivia() {
1089
+ return this.tokens.name.leadingTrivia;
1090
+ }
1091
+ clone() {
1092
+ return this.finalizeClone(new VariableExpression({
1093
+ name: util_1.default.cloneToken(this.tokens.name)
1094
+ }));
1095
+ }
667
1096
  }
668
1097
  exports.VariableExpression = VariableExpression;
669
- class SourceLiteralExpression extends Expression {
670
- constructor(token) {
1098
+ class SourceLiteralExpression extends AstNode_1.Expression {
1099
+ constructor(options) {
1100
+ var _a;
671
1101
  super();
672
- this.token = token;
673
- this.range = token.range;
1102
+ this.kind = AstNode_1.AstNodeKind.SourceLiteralExpression;
1103
+ this.tokens = {
1104
+ value: options.value
1105
+ };
1106
+ this.location = util_1.default.cloneLocation((_a = this.tokens.value) === null || _a === void 0 ? void 0 : _a.location);
1107
+ }
1108
+ /**
1109
+ * Find the index of the function in its parent
1110
+ */
1111
+ findFunctionIndex(parentFunction, func) {
1112
+ let index = -1;
1113
+ parentFunction.findChild((node) => {
1114
+ if ((0, reflection_1.isFunctionExpression)(node)) {
1115
+ index++;
1116
+ if (node === func) {
1117
+ return true;
1118
+ }
1119
+ }
1120
+ }, {
1121
+ walkMode: visitors_1.WalkMode.visitAllRecursive
1122
+ });
1123
+ return index;
674
1124
  }
675
1125
  getFunctionName(state, parseMode) {
676
- let functionExpression = state.file.getFunctionExpressionAtPosition(this.token.range.start);
1126
+ let func = this.findAncestor(reflection_1.isFunctionExpression);
677
1127
  let nameParts = [];
678
- while (functionExpression.parentFunction) {
679
- let index = functionExpression.parentFunction.childFunctionExpressions.indexOf(functionExpression);
1128
+ let parentFunction;
1129
+ while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
1130
+ let index = this.findFunctionIndex(parentFunction, func);
680
1131
  nameParts.unshift(`anon${index}`);
681
- functionExpression = functionExpression.parentFunction;
1132
+ func = parentFunction;
682
1133
  }
683
1134
  //get the index of this function in its parent
684
- nameParts.unshift(functionExpression.functionStatement.getName(parseMode));
1135
+ if ((0, reflection_1.isFunctionStatement)(func.parent)) {
1136
+ nameParts.unshift(func.parent.getName(parseMode));
1137
+ }
685
1138
  return nameParts.join('$');
686
1139
  }
1140
+ /**
1141
+ * Get the line number from our token or from the closest ancestor that has a range
1142
+ */
1143
+ getClosestLineNumber() {
1144
+ var _a;
1145
+ let node = this;
1146
+ while (node) {
1147
+ if ((_a = node.location) === null || _a === void 0 ? void 0 : _a.range) {
1148
+ return node.location.range.start.line + 1;
1149
+ }
1150
+ node = node.parent;
1151
+ }
1152
+ return -1;
1153
+ }
687
1154
  transpile(state) {
1155
+ var _a;
688
1156
  let text;
689
- switch (this.token.kind) {
690
- case lexer_1.TokenKind.SourceFilePathLiteral:
1157
+ switch (this.tokens.value.kind) {
1158
+ case TokenKind_1.TokenKind.SourceFilePathLiteral:
691
1159
  const pathUrl = fileUrl(state.srcPath);
692
1160
  text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
693
1161
  break;
694
- case lexer_1.TokenKind.SourceLineNumLiteral:
695
- text = `${this.token.range.start.line + 1}`;
1162
+ case TokenKind_1.TokenKind.SourceLineNumLiteral:
1163
+ //TODO find first parent that has range, or default to -1
1164
+ text = `${this.getClosestLineNumber()}`;
696
1165
  break;
697
- case lexer_1.TokenKind.FunctionNameLiteral:
1166
+ case TokenKind_1.TokenKind.FunctionNameLiteral:
698
1167
  text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
699
1168
  break;
700
- case lexer_1.TokenKind.SourceFunctionNameLiteral:
1169
+ case TokenKind_1.TokenKind.SourceFunctionNameLiteral:
701
1170
  text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrighterScript)}"`;
702
1171
  break;
703
- case lexer_1.TokenKind.SourceLocationLiteral:
1172
+ case TokenKind_1.TokenKind.SourceNamespaceNameLiteral:
1173
+ let namespaceParts = this.getFunctionName(state, Parser_1.ParseMode.BrighterScript).split('.');
1174
+ namespaceParts.pop(); // remove the function name
1175
+ text = `"${namespaceParts.join('.')}"`;
1176
+ break;
1177
+ case TokenKind_1.TokenKind.SourceNamespaceRootNameLiteral:
1178
+ let namespaceRootParts = this.getFunctionName(state, Parser_1.ParseMode.BrighterScript).split('.');
1179
+ namespaceRootParts.pop(); // remove the function name
1180
+ let rootNamespace = (_a = namespaceRootParts.shift()) !== null && _a !== void 0 ? _a : '';
1181
+ text = `"${rootNamespace}"`;
1182
+ break;
1183
+ case TokenKind_1.TokenKind.SourceLocationLiteral:
704
1184
  const locationUrl = fileUrl(state.srcPath);
705
- text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
1185
+ //TODO find first parent that has range, or default to -1
1186
+ text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.getClosestLineNumber()}"`;
706
1187
  break;
707
- case lexer_1.TokenKind.PkgPathLiteral:
708
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}"`;
1188
+ case TokenKind_1.TokenKind.PkgPathLiteral:
1189
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
709
1190
  break;
710
- case lexer_1.TokenKind.PkgLocationLiteral:
711
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}:" + str(LINE_NUM)`;
1191
+ case TokenKind_1.TokenKind.PkgLocationLiteral:
1192
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}:" + str(LINE_NUM)`;
712
1193
  break;
713
- case lexer_1.TokenKind.LineNumLiteral:
1194
+ case TokenKind_1.TokenKind.LineNumLiteral:
714
1195
  default:
715
1196
  //use the original text (because it looks like a variable)
716
- text = this.token.text;
1197
+ text = this.tokens.value.text;
717
1198
  break;
718
1199
  }
719
1200
  return [
@@ -723,6 +1204,14 @@ class SourceLiteralExpression extends Expression {
723
1204
  walk(visitor, options) {
724
1205
  //nothing to walk
725
1206
  }
1207
+ get leadingTrivia() {
1208
+ return this.tokens.value.leadingTrivia;
1209
+ }
1210
+ clone() {
1211
+ return this.finalizeClone(new SourceLiteralExpression({
1212
+ value: util_1.default.cloneToken(this.tokens.value)
1213
+ }));
1214
+ }
726
1215
  }
727
1216
  exports.SourceLiteralExpression = SourceLiteralExpression;
728
1217
  /**
@@ -730,61 +1219,84 @@ exports.SourceLiteralExpression = SourceLiteralExpression;
730
1219
  * except we need to uniquely identify these statements so we can
731
1220
  * do more type checking.
732
1221
  */
733
- class NewExpression extends Expression {
734
- constructor(newKeyword, call) {
1222
+ class NewExpression extends AstNode_1.Expression {
1223
+ constructor(options) {
735
1224
  super();
736
- this.newKeyword = newKeyword;
737
- this.call = call;
738
- this.range = util_1.default.createRangeFromPositions(this.newKeyword.range.start, this.call.range.end);
1225
+ this.kind = AstNode_1.AstNodeKind.NewExpression;
1226
+ this.tokens = {
1227
+ new: options.new
1228
+ };
1229
+ this.call = options.call;
1230
+ this.location = util_1.default.createBoundingLocation(this.tokens.new, this.call);
739
1231
  }
740
1232
  /**
741
1233
  * The name of the class to initialize (with optional namespace prefixed)
742
1234
  */
743
1235
  get className() {
744
1236
  //the parser guarantees the callee of a new statement's call object will be
745
- //a NamespacedVariableNameExpression
1237
+ //either a VariableExpression or a DottedGet
746
1238
  return this.call.callee;
747
1239
  }
748
- get namespaceName() {
749
- return this.call.namespaceName;
750
- }
751
1240
  transpile(state) {
752
- var _a, _b;
753
- 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;
1241
+ var _a;
1242
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
1243
+ 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;
754
1244
  //new statements within a namespace block can omit the leading namespace if the class resides in that same namespace.
755
1245
  //So we need to figure out if this is a namespace-omitted class, or if this class exists without a namespace.
756
1246
  return this.call.transpile(state, cls === null || cls === void 0 ? void 0 : cls.getName(Parser_1.ParseMode.BrightScript));
757
1247
  }
758
1248
  walk(visitor, options) {
759
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
760
- visitors_1.walk(this, 'call', visitor, options);
1249
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1250
+ (0, visitors_2.walk)(this, 'call', visitor, options);
1251
+ }
1252
+ }
1253
+ getType(options) {
1254
+ const result = this.call.getType(options);
1255
+ if (options.typeChain) {
1256
+ // modify last typechain entry to show it is a new ...()
1257
+ const lastEntry = options.typeChain[options.typeChain.length - 1];
1258
+ if (lastEntry) {
1259
+ lastEntry.astNode = this;
1260
+ }
761
1261
  }
1262
+ return result;
1263
+ }
1264
+ get leadingTrivia() {
1265
+ return this.tokens.new.leadingTrivia;
1266
+ }
1267
+ clone() {
1268
+ var _a;
1269
+ return this.finalizeClone(new NewExpression({
1270
+ new: util_1.default.cloneToken(this.tokens.new),
1271
+ call: (_a = this.call) === null || _a === void 0 ? void 0 : _a.clone()
1272
+ }), ['call']);
762
1273
  }
763
1274
  }
764
1275
  exports.NewExpression = NewExpression;
765
- class CallfuncExpression extends Expression {
766
- constructor(callee, operator, methodName, openingParen, args, closingParen) {
767
- var _a, _b, _c;
1276
+ class CallfuncExpression extends AstNode_1.Expression {
1277
+ constructor(options) {
1278
+ var _a, _b;
768
1279
  super();
769
- this.callee = callee;
770
- this.operator = operator;
771
- this.methodName = methodName;
772
- this.openingParen = openingParen;
773
- this.args = args;
774
- this.closingParen = closingParen;
775
- this.range = util_1.default.createRangeFromPositions(callee.range.start, ((_c = (_b = (_a = closingParen !== null && closingParen !== void 0 ? closingParen : args[args.length - 1]) !== null && _a !== void 0 ? _a : openingParen) !== null && _b !== void 0 ? _b : methodName) !== null && _c !== void 0 ? _c : operator).range.end);
1280
+ this.kind = AstNode_1.AstNodeKind.CallfuncExpression;
1281
+ this.tokens = {
1282
+ operator: options.operator,
1283
+ methodName: options.methodName,
1284
+ openingParen: options.openingParen,
1285
+ closingParen: options.closingParen
1286
+ };
1287
+ this.callee = options.callee;
1288
+ this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
1289
+ this.location = util_1.default.createBoundingLocation(this.callee, this.tokens.operator, this.tokens.methodName, this.tokens.openingParen, ...(_b = this.args) !== null && _b !== void 0 ? _b : [], this.tokens.closingParen);
776
1290
  }
777
1291
  transpile(state) {
1292
+ var _a;
778
1293
  let result = [];
779
- result.push(...this.callee.transpile(state), state.sourceNode(this.operator, '.callfunc'), state.transpileToken(this.openingParen),
1294
+ result.push(...this.callee.transpile(state), state.sourceNode(this.tokens.operator, '.callfunc'), state.transpileToken(this.tokens.openingParen, '('),
780
1295
  //the name of the function
781
- state.sourceNode(this.methodName, ['"', this.methodName.text, '"']), ', ');
782
- //transpile args
783
- //callfunc with zero args never gets called, so pass invalid as the first parameter if there are no args
784
- if (this.args.length === 0) {
785
- result.push('invalid');
786
- }
787
- else {
1296
+ state.sourceNode(this.tokens.methodName, ['"', this.tokens.methodName.text, '"']));
1297
+ if (((_a = this.args) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1298
+ result.push(', ');
1299
+ //transpile args
788
1300
  for (let i = 0; i < this.args.length; i++) {
789
1301
  //add comma between args
790
1302
  if (i > 0) {
@@ -794,28 +1306,50 @@ class CallfuncExpression extends Expression {
794
1306
  result.push(...arg.transpile(state));
795
1307
  }
796
1308
  }
797
- result.push(state.transpileToken(this.closingParen));
1309
+ else if (state.options.legacyCallfuncHandling) {
1310
+ result.push(', ', 'invalid');
1311
+ }
1312
+ result.push(state.transpileToken(this.tokens.closingParen, ')'));
798
1313
  return result;
799
1314
  }
800
1315
  walk(visitor, options) {
801
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
802
- visitors_1.walk(this, 'callee', visitor, options);
803
- for (let i = 0; i < this.args.length; i++) {
804
- visitors_1.walk(this.args, i, visitor, options, this);
805
- }
1316
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1317
+ (0, visitors_2.walk)(this, 'callee', visitor, options);
1318
+ (0, visitors_2.walkArray)(this.args, visitor, options, this);
806
1319
  }
807
1320
  }
1321
+ getType(options) {
1322
+ var _a;
1323
+ const result = (_a = util_1.default.getCallFuncType(this, this.tokens.methodName, options)) !== null && _a !== void 0 ? _a : DynamicType_1.DynamicType.instance;
1324
+ return result;
1325
+ }
1326
+ get leadingTrivia() {
1327
+ return this.callee.leadingTrivia;
1328
+ }
1329
+ clone() {
1330
+ var _a, _b;
1331
+ return this.finalizeClone(new CallfuncExpression({
1332
+ callee: (_a = this.callee) === null || _a === void 0 ? void 0 : _a.clone(),
1333
+ operator: util_1.default.cloneToken(this.tokens.operator),
1334
+ methodName: util_1.default.cloneToken(this.tokens.methodName),
1335
+ openingParen: util_1.default.cloneToken(this.tokens.openingParen),
1336
+ args: (_b = this.args) === null || _b === void 0 ? void 0 : _b.map(e => e === null || e === void 0 ? void 0 : e.clone()),
1337
+ closingParen: util_1.default.cloneToken(this.tokens.closingParen)
1338
+ }), ['callee', 'args']);
1339
+ }
808
1340
  }
809
1341
  exports.CallfuncExpression = CallfuncExpression;
810
1342
  /**
811
1343
  * Since template strings can contain newlines, we need to concatenate multiple strings together with chr() calls.
812
1344
  * This is a single expression that represents the string contatenation of all parts of a single quasi.
813
1345
  */
814
- class TemplateStringQuasiExpression extends Expression {
815
- constructor(expressions) {
1346
+ class TemplateStringQuasiExpression extends AstNode_1.Expression {
1347
+ constructor(options) {
1348
+ var _a;
816
1349
  super();
817
- this.expressions = expressions;
818
- this.range = util_1.default.createRangeFromPositions(this.expressions[0].range.start, this.expressions[this.expressions.length - 1].range.end);
1350
+ this.kind = AstNode_1.AstNodeKind.TemplateStringQuasiExpression;
1351
+ this.expressions = options.expressions;
1352
+ this.location = util_1.default.createBoundingLocation(...(_a = this.expressions) !== null && _a !== void 0 ? _a : []);
819
1353
  }
820
1354
  transpile(state, skipEmptyStrings = true) {
821
1355
  let result = [];
@@ -823,7 +1357,7 @@ class TemplateStringQuasiExpression extends Expression {
823
1357
  for (let expression of this.expressions) {
824
1358
  //skip empty strings
825
1359
  //TODO what does an empty string literal expression look like?
826
- if (expression.token.text === '' && skipEmptyStrings === true) {
1360
+ if (expression.tokens.value.text === '' && skipEmptyStrings === true) {
827
1361
  continue;
828
1362
  }
829
1363
  result.push(plus, ...expression.transpile(state));
@@ -832,28 +1366,40 @@ class TemplateStringQuasiExpression extends Expression {
832
1366
  return result;
833
1367
  }
834
1368
  walk(visitor, options) {
835
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
836
- for (let i = 0; i < this.expressions.length; i++) {
837
- visitors_1.walk(this.expressions, i, visitor, options, this);
838
- }
1369
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1370
+ (0, visitors_2.walkArray)(this.expressions, visitor, options, this);
839
1371
  }
840
1372
  }
1373
+ clone() {
1374
+ var _a;
1375
+ return this.finalizeClone(new TemplateStringQuasiExpression({
1376
+ expressions: (_a = this.expressions) === null || _a === void 0 ? void 0 : _a.map(e => e === null || e === void 0 ? void 0 : e.clone())
1377
+ }), ['expressions']);
1378
+ }
841
1379
  }
842
1380
  exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
843
- class TemplateStringExpression extends Expression {
844
- constructor(openingBacktick, quasis, expressions, closingBacktick) {
1381
+ class TemplateStringExpression extends AstNode_1.Expression {
1382
+ constructor(options) {
1383
+ var _a, _b, _c;
845
1384
  super();
846
- this.openingBacktick = openingBacktick;
847
- this.quasis = quasis;
848
- this.expressions = expressions;
849
- this.closingBacktick = closingBacktick;
850
- this.range = util_1.default.createRangeFromPositions(quasis[0].range.start, quasis[quasis.length - 1].range.end);
1385
+ this.kind = AstNode_1.AstNodeKind.TemplateStringExpression;
1386
+ this.tokens = {
1387
+ openingBacktick: options.openingBacktick,
1388
+ closingBacktick: options.closingBacktick
1389
+ };
1390
+ this.quasis = options.quasis;
1391
+ this.expressions = options.expressions;
1392
+ this.location = util_1.default.createBoundingLocation(this.tokens.openingBacktick, (_a = this.quasis) === null || _a === void 0 ? void 0 : _a[0], (_b = this.quasis) === null || _b === void 0 ? void 0 : _b[((_c = this.quasis) === null || _c === void 0 ? void 0 : _c.length) - 1], this.tokens.closingBacktick);
1393
+ }
1394
+ getType(options) {
1395
+ return StringType_1.StringType.instance;
851
1396
  }
852
1397
  transpile(state) {
853
- if (this.quasis.length === 1 && this.expressions.length === 0) {
1398
+ //if this is essentially just a normal brightscript string but with backticks, transpile it as a normal string without parens
1399
+ if (this.expressions.length === 0 && this.quasis.length === 1 && this.quasis[0].expressions.length === 1) {
854
1400
  return this.quasis[0].transpile(state);
855
1401
  }
856
- let result = [];
1402
+ let result = ['('];
857
1403
  let plus = '';
858
1404
  //helper function to figure out when to include the plus
859
1405
  function add(...items) {
@@ -871,8 +1417,8 @@ class TemplateStringExpression extends Expression {
871
1417
  add(...quasi.transpile(state));
872
1418
  if (expression) {
873
1419
  //skip the toString wrapper around certain expressions
874
- if (reflection_1.isEscapedCharCodeLiteralExpression(expression) ||
875
- (reflection_1.isLiteralExpression(expression) && reflection_1.isStringType(expression.type))) {
1420
+ if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
1421
+ ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.getType()))) {
876
1422
  add(...expression.transpile(state));
877
1423
  //wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
878
1424
  }
@@ -881,35 +1427,51 @@ class TemplateStringExpression extends Expression {
881
1427
  }
882
1428
  }
883
1429
  }
1430
+ //the expression should be wrapped in parens so it can be used line a single expression at runtime
1431
+ result.push(')');
884
1432
  return result;
885
1433
  }
886
1434
  walk(visitor, options) {
887
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1435
+ var _a;
1436
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
888
1437
  //walk the quasis and expressions in left-to-right order
889
- for (let i = 0; i < this.quasis.length; i++) {
890
- visitors_1.walk(this.quasis, i, visitor, options, this);
1438
+ for (let i = 0; i < ((_a = this.quasis) === null || _a === void 0 ? void 0 : _a.length); i++) {
1439
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
891
1440
  //this skips the final loop iteration since we'll always have one more quasi than expression
892
1441
  if (this.expressions[i]) {
893
- visitors_1.walk(this.expressions, i, visitor, options, this);
1442
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
894
1443
  }
895
1444
  }
896
1445
  }
897
1446
  }
1447
+ clone() {
1448
+ var _a, _b;
1449
+ return this.finalizeClone(new TemplateStringExpression({
1450
+ openingBacktick: util_1.default.cloneToken(this.tokens.openingBacktick),
1451
+ quasis: (_a = this.quasis) === null || _a === void 0 ? void 0 : _a.map(e => e === null || e === void 0 ? void 0 : e.clone()),
1452
+ expressions: (_b = this.expressions) === null || _b === void 0 ? void 0 : _b.map(e => e === null || e === void 0 ? void 0 : e.clone()),
1453
+ closingBacktick: util_1.default.cloneToken(this.tokens.closingBacktick)
1454
+ }), ['quasis', 'expressions']);
1455
+ }
898
1456
  }
899
1457
  exports.TemplateStringExpression = TemplateStringExpression;
900
- class TaggedTemplateStringExpression extends Expression {
901
- constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
1458
+ class TaggedTemplateStringExpression extends AstNode_1.Expression {
1459
+ constructor(options) {
1460
+ var _a, _b, _c;
902
1461
  super();
903
- this.tagName = tagName;
904
- this.openingBacktick = openingBacktick;
905
- this.quasis = quasis;
906
- this.expressions = expressions;
907
- this.closingBacktick = closingBacktick;
908
- this.range = util_1.default.createRangeFromPositions(quasis[0].range.start, quasis[quasis.length - 1].range.end);
1462
+ this.kind = AstNode_1.AstNodeKind.TaggedTemplateStringExpression;
1463
+ this.tokens = {
1464
+ tagName: options.tagName,
1465
+ openingBacktick: options.openingBacktick,
1466
+ closingBacktick: options.closingBacktick
1467
+ };
1468
+ this.quasis = options.quasis;
1469
+ this.expressions = options.expressions;
1470
+ this.location = util_1.default.createBoundingLocation(this.tokens.tagName, this.tokens.openingBacktick, (_a = this.quasis) === null || _a === void 0 ? void 0 : _a[0], (_b = this.quasis) === null || _b === void 0 ? void 0 : _b[((_c = this.quasis) === null || _c === void 0 ? void 0 : _c.length) - 1], this.tokens.closingBacktick);
909
1471
  }
910
1472
  transpile(state) {
911
1473
  let result = [];
912
- result.push(state.transpileToken(this.tagName), '([');
1474
+ result.push(state.transpileToken(this.tokens.tagName), '([');
913
1475
  //add quasis as the first array
914
1476
  for (let i = 0; i < this.quasis.length; i++) {
915
1477
  let quasi = this.quasis[i];
@@ -928,30 +1490,47 @@ class TaggedTemplateStringExpression extends Expression {
928
1490
  }
929
1491
  result.push(...expression.transpile(state));
930
1492
  }
931
- result.push(state.sourceNode(this.closingBacktick, '])'));
1493
+ result.push(state.sourceNode(this.tokens.closingBacktick, '])'));
932
1494
  return result;
933
1495
  }
934
1496
  walk(visitor, options) {
935
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1497
+ var _a;
1498
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
936
1499
  //walk the quasis and expressions in left-to-right order
937
- for (let i = 0; i < this.quasis.length; i++) {
938
- visitors_1.walk(this.quasis, i, visitor, options, this);
1500
+ for (let i = 0; i < ((_a = this.quasis) === null || _a === void 0 ? void 0 : _a.length); i++) {
1501
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
939
1502
  //this skips the final loop iteration since we'll always have one more quasi than expression
940
1503
  if (this.expressions[i]) {
941
- visitors_1.walk(this.expressions, i, visitor, options, this);
1504
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
942
1505
  }
943
1506
  }
944
1507
  }
945
1508
  }
1509
+ clone() {
1510
+ var _a, _b;
1511
+ return this.finalizeClone(new TaggedTemplateStringExpression({
1512
+ tagName: util_1.default.cloneToken(this.tokens.tagName),
1513
+ openingBacktick: util_1.default.cloneToken(this.tokens.openingBacktick),
1514
+ quasis: (_a = this.quasis) === null || _a === void 0 ? void 0 : _a.map(e => e === null || e === void 0 ? void 0 : e.clone()),
1515
+ expressions: (_b = this.expressions) === null || _b === void 0 ? void 0 : _b.map(e => e === null || e === void 0 ? void 0 : e.clone()),
1516
+ closingBacktick: util_1.default.cloneToken(this.tokens.closingBacktick)
1517
+ }), ['quasis', 'expressions']);
1518
+ }
946
1519
  }
947
1520
  exports.TaggedTemplateStringExpression = TaggedTemplateStringExpression;
948
- class AnnotationExpression extends Expression {
949
- constructor(atToken, nameToken) {
1521
+ class AnnotationExpression extends AstNode_1.Expression {
1522
+ constructor(options) {
950
1523
  super();
951
- this.atToken = atToken;
952
- this.nameToken = nameToken;
953
- this.name = nameToken.text;
954
- this.range = util_1.default.createRangeFromPositions(atToken.range.start, nameToken.range.end);
1524
+ this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
1525
+ this.tokens = {
1526
+ at: options.at,
1527
+ name: options.name
1528
+ };
1529
+ this.call = options.call;
1530
+ this.name = this.tokens.name.text;
1531
+ }
1532
+ get location() {
1533
+ return util_1.default.createBoundingLocation(this.tokens.at, this.tokens.name, this.call);
955
1534
  }
956
1535
  /**
957
1536
  * Convert annotation arguments to JavaScript types
@@ -963,8 +1542,13 @@ class AnnotationExpression extends Expression {
963
1542
  }
964
1543
  return this.call.args.map(e => expressionToValue(e, strict));
965
1544
  }
1545
+ get leadingTrivia() {
1546
+ var _a;
1547
+ return (_a = this.tokens.at) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1548
+ }
966
1549
  transpile(state) {
967
- return [];
1550
+ //transpile only our leading comments
1551
+ return state.transpileComments(this.leadingTrivia);
968
1552
  }
969
1553
  walk(visitor, options) {
970
1554
  //nothing to walk
@@ -977,37 +1561,51 @@ class AnnotationExpression extends Expression {
977
1561
  ...((_b = (_a = this.call) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : [])
978
1562
  ];
979
1563
  }
1564
+ clone() {
1565
+ const clone = this.finalizeClone(new AnnotationExpression({
1566
+ at: util_1.default.cloneToken(this.tokens.at),
1567
+ name: util_1.default.cloneToken(this.tokens.name)
1568
+ }));
1569
+ return clone;
1570
+ }
980
1571
  }
981
1572
  exports.AnnotationExpression = AnnotationExpression;
982
- class TernaryExpression extends Expression {
983
- constructor(test, questionMarkToken, consequent, colonToken, alternate) {
984
- var _a, _b, _c;
1573
+ class TernaryExpression extends AstNode_1.Expression {
1574
+ constructor(options) {
985
1575
  super();
986
- this.test = test;
987
- this.questionMarkToken = questionMarkToken;
988
- this.consequent = consequent;
989
- this.colonToken = colonToken;
990
- this.alternate = alternate;
991
- this.range = util_1.default.createRangeFromPositions(test.range.start, ((_c = (_b = (_a = alternate !== null && alternate !== void 0 ? alternate : colonToken) !== null && _a !== void 0 ? _a : consequent) !== null && _b !== void 0 ? _b : questionMarkToken) !== null && _c !== void 0 ? _c : test).range.end);
1576
+ this.kind = AstNode_1.AstNodeKind.TernaryExpression;
1577
+ this.tokens = {
1578
+ questionMark: options.questionMark,
1579
+ colon: options.colon
1580
+ };
1581
+ this.test = options.test;
1582
+ this.consequent = options.consequent;
1583
+ this.alternate = options.alternate;
1584
+ this.location = util_1.default.createBoundingLocation(this.test, this.tokens.questionMark, this.consequent, this.tokens.colon, this.alternate);
992
1585
  }
993
1586
  transpile(state) {
994
1587
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
995
1588
  let result = [];
996
- let consequentInfo = util_1.default.getExpressionInfo(this.consequent);
997
- let alternateInfo = util_1.default.getExpressionInfo(this.alternate);
1589
+ const file = state.file;
1590
+ let consequentInfo = util_1.default.getExpressionInfo(this.consequent, file);
1591
+ let alternateInfo = util_1.default.getExpressionInfo(this.alternate, file);
998
1592
  //get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
999
1593
  let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
1594
+ //discard names of global functions that cannot be passed by reference
1595
+ allUniqueVarNames = allUniqueVarNames.filter(name => {
1596
+ return !nonReferenceableFunctions.includes(name.toLowerCase());
1597
+ });
1000
1598
  let mutatingExpressions = [
1001
1599
  ...consequentInfo.expressions,
1002
1600
  ...alternateInfo.expressions
1003
1601
  ].filter(e => e instanceof CallExpression || e instanceof CallfuncExpression || e instanceof DottedGetExpression);
1004
1602
  if (mutatingExpressions.length > 0) {
1005
- result.push(state.sourceNode(this.questionMarkToken,
1603
+ result.push(state.sourceNode(this.tokens.questionMark,
1006
1604
  //write all the scope variables as parameters.
1007
1605
  //TODO handle when there are more than 31 parameters
1008
- `(function(__bsCondition, ${allUniqueVarNames.join(', ')})`), state.newline,
1606
+ `(function(${['__bsCondition', ...allUniqueVarNames].join(', ')})`), state.newline,
1009
1607
  //double indent so our `end function` line is still indented one at the end
1010
- state.indent(2), state.sourceNode(this.test, `if __bsCondition then`), state.newline, state.indent(1), state.sourceNode((_a = this.consequent) !== null && _a !== void 0 ? _a : this.questionMarkToken, 'return '), ...(_c = (_b = this.consequent) === null || _b === void 0 ? void 0 : _b.transpile(state)) !== null && _c !== void 0 ? _c : [state.sourceNode(this.questionMarkToken, 'invalid')], state.newline, state.indent(-1), state.sourceNode((_d = this.consequent) !== null && _d !== void 0 ? _d : this.questionMarkToken, 'else'), state.newline, state.indent(1), state.sourceNode((_e = this.consequent) !== null && _e !== void 0 ? _e : this.questionMarkToken, 'return '), ...(_g = (_f = this.alternate) === null || _f === void 0 ? void 0 : _f.transpile(state)) !== null && _g !== void 0 ? _g : [state.sourceNode((_h = this.consequent) !== null && _h !== void 0 ? _h : this.questionMarkToken, 'invalid')], state.newline, state.indent(-1), state.sourceNode(this.questionMarkToken, 'end if'), state.newline, state.indent(-1), state.sourceNode(this.questionMarkToken, 'end function)('), ...this.test.transpile(state), state.sourceNode(this.questionMarkToken, `, ${allUniqueVarNames.join(', ')})`));
1608
+ state.indent(2), state.sourceNode(this.test, `if __bsCondition then`), state.newline, state.indent(1), state.sourceNode((_a = this.consequent) !== null && _a !== void 0 ? _a : this.tokens.questionMark, 'return '), ...(_c = (_b = this.consequent) === null || _b === void 0 ? void 0 : _b.transpile(state)) !== null && _c !== void 0 ? _c : [state.sourceNode(this.tokens.questionMark, 'invalid')], state.newline, state.indent(-1), state.sourceNode((_d = this.consequent) !== null && _d !== void 0 ? _d : this.tokens.questionMark, 'else'), state.newline, state.indent(1), state.sourceNode((_e = this.consequent) !== null && _e !== void 0 ? _e : this.tokens.questionMark, 'return '), ...(_g = (_f = this.alternate) === null || _f === void 0 ? void 0 : _f.transpile(state)) !== null && _g !== void 0 ? _g : [state.sourceNode((_h = this.consequent) !== null && _h !== void 0 ? _h : this.tokens.questionMark, 'invalid')], state.newline, state.indent(-1), state.sourceNode(this.tokens.questionMark, 'end if'), state.newline, state.indent(-1), state.sourceNode(this.tokens.questionMark, 'end function)('), ...this.test.transpile(state), state.sourceNode(this.tokens.questionMark, `${['', ...allUniqueVarNames].join(', ')})`));
1011
1609
  state.blockDepth--;
1012
1610
  }
1013
1611
  else {
@@ -1016,33 +1614,52 @@ class TernaryExpression extends Expression {
1016
1614
  return result;
1017
1615
  }
1018
1616
  walk(visitor, options) {
1019
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1020
- visitors_1.walk(this, 'test', visitor, options);
1021
- visitors_1.walk(this, 'consequent', visitor, options);
1022
- visitors_1.walk(this, 'alternate', visitor, options);
1617
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1618
+ (0, visitors_2.walk)(this, 'test', visitor, options);
1619
+ (0, visitors_2.walk)(this, 'consequent', visitor, options);
1620
+ (0, visitors_2.walk)(this, 'alternate', visitor, options);
1023
1621
  }
1024
1622
  }
1623
+ get leadingTrivia() {
1624
+ return this.test.leadingTrivia;
1625
+ }
1626
+ clone() {
1627
+ var _a, _b, _c;
1628
+ return this.finalizeClone(new TernaryExpression({
1629
+ test: (_a = this.test) === null || _a === void 0 ? void 0 : _a.clone(),
1630
+ questionMark: util_1.default.cloneToken(this.tokens.questionMark),
1631
+ consequent: (_b = this.consequent) === null || _b === void 0 ? void 0 : _b.clone(),
1632
+ colon: util_1.default.cloneToken(this.tokens.colon),
1633
+ alternate: (_c = this.alternate) === null || _c === void 0 ? void 0 : _c.clone()
1634
+ }), ['test', 'consequent', 'alternate']);
1635
+ }
1025
1636
  }
1026
1637
  exports.TernaryExpression = TernaryExpression;
1027
- class NullCoalescingExpression extends Expression {
1028
- constructor(consequent, questionQuestionToken, alternate) {
1029
- var _a;
1638
+ class NullCoalescingExpression extends AstNode_1.Expression {
1639
+ constructor(options) {
1030
1640
  super();
1031
- this.consequent = consequent;
1032
- this.questionQuestionToken = questionQuestionToken;
1033
- this.alternate = alternate;
1034
- this.range = util_1.default.createRangeFromPositions(consequent.range.start, ((_a = alternate !== null && alternate !== void 0 ? alternate : questionQuestionToken) !== null && _a !== void 0 ? _a : consequent).range.end);
1641
+ this.kind = AstNode_1.AstNodeKind.NullCoalescingExpression;
1642
+ this.tokens = {
1643
+ questionQuestion: options.questionQuestion
1644
+ };
1645
+ this.consequent = options.consequent;
1646
+ this.alternate = options.alternate;
1647
+ this.location = util_1.default.createBoundingLocation(this.consequent, this.tokens.questionQuestion, this.alternate);
1035
1648
  }
1036
1649
  transpile(state) {
1037
1650
  let result = [];
1038
- let consequentInfo = util_1.default.getExpressionInfo(this.consequent);
1039
- let alternateInfo = util_1.default.getExpressionInfo(this.alternate);
1651
+ let consequentInfo = util_1.default.getExpressionInfo(this.consequent, state.file);
1652
+ let alternateInfo = util_1.default.getExpressionInfo(this.alternate, state.file);
1040
1653
  //get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
1041
1654
  let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
1655
+ //discard names of global functions that cannot be passed by reference
1656
+ allUniqueVarNames = allUniqueVarNames.filter(name => {
1657
+ return !nonReferenceableFunctions.includes(name.toLowerCase());
1658
+ });
1042
1659
  let hasMutatingExpression = [
1043
1660
  ...consequentInfo.expressions,
1044
1661
  ...alternateInfo.expressions
1045
- ].find(e => reflection_1.isCallExpression(e) || reflection_1.isCallfuncExpression(e) || reflection_1.isDottedGetExpression(e));
1662
+ ].find(e => (0, reflection_1.isCallExpression)(e) || (0, reflection_1.isCallfuncExpression)(e) || (0, reflection_1.isDottedGetExpression)(e));
1046
1663
  if (hasMutatingExpression) {
1047
1664
  result.push(`(function(`,
1048
1665
  //write all the scope variables as parameters.
@@ -1060,51 +1677,343 @@ class NullCoalescingExpression extends Expression {
1060
1677
  return result;
1061
1678
  }
1062
1679
  walk(visitor, options) {
1063
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1064
- visitors_1.walk(this, 'consequent', visitor, options);
1065
- visitors_1.walk(this, 'alternate', visitor, options);
1680
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1681
+ (0, visitors_2.walk)(this, 'consequent', visitor, options);
1682
+ (0, visitors_2.walk)(this, 'alternate', visitor, options);
1066
1683
  }
1067
1684
  }
1685
+ get leadingTrivia() {
1686
+ return this.consequent.leadingTrivia;
1687
+ }
1688
+ clone() {
1689
+ var _a, _b;
1690
+ return this.finalizeClone(new NullCoalescingExpression({
1691
+ consequent: (_a = this.consequent) === null || _a === void 0 ? void 0 : _a.clone(),
1692
+ questionQuestion: util_1.default.cloneToken(this.tokens.questionQuestion),
1693
+ alternate: (_b = this.alternate) === null || _b === void 0 ? void 0 : _b.clone()
1694
+ }), ['consequent', 'alternate']);
1695
+ }
1068
1696
  }
1069
1697
  exports.NullCoalescingExpression = NullCoalescingExpression;
1698
+ class RegexLiteralExpression extends AstNode_1.Expression {
1699
+ constructor(options) {
1700
+ super();
1701
+ this.kind = AstNode_1.AstNodeKind.RegexLiteralExpression;
1702
+ this.tokens = {
1703
+ regexLiteral: options.regexLiteral
1704
+ };
1705
+ }
1706
+ get location() {
1707
+ var _a, _b;
1708
+ return (_b = (_a = this.tokens) === null || _a === void 0 ? void 0 : _a.regexLiteral) === null || _b === void 0 ? void 0 : _b.location;
1709
+ }
1710
+ transpile(state) {
1711
+ var _a, _b;
1712
+ let text = (_b = (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
1713
+ let flags = '';
1714
+ //get any flags from the end
1715
+ const flagMatch = /\/([a-z]+)$/i.exec(text);
1716
+ if (flagMatch) {
1717
+ text = text.substring(0, flagMatch.index + 1);
1718
+ flags = flagMatch[1];
1719
+ }
1720
+ let pattern = text
1721
+ //remove leading and trailing slashes
1722
+ .substring(1, text.length - 1)
1723
+ //escape quotemarks
1724
+ .split('"').join('" + chr(34) + "');
1725
+ return [
1726
+ state.sourceNode(this.tokens.regexLiteral, [
1727
+ 'CreateObject("roRegex", ',
1728
+ `"${pattern}", `,
1729
+ `"${flags}"`,
1730
+ ')'
1731
+ ])
1732
+ ];
1733
+ }
1734
+ walk(visitor, options) {
1735
+ //nothing to walk
1736
+ }
1737
+ clone() {
1738
+ return this.finalizeClone(new RegexLiteralExpression({
1739
+ regexLiteral: util_1.default.cloneToken(this.tokens.regexLiteral)
1740
+ }));
1741
+ }
1742
+ get leadingTrivia() {
1743
+ var _a;
1744
+ return (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1745
+ }
1746
+ }
1747
+ exports.RegexLiteralExpression = RegexLiteralExpression;
1070
1748
  function expressionToValue(expr, strict) {
1749
+ var _a;
1071
1750
  if (!expr) {
1072
1751
  return null;
1073
1752
  }
1074
- if (reflection_1.isUnaryExpression(expr) && reflection_1.isLiteralNumber(expr.right)) {
1075
- return numberExpressionToValue(expr.right, expr.operator.text);
1753
+ if ((0, reflection_1.isUnaryExpression)(expr) && (0, reflection_1.isLiteralNumber)(expr.right)) {
1754
+ return numberExpressionToValue(expr.right, expr.tokens.operator.text);
1076
1755
  }
1077
- if (reflection_1.isLiteralString(expr)) {
1756
+ if ((0, reflection_1.isLiteralString)(expr)) {
1078
1757
  //remove leading and trailing quotes
1079
- return expr.token.text.replace(/^"/, '').replace(/"$/, '');
1758
+ return expr.tokens.value.text.replace(/^"/, '').replace(/"$/, '');
1080
1759
  }
1081
- if (reflection_1.isLiteralNumber(expr)) {
1760
+ if ((0, reflection_1.isLiteralNumber)(expr)) {
1082
1761
  return numberExpressionToValue(expr);
1083
1762
  }
1084
- if (reflection_1.isLiteralBoolean(expr)) {
1085
- return expr.token.text.toLowerCase() === 'true';
1763
+ if ((0, reflection_1.isLiteralBoolean)(expr)) {
1764
+ return expr.tokens.value.text.toLowerCase() === 'true';
1086
1765
  }
1087
- if (reflection_1.isArrayLiteralExpression(expr)) {
1766
+ if ((0, reflection_1.isArrayLiteralExpression)(expr)) {
1088
1767
  return expr.elements
1089
- .filter(e => !reflection_1.isCommentStatement(e))
1090
1768
  .map(e => expressionToValue(e, strict));
1091
1769
  }
1092
- if (reflection_1.isAALiteralExpression(expr)) {
1770
+ if ((0, reflection_1.isAALiteralExpression)(expr)) {
1093
1771
  return expr.elements.reduce((acc, e) => {
1094
- if (!reflection_1.isCommentStatement(e)) {
1095
- acc[e.keyToken.text] = expressionToValue(e.value, strict);
1096
- }
1772
+ acc[e.tokens.key.text] = expressionToValue(e.value, strict);
1097
1773
  return acc;
1098
1774
  }, {});
1099
1775
  }
1776
+ //for annotations, we only support serializing pure string values
1777
+ if ((0, reflection_1.isTemplateStringExpression)(expr)) {
1778
+ if (((_a = expr.quasis) === null || _a === void 0 ? void 0 : _a.length) === 1 && expr.expressions.length === 0) {
1779
+ return expr.quasis[0].expressions.map(x => x.tokens.value.text).join('');
1780
+ }
1781
+ }
1100
1782
  return strict ? null : expr;
1101
1783
  }
1102
1784
  function numberExpressionToValue(expr, operator = '') {
1103
- if (reflection_1.isIntegerType(expr.type) || reflection_1.isLongIntegerType(expr.type)) {
1104
- return parseInt(operator + expr.token.text);
1785
+ if ((0, reflection_1.isIntegerType)(expr.getType()) || (0, reflection_1.isLongIntegerType)(expr.getType())) {
1786
+ return parseInt(operator + expr.tokens.value.text);
1105
1787
  }
1106
1788
  else {
1107
- return parseFloat(operator + expr.token.text);
1789
+ return parseFloat(operator + expr.tokens.value.text);
1790
+ }
1791
+ }
1792
+ class TypeExpression extends AstNode_1.Expression {
1793
+ constructor(options) {
1794
+ var _a;
1795
+ super();
1796
+ this.kind = AstNode_1.AstNodeKind.TypeExpression;
1797
+ this.expression = options.expression;
1798
+ this.location = util_1.default.cloneLocation((_a = this.expression) === null || _a === void 0 ? void 0 : _a.location);
1799
+ }
1800
+ transpile(state) {
1801
+ const exprType = this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ });
1802
+ if ((0, reflection_1.isNativeType)(exprType)) {
1803
+ return this.expression.transpile(state);
1804
+ }
1805
+ return [exprType.toTypeString()];
1806
+ }
1807
+ walk(visitor, options) {
1808
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1809
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
1810
+ }
1811
+ }
1812
+ getType(options) {
1813
+ return this.expression.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */ }));
1814
+ }
1815
+ getTypedef(state) {
1816
+ // TypeDefs should pass through any valid type names
1817
+ return this.expression.transpile(state);
1818
+ }
1819
+ getName(parseMode = Parser_1.ParseMode.BrighterScript) {
1820
+ //TODO: this may not support Complex Types, eg. generics or Unions
1821
+ return util_1.default.getAllDottedGetPartsAsString(this.expression, parseMode);
1822
+ }
1823
+ getNameParts() {
1824
+ //TODO: really, this code is only used to get Namespaces. It could be more clear.
1825
+ return util_1.default.getAllDottedGetParts(this.expression).map(x => x.text);
1826
+ }
1827
+ clone() {
1828
+ var _a;
1829
+ return this.finalizeClone(new TypeExpression({
1830
+ expression: (_a = this.expression) === null || _a === void 0 ? void 0 : _a.clone()
1831
+ }), ['expression']);
1832
+ }
1833
+ }
1834
+ exports.TypeExpression = TypeExpression;
1835
+ class TypecastExpression extends AstNode_1.Expression {
1836
+ constructor(options) {
1837
+ super();
1838
+ this.kind = AstNode_1.AstNodeKind.TypecastExpression;
1839
+ this.tokens = {
1840
+ as: options.as
1841
+ };
1842
+ this.obj = options.obj;
1843
+ this.typeExpression = options.typeExpression;
1844
+ this.location = util_1.default.createBoundingLocation(this.obj, this.tokens.as, this.typeExpression);
1845
+ }
1846
+ transpile(state) {
1847
+ return this.obj.transpile(state);
1848
+ }
1849
+ walk(visitor, options) {
1850
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1851
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
1852
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
1853
+ }
1854
+ }
1855
+ getType(options) {
1856
+ const result = this.typeExpression.getType(options);
1857
+ if (options.typeChain) {
1858
+ // modify last typechain entry to show it is a typecast
1859
+ const lastEntry = options.typeChain[options.typeChain.length - 1];
1860
+ if (lastEntry) {
1861
+ lastEntry.astNode = this;
1862
+ }
1863
+ }
1864
+ return result;
1865
+ }
1866
+ clone() {
1867
+ var _a, _b;
1868
+ return this.finalizeClone(new TypecastExpression({
1869
+ obj: (_a = this.obj) === null || _a === void 0 ? void 0 : _a.clone(),
1870
+ as: util_1.default.cloneToken(this.tokens.as),
1871
+ typeExpression: (_b = this.typeExpression) === null || _b === void 0 ? void 0 : _b.clone()
1872
+ }), ['obj', 'typeExpression']);
1873
+ }
1874
+ }
1875
+ exports.TypecastExpression = TypecastExpression;
1876
+ class TypedArrayExpression extends AstNode_1.Expression {
1877
+ constructor(options) {
1878
+ super();
1879
+ this.kind = AstNode_1.AstNodeKind.TypedArrayExpression;
1880
+ this.tokens = {
1881
+ leftBracket: options.leftBracket,
1882
+ rightBracket: options.rightBracket
1883
+ };
1884
+ this.innerType = options.innerType;
1885
+ this.location = util_1.default.createBoundingLocation(this.innerType, this.tokens.leftBracket, this.tokens.rightBracket);
1886
+ }
1887
+ transpile(state) {
1888
+ return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
1889
+ }
1890
+ walk(visitor, options) {
1891
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1892
+ (0, visitors_2.walk)(this, 'innerType', visitor, options);
1893
+ }
1894
+ }
1895
+ getType(options) {
1896
+ return new ArrayType_1.ArrayType(this.innerType.getType(options));
1897
+ }
1898
+ clone() {
1899
+ var _a;
1900
+ return this.finalizeClone(new TypedArrayExpression({
1901
+ innerType: (_a = this.innerType) === null || _a === void 0 ? void 0 : _a.clone(),
1902
+ leftBracket: util_1.default.cloneToken(this.tokens.leftBracket),
1903
+ rightBracket: util_1.default.cloneToken(this.tokens.rightBracket)
1904
+ }), ['innerType']);
1108
1905
  }
1109
1906
  }
1907
+ exports.TypedArrayExpression = TypedArrayExpression;
1908
+ class InlineInterfaceExpression extends AstNode_1.Expression {
1909
+ constructor(options) {
1910
+ super();
1911
+ this.kind = AstNode_1.AstNodeKind.InlineInterfaceExpression;
1912
+ this.tokens = {
1913
+ open: options.open,
1914
+ close: options.close
1915
+ };
1916
+ this.members = options.members;
1917
+ this.location = util_1.default.createBoundingLocation(this.tokens.open, ...this.members, this.tokens.close);
1918
+ }
1919
+ get leadingTrivia() {
1920
+ var _a;
1921
+ return (_a = this.tokens.open) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1922
+ }
1923
+ transpile(state) {
1924
+ return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
1925
+ }
1926
+ walk(visitor, options) {
1927
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1928
+ (0, visitors_2.walkArray)(this.members, visitor, options, this);
1929
+ }
1930
+ }
1931
+ getType(options) {
1932
+ var _a, _b, _c;
1933
+ const resultType = new InlineInterfaceType_1.InlineInterfaceType();
1934
+ for (const member of this.members) {
1935
+ let memberName = (_c = (_b = (_a = member.tokens) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : '';
1936
+ if (member.tokens.name.kind === TokenKind_1.TokenKind.StringLiteral) {
1937
+ memberName = memberName.replace(/"/g, ''); // remove quotes if it was a stringLiteral
1938
+ }
1939
+ if (memberName) {
1940
+ const memberType = member === null || member === void 0 ? void 0 : member.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); // no typechain info needed
1941
+ let flag = 1 /* SymbolTypeFlag.runtime */;
1942
+ if (member.isOptional) {
1943
+ flag |= 4 /* SymbolTypeFlag.optional */;
1944
+ }
1945
+ resultType.addMember(memberName, { definingNode: member }, memberType, flag);
1946
+ }
1947
+ }
1948
+ return resultType;
1949
+ }
1950
+ clone() {
1951
+ var _a;
1952
+ return this.finalizeClone(new InlineInterfaceExpression({
1953
+ open: util_1.default.cloneToken(this.tokens.open),
1954
+ members: (_a = this.members) === null || _a === void 0 ? void 0 : _a.map(x => x === null || x === void 0 ? void 0 : x.clone()),
1955
+ close: util_1.default.cloneToken(this.tokens.close)
1956
+ }), ['members']);
1957
+ }
1958
+ }
1959
+ exports.InlineInterfaceExpression = InlineInterfaceExpression;
1960
+ class InlineInterfaceMemberExpression extends AstNode_1.Expression {
1961
+ constructor(options) {
1962
+ super();
1963
+ this.kind = AstNode_1.AstNodeKind.InlineInterfaceMemberExpression;
1964
+ this.tokens = {
1965
+ name: options.name,
1966
+ as: options.as,
1967
+ optional: options.optional
1968
+ };
1969
+ this.typeExpression = options.typeExpression;
1970
+ this.location = util_1.default.createBoundingLocation(this.tokens.optional, this.tokens.name, this.tokens.as, this.typeExpression);
1971
+ }
1972
+ get leadingTrivia() {
1973
+ var _a, _b;
1974
+ return (_b = (_a = this.tokens.optional) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : this.tokens.name.leadingTrivia;
1975
+ }
1976
+ transpile(state) {
1977
+ throw new Error('Method not implemented.');
1978
+ }
1979
+ walk(visitor, options) {
1980
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1981
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
1982
+ }
1983
+ }
1984
+ getType(options) {
1985
+ var _a, _b;
1986
+ return (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(options)) !== null && _b !== void 0 ? _b : DynamicType_1.DynamicType.instance;
1987
+ }
1988
+ get isOptional() {
1989
+ return !!this.tokens.optional;
1990
+ }
1991
+ clone() {
1992
+ var _a;
1993
+ return this.finalizeClone(new InlineInterfaceMemberExpression({
1994
+ typeExpression: (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.clone(),
1995
+ as: util_1.default.cloneToken(this.tokens.as),
1996
+ name: util_1.default.cloneToken(this.tokens.name),
1997
+ optional: util_1.default.cloneToken(this.tokens.optional)
1998
+ }), ['typeExpression']);
1999
+ }
2000
+ }
2001
+ exports.InlineInterfaceMemberExpression = InlineInterfaceMemberExpression;
2002
+ /**
2003
+ * A list of names of functions that are restricted from being stored to a
2004
+ * variable, property, or passed as an argument. (i.e. `type` or `createobject`).
2005
+ * Names are stored in lower case.
2006
+ */
2007
+ const nonReferenceableFunctions = [
2008
+ 'createobject',
2009
+ 'type',
2010
+ 'getglobalaa',
2011
+ 'box',
2012
+ 'run',
2013
+ 'eval',
2014
+ 'getlastruncompileerror',
2015
+ 'getlastrunruntimeerror',
2016
+ 'tab',
2017
+ 'pos'
2018
+ ];
1110
2019
  //# sourceMappingURL=Expression.js.map