brighterscript 1.0.0-alpha.5 → 1.0.0-alpha.51

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