brighterscript 1.0.0-alpha.3 → 1.0.0-alpha.31

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 (608) hide show
  1. package/CHANGELOG.md +1249 -285
  2. package/README.md +61 -131
  3. package/bsconfig.schema.json +68 -2
  4. package/dist/ActionPipeline.d.ts +10 -0
  5. package/dist/ActionPipeline.js +40 -0
  6. package/dist/ActionPipeline.js.map +1 -0
  7. package/dist/AstValidationSegmenter.d.ts +42 -0
  8. package/dist/AstValidationSegmenter.js +232 -0
  9. package/dist/AstValidationSegmenter.js.map +1 -0
  10. package/dist/BsConfig.d.ts +51 -6
  11. package/dist/BusyStatusTracker.d.ts +31 -0
  12. package/dist/BusyStatusTracker.js +83 -0
  13. package/dist/BusyStatusTracker.js.map +1 -0
  14. package/dist/Cache.d.ts +5 -6
  15. package/dist/Cache.js +12 -11
  16. package/dist/Cache.js.map +1 -1
  17. package/dist/CacheVerifier.d.ts +7 -0
  18. package/dist/CacheVerifier.js +20 -0
  19. package/dist/CacheVerifier.js.map +1 -0
  20. package/dist/CodeActionUtil.d.ts +11 -2
  21. package/dist/CodeActionUtil.js +17 -3
  22. package/dist/CodeActionUtil.js.map +1 -1
  23. package/dist/CommentFlagProcessor.d.ts +7 -6
  24. package/dist/CommentFlagProcessor.js +10 -7
  25. package/dist/CommentFlagProcessor.js.map +1 -1
  26. package/dist/CrossScopeValidator.d.ts +67 -0
  27. package/dist/CrossScopeValidator.js +625 -0
  28. package/dist/CrossScopeValidator.js.map +1 -0
  29. package/dist/DependencyGraph.d.ts +8 -3
  30. package/dist/DependencyGraph.js +49 -16
  31. package/dist/DependencyGraph.js.map +1 -1
  32. package/dist/DiagnosticCollection.d.ts +5 -3
  33. package/dist/DiagnosticCollection.js +18 -16
  34. package/dist/DiagnosticCollection.js.map +1 -1
  35. package/dist/DiagnosticFilterer.d.ts +8 -4
  36. package/dist/DiagnosticFilterer.js +77 -44
  37. package/dist/DiagnosticFilterer.js.map +1 -1
  38. package/dist/DiagnosticManager.d.ts +56 -0
  39. package/dist/DiagnosticManager.js +218 -0
  40. package/dist/DiagnosticManager.js.map +1 -0
  41. package/dist/DiagnosticMessages.d.ts +187 -20
  42. package/dist/DiagnosticMessages.js +247 -29
  43. package/dist/DiagnosticMessages.js.map +1 -1
  44. package/dist/DiagnosticSeverityAdjuster.d.ts +7 -0
  45. package/dist/DiagnosticSeverityAdjuster.js +41 -0
  46. package/dist/DiagnosticSeverityAdjuster.js.map +1 -0
  47. package/dist/FunctionScope.d.ts +28 -0
  48. package/dist/FunctionScope.js +52 -0
  49. package/dist/FunctionScope.js.map +1 -0
  50. package/dist/KeyedThrottler.d.ts +3 -3
  51. package/dist/KeyedThrottler.js +3 -3
  52. package/dist/KeyedThrottler.js.map +1 -1
  53. package/dist/LanguageServer.d.ts +72 -47
  54. package/dist/LanguageServer.js +544 -312
  55. package/dist/LanguageServer.js.map +1 -1
  56. package/dist/Logger.d.ts +9 -10
  57. package/dist/Logger.js +36 -30
  58. package/dist/Logger.js.map +1 -1
  59. package/dist/PluginInterface.d.ts +29 -7
  60. package/dist/PluginInterface.js +90 -7
  61. package/dist/PluginInterface.js.map +1 -1
  62. package/dist/Program.d.ts +199 -100
  63. package/dist/Program.js +1056 -700
  64. package/dist/Program.js.map +1 -1
  65. package/dist/ProgramBuilder.d.ts +29 -18
  66. package/dist/ProgramBuilder.js +170 -132
  67. package/dist/ProgramBuilder.js.map +1 -1
  68. package/dist/Scope.d.ts +144 -109
  69. package/dist/Scope.js +533 -552
  70. package/dist/Scope.js.map +1 -1
  71. package/dist/SemanticTokenUtils.d.ts +14 -0
  72. package/dist/SemanticTokenUtils.js +85 -0
  73. package/dist/SemanticTokenUtils.js.map +1 -0
  74. package/dist/Stopwatch.d.ts +4 -0
  75. package/dist/Stopwatch.js +8 -1
  76. package/dist/Stopwatch.js.map +1 -1
  77. package/dist/SymbolTable.d.ts +91 -24
  78. package/dist/SymbolTable.js +290 -64
  79. package/dist/SymbolTable.js.map +1 -1
  80. package/dist/SymbolTypeFlag.d.ts +9 -0
  81. package/dist/SymbolTypeFlag.js +14 -0
  82. package/dist/SymbolTypeFlag.js.map +1 -0
  83. package/dist/Throttler.d.ts +12 -0
  84. package/dist/Throttler.js +39 -0
  85. package/dist/Throttler.js.map +1 -1
  86. package/dist/Watcher.d.ts +0 -3
  87. package/dist/Watcher.js +0 -3
  88. package/dist/Watcher.js.map +1 -1
  89. package/dist/XmlScope.d.ts +5 -15
  90. package/dist/XmlScope.js +35 -87
  91. package/dist/XmlScope.js.map +1 -1
  92. package/dist/astUtils/CachedLookups.d.ts +50 -0
  93. package/dist/astUtils/CachedLookups.js +331 -0
  94. package/dist/astUtils/CachedLookups.js.map +1 -0
  95. package/dist/astUtils/Editor.d.ts +69 -0
  96. package/dist/astUtils/Editor.js +245 -0
  97. package/dist/astUtils/Editor.js.map +1 -0
  98. package/dist/astUtils/Editor.spec.js +258 -0
  99. package/dist/astUtils/Editor.spec.js.map +1 -0
  100. package/dist/astUtils/creators.d.ts +33 -10
  101. package/dist/astUtils/creators.js +224 -30
  102. package/dist/astUtils/creators.js.map +1 -1
  103. package/dist/astUtils/creators.spec.js +5 -5
  104. package/dist/astUtils/creators.spec.js.map +1 -1
  105. package/dist/astUtils/reflection.d.ts +146 -82
  106. package/dist/astUtils/reflection.js +308 -132
  107. package/dist/astUtils/reflection.js.map +1 -1
  108. package/dist/astUtils/reflection.spec.js +267 -162
  109. package/dist/astUtils/reflection.spec.js.map +1 -1
  110. package/dist/astUtils/stackedVisitor.js.map +1 -1
  111. package/dist/astUtils/stackedVisitor.spec.js +14 -14
  112. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  113. package/dist/astUtils/visitors.d.ts +115 -53
  114. package/dist/astUtils/visitors.js +70 -13
  115. package/dist/astUtils/visitors.js.map +1 -1
  116. package/dist/astUtils/visitors.spec.js +465 -51
  117. package/dist/astUtils/visitors.spec.js.map +1 -1
  118. package/dist/astUtils/xml.d.ts +9 -8
  119. package/dist/astUtils/xml.js +10 -5
  120. package/dist/astUtils/xml.js.map +1 -1
  121. package/dist/bscPlugin/BscPlugin.d.ts +22 -1
  122. package/dist/bscPlugin/BscPlugin.js +88 -0
  123. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  124. package/dist/bscPlugin/CallExpressionInfo.d.ts +36 -0
  125. package/dist/bscPlugin/CallExpressionInfo.js +131 -0
  126. package/dist/bscPlugin/CallExpressionInfo.js.map +1 -0
  127. package/dist/bscPlugin/FileWriter.d.ts +6 -0
  128. package/dist/bscPlugin/FileWriter.js +24 -0
  129. package/dist/bscPlugin/FileWriter.js.map +1 -0
  130. package/dist/bscPlugin/SignatureHelpUtil.d.ts +10 -0
  131. package/dist/bscPlugin/SignatureHelpUtil.js +137 -0
  132. package/dist/bscPlugin/SignatureHelpUtil.js.map +1 -0
  133. package/dist/bscPlugin/codeActions/CodeActionsProcessor.d.ts +1 -1
  134. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +26 -17
  135. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  136. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +94 -20
  137. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  138. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +60 -0
  139. package/dist/bscPlugin/completions/CompletionsProcessor.js +601 -0
  140. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -0
  141. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +2139 -0
  142. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +1 -0
  143. package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
  144. package/dist/bscPlugin/definition/DefinitionProvider.js +210 -0
  145. package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
  146. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +88 -0
  147. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
  148. package/dist/bscPlugin/fileProviders/FileProvider.d.ts +9 -0
  149. package/dist/bscPlugin/fileProviders/FileProvider.js +51 -0
  150. package/dist/bscPlugin/fileProviders/FileProvider.js.map +1 -0
  151. package/dist/bscPlugin/hover/HoverProcessor.d.ts +18 -0
  152. package/dist/bscPlugin/hover/HoverProcessor.js +218 -0
  153. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -0
  154. package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +1 -0
  155. package/dist/bscPlugin/hover/HoverProcessor.spec.js +737 -0
  156. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -0
  157. package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
  158. package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
  159. package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
  160. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +1 -0
  161. package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
  162. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
  163. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +14 -0
  164. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +144 -0
  165. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
  166. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
  167. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +504 -0
  168. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
  169. package/dist/bscPlugin/serialize/BslibInjector.spec.d.ts +1 -0
  170. package/dist/bscPlugin/serialize/BslibInjector.spec.js +19 -0
  171. package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +1 -0
  172. package/dist/bscPlugin/serialize/BslibManager.d.ts +9 -0
  173. package/dist/bscPlugin/serialize/BslibManager.js +40 -0
  174. package/dist/bscPlugin/serialize/BslibManager.js.map +1 -0
  175. package/dist/bscPlugin/serialize/FileSerializer.d.ts +9 -0
  176. package/dist/bscPlugin/serialize/FileSerializer.js +72 -0
  177. package/dist/bscPlugin/serialize/FileSerializer.js.map +1 -0
  178. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.d.ts +7 -0
  179. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js +22 -0
  180. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js.map +1 -0
  181. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +1 -0
  182. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +291 -0
  183. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +1 -0
  184. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.d.ts +7 -0
  185. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js +26 -0
  186. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js.map +1 -0
  187. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +1 -0
  188. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +245 -0
  189. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +1 -0
  190. package/dist/bscPlugin/symbols/symbolUtils.d.ts +5 -0
  191. package/dist/bscPlugin/symbols/symbolUtils.js +140 -0
  192. package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -0
  193. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.d.ts +21 -0
  194. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js +199 -0
  195. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +1 -0
  196. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.d.ts +1 -0
  197. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +41 -0
  198. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +1 -0
  199. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +12 -0
  200. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +99 -0
  201. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +1 -0
  202. package/dist/bscPlugin/validation/BrsFileAfterValidator.d.ts +7 -0
  203. package/dist/bscPlugin/validation/BrsFileAfterValidator.js +18 -0
  204. package/dist/bscPlugin/validation/BrsFileAfterValidator.js.map +1 -0
  205. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +34 -0
  206. package/dist/bscPlugin/validation/BrsFileValidator.js +462 -0
  207. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
  208. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +1 -0
  209. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +758 -0
  210. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -0
  211. package/dist/bscPlugin/validation/ProgramValidator.d.ts +11 -0
  212. package/dist/bscPlugin/validation/ProgramValidator.js +33 -0
  213. package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -0
  214. package/dist/bscPlugin/validation/ScopeValidator.d.ts +123 -0
  215. package/dist/bscPlugin/validation/ScopeValidator.js +1026 -0
  216. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
  217. package/dist/bscPlugin/validation/ScopeValidator.spec.d.ts +1 -0
  218. package/dist/bscPlugin/validation/ScopeValidator.spec.js +2897 -0
  219. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +1 -0
  220. package/dist/bscPlugin/validation/XmlFileValidator.d.ts +8 -0
  221. package/dist/bscPlugin/validation/XmlFileValidator.js +44 -0
  222. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -0
  223. package/dist/cli.js +117 -11
  224. package/dist/cli.js.map +1 -1
  225. package/dist/deferred.d.ts +3 -3
  226. package/dist/deferred.js.map +1 -1
  227. package/dist/diagnosticUtils.d.ts +10 -3
  228. package/dist/diagnosticUtils.js +58 -21
  229. package/dist/diagnosticUtils.js.map +1 -1
  230. package/dist/examples/plugins/removePrint.js +8 -12
  231. package/dist/examples/plugins/removePrint.js.map +1 -1
  232. package/dist/files/AssetFile.d.ts +24 -0
  233. package/dist/files/AssetFile.js +25 -0
  234. package/dist/files/AssetFile.js.map +1 -0
  235. package/dist/files/BrsFile.Class.spec.js +858 -153
  236. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  237. package/dist/files/BrsFile.d.ts +147 -82
  238. package/dist/files/BrsFile.js +853 -911
  239. package/dist/files/BrsFile.js.map +1 -1
  240. package/dist/files/BrsFile.spec.js +3056 -836
  241. package/dist/files/BrsFile.spec.js.map +1 -1
  242. package/dist/files/BscFile.d.ts +101 -0
  243. package/dist/files/BscFile.js +15 -0
  244. package/dist/files/BscFile.js.map +1 -0
  245. package/dist/files/Factory.d.ts +25 -0
  246. package/dist/files/Factory.js +22 -0
  247. package/dist/files/Factory.js.map +1 -0
  248. package/dist/files/LazyFileData.d.ts +20 -0
  249. package/dist/files/LazyFileData.js +54 -0
  250. package/dist/files/LazyFileData.js.map +1 -0
  251. package/dist/files/LazyFileData.spec.d.ts +1 -0
  252. package/dist/files/LazyFileData.spec.js +27 -0
  253. package/dist/files/LazyFileData.spec.js.map +1 -0
  254. package/dist/files/XmlFile.d.ts +73 -41
  255. package/dist/files/XmlFile.js +126 -138
  256. package/dist/files/XmlFile.js.map +1 -1
  257. package/dist/files/XmlFile.spec.js +450 -318
  258. package/dist/files/XmlFile.spec.js.map +1 -1
  259. package/dist/files/tests/imports.spec.js +62 -52
  260. package/dist/files/tests/imports.spec.js.map +1 -1
  261. package/dist/files/tests/optionalChaning.spec.d.ts +1 -0
  262. package/dist/files/tests/optionalChaning.spec.js +152 -0
  263. package/dist/files/tests/optionalChaning.spec.js.map +1 -0
  264. package/dist/globalCallables.d.ts +3 -1
  265. package/dist/globalCallables.js +416 -162
  266. package/dist/globalCallables.js.map +1 -1
  267. package/dist/index.d.ts +25 -3
  268. package/dist/index.js +42 -5
  269. package/dist/index.js.map +1 -1
  270. package/dist/interfaces.d.ts +717 -119
  271. package/dist/interfaces.js +21 -0
  272. package/dist/interfaces.js.map +1 -1
  273. package/dist/lexer/Character.spec.js +5 -5
  274. package/dist/lexer/Character.spec.js.map +1 -1
  275. package/dist/lexer/Lexer.d.ts +40 -9
  276. package/dist/lexer/Lexer.js +191 -49
  277. package/dist/lexer/Lexer.js.map +1 -1
  278. package/dist/lexer/Lexer.spec.js +775 -563
  279. package/dist/lexer/Lexer.spec.js.map +1 -1
  280. package/dist/lexer/Token.d.ts +11 -3
  281. package/dist/lexer/Token.js +10 -2
  282. package/dist/lexer/Token.js.map +1 -1
  283. package/dist/lexer/TokenKind.d.ts +27 -1
  284. package/dist/lexer/TokenKind.js +112 -5
  285. package/dist/lexer/TokenKind.js.map +1 -1
  286. package/dist/logging.d.ts +9 -0
  287. package/dist/logging.js +16 -0
  288. package/dist/logging.js.map +1 -0
  289. package/dist/parser/AstNode.d.ts +181 -0
  290. package/dist/parser/AstNode.js +246 -0
  291. package/dist/parser/AstNode.js.map +1 -0
  292. package/dist/parser/AstNode.spec.d.ts +1 -0
  293. package/dist/parser/AstNode.spec.js +165 -0
  294. package/dist/parser/AstNode.spec.js.map +1 -0
  295. package/dist/parser/BrsTranspileState.d.ts +12 -2
  296. package/dist/parser/BrsTranspileState.js +6 -0
  297. package/dist/parser/BrsTranspileState.js.map +1 -1
  298. package/dist/parser/Expression.d.ts +454 -210
  299. package/dist/parser/Expression.js +953 -498
  300. package/dist/parser/Expression.js.map +1 -1
  301. package/dist/parser/Parser.Class.spec.js +200 -95
  302. package/dist/parser/Parser.Class.spec.js.map +1 -1
  303. package/dist/parser/Parser.d.ts +106 -120
  304. package/dist/parser/Parser.js +1432 -931
  305. package/dist/parser/Parser.js.map +1 -1
  306. package/dist/parser/Parser.spec.d.ts +3 -1
  307. package/dist/parser/Parser.spec.js +1383 -456
  308. package/dist/parser/Parser.spec.js.map +1 -1
  309. package/dist/parser/SGParser.d.ts +44 -6
  310. package/dist/parser/SGParser.js +212 -185
  311. package/dist/parser/SGParser.js.map +1 -1
  312. package/dist/parser/SGParser.spec.js +30 -28
  313. package/dist/parser/SGParser.spec.js.map +1 -1
  314. package/dist/parser/SGTypes.d.ts +293 -50
  315. package/dist/parser/SGTypes.js +540 -187
  316. package/dist/parser/SGTypes.js.map +1 -1
  317. package/dist/parser/Statement.d.ts +759 -247
  318. package/dist/parser/Statement.js +1785 -607
  319. package/dist/parser/Statement.js.map +1 -1
  320. package/dist/parser/Statement.spec.js +45 -34
  321. package/dist/parser/Statement.spec.js.map +1 -1
  322. package/dist/parser/TranspileState.d.ts +18 -8
  323. package/dist/parser/TranspileState.js +76 -12
  324. package/dist/parser/TranspileState.js.map +1 -1
  325. package/dist/parser/tests/Parser.spec.d.ts +10 -9
  326. package/dist/parser/tests/Parser.spec.js +18 -14
  327. package/dist/parser/tests/Parser.spec.js.map +1 -1
  328. package/dist/parser/tests/controlFlow/For.spec.js +79 -69
  329. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  330. package/dist/parser/tests/controlFlow/ForEach.spec.js +53 -47
  331. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  332. package/dist/parser/tests/controlFlow/If.spec.js +217 -196
  333. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  334. package/dist/parser/tests/controlFlow/While.spec.js +48 -42
  335. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  336. package/dist/parser/tests/expression/Additive.spec.js +31 -31
  337. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  338. package/dist/parser/tests/expression/ArrayLiterals.spec.js +157 -120
  339. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  340. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +202 -139
  341. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  342. package/dist/parser/tests/expression/Boolean.spec.js +25 -25
  343. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  344. package/dist/parser/tests/expression/Call.spec.js +150 -41
  345. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  346. package/dist/parser/tests/expression/Exponential.spec.js +18 -18
  347. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  348. package/dist/parser/tests/expression/Function.spec.js +257 -257
  349. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  350. package/dist/parser/tests/expression/Indexing.spec.js +160 -90
  351. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  352. package/dist/parser/tests/expression/Multiplicative.spec.js +38 -38
  353. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  354. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +196 -98
  355. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  356. package/dist/parser/tests/expression/PrefixUnary.spec.js +42 -42
  357. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  358. package/dist/parser/tests/expression/Primary.spec.js +42 -42
  359. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  360. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
  361. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +171 -0
  362. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
  363. package/dist/parser/tests/expression/Relational.spec.js +44 -44
  364. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  365. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +31 -31
  366. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  367. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +230 -90
  368. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  369. package/dist/parser/tests/expression/TernaryExpression.spec.js +377 -148
  370. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  371. package/dist/parser/tests/expression/TypeExpression.spec.d.ts +1 -0
  372. package/dist/parser/tests/expression/TypeExpression.spec.js +126 -0
  373. package/dist/parser/tests/expression/TypeExpression.spec.js.map +1 -0
  374. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +1 -0
  375. package/dist/parser/tests/expression/UnaryExpression.spec.js +52 -0
  376. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -0
  377. package/dist/parser/tests/statement/AssignmentOperators.spec.js +37 -37
  378. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  379. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +1 -0
  380. package/dist/parser/tests/statement/ConstStatement.spec.js +262 -0
  381. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -0
  382. package/dist/parser/tests/statement/Continue.spec.d.ts +1 -0
  383. package/dist/parser/tests/statement/Continue.spec.js +119 -0
  384. package/dist/parser/tests/statement/Continue.spec.js.map +1 -0
  385. package/dist/parser/tests/statement/Declaration.spec.js +45 -45
  386. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  387. package/dist/parser/tests/statement/Dim.spec.js +22 -22
  388. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  389. package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
  390. package/dist/parser/tests/statement/Enum.spec.js +745 -0
  391. package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
  392. package/dist/parser/tests/statement/For.spec.d.ts +1 -0
  393. package/dist/parser/tests/statement/For.spec.js +45 -0
  394. package/dist/parser/tests/statement/For.spec.js.map +1 -0
  395. package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
  396. package/dist/parser/tests/statement/ForEach.spec.js +36 -0
  397. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
  398. package/dist/parser/tests/statement/Function.spec.js +208 -198
  399. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  400. package/dist/parser/tests/statement/Goto.spec.js +16 -15
  401. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  402. package/dist/parser/tests/statement/Increment.spec.js +51 -51
  403. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  404. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
  405. package/dist/parser/tests/statement/InterfaceStatement.spec.js +110 -0
  406. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
  407. package/dist/parser/tests/statement/LibraryStatement.spec.js +18 -18
  408. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  409. package/dist/parser/tests/statement/Misc.spec.js +123 -163
  410. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  411. package/dist/parser/tests/statement/PrintStatement.spec.js +125 -108
  412. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  413. package/dist/parser/tests/statement/ReturnStatement.spec.js +51 -49
  414. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  415. package/dist/parser/tests/statement/Set.spec.js +110 -97
  416. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  417. package/dist/parser/tests/statement/Stop.spec.js +13 -12
  418. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  419. package/dist/parser/tests/statement/Throw.spec.js +6 -6
  420. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  421. package/dist/parser/tests/statement/TryCatch.spec.js +26 -15
  422. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  423. package/dist/preprocessor/Manifest.d.ts +6 -6
  424. package/dist/preprocessor/Manifest.js +17 -38
  425. package/dist/preprocessor/Manifest.js.map +1 -1
  426. package/dist/preprocessor/Manifest.spec.d.ts +1 -0
  427. package/dist/preprocessor/Manifest.spec.js +78 -103
  428. package/dist/preprocessor/Manifest.spec.js.map +1 -1
  429. package/dist/roku-types/data.json +19369 -0
  430. package/dist/roku-types/index.d.ts +5497 -0
  431. package/dist/roku-types/index.js +11 -0
  432. package/dist/roku-types/index.js.map +1 -0
  433. package/dist/types/ArrayType.d.ts +9 -5
  434. package/dist/types/ArrayType.js +68 -24
  435. package/dist/types/ArrayType.js.map +1 -1
  436. package/dist/types/ArrayType.spec.js +39 -11
  437. package/dist/types/ArrayType.spec.js.map +1 -1
  438. package/dist/types/AssociativeArrayType.d.ts +14 -0
  439. package/dist/types/AssociativeArrayType.js +60 -0
  440. package/dist/types/AssociativeArrayType.js.map +1 -0
  441. package/dist/types/BaseFunctionType.d.ts +9 -0
  442. package/dist/types/BaseFunctionType.js +25 -0
  443. package/dist/types/BaseFunctionType.js.map +1 -0
  444. package/dist/types/BooleanType.d.ts +10 -5
  445. package/dist/types/BooleanType.js +21 -9
  446. package/dist/types/BooleanType.js.map +1 -1
  447. package/dist/types/BooleanType.spec.js +10 -4
  448. package/dist/types/BooleanType.spec.js.map +1 -1
  449. package/dist/types/BscType.d.ts +29 -3
  450. package/dist/types/BscType.js +121 -0
  451. package/dist/types/BscType.js.map +1 -1
  452. package/dist/types/BscTypeKind.d.ts +25 -0
  453. package/dist/types/BscTypeKind.js +30 -0
  454. package/dist/types/BscTypeKind.js.map +1 -0
  455. package/dist/types/BuiltInInterfaceAdder.d.ts +25 -0
  456. package/dist/types/BuiltInInterfaceAdder.js +201 -0
  457. package/dist/types/BuiltInInterfaceAdder.js.map +1 -0
  458. package/dist/types/BuiltInInterfaceAdder.spec.d.ts +1 -0
  459. package/dist/types/BuiltInInterfaceAdder.spec.js +115 -0
  460. package/dist/types/BuiltInInterfaceAdder.spec.js.map +1 -0
  461. package/dist/types/ClassType.d.ts +16 -0
  462. package/dist/types/ClassType.js +57 -0
  463. package/dist/types/ClassType.js.map +1 -0
  464. package/dist/types/ClassType.spec.d.ts +1 -0
  465. package/dist/types/ClassType.spec.js +76 -0
  466. package/dist/types/ClassType.spec.js.map +1 -0
  467. package/dist/types/ComponentType.d.ts +27 -0
  468. package/dist/types/ComponentType.js +83 -0
  469. package/dist/types/ComponentType.js.map +1 -0
  470. package/dist/types/DoubleType.d.ts +10 -5
  471. package/dist/types/DoubleType.js +25 -18
  472. package/dist/types/DoubleType.js.map +1 -1
  473. package/dist/types/DoubleType.spec.js +12 -4
  474. package/dist/types/DoubleType.spec.js.map +1 -1
  475. package/dist/types/DynamicType.d.ts +12 -5
  476. package/dist/types/DynamicType.js +22 -6
  477. package/dist/types/DynamicType.js.map +1 -1
  478. package/dist/types/DynamicType.spec.js +16 -5
  479. package/dist/types/DynamicType.spec.js.map +1 -1
  480. package/dist/types/EnumType.d.ts +40 -0
  481. package/dist/types/EnumType.js +80 -0
  482. package/dist/types/EnumType.js.map +1 -0
  483. package/dist/types/EnumType.spec.d.ts +1 -0
  484. package/dist/types/EnumType.spec.js +33 -0
  485. package/dist/types/EnumType.spec.js.map +1 -0
  486. package/dist/types/FloatType.d.ts +10 -5
  487. package/dist/types/FloatType.js +25 -18
  488. package/dist/types/FloatType.js.map +1 -1
  489. package/dist/types/FloatType.spec.js +4 -4
  490. package/dist/types/FloatType.spec.js.map +1 -1
  491. package/dist/types/FunctionType.d.ts +10 -22
  492. package/dist/types/FunctionType.js +26 -63
  493. package/dist/types/FunctionType.js.map +1 -1
  494. package/dist/types/InheritableType.d.ts +28 -0
  495. package/dist/types/InheritableType.js +157 -0
  496. package/dist/types/InheritableType.js.map +1 -0
  497. package/dist/types/IntegerType.d.ts +10 -5
  498. package/dist/types/IntegerType.js +25 -18
  499. package/dist/types/IntegerType.js.map +1 -1
  500. package/dist/types/IntegerType.spec.js +8 -4
  501. package/dist/types/IntegerType.spec.js.map +1 -1
  502. package/dist/types/InterfaceType.d.ts +14 -6
  503. package/dist/types/InterfaceType.js +26 -15
  504. package/dist/types/InterfaceType.js.map +1 -1
  505. package/dist/types/InterfaceType.spec.d.ts +1 -0
  506. package/dist/types/InterfaceType.spec.js +227 -0
  507. package/dist/types/InterfaceType.spec.js.map +1 -0
  508. package/dist/types/InvalidType.d.ts +9 -5
  509. package/dist/types/InvalidType.js +20 -9
  510. package/dist/types/InvalidType.js.map +1 -1
  511. package/dist/types/InvalidType.spec.js +8 -4
  512. package/dist/types/InvalidType.spec.js.map +1 -1
  513. package/dist/types/LongIntegerType.d.ts +10 -5
  514. package/dist/types/LongIntegerType.js +25 -18
  515. package/dist/types/LongIntegerType.js.map +1 -1
  516. package/dist/types/LongIntegerType.spec.js +10 -4
  517. package/dist/types/LongIntegerType.spec.js.map +1 -1
  518. package/dist/types/NamespaceType.d.ts +12 -0
  519. package/dist/types/NamespaceType.js +28 -0
  520. package/dist/types/NamespaceType.js.map +1 -0
  521. package/dist/types/ObjectType.d.ts +10 -5
  522. package/dist/types/ObjectType.js +23 -9
  523. package/dist/types/ObjectType.js.map +1 -1
  524. package/dist/types/ObjectType.spec.js +3 -3
  525. package/dist/types/ObjectType.spec.js.map +1 -1
  526. package/dist/types/ReferenceType.d.ts +79 -0
  527. package/dist/types/ReferenceType.js +522 -0
  528. package/dist/types/ReferenceType.js.map +1 -0
  529. package/dist/types/ReferenceType.spec.d.ts +1 -0
  530. package/dist/types/ReferenceType.spec.js +151 -0
  531. package/dist/types/ReferenceType.spec.js.map +1 -0
  532. package/dist/types/StringType.d.ts +13 -5
  533. package/dist/types/StringType.js +25 -9
  534. package/dist/types/StringType.js.map +1 -1
  535. package/dist/types/StringType.spec.js +3 -3
  536. package/dist/types/StringType.spec.js.map +1 -1
  537. package/dist/types/TypedFunctionType.d.ts +33 -0
  538. package/dist/types/TypedFunctionType.js +106 -0
  539. package/dist/types/TypedFunctionType.js.map +1 -0
  540. package/dist/types/TypedFunctionType.spec.d.ts +1 -0
  541. package/dist/types/TypedFunctionType.spec.js +122 -0
  542. package/dist/types/TypedFunctionType.spec.js.map +1 -0
  543. package/dist/types/UninitializedType.d.ts +8 -6
  544. package/dist/types/UninitializedType.js +15 -9
  545. package/dist/types/UninitializedType.js.map +1 -1
  546. package/dist/types/UnionType.d.ts +20 -0
  547. package/dist/types/UnionType.js +127 -0
  548. package/dist/types/UnionType.js.map +1 -0
  549. package/dist/types/UnionType.spec.d.ts +1 -0
  550. package/dist/types/UnionType.spec.js +129 -0
  551. package/dist/types/UnionType.spec.js.map +1 -0
  552. package/dist/types/VoidType.d.ts +10 -5
  553. package/dist/types/VoidType.js +20 -9
  554. package/dist/types/VoidType.js.map +1 -1
  555. package/dist/types/VoidType.spec.js +3 -3
  556. package/dist/types/VoidType.spec.js.map +1 -1
  557. package/dist/types/helper.spec.d.ts +1 -0
  558. package/dist/types/helper.spec.js +144 -0
  559. package/dist/types/helper.spec.js.map +1 -0
  560. package/dist/types/helpers.d.ts +26 -0
  561. package/dist/types/helpers.js +191 -0
  562. package/dist/types/helpers.js.map +1 -0
  563. package/dist/types/index.d.ts +22 -0
  564. package/dist/types/index.js +39 -0
  565. package/dist/types/index.js.map +1 -0
  566. package/dist/util.d.ts +218 -106
  567. package/dist/util.js +1310 -320
  568. package/dist/util.js.map +1 -1
  569. package/dist/validators/ClassValidator.d.ts +9 -15
  570. package/dist/validators/ClassValidator.js +81 -134
  571. package/dist/validators/ClassValidator.js.map +1 -1
  572. package/package.json +169 -138
  573. package/dist/astUtils/index.d.ts +0 -7
  574. package/dist/astUtils/index.js +0 -26
  575. package/dist/astUtils/index.js.map +0 -1
  576. package/dist/lexer/index.d.ts +0 -3
  577. package/dist/lexer/index.js +0 -17
  578. package/dist/lexer/index.js.map +0 -1
  579. package/dist/parser/index.d.ts +0 -3
  580. package/dist/parser/index.js +0 -16
  581. package/dist/parser/index.js.map +0 -1
  582. package/dist/preprocessor/Chunk.d.ts +0 -82
  583. package/dist/preprocessor/Chunk.js +0 -77
  584. package/dist/preprocessor/Chunk.js.map +0 -1
  585. package/dist/preprocessor/Preprocessor.d.ts +0 -60
  586. package/dist/preprocessor/Preprocessor.js +0 -156
  587. package/dist/preprocessor/Preprocessor.js.map +0 -1
  588. package/dist/preprocessor/Preprocessor.spec.js +0 -152
  589. package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
  590. package/dist/preprocessor/PreprocessorParser.d.ts +0 -61
  591. package/dist/preprocessor/PreprocessorParser.js +0 -194
  592. package/dist/preprocessor/PreprocessorParser.js.map +0 -1
  593. package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
  594. package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
  595. package/dist/preprocessor/index.d.ts +0 -3
  596. package/dist/preprocessor/index.js +0 -16
  597. package/dist/preprocessor/index.js.map +0 -1
  598. package/dist/types/CustomType.d.ts +0 -10
  599. package/dist/types/CustomType.js +0 -35
  600. package/dist/types/CustomType.js.map +0 -1
  601. package/dist/types/FunctionType.spec.js +0 -29
  602. package/dist/types/FunctionType.spec.js.map +0 -1
  603. package/dist/types/LazyType.d.ts +0 -15
  604. package/dist/types/LazyType.js +0 -32
  605. package/dist/types/LazyType.js.map +0 -1
  606. /package/dist/{preprocessor/Preprocessor.spec.d.ts → astUtils/Editor.spec.d.ts} +0 -0
  607. /package/dist/{preprocessor/PreprocessorParser.spec.d.ts → bscPlugin/completions/CompletionsProcessor.spec.d.ts} +0 -0
  608. /package/dist/{types/FunctionType.spec.d.ts → bscPlugin/definition/DefinitionProvider.spec.d.ts} +0 -0
