brighterscript 1.0.0-alpha.4 → 1.0.0-alpha.40

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