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,36 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ThrowStatement = exports.TryCatchStatement = exports.ClassFieldStatement = exports.ClassMethodStatement = exports.ClassStatement = exports.ImportStatement = exports.NamespaceStatement = exports.LibraryStatement = exports.IndexedSetStatement = exports.DottedSetStatement = exports.WhileStatement = exports.ForEachStatement = exports.ForStatement = exports.StopStatement = exports.EndStatement = exports.ReturnStatement = exports.LabelStatement = exports.GotoStatement = exports.DimStatement = exports.PrintStatement = exports.IncrementStatement = exports.IfStatement = exports.FunctionStatement = exports.ExitWhileStatement = exports.ExitForStatement = exports.CommentStatement = exports.ExpressionStatement = exports.Block = exports.AssignmentStatement = exports.Body = exports.EmptyStatement = exports.Statement = void 0;
4
- const lexer_1 = require("../lexer");
3
+ exports.TypeStatement = exports.ConditionalCompileConstStatement = exports.ConditionalCompileStatement = exports.AliasStatement = exports.ConditionalCompileErrorStatement = exports.TypecastStatement = exports.ContinueStatement = exports.ConstStatement = exports.EnumMemberStatement = exports.EnumStatement = exports.ThrowStatement = exports.CatchStatement = exports.TryCatchStatement = exports.FieldStatement = exports.MethodStatement = exports.ClassStatement = exports.InterfaceMethodStatement = exports.InterfaceFieldStatement = exports.InterfaceStatement = exports.ImportStatement = exports.NamespaceStatement = exports.LibraryStatement = exports.IndexedSetStatement = exports.DottedSetStatement = exports.WhileStatement = exports.ForEachStatement = exports.ForStatement = exports.StopStatement = exports.EndStatement = exports.ReturnStatement = exports.LabelStatement = exports.GotoStatement = exports.DimStatement = exports.PrintStatement = exports.IncrementStatement = exports.IfStatement = exports.FunctionStatement = exports.ExitStatement = exports.ExpressionStatement = exports.Block = exports.AugmentedAssignmentStatement = exports.AssignmentStatement = exports.Body = exports.EmptyStatement = void 0;
4
+ const TokenKind_1 = require("../lexer/TokenKind");
5
5
  const Expression_1 = require("./Expression");
6
+ const Expression_2 = require("./Expression");
6
7
  const util_1 = require("../util");
7
- const vscode_languageserver_1 = require("vscode-languageserver");
8
8
  const Parser_1 = require("./Parser");
9
9
  const visitors_1 = require("../astUtils/visitors");
10
10
  const reflection_1 = require("../astUtils/reflection");
11
+ const interfaces_1 = require("../interfaces");
11
12
  const creators_1 = require("../astUtils/creators");
12
13
  const DynamicType_1 = require("../types/DynamicType");
13
14
  const SymbolTable_1 = require("../SymbolTable");