@@ -1,64 +1,85 @@
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.TypedArrayExpression = exports.TypecastExpression = exports.TypeExpression = exports.RegexLiteralExpression = exports.NullCoalescingExpression = exports.TernaryExpression = exports.AnnotationExpression = exports.TaggedTemplateStringExpression = exports.TemplateStringExpression = exports.TemplateStringQuasiExpression = exports.CallfuncExpression = exports.NewExpression = exports.SourceLiteralExpression = exports.VariableExpression = exports.UnaryExpression = exports.AALiteralExpression = exports.AAMemberExpression = exports.ArrayLiteralExpression = exports.EscapedCharCodeLiteralExpression = exports.LiteralExpression = exports.GroupingExpression = exports.IndexedGetExpression = exports.XmlAttributeGetExpression = exports.DottedGetExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = void 0;
4
+ 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 creators_1 = require("../astUtils/creators");
23
+ const types_1 = require("../types");
13
24
  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) {
25
+ class BinaryExpression extends AstNode_1.Expression {
26
+ constructor(options) {
26
27
  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);
28
+ this.kind = AstNode_1.AstNodeKind.BinaryExpression;
29
+ this.tokens = {
30
+ operator: options.operator
31
+ };
32
+ this.left = options.left;
33
+ this.right = options.right;
34
+ this.range = util_1.default.createBoundingRange(this.left, this.tokens.operator, this.right);
31
35
  }
32
36
  transpile(state) {
33
37
  return [
34
38
  state.sourceNode(this.left, this.left.transpile(state)),
35
39
  ' ',
36
- state.transpileToken(this.operator),
40
+ state.transpileToken(this.tokens.operator),
37
41
  ' ',
38
42
  state.sourceNode(this.right, this.right.transpile(state))
39
43
  ];
40
44
  }
41
45
  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);
46
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
47
+ (0, visitors_2.walk)(this, 'left', visitor, options);
48
+ (0, visitors_2.walk)(this, 'right', visitor, options);
49
+ }
50
+ }
51
+ getType(options) {
52
+ const operatorKind = this.tokens.operator.kind;
53
+ if (options.flags & 2 /* SymbolTypeFlag.typetime */) {
54
+ // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
55
+ switch (operatorKind) {
56
+ case TokenKind_1.TokenKind.Or:
57
+ return new UnionType_1.UnionType([this.left.getType(options), this.right.getType(options)]);
58
+ //TODO: Intersection Types?, eg. case TokenKind.And:
59
+ }
60
+ }
61
+ else if (options.flags & 1 /* SymbolTypeFlag.runtime */) {
62
+ return util_1.default.binaryOperatorResultType(this.left.getType(options), this.tokens.operator, this.right.getType(options));
45
63
  }
64
+ return DynamicType_1.DynamicType.instance;
65
+ }
66
+ getLeadingTrivia() {
67
+ return this.left.getLeadingTrivia();
46
68
  }
47
69
  }
48
70
  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) {
71
+ class CallExpression extends AstNode_1.Expression {
72
+ constructor(options) {
73
+ var _a;
55
74
  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);
75
+ this.kind = AstNode_1.AstNodeKind.CallExpression;
76
+ this.tokens = {
77
+ openingParen: options.openingParen,
78
+ closingParen: options.closingParen
79
+ };
80
+ this.callee = options.callee;
81
+ this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
82
+ this.range = util_1.default.createBoundingRange(this.callee, this.tokens.openingParen, ...this.args, this.tokens.closingParen);
62
83
  }
63
84
  transpile(state, nameOverride) {
64
85
  let result = [];
@@ -69,7 +90,7 @@ class CallExpression extends Expression {
69
90
  else {
70
91
  result.push(...this.callee.transpile(state));
71
92
  }
72
- result.push(state.transpileToken(this.openingParen));
93
+ result.push(state.transpileToken(this.tokens.openingParen, '('));
73
94
  for (let i = 0; i < this.args.length; i++) {
74
95
  //add comma between args
75
96
  if (i > 0) {
@@ -78,80 +99,103 @@ class CallExpression extends Expression {
78
99
  let arg = this.args[i];
79
100
  result.push(...arg.transpile(state));
80
101
  }
81
- result.push(state.transpileToken(this.closingParen));
102
+ if (this.tokens.closingParen) {
103
+ result.push(state.transpileToken(this.tokens.closingParen));
104
+ }
82
105
  return result;
83
106
  }
84
107
  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);
89
- }
108
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
109
+ (0, visitors_2.walk)(this, 'callee', visitor, options);
110
+ (0, visitors_2.walkArray)(this.args, visitor, options, this);
111
+ }
112
+ }
113
+ getType(options) {
114
+ var _a, _b;
115
+ const calleeType = this.callee.getType(options);
116
+ if (options.ignoreCall) {
117
+ return calleeType;
118
+ }
119
+ if ((0, reflection_1.isNewExpression)(this.parent)) {
120
+ return calleeType;
121
+ }
122
+ const specialCaseReturnType = util_1.default.getSpecialCaseCallExpressionReturnType(this);
123
+ if (specialCaseReturnType) {
124
+ return specialCaseReturnType;
90
125
  }
126
+ if ((0, reflection_1.isCallableType)(calleeType) && (!(0, reflection_1.isReferenceType)(calleeType.returnType) || ((_a = calleeType.returnType) === null || _a === void 0 ? void 0 : _a.isResolvable()))) {
127
+ return calleeType.returnType;
128
+ }
129
+ if (!(0, reflection_1.isReferenceType)(calleeType) && ((_b = calleeType === null || calleeType === void 0 ? void 0 : calleeType.returnType) === null || _b === void 0 ? void 0 : _b.isResolvable())) {
130
+ return calleeType.returnType;
131
+ }
132
+ return new ReferenceType_1.TypePropertyReferenceType(calleeType, 'returnType');
133
+ }
134
+ getLeadingTrivia() {
135
+ return this.callee.getLeadingTrivia();
91
136
  }
92
137
  }