14
- /**
15
- * A BrightScript statement
16
- */
17
- class Statement {
18
- constructor() {
19
- /**
20
- * When being considered by the walk visitor, this describes what type of element the current class is.
21
- */
22
- this.visitMode = visitors_1.InternalWalkMode.visitStatements;
23
- }
24
- }
25
- exports.Statement = Statement;
26
- class EmptyStatement extends Statement {
27
- constructor(
28
- /**
29
- * Create a negative range to indicate this is an interpolated location
30
- */
31
- range = creators_1.interpolatedRange) {
15
+ const AstNode_1 = require("./AstNode");
16
+ const ClassType_1 = require("../types/ClassType");
17
+ const EnumType_1 = require("../types/EnumType");
18
+ const NamespaceType_1 = require("../types/NamespaceType");
19
+ const InterfaceType_1 = require("../types/InterfaceType");
20
+ const VoidType_1 = require("../types/VoidType");
21
+ const TypedFunctionType_1 = require("../types/TypedFunctionType");
22
+ const ArrayType_1 = require("../types/ArrayType");
23
+ const BrightScriptDocParser_1 = require("./BrightScriptDocParser");
24
+ const ReferenceType_1 = require("../types/ReferenceType");
25
+ class EmptyStatement extends AstNode_1.Statement {
26
+ constructor(options) {
32
27
  super();
33
- this.range = range;
28
+ this.kind = AstNode_1.AstNodeKind.EmptyStatement;
29
+ this.location = undefined;
34
30
  }
35
31
  transpile(state) {
36
32
  return [];
@@ -38,22 +34,39 @@ class EmptyStatement extends Statement {
38
34
  walk(visitor, options) {
39
35
  //nothing to walk
40
36
  }
37
+ clone() {
38
+ return this.finalizeClone(new EmptyStatement({
39
+ range: util_1.util.cloneLocation(this.location)
40
+ }));
41
+ }
41
42
  }
42
43
  exports.EmptyStatement = EmptyStatement;
43
44
  /**
44
45
  * This is a top-level statement. Consider this the root of the AST
45
46
  */
46
- class Body extends Statement {
47
- constructor(statements = []) {
47
+ class Body extends AstNode_1.Statement {
48
+ constructor(options) {
49
+ var _a;
48
50
  super();
49
- this.statements = statements;
51
+ this.statements = [];
52
+ this.kind = AstNode_1.AstNodeKind.Body;
53
+ this.symbolTable = new SymbolTable_1.SymbolTable('Body', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
54
+ this.statements = (_a = options === null || options === void 0 ? void 0 : options.statements) !== null && _a !== void 0 ? _a : [];
50
55
  }
51
- get range() {
52
- var _a, _b, _c, _d;
53
- return util_1.util.createRangeFromPositions((_b = (_a = this.statements[0]) === null || _a === void 0 ? void 0 : _a.range.start) !== null && _b !== void 0 ? _b : vscode_languageserver_1.Position.create(0, 0), (_d = (_c = this.statements[this.statements.length - 1]) === null || _c === void 0 ? void 0 : _c.range.end) !== null && _d !== void 0 ? _d : vscode_languageserver_1.Position.create(0, 0));
56
+ get location() {
57
+ var _a;
58
+ if (!this._location) {
59
+ //this needs to be a getter because the body has its statements pushed to it after being constructed
60
+ this._location = util_1.util.createBoundingLocation(...((_a = this.statements) !== null && _a !== void 0 ? _a : []));
61
+ }
62
+ return this._location;
63
+ }
64
+ set location(value) {
65
+ this._location = value;
54
66
  }
55
67
  transpile(state) {
56
- let result = [];
68
+ var _a, _b, _c, _d, _e, _f;
69
+ let result = state.transpileAnnotations(this);
57
70
  for (let i = 0; i < this.statements.length; i++) {
58
71
  let statement = this.statements[i];
59
72
  let previousStatement = this.statements[i - 1];
@@ -62,20 +75,20 @@ class Body extends Statement {
62
75
  //this is the first statement. do nothing related to spacing and newlines
63
76
  //if comment is on same line as prior sibling
64
77
  }
65
- else if (reflection_1.isCommentStatement(statement) && previousStatement && statement.range.start.line === previousStatement.range.end.line) {
78
+ else if (util_1.util.hasLeadingComments(statement) && previousStatement && ((_d = (_c = (_b = (_a = util_1.util.getLeadingComments(statement)) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.location) === null || _c === void 0 ? void 0 : _c.range) === null || _d === void 0 ? void 0 : _d.start.line) === ((_f = (_e = previousStatement.location) === null || _e === void 0 ? void 0 : _e.range) === null || _f === void 0 ? void 0 : _f.end.line)) {
66
79
  result.push(' ');
67
80
  //add double newline if this is a comment, and next is a function
68
81
  }
69
- else if (reflection_1.isCommentStatement(statement) && nextStatement && reflection_1.isFunctionStatement(nextStatement)) {
70
- result.push('\n\n');
82
+ else if (util_1.util.hasLeadingComments(statement) && nextStatement && (0, reflection_1.isFunctionStatement)(nextStatement)) {
83
+ result.push(state.newline, state.newline);
71
84
  //add double newline if is function not preceeded by a comment
72
85
  }
73
- else if (reflection_1.isFunctionStatement(statement) && previousStatement && !(reflection_1.isCommentStatement(previousStatement))) {
74
- result.push('\n\n');
86
+ else if ((0, reflection_1.isFunctionStatement)(statement) && previousStatement && !util_1.util.hasLeadingComments(statement)) {
87
+ result.push(state.newline, state.newline);
75
88
  }
76
89
  else {
77
90
  //separate statements by a single newline
78
- result.push('\n');
91
+ result.push(state.newline);
79
92
  }
80
93
  result.push(...statement.transpile(state));
81
94
  }
@@ -85,7 +98,7 @@ class Body extends Statement {
85
98
  let result = [];
86
99
  for (const statement of this.statements) {
87
100
  //if the current statement supports generating typedef, call it
88
- if ('getTypedef' in statement) {
101
+ if ((0, reflection_1.isTypedefProvider)(statement)) {
89
102
  result.push(state.indent(), ...statement.getTypedef(state), state.newline);
90
103
  }
91
104
  }
@@ -93,63 +106,203 @@ class Body extends Statement {
93
106
  }
94
107
  walk(visitor, options) {
95
108
  if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
96
- for (let i = 0; i < this.statements.length; i++) {
97
- visitors_1.walk(this.statements, i, visitor, options, this);
98
- }
109
+ (0, visitors_1.walkArray)(this.statements, visitor, options, this);
99
110
  }
100
111
  }
112
+ clone() {
113
+ var _a;
114
+ return this.finalizeClone(new Body({
115
+ statements: (_a = this.statements) === null || _a === void 0 ? void 0 : _a.map(s => s === null || s === void 0 ? void 0 : s.clone())
116
+ }), ['statements']);
117
+ }
101
118
  }
102
119
  exports.Body = Body;
103
- class AssignmentStatement extends Statement {
104
- constructor(name, equals, value, containingFunction) {
120
+ class AssignmentStatement extends AstNode_1.Statement {
121
+ constructor(options) {
105
122
  super();
106
- this.name = name;
107
- this.equals = equals;
108
- this.value = value;
109
- this.containingFunction = containingFunction;
110
- this.range = util_1.util.createRangeFromPositions(this.name.range.start, this.value.range.end);
123
+ this.kind = AstNode_1.AstNodeKind.AssignmentStatement;
124
+ this.value = options.value;
125
+ this.tokens = {
126
+ equals: options.equals,
127
+ name: options.name,
128
+ as: options.as
129
+ };
130
+ this.typeExpression = options.typeExpression;
131
+ this.location = util_1.util.createBoundingLocation(util_1.util.createBoundingLocationFromTokens(this.tokens), this.value);
111
132
  }
112
133
  transpile(state) {
113
- var _a, _b;
114
- //if the value is a compound assignment, just transpile the expression itself
115
- if (lexer_1.CompoundAssignmentOperators.includes((_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.operator) === null || _b === void 0 ? void 0 : _b.kind)) {
116
- return this.value.transpile(state);
117
- }
118
- else {
119
- return [
120
- state.transpileToken(this.name),
121
- ' ',
122
- state.transpileToken(this.equals),
123
- ' ',
124
- ...this.value.transpile(state)
125
- ];
126
- }
134
+ var _a;
135
+ return [
136
+ state.transpileToken(this.tokens.name),
137
+ ' ',
138
+ state.transpileToken((_a = this.tokens.equals) !== null && _a !== void 0 ? _a : (0, creators_1.createToken)(TokenKind_1.TokenKind.Equal), '='),
139
+ ' ',
140
+ ...this.value.transpile(state)
141
+ ];
127
142
  }
128
143
  walk(visitor, options) {
129
144
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
130
- visitors_1.walk(this, 'value', visitor, options);
145
+ (0, visitors_1.walk)(this, 'typeExpression', visitor, options);
146
+ (0, visitors_1.walk)(this, 'value', visitor, options);
131
147
  }
132
148
  }
149
+ getType(options) {
150
+ var _a, _b, _c, _d;
151
+ const variableTypeFromCode = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
152
+ const docs = BrightScriptDocParser_1.default.parseNode(this);
153
+ const variableTypeFromDocs = docs === null || docs === void 0 ? void 0 : docs.getTypeTagBscType(options);
154
+ const variableType = (_b = util_1.util.chooseTypeFromCodeOrDocComment(variableTypeFromCode, variableTypeFromDocs, options)) !== null && _b !== void 0 ? _b : this.value.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
155
+ // Note: compound assignments (eg. +=) are internally dealt with via the RHS being a BinaryExpression
156
+ // so this.value will be a BinaryExpression, and BinaryExpressions can figure out their own types
157
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({ name: this.tokens.name.text, type: variableType, data: options.data, location: (_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.location, astNode: this }));
158
+ return variableType;
159
+ }
160
+ get leadingTrivia() {
161
+ return this.tokens.name.leadingTrivia;
162
+ }
163
+ clone() {
164
+ var _a, _b;
165
+ return this.finalizeClone(new AssignmentStatement({
166
+ name: util_1.util.cloneToken(this.tokens.name),
167
+ value: (_a = this.value) === null || _a === void 0 ? void 0 : _a.clone(),
168
+ as: util_1.util.cloneToken(this.tokens.as),
169
+ equals: util_1.util.cloneToken(this.tokens.equals),
170
+ typeExpression: (_b = this.typeExpression) === null || _b === void 0 ? void 0 : _b.clone()
171
+ }), ['value', 'typeExpression']);
172
+ }
133
173
  }
134
174
  exports.AssignmentStatement = AssignmentStatement;
135
- class Block extends Statement {
136
- constructor(statements, startingRange) {
175
+ class AugmentedAssignmentStatement extends AstNode_1.Statement {
176
+ constructor(options) {
177
+ super();
178
+ this.kind = AstNode_1.AstNodeKind.AugmentedAssignmentStatement;
179
+ this.value = options.value;
180
+ this.tokens = {
181
+ operator: options.operator
182
+ };
183
+ this.item = options.item;
184
+ this.value = options.value;
185
+ this.location = util_1.util.createBoundingLocation(this.item, util_1.util.createBoundingLocationFromTokens(this.tokens), this.value);
186
+ }
187
+ transpile(state) {
188
+ return [
189
+ this.item.transpile(state),
190
+ ' ',
191
+ state.transpileToken(this.tokens.operator),
192
+ ' ',
193
+ this.value.transpile(state)
194
+ ];
195
+ }
196
+ walk(visitor, options) {
197
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
198
+ (0, visitors_1.walk)(this, 'item', visitor, options);
199
+ (0, visitors_1.walk)(this, 'value', visitor, options);
200
+ }
201
+ }
202
+ getType(options) {
203
+ const variableType = util_1.util.binaryOperatorResultType(this.item.getType(options), this.tokens.operator, this.value.getType(options));
204
+ //const variableType = this.typeExpression?.getType({ ...options, typeChain: undefined }) ?? this.value.getType({ ...options, typeChain: undefined });
205
+ // Note: compound assignments (eg. +=) are internally dealt with via the RHS being a BinaryExpression
206
+ // so this.value will be a BinaryExpression, and BinaryExpressions can figure out their own types
207
+ // options.typeChain?.push(new TypeChainEntry({ name: this.tokens.name.text, type: variableType, data: options.data, range: this.tokens.name.range, astNode: this }));
208
+ return variableType;
209
+ }
210
+ get leadingTrivia() {
211
+ return this.item.leadingTrivia;
212
+ }
213
+ clone() {
214
+ var _a, _b;
215
+ return this.finalizeClone(new AugmentedAssignmentStatement({
216
+ item: (_a = this.item) === null || _a === void 0 ? void 0 : _a.clone(),
217
+ operator: util_1.util.cloneToken(this.tokens.operator),
218
+ value: (_b = this.value) === null || _b === void 0 ? void 0 : _b.clone()
219
+ }), ['item', 'value']);
220
+ }
221
+ }
222
+ exports.AugmentedAssignmentStatement = AugmentedAssignmentStatement;
223
+ class Block extends AstNode_1.Statement {
224
+ constructor(options) {
137
225
  super();
138
- this.statements = statements;
139
- this.startingRange = startingRange;
140
- this.range = util_1.util.createRangeFromPositions(this.startingRange.start, this.statements.length
141
- ? this.statements[this.statements.length - 1].range.end
142
- : this.startingRange.start);
226
+ this.kind = AstNode_1.AstNodeKind.Block;
227
+ this.statements = options.statements;
228
+ this.symbolTable = new SymbolTable_1.SymbolTable('Block', () => this.parent.getSymbolTable());
229
+ }
230
+ buildLocation() {
231
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
232
+ if (((_a = this.statements) === null || _a === void 0 ? void 0 : _a.length) > 0) {
233
+ return util_1.util.createBoundingLocation(...(_b = this.statements) !== null && _b !== void 0 ? _b : []);
234
+ }
235
+ let lastBitBefore;
236
+ let firstBitAfter;
237
+ if ((0, reflection_1.isFunctionExpression)(this.parent)) {
238
+ lastBitBefore = util_1.util.createBoundingLocation(this.parent.tokens.functionType, this.parent.tokens.leftParen, ...((_c = this.parent.parameters) !== null && _c !== void 0 ? _c : []), this.parent.tokens.rightParen, this.parent.tokens.as, this.parent.returnTypeExpression);
239
+ firstBitAfter = (_d = this.parent.tokens.endFunctionType) === null || _d === void 0 ? void 0 : _d.location;
240
+ }
241
+ else if ((0, reflection_1.isIfStatement)(this.parent)) {
242
+ if (this.parent.thenBranch === this) {
243
+ lastBitBefore = util_1.util.createBoundingLocation(this.parent.tokens.then, this.parent.condition);
244
+ firstBitAfter = util_1.util.createBoundingLocation(this.parent.tokens.else, this.parent.elseBranch, this.parent.tokens.endIf);
245
+ }
246
+ else if (this.parent.elseBranch === this) {
247
+ lastBitBefore = (_e = this.parent.tokens.else) === null || _e === void 0 ? void 0 : _e.location;
248
+ firstBitAfter = (_f = this.parent.tokens.endIf) === null || _f === void 0 ? void 0 : _f.location;
249
+ }
250
+ }
251
+ else if ((0, reflection_1.isConditionalCompileStatement)(this.parent)) {
252
+ if (this.parent.thenBranch === this) {
253
+ lastBitBefore = util_1.util.createBoundingLocation(this.parent.tokens.condition, this.parent.tokens.not, this.parent.tokens.hashIf);
254
+ firstBitAfter = util_1.util.createBoundingLocation(this.parent.tokens.hashElse, this.parent.elseBranch, this.parent.tokens.hashEndIf);
255
+ }
256
+ else if (this.parent.elseBranch === this) {
257
+ lastBitBefore = (_g = this.parent.tokens.hashElse) === null || _g === void 0 ? void 0 : _g.location;
258
+ firstBitAfter = (_h = this.parent.tokens.hashEndIf) === null || _h === void 0 ? void 0 : _h.location;
259
+ }
260
+ }
261
+ else if ((0, reflection_1.isForStatement)(this.parent)) {
262
+ lastBitBefore = util_1.util.createBoundingLocation(this.parent.increment, this.parent.tokens.step, this.parent.finalValue, this.parent.tokens.to, this.parent.counterDeclaration, this.parent.tokens.for);
263
+ firstBitAfter = (_j = this.parent.tokens.endFor) === null || _j === void 0 ? void 0 : _j.location;
264
+ }
265
+ else if ((0, reflection_1.isForEachStatement)(this.parent)) {
266
+ lastBitBefore = util_1.util.createBoundingLocation(this.parent.target, this.parent.tokens.in, this.parent.tokens.item, this.parent.tokens.forEach);
267
+ firstBitAfter = (_k = this.parent.tokens.endFor) === null || _k === void 0 ? void 0 : _k.location;
268
+ }
269
+ else if ((0, reflection_1.isWhileStatement)(this.parent)) {
270
+ lastBitBefore = util_1.util.createBoundingLocation(this.parent.condition, this.parent.tokens.while);
271
+ firstBitAfter = (_l = this.parent.tokens.endWhile) === null || _l === void 0 ? void 0 : _l.location;
272
+ }
273
+ else if ((0, reflection_1.isTryCatchStatement)(this.parent)) {
274
+ lastBitBefore = util_1.util.createBoundingLocation(this.parent.tokens.try);
275
+ firstBitAfter = util_1.util.createBoundingLocation(this.parent.tokens.endTry, this.parent.catchStatement);
276
+ }
277
+ else if ((0, reflection_1.isCatchStatement)(this.parent) && (0, reflection_1.isTryCatchStatement)((_m = this.parent) === null || _m === void 0 ? void 0 : _m.parent)) {
278
+ lastBitBefore = util_1.util.createBoundingLocation(this.parent.tokens.catch, this.parent.exceptionVariableExpression);
279
+ firstBitAfter = (_o = this.parent.parent.tokens.endTry) === null || _o === void 0 ? void 0 : _o.location;
280
+ }
281
+ if ((lastBitBefore === null || lastBitBefore === void 0 ? void 0 : lastBitBefore.range) && (firstBitAfter === null || firstBitAfter === void 0 ? void 0 : firstBitAfter.range)) {
282
+ return util_1.util.createLocation(lastBitBefore.range.end.line, lastBitBefore.range.end.character, firstBitAfter.range.start.line, firstBitAfter.range.start.character, (_p = lastBitBefore.uri) !== null && _p !== void 0 ? _p : firstBitAfter.uri);
283
+ }
284
+ }
285
+ get location() {
286
+ if (!this._location) {
287
+ //this needs to be a getter because the body has its statements pushed to it after being constructed
288
+ this._location = this.buildLocation();
289
+ }
290
+ return this._location;
291
+ }
292
+ set location(value) {
293
+ this._location = value;
143
294
  }
144
295
  transpile(state) {
296
+ var _a;
145
297
  state.blockDepth++;
146
298
  let results = [];
147
299
  for (let i = 0; i < this.statements.length; i++) {
148
300
  let previousStatement = this.statements[i - 1];
149
301
  let statement = this.statements[i];
302
+ //is not a comment
150
303
  //if comment is on same line as parent
151
- if (reflection_1.isCommentStatement(statement) &&
152
- (util_1.util.linesTouch(state.lineage[0], statement) || util_1.util.linesTouch(previousStatement, statement))) {
304
+ if (util_1.util.isLeadingCommentOnSameLine((_a = state.lineage[0]) === null || _a === void 0 ? void 0 : _a.location, statement) ||
305
+ util_1.util.isLeadingCommentOnSameLine(previousStatement === null || previousStatement === void 0 ? void 0 : previousStatement.location, statement)) {
153
306
  results.push(' ');
154
307
  //is not a comment
155
308
  }
@@ -165,166 +318,195 @@ class Block extends Statement {
165
318
  state.blockDepth--;
166
319
  return results;
167
320
  }
321
+ get leadingTrivia() {
322
+ var _a, _b;
323
+ return (_b = (_a = this.statements[0]) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
324
+ }
168
325
  walk(visitor, options) {
169
326
  if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
170
- for (let i = 0; i < this.statements.length; i++) {
171
- visitors_1.walk(this.statements, i, visitor, options, this);
172
- }
327
+ (0, visitors_1.walkArray)(this.statements, visitor, options, this);
173
328
  }
174
329
  }
330
+ clone() {
331
+ var _a;
332
+ return this.finalizeClone(new Block({
333
+ statements: (_a = this.statements) === null || _a === void 0 ? void 0 : _a.map(s => s === null || s === void 0 ? void 0 : s.clone())
334
+ }), ['statements']);
335
+ }
175
336
  }
176
337
  exports.Block = Block;
177
- class ExpressionStatement extends Statement {
178
- constructor(expression) {
338
+ class ExpressionStatement extends AstNode_1.Statement {
339
+ constructor(options) {
340
+ var _a;
179
341
  super();
180
- this.expression = expression;
181
- this.range = this.expression.range;
342
+ this.kind = AstNode_1.AstNodeKind.ExpressionStatement;
343
+ this.expression = options.expression;
344
+ this.location = (_a = this.expression) === null || _a === void 0 ? void 0 : _a.location;
182
345
  }
183
346
  transpile(state) {
184
- return this.expression.transpile(state);
347
+ return [
348
+ state.transpileAnnotations(this),
349
+ this.expression.transpile(state)
350
+ ];
185
351
  }
186
352
  walk(visitor, options) {
187
353
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
188
- visitors_1.walk(this, 'expression', visitor, options);
189
- }
190
- }
191
- }
192
- exports.ExpressionStatement = ExpressionStatement;
193
- class CommentStatement extends Statement {
194
- constructor(comments) {
195
- var _a;
196
- super();
197
- this.comments = comments;
198
- this.visitMode = visitors_1.InternalWalkMode.visitStatements | visitors_1.InternalWalkMode.visitExpressions;
199
- if (((_a = this.comments) === null || _a === void 0 ? void 0 : _a.length) > 0) {
200
- this.range = util_1.util.createRangeFromPositions(this.comments[0].range.start, this.comments[this.comments.length - 1].range.end);
201
- }
202
- }
203
- get text() {
204
- return this.comments.map(x => x.text).join('\n');
205
- }
206
- transpile(state) {
207
- let result = [];
208
- for (let i = 0; i < this.comments.length; i++) {
209
- let comment = this.comments[i];
210
- if (i > 0) {
211
- result.push(state.indent());
212
- }
213
- result.push(state.transpileToken(comment));
214
- //add newline for all except final comment
215
- if (i < this.comments.length - 1) {
216
- result.push('\n');
217
- }
354
+ (0, visitors_1.walk)(this, 'expression', visitor, options);
218
355
  }
219
- return result;
220
356
  }
221
- getTypedef(state) {
222
- return this.transpile(state);
357
+ get leadingTrivia() {
358
+ return this.expression.leadingTrivia;
223
359
  }
224
- walk(visitor, options) {
225
- //nothing to walk
360
+ clone() {
361
+ var _a;
362
+ return this.finalizeClone(new ExpressionStatement({
363
+ expression: (_a = this.expression) === null || _a === void 0 ? void 0 : _a.clone()
364
+ }), ['expression']);
226
365
  }
227
366
  }
228
- exports.CommentStatement = CommentStatement;
229
- class ExitForStatement extends Statement {
230
- constructor(tokens) {
367
+ exports.ExpressionStatement = ExpressionStatement;
368
+ class ExitStatement extends AstNode_1.Statement {
369
+ constructor(options) {
231
370
  super();
232
- this.tokens = tokens;
233
- this.range = this.tokens.exitFor.range;
371
+ this.kind = AstNode_1.AstNodeKind.ExitStatement;
372
+ this.tokens = {
373
+ exit: options === null || options === void 0 ? void 0 : options.exit,
374
+ loopType: options.loopType
375
+ };
376
+ this.location = util_1.util.createBoundingLocation(this.tokens.exit, this.tokens.loopType);
234
377
  }
235
378
  transpile(state) {
379
+ var _a, _b;
236
380
  return [
237
- state.transpileToken(this.tokens.exitFor)
381
+ state.transpileToken(this.tokens.exit, 'exit'),
382
+ (_b = (_a = this.tokens.loopType) === null || _a === void 0 ? void 0 : _a.leadingWhitespace) !== null && _b !== void 0 ? _b : ' ',
383
+ state.transpileToken(this.tokens.loopType)
238
384
  ];
239
385
  }
240
386
  walk(visitor, options) {
241
387
  //nothing to walk
242
388
  }
243
- }
244
- exports.ExitForStatement = ExitForStatement;
245
- class ExitWhileStatement extends Statement {
246
- constructor(tokens) {
247
- super();
248
- this.tokens = tokens;
249
- this.range = this.tokens.exitWhile.range;
250
- }
251
- transpile(state) {
252
- return [
253
- state.transpileToken(this.tokens.exitWhile)
254
- ];
389
+ get leadingTrivia() {
390
+ var _a;
391
+ return (_a = this.tokens.exit) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
255
392
  }
256
- walk(visitor, options) {
257
- //nothing to walk
393
+ clone() {
394
+ return this.finalizeClone(new ExitStatement({
395
+ loopType: util_1.util.cloneToken(this.tokens.loopType),
396
+ exit: util_1.util.cloneToken(this.tokens.exit)
397
+ }));
258
398
  }
259
399
  }
260
- exports.ExitWhileStatement = ExitWhileStatement;
261
- class FunctionStatement extends Statement {
262
- constructor(name, func, namespaceName) {
400
+ exports.ExitStatement = ExitStatement;
401
+ class FunctionStatement extends AstNode_1.Statement {
402
+ constructor(options) {
403
+ var _a, _b;
263
404
  super();
264
- this.name = name;
265
- this.func = func;
266
- this.namespaceName = namespaceName;
267
- this.range = this.func.range;
405
+ this.kind = AstNode_1.AstNodeKind.FunctionStatement;
406
+ this.tokens = {
407
+ name: options.name
408
+ };
409
+ this.func = options.func;
410
+ if (this.func) {
411
+ this.func.symbolTable.name += `: '${(_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text}'`;
412
+ }
413
+ this.location = (_b = this.func) === null || _b === void 0 ? void 0 : _b.location;
268
414
  }
269
415
  /**
270
416
  * Get the name of this expression based on the parse mode
271
417
  */
272
418
  getName(parseMode) {
273
- if (this.namespaceName) {
419
+ var _a;
420
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
421
+ if (namespace) {
274
422
  let delimiter = parseMode === Parser_1.ParseMode.BrighterScript ? '.' : '_';
275
- let namespaceName = this.namespaceName.getName(parseMode);
276
- return namespaceName + delimiter + this.name.text;
423
+ let namespaceName = namespace.getName(parseMode);
424
+ return namespaceName + delimiter + ((_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text);
277
425
  }
278
426
  else {
279
- return this.name.text;
427
+ return this.tokens.name.text;
280
428
  }
281
429
  }
430
+ get leadingTrivia() {
431
+ return this.func.leadingTrivia;
432
+ }
282
433
  transpile(state) {
283
434
  //create a fake token using the full transpiled name
284
- let nameToken = Object.assign(Object.assign({}, this.name), { text: this.getName(Parser_1.ParseMode.BrightScript) });
285
- return this.func.transpile(state, nameToken);
435
+ let nameToken = Object.assign(Object.assign({}, this.tokens.name), { text: this.getName(Parser_1.ParseMode.BrightScript) });
436
+ return [
437
+ ...state.transpileAnnotations(this),
438
+ ...this.func.transpile(state, nameToken)
439
+ ];
286
440
  }
287
441
  getTypedef(state) {
288
- var _a;
442
+ var _a, _b;
289
443
  let result = [];
290
- for (let annotation of (_a = this.annotations) !== null && _a !== void 0 ? _a : []) {
444
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
445
+ result.push(comment.text, state.newline, state.indent());
446
+ }
447
+ for (let annotation of (_b = this.annotations) !== null && _b !== void 0 ? _b : []) {
291
448
  result.push(...annotation.getTypedef(state), state.newline, state.indent());
292
449
  }
293
- result.push(...this.func.getTypedef(state, this.name));
450
+ result.push(...this.func.getTypedef(state));
294
451
  return result;
295
452
  }
296
453
  walk(visitor, options) {
297
454
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
298
- visitors_1.walk(this, 'func', visitor, options);
455
+ (0, visitors_1.walk)(this, 'func', visitor, options);
299
456
  }
300
457
  }
458
+ getType(options) {
459
+ const funcExprType = this.func.getType(options);
460
+ funcExprType.setName(this.getName(Parser_1.ParseMode.BrighterScript));
461
+ return funcExprType;
462
+ }
463
+ clone() {
464
+ var _a;
465
+ return this.finalizeClone(new FunctionStatement({
466
+ func: (_a = this.func) === null || _a === void 0 ? void 0 : _a.clone(),
467
+ name: util_1.util.cloneToken(this.tokens.name)
468
+ }), ['func']);
469
+ }
301
470
  }
302
471
  exports.FunctionStatement = FunctionStatement;
303
- class IfStatement extends Statement {
304
- constructor(tokens, condition, thenBranch, elseBranch, isInline) {
305
- var _a, _b;
472
+ class IfStatement extends AstNode_1.Statement {
473
+ constructor(options) {
306
474
  super();
307
- this.tokens = tokens;
308
- this.condition = condition;
309
- this.thenBranch = thenBranch;
310
- this.elseBranch = elseBranch;
311
- this.isInline = isInline;
312
- this.range = util_1.util.createRangeFromPositions(this.tokens.if.range.start, ((_b = (_a = this.tokens.endIf) !== null && _a !== void 0 ? _a : this.elseBranch) !== null && _b !== void 0 ? _b : this.thenBranch).range.end);
475
+ this.kind = AstNode_1.AstNodeKind.IfStatement;
476
+ this.condition = options.condition;
477
+ this.thenBranch = options.thenBranch;
478
+ this.elseBranch = options.elseBranch;
479
+ this.tokens = {
480
+ if: options.if,
481
+ then: options.then,
482
+ else: options.else,
483
+ endIf: options.endIf
484
+ };
485
+ this.location = util_1.util.createBoundingLocation(util_1.util.createBoundingLocationFromTokens(this.tokens), this.condition, this.thenBranch, this.elseBranch);
486
+ }
487
+ get isInline() {
488
+ var _a, _b, _c, _d;
489
+ const allLeadingTrivia = [
490
+ ...this.thenBranch.leadingTrivia,
491
+ ...this.thenBranch.statements.map(s => s.leadingTrivia).flat(),
492
+ ...((_b = (_a = this.tokens.else) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : []),
493
+ ...((_d = (_c = this.tokens.endIf) === null || _c === void 0 ? void 0 : _c.leadingTrivia) !== null && _d !== void 0 ? _d : [])
494
+ ];
495
+ const hasNewline = allLeadingTrivia.find(t => t.kind === TokenKind_1.TokenKind.Newline);
496
+ return !hasNewline;
313
497
  }
314
498
  transpile(state) {
499
+ var _a, _b;
315
500
  let results = [];
316
501
  //if (already indented by block)
317
- results.push(state.transpileToken(this.tokens.if));
502
+ results.push(state.transpileToken((_a = this.tokens.if) !== null && _a !== void 0 ? _a : (0, creators_1.createToken)(TokenKind_1.TokenKind.If)));
318
503
  results.push(' ');
319
504
  //conditions
320
505
  results.push(...this.condition.transpile(state));
321
- results.push(' ');
322
506
  //then
323
507
  if (this.tokens.then) {
324
- results.push(state.transpileToken(this.tokens.then));
325
- }
326
- else {
327
- results.push('then');
508
+ results.push(' ');
509
+ results.push(state.transpileToken(this.tokens.then, 'then'));
328
510
  }
329
511
  state.lineage.unshift(this);
330
512
  //if statement body
@@ -333,20 +515,18 @@ class IfStatement extends Statement {
333
515
  if (thenNodes.length > 0) {
334
516
  results.push(thenNodes);
335
517
  }
336
- results.push('\n');
337
518
  //else branch
338
- if (this.tokens.else) {
339
- //else
340
- results.push(state.indent(), state.transpileToken(this.tokens.else));
341
- }
342
519
  if (this.elseBranch) {
343
- if (reflection_1.isIfStatement(this.elseBranch)) {
520
+ //else
521
+ results.push(...state.transpileEndBlockToken(this.thenBranch, this.tokens.else, 'else'));
522
+ if ((0, reflection_1.isIfStatement)(this.elseBranch)) {
344
523
  //chained elseif
345
524
  state.lineage.unshift(this.elseBranch);
346
525
  let body = this.elseBranch.transpile(state);
347
526
  state.lineage.shift();
348
527
  if (body.length > 0) {
349
- results.push(' ');
528
+ //zero or more spaces between the `else` and the `if`
529
+ results.push(this.elseBranch.tokens.if.leadingWhitespace);
350
530
  results.push(...body);
351
531
  // stop here because chained if will transpile the rest
352
532
  return results;
@@ -357,125 +537,167 @@ class IfStatement extends Statement {
357
537
  }
358
538
  else {
359
539
  //else body
360
- state.lineage.unshift(this.elseBranch);
540
+ state.lineage.unshift(this.tokens.else);
361
541
  let body = this.elseBranch.transpile(state);
362
542
  state.lineage.shift();
363
543
  if (body.length > 0) {
364
544
  results.push(...body);
365
545
  }
366
- results.push('\n');
367
546
  }
368
547
  }
369
548
  //end if
370
- results.push(state.indent());
371
- if (this.tokens.endIf) {
372
- results.push(state.transpileToken(this.tokens.endIf));
373
- }
374
- else {
375
- results.push('end if');
376
- }
549
+ results.push(...state.transpileEndBlockToken((_b = this.elseBranch) !== null && _b !== void 0 ? _b : this.thenBranch, this.tokens.endIf, 'end if'));
377
550
  return results;
378
551
  }
379
552
  walk(visitor, options) {
380
553
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
381
- visitors_1.walk(this, 'condition', visitor, options);
554
+ (0, visitors_1.walk)(this, 'condition', visitor, options);
382
555
  }
383
556
  if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
384
- visitors_1.walk(this, 'thenBranch', visitor, options);
557
+ (0, visitors_1.walk)(this, 'thenBranch', visitor, options);
385
558
  }
386
559
  if (this.elseBranch && options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
387
- visitors_1.walk(this, 'elseBranch', visitor, options);
560
+ (0, visitors_1.walk)(this, 'elseBranch', visitor, options);
388
561
  }
389
562
  }
563
+ get leadingTrivia() {
564
+ var _a, _b;
565
+ return (_b = (_a = this.tokens.if) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
566
+ }
567
+ get endTrivia() {
568
+ var _a, _b;
569
+ return (_b = (_a = this.tokens.endIf) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
570
+ }
571
+ clone() {
572
+ var _a, _b, _c;
573
+ return this.finalizeClone(new IfStatement({
574
+ if: util_1.util.cloneToken(this.tokens.if),
575
+ else: util_1.util.cloneToken(this.tokens.else),
576
+ endIf: util_1.util.cloneToken(this.tokens.endIf),
577
+ then: util_1.util.cloneToken(this.tokens.then),
578
+ condition: (_a = this.condition) === null || _a === void 0 ? void 0 : _a.clone(),
579
+ thenBranch: (_b = this.thenBranch) === null || _b === void 0 ? void 0 : _b.clone(),
580
+ elseBranch: (_c = this.elseBranch) === null || _c === void 0 ? void 0 : _c.clone()
581
+ }), ['condition', 'thenBranch', 'elseBranch']);
582
+ }
390
583
  }
391
584
  exports.IfStatement = IfStatement;
392
- class IncrementStatement extends Statement {
393
- constructor(value, operator) {
585
+ class IncrementStatement extends AstNode_1.Statement {
586
+ constructor(options) {
394
587
  super();
395
- this.value = value;
396
- this.operator = operator;
397
- this.range = util_1.util.createRangeFromPositions(this.value.range.start, this.operator.range.end);
588
+ this.kind = AstNode_1.AstNodeKind.IncrementStatement;
589
+ this.value = options.value;
590
+ this.tokens = {
591
+ operator: options.operator
592
+ };
593
+ this.location = util_1.util.createBoundingLocation(this.value, this.tokens.operator);
398
594
  }
399
595
  transpile(state) {
400
596
  return [
401
597
  ...this.value.transpile(state),
402
- state.transpileToken(this.operator)
598
+ state.transpileToken(this.tokens.operator)
403
599
  ];
404
600
  }
405
601
  walk(visitor, options) {
406
602
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
407
- visitors_1.walk(this, 'value', visitor, options);
603
+ (0, visitors_1.walk)(this, 'value', visitor, options);
408
604
  }
409
605
  }
606
+ get leadingTrivia() {
607
+ var _a, _b;
608
+ return (_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
609
+ }
610
+ clone() {
611
+ var _a;
612
+ return this.finalizeClone(new IncrementStatement({
613
+ value: (_a = this.value) === null || _a === void 0 ? void 0 : _a.clone(),
614
+ operator: util_1.util.cloneToken(this.tokens.operator)
615
+ }), ['value']);
616
+ }
410
617
  }
411
618
  exports.IncrementStatement = IncrementStatement;
412
619
  /**
413
620
  * Represents a `print` statement within BrightScript.
414
621
  */
415
- class PrintStatement extends Statement {
622
+ class PrintStatement extends AstNode_1.Statement {
416
623
  /**
417
624
  * Creates a new internal representation of a BrightScript `print` statement.
418
- * @param expressions an array of expressions or `PrintSeparator`s to be
419
- * evaluated and printed.
625
+ * @param options the options for this statement
626
+ * @param options.print a print token
627
+ * @param options.expressions an array of expressions to be evaluated and printed. Wrap PrintSeparator tokens (`;` or `,`) in `PrintSeparatorExpression`
420
628
  */
421
- constructor(tokens, expressions) {
629
+ constructor(options) {
630
+ var _a;
422
631
  super();
423
- this.tokens = tokens;
424
- this.expressions = expressions;
425
- this.range = util_1.util.createRangeFromPositions(this.tokens.print.range.start, this.expressions.length
426
- ? this.expressions[this.expressions.length - 1].range.end
427
- : this.tokens.print.range.end);
632
+ this.kind = AstNode_1.AstNodeKind.PrintStatement;
633
+ this.tokens = {
634
+ print: options.print
635
+ };
636
+ this.expressions = options.expressions;
637
+ this.location = util_1.util.createBoundingLocation(this.tokens.print, ...((_a = this.expressions) !== null && _a !== void 0 ? _a : []));
428
638
  }
429
639
  transpile(state) {
430
640
  var _a;
431
641
  let result = [
432
- state.transpileToken(this.tokens.print),
433
- ' '
642
+ state.transpileToken(this.tokens.print, 'print')
434
643
  ];
644
+ //if the first expression has no leading whitespace, add a single space between the `print` and the expression
645
+ if (this.expressions.length > 0 && !this.expressions[0].leadingTrivia.find(t => (t === null || t === void 0 ? void 0 : t.kind) === TokenKind_1.TokenKind.Whitespace)) {
646
+ result.push(' ');
647
+ }
648
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
435
649
  for (let i = 0; i < this.expressions.length; i++) {
436
- const expressionOrSeparator = this.expressions[i];
437
- if (expressionOrSeparator.transpile) {
438
- result.push(...expressionOrSeparator.transpile(state));
439
- }
440
- else {
441
- result.push(state.tokenToSourceNode(expressionOrSeparator));
650
+ const expression = this.expressions[i];
651
+ let leadingWhitespace = (_a = expression.leadingTrivia.find(t => (t === null || t === void 0 ? void 0 : t.kind) === TokenKind_1.TokenKind.Whitespace)) === null || _a === void 0 ? void 0 : _a.text;
652
+ if (leadingWhitespace) {
653
+ result.push(leadingWhitespace);
654
+ //if the previous expression was NOT a separator, and this one is not also, add a space between them
442
655
  }
443
- //if there's an expression after us, add a space
444
- if ((_a = this.expressions[i + 1]) === null || _a === void 0 ? void 0 : _a.transpile) {
656
+ else if (i > 0 && !(0, reflection_1.isPrintSeparatorExpression)(this.expressions[i - 1]) && !(0, reflection_1.isPrintSeparatorExpression)(expression) && !leadingWhitespace) {
445
657
  result.push(' ');
446
658
  }
659
+ result.push(...expression.transpile(state));
447
660
  }
448
661
  return result;
449
662
  }
450
663
  walk(visitor, options) {
451
664
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
452
- for (let i = 0; i < this.expressions.length; i++) {
453
- //sometimes we have semicolon `Token`s in the expressions list (should probably fix that...), so only emit the actual expressions
454
- if (reflection_1.isExpression(this.expressions[i])) {
455
- visitors_1.walk(this.expressions, i, visitor, options, this);
456
- }
457
- }
665
+ (0, visitors_1.walkArray)(this.expressions, visitor, options, this);
458
666
  }
459
667
  }
668
+ get leadingTrivia() {
669
+ var _a, _b;
670
+ return (_b = (_a = this.tokens.print) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
671
+ }
672
+ clone() {
673
+ var _a;
674
+ return this.finalizeClone(new PrintStatement({
675
+ print: util_1.util.cloneToken(this.tokens.print),
676
+ expressions: (_a = this.expressions) === null || _a === void 0 ? void 0 : _a.map(e => e === null || e === void 0 ? void 0 : e.clone())
677
+ }), ['expressions']);
678
+ }
460
679
  }
461
680
  exports.PrintStatement = PrintStatement;
462
- class DimStatement extends Statement {
463
- constructor(dimToken, identifier, openingSquare, dimensions, closingSquare) {
464
- var _a, _b, _c, _d;
681
+ class DimStatement extends AstNode_1.Statement {
682
+ constructor(options) {
683
+ var _a;
465
684
  super();
466
- this.dimToken = dimToken;
467
- this.identifier = identifier;
468
- this.openingSquare = openingSquare;
469
- this.dimensions = dimensions;
470
- this.closingSquare = closingSquare;
471
- this.range = util_1.util.createRangeFromPositions(this.dimToken.range.start, ((_d = (_c = (_b = (_a = this.closingSquare) !== null && _a !== void 0 ? _a : this.dimensions[this.dimensions.length - 1]) !== null && _b !== void 0 ? _b : this.openingSquare) !== null && _c !== void 0 ? _c : this.identifier) !== null && _d !== void 0 ? _d : this.dimToken).range.end);
685
+ this.kind = AstNode_1.AstNodeKind.DimStatement;
686
+ this.tokens = {
687
+ dim: options === null || options === void 0 ? void 0 : options.dim,
688
+ name: options.name,
689
+ openingSquare: options.openingSquare,
690
+ closingSquare: options.closingSquare
691
+ };
692
+ this.dimensions = options.dimensions;
693
+ this.location = util_1.util.createBoundingLocation(options.dim, options.name, options.openingSquare, ...((_a = this.dimensions) !== null && _a !== void 0 ? _a : []), options.closingSquare);
472
694
  }
473
695
  transpile(state) {
474
696
  let result = [
475
- state.transpileToken(this.dimToken),
697
+ state.transpileToken(this.tokens.dim, 'dim'),
476
698
  ' ',
477
- state.transpileToken(this.identifier),
478
- state.transpileToken(this.openingSquare)
699
+ state.transpileToken(this.tokens.name),
700
+ state.transpileToken(this.tokens.openingSquare, '[')
479
701
  ];
480
702
  for (let i = 0; i < this.dimensions.length; i++) {
481
703
  if (i > 0) {
@@ -483,28 +705,53 @@ class DimStatement extends Statement {
483
705
  }
484
706
  result.push(...this.dimensions[i].transpile(state));
485
707
  }
486
- result.push(state.transpileToken(this.closingSquare));
708
+ result.push(state.transpileToken(this.tokens.closingSquare, ']'));
487
709
  return result;
488
710
  }
489
711
  walk(visitor, options) {
490
- var _a;
491
- if (((_a = this.dimensions) === null || _a === void 0 ? void 0 : _a.length) > 0 && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
492
- for (let i = 0; i < this.dimensions.length; i++) {
493
- visitors_1.walk(this.dimensions, i, visitor, options, this);
494
- }
712
+ var _a, _b;
713
+ if (((_a = this.dimensions) === null || _a === void 0 ? void 0 : _a.length) !== undefined && ((_b = this.dimensions) === null || _b === void 0 ? void 0 : _b.length) > 0 && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
714
+ (0, visitors_1.walkArray)(this.dimensions, visitor, options, this);
715
+ }
716
+ }
717
+ getType(options) {
718
+ var _a, _b;
719
+ const numDimensions = (_b = (_a = this.dimensions) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 1;
720
+ let type = new ArrayType_1.ArrayType();
721
+ for (let i = 0; i < numDimensions - 1; i++) {
722
+ type = new ArrayType_1.ArrayType(type);
495
723
  }
724
+ return type;
725
+ }
726
+ get leadingTrivia() {
727
+ var _a, _b;
728
+ return (_b = (_a = this.tokens.dim) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
729
+ }
730
+ clone() {
731
+ var _a;
732
+ return this.finalizeClone(new DimStatement({
733
+ dim: util_1.util.cloneToken(this.tokens.dim),
734
+ name: util_1.util.cloneToken(this.tokens.name),
735
+ openingSquare: util_1.util.cloneToken(this.tokens.openingSquare),
736
+ dimensions: (_a = this.dimensions) === null || _a === void 0 ? void 0 : _a.map(e => e === null || e === void 0 ? void 0 : e.clone()),
737
+ closingSquare: util_1.util.cloneToken(this.tokens.closingSquare)
738
+ }), ['dimensions']);
496
739
  }
497
740
  }
498
741
  exports.DimStatement = DimStatement;
499
- class GotoStatement extends Statement {
500
- constructor(tokens) {
742
+ class GotoStatement extends AstNode_1.Statement {
743
+ constructor(options) {
501
744
  super();
502
- this.tokens = tokens;
503
- this.range = util_1.util.createRangeFromPositions(this.tokens.goto.range.start, this.tokens.label.range.end);
745
+ this.kind = AstNode_1.AstNodeKind.GotoStatement;
746
+ this.tokens = {
747
+ goto: options.goto,
748
+ label: options.label
749
+ };
750
+ this.location = util_1.util.createBoundingLocation(this.tokens.goto, this.tokens.label);
504
751
  }
505
752
  transpile(state) {
506
753
  return [
507
- state.transpileToken(this.tokens.goto),
754
+ state.transpileToken(this.tokens.goto, 'goto'),
508
755
  ' ',
509
756
  state.transpileToken(this.tokens.label)
510
757
  ];
@@ -512,36 +759,61 @@ class GotoStatement extends Statement {
512
759
  walk(visitor, options) {
513
760
  //nothing to walk
514
761
  }
762
+ get leadingTrivia() {
763
+ var _a, _b;
764
+ return (_b = (_a = this.tokens.goto) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
765
+ }
766
+ clone() {
767
+ return this.finalizeClone(new GotoStatement({
768
+ goto: util_1.util.cloneToken(this.tokens.goto),
769
+ label: util_1.util.cloneToken(this.tokens.label)
770
+ }));
771
+ }
515
772
  }
516
773
  exports.GotoStatement = GotoStatement;
517
- class LabelStatement extends Statement {
518
- constructor(tokens) {
774
+ class LabelStatement extends AstNode_1.Statement {
775
+ constructor(options) {
519
776
  super();
520
- this.tokens = tokens;
521
- this.range = util_1.util.createRangeFromPositions(this.tokens.identifier.range.start, this.tokens.colon.range.end);
777
+ this.kind = AstNode_1.AstNodeKind.LabelStatement;
778
+ this.tokens = {
779
+ name: options.name,
780
+ colon: options.colon
781
+ };
782
+ this.location = util_1.util.createBoundingLocation(this.tokens.name, this.tokens.colon);
783
+ }
784
+ get leadingTrivia() {
785
+ return this.tokens.name.leadingTrivia;
522
786
  }
523
787
  transpile(state) {
524
788
  return [
525
- state.transpileToken(this.tokens.identifier),
526
- state.transpileToken(this.tokens.colon)
789
+ state.transpileToken(this.tokens.name),
790
+ state.transpileToken(this.tokens.colon, ':')
527
791
  ];
528
792
  }
529
793
  walk(visitor, options) {
530
794
  //nothing to walk
531
795
  }
796
+ clone() {
797
+ return this.finalizeClone(new LabelStatement({
798
+ name: util_1.util.cloneToken(this.tokens.name),
799
+ colon: util_1.util.cloneToken(this.tokens.colon)
800
+ }));
801
+ }
532
802
  }
533
803
  exports.LabelStatement = LabelStatement;
534
- class ReturnStatement extends Statement {
535
- constructor(tokens, value) {
536
- var _a;
804
+ class ReturnStatement extends AstNode_1.Statement {
805
+ constructor(options) {
537
806
  super();
538
- this.tokens = tokens;
539
- this.value = value;
540
- this.range = util_1.util.createRangeFromPositions(this.tokens.return.range.start, ((_a = this.value) === null || _a === void 0 ? void 0 : _a.range.end) || this.tokens.return.range.end);
807
+ this.kind = AstNode_1.AstNodeKind.ReturnStatement;
808
+ this.tokens = {
809
+ return: options === null || options === void 0 ? void 0 : options.return
810
+ };
811
+ this.value = options === null || options === void 0 ? void 0 : options.value;
812
+ this.location = util_1.util.createBoundingLocation(this.tokens.return, this.value);
541
813
  }
542
814
  transpile(state) {
543
815
  let result = [];
544
- result.push(state.transpileToken(this.tokens.return));
816
+ result.push(state.transpileToken(this.tokens.return, 'return'));
545
817
  if (this.value) {
546
818
  result.push(' ');
547
819
  result.push(...this.value.transpile(state));
@@ -550,258 +822,409 @@ class ReturnStatement extends Statement {
550
822
  }
551
823
  walk(visitor, options) {
552
824
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
553
- visitors_1.walk(this, 'value', visitor, options);
825
+ (0, visitors_1.walk)(this, 'value', visitor, options);
554
826
  }
555
827
  }
828
+ get leadingTrivia() {
829
+ var _a, _b;
830
+ return (_b = (_a = this.tokens.return) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
831
+ }
832
+ clone() {
833
+ var _a;
834
+ return this.finalizeClone(new ReturnStatement({
835
+ return: util_1.util.cloneToken(this.tokens.return),
836
+ value: (_a = this.value) === null || _a === void 0 ? void 0 : _a.clone()
837
+ }), ['value']);
838
+ }
556
839
  }
557
840
  exports.ReturnStatement = ReturnStatement;
558
- class EndStatement extends Statement {
559
- constructor(tokens) {
841
+ class EndStatement extends AstNode_1.Statement {
842
+ constructor(options) {
843
+ var _a;
560
844
  super();
561
- this.tokens = tokens;
562
- this.range = util_1.util.createRangeFromPositions(this.tokens.end.range.start, this.tokens.end.range.end);
845
+ this.kind = AstNode_1.AstNodeKind.EndStatement;
846
+ this.tokens = {
847
+ end: options === null || options === void 0 ? void 0 : options.end
848
+ };
849
+ this.location = (_a = this.tokens.end) === null || _a === void 0 ? void 0 : _a.location;
563
850
  }
564
851
  transpile(state) {
565
852
  return [
566
- state.transpileToken(this.tokens.end)
853
+ state.transpileToken(this.tokens.end, 'end')
567
854
  ];
568
855
  }
569
856
  walk(visitor, options) {
570
857
  //nothing to walk
571
858
  }
859
+ get leadingTrivia() {
860
+ var _a, _b;
861
+ return (_b = (_a = this.tokens.end) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
862
+ }
863
+ clone() {
864
+ return this.finalizeClone(new EndStatement({
865
+ end: util_1.util.cloneToken(this.tokens.end)
866
+ }));
867
+ }
572
868
  }
573
869
  exports.EndStatement = EndStatement;
574
- class StopStatement extends Statement {
575
- constructor(tokens) {
870
+ class StopStatement extends AstNode_1.Statement {
871
+ constructor(options) {
872
+ var _a, _b;
576
873
  super();
577
- this.tokens = tokens;
578
- this.range = util_1.util.createRangeFromPositions(this.tokens.stop.range.start, this.tokens.stop.range.end);
874
+ this.kind = AstNode_1.AstNodeKind.StopStatement;
875
+ this.tokens = { stop: options === null || options === void 0 ? void 0 : options.stop };
876
+ this.location = (_b = (_a = this.tokens) === null || _a === void 0 ? void 0 : _a.stop) === null || _b === void 0 ? void 0 : _b.location;
579
877
  }
580
878
  transpile(state) {
581
879
  return [
582
- state.transpileToken(this.tokens.stop)
880
+ state.transpileToken(this.tokens.stop, 'stop')
583
881
  ];
584
882
  }
585
883
  walk(visitor, options) {
586
884
  //nothing to walk
587
885
  }
886
+ get leadingTrivia() {
887
+ var _a, _b;
888
+ return (_b = (_a = this.tokens.stop) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
889
+ }
890
+ clone() {
891
+ return this.finalizeClone(new StopStatement({
892
+ stop: util_1.util.cloneToken(this.tokens.stop)
893
+ }));
894
+ }
588
895
  }
589
896
  exports.StopStatement = StopStatement;
590
- class ForStatement extends Statement {
591
- constructor(forToken, counterDeclaration, toToken, finalValue, body, endForToken, stepToken, increment) {
592
- var _a, _b;
897
+ class ForStatement extends AstNode_1.Statement {
898
+ constructor(options) {
593
899
  super();
594
- this.forToken = forToken;
595
- this.counterDeclaration = counterDeclaration;
596
- this.toToken = toToken;
597
- this.finalValue = finalValue;
598
- this.body = body;
599
- this.endForToken = endForToken;
600
- this.stepToken = stepToken;
601
- this.increment = increment;
602
- const lastRange = (_b = (_a = this.endForToken) === null || _a === void 0 ? void 0 : _a.range) !== null && _b !== void 0 ? _b : body.range;
603
- this.range = util_1.util.createRangeFromPositions(this.forToken.range.start, lastRange.end);
900
+ this.kind = AstNode_1.AstNodeKind.ForStatement;
901
+ this.tokens = {
902
+ for: options.for,
903
+ to: options.to,
904
+ endFor: options.endFor,
905
+ step: options.step
906
+ };
907
+ this.counterDeclaration = options.counterDeclaration;
908
+ this.finalValue = options.finalValue;
909
+ this.body = options.body;
910
+ this.increment = options.increment;
911
+ this.location = util_1.util.createBoundingLocation(this.tokens.for, this.counterDeclaration, this.tokens.to, this.finalValue, this.tokens.step, this.increment, this.body, this.tokens.endFor);
604
912
  }
605
913
  transpile(state) {
606
914
  let result = [];
607
915
  //for
608
- result.push(state.transpileToken(this.forToken), ' ');
916
+ result.push(state.transpileToken(this.tokens.for, 'for'), ' ');
609
917
  //i=1
610
918
  result.push(...this.counterDeclaration.transpile(state), ' ');
611
919
  //to
612
- result.push(state.transpileToken(this.toToken), ' ');
920
+ result.push(state.transpileToken(this.tokens.to, 'to'), ' ');
613
921
  //final value
614
922
  result.push(this.finalValue.transpile(state));
615
923
  //step
616
- if (this.stepToken) {
617
- result.push(' ', state.transpileToken(this.stepToken), ' ', this.increment.transpile(state));
924
+ if (this.increment) {
925
+ result.push(' ', state.transpileToken(this.tokens.step, 'step'), ' ', this.increment.transpile(state));
618
926
  }
619
927
  //loop body
620
928
  state.lineage.unshift(this);
621
929
  result.push(...this.body.transpile(state));
622
930
  state.lineage.shift();
623
- if (this.body.statements.length > 0) {
624
- result.push('\n');
625
- }
626
931
  //end for
627
- result.push(state.indent(), state.transpileToken(this.endForToken));
932
+ result.push(...state.transpileEndBlockToken(this.body, this.tokens.endFor, 'end for'));
628
933
  return result;
629
934
  }
630
935
  walk(visitor, options) {
631
936
  if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
632
- visitors_1.walk(this, 'counterDeclaration', visitor, options);
937
+ (0, visitors_1.walk)(this, 'counterDeclaration', visitor, options);
633
938
  }
634
939
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
635
- visitors_1.walk(this, 'finalValue', visitor, options);
636
- visitors_1.walk(this, 'increment', visitor, options);
940
+ (0, visitors_1.walk)(this, 'finalValue', visitor, options);
941
+ (0, visitors_1.walk)(this, 'increment', visitor, options);
637
942
  }
638
943
  if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
639
- visitors_1.walk(this, 'body', visitor, options);
944
+ (0, visitors_1.walk)(this, 'body', visitor, options);
640
945
  }
641
946
  }
947
+ get leadingTrivia() {
948
+ var _a, _b;
949
+ return (_b = (_a = this.tokens.for) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
950
+ }
951
+ get endTrivia() {
952
+ var _a, _b;
953
+ return (_b = (_a = this.tokens.endFor) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
954
+ }
955
+ clone() {
956
+ var _a, _b, _c, _d;
957
+ return this.finalizeClone(new ForStatement({
958
+ for: util_1.util.cloneToken(this.tokens.for),
959
+ counterDeclaration: (_a = this.counterDeclaration) === null || _a === void 0 ? void 0 : _a.clone(),
960
+ to: util_1.util.cloneToken(this.tokens.to),
961
+ finalValue: (_b = this.finalValue) === null || _b === void 0 ? void 0 : _b.clone(),
962
+ body: (_c = this.body) === null || _c === void 0 ? void 0 : _c.clone(),
963
+ endFor: util_1.util.cloneToken(this.tokens.endFor),
964
+ step: util_1.util.cloneToken(this.tokens.step),
965
+ increment: (_d = this.increment) === null || _d === void 0 ? void 0 : _d.clone()
966
+ }), ['counterDeclaration', 'finalValue', 'body', 'increment']);
967
+ }
642
968
  }
643
969
  exports.ForStatement = ForStatement;
644
- class ForEachStatement extends Statement {
645
- constructor(forEachToken, item, inToken, target, body, endForToken) {
646
- var _a, _b, _c, _d, _e;
970
+ class ForEachStatement extends AstNode_1.Statement {
971
+ constructor(options) {
647
972
  super();
648
- this.forEachToken = forEachToken;
649
- this.item = item;
650
- this.inToken = inToken;
651
- this.target = target;
652
- this.body = body;
653
- this.endForToken = endForToken;
654
- this.range = util_1.util.createRangeFromPositions(this.forEachToken.range.start, ((_e = (_d = (_c = (_b = (_a = this.endForToken) !== null && _a !== void 0 ? _a : this.body) !== null && _b !== void 0 ? _b : this.target) !== null && _c !== void 0 ? _c : this.inToken) !== null && _d !== void 0 ? _d : this.item) !== null && _e !== void 0 ? _e : this.forEachToken).range.end);
973
+ this.kind = AstNode_1.AstNodeKind.ForEachStatement;
974
+ this.tokens = {
975
+ forEach: options.forEach,
976
+ item: options.item,
977
+ as: options.as,
978
+ in: options.in,
979
+ endFor: options.endFor
980
+ };
981
+ this.body = options.body;
982
+ this.target = options.target;
983
+ this.typeExpression = options.typeExpression;
984
+ this.location = util_1.util.createBoundingLocation(this.tokens.forEach, this.tokens.item, this.tokens.as, this.typeExpression, this.tokens.in, this.target, this.body, this.tokens.endFor);
655
985
  }
656
986
  transpile(state) {
657
987
  let result = [];
658
988
  //for each
659
- result.push(state.transpileToken(this.forEachToken), ' ');
989
+ result.push(state.transpileToken(this.tokens.forEach, 'for each'), ' ');
660
990
  //item
661
- result.push(state.transpileToken(this.item), ' ');
991
+ result.push(state.transpileToken(this.tokens.item), ' ');
662
992
  //in
663
- result.push(state.transpileToken(this.inToken), ' ');
993
+ result.push(state.transpileToken(this.tokens.in, 'in'), ' ');
664
994
  //target
665
995
  result.push(...this.target.transpile(state));
666
996
  //body
667
997
  state.lineage.unshift(this);
668
998
  result.push(...this.body.transpile(state));
669
999
  state.lineage.shift();
670
- if (this.body.statements.length > 0) {
671
- result.push('\n');
672
- }
673
1000
  //end for
674
- result.push(state.indent(), state.transpileToken(this.endForToken));
1001
+ result.push(...state.transpileEndBlockToken(this.body, this.tokens.endFor, 'end for'));
675
1002
  return result;
676
1003
  }
677
1004
  walk(visitor, options) {
678
1005
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
679
- visitors_1.walk(this, 'target', visitor, options);
1006
+ (0, visitors_1.walk)(this, 'target', visitor, options);
680
1007
  }
681
1008
  if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
682
- visitors_1.walk(this, 'body', visitor, options);
1009
+ (0, visitors_1.walk)(this, 'body', visitor, options);
1010
+ }
1011
+ }
1012
+ getType(options) {
1013
+ // Used for hovers on the statement 'item' token
1014
+ return this.getLoopVariableType(options);
1015
+ }
1016
+ getLoopVariableType(options) {
1017
+ if (this.typeExpression) {
1018
+ return this.typeExpression.getType(options);
683
1019
  }
1020
+ //register the for loop variable
1021
+ const loopTargetType = this.target.getType({ flags: 1 /* SymbolTypeFlag.runtime */ });
1022
+ const loopVarType = new ReferenceType_1.ArrayDefaultTypeReferenceType(loopTargetType);
1023
+ return loopVarType;
1024
+ }
1025
+ get leadingTrivia() {
1026
+ var _a, _b;
1027
+ return (_b = (_a = this.tokens.forEach) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1028
+ }
1029
+ get endTrivia() {
1030
+ var _a, _b;
1031
+ return (_b = (_a = this.tokens.endFor) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1032
+ }
1033
+ clone() {
1034
+ var _a, _b, _c;
1035
+ return this.finalizeClone(new ForEachStatement({
1036
+ forEach: util_1.util.cloneToken(this.tokens.forEach),
1037
+ in: util_1.util.cloneToken(this.tokens.in),
1038
+ as: util_1.util.cloneToken(this.tokens.as),
1039
+ typeExpression: (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.clone(),
1040
+ endFor: util_1.util.cloneToken(this.tokens.endFor),
1041
+ item: util_1.util.cloneToken(this.tokens.item),
1042
+ target: (_b = this.target) === null || _b === void 0 ? void 0 : _b.clone(),
1043
+ body: (_c = this.body) === null || _c === void 0 ? void 0 : _c.clone()
1044
+ }), ['target', 'body']);
684
1045
  }
685
1046
  }
686
1047
  exports.ForEachStatement = ForEachStatement;
687
- class WhileStatement extends Statement {
688
- constructor(tokens, condition, body) {
689
- var _a, _b;
1048
+ class WhileStatement extends AstNode_1.Statement {
1049
+ constructor(options) {
690
1050
  super();
691
- this.tokens = tokens;
692
- this.condition = condition;
693
- this.body = body;
694
- const lastRange = (_b = (_a = this.tokens.endWhile) === null || _a === void 0 ? void 0 : _a.range) !== null && _b !== void 0 ? _b : body.range;
695
- this.range = util_1.util.createRangeFromPositions(this.tokens.while.range.start, lastRange.end);
1051
+ this.kind = AstNode_1.AstNodeKind.WhileStatement;
1052
+ this.tokens = {
1053
+ while: options.while,
1054
+ endWhile: options.endWhile
1055
+ };
1056
+ this.body = options.body;
1057
+ this.condition = options.condition;
1058
+ this.location = util_1.util.createBoundingLocation(this.tokens.while, this.condition, this.body, this.tokens.endWhile);
696
1059
  }
697
1060
  transpile(state) {
698
1061
  let result = [];
699
1062
  //while
700
- result.push(state.transpileToken(this.tokens.while), ' ');
1063
+ result.push(state.transpileToken(this.tokens.while, 'while'), ' ');
701
1064
  //condition
702
1065
  result.push(...this.condition.transpile(state));
703
1066
  state.lineage.unshift(this);
704
1067
  //body
705
1068
  result.push(...this.body.transpile(state));
706
1069
  state.lineage.shift();
707
- //trailing newline only if we have body statements
708
- result.push('\n');
709
1070
  //end while
710
- result.push(state.indent(), state.transpileToken(this.tokens.endWhile));
1071
+ result.push(...state.transpileEndBlockToken(this.body, this.tokens.endWhile, 'end while'));
711
1072
  return result;
712
1073
  }
713
1074
  walk(visitor, options) {
714
1075
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
715
- visitors_1.walk(this, 'condition', visitor, options);
1076
+ (0, visitors_1.walk)(this, 'condition', visitor, options);
716
1077
  }
717
1078
  if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
718
- visitors_1.walk(this, 'body', visitor, options);
1079
+ (0, visitors_1.walk)(this, 'body', visitor, options);
719
1080
  }
720
1081
  }
1082
+ get leadingTrivia() {
1083
+ var _a, _b;
1084
+ return (_b = (_a = this.tokens.while) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1085
+ }
1086
+ get endTrivia() {
1087
+ var _a, _b;
1088
+ return (_b = (_a = this.tokens.endWhile) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1089
+ }
1090
+ clone() {
1091
+ var _a, _b;
1092
+ return this.finalizeClone(new WhileStatement({
1093
+ while: util_1.util.cloneToken(this.tokens.while),
1094
+ endWhile: util_1.util.cloneToken(this.tokens.endWhile),
1095
+ condition: (_a = this.condition) === null || _a === void 0 ? void 0 : _a.clone(),
1096
+ body: (_b = this.body) === null || _b === void 0 ? void 0 : _b.clone()
1097
+ }), ['condition', 'body']);
1098
+ }
721
1099
  }
722
1100
  exports.WhileStatement = WhileStatement;
723
- class DottedSetStatement extends Statement {
724
- constructor(obj, name, value) {
1101
+ class DottedSetStatement extends AstNode_1.Statement {
1102
+ constructor(options) {
725
1103
  super();
726
- this.obj = obj;
727
- this.name = name;
728
- this.value = value;
729
- this.range = util_1.util.createRangeFromPositions(this.obj.range.start, this.value.range.end);
1104
+ this.kind = AstNode_1.AstNodeKind.DottedSetStatement;
1105
+ this.tokens = {
1106
+ name: options.name,
1107
+ dot: options.dot,
1108
+ equals: options.equals
1109
+ };
1110
+ this.obj = options.obj;
1111
+ this.value = options.value;
1112
+ this.location = util_1.util.createBoundingLocation(this.obj, this.tokens.dot, this.tokens.equals, this.tokens.name, this.value);
730
1113
  }
731
1114
  transpile(state) {
732
- var _a, _b;
733
1115
  //if the value is a compound assignment, don't add the obj, dot, name, or operator...the expression will handle that
734
- if (lexer_1.CompoundAssignmentOperators.includes((_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.operator) === null || _b === void 0 ? void 0 : _b.kind)) {
735
- return this.value.transpile(state);
736
- }
737
- else {
738
- return [
739
- //object
740
- ...this.obj.transpile(state),
741
- '.',
742
- //name
743
- state.transpileToken(this.name),
744
- ' = ',
745
- //right-hand-side of assignment
746
- ...this.value.transpile(state)
747
- ];
748
- }
1116
+ return [
1117
+ //object
1118
+ ...this.obj.transpile(state),
1119
+ this.tokens.dot ? state.tokenToSourceNode(this.tokens.dot) : '.',
1120
+ //name
1121
+ state.transpileToken(this.tokens.name),
1122
+ ' ',
1123
+ state.transpileToken(this.tokens.equals, '='),
1124
+ ' ',
1125
+ //right-hand-side of assignment
1126
+ ...this.value.transpile(state)
1127
+ ];
749
1128
  }
750
1129
  walk(visitor, options) {
751
1130
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
752
- visitors_1.walk(this, 'obj', visitor, options);
753
- visitors_1.walk(this, 'value', visitor, options);
1131
+ (0, visitors_1.walk)(this, 'obj', visitor, options);
1132
+ (0, visitors_1.walk)(this, 'value', visitor, options);
754
1133
  }
755
1134
  }
1135
+ getType(options) {
1136
+ var _a, _b, _c, _d, _e;
1137
+ const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
1138
+ const result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text, options);
1139
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
1140
+ name: (_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text,
1141
+ type: result, data: options.data,
1142
+ location: (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.location,
1143
+ astNode: this
1144
+ }));
1145
+ return result;
1146
+ }
1147
+ get leadingTrivia() {
1148
+ return this.obj.leadingTrivia;
1149
+ }
1150
+ clone() {
1151
+ var _a, _b;
1152
+ return this.finalizeClone(new DottedSetStatement({
1153
+ obj: (_a = this.obj) === null || _a === void 0 ? void 0 : _a.clone(),
1154
+ dot: util_1.util.cloneToken(this.tokens.dot),
1155
+ name: util_1.util.cloneToken(this.tokens.name),
1156
+ equals: util_1.util.cloneToken(this.tokens.equals),
1157
+ value: (_b = this.value) === null || _b === void 0 ? void 0 : _b.clone()
1158
+ }), ['obj', 'value']);
1159
+ }
756
1160
  }
757
1161
  exports.DottedSetStatement = DottedSetStatement;
758
- class IndexedSetStatement extends Statement {
759
- constructor(obj, index, value, openingSquare, closingSquare) {
1162
+ class IndexedSetStatement extends AstNode_1.Statement {
1163
+ constructor(options) {
1164
+ var _a;
760
1165
  super();
761
- this.obj = obj;
762
- this.index = index;
763
- this.value = value;
764
- this.openingSquare = openingSquare;
765
- this.closingSquare = closingSquare;
766
- this.range = util_1.util.createRangeFromPositions(this.obj.range.start, this.value.range.end);
1166
+ this.kind = AstNode_1.AstNodeKind.IndexedSetStatement;
1167
+ this.tokens = {
1168
+ openingSquare: options.openingSquare,
1169
+ closingSquare: options.closingSquare,
1170
+ equals: options.equals
1171
+ };
1172
+ this.obj = options.obj;
1173
+ this.indexes = (_a = options.indexes) !== null && _a !== void 0 ? _a : [];
1174
+ this.value = options.value;
1175
+ this.location = util_1.util.createBoundingLocation(this.obj, this.tokens.openingSquare, ...this.indexes, this.tokens.closingSquare, this.value);
767
1176
  }
768
1177
  transpile(state) {
769
- var _a, _b;
770
- //if the value is a component assignment, don't add the obj, index or operator...the expression will handle that
771
- if (lexer_1.CompoundAssignmentOperators.includes((_b = (_a = this.value) === null || _a === void 0 ? void 0 : _a.operator) === null || _b === void 0 ? void 0 : _b.kind)) {
772
- return this.value.transpile(state);
773
- }
774
- else {
775
- return [
776
- //obj
777
- ...this.obj.transpile(state),
778
- // [
779
- state.transpileToken(this.openingSquare),
780
- // index
781
- ...this.index.transpile(state),
782
- // ]
783
- state.transpileToken(this.closingSquare),
784
- // =
785
- ' = ',
786
- // value
787
- ...this.value.transpile(state)
788
- ];
1178
+ var _a;
1179
+ const result = [];
1180
+ result.push(
1181
+ //obj
1182
+ ...this.obj.transpile(state),
1183
+ // [
1184
+ state.transpileToken(this.tokens.openingSquare, '['));
1185
+ for (let i = 0; i < this.indexes.length; i++) {
1186
+ //add comma between indexes
1187
+ if (i > 0) {
1188
+ result.push(', ');
1189
+ }
1190
+ let index = this.indexes[i];
1191
+ result.push(...((_a = index === null || index === void 0 ? void 0 : index.transpile(state)) !== null && _a !== void 0 ? _a : []));
789
1192
  }
1193
+ result.push(state.transpileToken(this.tokens.closingSquare, ']'), ' ', state.transpileToken(this.tokens.equals, '='), ' ', ...this.value.transpile(state));
1194
+ return result;
790
1195
  }
791
1196
  walk(visitor, options) {
792
1197
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
793
- visitors_1.walk(this, 'obj', visitor, options);
794
- visitors_1.walk(this, 'index', visitor, options);
795
- visitors_1.walk(this, 'value', visitor, options);
1198
+ (0, visitors_1.walk)(this, 'obj', visitor, options);
1199
+ (0, visitors_1.walkArray)(this.indexes, visitor, options, this);
1200
+ (0, visitors_1.walk)(this, 'value', visitor, options);
796
1201
  }
797
1202
  }
1203
+ get leadingTrivia() {
1204
+ return this.obj.leadingTrivia;
1205
+ }
1206
+ clone() {
1207
+ var _a, _b, _c;
1208
+ return this.finalizeClone(new IndexedSetStatement({
1209
+ obj: (_a = this.obj) === null || _a === void 0 ? void 0 : _a.clone(),
1210
+ openingSquare: util_1.util.cloneToken(this.tokens.openingSquare),
1211
+ indexes: (_b = this.indexes) === null || _b === void 0 ? void 0 : _b.map(x => x === null || x === void 0 ? void 0 : x.clone()),
1212
+ closingSquare: util_1.util.cloneToken(this.tokens.closingSquare),
1213
+ equals: util_1.util.cloneToken(this.tokens.equals),
1214
+ value: (_c = this.value) === null || _c === void 0 ? void 0 : _c.clone()
1215
+ }), ['obj', 'indexes', 'value']);
1216
+ }
798
1217
  }
799
1218
  exports.IndexedSetStatement = IndexedSetStatement;
800
- class LibraryStatement extends Statement {
801
- constructor(tokens) {
1219
+ class LibraryStatement extends AstNode_1.Statement {
1220
+ constructor(options) {
802
1221
  super();
803
- this.tokens = tokens;
804
- this.range = util_1.util.createRangeFromPositions(this.tokens.library.range.start, this.tokens.filePath ? this.tokens.filePath.range.end : this.tokens.library.range.end);
1222
+ this.kind = AstNode_1.AstNodeKind.LibraryStatement;
1223
+ this.tokens = {
1224
+ library: options === null || options === void 0 ? void 0 : options.library,
1225
+ filePath: options === null || options === void 0 ? void 0 : options.filePath
1226
+ };
1227
+ this.location = util_1.util.createBoundingLocation(this.tokens.library, this.tokens.filePath);
805
1228
  }
806
1229
  transpile(state) {
807
1230
  let result = [];
@@ -818,38 +1241,87 @@ class LibraryStatement extends Statement {
818
1241
  walk(visitor, options) {
819
1242
  //nothing to walk
820
1243
  }
1244
+ get leadingTrivia() {
1245
+ var _a, _b;
1246
+ return (_b = (_a = this.tokens.library) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1247
+ }
1248
+ clone() {
1249
+ var _a, _b;
1250
+ return this.finalizeClone(new LibraryStatement({
1251
+ library: util_1.util.cloneToken((_a = this.tokens) === null || _a === void 0 ? void 0 : _a.library),
1252
+ filePath: util_1.util.cloneToken((_b = this.tokens) === null || _b === void 0 ? void 0 : _b.filePath)
1253
+ }));
1254
+ }
821
1255
  }
822
1256
  exports.LibraryStatement = LibraryStatement;
823
- class NamespaceStatement extends Statement {
824
- constructor(keyword,
825
- //this should technically only be a VariableExpression or DottedGetExpression, but that can be enforced elsewhere
826
- nameExpression, body, endKeyword, parentSymbolTable) {
1257
+ class NamespaceStatement extends AstNode_1.Statement {
1258
+ constructor(options) {
827
1259
  super();
828
- this.keyword = keyword;
829
- this.nameExpression = nameExpression;
830
- this.body = body;
831
- this.endKeyword = endKeyword;
832
- this.parentSymbolTable = parentSymbolTable;
833
- this.name = this.nameExpression.getName(Parser_1.ParseMode.BrighterScript);
834
- this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
835
- }
836
- get range() {
837
- var _a, _b, _c;
838
- return util_1.util.createRangeFromPositions(this.keyword.range.start, ((_c = (_b = (_a = this.endKeyword) !== null && _a !== void 0 ? _a : this.body) !== null && _b !== void 0 ? _b : this.nameExpression) !== null && _c !== void 0 ? _c : this.keyword).range.end);
1260
+ this.kind = AstNode_1.AstNodeKind.NamespaceStatement;
1261
+ this.tokens = {
1262
+ namespace: options.namespace,
1263
+ endNamespace: options.endNamespace
1264
+ };
1265
+ this.nameExpression = options.nameExpression;
1266
+ this.body = options.body;
1267
+ this.symbolTable = new SymbolTable_1.SymbolTable(`NamespaceStatement: '${this.name}'`, () => { var _a; return (_a = this.getRoot()) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
1268
+ }
1269
+ /**
1270
+ * The string name for this namespace
1271
+ */
1272
+ get name() {
1273
+ return this.getName(Parser_1.ParseMode.BrighterScript);
1274
+ }
1275
+ get location() {
1276
+ return this.cacheLocation();
1277
+ }
1278
+ cacheLocation() {
1279
+ if (!this._location) {
1280
+ this._location = util_1.util.createBoundingLocation(this.tokens.namespace, this.nameExpression, this.body, this.tokens.endNamespace);
1281
+ }
1282
+ return this._location;
839
1283
  }
840
1284
  getName(parseMode) {
841
- return this.nameExpression.getName(parseMode);
1285
+ var _a, _b;
1286
+ const sep = parseMode === Parser_1.ParseMode.BrighterScript ? '.' : '_';
1287
+ let name = util_1.util.getAllDottedGetPartsAsString(this.nameExpression, parseMode);
1288
+ if (((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.kind) === AstNode_1.AstNodeKind.NamespaceStatement) {
1289
+ name = this.parent.parent.getName(parseMode) + sep + name;
1290
+ }
1291
+ return name;
1292
+ }
1293
+ get leadingTrivia() {
1294
+ var _a;
1295
+ return (_a = this.tokens.namespace) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1296
+ }
1297
+ get endTrivia() {
1298
+ var _a;
1299
+ return (_a = this.tokens.endNamespace) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1300
+ }
1301
+ getNameParts() {
1302
+ var _a, _b;
1303
+ let parts = util_1.util.getAllDottedGetParts(this.nameExpression);
1304
+ if (((_b = (_a = this.parent) === null || _a === void 0 ? void 0 : _a.parent) === null || _b === void 0 ? void 0 : _b.kind) === AstNode_1.AstNodeKind.NamespaceStatement) {
1305
+ parts = this.parent.parent.getNameParts().concat(parts);
1306
+ }
1307
+ return parts;
842
1308
  }
843
1309
  transpile(state) {
844
1310
  //namespaces don't actually have any real content, so just transpile their bodies
845
- return this.body.transpile(state);
1311
+ return [
1312
+ state.transpileAnnotations(this),
1313
+ state.transpileLeadingComments(this.tokens.namespace),
1314
+ this.body.transpile(state),
1315
+ state.transpileLeadingComments(this.tokens.endNamespace)
1316
+ ];
846
1317
  }
847
1318
  getTypedef(state) {
848
- let result = [
849
- 'namespace ',
850
- ...this.nameExpression.getName(Parser_1.ParseMode.BrighterScript),
851
- state.newline
852
- ];
1319
+ var _a;
1320
+ let result = [];
1321
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
1322
+ result.push(comment.text, state.newline, state.indent());
1323
+ }
1324
+ result.push('namespace ', ...this.getName(Parser_1.ParseMode.BrighterScript), state.newline);
853
1325
  state.blockDepth++;
854
1326
  result.push(...this.body.getTypedef(state));
855
1327
  state.blockDepth--;
@@ -858,90 +1330,449 @@ class NamespaceStatement extends Statement {
858
1330
  }
859
1331
  walk(visitor, options) {
860
1332
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
861
- visitors_1.walk(this, 'nameExpression', visitor, options);
1333
+ (0, visitors_1.walk)(this, 'nameExpression', visitor, options);
862
1334
  }
863
1335
  if (this.body.statements.length > 0 && options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
864
- visitors_1.walk(this, 'body', visitor, options);
1336
+ (0, visitors_1.walk)(this, 'body', visitor, options);
865
1337
  }
866
1338
  }
1339
+ getType(options) {
1340
+ const resultType = new NamespaceType_1.NamespaceType(this.name);
1341
+ return resultType;
1342
+ }
1343
+ clone() {
1344
+ var _a, _b;
1345
+ const clone = this.finalizeClone(new NamespaceStatement({
1346
+ namespace: util_1.util.cloneToken(this.tokens.namespace),
1347
+ nameExpression: (_a = this.nameExpression) === null || _a === void 0 ? void 0 : _a.clone(),
1348
+ body: (_b = this.body) === null || _b === void 0 ? void 0 : _b.clone(),
1349
+ endNamespace: util_1.util.cloneToken(this.tokens.endNamespace)
1350
+ }), ['nameExpression', 'body']);
1351
+ clone.cacheLocation();
1352
+ return clone;
1353
+ }
867
1354
  }
868
1355
  exports.NamespaceStatement = NamespaceStatement;
869
- class ImportStatement extends Statement {
870
- constructor(importToken, filePathToken) {
1356
+ class ImportStatement extends AstNode_1.Statement {
1357
+ constructor(options) {
1358
+ var _a, _b;
871
1359
  super();
872
- this.importToken = importToken;
873
- this.filePathToken = filePathToken;
874
- this.range = util_1.util.createRangeFromPositions(importToken.range.start, (filePathToken !== null && filePathToken !== void 0 ? filePathToken : importToken).range.end);
875
- if (this.filePathToken) {
1360
+ this.kind = AstNode_1.AstNodeKind.ImportStatement;
1361
+ this.tokens = {
1362
+ import: options.import,
1363
+ path: options.path
1364
+ };
1365
+ this.location = util_1.util.createBoundingLocation(this.tokens.import, this.tokens.path);
1366
+ if (this.tokens.path) {
876
1367
  //remove quotes
877
- this.filePath = this.filePathToken.text.replace(/"/g, '');
878
- //adjust the range to exclude the quotes
879
- this.filePathToken.range = util_1.util.createRange(this.filePathToken.range.start.line, this.filePathToken.range.start.character + 1, this.filePathToken.range.end.line, this.filePathToken.range.end.character - 1);
1368
+ this.filePath = this.tokens.path.text.replace(/"/g, '');
1369
+ if ((_b = (_a = this.tokens.path) === null || _a === void 0 ? void 0 : _a.location) === null || _b === void 0 ? void 0 : _b.range) {
1370
+ //adjust the range to exclude the quotes
1371
+ this.tokens.path.location = util_1.util.createLocation(this.tokens.path.location.range.start.line, this.tokens.path.location.range.start.character + 1, this.tokens.path.location.range.end.line, this.tokens.path.location.range.end.character - 1, this.tokens.path.location.uri);
1372
+ }
880
1373
  }
881
1374
  }
882
1375
  transpile(state) {
883
1376
  //The xml files are responsible for adding the additional script imports, but
884
1377
  //add the import statement as a comment just for debugging purposes
885
1378
  return [
886
- `'`,
887
- state.transpileToken(this.importToken),
1379
+ state.transpileToken(this.tokens.import, 'import', true),
888
1380
  ' ',
889
- state.transpileToken(this.filePathToken)
1381
+ state.transpileToken(this.tokens.path)
890
1382
  ];
891
1383
  }
892
1384
  /**
893
1385
  * Get the typedef for this statement
894
1386
  */
895
1387
  getTypedef(state) {
1388
+ var _a, _b;
896
1389
  return [
897
- this.importToken.text,
1390
+ (_b = (_a = this.tokens.import) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'import',
898
1391
  ' ',
899
1392
  //replace any `.bs` extension with `.brs`
900
- this.filePathToken.text.replace(/\.bs"?$/i, '.brs"')
1393
+ this.tokens.path.text.replace(/\.bs"?$/i, '.brs"')
901
1394
  ];
902
1395
  }
903
1396
  walk(visitor, options) {
904
1397
  //nothing to walk
905
1398
  }
1399
+ get leadingTrivia() {
1400
+ var _a, _b;
1401
+ return (_b = (_a = this.tokens.import) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1402
+ }
1403
+ clone() {
1404
+ return this.finalizeClone(new ImportStatement({
1405
+ import: util_1.util.cloneToken(this.tokens.import),
1406
+ path: util_1.util.cloneToken(this.tokens.path)
1407
+ }));
1408
+ }
906
1409
  }
907
1410
  exports.ImportStatement = ImportStatement;
908
- class ClassStatement extends Statement {
909
- constructor(classKeyword,
1411
+ class InterfaceStatement extends AstNode_1.Statement {
1412
+ constructor(options) {
1413
+ var _a;
1414
+ super();
1415
+ this.kind = AstNode_1.AstNodeKind.InterfaceStatement;
1416
+ this.tokens = {};
1417
+ this.tokens = {
1418
+ interface: options.interface,
1419
+ name: options.name,
1420
+ extends: options.extends,
1421
+ endInterface: options.endInterface
1422
+ };
1423
+ this.parentInterfaceName = options.parentInterfaceName;
1424
+ this.body = options.body;
1425
+ this.location = util_1.util.createBoundingLocation(this.tokens.interface, this.tokens.name, this.tokens.extends, this.parentInterfaceName, ...(_a = this.body) !== null && _a !== void 0 ? _a : [], this.tokens.endInterface);
1426
+ }
1427
+ get fields() {
1428
+ return this.body.filter(x => (0, reflection_1.isInterfaceFieldStatement)(x));
1429
+ }
1430
+ get methods() {
1431
+ return this.body.filter(x => (0, reflection_1.isInterfaceMethodStatement)(x));
1432
+ }
1433
+ hasParentInterface() {
1434
+ return !!this.parentInterfaceName;
1435
+ }
1436
+ get leadingTrivia() {
1437
+ var _a;
1438
+ return (_a = this.tokens.interface) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1439
+ }
1440
+ get endTrivia() {
1441
+ var _a;
1442
+ return (_a = this.tokens.endInterface) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1443
+ }
910
1444
  /**
911
- * The name of the class (without namespace prefix)
1445
+ * The name of the interface WITH its leading namespace (if applicable)
912
1446
  */
913
- name, body, end, extendsKeyword, parentClassName, namespaceName) {
914
- var _a, _b, _c;
1447
+ get fullName() {
1448
+ var _a;
1449
+ const name = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text;
1450
+ if (name) {
1451
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
1452
+ if (namespace) {
1453
+ let namespaceName = namespace.getName(Parser_1.ParseMode.BrighterScript);
1454
+ return `${namespaceName}.${name}`;
1455
+ }
1456
+ else {
1457
+ return name;
1458
+ }
1459
+ }
1460
+ else {
1461
+ //return undefined which will allow outside callers to know that this interface doesn't have a name
1462
+ return undefined;
1463
+ }
1464
+ }
1465
+ /**
1466
+ * The name of the interface (without the namespace prefix)
1467
+ */
1468
+ get name() {
1469
+ var _a;
1470
+ return (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text;
1471
+ }
1472
+ /**
1473
+ * Get the name of this expression based on the parse mode
1474
+ */
1475
+ getName(parseMode) {
1476
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
1477
+ if (namespace) {
1478
+ let delimiter = parseMode === Parser_1.ParseMode.BrighterScript ? '.' : '_';
1479
+ let namespaceName = namespace.getName(parseMode);
1480
+ return namespaceName + delimiter + this.name;
1481
+ }
1482
+ else {
1483
+ return this.name;
1484
+ }
1485
+ }
1486
+ transpile(state) {
1487
+ //interfaces should completely disappear at runtime
1488
+ return [
1489
+ state.transpileLeadingComments(this.tokens.interface)
1490
+ ];
1491
+ }
1492
+ getTypedef(state) {
1493
+ var _a, _b, _c, _d;
1494
+ const result = [];
1495
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
1496
+ result.push(comment.text, state.newline, state.indent());
1497
+ }
1498
+ for (let annotation of (_b = this.annotations) !== null && _b !== void 0 ? _b : []) {
1499
+ result.push(...annotation.getTypedef(state), state.newline, state.indent());
1500
+ }
1501
+ result.push(this.tokens.interface.text, ' ', this.tokens.name.text);
1502
+ const parentInterfaceName = (_c = this.parentInterfaceName) === null || _c === void 0 ? void 0 : _c.getName();
1503
+ if (parentInterfaceName) {
1504
+ result.push(' extends ', parentInterfaceName);
1505
+ }
1506
+ const body = (_d = this.body) !== null && _d !== void 0 ? _d : [];
1507
+ if (body.length > 0) {
1508
+ state.blockDepth++;
1509
+ }
1510
+ for (const statement of body) {
1511
+ if ((0, reflection_1.isInterfaceMethodStatement)(statement) || (0, reflection_1.isInterfaceFieldStatement)(statement)) {
1512
+ result.push(state.newline, state.indent(), ...statement.getTypedef(state));
1513
+ }
1514
+ else {
1515
+ result.push(state.newline, state.indent(), ...statement.transpile(state));
1516
+ }
1517
+ }
1518
+ if (body.length > 0) {
1519
+ state.blockDepth--;
1520
+ }
1521
+ result.push(state.newline, state.indent(), 'end interface', state.newline);
1522
+ return result;
1523
+ }
1524
+ walk(visitor, options) {
1525
+ //visitor-less walk function to do parent linking
1526
+ (0, visitors_1.walk)(this, 'parentInterfaceName', null, options);
1527
+ if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
1528
+ (0, visitors_1.walkArray)(this.body, visitor, options, this);
1529
+ }
1530
+ }
1531
+ getType(options) {
1532
+ var _a, _b, _c, _d;
1533
+ const superIface = (_a = this.parentInterfaceName) === null || _a === void 0 ? void 0 : _a.getType(options);
1534
+ const resultType = new InterfaceType_1.InterfaceType(this.getName(Parser_1.ParseMode.BrighterScript), superIface);
1535
+ for (const statement of this.methods) {
1536
+ const memberType = statement === null || statement === void 0 ? void 0 : statement.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); // no typechain info needed
1537
+ const flag = statement.isOptional ? 1 /* SymbolTypeFlag.runtime */ | 4 /* SymbolTypeFlag.optional */ : 1 /* SymbolTypeFlag.runtime */;
1538
+ resultType.addMember((_b = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _b === void 0 ? void 0 : _b.text, { definingNode: statement }, memberType, flag);
1539
+ }
1540
+ for (const statement of this.fields) {
1541
+ const memberType = statement === null || statement === void 0 ? void 0 : statement.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); // no typechain info needed
1542
+ const flag = statement.isOptional ? 1 /* SymbolTypeFlag.runtime */ | 4 /* SymbolTypeFlag.optional */ : 1 /* SymbolTypeFlag.runtime */;
1543
+ resultType.addMember((_c = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _c === void 0 ? void 0 : _c.text, { definingNode: statement, isInstance: true }, memberType, flag);
1544
+ }
1545
+ (_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry({
1546
+ name: this.getName(Parser_1.ParseMode.BrighterScript),
1547
+ type: resultType,
1548
+ data: options.data,
1549
+ astNode: this
1550
+ }));
1551
+ return resultType;
1552
+ }
1553
+ clone() {
1554
+ var _a, _b;
1555
+ return this.finalizeClone(new InterfaceStatement({
1556
+ interface: util_1.util.cloneToken(this.tokens.interface),
1557
+ name: util_1.util.cloneToken(this.tokens.name),
1558
+ extends: util_1.util.cloneToken(this.tokens.extends),
1559
+ parentInterfaceName: (_a = this.parentInterfaceName) === null || _a === void 0 ? void 0 : _a.clone(),
1560
+ body: (_b = this.body) === null || _b === void 0 ? void 0 : _b.map(x => x === null || x === void 0 ? void 0 : x.clone()),
1561
+ endInterface: util_1.util.cloneToken(this.tokens.endInterface)
1562
+ }), ['parentInterfaceName', 'body']);
1563
+ }
1564
+ }
1565
+ exports.InterfaceStatement = InterfaceStatement;
1566
+ class InterfaceFieldStatement extends AstNode_1.Statement {
1567
+ constructor(options) {
1568
+ super();
1569
+ this.kind = AstNode_1.AstNodeKind.InterfaceFieldStatement;
1570
+ this.tokens = {
1571
+ optional: options.optional,
1572
+ name: options.name,
1573
+ as: options.as
1574
+ };
1575
+ this.typeExpression = options.typeExpression;
1576
+ this.location = util_1.util.createBoundingLocation(this.tokens.optional, this.tokens.name, this.tokens.as, this.typeExpression);
1577
+ }
1578
+ transpile(state) {
1579
+ throw new Error('Method not implemented.');
1580
+ }
1581
+ get leadingTrivia() {
1582
+ var _a, _b;
1583
+ return (_b = (_a = this.tokens.optional) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : this.tokens.name.leadingTrivia;
1584
+ }
1585
+ get name() {
1586
+ return this.tokens.name.text;
1587
+ }
1588
+ get isOptional() {
1589
+ return !!this.tokens.optional;
1590
+ }
1591
+ walk(visitor, options) {
1592
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1593
+ (0, visitors_1.walk)(this, 'typeExpression', visitor, options);
1594
+ }
1595
+ }
1596
+ getTypedef(state) {
1597
+ var _a, _b;
1598
+ const result = [];
1599
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
1600
+ result.push(comment.text, state.newline, state.indent());
1601
+ }
1602
+ for (let annotation of (_b = this.annotations) !== null && _b !== void 0 ? _b : []) {
1603
+ result.push(...annotation.getTypedef(state), state.newline, state.indent());
1604
+ }
1605
+ if (this.isOptional) {
1606
+ result.push(this.tokens.optional.text, ' ');
1607
+ }
1608
+ result.push(this.tokens.name.text);
1609
+ if (this.typeExpression) {
1610
+ result.push(' as ', ...this.typeExpression.getTypedef(state));
1611
+ }
1612
+ return result;
1613
+ }
1614
+ getType(options) {
1615
+ var _a, _b;
1616
+ return (_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getType(options)) !== null && _b !== void 0 ? _b : DynamicType_1.DynamicType.instance;
1617
+ }
1618
+ clone() {
1619
+ var _a;
1620
+ return this.finalizeClone(new InterfaceFieldStatement({
1621
+ name: util_1.util.cloneToken(this.tokens.name),
1622
+ as: util_1.util.cloneToken(this.tokens.as),
1623
+ typeExpression: (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.clone(),
1624
+ optional: util_1.util.cloneToken(this.tokens.optional)
1625
+ }));
1626
+ }
1627
+ }
1628
+ exports.InterfaceFieldStatement = InterfaceFieldStatement;
1629
+ //TODO: there is much that is similar with this and FunctionExpression.
1630
+ //It would be nice to refactor this so there is less duplicated code
1631
+ class InterfaceMethodStatement extends AstNode_1.Statement {
1632
+ constructor(options) {
1633
+ var _a;
1634
+ super();
1635
+ this.kind = AstNode_1.AstNodeKind.InterfaceMethodStatement;
1636
+ this.tokens = {
1637
+ optional: options.optional,
1638
+ functionType: options.functionType,
1639
+ name: options.name,
1640
+ leftParen: options.leftParen,
1641
+ rightParen: options.rightParen,
1642
+ as: options.as
1643
+ };
1644
+ this.params = (_a = options.params) !== null && _a !== void 0 ? _a : [];
1645
+ this.returnTypeExpression = options.returnTypeExpression;
1646
+ }
1647
+ transpile(state) {
1648
+ throw new Error('Method not implemented.');
1649
+ }
1650
+ get location() {
1651
+ var _a;
1652
+ return util_1.util.createBoundingLocation(this.tokens.optional, this.tokens.functionType, this.tokens.name, this.tokens.leftParen, ...((_a = this.params) !== null && _a !== void 0 ? _a : []), this.tokens.rightParen, this.tokens.as, this.returnTypeExpression);
1653
+ }
1654
+ /**
1655
+ * Get the name of this method.
1656
+ */
1657
+ getName(parseMode) {
1658
+ return this.tokens.name.text;
1659
+ }
1660
+ get isOptional() {
1661
+ return !!this.tokens.optional;
1662
+ }
1663
+ get leadingTrivia() {
1664
+ var _a, _b;
1665
+ return (_b = (_a = this.tokens.optional) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : this.tokens.functionType.leadingTrivia;
1666
+ }
1667
+ walk(visitor, options) {
1668
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1669
+ (0, visitors_1.walk)(this, 'returnTypeExpression', visitor, options);
1670
+ }
1671
+ }
1672
+ getTypedef(state) {
1673
+ var _a, _b, _c, _d, _e;
1674
+ const result = [];
1675
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
1676
+ result.push(comment.text, state.newline, state.indent());
1677
+ }
1678
+ for (let annotation of (_b = this.annotations) !== null && _b !== void 0 ? _b : []) {
1679
+ result.push(...annotation.getTypedef(state), state.newline, state.indent());
1680
+ }
1681
+ if (this.isOptional) {
1682
+ result.push(this.tokens.optional.text, ' ');
1683
+ }
1684
+ result.push((_d = (_c = this.tokens.functionType) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : 'function', ' ', this.tokens.name.text, '(');
1685
+ const params = (_e = this.params) !== null && _e !== void 0 ? _e : [];
1686
+ for (let i = 0; i < params.length; i++) {
1687
+ if (i > 0) {
1688
+ result.push(', ');
1689
+ }
1690
+ const param = params[i];
1691
+ result.push(param.tokens.name.text);
1692
+ if (param.typeExpression) {
1693
+ result.push(' as ', ...param.typeExpression.getTypedef(state));
1694
+ }
1695
+ }
1696
+ result.push(')');
1697
+ if (this.returnTypeExpression) {
1698
+ result.push(' as ', ...this.returnTypeExpression.getTypedef(state));
1699
+ }
1700
+ return result;
1701
+ }
1702
+ getType(options) {
1703
+ var _a, _b, _c, _d;
1704
+ //if there's a defined return type, use that
1705
+ let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(options);
1706
+ const isSub = ((_b = this.tokens.functionType) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Sub || !returnType;
1707
+ //if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
1708
+ if (!returnType) {
1709
+ returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
1710
+ }
1711
+ const resultType = new TypedFunctionType_1.TypedFunctionType(returnType);
1712
+ resultType.isSub = isSub;
1713
+ for (let param of this.params) {
1714
+ resultType.addParameter(param.tokens.name.text, param.getType(options), !!param.defaultValue);
1715
+ }
1716
+ if (options.typeChain) {
1717
+ // need Interface type for type chain
1718
+ (_c = this.parent) === null || _c === void 0 ? void 0 : _c.getType(options);
1719
+ }
1720
+ let funcName = this.getName(Parser_1.ParseMode.BrighterScript);
1721
+ resultType.setName(funcName);
1722
+ (_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry({ name: resultType.name, type: resultType, data: options.data, astNode: this }));
1723
+ return resultType;
1724
+ }
1725
+ clone() {
1726
+ var _a, _b;
1727
+ return this.finalizeClone(new InterfaceMethodStatement({
1728
+ optional: util_1.util.cloneToken(this.tokens.optional),
1729
+ functionType: util_1.util.cloneToken(this.tokens.functionType),
1730
+ name: util_1.util.cloneToken(this.tokens.name),
1731
+ leftParen: util_1.util.cloneToken(this.tokens.leftParen),
1732
+ params: (_a = this.params) === null || _a === void 0 ? void 0 : _a.map(p => p === null || p === void 0 ? void 0 : p.clone()),
1733
+ rightParen: util_1.util.cloneToken(this.tokens.rightParen),
1734
+ as: util_1.util.cloneToken(this.tokens.as),
1735
+ returnTypeExpression: (_b = this.returnTypeExpression) === null || _b === void 0 ? void 0 : _b.clone()
1736
+ }), ['params']);
1737
+ }
1738
+ }
1739
+ exports.InterfaceMethodStatement = InterfaceMethodStatement;
1740
+ class ClassStatement extends AstNode_1.Statement {
1741
+ constructor(options) {
1742
+ var _a, _b, _c, _d, _e;
915
1743
  super();
916
- this.classKeyword = classKeyword;
917
- this.name = name;
918
- this.body = body;
919
- this.end = end;
920
- this.extendsKeyword = extendsKeyword;
921
- this.parentClassName = parentClassName;
922
- this.namespaceName = namespaceName;
1744
+ this.kind = AstNode_1.AstNodeKind.ClassStatement;
923
1745
  this.memberMap = {};
924
1746
  this.methods = [];
925
1747
  this.fields = [];
926
- this.body = (_a = this.body) !== null && _a !== void 0 ? _a : [];
1748
+ this.body = (_a = options.body) !== null && _a !== void 0 ? _a : [];
1749
+ this.tokens = {
1750
+ name: options.name,
1751
+ class: options.class,
1752
+ endClass: options.endClass,
1753
+ extends: options.extends
1754
+ };
1755
+ this.parentClassName = options.parentClassName;
1756
+ this.symbolTable = new SymbolTable_1.SymbolTable(`ClassStatement: '${(_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text}'`, () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
927
1757
  for (let statement of this.body) {
928
- if (reflection_1.isClassMethodStatement(statement)) {
1758
+ if ((0, reflection_1.isMethodStatement)(statement)) {
929
1759
  this.methods.push(statement);
930
- this.memberMap[(_b = statement === null || statement === void 0 ? void 0 : statement.name) === null || _b === void 0 ? void 0 : _b.text.toLowerCase()] = statement;
1760
+ this.memberMap[(_c = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _c === void 0 ? void 0 : _c.text.toLowerCase()] = statement;
931
1761
  }
932
- else if (reflection_1.isClassFieldStatement(statement)) {
1762
+ else if ((0, reflection_1.isFieldStatement)(statement)) {
933
1763
  this.fields.push(statement);
934
- this.memberMap[(_c = statement === null || statement === void 0 ? void 0 : statement.name) === null || _c === void 0 ? void 0 : _c.text.toLowerCase()] = statement;
1764
+ this.memberMap[(_d = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _d === void 0 ? void 0 : _d.text.toLowerCase()] = statement;
935
1765
  }
936
1766
  }
937
- this.range = util_1.util.createRangeFromPositions(this.classKeyword.range.start, this.end.range.end);
1767
+ this.location = util_1.util.createBoundingLocation(this.parentClassName, ...((_e = this.body) !== null && _e !== void 0 ? _e : []), util_1.util.createBoundingLocationFromTokens(this.tokens));
938
1768
  }
939
1769
  getName(parseMode) {
940
1770
  var _a;
941
- const name = (_a = this.name) === null || _a === void 0 ? void 0 : _a.text;
1771
+ const name = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text;
942
1772
  if (name) {
943
- if (this.namespaceName) {
944
- let namespaceName = this.namespaceName.getName(parseMode);
1773
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
1774
+ if (namespace) {
1775
+ let namespaceName = namespace.getName(parseMode);
945
1776
  let separator = parseMode === Parser_1.ParseMode.BrighterScript ? '.' : '_';
946
1777
  return namespaceName + separator + name;
947
1778
  }
@@ -954,30 +1785,59 @@ class ClassStatement extends Statement {
954
1785
  return undefined;
955
1786
  }
956
1787
  }
1788
+ get leadingTrivia() {
1789
+ var _a;
1790
+ return (_a = this.tokens.class) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
1791
+ }
1792
+ get endTrivia() {
1793
+ var _a, _b;
1794
+ return (_b = (_a = this.tokens.endClass) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1795
+ }
957
1796
  transpile(state) {
958
1797
  let result = [];
1798
+ const className = this.getName(Parser_1.ParseMode.BrightScript).replace(/\./g, '_');
1799
+ const ancestors = this.getAncestors(state);
1800
+ const body = this.getTranspiledClassBody(ancestors);
1801
+ //make the methods
1802
+ result.push(...this.getTranspiledMethods(state, className, body));
959
1803
  //make the builder
960
- result.push(...this.getTranspiledBuilder(state));
1804
+ result.push(...this.getTranspiledBuilder(state, className, ancestors, body));
961
1805
  result.push('\n', state.indent());
962
1806
  //make the class assembler (i.e. the public-facing class creator method)
963
- result.push(...this.getTranspiledClassFunction(state));
1807
+ result.push(...this.getTranspiledClassFunction(state, className));
964
1808
  return result;
965
1809
  }
966
1810
  getTypedef(state) {
967
1811
  var _a, _b;
968
1812
  const result = [];
969
- for (let annotation of (_a = this.annotations) !== null && _a !== void 0 ? _a : []) {
1813
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
1814
+ result.push(comment.text, state.newline, state.indent());
1815
+ }
1816
+ for (let annotation of (_b = this.annotations) !== null && _b !== void 0 ? _b : []) {
970
1817
  result.push(...annotation.getTypedef(state), state.newline, state.indent());
971
1818
  }
972
- result.push('class ', this.name.text);
973
- if (this.extendsKeyword && this.parentClassName) {
974
- const fqName = util_1.util.getFullyQualifiedClassName(this.parentClassName.getName(Parser_1.ParseMode.BrighterScript), (_b = this.namespaceName) === null || _b === void 0 ? void 0 : _b.getName(Parser_1.ParseMode.BrighterScript));
1819
+ result.push('class ', this.tokens.name.text);
1820
+ if (this.parentClassName) {
1821
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
1822
+ const fqName = util_1.util.getFullyQualifiedClassName(this.parentClassName.getName(), namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript));
975
1823
  result.push(` extends ${fqName}`);
976
1824
  }
977
1825
  result.push(state.newline);
978
1826
  state.blockDepth++;
979
- for (const member of this.body) {
980
- if ('getTypedef' in member) {
1827
+ let body = this.body;
1828
+ //inject an empty "new" method if missing
1829
+ if (!this.getConstructorFunction()) {
1830
+ const constructor = (0, creators_1.createMethodStatement)('new', TokenKind_1.TokenKind.Sub);
1831
+ constructor.parent = this;
1832
+ //walk the constructor to set up parent links
1833
+ constructor.link();
1834
+ body = [
1835
+ constructor,
1836
+ ...this.body
1837
+ ];
1838
+ }
1839
+ for (const member of body) {
1840
+ if ((0, reflection_1.isTypedefProvider)(member)) {
981
1841
  result.push(state.indent(), ...member.getTypedef(state), state.newline);
982
1842
  }
983
1843
  }
@@ -991,20 +1851,27 @@ class ClassStatement extends Statement {
991
1851
  * The base class is index 0, its child is index 1, and so on.
992
1852
  */
993
1853
  getParentClassIndex(state) {
994
- var _a, _b;
1854
+ var _a;
995
1855
  let myIndex = 0;
996
1856
  let stmt = this;
997
1857
  while (stmt) {
998
1858
  if (stmt.parentClassName) {
1859
+ const namespace = stmt.findAncestor(reflection_1.isNamespaceStatement);
999
1860
  //find the parent class
1000
- stmt = (_b = state.file.getClassFileLink(stmt.parentClassName.getName(Parser_1.ParseMode.BrighterScript), (_a = stmt.namespaceName) === null || _a === void 0 ? void 0 : _a.getName(Parser_1.ParseMode.BrighterScript))) === null || _b === void 0 ? void 0 : _b.item;
1861
+ stmt = (_a = state.file.getClassFileLink(stmt.parentClassName.getName(), namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) === null || _a === void 0 ? void 0 : _a.item;
1001
1862
  myIndex++;
1002
1863
  }
1003
1864
  else {
1004
1865
  break;
1005
1866
  }
1006
1867
  }
1007
- return myIndex - 1;
1868
+ const result = myIndex - 1;
1869
+ if (result >= 0) {
1870
+ return result;
1871
+ }
1872
+ else {
1873
+ return null;
1874
+ }
1008
1875
  }
1009
1876
  hasParentClass() {
1010
1877
  return !!this.parentClassName;
@@ -1014,12 +1881,13 @@ class ClassStatement extends Statement {
1014
1881
  * This will return an empty array if no ancestors were found
1015
1882
  */
1016
1883
  getAncestors(state) {
1017
- var _a, _b;
1884
+ var _a;
1018
1885
  let ancestors = [];
1019
1886
  let stmt = this;
1020
1887
  while (stmt) {
1021
1888
  if (stmt.parentClassName) {
1022
- stmt = (_b = state.file.getClassFileLink(stmt.parentClassName.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;
1889
+ const namespace = stmt.findAncestor(reflection_1.isNamespaceStatement);
1890
+ stmt = (_a = state.file.getClassFileLink(stmt.parentClassName.getName(), namespace === null || namespace === void 0 ? void 0 : namespace.getName(Parser_1.ParseMode.BrighterScript))) === null || _a === void 0 ? void 0 : _a.item;
1023
1891
  ancestors.push(stmt);
1024
1892
  }
1025
1893
  else {
@@ -1028,33 +1896,40 @@ class ClassStatement extends Statement {
1028
1896
  }
1029
1897
  return ancestors;
1030
1898
  }
1031
- getBuilderName(name) {
1032
- if (name.includes('.')) {
1033
- name = name.replace(/\./gi, '_');
1034
- }
1035
- return `__${name}_builder`;
1899
+ getBuilderName(transpiledClassName) {
1900
+ return `__${transpiledClassName}_builder`;
1901
+ }
1902
+ getMethodIdentifier(transpiledClassName, statement) {
1903
+ return Object.assign(Object.assign({}, statement.tokens.name), { text: `__${transpiledClassName}_method_${statement.tokens.name.text}` });
1904
+ }
1905
+ getConstructorType() {
1906
+ var _a, _b;
1907
+ const constructorType = (_b = (_a = this.getConstructorFunction()) === null || _a === void 0 ? void 0 : _a.getType({ flags: 1 /* SymbolTypeFlag.runtime */ })) !== null && _b !== void 0 ? _b : new TypedFunctionType_1.TypedFunctionType(null);
1908
+ constructorType.returnType = this.getType({ flags: 1 /* SymbolTypeFlag.runtime */ });
1909
+ return constructorType;
1036
1910
  }
1037
1911
  /**
1038
1912
  * Get the constructor function for this class (if exists), or undefined if not exist
1039
1913
  */
1040
1914
  getConstructorFunction() {
1041
- var _a, _b;
1042
- for (let key in this.memberMap) {
1043
- let member = this.memberMap[key];
1044
- if (((_b = (_a = member.name) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'new') {
1045
- return member;
1915
+ return this.body.find((stmt) => {
1916
+ var _a, _b;
1917
+ return ((_b = (_a = stmt === null || stmt === void 0 ? void 0 : stmt.tokens.name) === null || _a === void 0 ? void 0 : _a.text) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'new';
1918
+ });
1919
+ }
1920
+ /**
1921
+ * Return the parameters for the first constructor function for this class
1922
+ * @param ancestors The list of ancestors for this class
1923
+ * @returns The parameters for the first constructor function for this class
1924
+ */
1925
+ getConstructorParams(ancestors) {
1926
+ for (let ancestor of ancestors) {
1927
+ const ctor = ancestor === null || ancestor === void 0 ? void 0 : ancestor.getConstructorFunction();
1928
+ if (ctor) {
1929
+ return ctor.func.parameters;
1046
1930
  }
1047
1931
  }
1048
- }
1049
- getEmptyNewFunction() {
1050
- let stmt = Parser_1.Parser.parse(`
1051
- class UtilClass
1052
- sub new()
1053
- end sub
1054
- end class
1055
- `, { mode: Parser_1.ParseMode.BrighterScript }).statements[0].memberMap.new;
1056
- //TODO make locations point to 0,0 (might not matter?)
1057
- return stmt;
1932
+ return [];
1058
1933
  }
1059
1934
  /**
1060
1935
  * Determine if the specified field was declared in one of the ancestor classes
@@ -1073,21 +1948,17 @@ class ClassStatement extends Statement {
1073
1948
  * This needs to be a separate function so that child classes can call the builder from their parent
1074
1949
  * without instantiating the parent constructor at that point in time.
1075
1950
  */
1076
- getTranspiledBuilder(state) {
1077
- var _a;
1951
+ getTranspiledBuilder(state, transpiledClassName, ancestors, body) {
1078
1952
  let result = [];
1079
- result.push(`function ${this.getBuilderName(this.getName(Parser_1.ParseMode.BrightScript))}()\n`);
1953
+ result.push(`function ${this.getBuilderName(transpiledClassName)}()\n`);
1080
1954
  state.blockDepth++;
1081
1955
  //indent
1082
1956
  result.push(state.indent());
1083
- /**
1084
- * The lineage of this class. index 0 is a direct parent, index 1 is index 0's parent, etc...
1085
- */
1086
- let ancestors = this.getAncestors(state);
1087
1957
  //construct parent class or empty object
1088
1958
  if (ancestors[0]) {
1089
- let fullyQualifiedClassName = util_1.util.getFullyQualifiedClassName(ancestors[0].getName(Parser_1.ParseMode.BrighterScript), (_a = ancestors[0].namespaceName) === null || _a === void 0 ? void 0 : _a.getName(Parser_1.ParseMode.BrighterScript));
1090
- result.push('instance = ', this.getBuilderName(fullyQualifiedClassName), '()');
1959
+ const ancestorNamespace = ancestors[0].findAncestor(reflection_1.isNamespaceStatement);
1960
+ let fullyQualifiedClassName = util_1.util.getFullyQualifiedClassName(ancestors[0].getName(Parser_1.ParseMode.BrighterScript), ancestorNamespace === null || ancestorNamespace === void 0 ? void 0 : ancestorNamespace.getName(Parser_1.ParseMode.BrighterScript));
1961
+ result.push(`instance = ${this.getBuilderName(fullyQualifiedClassName.replace(/\./g, '_'))}()`);
1091
1962
  }
1092
1963
  else {
1093
1964
  //use an empty object.
@@ -1095,29 +1966,30 @@ class ClassStatement extends Statement {
1095
1966
  }
1096
1967
  result.push(state.newline, state.indent());
1097
1968
  let parentClassIndex = this.getParentClassIndex(state);
1098
- //create empty `new` function if class is missing it (simplifies transpile logic)
1099
- if (!this.getConstructorFunction()) {
1100
- this.memberMap.new = this.getEmptyNewFunction();
1101
- this.body = [this.memberMap.new, ...this.body];
1102
- }
1103
- for (let statement of this.body) {
1969
+ for (let statement of body) {
1104
1970
  //is field statement
1105
- if (reflection_1.isClassFieldStatement(statement)) {
1971
+ if ((0, reflection_1.isFieldStatement)(statement)) {
1106
1972
  //do nothing with class fields in this situation, they are handled elsewhere
1107
1973
  continue;
1108
1974
  //methods
1109
1975
  }
1110
- else if (reflection_1.isClassMethodStatement(statement)) {
1976
+ else if ((0, reflection_1.isMethodStatement)(statement)) {
1111
1977
  //store overridden parent methods as super{parentIndex}_{methodName}
1112
1978
  if (
1113
1979
  //is override method
1114
- statement.override ||
1980
+ statement.tokens.override ||
1115
1981
  //is constructor function in child class
1116
- (statement.name.text.toLowerCase() === 'new' && ancestors[0])) {
1117
- result.push(`instance.super${parentClassIndex}_${statement.name.text} = instance.${statement.name.text}`, state.newline, state.indent());
1982
+ (statement.tokens.name.text.toLowerCase() === 'new' && ancestors[0])) {
1983
+ result.push(`instance.super${parentClassIndex}_${statement.tokens.name.text} = instance.${statement.tokens.name.text}`, state.newline, state.indent());
1118
1984
  }
1119
1985
  state.classStatement = this;
1120
- result.push('instance.', state.transpileToken(statement.name), ' = ', ...statement.transpile(state), state.newline, state.indent());
1986
+ state.skipLeadingComments = true;
1987
+ //add leading comments
1988
+ if (statement.leadingTrivia.filter(token => token.kind === TokenKind_1.TokenKind.Comment).length > 0) {
1989
+ result.push(...state.transpileComments(statement.leadingTrivia), state.indent());
1990
+ }
1991
+ result.push('instance.', state.transpileToken(statement.tokens.name), ' = ', state.transpileToken(this.getMethodIdentifier(transpiledClassName, statement)), state.newline, state.indent());
1992
+ state.skipLeadingComments = false;
1121
1993
  delete state.classStatement;
1122
1994
  }
1123
1995
  else {
@@ -1132,16 +2004,79 @@ class ClassStatement extends Statement {
1132
2004
  result.push(`end function`);
1133
2005
  return result;
1134
2006
  }
2007
+ /**
2008
+ * Returns a copy of the class' body, with the constructor function added if it doesn't exist.
2009
+ */
2010
+ getTranspiledClassBody(ancestors) {
2011
+ const body = [];
2012
+ body.push(...this.body);
2013
+ //inject an empty "new" method if missing
2014
+ if (!this.getConstructorFunction()) {
2015
+ if (ancestors.length === 0) {
2016
+ body.unshift((0, creators_1.createMethodStatement)('new', TokenKind_1.TokenKind.Sub));
2017
+ }
2018
+ else {
2019
+ const params = this.getConstructorParams(ancestors);
2020
+ const call = new ExpressionStatement({
2021
+ expression: new Expression_2.CallExpression({
2022
+ callee: new Expression_2.VariableExpression({
2023
+ name: (0, creators_1.createToken)(TokenKind_1.TokenKind.Identifier, 'super')
2024
+ }),
2025
+ openingParen: (0, creators_1.createToken)(TokenKind_1.TokenKind.LeftParen),
2026
+ args: params.map(x => new Expression_2.VariableExpression({
2027
+ name: x.tokens.name
2028
+ })),
2029
+ closingParen: (0, creators_1.createToken)(TokenKind_1.TokenKind.RightParen)
2030
+ })
2031
+ });
2032
+ body.unshift(new MethodStatement({
2033
+ modifiers: [],
2034
+ name: (0, creators_1.createIdentifier)('new'),
2035
+ func: new Expression_1.FunctionExpression({
2036
+ parameters: params.map(x => x.clone()),
2037
+ body: new Block({ statements: [call] }),
2038
+ functionType: (0, creators_1.createToken)(TokenKind_1.TokenKind.Sub),
2039
+ endFunctionType: (0, creators_1.createToken)(TokenKind_1.TokenKind.EndSub),
2040
+ leftParen: (0, creators_1.createToken)(TokenKind_1.TokenKind.LeftParen),
2041
+ rightParen: (0, creators_1.createToken)(TokenKind_1.TokenKind.RightParen)
2042
+ }),
2043
+ override: null
2044
+ }));
2045
+ }
2046
+ }
2047
+ return body;
2048
+ }
2049
+ /**
2050
+ * These are the methods that are defined in this class. They are transpiled outside of the class body
2051
+ * to ensure they don't appear as "$anon_#" in stack traces and crash logs.
2052
+ */
2053
+ getTranspiledMethods(state, transpiledClassName, body) {
2054
+ let result = [];
2055
+ for (let statement of body) {
2056
+ if ((0, reflection_1.isMethodStatement)(statement)) {
2057
+ state.classStatement = this;
2058
+ result.push(...statement.transpile(state, this.getMethodIdentifier(transpiledClassName, statement)), state.newline, state.indent());
2059
+ delete state.classStatement;
2060
+ }
2061
+ }
2062
+ return result;
2063
+ }
1135
2064
  /**
1136
2065
  * The class function is the function with the same name as the class. This is the function that
1137
2066
  * consumers should call to create a new instance of that class.
1138
2067
  * This invokes the builder, gets an instance of the class, then invokes the "new" function on that class.
1139
2068
  */
1140
- getTranspiledClassFunction(state) {
1141
- let result = [];
2069
+ getTranspiledClassFunction(state, transpiledClassName) {
2070
+ let result = state.transpileAnnotations(this);
1142
2071
  const constructorFunction = this.getConstructorFunction();
1143
- const constructorParams = constructorFunction ? constructorFunction.func.parameters : [];
1144
- result.push(state.sourceNode(this.classKeyword, 'function'), state.sourceNode(this.classKeyword, ' '), state.sourceNode(this.name, this.getName(Parser_1.ParseMode.BrightScript)), `(`);
2072
+ let constructorParams = [];
2073
+ if (constructorFunction) {
2074
+ constructorParams = constructorFunction.func.parameters;
2075
+ }
2076
+ else {
2077
+ constructorParams = this.getConstructorParams(this.getAncestors(state));
2078
+ }
2079
+ result.push(state.transpileLeadingComments(this.tokens.class), state.sourceNode(this.tokens.class, 'function'), state.sourceNode(this.tokens.class, ' '), state.sourceNode(this.tokens.name, this.getName(Parser_1.ParseMode.BrightScript)), `(`);
1145
2080
  let i = 0;
1146
2081
  for (let param of constructorParams) {
1147
2082
  if (i > 0) {
@@ -1153,7 +2088,7 @@ class ClassStatement extends Statement {
1153
2088
  result.push(')', '\n');
1154
2089
  state.blockDepth++;
1155
2090
  result.push(state.indent());
1156
- result.push(`instance = ${this.getBuilderName(this.getName(Parser_1.ParseMode.BrightScript))}()\n`);
2091
+ result.push(`instance = ${this.getBuilderName(transpiledClassName)}()\n`);
1157
2092
  result.push(state.indent());
1158
2093
  result.push(`instance.new(`);
1159
2094
  //append constructor arguments
@@ -1162,7 +2097,7 @@ class ClassStatement extends Statement {
1162
2097
  if (i > 0) {
1163
2098
  result.push(', ');
1164
2099
  }
1165
- result.push(state.transpileToken(param.name));
2100
+ result.push(state.transpileToken(param.tokens.name));
1166
2101
  i++;
1167
2102
  }
1168
2103
  result.push(')', '\n');
@@ -1174,24 +2109,92 @@ class ClassStatement extends Statement {
1174
2109
  return result;
1175
2110
  }
1176
2111
  walk(visitor, options) {
2112
+ //visitor-less walk function to do parent linking
2113
+ (0, visitors_1.walk)(this, 'parentClassName', null, options);
1177
2114
  if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
1178
- for (let i = 0; i < this.body.length; i++) {
1179
- visitors_1.walk(this.body, i, visitor, options, this);
2115
+ (0, visitors_1.walkArray)(this.body, visitor, options, this);
2116
+ }
2117
+ }
2118
+ getType(options) {
2119
+ var _a, _b, _c, _d, _e, _f, _g, _h;
2120
+ const superClass = (_a = this.parentClassName) === null || _a === void 0 ? void 0 : _a.getType(options);
2121
+ const resultType = new ClassType_1.ClassType(this.getName(Parser_1.ParseMode.BrighterScript), superClass);
2122
+ for (const statement of this.methods) {
2123
+ const funcType = statement === null || statement === void 0 ? void 0 : statement.func.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); //no typechain needed
2124
+ let flag = 1 /* SymbolTypeFlag.runtime */;
2125
+ if (((_b = statement.accessModifier) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Private) {
2126
+ flag |= 8 /* SymbolTypeFlag.private */;
2127
+ }
2128
+ if (((_c = statement.accessModifier) === null || _c === void 0 ? void 0 : _c.kind) === TokenKind_1.TokenKind.Protected) {
2129
+ flag |= 16 /* SymbolTypeFlag.protected */;
1180
2130
  }
2131
+ resultType.addMember((_d = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _d === void 0 ? void 0 : _d.text, { definingNode: statement }, funcType, flag);
1181
2132
  }
2133
+ for (const statement of this.fields) {
2134
+ const fieldType = statement.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })); //no typechain needed
2135
+ let flag = 1 /* SymbolTypeFlag.runtime */;
2136
+ if (statement.isOptional) {
2137
+ flag |= 4 /* SymbolTypeFlag.optional */;
2138
+ }
2139
+ if (((_e = statement.tokens.accessModifier) === null || _e === void 0 ? void 0 : _e.kind) === TokenKind_1.TokenKind.Private) {
2140
+ flag |= 8 /* SymbolTypeFlag.private */;
2141
+ }
2142
+ if (((_f = statement.tokens.accessModifier) === null || _f === void 0 ? void 0 : _f.kind) === TokenKind_1.TokenKind.Protected) {
2143
+ flag |= 16 /* SymbolTypeFlag.protected */;
2144
+ }
2145
+ resultType.addMember((_g = statement === null || statement === void 0 ? void 0 : statement.tokens.name) === null || _g === void 0 ? void 0 : _g.text, { definingNode: statement, isInstance: true }, fieldType, flag);
2146
+ }
2147
+ (_h = options.typeChain) === null || _h === void 0 ? void 0 : _h.push(new interfaces_1.TypeChainEntry({ name: resultType.name, type: resultType, data: options.data, astNode: this }));
2148
+ return resultType;
2149
+ }
2150
+ clone() {
2151
+ var _a, _b;
2152
+ return this.finalizeClone(new ClassStatement({
2153
+ class: util_1.util.cloneToken(this.tokens.class),
2154
+ name: util_1.util.cloneToken(this.tokens.name),
2155
+ body: (_a = this.body) === null || _a === void 0 ? void 0 : _a.map(x => x === null || x === void 0 ? void 0 : x.clone()),
2156
+ endClass: util_1.util.cloneToken(this.tokens.endClass),
2157
+ extends: util_1.util.cloneToken(this.tokens.extends),
2158
+ parentClassName: (_b = this.parentClassName) === null || _b === void 0 ? void 0 : _b.clone()
2159
+ }), ['body', 'parentClassName']);
1182
2160
  }
1183
2161
  }
1184
2162
  exports.ClassStatement = ClassStatement;
1185
- class ClassMethodStatement extends FunctionStatement {
1186
- constructor(accessModifier, name, func, override) {
1187
- var _a;
1188
- super(name, func, undefined);
1189
- this.accessModifier = accessModifier;
1190
- this.override = override;
1191
- this.range = util_1.util.createRangeFromPositions(((_a = this.accessModifier) !== null && _a !== void 0 ? _a : this.func).range.start, this.func.range.end);
2163
+ const accessModifiers = [
2164
+ TokenKind_1.TokenKind.Public,
2165
+ TokenKind_1.TokenKind.Protected,
2166
+ TokenKind_1.TokenKind.Private
2167
+ ];
2168
+ class MethodStatement extends FunctionStatement {
2169
+ constructor(options) {
2170
+ super(options);
2171
+ this.kind = AstNode_1.AstNodeKind.MethodStatement;
2172
+ this.modifiers = [];
2173
+ if (options.modifiers) {
2174
+ if (Array.isArray(options.modifiers)) {
2175
+ this.modifiers.push(...options.modifiers);
2176
+ }
2177
+ else {
2178
+ this.modifiers.push(options.modifiers);
2179
+ }
2180
+ }
2181
+ this.tokens = Object.assign(Object.assign({}, this.tokens), { override: options.override });
2182
+ this.location = util_1.util.createBoundingLocation(...(this.modifiers), util_1.util.createBoundingLocationFromTokens(this.tokens), this.func);
1192
2183
  }
1193
- transpile(state) {
1194
- if (this.name.text.toLowerCase() === 'new') {
2184
+ get accessModifier() {
2185
+ return this.modifiers.find(x => accessModifiers.includes(x.kind));
2186
+ }
2187
+ /**
2188
+ * Get the name of this method.
2189
+ */
2190
+ getName(parseMode) {
2191
+ return this.tokens.name.text;
2192
+ }
2193
+ get leadingTrivia() {
2194
+ return this.func.leadingTrivia;
2195
+ }
2196
+ transpile(state, name) {
2197
+ if (this.tokens.name.text.toLowerCase() === 'new') {
1195
2198
  this.ensureSuperConstructorCall(state);
1196
2199
  //TODO we need to undo this at the bottom of this method
1197
2200
  this.injectFieldInitializersForConstructor(state);
@@ -1199,18 +2202,18 @@ class ClassMethodStatement extends FunctionStatement {
1199
2202
  //TODO - remove type information from these methods because that doesn't work
1200
2203
  //convert the `super` calls into the proper methods
1201
2204
  const parentClassIndex = state.classStatement.getParentClassIndex(state);
1202
- const visitor = visitors_1.createVisitor({
2205
+ const visitor = (0, visitors_1.createVisitor)({
1203
2206
  VariableExpression: e => {
1204
- if (e.name.text.toLocaleLowerCase() === 'super') {
1205
- e.name.text = `m.super${parentClassIndex}_new`;
2207
+ if (e.tokens.name.text.toLocaleLowerCase() === 'super') {
2208
+ state.editor.setProperty(e.tokens.name, 'text', `m.super${parentClassIndex}_new`);
1206
2209
  }
1207
2210
  },
1208
2211
  DottedGetExpression: e => {
1209
2212
  const beginningVariable = util_1.util.findBeginningVariableExpression(e);
1210
2213
  const lowerName = beginningVariable === null || beginningVariable === void 0 ? void 0 : beginningVariable.getName(Parser_1.ParseMode.BrighterScript).toLowerCase();
1211
2214
  if (lowerName === 'super') {
1212
- beginningVariable.name.text = 'm';
1213
- e.name.text = `super${parentClassIndex}_${e.name.text}`;
2215
+ state.editor.setProperty(beginningVariable.tokens.name, 'text', 'm');
2216
+ state.editor.setProperty(e.tokens.name, 'text', `super${parentClassIndex}_${e.tokens.name.text}`);
1214
2217
  }
1215
2218
  }
1216
2219
  });
@@ -1219,21 +2222,24 @@ class ClassMethodStatement extends FunctionStatement {
1219
2222
  visitor(statement, undefined);
1220
2223
  statement.walk(visitor, walkOptions);
1221
2224
  }
1222
- return this.func.transpile(state);
2225
+ return this.func.transpile(state, name);
1223
2226
  }
1224
2227
  getTypedef(state) {
1225
- var _a;
2228
+ var _a, _b;
1226
2229
  const result = [];
1227
- for (let annotation of (_a = this.annotations) !== null && _a !== void 0 ? _a : []) {
2230
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
2231
+ result.push(comment.text, state.newline, state.indent());
2232
+ }
2233
+ for (let annotation of (_b = this.annotations) !== null && _b !== void 0 ? _b : []) {
1228
2234
  result.push(...annotation.getTypedef(state), state.newline, state.indent());
1229
2235
  }
1230
2236
  if (this.accessModifier) {
1231
2237
  result.push(this.accessModifier.text, ' ');
1232
2238
  }
1233
- if (this.override) {
2239
+ if (this.tokens.override) {
1234
2240
  result.push('override ');
1235
2241
  }
1236
- result.push(...this.func.getTypedef(state, this.name));
2242
+ result.push(...this.func.getTypedef(state));
1237
2243
  return result;
1238
2244
  }
1239
2245
  /**
@@ -1245,180 +2251,961 @@ class ClassMethodStatement extends FunctionStatement {
1245
2251
  if (state.classStatement.getAncestors(state).length === 0) {
1246
2252
  return;
1247
2253
  }
1248
- //if the first statement is a call to super, quit here
1249
- let firstStatement = this.func.body.statements[0];
1250
- if (
1251
- //is a call statement
1252
- reflection_1.isExpressionStatement(firstStatement) && reflection_1.isCallExpression(firstStatement.expression) &&
1253
- //is a call to super
1254
- util_1.util.findBeginningVariableExpression(firstStatement === null || firstStatement === void 0 ? void 0 : firstStatement.expression.callee).name.text.toLowerCase() === 'super') {
2254
+ //check whether any calls to super exist
2255
+ let containsSuperCall = this.func.body.statements.findIndex((x) => {
2256
+ var _a;
2257
+ //is a call statement
2258
+ return (0, reflection_1.isExpressionStatement)(x) && (0, reflection_1.isCallExpression)(x.expression) &&
2259
+ //is a call to super
2260
+ ((_a = util_1.util.findBeginningVariableExpression(x.expression.callee).tokens.name) === null || _a === void 0 ? void 0 : _a.text.toLowerCase()) === 'super';
2261
+ }) !== -1;
2262
+ //if a call to super exists, quit here
2263
+ if (containsSuperCall) {
1255
2264
  return;
1256
2265
  }
1257
- //this is a child class, and the first statement isn't a call to super. Inject one
1258
- this.func.body.statements.unshift(new ExpressionStatement(new Expression_1.CallExpression(new Expression_1.VariableExpression({
1259
- kind: lexer_1.TokenKind.Identifier,
1260
- text: 'super',
1261
- isReserved: false,
1262
- range: state.classStatement.name.range,
1263
- leadingWhitespace: ''
1264
- }, null), {
1265
- kind: lexer_1.TokenKind.LeftParen,
1266
- text: '(',
1267
- isReserved: false,
1268
- range: state.classStatement.name.range,
1269
- leadingWhitespace: ''
1270
- }, {
1271
- kind: lexer_1.TokenKind.RightParen,
1272
- text: ')',
1273
- isReserved: false,
1274
- range: state.classStatement.name.range,
1275
- leadingWhitespace: ''
1276
- }, [], null)));
2266
+ //this is a child class, and the constructor doesn't contain a call to super. Inject one
2267
+ const superCall = new ExpressionStatement({
2268
+ expression: new Expression_2.CallExpression({
2269
+ callee: new Expression_2.VariableExpression({
2270
+ name: {
2271
+ kind: TokenKind_1.TokenKind.Identifier,
2272
+ text: 'super',
2273
+ isReserved: false,
2274
+ location: state.classStatement.tokens.name.location,
2275
+ leadingWhitespace: '',
2276
+ leadingTrivia: []
2277
+ }
2278
+ }),
2279
+ openingParen: {
2280
+ kind: TokenKind_1.TokenKind.LeftParen,
2281
+ text: '(',
2282
+ isReserved: false,
2283
+ location: state.classStatement.tokens.name.location,
2284
+ leadingWhitespace: '',
2285
+ leadingTrivia: []
2286
+ },
2287
+ closingParen: {
2288
+ kind: TokenKind_1.TokenKind.RightParen,
2289
+ text: ')',
2290
+ isReserved: false,
2291
+ location: state.classStatement.tokens.name.location,
2292
+ leadingWhitespace: '',
2293
+ leadingTrivia: []
2294
+ },
2295
+ args: []
2296
+ })
2297
+ });
2298
+ state.editor.arrayUnshift(this.func.body.statements, superCall);
1277
2299
  }
1278
2300
  /**
1279
2301
  * Inject field initializers at the top of the `new` function (after any present `super()` call)
1280
2302
  */
1281
2303
  injectFieldInitializersForConstructor(state) {
2304
+ var _a;
1282
2305
  let startingIndex = state.classStatement.hasParentClass() ? 1 : 0;
1283
2306
  let newStatements = [];
1284
2307
  //insert the field initializers in order
1285
2308
  for (let field of state.classStatement.fields) {
1286
- let thisQualifiedName = Object.assign({}, field.name);
1287
- thisQualifiedName.text = 'm.' + field.name.text;
1288
- if (field.initialValue) {
1289
- newStatements.push(new AssignmentStatement(thisQualifiedName, field.equal, field.initialValue, this.func));
1290
- }
1291
- else {
1292
- //if there is no initial value, set the initial value to `invalid`
1293
- newStatements.push(new AssignmentStatement(thisQualifiedName, creators_1.createToken(lexer_1.TokenKind.Equal, '=', field.name.range), creators_1.createInvalidLiteral('invalid', field.name.range), this.func));
1294
- }
1295
- }
1296
- this.func.body.statements.splice(startingIndex, 0, ...newStatements);
2309
+ let thisQualifiedName = Object.assign({}, field.tokens.name);
2310
+ thisQualifiedName.text = 'm.' + ((_a = field.tokens.name) === null || _a === void 0 ? void 0 : _a.text);
2311
+ const fieldAssignment = field.initialValue
2312
+ ? new AssignmentStatement({
2313
+ equals: field.tokens.equals,
2314
+ name: thisQualifiedName,
2315
+ value: field.initialValue
2316
+ })
2317
+ : new AssignmentStatement({
2318
+ equals: (0, creators_1.createToken)(TokenKind_1.TokenKind.Equal, '=', field.tokens.name.location),
2319
+ name: thisQualifiedName,
2320
+ //if there is no initial value, set the initial value to `invalid`
2321
+ value: (0, creators_1.createInvalidLiteral)('invalid', field.tokens.name.location)
2322
+ });
2323
+ // Add parent so namespace lookups work
2324
+ fieldAssignment.parent = state.classStatement;
2325
+ newStatements.push(fieldAssignment);
2326
+ }
2327
+ state.editor.arraySplice(this.func.body.statements, startingIndex, 0, ...newStatements);
1297
2328
  }
1298
2329
  walk(visitor, options) {
1299
2330
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1300
- visitors_1.walk(this, 'func', visitor, options);
2331
+ (0, visitors_1.walk)(this, 'func', visitor, options);
1301
2332
  }
1302
2333
  }
2334
+ clone() {
2335
+ var _a, _b;
2336
+ return this.finalizeClone(new MethodStatement({
2337
+ modifiers: (_a = this.modifiers) === null || _a === void 0 ? void 0 : _a.map(m => util_1.util.cloneToken(m)),
2338
+ name: util_1.util.cloneToken(this.tokens.name),
2339
+ func: (_b = this.func) === null || _b === void 0 ? void 0 : _b.clone(),
2340
+ override: util_1.util.cloneToken(this.tokens.override)
2341
+ }), ['func']);
2342
+ }
1303
2343
  }
1304
- exports.ClassMethodStatement = ClassMethodStatement;
1305
- class ClassFieldStatement extends Statement {
1306
- constructor(accessModifier, name, as, type, equal, initialValue) {
1307
- var _a, _b, _c, _d;
2344
+ exports.MethodStatement = MethodStatement;
2345
+ class FieldStatement extends AstNode_1.Statement {
2346
+ constructor(options) {
1308
2347
  super();
1309
- this.accessModifier = accessModifier;
1310
- this.name = name;
1311
- this.as = as;
1312
- this.type = type;
1313
- this.equal = equal;
1314
- this.initialValue = initialValue;
1315
- this.range = util_1.util.createRangeFromPositions(((_a = this.accessModifier) !== null && _a !== void 0 ? _a : this.name).range.start, ((_d = (_c = (_b = this.initialValue) !== null && _b !== void 0 ? _b : this.type) !== null && _c !== void 0 ? _c : this.as) !== null && _d !== void 0 ? _d : this.name).range.end);
2348
+ this.kind = AstNode_1.AstNodeKind.FieldStatement;
2349
+ this.tokens = {
2350
+ accessModifier: options.accessModifier,
2351
+ name: options.name,
2352
+ as: options.as,
2353
+ equals: options.equals,
2354
+ optional: options.optional
2355
+ };
2356
+ this.typeExpression = options.typeExpression;
2357
+ this.initialValue = options.initialValue;
2358
+ this.location = util_1.util.createBoundingLocation(util_1.util.createBoundingLocationFromTokens(this.tokens), this.typeExpression, this.initialValue);
1316
2359
  }
1317
2360
  /**
1318
2361
  * Derive a ValueKind from the type token, or the initial value.
1319
2362
  * Defaults to `DynamicType`
1320
2363
  */
1321
- getType() {
1322
- if (this.type) {
1323
- return util_1.util.tokenToBscType(this.type);
1324
- }
1325
- else if (reflection_1.isLiteralExpression(this.initialValue)) {
1326
- return this.initialValue.type;
1327
- }
1328
- else {
1329
- return new DynamicType_1.DynamicType();
2364
+ getType(options) {
2365
+ var _a, _b, _c, _d;
2366
+ let initialValueType = (_a = this.initialValue) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */ }));
2367
+ if ((0, reflection_1.isInvalidType)(initialValueType) || (0, reflection_1.isVoidType)(initialValueType) || (0, reflection_1.isUninitializedType)(initialValueType)) {
2368
+ initialValueType = undefined;
1330
2369
  }
2370
+ return (_d = (_c = (_b = this.typeExpression) === null || _b === void 0 ? void 0 : _b.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */ }))) !== null && _c !== void 0 ? _c : util_1.util.getDefaultTypeFromValueType(initialValueType)) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
2371
+ }
2372
+ get leadingTrivia() {
2373
+ var _a, _b, _c, _d;
2374
+ return (_d = (_b = (_a = this.tokens.accessModifier) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : (_c = this.tokens.optional) === null || _c === void 0 ? void 0 : _c.leadingTrivia) !== null && _d !== void 0 ? _d : this.tokens.name.leadingTrivia;
2375
+ }
2376
+ get isOptional() {
2377
+ return !!this.tokens.optional;
1331
2378
  }
1332
2379
  transpile(state) {
1333
2380
  throw new Error('transpile not implemented for ' + Object.getPrototypeOf(this).constructor.name);
1334
2381
  }
1335
2382
  getTypedef(state) {
1336
- var _a, _b, _c, _d;
2383
+ var _a, _b, _c, _d, _e;
1337
2384
  const result = [];
1338
- if (this.name) {
1339
- for (let annotation of (_a = this.annotations) !== null && _a !== void 0 ? _a : []) {
2385
+ if (this.tokens.name) {
2386
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
2387
+ result.push(comment.text, state.newline, state.indent());
2388
+ }
2389
+ for (let annotation of (_b = this.annotations) !== null && _b !== void 0 ? _b : []) {
1340
2390
  result.push(...annotation.getTypedef(state), state.newline, state.indent());
1341
2391
  }
1342
- let type = this.getType();
1343
- if (reflection_1.isInvalidType(type) || reflection_1.isVoidType(type)) {
1344
- type = new DynamicType_1.DynamicType();
2392
+ let type = this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ });
2393
+ if ((0, reflection_1.isInvalidType)(type) || (0, reflection_1.isVoidType)(type) || (0, reflection_1.isUninitializedType)(type)) {
2394
+ type = DynamicType_1.DynamicType.instance;
1345
2395
  }
1346
- result.push((_c = (_b = this.accessModifier) === null || _b === void 0 ? void 0 : _b.text) !== null && _c !== void 0 ? _c : 'public', ' ', (_d = this.name) === null || _d === void 0 ? void 0 : _d.text, ' as ', type.toTypeString());
2396
+ result.push((_d = (_c = this.tokens.accessModifier) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : 'public', ' ');
2397
+ if (this.isOptional) {
2398
+ result.push(this.tokens.optional.text, ' ');
2399
+ }
2400
+ result.push((_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.text, ' as ', type.toTypeString());
1347
2401
  }
1348
2402
  return result;
1349
2403
  }
1350
2404
  walk(visitor, options) {
1351
- if (this.initialValue && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1352
- visitors_1.walk(this, 'initialValue', visitor, options);
2405
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
2406
+ (0, visitors_1.walk)(this, 'typeExpression', visitor, options);
2407
+ (0, visitors_1.walk)(this, 'initialValue', visitor, options);
1353
2408
  }
1354
2409
  }
2410
+ clone() {
2411
+ var _a, _b;
2412
+ return this.finalizeClone(new FieldStatement({
2413
+ accessModifier: util_1.util.cloneToken(this.tokens.accessModifier),
2414
+ name: util_1.util.cloneToken(this.tokens.name),
2415
+ as: util_1.util.cloneToken(this.tokens.as),
2416
+ typeExpression: (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.clone(),
2417
+ equals: util_1.util.cloneToken(this.tokens.equals),
2418
+ initialValue: (_b = this.initialValue) === null || _b === void 0 ? void 0 : _b.clone(),
2419
+ optional: util_1.util.cloneToken(this.tokens.optional)
2420
+ }), ['initialValue']);
2421
+ }
1355
2422
  }
1356
- exports.ClassFieldStatement = ClassFieldStatement;
1357
- class TryCatchStatement extends Statement {
1358
- constructor(tryToken, tryBranch, catchToken, exceptionVariable, catchBranch, endTryToken) {
2423
+ exports.FieldStatement = FieldStatement;
2424
+ class TryCatchStatement extends AstNode_1.Statement {
2425
+ constructor(options) {
1359
2426
  super();
1360
- this.tryToken = tryToken;
1361
- this.tryBranch = tryBranch;
1362
- this.catchToken = catchToken;
1363
- this.exceptionVariable = exceptionVariable;
1364
- this.catchBranch = catchBranch;
1365
- this.endTryToken = endTryToken;
1366
- }
1367
- get range() {
1368
- var _a, _b, _c, _d, _e;
1369
- return util_1.util.createRangeFromPositions(this.tryToken.range.start, ((_e = (_d = (_c = (_b = (_a = this.endTryToken) !== null && _a !== void 0 ? _a : this.catchBranch) !== null && _b !== void 0 ? _b : this.exceptionVariable) !== null && _c !== void 0 ? _c : this.catchToken) !== null && _d !== void 0 ? _d : this.tryBranch) !== null && _e !== void 0 ? _e : this.tryToken).range.end);
2427
+ this.kind = AstNode_1.AstNodeKind.TryCatchStatement;
2428
+ this.tokens = {
2429
+ try: options.try,
2430
+ endTry: options.endTry
2431
+ };
2432
+ this.tryBranch = options.tryBranch;
2433
+ this.catchStatement = options.catchStatement;
2434
+ this.location = util_1.util.createBoundingLocation(this.tokens.try, this.tryBranch, this.catchStatement, this.tokens.endTry);
1370
2435
  }
1371
2436
  transpile(state) {
2437
+ var _a, _b;
1372
2438
  return [
1373
- state.transpileToken(this.tryToken),
2439
+ state.transpileToken(this.tokens.try, 'try'),
1374
2440
  ...this.tryBranch.transpile(state),
1375
2441
  state.newline,
1376
2442
  state.indent(),
1377
- state.transpileToken(this.catchToken),
1378
- ' ',
1379
- state.transpileToken(this.exceptionVariable),
1380
- ...this.catchBranch.transpile(state),
2443
+ ...((_b = (_a = this.catchStatement) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : ['catch']),
1381
2444
  state.newline,
1382
2445
  state.indent(),
1383
- state.transpileToken(this.endTryToken)
2446
+ state.transpileToken(this.tokens.endTry, 'end try')
1384
2447
  ];
1385
2448
  }
1386
2449
  walk(visitor, options) {
1387
2450
  if (this.tryBranch && options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
1388
- visitors_1.walk(this, 'tryBranch', visitor, options);
1389
- visitors_1.walk(this, 'catchBranch', visitor, options);
2451
+ (0, visitors_1.walk)(this, 'tryBranch', visitor, options);
2452
+ (0, visitors_1.walk)(this, 'catchStatement', visitor, options);
1390
2453
  }
1391
2454
  }
2455
+ get leadingTrivia() {
2456
+ var _a, _b;
2457
+ return (_b = (_a = this.tokens.try) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
2458
+ }
2459
+ get endTrivia() {
2460
+ var _a, _b;
2461
+ return (_b = (_a = this.tokens.endTry) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
2462
+ }
2463
+ clone() {
2464
+ var _a, _b;
2465
+ return this.finalizeClone(new TryCatchStatement({
2466
+ try: util_1.util.cloneToken(this.tokens.try),
2467
+ endTry: util_1.util.cloneToken(this.tokens.endTry),
2468
+ tryBranch: (_a = this.tryBranch) === null || _a === void 0 ? void 0 : _a.clone(),
2469
+ catchStatement: (_b = this.catchStatement) === null || _b === void 0 ? void 0 : _b.clone()
2470
+ }), ['tryBranch', 'catchStatement']);
2471
+ }
1392
2472
  }
1393
2473
  exports.TryCatchStatement = TryCatchStatement;
1394
- class ThrowStatement extends Statement {
1395
- constructor(throwToken, expression) {
1396
- var _a;
2474
+ class CatchStatement extends AstNode_1.Statement {
2475
+ constructor(options) {
1397
2476
  super();
1398
- this.throwToken = throwToken;
1399
- this.expression = expression;
1400
- this.range = util_1.util.createRangeFromPositions(this.throwToken.range.start, ((_a = this.expression) !== null && _a !== void 0 ? _a : this.throwToken).range.end);
2477
+ this.kind = AstNode_1.AstNodeKind.CatchStatement;
2478
+ this.tokens = {
2479
+ catch: options === null || options === void 0 ? void 0 : options.catch
2480
+ };
2481
+ this.exceptionVariableExpression = options === null || options === void 0 ? void 0 : options.exceptionVariableExpression;
2482
+ this.catchBranch = options === null || options === void 0 ? void 0 : options.catchBranch;
2483
+ this.location = util_1.util.createBoundingLocation(this.tokens.catch, this.exceptionVariableExpression, this.catchBranch);
1401
2484
  }
1402
2485
  transpile(state) {
1403
- const result = [
1404
- state.transpileToken(this.throwToken),
1405
- ' '
2486
+ var _a, _b, _c, _d, _e;
2487
+ return [
2488
+ state.transpileToken(this.tokens.catch, 'catch'),
2489
+ ' ',
2490
+ (_b = (_a = this.exceptionVariableExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : [
2491
+ //use the variable named `e` if it doesn't exist in this function body. otherwise use '__bsc_error' just to make sure we're out of the way
2492
+ ((_c = this.getSymbolTable()) === null || _c === void 0 ? void 0 : _c.hasSymbol('e', 1 /* SymbolTypeFlag.runtime */))
2493
+ ? '__bsc_error'
2494
+ : 'e'
2495
+ ],
2496
+ ...((_e = (_d = this.catchBranch) === null || _d === void 0 ? void 0 : _d.transpile(state)) !== null && _e !== void 0 ? _e : [])
1406
2497
  ];
1407
- //if we have an expression, transpile it
1408
- if (this.expression) {
1409
- result.push(...this.expression.transpile(state));
1410
- //no expression found. Rather than emit syntax errors, provide a generic error message
1411
- }
2498
+ }
2499
+ walk(visitor, options) {
2500
+ if (this.catchBranch && options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
2501
+ (0, visitors_1.walk)(this, 'catchBranch', visitor, options);
2502
+ }
2503
+ }
2504
+ get leadingTrivia() {
2505
+ var _a, _b;
2506
+ return (_b = (_a = this.tokens.catch) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
2507
+ }
2508
+ clone() {
2509
+ var _a, _b;
2510
+ return this.finalizeClone(new CatchStatement({
2511
+ catch: util_1.util.cloneToken(this.tokens.catch),
2512
+ exceptionVariableExpression: (_a = this.exceptionVariableExpression) === null || _a === void 0 ? void 0 : _a.clone(),
2513
+ catchBranch: (_b = this.catchBranch) === null || _b === void 0 ? void 0 : _b.clone()
2514
+ }), ['catchBranch']);
2515
+ }
2516
+ }
2517
+ exports.CatchStatement = CatchStatement;
2518
+ class ThrowStatement extends AstNode_1.Statement {
2519
+ constructor(options) {
2520
+ super();
2521
+ this.kind = AstNode_1.AstNodeKind.ThrowStatement;
2522
+ this.tokens = {
2523
+ throw: options.throw
2524
+ };
2525
+ this.expression = options.expression;
2526
+ this.location = util_1.util.createBoundingLocation(this.tokens.throw, this.expression);
2527
+ }
2528
+ transpile(state) {
2529
+ const result = [
2530
+ state.transpileToken(this.tokens.throw, 'throw'),
2531
+ ' '
2532
+ ];
2533
+ //if we have an expression, transpile it
2534
+ if (this.expression) {
2535
+ result.push(...this.expression.transpile(state));
2536
+ //no expression found. Rather than emit syntax errors, provide a generic error message
2537
+ }
1412
2538
  else {
1413
- result.push('"An error has occurred"');
2539
+ result.push('"User-specified exception"');
1414
2540
  }
1415
2541
  return result;
1416
2542
  }
1417
2543
  walk(visitor, options) {
1418
2544
  if (this.expression && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1419
- visitors_1.walk(this, 'expression', visitor, options);
2545
+ (0, visitors_1.walk)(this, 'expression', visitor, options);
1420
2546
  }
1421
2547
  }
2548
+ get leadingTrivia() {
2549
+ var _a, _b;
2550
+ return (_b = (_a = this.tokens.throw) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
2551
+ }
2552
+ clone() {
2553
+ var _a;
2554
+ return this.finalizeClone(new ThrowStatement({
2555
+ throw: util_1.util.cloneToken(this.tokens.throw),
2556
+ expression: (_a = this.expression) === null || _a === void 0 ? void 0 : _a.clone()
2557
+ }), ['expression']);
2558
+ }
1422
2559
  }
1423
2560
  exports.ThrowStatement = ThrowStatement;
2561
+ class EnumStatement extends AstNode_1.Statement {
2562
+ constructor(options) {
2563
+ var _a;
2564
+ super();
2565
+ this.kind = AstNode_1.AstNodeKind.EnumStatement;
2566
+ this.tokens = {
2567
+ enum: options.enum,
2568
+ name: options.name,
2569
+ endEnum: options.endEnum
2570
+ };
2571
+ this.symbolTable = new SymbolTable_1.SymbolTable('Enum');
2572
+ this.body = (_a = options.body) !== null && _a !== void 0 ? _a : [];
2573
+ }
2574
+ get location() {
2575
+ return util_1.util.createBoundingLocation(this.tokens.enum, this.tokens.name, ...this.body, this.tokens.endEnum);
2576
+ }
2577
+ getMembers() {
2578
+ const result = [];
2579
+ for (const statement of this.body) {
2580
+ if ((0, reflection_1.isEnumMemberStatement)(statement)) {
2581
+ result.push(statement);
2582
+ }
2583
+ }
2584
+ return result;
2585
+ }
2586
+ get leadingTrivia() {
2587
+ var _a;
2588
+ return (_a = this.tokens.enum) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
2589
+ }
2590
+ get endTrivia() {
2591
+ var _a, _b;
2592
+ return (_b = (_a = this.tokens.endEnum) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
2593
+ }
2594
+ /**
2595
+ * Get a map of member names and their values.
2596
+ * All values are stored as their AST LiteralExpression representation (i.e. string enum values include the wrapping quotes)
2597
+ */
2598
+ getMemberValueMap() {
2599
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
2600
+ const result = new Map();
2601
+ const members = this.getMembers();
2602
+ let currentIntValue = 0;
2603
+ for (const member of members) {
2604
+ //if there is no value, assume an integer and increment the int counter
2605
+ if (!member.value) {
2606
+ result.set((_a = member.name) === null || _a === void 0 ? void 0 : _a.toLowerCase(), currentIntValue.toString());
2607
+ currentIntValue++;
2608
+ //if explicit integer value, use it and increment the int counter
2609
+ }
2610
+ else if ((0, reflection_1.isLiteralExpression)(member.value) && member.value.tokens.value.kind === TokenKind_1.TokenKind.IntegerLiteral) {
2611
+ //try parsing as integer literal, then as hex integer literal.
2612
+ let tokenIntValue = (_b = util_1.util.parseInt(member.value.tokens.value.text)) !== null && _b !== void 0 ? _b : util_1.util.parseInt(member.value.tokens.value.text.replace(/&h/i, '0x'));
2613
+ if (tokenIntValue !== undefined) {
2614
+ currentIntValue = tokenIntValue;
2615
+ currentIntValue++;
2616
+ }
2617
+ result.set((_c = member.name) === null || _c === void 0 ? void 0 : _c.toLowerCase(), member.value.tokens.value.text);
2618
+ //simple unary expressions (like `-1`)
2619
+ }
2620
+ else if ((0, reflection_1.isUnaryExpression)(member.value) && (0, reflection_1.isLiteralExpression)(member.value.right)) {
2621
+ result.set((_d = member.name) === null || _d === void 0 ? void 0 : _d.toLowerCase(), member.value.tokens.operator.text + member.value.right.tokens.value.text);
2622
+ //all other values
2623
+ }
2624
+ else {
2625
+ result.set((_e = member.name) === null || _e === void 0 ? void 0 : _e.toLowerCase(), (_j = (_h = (_g = (_f = member.value) === null || _f === void 0 ? void 0 : _f.tokens) === null || _g === void 0 ? void 0 : _g.value) === null || _h === void 0 ? void 0 : _h.text) !== null && _j !== void 0 ? _j : 'invalid');
2626
+ }
2627
+ }
2628
+ return result;
2629
+ }
2630
+ getMemberValue(name) {
2631
+ return this.getMemberValueMap().get(name.toLowerCase());
2632
+ }
2633
+ /**
2634
+ * The name of the enum (without the namespace prefix)
2635
+ */
2636
+ get name() {
2637
+ var _a;
2638
+ return (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text;
2639
+ }
2640
+ /**
2641
+ * The name of the enum WITH its leading namespace (if applicable)
2642
+ */
2643
+ get fullName() {
2644
+ var _a;
2645
+ const name = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text;
2646
+ if (name) {
2647
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
2648
+ if (namespace) {
2649
+ let namespaceName = namespace.getName(Parser_1.ParseMode.BrighterScript);
2650
+ return `${namespaceName}.${name}`;
2651
+ }
2652
+ else {
2653
+ return name;
2654
+ }
2655
+ }
2656
+ else {
2657
+ //return undefined which will allow outside callers to know that this doesn't have a name
2658
+ return undefined;
2659
+ }
2660
+ }
2661
+ transpile(state) {
2662
+ //enum declarations don't exist at runtime, so just transpile comments and trivia
2663
+ return [
2664
+ state.transpileAnnotations(this),
2665
+ state.transpileLeadingComments(this.tokens.enum)
2666
+ ];
2667
+ }
2668
+ getTypedef(state) {
2669
+ var _a, _b, _c, _d, _e, _f;
2670
+ const result = [];
2671
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
2672
+ result.push(comment.text, state.newline, state.indent());
2673
+ }
2674
+ for (let annotation of (_b = this.annotations) !== null && _b !== void 0 ? _b : []) {
2675
+ result.push(...annotation.getTypedef(state), state.newline, state.indent());
2676
+ }
2677
+ result.push((_d = (_c = this.tokens.enum) === null || _c === void 0 ? void 0 : _c.text) !== null && _d !== void 0 ? _d : 'enum', ' ', this.tokens.name.text);
2678
+ result.push(state.newline);
2679
+ state.blockDepth++;
2680
+ for (const member of this.body) {
2681
+ if ((0, reflection_1.isTypedefProvider)(member)) {
2682
+ result.push(state.indent(), ...member.getTypedef(state), state.newline);
2683
+ }
2684
+ }
2685
+ state.blockDepth--;
2686
+ result.push(state.indent(), (_f = (_e = this.tokens.endEnum) === null || _e === void 0 ? void 0 : _e.text) !== null && _f !== void 0 ? _f : 'end enum');
2687
+ return result;
2688
+ }
2689
+ walk(visitor, options) {
2690
+ if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
2691
+ (0, visitors_1.walkArray)(this.body, visitor, options, this);
2692
+ }
2693
+ }
2694
+ getType(options) {
2695
+ var _a, _b, _c;
2696
+ const members = this.getMembers();
2697
+ const resultType = new EnumType_1.EnumType(this.fullName, (_a = members[0]) === null || _a === void 0 ? void 0 : _a.getType(options).underlyingType);
2698
+ resultType.pushMemberProvider(() => this.getSymbolTable());
2699
+ for (const statement of members) {
2700
+ const memberType = statement.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
2701
+ memberType.parentEnumType = resultType;
2702
+ resultType.addMember((_c = (_b = statement === null || statement === void 0 ? void 0 : statement.tokens) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.text, { definingNode: statement }, memberType, 1 /* SymbolTypeFlag.runtime */);
2703
+ }
2704
+ return resultType;
2705
+ }
2706
+ clone() {
2707
+ var _a;
2708
+ return this.finalizeClone(new EnumStatement({
2709
+ enum: util_1.util.cloneToken(this.tokens.enum),
2710
+ name: util_1.util.cloneToken(this.tokens.name),
2711
+ endEnum: util_1.util.cloneToken(this.tokens.endEnum),
2712
+ body: (_a = this.body) === null || _a === void 0 ? void 0 : _a.map(x => x === null || x === void 0 ? void 0 : x.clone())
2713
+ }), ['body']);
2714
+ }
2715
+ }
2716
+ exports.EnumStatement = EnumStatement;
2717
+ class EnumMemberStatement extends AstNode_1.Statement {
2718
+ constructor(options) {
2719
+ super();
2720
+ this.kind = AstNode_1.AstNodeKind.EnumMemberStatement;
2721
+ this.tokens = {
2722
+ name: options.name,
2723
+ equals: options.equals
2724
+ };
2725
+ this.value = options.value;
2726
+ }
2727
+ get location() {
2728
+ return util_1.util.createBoundingLocation(this.tokens.name, this.tokens.equals, this.value);
2729
+ }
2730
+ /**
2731
+ * The name of the member
2732
+ */
2733
+ get name() {
2734
+ return this.tokens.name.text;
2735
+ }
2736
+ get leadingTrivia() {
2737
+ return this.tokens.name.leadingTrivia;
2738
+ }
2739
+ transpile(state) {
2740
+ return [];
2741
+ }
2742
+ getTypedef(state) {
2743
+ var _a;
2744
+ const result = [];
2745
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
2746
+ result.push(comment.text, state.newline, state.indent());
2747
+ }
2748
+ result.push(this.tokens.name.text);
2749
+ if (this.tokens.equals) {
2750
+ result.push(' ', this.tokens.equals.text, ' ');
2751
+ if (this.value) {
2752
+ result.push(...this.value.transpile(state));
2753
+ }
2754
+ }
2755
+ return result;
2756
+ }
2757
+ walk(visitor, options) {
2758
+ if (this.value && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
2759
+ (0, visitors_1.walk)(this, 'value', visitor, options);
2760
+ }
2761
+ }
2762
+ getType(options) {
2763
+ var _a, _b, _c, _d;
2764
+ return new EnumType_1.EnumMemberType((_a = this.parent) === null || _a === void 0 ? void 0 : _a.fullName, (_c = (_b = this.tokens) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.text, (_d = this.value) === null || _d === void 0 ? void 0 : _d.getType(options));
2765
+ }
2766
+ clone() {
2767
+ var _a;
2768
+ return this.finalizeClone(new EnumMemberStatement({
2769
+ name: util_1.util.cloneToken(this.tokens.name),
2770
+ equals: util_1.util.cloneToken(this.tokens.equals),
2771
+ value: (_a = this.value) === null || _a === void 0 ? void 0 : _a.clone()
2772
+ }), ['value']);
2773
+ }
2774
+ }
2775
+ exports.EnumMemberStatement = EnumMemberStatement;
2776
+ class ConstStatement extends AstNode_1.Statement {
2777
+ constructor(options) {
2778
+ super();
2779
+ this.kind = AstNode_1.AstNodeKind.ConstStatement;
2780
+ this.tokens = {
2781
+ const: options.const,
2782
+ name: options.name,
2783
+ equals: options.equals
2784
+ };
2785
+ this.value = options.value;
2786
+ this.location = util_1.util.createBoundingLocation(this.tokens.const, this.tokens.name, this.tokens.equals, this.value);
2787
+ }
2788
+ get name() {
2789
+ return this.tokens.name.text;
2790
+ }
2791
+ get leadingTrivia() {
2792
+ var _a;
2793
+ return (_a = this.tokens.const) === null || _a === void 0 ? void 0 : _a.leadingTrivia;
2794
+ }
2795
+ /**
2796
+ * The name of the statement WITH its leading namespace (if applicable)
2797
+ */
2798
+ get fullName() {
2799
+ var _a;
2800
+ const name = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.text;
2801
+ if (name) {
2802
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
2803
+ if (namespace) {
2804
+ let namespaceName = namespace.getName(Parser_1.ParseMode.BrighterScript);
2805
+ return `${namespaceName}.${name}`;
2806
+ }
2807
+ else {
2808
+ return name;
2809
+ }
2810
+ }
2811
+ else {
2812
+ //return undefined which will allow outside callers to know that this doesn't have a name
2813
+ return undefined;
2814
+ }
2815
+ }
2816
+ transpile(state) {
2817
+ //const declarations don't exist at runtime, so just transpile comments and trivia
2818
+ return [
2819
+ state.transpileAnnotations(this),
2820
+ state.transpileLeadingComments(this.tokens.const)
2821
+ ];
2822
+ }
2823
+ getTypedef(state) {
2824
+ var _a;
2825
+ const result = [];
2826
+ for (let comment of (_a = util_1.util.getLeadingComments(this)) !== null && _a !== void 0 ? _a : []) {
2827
+ result.push(comment.text, state.newline, state.indent());
2828
+ }
2829
+ result.push(this.tokens.const ? state.tokenToSourceNode(this.tokens.const) : 'const', ' ', state.tokenToSourceNode(this.tokens.name), ' ', this.tokens.equals ? state.tokenToSourceNode(this.tokens.equals) : '=', ' ', ...this.value.transpile(state));
2830
+ return result;
2831
+ }
2832
+ walk(visitor, options) {
2833
+ if (this.value && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
2834
+ (0, visitors_1.walk)(this, 'value', visitor, options);
2835
+ }
2836
+ }
2837
+ getType(options) {
2838
+ return this.value.getType(options);
2839
+ }
2840
+ clone() {
2841
+ var _a;
2842
+ return this.finalizeClone(new ConstStatement({
2843
+ const: util_1.util.cloneToken(this.tokens.const),
2844
+ name: util_1.util.cloneToken(this.tokens.name),
2845
+ equals: util_1.util.cloneToken(this.tokens.equals),
2846
+ value: (_a = this.value) === null || _a === void 0 ? void 0 : _a.clone()
2847
+ }), ['value']);
2848
+ }
2849
+ }
2850
+ exports.ConstStatement = ConstStatement;
2851
+ class ContinueStatement extends AstNode_1.Statement {
2852
+ constructor(options) {
2853
+ super();
2854
+ this.kind = AstNode_1.AstNodeKind.ContinueStatement;
2855
+ this.tokens = {
2856
+ continue: options.continue,
2857
+ loopType: options.loopType
2858
+ };
2859
+ this.location = util_1.util.createBoundingLocation(this.tokens.continue, this.tokens.loopType);
2860
+ }
2861
+ transpile(state) {
2862
+ var _a, _b, _c, _d, _e;
2863
+ return [
2864
+ state.sourceNode(this.tokens.continue, (_b = (_a = this.tokens.continue) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'continue'),
2865
+ (_d = (_c = this.tokens.loopType) === null || _c === void 0 ? void 0 : _c.leadingWhitespace) !== null && _d !== void 0 ? _d : ' ',
2866
+ state.sourceNode(this.tokens.continue, (_e = this.tokens.loopType) === null || _e === void 0 ? void 0 : _e.text)
2867
+ ];
2868
+ }
2869
+ walk(visitor, options) {
2870
+ //nothing to walk
2871
+ }
2872
+ get leadingTrivia() {
2873
+ var _a, _b;
2874
+ return (_b = (_a = this.tokens.continue) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
2875
+ }
2876
+ clone() {
2877
+ return this.finalizeClone(new ContinueStatement({
2878
+ continue: util_1.util.cloneToken(this.tokens.continue),
2879
+ loopType: util_1.util.cloneToken(this.tokens.loopType)
2880
+ }));
2881
+ }
2882
+ }
2883
+ exports.ContinueStatement = ContinueStatement;
2884
+ class TypecastStatement extends AstNode_1.Statement {
2885
+ constructor(options) {
2886
+ super();
2887
+ this.kind = AstNode_1.AstNodeKind.TypecastStatement;
2888
+ this.tokens = {
2889
+ typecast: options.typecast
2890
+ };
2891
+ this.typecastExpression = options.typecastExpression;
2892
+ this.location = util_1.util.createBoundingLocation(this.tokens.typecast, this.typecastExpression);
2893
+ }
2894
+ transpile(state) {
2895
+ //the typecast statement is a comment just for debugging purposes
2896
+ return [
2897
+ state.transpileToken(this.tokens.typecast, 'typecast', true),
2898
+ ' ',
2899
+ this.typecastExpression.obj.transpile(state),
2900
+ ' ',
2901
+ state.transpileToken(this.typecastExpression.tokens.as, 'as'),
2902
+ ' ',
2903
+ this.typecastExpression.typeExpression.getName(Parser_1.ParseMode.BrighterScript)
2904
+ ];
2905
+ }
2906
+ walk(visitor, options) {
2907
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
2908
+ (0, visitors_1.walk)(this, 'typecastExpression', visitor, options);
2909
+ }
2910
+ }
2911
+ get leadingTrivia() {
2912
+ var _a, _b;
2913
+ return (_b = (_a = this.tokens.typecast) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
2914
+ }
2915
+ getType(options) {
2916
+ return this.typecastExpression.getType(options);
2917
+ }
2918
+ clone() {
2919
+ var _a;
2920
+ return this.finalizeClone(new TypecastStatement({
2921
+ typecast: util_1.util.cloneToken(this.tokens.typecast),
2922
+ typecastExpression: (_a = this.typecastExpression) === null || _a === void 0 ? void 0 : _a.clone()
2923
+ }), ['typecastExpression']);
2924
+ }
2925
+ }
2926
+ exports.TypecastStatement = TypecastStatement;
2927
+ class ConditionalCompileErrorStatement extends AstNode_1.Statement {
2928
+ constructor(options) {
2929
+ super();
2930
+ this.kind = AstNode_1.AstNodeKind.ConditionalCompileErrorStatement;
2931
+ this.tokens = {
2932
+ hashError: options.hashError,
2933
+ message: options.message
2934
+ };
2935
+ this.location = util_1.util.createBoundingLocation(util_1.util.createBoundingLocationFromTokens(this.tokens));
2936
+ }
2937
+ transpile(state) {
2938
+ return [
2939
+ state.transpileToken(this.tokens.hashError, '#error'),
2940
+ ' ',
2941
+ state.transpileToken(this.tokens.message)
2942
+ ];
2943
+ }
2944
+ walk(visitor, options) {
2945
+ // nothing to walk
2946
+ }
2947
+ get leadingTrivia() {
2948
+ var _a;
2949
+ return (_a = this.tokens.hashError.leadingTrivia) !== null && _a !== void 0 ? _a : [];
2950
+ }
2951
+ clone() {
2952
+ return this.finalizeClone(new ConditionalCompileErrorStatement({
2953
+ hashError: util_1.util.cloneToken(this.tokens.hashError),
2954
+ message: util_1.util.cloneToken(this.tokens.message)
2955
+ }));
2956
+ }
2957
+ }
2958
+ exports.ConditionalCompileErrorStatement = ConditionalCompileErrorStatement;
2959
+ class AliasStatement extends AstNode_1.Statement {
2960
+ constructor(options) {
2961
+ super();
2962
+ this.kind = AstNode_1.AstNodeKind.AliasStatement;
2963
+ this.tokens = {
2964
+ alias: options.alias,
2965
+ name: options.name,
2966
+ equals: options.equals
2967
+ };
2968
+ this.value = options.value;
2969
+ this.location = util_1.util.createBoundingLocation(this.tokens.alias, this.tokens.name, this.tokens.equals, this.value);
2970
+ }
2971
+ transpile(state) {
2972
+ //transpile to a comment just for debugging purposes
2973
+ return [
2974
+ state.transpileToken(this.tokens.alias, 'alias', true),
2975
+ ' ',
2976
+ state.transpileToken(this.tokens.name),
2977
+ ' ',
2978
+ state.transpileToken(this.tokens.equals, '='),
2979
+ ' ',
2980
+ this.value.transpile(state)
2981
+ ];
2982
+ }
2983
+ walk(visitor, options) {
2984
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
2985
+ (0, visitors_1.walk)(this, 'value', visitor, options);
2986
+ }
2987
+ }
2988
+ get leadingTrivia() {
2989
+ var _a, _b;
2990
+ return (_b = (_a = this.tokens.alias) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
2991
+ }
2992
+ getType(options) {
2993
+ return this.value.getType(options);
2994
+ }
2995
+ clone() {
2996
+ var _a;
2997
+ return this.finalizeClone(new AliasStatement({
2998
+ alias: util_1.util.cloneToken(this.tokens.alias),
2999
+ name: util_1.util.cloneToken(this.tokens.name),
3000
+ equals: util_1.util.cloneToken(this.tokens.equals),
3001
+ value: (_a = this.value) === null || _a === void 0 ? void 0 : _a.clone()
3002
+ }), ['value']);
3003
+ }
3004
+ }
3005
+ exports.AliasStatement = AliasStatement;
3006
+ class ConditionalCompileStatement extends AstNode_1.Statement {
3007
+ constructor(options) {
3008
+ super();
3009
+ this.kind = AstNode_1.AstNodeKind.ConditionalCompileStatement;
3010
+ this.thenBranch = options.thenBranch;
3011
+ this.elseBranch = options.elseBranch;
3012
+ this.tokens = {
3013
+ hashIf: options.hashIf,
3014
+ not: options.not,
3015
+ condition: options.condition,
3016
+ hashElse: options.hashElse,
3017
+ hashEndIf: options.hashEndIf
3018
+ };
3019
+ this.location = util_1.util.createBoundingLocation(util_1.util.createBoundingLocationFromTokens(this.tokens), this.thenBranch, this.elseBranch);
3020
+ }
3021
+ transpile(state) {
3022
+ var _a, _b, _c;
3023
+ let results = [];
3024
+ //if (already indented by block)
3025
+ if (!state.conditionalCompileStatement) {
3026
+ // only transpile the #if in the case when we're not in a conditionalCompileStatement already
3027
+ results.push(state.transpileToken((_a = this.tokens.hashIf) !== null && _a !== void 0 ? _a : (0, creators_1.createToken)(TokenKind_1.TokenKind.HashIf)));
3028
+ }
3029
+ results.push(' ');
3030
+ //conditions
3031
+ if (this.tokens.not) {
3032
+ results.push('not');
3033
+ results.push(' ');
3034
+ }
3035
+ results.push(state.transpileToken(this.tokens.condition));
3036
+ state.lineage.unshift(this);
3037
+ //if statement body
3038
+ let thenNodes = this.thenBranch.transpile(state);
3039
+ state.lineage.shift();
3040
+ if (thenNodes.length > 0) {
3041
+ results.push(thenNodes);
3042
+ }
3043
+ //else branch
3044
+ if (this.elseBranch) {
3045
+ const elseIsCC = (0, reflection_1.isConditionalCompileStatement)(this.elseBranch);
3046
+ const endBlockToken = elseIsCC ? (_b = this.elseBranch.tokens.hashIf) !== null && _b !== void 0 ? _b : (0, creators_1.createToken)(TokenKind_1.TokenKind.HashElseIf) : this.tokens.hashElse;
3047
+ //else
3048
+ results.push(...state.transpileEndBlockToken(this.thenBranch, endBlockToken, (0, creators_1.createToken)(TokenKind_1.TokenKind.HashElse).text));
3049
+ if (elseIsCC) {
3050
+ //chained else if
3051
+ state.lineage.unshift(this.elseBranch);
3052
+ // transpile following #if with knowledge of current
3053
+ const existingCCStmt = state.conditionalCompileStatement;
3054
+ state.conditionalCompileStatement = this;
3055
+ let body = this.elseBranch.transpile(state);
3056
+ state.conditionalCompileStatement = existingCCStmt;
3057
+ state.lineage.shift();
3058
+ if (body.length > 0) {
3059
+ //zero or more spaces between the `else` and the `if`
3060
+ results.push(...body);
3061
+ // stop here because chained if will transpile the rest
3062
+ return results;
3063
+ }
3064
+ else {
3065
+ results.push('\n');
3066
+ }
3067
+ }
3068
+ else {
3069
+ //else body
3070
+ state.lineage.unshift(this.tokens.hashElse);
3071
+ let body = this.elseBranch.transpile(state);
3072
+ state.lineage.shift();
3073
+ if (body.length > 0) {
3074
+ results.push(...body);
3075
+ }
3076
+ }
3077
+ }
3078
+ //end if
3079
+ results.push(...state.transpileEndBlockToken((_c = this.elseBranch) !== null && _c !== void 0 ? _c : this.thenBranch, this.tokens.hashEndIf, '#end if'));
3080
+ return results;
3081
+ }
3082
+ walk(visitor, options) {
3083
+ var _a;
3084
+ if (options.walkMode & visitors_1.InternalWalkMode.walkStatements) {
3085
+ const bsConsts = (_a = options.bsConsts) !== null && _a !== void 0 ? _a : this.getBsConsts();
3086
+ let conditionTrue = bsConsts === null || bsConsts === void 0 ? void 0 : bsConsts.get(this.tokens.condition.text.toLowerCase());
3087
+ if (this.tokens.not) {
3088
+ // flips the boolean value
3089
+ conditionTrue = !conditionTrue;
3090
+ }
3091
+ const walkFalseBlocks = options.walkMode & visitors_1.InternalWalkMode.visitFalseConditionalCompilationBlocks;
3092
+ if (conditionTrue || walkFalseBlocks) {
3093
+ (0, visitors_1.walk)(this, 'thenBranch', visitor, options);
3094
+ }
3095
+ if (this.elseBranch && (!conditionTrue || walkFalseBlocks)) {
3096
+ (0, visitors_1.walk)(this, 'elseBranch', visitor, options);
3097
+ }
3098
+ }
3099
+ }
3100
+ get leadingTrivia() {
3101
+ var _a, _b;
3102
+ return (_b = (_a = this.tokens.hashIf) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
3103
+ }
3104
+ clone() {
3105
+ var _a, _b;
3106
+ return this.finalizeClone(new ConditionalCompileStatement({
3107
+ hashIf: util_1.util.cloneToken(this.tokens.hashIf),
3108
+ not: util_1.util.cloneToken(this.tokens.not),
3109
+ condition: util_1.util.cloneToken(this.tokens.condition),
3110
+ hashElse: util_1.util.cloneToken(this.tokens.hashElse),
3111
+ hashEndIf: util_1.util.cloneToken(this.tokens.hashEndIf),
3112
+ thenBranch: (_a = this.thenBranch) === null || _a === void 0 ? void 0 : _a.clone(),
3113
+ elseBranch: (_b = this.elseBranch) === null || _b === void 0 ? void 0 : _b.clone()
3114
+ }), ['thenBranch', 'elseBranch']);
3115
+ }
3116
+ getBranchStatementIndex(stmt) {
3117
+ if (this.thenBranch === stmt) {
3118
+ return 0;
3119
+ }
3120
+ else if (this.elseBranch === stmt) {
3121
+ return 1;
3122
+ }
3123
+ return -1;
3124
+ }
3125
+ }
3126
+ exports.ConditionalCompileStatement = ConditionalCompileStatement;
3127
+ class ConditionalCompileConstStatement extends AstNode_1.Statement {
3128
+ constructor(options) {
3129
+ super();
3130
+ this.kind = AstNode_1.AstNodeKind.ConditionalCompileConstStatement;
3131
+ this.tokens = {
3132
+ hashConst: options.hashConst
3133
+ };
3134
+ this.assignment = options.assignment;
3135
+ this.location = util_1.util.createBoundingLocation(util_1.util.createBoundingLocationFromTokens(this.tokens), this.assignment);
3136
+ }
3137
+ transpile(state) {
3138
+ return [
3139
+ state.transpileToken(this.tokens.hashConst, '#const'),
3140
+ ' ',
3141
+ state.transpileToken(this.assignment.tokens.name),
3142
+ ' ',
3143
+ state.transpileToken(this.assignment.tokens.equals, '='),
3144
+ ' ',
3145
+ ...this.assignment.value.transpile(state)
3146
+ ];
3147
+ }
3148
+ walk(visitor, options) {
3149
+ // nothing to walk
3150
+ }
3151
+ get leadingTrivia() {
3152
+ var _a;
3153
+ return (_a = this.tokens.hashConst.leadingTrivia) !== null && _a !== void 0 ? _a : [];
3154
+ }
3155
+ clone() {
3156
+ var _a;
3157
+ return this.finalizeClone(new ConditionalCompileConstStatement({
3158
+ hashConst: util_1.util.cloneToken(this.tokens.hashConst),
3159
+ assignment: (_a = this.assignment) === null || _a === void 0 ? void 0 : _a.clone()
3160
+ }), ['assignment']);
3161
+ }
3162
+ }
3163
+ exports.ConditionalCompileConstStatement = ConditionalCompileConstStatement;
3164
+ class TypeStatement extends AstNode_1.Statement {
3165
+ constructor(options) {
3166
+ super();
3167
+ this.kind = AstNode_1.AstNodeKind.TypeStatement;
3168
+ this.tokens = {
3169
+ type: options.type,
3170
+ name: options.name,
3171
+ equals: options.equals
3172
+ };
3173
+ this.value = options.value;
3174
+ this.location = util_1.util.createBoundingLocation(this.tokens.type, this.tokens.name, this.tokens.equals, this.value);
3175
+ }
3176
+ transpile(state) {
3177
+ //transpile to a comment just for debugging purposes
3178
+ return [
3179
+ state.transpileToken(this.tokens.type, 'type', true),
3180
+ ' ',
3181
+ state.transpileToken(this.tokens.name),
3182
+ ' ',
3183
+ state.transpileToken(this.tokens.equals, '='),
3184
+ ' ',
3185
+ this.value.transpile(state)
3186
+ ];
3187
+ }
3188
+ walk(visitor, options) {
3189
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
3190
+ (0, visitors_1.walk)(this, 'value', visitor, options);
3191
+ }
3192
+ }
3193
+ get leadingTrivia() {
3194
+ var _a, _b;
3195
+ return (_b = (_a = this.tokens.type) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
3196
+ }
3197
+ getType(options) {
3198
+ return this.value.getType(options);
3199
+ }
3200
+ clone() {
3201
+ var _a;
3202
+ return this.finalizeClone(new TypeStatement({
3203
+ type: util_1.util.cloneToken(this.tokens.type),
3204
+ name: util_1.util.cloneToken(this.tokens.name),
3205
+ equals: util_1.util.cloneToken(this.tokens.equals),
3206
+ value: (_a = this.value) === null || _a === void 0 ? void 0 : _a.clone()
3207
+ }), ['value']);
3208
+ }
3209
+ }
3210
+ exports.TypeStatement = TypeStatement;
1424
3211
  //# sourceMappingURL=Statement.js.map