93
138
  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) {
139
+ /**
140
+ * Number of parameters that can be defined on a function
141
+ *
142
+ * Prior to Roku OS 11.5, this was 32
143
+ * As of Roku OS 11.5, this is 63
144
+ */
145
+ CallExpression.MaximumArguments = 63;
146
+ class FunctionExpression extends AstNode_1.Expression {
147
+ constructor(options) {
148
+ var _a;
101
149
  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);
150
+ this.kind = AstNode_1.AstNodeKind.FunctionExpression;
151
+ this.tokens = {
152
+ functionType: options.functionType,
153
+ leftParen: options.leftParen,
154
+ rightParen: options.rightParen,
155
+ as: options.as,
156
+ endFunctionType: options.endFunctionType
157
+ };
158
+ this.parameters = (_a = options.parameters) !== null && _a !== void 0 ? _a : [];
159
+ this.body = options.body;
160
+ this.returnTypeExpression = options.returnTypeExpression;
161
+ //if there's a body, and it doesn't have a SymbolTable, assign one
162
+ if (this.body) {
163
+ if (!this.body.symbolTable) {
164
+ this.body.symbolTable = new SymbolTable_1.SymbolTable(`Block`, () => this.getSymbolTable());
165
+ }
166
+ else {
167
+ this.body.symbolTable.pushParentProvider(() => this.getSymbolTable());
168
+ }
169
+ this.body.parent = this;
135
170
  }
171
+ this.symbolTable = new SymbolTable_1.SymbolTable('FunctionExpression', () => { var _a; return (_a = this.parent) === null || _a === void 0 ? void 0 : _a.getSymbolTable(); });
172
+ }
173
+ getLeadingTrivia() {
174
+ var _a, _b;
175
+ return (_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
176
+ }
177
+ getEndTrivia() {
178
+ var _a, _b;
179
+ return (_b = (_a = this.tokens.endFunctionType) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
136
180
  }
137
181
  /**
138
182
  * 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
183
  * and ending with the last n' in 'end function' or 'b' in 'end sub'
140
184
  */
141
185
  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);
186
+ return util_1.default.createBoundingRange(this.tokens.functionType, this.tokens.leftParen, ...this.parameters, this.tokens.rightParen, this.tokens.as, this.returnTypeExpression, this.tokens.endFunctionType);
144
187
  }
145
188
  transpile(state, name, includeBody = true) {
189
+ var _a, _b, _c;
146
190
  let results = [];
147
191
  //'function'|'sub'
148
- results.push(state.transpileToken(this.functionType));
192
+ results.push(state.transpileToken(this.tokens.functionType, 'function'));
149
193
  //functionName?
150
194
  if (name) {
151
195
  results.push(' ', state.transpileToken(name));
152
196
  }
153
197
  //leftParen
154
- results.push(state.transpileToken(this.leftParen));
198
+ results.push(state.transpileToken(this.tokens.leftParen));
155
199
  //parameters
156
200
  for (let i = 0; i < this.parameters.length; i++) {
157
201
  let param = this.parameters[i];
@@ -163,71 +207,130 @@ class FunctionExpression extends Expression {
163
207
  results.push(param.transpile(state));
164
208
  }
165
209
  //right paren
166
- results.push(state.transpileToken(this.rightParen));
210
+ results.push(state.transpileToken(this.tokens.rightParen));
167
211
  //as [Type]
168
- if (this.asToken) {
212
+ if (!state.options.removeParameterTypes && this.returnTypeExpression) {
169
213
  results.push(' ',
170
214
  //as
171
- state.transpileToken(this.asToken), ' ',
215
+ state.transpileToken(this.tokens.as, 'as'), ' ',
172
216
  //return type
173
- state.sourceNode(this.returnTypeToken, this.returnType.toTypeString()));
217
+ ...this.returnTypeExpression.transpile(state));
174
218
  }
219
+ let hasBody = false;
175
220
  if (includeBody) {
176
221
  state.lineage.unshift(this);
177
222
  let body = this.body.transpile(state);
223
+ hasBody = body.length > 0;
178
224
  state.lineage.shift();
179
225
  results.push(...body);
180
226
  }
181
- results.push('\n');
182
- //'end sub'|'end function'
183
- results.push(state.indent(), state.transpileToken(this.end));
227
+ 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;
228
+ results.push(...state.transpileEndBlockToken(lastLocatable, this.tokens.endFunctionType, `end ${(_c = this.tokens.functionType) !== null && _c !== void 0 ? _c : 'function'}`));
184
229
  return results;
185
230
  }
186
- getTypedef(state, name) {
187
- return this.transpile(state, name, false);
231
+ getTypedef(state) {
232
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
233
+ let results = [
234
+ new source_map_1.SourceNode(1, 0, null, [
235
+ //'function'|'sub'
236
+ (_b = (_a = this.tokens.functionType) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : 'function',
237
+ //functionName?
238
+ ...((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 : ''] : []),
239
+ //leftParen
240
+ '(',
241
+ //parameters
242
+ ...((_f = (_e = this.parameters) === null || _e === void 0 ? void 0 : _e.map((param, i) => ([
243
+ //separating comma
244
+ i > 0 ? ', ' : '',
245
+ ...param.getTypedef(state)
246
+ ]))) !== null && _f !== void 0 ? _f : []),
247
+ //right paren
248
+ ')',
249
+ //as <ReturnType>
250
+ ...(this.returnTypeExpression ? [
251
+ ' ',
252
+ (_h = (_g = this.tokens.as) === null || _g === void 0 ? void 0 : _g.text) !== null && _h !== void 0 ? _h : 'as',
253
+ ' ',
254
+ ...this.returnTypeExpression.getTypedef(state)
255
+ ] : []),
256
+ '\n',
257
+ state.indent(),
258
+ //'end sub'|'end function'
259
+ (_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'}`
260
+ ])
261
+ ];
262
+ return results;
188
263
  }
189
264
  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
- }
265
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
266
+ (0, visitors_2.walkArray)(this.parameters, visitor, options, this);
267
+ (0, visitors_2.walk)(this, 'returnTypeExpression', visitor, options);
194
268
  //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);
269
+ if (options.walkMode & visitors_2.InternalWalkMode.recurseChildFunctions) {
270
+ (0, visitors_2.walk)(this, 'body', visitor, options);
197
271
  }
198
272
  }
199
273
  }
200
- getFunctionType() {
201
- let functionType = new FunctionType_1.FunctionType(this.returnType);
202
- functionType.isSub = this.functionType.text === 'sub';
274
+ getType(options) {
275
+ var _a, _b, _c, _d;
276
+ //if there's a defined return type, use that
277
+ let returnType = (_a = this.returnTypeExpression) === null || _a === void 0 ? void 0 : _a.getType(Object.assign(Object.assign({}, options), { typeChain: undefined }));
278
+ const isSub = ((_b = this.tokens.functionType) === null || _b === void 0 ? void 0 : _b.kind) === TokenKind_1.TokenKind.Sub;
279
+ //if we don't have a return type and this is a sub, set the return type to `void`. else use `dynamic`
280
+ if (!returnType) {
281
+ returnType = isSub ? VoidType_1.VoidType.instance : DynamicType_1.DynamicType.instance;
282
+ }
283
+ const resultType = new types_1.TypedFunctionType(returnType);
284
+ resultType.isSub = isSub;
203
285
  for (let param of this.parameters) {
204
- functionType.addParameter(param.name.text, param.type, param.isOptional);
286
+ resultType.addParameter(param.tokens.name.text, param.getType(Object.assign(Object.assign({}, options), { typeChain: undefined })), !!param.defaultValue);
287
+ }
288
+ // Figure out this function's name if we can
289
+ let funcName = '';
290
+ if ((0, reflection_1.isMethodStatement)(this.parent) || (0, reflection_1.isInterfaceMethodStatement)(this.parent)) {
291
+ funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
292
+ if (options.typeChain) {
293
+ // Get the typechain info from the parent class
294
+ (_c = this.parent.parent) === null || _c === void 0 ? void 0 : _c.getType(options);
295
+ }
205
296
  }
206
- return functionType;
297
+ else if ((0, reflection_1.isFunctionStatement)(this.parent)) {
298
+ funcName = this.parent.getName(Parser_1.ParseMode.BrighterScript);
299
+ }
300
+ if (funcName) {
301
+ resultType.setName(funcName);
302
+ }
303
+ (_d = options.typeChain) === null || _d === void 0 ? void 0 : _d.push(new interfaces_1.TypeChainEntry({ name: funcName, type: resultType, data: options.data, astNode: this }));
304
+ return resultType;
207
305
  }
208
306
  }
209
307
  exports.FunctionExpression = FunctionExpression;
210
- class FunctionParameterExpression extends Expression {
211
- constructor(name, type, equalsToken, defaultValue, asToken, typeToken, namespaceName) {
308
+ class FunctionParameterExpression extends AstNode_1.Expression {
309
+ constructor(options) {
212
310
  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;
311
+ this.kind = AstNode_1.AstNodeKind.FunctionParameterExpression;
312
+ this.tokens = {
313
+ name: options.name,
314
+ equals: options.equals,
315
+ as: options.as
316
+ };
317
+ this.defaultValue = options.defaultValue;
318
+ this.typeExpression = options.typeExpression;
319
+ }
320
+ getType(options) {
321
+ var _a, _b, _c, _d, _e;
322
+ const paramType = (_d = (_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 : (_c = this.defaultValue) === null || _c === void 0 ? void 0 : _c.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */, typeChain: undefined }))) !== null && _d !== void 0 ? _d : DynamicType_1.DynamicType.instance;
323
+ (_e = options.typeChain) === null || _e === void 0 ? void 0 : _e.push(new interfaces_1.TypeChainEntry({ name: this.tokens.name.text, type: paramType, data: options.data, astNode: this }));
324
+ return paramType;
220
325
  }
221
326
  get range() {
222
- return {
223
- start: this.name.range.start,
224
- end: this.typeToken ? this.typeToken.range.end : this.name.range.end
225
- };
327
+ return util_1.default.createBoundingRange(this.tokens.name, this.tokens.as, this.typeExpression, this.tokens.equals, this.defaultValue);
226
328
  }
227
329
  transpile(state) {
330
+ var _a, _b;
228
331
  let result = [
229
332
  //name
230
- state.transpileToken(this.name)
333
+ state.transpileToken(this.tokens.name)
231
334
  ];
232
335
  //default value
233
336
  if (this.defaultValue) {
@@ -235,211 +338,271 @@ class FunctionParameterExpression extends Expression {
235
338
  result.push(this.defaultValue.transpile(state));
236
339
  }
237
340
  //type declaration
238
- if (this.asToken) {
341
+ if (this.typeExpression && !state.options.removeParameterTypes) {
239
342
  result.push(' ');
240
- result.push(state.transpileToken(this.asToken));
343
+ result.push(state.transpileToken(this.tokens.as, 'as'));
241
344
  result.push(' ');
242
- result.push(state.sourceNode(this.typeToken, this.type.toTypeString()));
345
+ result.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.transpile(state)) !== null && _b !== void 0 ? _b : []));
243
346
  }
244
347
  return result;
245
348
  }
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);
349
+ getTypedef(state) {
350
+ var _a, _b;
351
+ const results = [this.tokens.name.text];
352
+ if (this.defaultValue) {
353
+ results.push(' = ', ...this.defaultValue.transpile(state));
354
+ }
355
+ if (this.tokens.as) {
356
+ results.push(' as ');
357
+ // TODO: Is this conditional needed? Will typeToken always exist
358
+ // so long as `asToken` exists?
359
+ if (this.typeExpression) {
360
+ results.push(...((_b = (_a = this.typeExpression) === null || _a === void 0 ? void 0 : _a.getTypedef(state)) !== null && _b !== void 0 ? _b : ['']));
281
361
  }
282
362
  }
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
- }
363
+ return results;
292
364
  }
293
365
  walk(visitor, options) {
294
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
295
- visitors_1.walk(this, 'expression', visitor, options);
366
+ // eslint-disable-next-line no-bitwise
367
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
368
+ (0, visitors_2.walk)(this, 'defaultValue', visitor, options);
369
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
296
370
  }
297
371
  }
372
+ getLeadingTrivia() {
373
+ var _a;
374
+ return (_a = this.tokens.name.leadingTrivia) !== null && _a !== void 0 ? _a : [];
375
+ }
298
376
  }
299
- exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
300
- class DottedGetExpression extends Expression {
301
- constructor(obj, name, dot) {
377
+ exports.FunctionParameterExpression = FunctionParameterExpression;
378
+ class DottedGetExpression extends AstNode_1.Expression {
379
+ constructor(options) {
302
380
  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);
381
+ this.kind = AstNode_1.AstNodeKind.DottedGetExpression;
382
+ this.tokens = {
383
+ name: options.name,
384
+ dot: options.dot
385
+ };
386
+ this.obj = options.obj;
387
+ this.range = util_1.default.createBoundingRange(this.obj, this.tokens.dot, this.tokens.name);
307
388
  }
308
389
  transpile(state) {
309
390
  //if the callee starts with a namespace name, transpile the name
310
391
  if (state.file.calleeStartsWithNamespace(this)) {
311
- return new NamespacedVariableNameExpression(this).transpile(state);
392
+ return [
393
+ state.sourceNode(this, this.getName(Parser_1.ParseMode.BrightScript))
394
+ ];
312
395
  }
313
396
  else {
314
397
  return [
315
398
  ...this.obj.transpile(state),
316
- '.',
317
- state.transpileToken(this.name)
399
+ state.transpileToken(this.tokens.dot, '.'),
400
+ state.transpileToken(this.tokens.name)
318
401
  ];
319
402
  }
320
403
  }
321
404
  walk(visitor, options) {
322
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
323
- visitors_1.walk(this, 'obj', visitor, options);
324
- }
405
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
406
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
407
+ }
408
+ }
409
+ getType(options) {
410
+ var _a, _b, _c, _d, _e, _f;
411
+ const objType = (_a = this.obj) === null || _a === void 0 ? void 0 : _a.getType(options);
412
+ let result = objType === null || objType === void 0 ? void 0 : objType.getMemberType((_b = this.tokens.name) === null || _b === void 0 ? void 0 : _b.text, options);
413
+ if (util_1.default.isClassUsedAsFunction(result, this, options)) {
414
+ // treat this class constructor as a function
415
+ result = FunctionType_1.FunctionType.instance;
416
+ }
417
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
418
+ name: (_d = this.tokens.name) === null || _d === void 0 ? void 0 : _d.text,
419
+ type: result,
420
+ data: options.data,
421
+ range: (_f = (_e = this.tokens.name) === null || _e === void 0 ? void 0 : _e.range) !== null && _f !== void 0 ? _f : this.range,
422
+ astNode: this
423
+ }));
424
+ if (result ||
425
+ options.flags & 2 /* SymbolTypeFlag.typetime */ ||
426
+ ((0, reflection_1.isPrimitiveType)(objType) || (0, reflection_1.isCallableType)(objType))) {
427
+ // All types should be known at typeTime, or the obj is well known
428
+ return result;
429
+ }
430
+ // It is possible at runtime that a value has been added dynamically to an object, or something
431
+ // TODO: maybe have a strict flag on this?
432
+ return DynamicType_1.DynamicType.instance;
433
+ }
434
+ getName(parseMode) {
435
+ return util_1.default.getAllDottedGetPartsAsString(this, parseMode);
436
+ }
437
+ getLeadingTrivia() {
438
+ return this.obj.getLeadingTrivia();
325
439
  }
326
440
  }
327
441
  exports.DottedGetExpression = DottedGetExpression;
328
- class XmlAttributeGetExpression extends Expression {
329
- constructor(obj, name, at) {
442
+ class XmlAttributeGetExpression extends AstNode_1.Expression {
443
+ constructor(options) {
330
444
  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);
445
+ this.kind = AstNode_1.AstNodeKind.XmlAttributeGetExpression;
446
+ this.obj = options.obj;
447
+ this.tokens = { at: options.at, name: options.name };
448
+ this.range = util_1.default.createBoundingRange(this.obj, this.tokens.at, this.tokens.name);
335
449
  }
336
450
  transpile(state) {
337
451
  return [
338
452
  ...this.obj.transpile(state),
339
- '@',
340
- state.transpileToken(this.name)
453
+ state.transpileToken(this.tokens.at, '@'),
454
+ state.transpileToken(this.tokens.name)
341
455
  ];
342
456
  }
343
457
  walk(visitor, options) {
344
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
345
- visitors_1.walk(this, 'obj', visitor, options);
458
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
459
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
346
460
  }
347
461
  }
462
+ getLeadingTrivia() {
463
+ return this.obj.getLeadingTrivia();
464
+ }
348
465
  }
349
466
  exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
350
- class IndexedGetExpression extends Expression {
351
- constructor(obj, index, openingSquare, closingSquare) {
467
+ class IndexedGetExpression extends AstNode_1.Expression {
468
+ constructor(options) {
352
469
  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);
470
+ this.kind = AstNode_1.AstNodeKind.IndexedGetExpression;
471
+ this.tokens = {
472
+ openingSquare: options.openingSquare,
473
+ closingSquare: options.closingSquare,
474
+ questionDot: options.questionDot
475
+ };
476
+ this.obj = options.obj;
477
+ this.indexes = options.indexes;
478
+ this.range = util_1.default.createBoundingRange(this.obj, this.tokens.openingSquare, this.tokens.questionDot, this.tokens.openingSquare, ...this.indexes, this.tokens.closingSquare);
358
479
  }
359
480
  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
- ];
481
+ var _a;
482
+ const result = [];
483
+ result.push(...this.obj.transpile(state), this.tokens.questionDot ? state.transpileToken(this.tokens.questionDot) : '', state.transpileToken(this.tokens.openingSquare, '['));
484
+ for (let i = 0; i < this.indexes.length; i++) {
485
+ //add comma between indexes
486
+ if (i > 0) {
487
+ result.push(', ');
488
+ }
489
+ let index = this.indexes[i];
490
+ result.push(...((_a = index === null || index === void 0 ? void 0 : index.transpile(state)) !== null && _a !== void 0 ? _a : []));
491
+ }
492
+ result.push(state.transpileToken(this.tokens.closingSquare, ']'));
493
+ return result;
366
494
  }
367
495
  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);
496
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
497
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
498
+ (0, visitors_2.walkArray)(this.indexes, visitor, options, this);
499
+ }
500
+ }
501
+ getType(options) {
502
+ const objType = this.obj.getType(options);
503
+ if ((0, reflection_1.isArrayType)(objType)) {
504
+ // This is used on an array. What is the default type of that array?
505
+ return objType.defaultType;
371
506
  }
507
+ return super.getType(options);
508
+ }
509
+ getLeadingTrivia() {
510
+ return this.obj.getLeadingTrivia();
372
511
  }
373
512
  }
374
513
  exports.IndexedGetExpression = IndexedGetExpression;
375
- class GroupingExpression extends Expression {
376
- constructor(tokens, expression) {
514
+ class GroupingExpression extends AstNode_1.Expression {
515
+ constructor(options) {
377
516
  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);
517
+ this.kind = AstNode_1.AstNodeKind.GroupingExpression;
518
+ this.tokens = {
519
+ rightParen: options.rightParen,
520
+ leftParen: options.leftParen
521
+ };
522
+ this.expression = options.expression;
523
+ this.range = util_1.default.createBoundingRange(this.tokens.leftParen, this.expression, this.tokens.rightParen);
381
524
  }
382
525
  transpile(state) {
526
+ if ((0, reflection_1.isTypecastExpression)(this.expression)) {
527
+ return this.expression.transpile(state);
528
+ }
383
529
  return [
384
- state.transpileToken(this.tokens.left),
530
+ state.transpileToken(this.tokens.leftParen),
385
531
  ...this.expression.transpile(state),
386
- state.transpileToken(this.tokens.right)
532
+ state.transpileToken(this.tokens.rightParen)
387
533
  ];
388
534
  }
389
535
  walk(visitor, options) {
390
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
391
- visitors_1.walk(this, 'expression', visitor, options);
536
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
537
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
392
538
  }
393
539
  }
540
+ getType(options) {
541
+ return this.expression.getType(options);
542
+ }
543
+ getLeadingTrivia() {
544
+ var _a, _b;
545
+ return (_b = (_a = this.tokens.leftParen) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
546
+ }
394
547
  }
395
548
  exports.GroupingExpression = GroupingExpression;
396
- class LiteralExpression extends Expression {
397
- constructor(token) {
549
+ class LiteralExpression extends AstNode_1.Expression {
550
+ constructor(options) {
398
551
  super();
399
- this.token = token;
400
- this.type = util_1.default.tokenToBscType(token);
552
+ this.kind = AstNode_1.AstNodeKind.LiteralExpression;
553
+ this.tokens = {
554
+ value: options.value
555
+ };
401
556
  }
402
557
  get range() {
403
- return this.token.range;
558
+ return this.tokens.value.range;
559
+ }
560
+ getType(options) {
561
+ return util_1.default.tokenToBscType(this.tokens.value);
404
562
  }
405
563
  transpile(state) {
406
564
  let text;
407
- if (this.token.kind === lexer_1.TokenKind.TemplateStringQuasi) {
565
+ if (this.tokens.value.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
408
566
  //wrap quasis with quotes (and escape inner quotemarks)
409
- text = `"${this.token.text.replace(/"/g, '""')}"`;
567
+ text = `"${this.tokens.value.text.replace(/"/g, '""')}"`;
410
568
  }
411
- else if (reflection_1.isStringType(this.type)) {
412
- text = this.token.text;
569
+ else if (this.tokens.value.kind === TokenKind_1.TokenKind.StringLiteral) {
570
+ text = this.tokens.value.text;
413
571
  //add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
414
572
  if (text.endsWith('"') === false) {
415
573
  text += '"';
416
574
  }
417
575
  }
418
576
  else {
419
- text = this.token.text;
577
+ text = this.tokens.value.text;
420
578
  }
421
579
  return [
422
- state.sourceNode(this, text)
580
+ state.transpileToken(Object.assign(Object.assign({}, this.tokens.value), { text: text }))
423
581
  ];
424
582
  }
425
583
  walk(visitor, options) {
426
584
  //nothing to walk
427
585
  }
586
+ getLeadingTrivia() {
587
+ var _a;
588
+ return (_a = this.tokens.value.leadingTrivia) !== null && _a !== void 0 ? _a : [];
589
+ }
428
590
  }
429
591
  exports.LiteralExpression = LiteralExpression;
430
592
  /**
431
593
  * This is a special expression only used within template strings. It exists so we can prevent producing lots of empty strings
432
594
  * during template string transpile by identifying these expressions explicitly and skipping the bslib_toString around them
433
595
  */
434
- class EscapedCharCodeLiteralExpression extends Expression {
435
- constructor(token) {
596
+ class EscapedCharCodeLiteralExpression extends AstNode_1.Expression {
597
+ constructor(options) {
436
598
  super();
437
- this.token = token;
438
- this.range = token.range;
599
+ this.kind = AstNode_1.AstNodeKind.EscapedCharCodeLiteralExpression;
600
+ this.tokens = { value: options.value };
601
+ this.range = this.tokens.value.range;
439
602
  }
440
603
  transpile(state) {
441
604
  return [
442
- state.sourceNode(this, `chr(${this.token.charCode})`)
605
+ state.sourceNode(this, `chr(${this.tokens.value.charCode})`)
443
606
  ];
444
607
  }
445
608
  walk(visitor, options) {
@@ -447,101 +610,106 @@ class EscapedCharCodeLiteralExpression extends Expression {
447
610
  }
448
611
  }
449
612
  exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
450
- class ArrayLiteralExpression extends Expression {
451
- constructor(elements, open, close, hasSpread = false) {
613
+ class ArrayLiteralExpression extends AstNode_1.Expression {
614
+ constructor(options) {
452
615
  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);
616
+ this.kind = AstNode_1.AstNodeKind.ArrayLiteralExpression;
617
+ this.tokens = {
618
+ open: options.open,
619
+ close: options.close
620
+ };
621
+ this.elements = options.elements;
622
+ this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
458
623
  }
459
624
  transpile(state) {
625
+ var _a;
460
626
  let result = [];
461
- result.push(state.transpileToken(this.open));
627
+ result.push(state.transpileToken(this.tokens.open, '['));
462
628
  let hasChildren = this.elements.length > 0;
463
629
  state.blockDepth++;
464
630
  for (let i = 0; i < this.elements.length; i++) {
465
631
  let previousElement = this.elements[i - 1];
466
632
  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();
633
+ if (util_1.default.isLeadingCommentOnSameLine(previousElement !== null && previousElement !== void 0 ? previousElement : this.tokens.open, element)) {
634
+ result.push(' ');
478
635
  }
479
636
  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
- }
637
+ result.push('\n', state.indent());
491
638
  }
639
+ result.push(...element.transpile(state));
492
640
  }
493
641
  state.blockDepth--;
494
642
  //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));
643
+ const lastLocatable = (_a = this.elements[this.elements.length - 1]) !== null && _a !== void 0 ? _a : this.tokens.open;
644
+ result.push(...state.transpileEndBlockToken(lastLocatable, this.tokens.close, ']', hasChildren));
500
645
  return result;
501
646
  }
502
647
  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
- }
648
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
649
+ (0, visitors_2.walkArray)(this.elements, visitor, options, this);
507
650
  }
508
651
  }
652
+ getType(options) {
653
+ const innerTypes = this.elements.map(expr => expr.getType(options));
654
+ return new ArrayType_1.ArrayType(...innerTypes);
655
+ }
656
+ getLeadingTrivia() {
657
+ var _a, _b;
658
+ return (_b = (_a = this.tokens.open) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
659
+ }
660
+ getEndTrivia() {
661
+ var _a, _b;
662
+ return (_b = (_a = this.tokens.close) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
663
+ }
509
664
  }
510
665
  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) {
666
+ class AAMemberExpression extends AstNode_1.Expression {
667
+ constructor(options) {
515
668
  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);
669
+ this.kind = AstNode_1.AstNodeKind.AAMemberExpression;
670
+ this.tokens = {
671
+ key: options.key,
672
+ colon: options.colon,
673
+ comma: options.comma
674
+ };
675
+ this.value = options.value;
676
+ this.range = util_1.default.createBoundingRange(this.tokens.key, this.tokens.colon, this.value);
520
677
  }
521
678
  transpile(state) {
522
679
  //TODO move the logic from AALiteralExpression loop into this function
523
680
  return [];
524
681
  }
525
682
  walk(visitor, options) {
526
- visitors_1.walk(this, 'value', visitor, options);
683
+ (0, visitors_2.walk)(this, 'value', visitor, options);
684
+ }
685
+ getType(options) {
686
+ return this.value.getType(options);
687
+ }
688
+ getLeadingTrivia() {
689
+ var _a;
690
+ return (_a = this.tokens.key.leadingTrivia) !== null && _a !== void 0 ? _a : [];
527
691
  }
528
692
  }
529
693
  exports.AAMemberExpression = AAMemberExpression;
530
- class AALiteralExpression extends Expression {
531
- constructor(elements, open, close) {
694
+ class AALiteralExpression extends AstNode_1.Expression {
695
+ constructor(options) {
532
696
  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);
697
+ this.kind = AstNode_1.AstNodeKind.AALiteralExpression;
698
+ this.tokens = {
699
+ open: options.open,
700
+ close: options.close
701
+ };
702
+ this.elements = options.elements;
703
+ this.range = util_1.default.createBoundingRange(this.tokens.open, ...this.elements, this.tokens.close);
537
704
  }
538
705
  transpile(state) {
706
+ var _a;
539
707
  let result = [];
540
708
  //open curly
541
- result.push(state.transpileToken(this.open));
709
+ result.push(state.transpileToken(this.tokens.open, '{'));
542
710
  let hasChildren = this.elements.length > 0;
543
711
  //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))) {
712
+ if (hasChildren && !util_1.default.isLeadingCommentOnSameLine(this.tokens.open, this.elements[0])) {
545
713
  result.push('\n');
546
714
  }
547
715
  state.blockDepth++;
@@ -550,170 +718,235 @@ class AALiteralExpression extends Expression {
550
718
  let previousElement = this.elements[i - 1];
551
719
  let nextElement = this.elements[i + 1];
552
720
  //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))) {
721
+ if (util_1.default.isLeadingCommentOnSameLine(this.tokens.open, element) ||
722
+ util_1.default.isLeadingCommentOnSameLine(previousElement, element)) {
555
723
  result.push(' ');
556
- //indent line
557
724
  }
558
725
  else {
726
+ //indent line
559
727
  result.push(state.indent());
560
728
  }
561
- //render comments
562
- if (reflection_1.isCommentStatement(element)) {
563
- result.push(...element.transpile(state));
564
- }
565
- else {
566
- //key
567
- result.push(state.transpileToken(element.keyToken));
568
- //colon
569
- result.push(state.transpileToken(element.colonToken), ' ');
570
- //determine if comments are the only members left in the array
571
- let onlyCommentsRemaining = true;
572
- for (let j = i + 1; j < this.elements.length; j++) {
573
- if (reflection_1.isCommentStatement(this.elements[j]) === false) {
574
- onlyCommentsRemaining = false;
575
- break;
576
- }
577
- }
578
- //value
579
- result.push(...element.value.transpile(state));
580
- //add trailing comma if not final element (excluding comments)
581
- if (i !== this.elements.length - 1 && onlyCommentsRemaining === false) {
582
- result.push(',');
583
- }
584
- }
729
+ //key
730
+ result.push(state.transpileToken(element.tokens.key));
731
+ //colon
732
+ result.push(state.transpileToken(element.tokens.colon, ':'), ' ');
733
+ //value
734
+ result.push(...element.value.transpile(state));
585
735
  //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) {
736
+ if (nextElement && !util_1.default.isLeadingCommentOnSameLine(element, nextElement)) {
587
737
  //add a newline between statements
588
- }
589
- else {
590
738
  result.push('\n');
591
739
  }
592
740
  }
593
741
  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));
742
+ const lastElement = (_a = this.elements[this.elements.length - 1]) !== null && _a !== void 0 ? _a : this.tokens.open;
743
+ result.push(...state.transpileEndBlockToken(lastElement, this.tokens.close, '}', hasChildren));
600
744
  return result;
601
745
  }
602
746
  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);
607
- }
608
- else {
609
- visitors_1.walk(this.elements, i, visitor, options, this);
610
- }
747
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
748
+ (0, visitors_2.walkArray)(this.elements, visitor, options, this);
749
+ }
750
+ }
751
+ getType(options) {
752
+ const resultType = new AssociativeArrayType_1.AssociativeArrayType();
753
+ resultType.addBuiltInInterfaces();
754
+ for (const element of this.elements) {
755
+ if ((0, reflection_1.isAAMemberExpression)(element)) {
756
+ resultType.addMember(element.tokens.key.text, { definingNode: element }, element.getType(options), 1 /* SymbolTypeFlag.runtime */);
611
757
  }
612
758
  }
759
+ return resultType;
760
+ }
761
+ getLeadingTrivia() {
762
+ var _a, _b;
763
+ return (_b = (_a = this.tokens.open) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
764
+ }
765
+ getEndTrivia() {
766
+ var _a, _b;
767
+ return (_b = (_a = this.tokens.close) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
613
768
  }
614
769
  }
615
770
  exports.AALiteralExpression = AALiteralExpression;
616
- class UnaryExpression extends Expression {
617
- constructor(operator, right) {
771
+ class UnaryExpression extends AstNode_1.Expression {
772
+ constructor(options) {
618
773
  super();
619
- this.operator = operator;
620
- this.right = right;
621
- this.range = util_1.default.createRangeFromPositions(this.operator.range.start, this.right.range.end);
774
+ this.kind = AstNode_1.AstNodeKind.UnaryExpression;
775
+ this.tokens = {
776
+ operator: options.operator
777
+ };
778
+ this.right = options.right;
779
+ this.range = util_1.default.createBoundingRange(this.tokens.operator, this.right);
622
780
  }
623
781
  transpile(state) {
782
+ let separatingWhitespace;
783
+ if ((0, reflection_1.isVariableExpression)(this.right)) {
784
+ separatingWhitespace = this.right.tokens.name.leadingWhitespace;
785
+ }
786
+ else if ((0, reflection_1.isLiteralExpression)(this.right)) {
787
+ separatingWhitespace = this.right.tokens.value.leadingWhitespace;
788
+ }
789
+ else {
790
+ separatingWhitespace = ' ';
791
+ }
624
792
  return [
625
- state.transpileToken(this.operator),
626
- ' ',
793
+ state.transpileToken(this.tokens.operator),
794
+ separatingWhitespace,
627
795
  ...this.right.transpile(state)
628
796
  ];
629
797
  }
630
798
  walk(visitor, options) {
631
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
632
- visitors_1.walk(this, 'right', visitor, options);
799
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
800
+ (0, visitors_2.walk)(this, 'right', visitor, options);
633
801
  }
634
802
  }
803
+ getType(options) {
804
+ return util_1.default.unaryOperatorResultType(this.tokens.operator, this.right.getType(options));
805
+ }
806
+ getLeadingTrivia() {
807
+ var _a;
808
+ return (_a = this.tokens.operator.leadingTrivia) !== null && _a !== void 0 ? _a : [];
809
+ }
635
810
  }
636
811
  exports.UnaryExpression = UnaryExpression;
637
- class VariableExpression extends Expression {
638
- constructor(name, namespaceName) {
812
+ class VariableExpression extends AstNode_1.Expression {
813
+ constructor(options) {
814
+ var _a;
639
815
  super();
640
- this.name = name;
641
- this.namespaceName = namespaceName;
642
- this.range = this.name.range;
816
+ this.kind = AstNode_1.AstNodeKind.VariableExpression;
817
+ this.tokens = {
818
+ name: options.name
819
+ };
820
+ this.range = (_a = this.tokens.name) === null || _a === void 0 ? void 0 : _a.range;
643
821
  }
644
822
  getName(parseMode) {
645
- return parseMode === Parser_1.ParseMode.BrightScript ? this.name.text : this.name.text;
823
+ return this.tokens.name.text;
646
824
  }
647
825
  transpile(state) {
648
- var _a;
649
826
  let result = [];
827
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
650
828
  //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))) {
829
+ if (namespace && state.file.calleeIsKnownNamespaceFunction(this, namespace.getName(Parser_1.ParseMode.BrighterScript))) {
652
830
  result.push(state.sourceNode(this, [
653
- this.namespaceName.getName(Parser_1.ParseMode.BrightScript),
831
+ namespace.getName(Parser_1.ParseMode.BrightScript),
654
832
  '_',
655
833
  this.getName(Parser_1.ParseMode.BrightScript)
656
834
  ]));
657
835
  //transpile normally
658
836
  }
659
837
  else {
660
- result.push(state.transpileToken(this.name));
838
+ result.push(state.transpileToken(this.tokens.name));
661
839
  }
662
840
  return result;
663
841
  }
664
842
  walk(visitor, options) {
665
843
  //nothing to walk
666
844
  }
845
+ getType(options) {
846
+ var _a;
847
+ let resultType = util_1.default.tokenToBscType(this.tokens.name);
848
+ const nameKey = this.getName();
849
+ if (!resultType) {
850
+ const symbolTable = this.getSymbolTable();
851
+ resultType = symbolTable === null || symbolTable === void 0 ? void 0 : symbolTable.getSymbolType(nameKey, Object.assign(Object.assign({}, options), { fullName: nameKey, tableProvider: () => this.getSymbolTable() }));
852
+ if (util_1.default.isClassUsedAsFunction(resultType, this, options)) {
853
+ resultType = FunctionType_1.FunctionType.instance;
854
+ }
855
+ }
856
+ (_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 }));
857
+ return resultType;
858
+ }
859
+ getLeadingTrivia() {
860
+ var _a;
861
+ return (_a = this.tokens.name.leadingTrivia) !== null && _a !== void 0 ? _a : [];
862
+ }
667
863
  }
668
864
  exports.VariableExpression = VariableExpression;
669
- class SourceLiteralExpression extends Expression {
670
- constructor(token) {
865
+ class SourceLiteralExpression extends AstNode_1.Expression {
866
+ constructor(options) {
867
+ var _a;
671
868
  super();
672
- this.token = token;
673
- this.range = token.range;
869
+ this.kind = AstNode_1.AstNodeKind.SourceLiteralExpression;
870
+ this.tokens = {
871
+ value: options.value
872
+ };
873
+ this.range = (_a = this.tokens.value) === null || _a === void 0 ? void 0 : _a.range;
874
+ }
875
+ /**
876
+ * Find the index of the function in its parent
877
+ */
878
+ findFunctionIndex(parentFunction, func) {
879
+ let index = -1;
880
+ parentFunction.findChild((node) => {
881
+ if ((0, reflection_1.isFunctionExpression)(node)) {
882
+ index++;
883
+ if (node === func) {
884
+ return true;
885
+ }
886
+ }
887
+ }, {
888
+ walkMode: visitors_1.WalkMode.visitAllRecursive
889
+ });
890
+ return index;
674
891
  }
675
892
  getFunctionName(state, parseMode) {
676
- let functionExpression = state.file.getFunctionExpressionAtPosition(this.token.range.start);
893
+ let func = this.findAncestor(reflection_1.isFunctionExpression);
677
894
  let nameParts = [];
678
- while (functionExpression.parentFunction) {
679
- let index = functionExpression.parentFunction.childFunctionExpressions.indexOf(functionExpression);
895
+ let parentFunction;
896
+ while ((parentFunction = func.findAncestor(reflection_1.isFunctionExpression))) {
897
+ let index = this.findFunctionIndex(parentFunction, func);
680
898
  nameParts.unshift(`anon${index}`);
681
- functionExpression = functionExpression.parentFunction;
899
+ func = parentFunction;
682
900
  }
683
901
  //get the index of this function in its parent
684
- nameParts.unshift(functionExpression.functionStatement.getName(parseMode));
902
+ nameParts.unshift(func.functionStatement.getName(parseMode));
685
903
  return nameParts.join('$');
686
904
  }
905
+ /**
906
+ * Get the line number from our token or from the closest ancestor that has a range
907
+ */
908
+ getClosestLineNumber() {
909
+ let node = this;
910
+ while (node) {
911
+ if (node.range) {
912
+ return node.range.start.line + 1;
913
+ }
914
+ node = node.parent;
915
+ }
916
+ return -1;
917
+ }
687
918
  transpile(state) {
688
919
  let text;
689
- switch (this.token.kind) {
690
- case lexer_1.TokenKind.SourceFilePathLiteral:
920
+ switch (this.tokens.value.kind) {
921
+ case TokenKind_1.TokenKind.SourceFilePathLiteral:
691
922
  const pathUrl = fileUrl(state.srcPath);
692
923
  text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
693
924
  break;
694
- case lexer_1.TokenKind.SourceLineNumLiteral:
695
- text = `${this.token.range.start.line + 1}`;
925
+ case TokenKind_1.TokenKind.SourceLineNumLiteral:
926
+ //TODO find first parent that has range, or default to -1
927
+ text = `${this.getClosestLineNumber()}`;
696
928
  break;
697
- case lexer_1.TokenKind.FunctionNameLiteral:
929
+ case TokenKind_1.TokenKind.FunctionNameLiteral:
698
930
  text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
699
931
  break;
700
- case lexer_1.TokenKind.SourceFunctionNameLiteral:
932
+ case TokenKind_1.TokenKind.SourceFunctionNameLiteral:
701
933
  text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrighterScript)}"`;
702
934
  break;
703
- case lexer_1.TokenKind.SourceLocationLiteral:
935
+ case TokenKind_1.TokenKind.SourceLocationLiteral:
704
936
  const locationUrl = fileUrl(state.srcPath);
705
- text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
937
+ //TODO find first parent that has range, or default to -1
938
+ text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.getClosestLineNumber()}"`;
706
939
  break;
707
- case lexer_1.TokenKind.PkgPathLiteral:
708
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}"`;
940
+ case TokenKind_1.TokenKind.PkgPathLiteral:
941
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}"`;
709
942
  break;
710
- case lexer_1.TokenKind.PkgLocationLiteral:
711
- text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}:" + str(LINE_NUM)`;
943
+ case TokenKind_1.TokenKind.PkgLocationLiteral:
944
+ text = `"${util_1.default.sanitizePkgPath(state.file.pkgPath)}:" + str(LINE_NUM)`;
712
945
  break;
713
- case lexer_1.TokenKind.LineNumLiteral:
946
+ case TokenKind_1.TokenKind.LineNumLiteral:
714
947
  default:
715
948
  //use the original text (because it looks like a variable)
716
- text = this.token.text;
949
+ text = this.tokens.value.text;
717
950
  break;
718
951
  }
719
952
  return [
@@ -723,6 +956,10 @@ class SourceLiteralExpression extends Expression {
723
956
  walk(visitor, options) {
724
957
  //nothing to walk
725
958
  }
959
+ getLeadingTrivia() {
960
+ var _a;
961
+ return (_a = this.tokens.value.leadingTrivia) !== null && _a !== void 0 ? _a : [];
962
+ }
726
963
  }
727
964
  exports.SourceLiteralExpression = SourceLiteralExpression;
728
965
  /**
@@ -730,61 +967,78 @@ exports.SourceLiteralExpression = SourceLiteralExpression;
730
967
  * except we need to uniquely identify these statements so we can
731
968
  * do more type checking.
732
969
  */
733
- class NewExpression extends Expression {
734
- constructor(newKeyword, call) {
970
+ class NewExpression extends AstNode_1.Expression {
971
+ constructor(options) {
735
972
  super();
736
- this.newKeyword = newKeyword;
737
- this.call = call;
738
- this.range = util_1.default.createRangeFromPositions(this.newKeyword.range.start, this.call.range.end);
973
+ this.kind = AstNode_1.AstNodeKind.NewExpression;
974
+ this.tokens = {
975
+ new: options.new
976
+ };
977
+ this.call = options.call;
978
+ this.range = util_1.default.createBoundingRange(this.tokens.new, this.call);
739
979
  }
740
980
  /**
741
981
  * The name of the class to initialize (with optional namespace prefixed)
742
982
  */
743
983
  get className() {
744
984
  //the parser guarantees the callee of a new statement's call object will be
745
- //a NamespacedVariableNameExpression
985
+ //either a VariableExpression or a DottedGet
746
986
  return this.call.callee;
747
987
  }
748
- get namespaceName() {
749
- return this.call.namespaceName;
750
- }
751
988
  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;
989
+ var _a;
990
+ const namespace = this.findAncestor(reflection_1.isNamespaceStatement);
991
+ 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
992
  //new statements within a namespace block can omit the leading namespace if the class resides in that same namespace.
755
993
  //So we need to figure out if this is a namespace-omitted class, or if this class exists without a namespace.
756
994
  return this.call.transpile(state, cls === null || cls === void 0 ? void 0 : cls.getName(Parser_1.ParseMode.BrightScript));
757
995
  }
758
996
  walk(visitor, options) {
759
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
760
- visitors_1.walk(this, 'call', visitor, options);
997
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
998
+ (0, visitors_2.walk)(this, 'call', visitor, options);
761
999
  }
762
1000
  }
1001
+ getType(options) {
1002
+ const result = this.call.getType(options);
1003
+ if (options.typeChain) {
1004
+ // modify last typechain entry to show it is a new ...()
1005
+ const lastEntry = options.typeChain[options.typeChain.length - 1];
1006
+ if (lastEntry) {
1007
+ lastEntry.astNode = this;
1008
+ }
1009
+ }
1010
+ return result;
1011
+ }
1012
+ getLeadingTrivia() {
1013
+ var _a;
1014
+ return (_a = this.tokens.new.leadingTrivia) !== null && _a !== void 0 ? _a : [];
1015
+ }
763
1016
  }
764
1017
  exports.NewExpression = NewExpression;
765
- class CallfuncExpression extends Expression {
766
- constructor(callee, operator, methodName, openingParen, args, closingParen) {
767
- var _a, _b, _c;
1018
+ class CallfuncExpression extends AstNode_1.Expression {
1019
+ constructor(options) {
1020
+ var _a;
768
1021
  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);
1022
+ this.kind = AstNode_1.AstNodeKind.CallfuncExpression;
1023
+ this.tokens = {
1024
+ operator: options.operator,
1025
+ methodName: options.methodName,
1026
+ openingParen: options.openingParen,
1027
+ closingParen: options.closingParen
1028
+ };
1029
+ this.callee = options.callee;
1030
+ this.args = (_a = options.args) !== null && _a !== void 0 ? _a : [];
1031
+ this.range = util_1.default.createBoundingRange(this.callee, this.tokens.operator, this.tokens.methodName, this.tokens.openingParen, ...this.args, this.tokens.closingParen);
776
1032
  }
777
1033
  transpile(state) {
1034
+ var _a;
778
1035
  let result = [];
779
- result.push(...this.callee.transpile(state), state.sourceNode(this.operator, '.callfunc'), state.transpileToken(this.openingParen),
1036
+ result.push(...this.callee.transpile(state), state.sourceNode(this.tokens.operator, '.callfunc'), state.transpileToken(this.tokens.openingParen, '('),
780
1037
  //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 {
1038
+ state.sourceNode(this.tokens.methodName, ['"', this.tokens.methodName.text, '"']));
1039
+ if (((_a = this.args) === null || _a === void 0 ? void 0 : _a.length) > 0) {
1040
+ result.push(', ');
1041
+ //transpile args
788
1042
  for (let i = 0; i < this.args.length; i++) {
789
1043
  //add comma between args
790
1044
  if (i > 0) {
@@ -794,16 +1048,54 @@ class CallfuncExpression extends Expression {
794
1048
  result.push(...arg.transpile(state));
795
1049
  }
796
1050
  }
797
- result.push(state.transpileToken(this.closingParen));
1051
+ else if (state.options.legacyCallfuncHandling) {
1052
+ result.push(', ', 'invalid');
1053
+ }
1054
+ result.push(state.transpileToken(this.tokens.closingParen, ')'));
798
1055
  return result;
799
1056
  }
800
1057
  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);
1058
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1059
+ (0, visitors_2.walk)(this, 'callee', visitor, options);
1060
+ (0, visitors_2.walkArray)(this.args, visitor, options, this);
1061
+ }
1062
+ }
1063
+ getType(options) {
1064
+ var _a, _b, _c;
1065
+ let result = DynamicType_1.DynamicType.instance;
1066
+ // a little hacky here with checking options.ignoreCall because callFuncExpression has the method name
1067
+ // It's nicer for CallExpression, because it's a call on any expression.
1068
+ const calleeType = this.callee.getType(Object.assign(Object.assign({}, options), { flags: 1 /* SymbolTypeFlag.runtime */ }));
1069
+ if ((0, reflection_1.isComponentType)(calleeType) || (0, reflection_1.isReferenceType)(calleeType)) {
1070
+ const funcType = (_b = (_a = calleeType).getCallFuncType) === null || _b === void 0 ? void 0 : _b.call(_a, this.tokens.methodName.text, options);
1071
+ if (funcType) {
1072
+ (_c = options.typeChain) === null || _c === void 0 ? void 0 : _c.push(new interfaces_1.TypeChainEntry({
1073
+ name: this.tokens.methodName.text,
1074
+ type: funcType,
1075
+ data: options.data,
1076
+ range: this.tokens.methodName.range,
1077
+ separatorToken: (0, creators_1.createToken)(TokenKind_1.TokenKind.Callfunc),
1078
+ astNode: this
1079
+ }));
1080
+ if (options.ignoreCall) {
1081
+ result = funcType;
1082
+ }
1083
+ }
1084
+ /* TODO:
1085
+ make callfunc return types work
1086
+ else if (isCallableType(funcType) && (!isReferenceType(funcType.returnType) || funcType.returnType.isResolvable())) {
1087
+ result = funcType.returnType;
1088
+ } else if (!isReferenceType(funcType) && (funcType as any)?.returnType?.isResolvable()) {
1089
+ result = (funcType as any).returnType;
1090
+ } else {
1091
+ return new TypePropertyReferenceType(funcType, 'returnType');
805
1092
  }
1093
+ */
806
1094
  }
1095
+ return result;
1096
+ }
1097
+ getLeadingTrivia() {
1098
+ return this.callee.getLeadingTrivia();
807
1099
  }
808
1100
  }
809
1101
  exports.CallfuncExpression = CallfuncExpression;
@@ -811,11 +1103,12 @@ exports.CallfuncExpression = CallfuncExpression;
811
1103
  * Since template strings can contain newlines, we need to concatenate multiple strings together with chr() calls.
812
1104
  * This is a single expression that represents the string contatenation of all parts of a single quasi.
813
1105
  */
814
- class TemplateStringQuasiExpression extends Expression {
815
- constructor(expressions) {
1106
+ class TemplateStringQuasiExpression extends AstNode_1.Expression {
1107
+ constructor(options) {
816
1108
  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);
1109
+ this.kind = AstNode_1.AstNodeKind.TemplateStringQuasiExpression;
1110
+ this.expressions = options.expressions;
1111
+ this.range = util_1.default.createBoundingRange(...this.expressions);
819
1112
  }
820
1113
  transpile(state, skipEmptyStrings = true) {
821
1114
  let result = [];
@@ -823,7 +1116,7 @@ class TemplateStringQuasiExpression extends Expression {
823
1116
  for (let expression of this.expressions) {
824
1117
  //skip empty strings
825
1118
  //TODO what does an empty string literal expression look like?
826
- if (expression.token.text === '' && skipEmptyStrings === true) {
1119
+ if (expression.tokens.value.text === '' && skipEmptyStrings === true) {
827
1120
  continue;
828
1121
  }
829
1122
  result.push(plus, ...expression.transpile(state));
@@ -832,28 +1125,32 @@ class TemplateStringQuasiExpression extends Expression {
832
1125
  return result;
833
1126
  }
834
1127
  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
- }
1128
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1129
+ (0, visitors_2.walkArray)(this.expressions, visitor, options, this);
839
1130
  }
840
1131
  }
841
1132
  }
842
1133
  exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
843
- class TemplateStringExpression extends Expression {
844
- constructor(openingBacktick, quasis, expressions, closingBacktick) {
1134
+ class TemplateStringExpression extends AstNode_1.Expression {
1135
+ constructor(options) {
845
1136
  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);
1137
+ this.kind = AstNode_1.AstNodeKind.TemplateStringExpression;
1138
+ this.tokens = {
1139
+ openingBacktick: options.openingBacktick,
1140
+ closingBacktick: options.closingBacktick
1141
+ };
1142
+ this.quasis = options.quasis;
1143
+ this.expressions = options.expressions;
1144
+ this.range = util_1.default.createBoundingRange(this.tokens.openingBacktick, this.quasis[0], this.quasis[this.quasis.length - 1], this.tokens.closingBacktick);
1145
+ }
1146
+ getType(options) {
1147
+ return StringType_1.StringType.instance;
851
1148
  }
852
1149
  transpile(state) {
853
1150
  if (this.quasis.length === 1 && this.expressions.length === 0) {
854
1151
  return this.quasis[0].transpile(state);
855
1152
  }
856
- let result = [];
1153
+ let result = ['('];
857
1154
  let plus = '';
858
1155
  //helper function to figure out when to include the plus
859
1156
  function add(...items) {
@@ -871,8 +1168,8 @@ class TemplateStringExpression extends Expression {
871
1168
  add(...quasi.transpile(state));
872
1169
  if (expression) {
873
1170
  //skip the toString wrapper around certain expressions
874
- if (reflection_1.isEscapedCharCodeLiteralExpression(expression) ||
875
- (reflection_1.isLiteralExpression(expression) && reflection_1.isStringType(expression.type))) {
1171
+ if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
1172
+ ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.getType()))) {
876
1173
  add(...expression.transpile(state));
877
1174
  //wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
878
1175
  }
@@ -881,35 +1178,40 @@ class TemplateStringExpression extends Expression {
881
1178
  }
882
1179
  }
883
1180
  }
1181
+ //the expression should be wrapped in parens so it can be used line a single expression at runtime
1182
+ result.push(')');
884
1183
  return result;
885
1184
  }
886
1185
  walk(visitor, options) {
887
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1186
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
888
1187
  //walk the quasis and expressions in left-to-right order
889
1188
  for (let i = 0; i < this.quasis.length; i++) {
890
- visitors_1.walk(this.quasis, i, visitor, options, this);
1189
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
891
1190
  //this skips the final loop iteration since we'll always have one more quasi than expression
892
1191
  if (this.expressions[i]) {
893
- visitors_1.walk(this.expressions, i, visitor, options, this);
1192
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
894
1193
  }
895
1194
  }
896
1195
  }
897
1196
  }
898
1197
  }
899
1198
  exports.TemplateStringExpression = TemplateStringExpression;
900
- class TaggedTemplateStringExpression extends Expression {
901
- constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
1199
+ class TaggedTemplateStringExpression extends AstNode_1.Expression {
1200
+ constructor(options) {
902
1201
  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);
1202
+ this.kind = AstNode_1.AstNodeKind.TaggedTemplateStringExpression;
1203
+ this.tokens = {
1204
+ tagName: options.tagName,
1205
+ openingBacktick: options.openingBacktick,
1206
+ closingBacktick: options.closingBacktick
1207
+ };
1208
+ this.quasis = options.quasis;
1209
+ this.expressions = options.expressions;
1210
+ this.range = util_1.default.createBoundingRange(this.tokens.tagName, this.tokens.openingBacktick, this.quasis[0], this.quasis[this.quasis.length - 1], this.tokens.closingBacktick);
909
1211
  }
910
1212
  transpile(state) {
911
1213
  let result = [];
912
- result.push(state.transpileToken(this.tagName), '([');
1214
+ result.push(state.transpileToken(this.tokens.tagName), '([');
913
1215
  //add quasis as the first array
914
1216
  for (let i = 0; i < this.quasis.length; i++) {
915
1217
  let quasi = this.quasis[i];
@@ -928,30 +1230,36 @@ class TaggedTemplateStringExpression extends Expression {
928
1230
  }
929
1231
  result.push(...expression.transpile(state));
930
1232
  }
931
- result.push(state.sourceNode(this.closingBacktick, '])'));
1233
+ result.push(state.sourceNode(this.tokens.closingBacktick, '])'));
932
1234
  return result;
933
1235
  }
934
1236
  walk(visitor, options) {
935
- if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1237
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
936
1238
  //walk the quasis and expressions in left-to-right order
937
1239
  for (let i = 0; i < this.quasis.length; i++) {
938
- visitors_1.walk(this.quasis, i, visitor, options, this);
1240
+ (0, visitors_2.walk)(this.quasis, i, visitor, options, this);
939
1241
  //this skips the final loop iteration since we'll always have one more quasi than expression
940
1242
  if (this.expressions[i]) {
941
- visitors_1.walk(this.expressions, i, visitor, options, this);
1243
+ (0, visitors_2.walk)(this.expressions, i, visitor, options, this);
942
1244
  }
943
1245
  }
944
1246
  }
945
1247
  }
946
1248
  }
947
1249
  exports.TaggedTemplateStringExpression = TaggedTemplateStringExpression;
948
- class AnnotationExpression extends Expression {
949
- constructor(atToken, nameToken) {
1250
+ class AnnotationExpression extends AstNode_1.Expression {
1251
+ constructor(options) {
950
1252
  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);
1253
+ this.kind = AstNode_1.AstNodeKind.AnnotationExpression;
1254
+ this.tokens = {
1255
+ at: options.at,
1256
+ name: options.name
1257
+ };
1258
+ this.call = options.call;
1259
+ this.name = this.tokens.name.text;
1260
+ }
1261
+ get range() {
1262
+ return util_1.default.createBoundingRange(this.tokens.at, this.tokens.name, this.call);
955
1263
  }
956
1264
  /**
957
1265
  * Convert annotation arguments to JavaScript types
@@ -963,6 +1271,10 @@ class AnnotationExpression extends Expression {
963
1271
  }
964
1272
  return this.call.args.map(e => expressionToValue(e, strict));
965
1273
  }
1274
+ getLeadingTrivia() {
1275
+ var _a, _b;
1276
+ return (_b = (_a = this.tokens.at) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1277
+ }
966
1278
  transpile(state) {
967
1279
  return [];
968
1280
  }
@@ -979,22 +1291,25 @@ class AnnotationExpression extends Expression {
979
1291
  }
980
1292
  }
981
1293
  exports.AnnotationExpression = AnnotationExpression;
982
- class TernaryExpression extends Expression {
983
- constructor(test, questionMarkToken, consequent, colonToken, alternate) {
984
- var _a, _b, _c;
1294
+ class TernaryExpression extends AstNode_1.Expression {
1295
+ constructor(options) {
985
1296
  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);
1297
+ this.kind = AstNode_1.AstNodeKind.TernaryExpression;
1298
+ this.tokens = {
1299
+ questionMark: options.questionMark,
1300
+ colon: options.colon
1301
+ };
1302
+ this.test = options.test;
1303
+ this.consequent = options.consequent;
1304
+ this.alternate = options.alternate;
1305
+ this.range = util_1.default.createBoundingRange(this.test, this.tokens.questionMark, this.consequent, this.tokens.colon, this.alternate);
992
1306
  }
993
1307
  transpile(state) {
994
1308
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
995
1309
  let result = [];
996
- let consequentInfo = util_1.default.getExpressionInfo(this.consequent);
997
- let alternateInfo = util_1.default.getExpressionInfo(this.alternate);
1310
+ const file = state.file;
1311
+ let consequentInfo = util_1.default.getExpressionInfo(this.consequent, file);
1312
+ let alternateInfo = util_1.default.getExpressionInfo(this.alternate, file);
998
1313
  //get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
999
1314
  let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
1000
1315
  let mutatingExpressions = [
@@ -1002,12 +1317,12 @@ class TernaryExpression extends Expression {
1002
1317
  ...alternateInfo.expressions
1003
1318
  ].filter(e => e instanceof CallExpression || e instanceof CallfuncExpression || e instanceof DottedGetExpression);
1004
1319
  if (mutatingExpressions.length > 0) {
1005
- result.push(state.sourceNode(this.questionMarkToken,
1320
+ result.push(state.sourceNode(this.tokens.questionMark,
1006
1321
  //write all the scope variables as parameters.
1007
1322
  //TODO handle when there are more than 31 parameters
1008
- `(function(__bsCondition, ${allUniqueVarNames.join(', ')})`), state.newline,
1323
+ `(function(${['__bsCondition', ...allUniqueVarNames].join(', ')})`), state.newline,
1009
1324
  //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(', ')})`));
1325
+ 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
1326
  state.blockDepth--;
1012
1327
  }
1013
1328
  else {
@@ -1016,33 +1331,38 @@ class TernaryExpression extends Expression {
1016
1331
  return result;
1017
1332
  }
1018
1333
  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);
1334
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1335
+ (0, visitors_2.walk)(this, 'test', visitor, options);
1336
+ (0, visitors_2.walk)(this, 'consequent', visitor, options);
1337
+ (0, visitors_2.walk)(this, 'alternate', visitor, options);
1023
1338
  }
1024
1339
  }
1340
+ getLeadingTrivia() {
1341
+ return this.test.getLeadingTrivia();
1342
+ }
1025
1343
  }
1026
1344
  exports.TernaryExpression = TernaryExpression;
1027
- class NullCoalescingExpression extends Expression {
1028
- constructor(consequent, questionQuestionToken, alternate) {
1029
- var _a;
1345
+ class NullCoalescingExpression extends AstNode_1.Expression {
1346
+ constructor(options) {
1030
1347
  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);
1348
+ this.kind = AstNode_1.AstNodeKind.NullCoalescingExpression;
1349
+ this.tokens = {
1350
+ questionQuestion: options.questionQuestion
1351
+ };
1352
+ this.consequent = options.consequent;
1353
+ this.alternate = options.alternate;
1354
+ this.range = util_1.default.createBoundingRange(this.consequent, this.tokens.questionQuestion, this.alternate);
1035
1355
  }
1036
1356
  transpile(state) {
1037
1357
  let result = [];
1038
- let consequentInfo = util_1.default.getExpressionInfo(this.consequent);
1039
- let alternateInfo = util_1.default.getExpressionInfo(this.alternate);
1358
+ let consequentInfo = util_1.default.getExpressionInfo(this.consequent, state.file);
1359
+ let alternateInfo = util_1.default.getExpressionInfo(this.alternate, state.file);
1040
1360
  //get all unique variable names used in the consequent and alternate, and sort them alphabetically so the output is consistent
1041
1361
  let allUniqueVarNames = [...new Set([...consequentInfo.uniqueVarNames, ...alternateInfo.uniqueVarNames])].sort();
1042
1362
  let hasMutatingExpression = [
1043
1363
  ...consequentInfo.expressions,
1044
1364
  ...alternateInfo.expressions
1045
- ].find(e => reflection_1.isCallExpression(e) || reflection_1.isCallfuncExpression(e) || reflection_1.isDottedGetExpression(e));
1365
+ ].find(e => (0, reflection_1.isCallExpression)(e) || (0, reflection_1.isCallfuncExpression)(e) || (0, reflection_1.isDottedGetExpression)(e));
1046
1366
  if (hasMutatingExpression) {
1047
1367
  result.push(`(function(`,
1048
1368
  //write all the scope variables as parameters.
@@ -1060,51 +1380,186 @@ class NullCoalescingExpression extends Expression {
1060
1380
  return result;
1061
1381
  }
1062
1382
  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);
1383
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1384
+ (0, visitors_2.walk)(this, 'consequent', visitor, options);
1385
+ (0, visitors_2.walk)(this, 'alternate', visitor, options);
1066
1386
  }
1067
1387
  }
1388
+ getLeadingTrivia() {
1389
+ return this.consequent.getLeadingTrivia();
1390
+ }
1068
1391
  }
1069
1392
  exports.NullCoalescingExpression = NullCoalescingExpression;
1393
+ class RegexLiteralExpression extends AstNode_1.Expression {
1394
+ constructor(options) {
1395
+ super();
1396
+ this.kind = AstNode_1.AstNodeKind.RegexLiteralExpression;
1397
+ this.tokens = {
1398
+ regexLiteral: options.regexLiteral
1399
+ };
1400
+ }
1401
+ get range() {
1402
+ var _a, _b;
1403
+ return (_b = (_a = this.tokens) === null || _a === void 0 ? void 0 : _a.regexLiteral) === null || _b === void 0 ? void 0 : _b.range;
1404
+ }
1405
+ transpile(state) {
1406
+ var _a, _b;
1407
+ let text = (_b = (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
1408
+ let flags = '';
1409
+ //get any flags from the end
1410
+ const flagMatch = /\/([a-z]+)$/i.exec(text);
1411
+ if (flagMatch) {
1412
+ text = text.substring(0, flagMatch.index + 1);
1413
+ flags = flagMatch[1];
1414
+ }
1415
+ let pattern = text
1416
+ //remove leading and trailing slashes
1417
+ .substring(1, text.length - 1)
1418
+ //escape quotemarks
1419
+ .split('"').join('" + chr(34) + "');
1420
+ return [
1421
+ state.sourceNode(this.tokens.regexLiteral, [
1422
+ 'CreateObject("roRegex", ',
1423
+ `"${pattern}", `,
1424
+ `"${flags}"`,
1425
+ ')'
1426
+ ])
1427
+ ];
1428
+ }
1429
+ walk(visitor, options) {
1430
+ //nothing to walk
1431
+ }
1432
+ getLeadingTrivia() {
1433
+ var _a, _b;
1434
+ return (_b = (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.leadingTrivia) !== null && _b !== void 0 ? _b : [];
1435
+ }
1436
+ }
1437
+ exports.RegexLiteralExpression = RegexLiteralExpression;
1070
1438
  function expressionToValue(expr, strict) {
1071
1439
  if (!expr) {
1072
1440
  return null;
1073
1441
  }
1074
- if (reflection_1.isUnaryExpression(expr) && reflection_1.isLiteralNumber(expr.right)) {
1075
- return numberExpressionToValue(expr.right, expr.operator.text);
1442
+ if ((0, reflection_1.isUnaryExpression)(expr) && (0, reflection_1.isLiteralNumber)(expr.right)) {
1443
+ return numberExpressionToValue(expr.right, expr.tokens.operator.text);
1076
1444
  }
1077
- if (reflection_1.isLiteralString(expr)) {
1445
+ if ((0, reflection_1.isLiteralString)(expr)) {
1078
1446
  //remove leading and trailing quotes
1079
- return expr.token.text.replace(/^"/, '').replace(/"$/, '');
1447
+ return expr.tokens.value.text.replace(/^"/, '').replace(/"$/, '');
1080
1448
  }
1081
- if (reflection_1.isLiteralNumber(expr)) {
1449
+ if ((0, reflection_1.isLiteralNumber)(expr)) {
1082
1450
  return numberExpressionToValue(expr);
1083
1451
  }
1084
- if (reflection_1.isLiteralBoolean(expr)) {
1085
- return expr.token.text.toLowerCase() === 'true';
1452
+ if ((0, reflection_1.isLiteralBoolean)(expr)) {
1453
+ return expr.tokens.value.text.toLowerCase() === 'true';
1086
1454
  }
1087
- if (reflection_1.isArrayLiteralExpression(expr)) {
1455
+ if ((0, reflection_1.isArrayLiteralExpression)(expr)) {
1088
1456
  return expr.elements
1089
- .filter(e => !reflection_1.isCommentStatement(e))
1090
1457
  .map(e => expressionToValue(e, strict));
1091
1458
  }
1092
- if (reflection_1.isAALiteralExpression(expr)) {
1459
+ if ((0, reflection_1.isAALiteralExpression)(expr)) {
1093
1460
  return expr.elements.reduce((acc, e) => {
1094
- if (!reflection_1.isCommentStatement(e)) {
1095
- acc[e.keyToken.text] = expressionToValue(e.value, strict);
1096
- }
1461
+ acc[e.tokens.key.text] = expressionToValue(e.value, strict);
1097
1462
  return acc;
1098
1463
  }, {});
1099
1464
  }
1100
1465
  return strict ? null : expr;
1101
1466
  }
1102
1467
  function numberExpressionToValue(expr, operator = '') {
1103
- if (reflection_1.isIntegerType(expr.type) || reflection_1.isLongIntegerType(expr.type)) {
1104
- return parseInt(operator + expr.token.text);
1468
+ if ((0, reflection_1.isIntegerType)(expr.getType()) || (0, reflection_1.isLongIntegerType)(expr.getType())) {
1469
+ return parseInt(operator + expr.tokens.value.text);
1105
1470
  }
1106
1471
  else {
1107
- return parseFloat(operator + expr.token.text);
1472
+ return parseFloat(operator + expr.tokens.value.text);
1473
+ }
1474
+ }
1475
+ class TypeExpression extends AstNode_1.Expression {
1476
+ constructor(options) {
1477
+ var _a;
1478
+ super();
1479
+ this.kind = AstNode_1.AstNodeKind.TypeExpression;
1480
+ this.expression = options.expression;
1481
+ this.range = (_a = this.expression) === null || _a === void 0 ? void 0 : _a.range;
1482
+ }
1483
+ transpile(state) {
1484
+ return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
1485
+ }
1486
+ walk(visitor, options) {
1487
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1488
+ (0, visitors_2.walk)(this, 'expression', visitor, options);
1489
+ }
1490
+ }
1491
+ getType(options) {
1492
+ return this.expression.getType(Object.assign(Object.assign({}, options), { flags: 2 /* SymbolTypeFlag.typetime */ }));
1493
+ }
1494
+ getTypedef(state) {
1495
+ // TypeDefs should pass through any valid type names
1496
+ return this.expression.transpile(state);
1497
+ }
1498
+ getName(parseMode = Parser_1.ParseMode.BrighterScript) {
1499
+ //TODO: this may not support Complex Types, eg. generics or Unions
1500
+ return util_1.default.getAllDottedGetPartsAsString(this.expression, parseMode);
1501
+ }
1502
+ getNameParts() {
1503
+ //TODO: really, this code is only used to get Namespaces. It could be more clear.
1504
+ return util_1.default.getAllDottedGetParts(this.expression).map(x => x.text);
1505
+ }
1506
+ }
1507
+ exports.TypeExpression = TypeExpression;
1508
+ class TypecastExpression extends AstNode_1.Expression {
1509
+ constructor(options) {
1510
+ super();
1511
+ this.kind = AstNode_1.AstNodeKind.TypecastExpression;
1512
+ this.tokens = {
1513
+ as: options.as
1514
+ };
1515
+ this.obj = options.obj;
1516
+ this.typeExpression = options.typeExpression;
1517
+ this.range = util_1.default.createBoundingRange(this.obj, this.tokens.as, this.typeExpression);
1518
+ }
1519
+ transpile(state) {
1520
+ return this.obj.transpile(state);
1521
+ }
1522
+ walk(visitor, options) {
1523
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1524
+ (0, visitors_2.walk)(this, 'obj', visitor, options);
1525
+ (0, visitors_2.walk)(this, 'typeExpression', visitor, options);
1526
+ }
1527
+ }
1528
+ getType(options) {
1529
+ const result = this.typeExpression.getType(options);
1530
+ if (options.typeChain) {
1531
+ // modify last typechain entry to show it is a typecast
1532
+ const lastEntry = options.typeChain[options.typeChain.length - 1];
1533
+ if (lastEntry) {
1534
+ lastEntry.astNode = this;
1535
+ }
1536
+ }
1537
+ return result;
1538
+ }
1539
+ }
1540
+ exports.TypecastExpression = TypecastExpression;
1541
+ class TypedArrayExpression extends AstNode_1.Expression {
1542
+ constructor(options) {
1543
+ super();
1544
+ this.kind = AstNode_1.AstNodeKind.TypedArrayExpression;
1545
+ this.tokens = {
1546
+ leftBracket: options.leftBracket,
1547
+ rightBracket: options.rightBracket
1548
+ };
1549
+ this.innerType = options.innerType;
1550
+ this.range = util_1.default.createBoundingRange(this.innerType, this.tokens.leftBracket, this.tokens.rightBracket);
1551
+ }
1552
+ transpile(state) {
1553
+ return [this.getType({ flags: 2 /* SymbolTypeFlag.typetime */ }).toTypeString()];
1554
+ }
1555
+ walk(visitor, options) {
1556
+ if (options.walkMode & visitors_2.InternalWalkMode.walkExpressions) {
1557
+ (0, visitors_2.walk)(this, 'innerType', visitor, options);
1558
+ }
1559
+ }
1560
+ getType(options) {
1561
+ return new ArrayType_1.ArrayType(this.innerType.getType(options));
1108
1562
  }
1109
1563
  }
1564
+ exports.TypedArrayExpression = TypedArrayExpression;
1110
1565
  //# sourceMappingURL=Expression.js.map