brighterscript 1.0.0-alpha.2 → 1.0.0-alpha.22

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 (388) hide show
  1. package/CHANGELOG.md +643 -253
  2. package/README.md +33 -9
  3. package/bsconfig.schema.json +22 -2
  4. package/dist/BsConfig.d.ts +9 -0
  5. package/dist/Cache.d.ts +5 -6
  6. package/dist/Cache.js +12 -11
  7. package/dist/Cache.js.map +1 -1
  8. package/dist/CodeActionUtil.d.ts +11 -2
  9. package/dist/CodeActionUtil.js +17 -3
  10. package/dist/CodeActionUtil.js.map +1 -1
  11. package/dist/CommentFlagProcessor.d.ts +4 -4
  12. package/dist/CommentFlagProcessor.js +5 -3
  13. package/dist/CommentFlagProcessor.js.map +1 -1
  14. package/dist/DependencyGraph.d.ts +2 -2
  15. package/dist/DependencyGraph.js +20 -7
  16. package/dist/DependencyGraph.js.map +1 -1
  17. package/dist/DiagnosticCollection.d.ts +3 -3
  18. package/dist/DiagnosticCollection.js +11 -11
  19. package/dist/DiagnosticCollection.js.map +1 -1
  20. package/dist/DiagnosticFilterer.js +5 -4
  21. package/dist/DiagnosticFilterer.js.map +1 -1
  22. package/dist/DiagnosticMessages.d.ts +59 -4
  23. package/dist/DiagnosticMessages.js +65 -7
  24. package/dist/DiagnosticMessages.js.map +1 -1
  25. package/dist/LanguageServer.d.ts +51 -39
  26. package/dist/LanguageServer.js +316 -232
  27. package/dist/LanguageServer.js.map +1 -1
  28. package/dist/Logger.d.ts +2 -0
  29. package/dist/Logger.js +10 -8
  30. package/dist/Logger.js.map +1 -1
  31. package/dist/PluginInterface.d.ts +7 -3
  32. package/dist/PluginInterface.js +9 -0
  33. package/dist/PluginInterface.js.map +1 -1
  34. package/dist/Program.d.ts +43 -25
  35. package/dist/Program.js +212 -95
  36. package/dist/Program.js.map +1 -1
  37. package/dist/ProgramBuilder.d.ts +4 -0
  38. package/dist/ProgramBuilder.js +36 -20
  39. package/dist/ProgramBuilder.js.map +1 -1
  40. package/dist/Scope.d.ts +126 -29
  41. package/dist/Scope.js +433 -156
  42. package/dist/Scope.js.map +1 -1
  43. package/dist/SemanticTokenUtils.d.ts +14 -0
  44. package/dist/SemanticTokenUtils.js +81 -0
  45. package/dist/SemanticTokenUtils.js.map +1 -0
  46. package/dist/SymbolTable.d.ts +10 -4
  47. package/dist/SymbolTable.js +55 -13
  48. package/dist/SymbolTable.js.map +1 -1
  49. package/dist/XmlScope.d.ts +7 -2
  50. package/dist/XmlScope.js +65 -27
  51. package/dist/XmlScope.js.map +1 -1
  52. package/dist/astUtils/AstEditor.d.ts +65 -0
  53. package/dist/astUtils/AstEditor.js +239 -0
  54. package/dist/astUtils/AstEditor.js.map +1 -0
  55. package/dist/{types/FunctionType.spec.d.ts → astUtils/AstEditor.spec.d.ts} +0 -0
  56. package/dist/astUtils/AstEditor.spec.js +254 -0
  57. package/dist/astUtils/AstEditor.spec.js.map +1 -0
  58. package/dist/astUtils/creators.d.ts +28 -6
  59. package/dist/astUtils/creators.js +137 -19
  60. package/dist/astUtils/creators.js.map +1 -1
  61. package/dist/astUtils/creators.spec.js +14 -4
  62. package/dist/astUtils/creators.spec.js.map +1 -1
  63. package/dist/astUtils/reflection.d.ts +32 -10
  64. package/dist/astUtils/reflection.js +82 -7
  65. package/dist/astUtils/reflection.js.map +1 -1
  66. package/dist/astUtils/reflection.spec.js +130 -119
  67. package/dist/astUtils/reflection.spec.js.map +1 -1
  68. package/dist/astUtils/stackedVisitor.js.map +1 -1
  69. package/dist/astUtils/stackedVisitor.spec.js +13 -13
  70. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  71. package/dist/astUtils/visitors.d.ts +76 -51
  72. package/dist/astUtils/visitors.js +31 -11
  73. package/dist/astUtils/visitors.js.map +1 -1
  74. package/dist/astUtils/visitors.spec.js +126 -32
  75. package/dist/astUtils/visitors.spec.js.map +1 -1
  76. package/dist/astUtils/xml.d.ts +4 -3
  77. package/dist/astUtils/xml.js +8 -3
  78. package/dist/astUtils/xml.js.map +1 -1
  79. package/dist/bscPlugin/BscPlugin.d.ts +7 -1
  80. package/dist/bscPlugin/BscPlugin.js +28 -0
  81. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  82. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +4 -4
  83. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  84. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +26 -26
  85. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  86. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +9 -0
  87. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +108 -0
  88. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
  89. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
  90. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +130 -0
  91. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
  92. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +8 -0
  93. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +52 -0
  94. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
  95. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +1 -0
  96. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
  97. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
  98. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +9 -0
  99. package/dist/bscPlugin/validation/BrsFileValidator.js +66 -0
  100. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
  101. package/dist/bscPlugin/validation/ScopeValidator.d.ts +29 -0
  102. package/dist/bscPlugin/validation/ScopeValidator.js +183 -0
  103. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
  104. package/dist/cli.js +10 -3
  105. package/dist/cli.js.map +1 -1
  106. package/dist/diagnosticUtils.d.ts +1 -0
  107. package/dist/diagnosticUtils.js +15 -8
  108. package/dist/diagnosticUtils.js.map +1 -1
  109. package/dist/examples/plugins/removePrint.js +12 -14
  110. package/dist/examples/plugins/removePrint.js.map +1 -1
  111. package/dist/files/BrsFile.Class.spec.js +717 -147
  112. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  113. package/dist/files/BrsFile.d.ts +70 -30
  114. package/dist/files/BrsFile.js +719 -353
  115. package/dist/files/BrsFile.js.map +1 -1
  116. package/dist/files/BrsFile.spec.js +1238 -449
  117. package/dist/files/BrsFile.spec.js.map +1 -1
  118. package/dist/files/XmlFile.d.ts +6 -5
  119. package/dist/files/XmlFile.js +38 -30
  120. package/dist/files/XmlFile.js.map +1 -1
  121. package/dist/files/XmlFile.spec.js +302 -237
  122. package/dist/files/XmlFile.spec.js.map +1 -1
  123. package/dist/files/tests/imports.spec.js +44 -42
  124. package/dist/files/tests/imports.spec.js.map +1 -1
  125. package/dist/files/tests/optionalChaning.spec.d.ts +1 -0
  126. package/dist/files/tests/optionalChaning.spec.js +88 -0
  127. package/dist/files/tests/optionalChaning.spec.js.map +1 -0
  128. package/dist/globalCallables.d.ts +3 -1
  129. package/dist/globalCallables.js +424 -152
  130. package/dist/globalCallables.js.map +1 -1
  131. package/dist/index.d.ts +13 -3
  132. package/dist/index.js +28 -5
  133. package/dist/index.js.map +1 -1
  134. package/dist/interfaces.d.ts +133 -16
  135. package/dist/lexer/Lexer.d.ts +19 -1
  136. package/dist/lexer/Lexer.js +127 -21
  137. package/dist/lexer/Lexer.js.map +1 -1
  138. package/dist/lexer/Lexer.spec.js +657 -536
  139. package/dist/lexer/Lexer.spec.js.map +1 -1
  140. package/dist/lexer/Token.d.ts +2 -2
  141. package/dist/lexer/TokenKind.d.ts +13 -1
  142. package/dist/lexer/TokenKind.js +60 -3
  143. package/dist/lexer/TokenKind.js.map +1 -1
  144. package/dist/parser/BrsTranspileState.d.ts +9 -0
  145. package/dist/parser/BrsTranspileState.js +14 -0
  146. package/dist/parser/BrsTranspileState.js.map +1 -1
  147. package/dist/parser/Expression.d.ts +150 -34
  148. package/dist/parser/Expression.js +335 -165
  149. package/dist/parser/Expression.js.map +1 -1
  150. package/dist/parser/Parser.Class.spec.js +189 -89
  151. package/dist/parser/Parser.Class.spec.js.map +1 -1
  152. package/dist/parser/Parser.d.ts +153 -30
  153. package/dist/parser/Parser.js +1100 -503
  154. package/dist/parser/Parser.js.map +1 -1
  155. package/dist/parser/Parser.spec.js +687 -266
  156. package/dist/parser/Parser.spec.js.map +1 -1
  157. package/dist/parser/SGParser.d.ts +41 -4
  158. package/dist/parser/SGParser.js +186 -175
  159. package/dist/parser/SGParser.js.map +1 -1
  160. package/dist/parser/SGParser.spec.js +35 -22
  161. package/dist/parser/SGParser.spec.js.map +1 -1
  162. package/dist/parser/SGTypes.d.ts +206 -38
  163. package/dist/parser/SGTypes.js +470 -161
  164. package/dist/parser/SGTypes.js.map +1 -1
  165. package/dist/parser/SGTypes.spec.d.ts +1 -0
  166. package/dist/parser/SGTypes.spec.js +351 -0
  167. package/dist/parser/SGTypes.spec.js.map +1 -0
  168. package/dist/parser/Statement.d.ts +202 -48
  169. package/dist/parser/Statement.js +648 -193
  170. package/dist/parser/Statement.js.map +1 -1
  171. package/dist/parser/Statement.spec.js +11 -11
  172. package/dist/parser/Statement.spec.js.map +1 -1
  173. package/dist/parser/TranspileState.d.ts +1 -1
  174. package/dist/parser/TranspileState.js +15 -7
  175. package/dist/parser/TranspileState.js.map +1 -1
  176. package/dist/parser/tests/Parser.spec.d.ts +10 -9
  177. package/dist/parser/tests/Parser.spec.js +15 -11
  178. package/dist/parser/tests/Parser.spec.js.map +1 -1
  179. package/dist/parser/tests/controlFlow/For.spec.js +60 -60
  180. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  181. package/dist/parser/tests/controlFlow/ForEach.spec.js +40 -39
  182. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  183. package/dist/parser/tests/controlFlow/If.spec.js +213 -194
  184. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  185. package/dist/parser/tests/controlFlow/While.spec.js +37 -37
  186. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  187. package/dist/parser/tests/expression/Additive.spec.js +30 -30
  188. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  189. package/dist/parser/tests/expression/ArrayLiterals.spec.js +119 -119
  190. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  191. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +162 -138
  192. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  193. package/dist/parser/tests/expression/Boolean.spec.js +24 -24
  194. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  195. package/dist/parser/tests/expression/Call.spec.js +41 -40
  196. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  197. package/dist/parser/tests/expression/Exponential.spec.js +17 -17
  198. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  199. package/dist/parser/tests/expression/Function.spec.js +256 -256
  200. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  201. package/dist/parser/tests/expression/Indexing.spec.js +87 -87
  202. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  203. package/dist/parser/tests/expression/Multiplicative.spec.js +37 -37
  204. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  205. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +75 -63
  206. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  207. package/dist/parser/tests/expression/PrefixUnary.spec.js +41 -41
  208. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  209. package/dist/parser/tests/expression/Primary.spec.js +41 -41
  210. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  211. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
  212. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +171 -0
  213. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
  214. package/dist/parser/tests/expression/Relational.spec.js +43 -43
  215. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  216. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +9 -9
  217. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  218. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +28 -28
  219. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  220. package/dist/parser/tests/expression/TernaryExpression.spec.js +102 -102
  221. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  222. package/dist/parser/tests/statement/AssignmentOperators.spec.js +36 -36
  223. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  224. package/dist/parser/tests/statement/Declaration.spec.js +44 -44
  225. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  226. package/dist/parser/tests/statement/Dim.spec.js +21 -21
  227. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  228. package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
  229. package/dist/parser/tests/statement/Enum.spec.js +840 -0
  230. package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
  231. package/dist/parser/tests/statement/For.spec.d.ts +1 -0
  232. package/dist/parser/tests/statement/For.spec.js +46 -0
  233. package/dist/parser/tests/statement/For.spec.js.map +1 -0
  234. package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
  235. package/dist/parser/tests/statement/ForEach.spec.js +37 -0
  236. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
  237. package/dist/parser/tests/statement/Function.spec.js +198 -197
  238. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  239. package/dist/parser/tests/statement/Goto.spec.js +15 -14
  240. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  241. package/dist/parser/tests/statement/Increment.spec.js +50 -50
  242. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  243. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
  244. package/dist/parser/tests/statement/InterfaceStatement.spec.js +254 -0
  245. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
  246. package/dist/parser/tests/statement/LibraryStatement.spec.js +17 -17
  247. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  248. package/dist/parser/tests/statement/Misc.spec.js +108 -106
  249. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  250. package/dist/parser/tests/statement/PrintStatement.spec.js +40 -40
  251. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  252. package/dist/parser/tests/statement/ReturnStatement.spec.js +46 -46
  253. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  254. package/dist/parser/tests/statement/Set.spec.js +83 -83
  255. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  256. package/dist/parser/tests/statement/Stop.spec.js +12 -11
  257. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  258. package/dist/parser/tests/statement/Throw.spec.js +5 -5
  259. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  260. package/dist/parser/tests/statement/TryCatch.spec.js +15 -13
  261. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  262. package/dist/preprocessor/Chunk.d.ts +1 -1
  263. package/dist/preprocessor/Chunk.js.map +1 -1
  264. package/dist/preprocessor/Manifest.d.ts +5 -5
  265. package/dist/preprocessor/Manifest.js +14 -35
  266. package/dist/preprocessor/Manifest.js.map +1 -1
  267. package/dist/preprocessor/Manifest.spec.d.ts +1 -0
  268. package/dist/preprocessor/Manifest.spec.js +78 -103
  269. package/dist/preprocessor/Manifest.spec.js.map +1 -1
  270. package/dist/preprocessor/Preprocessor.d.ts +1 -1
  271. package/dist/preprocessor/Preprocessor.js +8 -8
  272. package/dist/preprocessor/Preprocessor.js.map +1 -1
  273. package/dist/preprocessor/Preprocessor.spec.js +49 -49
  274. package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
  275. package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
  276. package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
  277. package/dist/roku-types/data.json +21891 -0
  278. package/dist/roku-types/index.d.ts +6776 -0
  279. package/dist/roku-types/index.js +11 -0
  280. package/dist/roku-types/index.js.map +1 -0
  281. package/dist/types/ArrayType.d.ts +8 -5
  282. package/dist/types/ArrayType.js +52 -12
  283. package/dist/types/ArrayType.js.map +1 -1
  284. package/dist/types/ArrayType.spec.js +72 -11
  285. package/dist/types/ArrayType.spec.js.map +1 -1
  286. package/dist/types/BooleanType.d.ts +4 -2
  287. package/dist/types/BooleanType.js +9 -4
  288. package/dist/types/BooleanType.js.map +1 -1
  289. package/dist/types/BooleanType.spec.js +5 -3
  290. package/dist/types/BooleanType.spec.js.map +1 -1
  291. package/dist/types/BscType.d.ts +20 -5
  292. package/dist/types/BscType.js +24 -0
  293. package/dist/types/BscType.js.map +1 -1
  294. package/dist/types/CustomType.d.ts +8 -6
  295. package/dist/types/CustomType.js +20 -11
  296. package/dist/types/CustomType.js.map +1 -1
  297. package/dist/types/DoubleType.d.ts +2 -0
  298. package/dist/types/DoubleType.js +14 -9
  299. package/dist/types/DoubleType.js.map +1 -1
  300. package/dist/types/DoubleType.spec.js +5 -3
  301. package/dist/types/DoubleType.spec.js.map +1 -1
  302. package/dist/types/DynamicType.d.ts +2 -0
  303. package/dist/types/DynamicType.js +6 -2
  304. package/dist/types/DynamicType.js.map +1 -1
  305. package/dist/types/DynamicType.spec.js +2 -2
  306. package/dist/types/DynamicType.spec.js.map +1 -1
  307. package/dist/types/EnumType.d.ts +22 -0
  308. package/dist/types/EnumType.js +55 -0
  309. package/dist/types/EnumType.js.map +1 -0
  310. package/dist/types/FloatType.d.ts +2 -0
  311. package/dist/types/FloatType.js +14 -9
  312. package/dist/types/FloatType.js.map +1 -1
  313. package/dist/types/FloatType.spec.js +4 -2
  314. package/dist/types/FloatType.spec.js.map +1 -1
  315. package/dist/types/FunctionType.d.ts +7 -31
  316. package/dist/types/FunctionType.js +11 -57
  317. package/dist/types/FunctionType.js.map +1 -1
  318. package/dist/types/IntegerType.d.ts +2 -0
  319. package/dist/types/IntegerType.js +14 -9
  320. package/dist/types/IntegerType.js.map +1 -1
  321. package/dist/types/IntegerType.spec.js +5 -3
  322. package/dist/types/IntegerType.spec.js.map +1 -1
  323. package/dist/types/InterfaceType.d.ts +13 -4
  324. package/dist/types/InterfaceType.js +48 -8
  325. package/dist/types/InterfaceType.js.map +1 -1
  326. package/dist/types/InterfaceType.spec.d.ts +1 -0
  327. package/dist/types/InterfaceType.spec.js +194 -0
  328. package/dist/types/InterfaceType.spec.js.map +1 -0
  329. package/dist/types/InvalidType.d.ts +4 -2
  330. package/dist/types/InvalidType.js +10 -5
  331. package/dist/types/InvalidType.js.map +1 -1
  332. package/dist/types/InvalidType.spec.js +4 -2
  333. package/dist/types/InvalidType.spec.js.map +1 -1
  334. package/dist/types/LazyType.d.ts +8 -7
  335. package/dist/types/LazyType.js +22 -10
  336. package/dist/types/LazyType.js.map +1 -1
  337. package/dist/types/LongIntegerType.d.ts +2 -0
  338. package/dist/types/LongIntegerType.js +14 -9
  339. package/dist/types/LongIntegerType.js.map +1 -1
  340. package/dist/types/LongIntegerType.spec.js +4 -2
  341. package/dist/types/LongIntegerType.spec.js.map +1 -1
  342. package/dist/types/ObjectType.d.ts +8 -4
  343. package/dist/types/ObjectType.js +9 -4
  344. package/dist/types/ObjectType.js.map +1 -1
  345. package/dist/types/ObjectType.spec.js +2 -2
  346. package/dist/types/ObjectType.spec.js.map +1 -1
  347. package/dist/types/StringType.d.ts +4 -2
  348. package/dist/types/StringType.js +9 -4
  349. package/dist/types/StringType.js.map +1 -1
  350. package/dist/types/StringType.spec.js +4 -2
  351. package/dist/types/StringType.spec.js.map +1 -1
  352. package/dist/types/TypedFunctionType.d.ts +28 -0
  353. package/dist/types/TypedFunctionType.js +88 -0
  354. package/dist/types/TypedFunctionType.js.map +1 -0
  355. package/dist/types/TypedFunctionType.spec.d.ts +1 -0
  356. package/dist/types/TypedFunctionType.spec.js +37 -0
  357. package/dist/types/TypedFunctionType.spec.js.map +1 -0
  358. package/dist/types/UninitializedType.js +3 -3
  359. package/dist/types/UninitializedType.js.map +1 -1
  360. package/dist/types/VoidType.d.ts +4 -2
  361. package/dist/types/VoidType.js +8 -4
  362. package/dist/types/VoidType.js.map +1 -1
  363. package/dist/types/VoidType.spec.js +2 -2
  364. package/dist/types/VoidType.spec.js.map +1 -1
  365. package/dist/types/helpers.d.ts +42 -0
  366. package/dist/types/helpers.js +118 -0
  367. package/dist/types/helpers.js.map +1 -0
  368. package/dist/util.d.ts +91 -21
  369. package/dist/util.js +364 -114
  370. package/dist/util.js.map +1 -1
  371. package/dist/validators/ClassValidator.d.ts +19 -2
  372. package/dist/validators/ClassValidator.js +164 -103
  373. package/dist/validators/ClassValidator.js.map +1 -1
  374. package/package.json +30 -19
  375. package/dist/astUtils/index.d.ts +0 -7
  376. package/dist/astUtils/index.js +0 -26
  377. package/dist/astUtils/index.js.map +0 -1
  378. package/dist/lexer/index.d.ts +0 -3
  379. package/dist/lexer/index.js +0 -17
  380. package/dist/lexer/index.js.map +0 -1
  381. package/dist/parser/index.d.ts +0 -3
  382. package/dist/parser/index.js +0 -16
  383. package/dist/parser/index.js.map +0 -1
  384. package/dist/preprocessor/index.d.ts +0 -3
  385. package/dist/preprocessor/index.js +0 -16
  386. package/dist/preprocessor/index.js.map +0 -1
  387. package/dist/types/FunctionType.spec.js +0 -23
  388. package/dist/types/FunctionType.spec.js.map +0 -1
@@ -1,7 +1,7 @@
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.ArrayTypeExpression = 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.NamespacedVariableNameExpression = exports.FunctionParameterExpression = exports.FunctionExpression = exports.CallExpression = exports.BinaryExpression = exports.Expression = 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");
@@ -10,7 +10,9 @@ const reflection_1 = require("../astUtils/reflection");
10
10
  const VoidType_1 = require("../types/VoidType");
11
11
  const DynamicType_1 = require("../types/DynamicType");
12
12
  const SymbolTable_1 = require("../SymbolTable");
13
- const FunctionType_1 = require("../types/FunctionType");
13
+ const TypedFunctionType_1 = require("../types/TypedFunctionType");
14
+ const ObjectType_1 = require("../types/ObjectType");
15
+ const ArrayType_1 = require("../types/ArrayType");
14
16
  /** A BrightScript expression */
15
17
  class Expression {
16
18
  constructor() {
@@ -27,7 +29,7 @@ class BinaryExpression extends Expression {
27
29
  this.left = left;
28
30
  this.operator = operator;
29
31
  this.right = right;
30
- this.range = util_1.default.createRangeFromPositions(this.left.range.start, this.right.range.end);
32
+ this.range = util_1.default.createBoundingRange(this.left, this.right);
31
33
  }
32
34
  transpile(state) {
33
35
  return [
@@ -40,14 +42,18 @@ class BinaryExpression extends Expression {
40
42
  }
41
43
  walk(visitor, options) {
42
44
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
43
- visitors_1.walk(this, 'left', visitor, options);
44
- visitors_1.walk(this, 'right', visitor, options);
45
+ (0, visitors_1.walk)(this, 'left', visitor, options);
46
+ (0, visitors_1.walk)(this, 'right', visitor, options);
45
47
  }
46
48
  }
47
49
  }
48
50
  exports.BinaryExpression = BinaryExpression;
49
51
  class CallExpression extends Expression {
50
- constructor(callee, openingParen, closingParen, args,
52
+ constructor(callee,
53
+ /**
54
+ * Can either be `(`, or `?(` for optional chaining
55
+ */
56
+ openingParen, closingParen, args,
51
57
  /**
52
58
  * 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
59
  */
@@ -58,7 +64,7 @@ class CallExpression extends Expression {
58
64
  this.closingParen = closingParen;
59
65
  this.args = args;
60
66
  this.namespaceName = namespaceName;
61
- this.range = util_1.default.createRangeFromPositions(this.callee.range.start, this.closingParen.range.end);
67
+ this.range = util_1.default.createBoundingRange(this.callee, this.closingParen);
62
68
  }
63
69
  transpile(state, nameOverride) {
64
70
  let result = [];
@@ -83,17 +89,15 @@ class CallExpression extends Expression {
83
89
  }
84
90
  walk(visitor, options) {
85
91
  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
- }
92
+ (0, visitors_1.walk)(this, 'callee', visitor, options);
93
+ (0, visitors_1.walkArray)(this.args, visitor, options, this);
90
94
  }
91
95
  }
92
96
  }
93
97
  exports.CallExpression = CallExpression;
94
- CallExpression.MaximumArguments = 32;
98
+ CallExpression.MaximumArguments = util_1.MAX_PARAM_COUNT;
95
99
  class FunctionExpression extends Expression {
96
- constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnTypeToken,
100
+ constructor(parameters, body, functionType, end, leftParen, rightParen, asToken, returnType,
97
101
  /**
98
102
  * If this function is enclosed within another function, this will reference that parent function
99
103
  */
@@ -106,7 +110,7 @@ class FunctionExpression extends Expression {
106
110
  this.leftParen = leftParen;
107
111
  this.rightParen = rightParen;
108
112
  this.asToken = asToken;
109
- this.returnTypeToken = returnTypeToken;
113
+ this.returnType = returnType;
110
114
  this.parentFunction = parentFunction;
111
115
  this.namespaceName = namespaceName;
112
116
  this.parentSymbolTable = parentSymbolTable;
@@ -120,27 +124,46 @@ class FunctionExpression extends Expression {
120
124
  * A list of all child functions declared directly within this function
121
125
  */
122
126
  this.childFunctionExpressions = [];
123
- if (this.returnTypeToken) {
124
- this.returnType = util_1.default.tokenToBscType(this.returnTypeToken);
127
+ if (this.returnType) {
128
+ this._returnType = this.returnType.type;
125
129
  }
126
130
  else if (this.functionType.text.toLowerCase() === 'sub') {
127
- this.returnType = new VoidType_1.VoidType();
131
+ this._returnType = new VoidType_1.VoidType();
128
132
  }
129
133
  else {
130
- this.returnType = new DynamicType_1.DynamicType();
134
+ this._returnType = new DynamicType_1.DynamicType();
131
135
  }
132
136
  this.symbolTable = new SymbolTable_1.SymbolTable(parentSymbolTable);
133
137
  for (let param of parameters) {
134
- this.symbolTable.addSymbol(param.name.text, param.name.range, param.type);
138
+ this.symbolTable.addSymbol(param.name.text, param.name.range, param.getType());
135
139
  }
136
140
  }
141
+ get range() {
142
+ return this.cacheRange();
143
+ }
137
144
  /**
138
- * 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
- * and ending with the last n' in 'end function' or 'b' in 'end sub'
145
+ * The range of the function
140
146
  */
141
- get range() {
142
- var _a, _b, _c, _d, _e;
143
- return util_1.default.createRangeFromPositions(((_a = this.functionType) !== null && _a !== void 0 ? _a : this.leftParen).range.start, ((_e = (_d = (_c = (_b = this.end) !== null && _b !== void 0 ? _b : this.body) !== null && _c !== void 0 ? _c : this.returnTypeToken) !== null && _d !== void 0 ? _d : this.asToken) !== null && _e !== void 0 ? _e : this.rightParen).range.end);
147
+ cacheRange() {
148
+ var _a;
149
+ if (!this._range) {
150
+ this._range = util_1.default.createBoundingRange(this.functionType, this.leftParen, ...((_a = this.parameters) !== null && _a !== void 0 ? _a : []), this.rightParen, this.asToken, this.returnType, this.body, this.end);
151
+ }
152
+ return this._range;
153
+ }
154
+ /**
155
+ * The type this function returns
156
+ */
157
+ getReturnType() {
158
+ return this._returnType;
159
+ }
160
+ /**
161
+ * The range of the function declaration, starting at the 'f' in function or 's' in sub (or the open paren if the keyword is missing),
162
+ * and ending with the last character in the returnTypeToken, or the 's' in 'as', or the rightParen
163
+ */
164
+ get functionDeclarationRange() {
165
+ var _a;
166
+ return util_1.default.createBoundingRange(this.functionType, this.leftParen, ...((_a = this.parameters) !== null && _a !== void 0 ? _a : []), this.rightParen, this.asToken, this.returnType);
144
167
  }
145
168
  transpile(state, name, includeBody = true) {
146
169
  let results = [];
@@ -170,7 +193,7 @@ class FunctionExpression extends Expression {
170
193
  //as
171
194
  state.transpileToken(this.asToken), ' ',
172
195
  //return type
173
- state.sourceNode(this.returnTypeToken, this.returnType.toTypeString()));
196
+ state.sourceNode(this.returnType, this.getReturnType().toTypeString(state.typeContext)));
174
197
  }
175
198
  if (includeBody) {
176
199
  state.lineage.unshift(this);
@@ -178,9 +201,11 @@ class FunctionExpression extends Expression {
178
201
  state.lineage.shift();
179
202
  results.push(...body);
180
203
  }
181
- results.push('\n');
182
- //'end sub'|'end function'
183
- results.push(state.indent(), state.transpileToken(this.end));
204
+ if (this.end) {
205
+ results.push('\n');
206
+ //'end sub'|'end function'
207
+ results.push(state.indent(), state.transpileToken(this.end));
208
+ }
184
209
  return results;
185
210
  }
186
211
  getTypedef(state, name) {
@@ -188,43 +213,38 @@ class FunctionExpression extends Expression {
188
213
  }
189
214
  walk(visitor, options) {
190
215
  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
- }
216
+ (0, visitors_1.walkArray)(this.parameters, visitor, options, this);
194
217
  //This is the core of full-program walking...it allows us to step into sub functions
195
218
  if (options.walkMode & visitors_1.InternalWalkMode.recurseChildFunctions) {
196
- visitors_1.walk(this, 'body', visitor, options);
219
+ (0, visitors_1.walk)(this, 'returnType', visitor, options);
220
+ (0, visitors_1.walk)(this, 'body', visitor, options);
197
221
  }
198
222
  }
199
223
  }
200
224
  getFunctionType() {
201
- let functionType = new FunctionType_1.FunctionType(this.returnType);
225
+ let functionType = new TypedFunctionType_1.TypedFunctionType(this.getReturnType());
202
226
  functionType.isSub = this.functionType.text === 'sub';
203
227
  for (let param of this.parameters) {
204
- let isRequired = !param.defaultValue;
205
- //TODO compute optional parameters
206
- functionType.addParameter(param.name.text, param.type, isRequired);
228
+ functionType.addParameter(param.name.text, param.getType(), param.isOptional);
207
229
  }
208
230
  return functionType;
209
231
  }
210
232
  }
211
233
  exports.FunctionExpression = FunctionExpression;
212
234
  class FunctionParameterExpression extends Expression {
213
- constructor(name, type, equalsToken, defaultValue, asToken, typeToken, namespaceName) {
235
+ constructor(name, typeInContext, equalsToken, defaultValue, asToken, type, namespaceName) {
214
236
  super();
215
237
  this.name = name;
216
- this.type = type;
238
+ this.typeInContext = typeInContext;
217
239
  this.equalsToken = equalsToken;
218
240
  this.defaultValue = defaultValue;
219
241
  this.asToken = asToken;
220
- this.typeToken = typeToken;
242
+ this.type = type;
221
243
  this.namespaceName = namespaceName;
244
+ this.range = util_1.default.createBoundingRange(this.name, this.equalsToken, this.defaultValue, this.asToken, this.type);
222
245
  }
223
- get range() {
224
- return {
225
- start: this.name.range.start,
226
- end: this.typeToken ? this.typeToken.range.end : this.name.range.end
227
- };
246
+ getType() {
247
+ return this.typeInContext;
228
248
  }
229
249
  transpile(state) {
230
250
  let result = [
@@ -241,16 +261,20 @@ class FunctionParameterExpression extends Expression {
241
261
  result.push(' ');
242
262
  result.push(state.transpileToken(this.asToken));
243
263
  result.push(' ');
244
- result.push(state.sourceNode(this.typeToken, this.type.toTypeString()));
264
+ result.push(state.sourceNode(this.type, this.getType().toTypeString(state.typeContext)));
245
265
  }
246
266
  return result;
247
267
  }
248
268
  walk(visitor, options) {
249
269
  // eslint-disable-next-line no-bitwise
250
270
  if (this.defaultValue && options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
251
- visitors_1.walk(this, 'defaultValue', visitor, options);
271
+ (0, visitors_1.walk)(this, 'defaultValue', visitor, options);
272
+ (0, visitors_1.walk)(this, 'type', visitor, options);
252
273
  }
253
274
  }
275
+ get isOptional() {
276
+ return !!this.defaultValue;
277
+ }
254
278
  }
255
279
  exports.FunctionParameterExpression = FunctionParameterExpression;
256
280
  class NamespacedVariableNameExpression extends Expression {
@@ -268,20 +292,20 @@ class NamespacedVariableNameExpression extends Expression {
268
292
  }
269
293
  getNameParts() {
270
294
  let parts = [];
271
- if (reflection_1.isVariableExpression(this.expression)) {
295
+ if ((0, reflection_1.isVariableExpression)(this.expression)) {
272
296
  parts.push(this.expression.name.text);
273
297
  }
274
298
  else {
275
299
  let expr = this.expression;
276
300
  parts.push(expr.name.text);
277
- while (reflection_1.isVariableExpression(expr) === false) {
301
+ while ((0, reflection_1.isVariableExpression)(expr) === false) {
278
302
  expr = expr.obj;
279
303
  parts.unshift(expr.name.text);
280
304
  }
281
305
  }
282
306
  return parts;
283
307
  }
284
- getName(parseMode) {
308
+ getName(parseMode = Parser_1.ParseMode.BrighterScript) {
285
309
  if (parseMode === Parser_1.ParseMode.BrighterScript) {
286
310
  return this.getNameParts().join('.');
287
311
  }
@@ -291,18 +315,22 @@ class NamespacedVariableNameExpression extends Expression {
291
315
  }
292
316
  walk(visitor, options) {
293
317
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
294
- visitors_1.walk(this, 'expression', visitor, options);
318
+ (0, visitors_1.walk)(this, 'expression', visitor, options);
295
319
  }
296
320
  }
297
321
  }
298
322
  exports.NamespacedVariableNameExpression = NamespacedVariableNameExpression;
299
323
  class DottedGetExpression extends Expression {
300
- constructor(obj, name, dot) {
324
+ constructor(obj, name,
325
+ /**
326
+ * Can either be `.`, or `?.` for optional chaining
327
+ */
328
+ dot) {
301
329
  super();
302
330
  this.obj = obj;
303
331
  this.name = name;
304
332
  this.dot = dot;
305
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.name.range.end);
333
+ this.range = util_1.default.createBoundingRange(this.obj, this.dot, this.name);
306
334
  }
307
335
  transpile(state) {
308
336
  //if the callee starts with a namespace name, transpile the name
@@ -312,52 +340,63 @@ class DottedGetExpression extends Expression {
312
340
  else {
313
341
  return [
314
342
  ...this.obj.transpile(state),
315
- '.',
343
+ state.transpileToken(this.dot),
316
344
  state.transpileToken(this.name)
317
345
  ];
318
346
  }
319
347
  }
320
348
  walk(visitor, options) {
321
349
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
322
- visitors_1.walk(this, 'obj', visitor, options);
350
+ (0, visitors_1.walk)(this, 'obj', visitor, options);
323
351
  }
324
352
  }
325
353
  }
326
354
  exports.DottedGetExpression = DottedGetExpression;
327
355
  class XmlAttributeGetExpression extends Expression {
328
- constructor(obj, name, at) {
356
+ constructor(obj, name,
357
+ /**
358
+ * Can either be `@`, or `?@` for optional chaining
359
+ */
360
+ at) {
329
361
  super();
330
362
  this.obj = obj;
331
363
  this.name = name;
332
364
  this.at = at;
333
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.name.range.end);
365
+ this.range = util_1.default.createBoundingRange(this.obj, this.at, this.name);
334
366
  }
335
367
  transpile(state) {
336
368
  return [
337
369
  ...this.obj.transpile(state),
338
- '@',
370
+ state.transpileToken(this.at),
339
371
  state.transpileToken(this.name)
340
372
  ];
341
373
  }
342
374
  walk(visitor, options) {
343
375
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
344
- visitors_1.walk(this, 'obj', visitor, options);
376
+ (0, visitors_1.walk)(this, 'obj', visitor, options);
345
377
  }
346
378
  }
347
379
  }
348
380
  exports.XmlAttributeGetExpression = XmlAttributeGetExpression;
349
381
  class IndexedGetExpression extends Expression {
350
- constructor(obj, index, openingSquare, closingSquare) {
382
+ constructor(obj, index,
383
+ /**
384
+ * Can either be `[` or `?[`. If `?.[` is used, this will be `[` and `optionalChainingToken` will be `?.`
385
+ */
386
+ openingSquare, closingSquare, questionDotToken // ? or ?.
387
+ ) {
351
388
  super();
352
389
  this.obj = obj;
353
390
  this.index = index;
354
391
  this.openingSquare = openingSquare;
355
392
  this.closingSquare = closingSquare;
356
- this.range = util_1.default.createRangeFromPositions(this.obj.range.start, this.closingSquare.range.end);
393
+ this.questionDotToken = questionDotToken;
394
+ this.range = util_1.default.createBoundingRange(this.obj, this.openingSquare, this.questionDotToken, this.openingSquare, this.index, this.closingSquare);
357
395
  }
358
396
  transpile(state) {
359
397
  return [
360
398
  ...this.obj.transpile(state),
399
+ this.questionDotToken ? state.transpileToken(this.questionDotToken) : '',
361
400
  state.transpileToken(this.openingSquare),
362
401
  ...this.index.transpile(state),
363
402
  state.transpileToken(this.closingSquare)
@@ -365,8 +404,8 @@ class IndexedGetExpression extends Expression {
365
404
  }
366
405
  walk(visitor, options) {
367
406
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
368
- visitors_1.walk(this, 'obj', visitor, options);
369
- visitors_1.walk(this, 'index', visitor, options);
407
+ (0, visitors_1.walk)(this, 'obj', visitor, options);
408
+ (0, visitors_1.walk)(this, 'index', visitor, options);
370
409
  }
371
410
  }
372
411
  }
@@ -376,7 +415,7 @@ class GroupingExpression extends Expression {
376
415
  super();
377
416
  this.tokens = tokens;
378
417
  this.expression = expression;
379
- this.range = util_1.default.createRangeFromPositions(this.tokens.left.range.start, this.tokens.right.range.end);
418
+ this.range = util_1.default.createBoundingRange(this.tokens.left, this.expression, this.tokens.right);
380
419
  }
381
420
  transpile(state) {
382
421
  return [
@@ -387,7 +426,7 @@ class GroupingExpression extends Expression {
387
426
  }
388
427
  walk(visitor, options) {
389
428
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
390
- visitors_1.walk(this, 'expression', visitor, options);
429
+ (0, visitors_1.walk)(this, 'expression', visitor, options);
391
430
  }
392
431
  }
393
432
  }
@@ -396,18 +435,16 @@ class LiteralExpression extends Expression {
396
435
  constructor(token) {
397
436
  super();
398
437
  this.token = token;
438
+ this.range = this.token.range;
399
439
  this.type = util_1.default.tokenToBscType(token);
400
440
  }
401
- get range() {
402
- return this.token.range;
403
- }
404
441
  transpile(state) {
405
442
  let text;
406
- if (this.token.kind === lexer_1.TokenKind.TemplateStringQuasi) {
443
+ if (this.token.kind === TokenKind_1.TokenKind.TemplateStringQuasi) {
407
444
  //wrap quasis with quotes (and escape inner quotemarks)
408
445
  text = `"${this.token.text.replace(/"/g, '""')}"`;
409
446
  }
410
- else if (reflection_1.isStringType(this.type)) {
447
+ else if ((0, reflection_1.isStringType)(this.type)) {
411
448
  text = this.token.text;
412
449
  //add trailing quotemark if it's missing. We will have already generated a diagnostic for this.
413
450
  if (text.endsWith('"') === false) {
@@ -448,12 +485,13 @@ class EscapedCharCodeLiteralExpression extends Expression {
448
485
  exports.EscapedCharCodeLiteralExpression = EscapedCharCodeLiteralExpression;
449
486
  class ArrayLiteralExpression extends Expression {
450
487
  constructor(elements, open, close, hasSpread = false) {
488
+ var _a;
451
489
  super();
452
490
  this.elements = elements;
453
491
  this.open = open;
454
492
  this.close = close;
455
493
  this.hasSpread = hasSpread;
456
- this.range = util_1.default.createRangeFromPositions(this.open.range.start, this.close.range.end);
494
+ this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
457
495
  }
458
496
  transpile(state) {
459
497
  let result = [];
@@ -463,7 +501,7 @@ class ArrayLiteralExpression extends Expression {
463
501
  for (let i = 0; i < this.elements.length; i++) {
464
502
  let previousElement = this.elements[i - 1];
465
503
  let element = this.elements[i];
466
- if (reflection_1.isCommentStatement(element)) {
504
+ if ((0, reflection_1.isCommentStatement)(element)) {
467
505
  //if the comment is on the same line as opening square or previous statement, don't add newline
468
506
  if (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element)) {
469
507
  result.push(' ');
@@ -478,15 +516,6 @@ class ArrayLiteralExpression extends Expression {
478
516
  else {
479
517
  result.push('\n');
480
518
  result.push(state.indent(), ...element.transpile(state));
481
- //add a comma if we know there will be another non-comment statement after this
482
- for (let j = i + 1; j < this.elements.length; j++) {
483
- let el = this.elements[j];
484
- //add a comma if there will be another element after this
485
- if (reflection_1.isCommentStatement(el) === false) {
486
- result.push(',');
487
- break;
488
- }
489
- }
490
519
  }
491
520
  }
492
521
  state.blockDepth--;
@@ -500,9 +529,7 @@ class ArrayLiteralExpression extends Expression {
500
529
  }
501
530
  walk(visitor, options) {
502
531
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
503
- for (let i = 0; i < this.elements.length; i++) {
504
- visitors_1.walk(this.elements, i, visitor, options, this);
505
- }
532
+ (0, visitors_1.walkArray)(this.elements, visitor, options, this);
506
533
  }
507
534
  }
508
535
  }
@@ -510,29 +537,44 @@ exports.ArrayLiteralExpression = ArrayLiteralExpression;
510
537
  class AAMemberExpression extends Expression {
511
538
  constructor(keyToken, colonToken,
512
539
  /** The expression evaluated to determine the member's initial value. */
513
- value) {
540
+ value, type) {
514
541
  super();
515
542
  this.keyToken = keyToken;
516
543
  this.colonToken = colonToken;
517
544
  this.value = value;
518
- this.range = util_1.default.createRangeFromPositions(keyToken.range.start, this.value.range.end);
545
+ this.type = type;
546
+ this.range = util_1.default.createBoundingRange(this.keyToken, this.colonToken, this.value);
519
547
  }
520
548
  transpile(state) {
521
549
  //TODO move the logic from AALiteralExpression loop into this function
522
550
  return [];
523
551
  }
524
552
  walk(visitor, options) {
525
- visitors_1.walk(this, 'value', visitor, options);
553
+ (0, visitors_1.walk)(this, 'value', visitor, options);
526
554
  }
527
555
  }
528
556
  exports.AAMemberExpression = AAMemberExpression;
529
557
  class AALiteralExpression extends Expression {
530
- constructor(elements, open, close) {
558
+ constructor(elements, open, close, functionExpression) {
559
+ var _a;
531
560
  super();
532
561
  this.elements = elements;
533
562
  this.open = open;
534
563
  this.close = close;
535
- this.range = util_1.default.createRangeFromPositions(this.open.range.start, this.close.range.end);
564
+ this.functionExpression = functionExpression;
565
+ this.symbolTable = new SymbolTable_1.SymbolTable();
566
+ this.memberTable = new SymbolTable_1.SymbolTable();
567
+ this.range = util_1.default.createBoundingRange(this.open, ...((_a = this.elements) !== null && _a !== void 0 ? _a : []), this.close);
568
+ this.buildSymbolTable();
569
+ }
570
+ buildSymbolTable() {
571
+ this.symbolTable.clear();
572
+ this.symbolTable.addSymbol('m', { start: this.open.range.start, end: this.close.range.end }, new ObjectType_1.ObjectType('object', this.memberTable));
573
+ for (const element of this.elements) {
574
+ if ((0, reflection_1.isAAMemberExpression)(element)) {
575
+ this.memberTable.addSymbol(element.keyToken.text, element.keyToken.range, (0, Parser_1.getBscTypeFromExpression)(element.value, this.functionExpression));
576
+ }
577
+ }
536
578
  }
537
579
  transpile(state) {
538
580
  let result = [];
@@ -540,7 +582,7 @@ class AALiteralExpression extends Expression {
540
582
  result.push(state.transpileToken(this.open));
541
583
  let hasChildren = this.elements.length > 0;
542
584
  //add newline if the object has children and the first child isn't a comment starting on the same line as opening curly
543
- if (hasChildren && (reflection_1.isCommentStatement(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.open))) {
585
+ if (hasChildren && ((0, reflection_1.isCommentStatement)(this.elements[0]) === false || !util_1.default.linesTouch(this.elements[0], this.open))) {
544
586
  result.push('\n');
545
587
  }
546
588
  state.blockDepth++;
@@ -549,7 +591,7 @@ class AALiteralExpression extends Expression {
549
591
  let previousElement = this.elements[i - 1];
550
592
  let nextElement = this.elements[i + 1];
551
593
  //don't indent if comment is same-line
552
- if (reflection_1.isCommentStatement(element) &&
594
+ if ((0, reflection_1.isCommentStatement)(element) &&
553
595
  (util_1.default.linesTouch(this.open, element) || util_1.default.linesTouch(previousElement, element))) {
554
596
  result.push(' ');
555
597
  //indent line
@@ -558,7 +600,7 @@ class AALiteralExpression extends Expression {
558
600
  result.push(state.indent());
559
601
  }
560
602
  //render comments
561
- if (reflection_1.isCommentStatement(element)) {
603
+ if ((0, reflection_1.isCommentStatement)(element)) {
562
604
  result.push(...element.transpile(state));
563
605
  }
564
606
  else {
@@ -566,23 +608,11 @@ class AALiteralExpression extends Expression {
566
608
  result.push(state.transpileToken(element.keyToken));
567
609
  //colon
568
610
  result.push(state.transpileToken(element.colonToken), ' ');
569
- //determine if comments are the only members left in the array
570
- let onlyCommentsRemaining = true;
571
- for (let j = i + 1; j < this.elements.length; j++) {
572
- if (reflection_1.isCommentStatement(this.elements[j]) === false) {
573
- onlyCommentsRemaining = false;
574
- break;
575
- }
576
- }
577
611
  //value
578
612
  result.push(...element.value.transpile(state));
579
- //add trailing comma if not final element (excluding comments)
580
- if (i !== this.elements.length - 1 && onlyCommentsRemaining === false) {
581
- result.push(',');
582
- }
583
613
  }
584
614
  //if next element is a same-line comment, skip the newline
585
- if (nextElement && reflection_1.isCommentStatement(nextElement) && nextElement.range.start.line === element.range.start.line) {
615
+ if (nextElement && (0, reflection_1.isCommentStatement)(nextElement) && nextElement.range.start.line === element.range.start.line) {
586
616
  //add a newline between statements
587
617
  }
588
618
  else {
@@ -600,14 +630,7 @@ class AALiteralExpression extends Expression {
600
630
  }
601
631
  walk(visitor, options) {
602
632
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
603
- for (let i = 0; i < this.elements.length; i++) {
604
- if (reflection_1.isCommentStatement(this.elements[i])) {
605
- visitors_1.walk(this.elements, i, visitor, options, this);
606
- }
607
- else {
608
- visitors_1.walk(this.elements, i, visitor, options, this);
609
- }
610
- }
633
+ (0, visitors_1.walkArray)(this.elements, visitor, options, this);
611
634
  }
612
635
  }
613
636
  }
@@ -617,7 +640,7 @@ class UnaryExpression extends Expression {
617
640
  super();
618
641
  this.operator = operator;
619
642
  this.right = right;
620
- this.range = util_1.default.createRangeFromPositions(this.operator.range.start, this.right.range.end);
643
+ this.range = util_1.default.createBoundingRange(this.operator, this.right);
621
644
  }
622
645
  transpile(state) {
623
646
  return [
@@ -628,7 +651,7 @@ class UnaryExpression extends Expression {
628
651
  }
629
652
  walk(visitor, options) {
630
653
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
631
- visitors_1.walk(this, 'right', visitor, options);
654
+ (0, visitors_1.walk)(this, 'right', visitor, options);
632
655
  }
633
656
  }
634
657
  }
@@ -686,28 +709,30 @@ class SourceLiteralExpression extends Expression {
686
709
  transpile(state) {
687
710
  let text;
688
711
  switch (this.token.kind) {
689
- case lexer_1.TokenKind.SourceFilePathLiteral:
690
- text = `"${fileUrl(state.srcPath)}"`;
712
+ case TokenKind_1.TokenKind.SourceFilePathLiteral:
713
+ const pathUrl = fileUrl(state.srcPath);
714
+ text = `"${pathUrl.substring(0, 4)}" + "${pathUrl.substring(4)}"`;
691
715
  break;
692
- case lexer_1.TokenKind.SourceLineNumLiteral:
716
+ case TokenKind_1.TokenKind.SourceLineNumLiteral:
693
717
  text = `${this.token.range.start.line + 1}`;
694
718
  break;
695
- case lexer_1.TokenKind.FunctionNameLiteral:
719
+ case TokenKind_1.TokenKind.FunctionNameLiteral:
696
720
  text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrightScript)}"`;
697
721
  break;
698
- case lexer_1.TokenKind.SourceFunctionNameLiteral:
722
+ case TokenKind_1.TokenKind.SourceFunctionNameLiteral:
699
723
  text = `"${this.getFunctionName(state, Parser_1.ParseMode.BrighterScript)}"`;
700
724
  break;
701
- case lexer_1.TokenKind.SourceLocationLiteral:
702
- text = `"${fileUrl(state.srcPath)}:${this.token.range.start.line + 1}"`;
725
+ case TokenKind_1.TokenKind.SourceLocationLiteral:
726
+ const locationUrl = fileUrl(state.srcPath);
727
+ text = `"${locationUrl.substring(0, 4)}" + "${locationUrl.substring(4)}:${this.token.range.start.line + 1}"`;
703
728
  break;
704
- case lexer_1.TokenKind.PkgPathLiteral:
729
+ case TokenKind_1.TokenKind.PkgPathLiteral:
705
730
  text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}"`;
706
731
  break;
707
- case lexer_1.TokenKind.PkgLocationLiteral:
732
+ case TokenKind_1.TokenKind.PkgLocationLiteral:
708
733
  text = `"${state.file.pkgPath.replace(/\.bs$/i, '.brs')}:" + str(LINE_NUM)`;
709
734
  break;
710
- case lexer_1.TokenKind.LineNumLiteral:
735
+ case TokenKind_1.TokenKind.LineNumLiteral:
711
736
  default:
712
737
  //use the original text (because it looks like a variable)
713
738
  text = this.token.text;
@@ -732,7 +757,7 @@ class NewExpression extends Expression {
732
757
  super();
733
758
  this.newKeyword = newKeyword;
734
759
  this.call = call;
735
- this.range = util_1.default.createRangeFromPositions(this.newKeyword.range.start, this.call.range.end);
760
+ this.range = util_1.default.createBoundingRange(this.newKeyword, this.call);
736
761
  }
737
762
  /**
738
763
  * The name of the class to initialize (with optional namespace prefixed)
@@ -754,14 +779,14 @@ class NewExpression extends Expression {
754
779
  }
755
780
  walk(visitor, options) {
756
781
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
757
- visitors_1.walk(this, 'call', visitor, options);
782
+ (0, visitors_1.walk)(this, 'call', visitor, options);
758
783
  }
759
784
  }
760
785
  }
761
786
  exports.NewExpression = NewExpression;
762
787
  class CallfuncExpression extends Expression {
763
788
  constructor(callee, operator, methodName, openingParen, args, closingParen) {
764
- var _a, _b, _c;
789
+ var _a;
765
790
  super();
766
791
  this.callee = callee;
767
792
  this.operator = operator;
@@ -769,7 +794,7 @@ class CallfuncExpression extends Expression {
769
794
  this.openingParen = openingParen;
770
795
  this.args = args;
771
796
  this.closingParen = closingParen;
772
- 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);
797
+ this.range = util_1.default.createBoundingRange(this.callee, this.operator, this.methodName, this.openingParen, ...((_a = this.args) !== null && _a !== void 0 ? _a : []), this.closingParen);
773
798
  }
774
799
  transpile(state) {
775
800
  let result = [];
@@ -796,10 +821,8 @@ class CallfuncExpression extends Expression {
796
821
  }
797
822
  walk(visitor, options) {
798
823
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
799
- visitors_1.walk(this, 'callee', visitor, options);
800
- for (let i = 0; i < this.args.length; i++) {
801
- visitors_1.walk(this.args, i, visitor, options, this);
802
- }
824
+ (0, visitors_1.walk)(this, 'callee', visitor, options);
825
+ (0, visitors_1.walkArray)(this.args, visitor, options, this);
803
826
  }
804
827
  }
805
828
  }
@@ -810,9 +833,10 @@ exports.CallfuncExpression = CallfuncExpression;
810
833
  */
811
834
  class TemplateStringQuasiExpression extends Expression {
812
835
  constructor(expressions) {
836
+ var _a;
813
837
  super();
814
838
  this.expressions = expressions;
815
- this.range = util_1.default.createRangeFromPositions(this.expressions[0].range.start, this.expressions[this.expressions.length - 1].range.end);
839
+ this.range = util_1.default.createBoundingRange(...((_a = this.expressions) !== null && _a !== void 0 ? _a : []));
816
840
  }
817
841
  transpile(state, skipEmptyStrings = true) {
818
842
  let result = [];
@@ -830,21 +854,21 @@ class TemplateStringQuasiExpression extends Expression {
830
854
  }
831
855
  walk(visitor, options) {
832
856
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
833
- for (let i = 0; i < this.expressions.length; i++) {
834
- visitors_1.walk(this.expressions, i, visitor, options, this);
835
- }
857
+ (0, visitors_1.walkArray)(this.expressions, visitor, options, this);
836
858
  }
837
859
  }
838
860
  }
839
861
  exports.TemplateStringQuasiExpression = TemplateStringQuasiExpression;
840
862
  class TemplateStringExpression extends Expression {
841
863
  constructor(openingBacktick, quasis, expressions, closingBacktick) {
864
+ var _a;
842
865
  super();
843
866
  this.openingBacktick = openingBacktick;
844
867
  this.quasis = quasis;
845
868
  this.expressions = expressions;
846
869
  this.closingBacktick = closingBacktick;
847
- this.range = util_1.default.createRangeFromPositions(quasis[0].range.start, quasis[quasis.length - 1].range.end);
870
+ //the expression always starts and ends with a quasi, so we don't need to consider the expression locations
871
+ this.range = util_1.default.createBoundingRange(this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
848
872
  }
849
873
  transpile(state) {
850
874
  if (this.quasis.length === 1 && this.expressions.length === 0) {
@@ -868,8 +892,8 @@ class TemplateStringExpression extends Expression {
868
892
  add(...quasi.transpile(state));
869
893
  if (expression) {
870
894
  //skip the toString wrapper around certain expressions
871
- if (reflection_1.isEscapedCharCodeLiteralExpression(expression) ||
872
- (reflection_1.isLiteralExpression(expression) && reflection_1.isStringType(expression.type))) {
895
+ if ((0, reflection_1.isEscapedCharCodeLiteralExpression)(expression) ||
896
+ ((0, reflection_1.isLiteralExpression)(expression) && (0, reflection_1.isStringType)(expression.type))) {
873
897
  add(...expression.transpile(state));
874
898
  //wrap all other expressions with a bslib_toString call to prevent runtime type mismatch errors
875
899
  }
@@ -884,10 +908,10 @@ class TemplateStringExpression extends Expression {
884
908
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
885
909
  //walk the quasis and expressions in left-to-right order
886
910
  for (let i = 0; i < this.quasis.length; i++) {
887
- visitors_1.walk(this.quasis, i, visitor, options, this);
911
+ (0, visitors_1.walk)(this.quasis, i, visitor, options, this);
888
912
  //this skips the final loop iteration since we'll always have one more quasi than expression
889
913
  if (this.expressions[i]) {
890
- visitors_1.walk(this.expressions, i, visitor, options, this);
914
+ (0, visitors_1.walk)(this.expressions, i, visitor, options, this);
891
915
  }
892
916
  }
893
917
  }
@@ -896,13 +920,15 @@ class TemplateStringExpression extends Expression {
896
920
  exports.TemplateStringExpression = TemplateStringExpression;
897
921
  class TaggedTemplateStringExpression extends Expression {
898
922
  constructor(tagName, openingBacktick, quasis, expressions, closingBacktick) {
923
+ var _a;
899
924
  super();
900
925
  this.tagName = tagName;
901
926
  this.openingBacktick = openingBacktick;
902
927
  this.quasis = quasis;
903
928
  this.expressions = expressions;
904
929
  this.closingBacktick = closingBacktick;
905
- this.range = util_1.default.createRangeFromPositions(quasis[0].range.start, quasis[quasis.length - 1].range.end);
930
+ //the expression always starts and ends with a quasi, so we don't need to consider the expression locations
931
+ this.range = util_1.default.createBoundingRange(this.tagName, this.openingBacktick, ...((_a = this.quasis) !== null && _a !== void 0 ? _a : []), this.closingBacktick);
906
932
  }
907
933
  transpile(state) {
908
934
  let result = [];
@@ -932,10 +958,10 @@ class TaggedTemplateStringExpression extends Expression {
932
958
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
933
959
  //walk the quasis and expressions in left-to-right order
934
960
  for (let i = 0; i < this.quasis.length; i++) {
935
- visitors_1.walk(this.quasis, i, visitor, options, this);
961
+ (0, visitors_1.walk)(this.quasis, i, visitor, options, this);
936
962
  //this skips the final loop iteration since we'll always have one more quasi than expression
937
963
  if (this.expressions[i]) {
938
- visitors_1.walk(this.expressions, i, visitor, options, this);
964
+ (0, visitors_1.walk)(this.expressions, i, visitor, options, this);
939
965
  }
940
966
  }
941
967
  }
@@ -948,7 +974,15 @@ class AnnotationExpression extends Expression {
948
974
  this.atToken = atToken;
949
975
  this.nameToken = nameToken;
950
976
  this.name = nameToken.text;
951
- this.range = util_1.default.createRangeFromPositions(atToken.range.start, nameToken.range.end);
977
+ }
978
+ get range() {
979
+ return this.cacheRange();
980
+ }
981
+ cacheRange() {
982
+ if (!this._range) {
983
+ this._range = util_1.default.createBoundingRange(this.atToken, this.nameToken, this.call);
984
+ }
985
+ return this._range;
952
986
  }
953
987
  /**
954
988
  * Convert annotation arguments to JavaScript types
@@ -978,14 +1012,13 @@ class AnnotationExpression extends Expression {
978
1012
  exports.AnnotationExpression = AnnotationExpression;
979
1013
  class TernaryExpression extends Expression {
980
1014
  constructor(test, questionMarkToken, consequent, colonToken, alternate) {
981
- var _a, _b, _c;
982
1015
  super();
983
1016
  this.test = test;
984
1017
  this.questionMarkToken = questionMarkToken;
985
1018
  this.consequent = consequent;
986
1019
  this.colonToken = colonToken;
987
1020
  this.alternate = alternate;
988
- 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);
1021
+ this.range = util_1.default.createBoundingRange(this.test, this.questionMarkToken, this.consequent, this.colonToken, this.alternate);
989
1022
  }
990
1023
  transpile(state) {
991
1024
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
@@ -1014,21 +1047,20 @@ class TernaryExpression extends Expression {
1014
1047
  }
1015
1048
  walk(visitor, options) {
1016
1049
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1017
- visitors_1.walk(this, 'test', visitor, options);
1018
- visitors_1.walk(this, 'consequent', visitor, options);
1019
- visitors_1.walk(this, 'alternate', visitor, options);
1050
+ (0, visitors_1.walk)(this, 'test', visitor, options);
1051
+ (0, visitors_1.walk)(this, 'consequent', visitor, options);
1052
+ (0, visitors_1.walk)(this, 'alternate', visitor, options);
1020
1053
  }
1021
1054
  }
1022
1055
  }
1023
1056
  exports.TernaryExpression = TernaryExpression;
1024
1057
  class NullCoalescingExpression extends Expression {
1025
1058
  constructor(consequent, questionQuestionToken, alternate) {
1026
- var _a;
1027
1059
  super();
1028
1060
  this.consequent = consequent;
1029
1061
  this.questionQuestionToken = questionQuestionToken;
1030
1062
  this.alternate = alternate;
1031
- 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);
1063
+ this.range = util_1.default.createBoundingRange(this.consequent, this.questionQuestionToken, this.alternate);
1032
1064
  }
1033
1065
  transpile(state) {
1034
1066
  let result = [];
@@ -1039,7 +1071,7 @@ class NullCoalescingExpression extends Expression {
1039
1071
  let hasMutatingExpression = [
1040
1072
  ...consequentInfo.expressions,
1041
1073
  ...alternateInfo.expressions
1042
- ].find(e => reflection_1.isCallExpression(e) || reflection_1.isCallfuncExpression(e) || reflection_1.isDottedGetExpression(e));
1074
+ ].find(e => (0, reflection_1.isCallExpression)(e) || (0, reflection_1.isCallfuncExpression)(e) || (0, reflection_1.isDottedGetExpression)(e));
1043
1075
  if (hasMutatingExpression) {
1044
1076
  result.push(`(function(`,
1045
1077
  //write all the scope variables as parameters.
@@ -1058,37 +1090,175 @@ class NullCoalescingExpression extends Expression {
1058
1090
  }
1059
1091
  walk(visitor, options) {
1060
1092
  if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1061
- visitors_1.walk(this, 'consequent', visitor, options);
1062
- visitors_1.walk(this, 'alternate', visitor, options);
1093
+ (0, visitors_1.walk)(this, 'consequent', visitor, options);
1094
+ (0, visitors_1.walk)(this, 'alternate', visitor, options);
1063
1095
  }
1064
1096
  }
1065
1097
  }
1066
1098
  exports.NullCoalescingExpression = NullCoalescingExpression;
1099
+ class RegexLiteralExpression extends Expression {
1100
+ constructor(tokens) {
1101
+ super();
1102
+ this.tokens = tokens;
1103
+ this.range = this.tokens.regexLiteral.range;
1104
+ }
1105
+ transpile(state) {
1106
+ var _a, _b;
1107
+ let text = (_b = (_a = this.tokens.regexLiteral) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '';
1108
+ let flags = '';
1109
+ //get any flags from the end
1110
+ const flagMatch = /\/([a-z]+)$/i.exec(text);
1111
+ if (flagMatch) {
1112
+ text = text.substring(0, flagMatch.index + 1);
1113
+ flags = flagMatch[1];
1114
+ }
1115
+ let pattern = text
1116
+ //remove leading and trailing slashes
1117
+ .substring(1, text.length - 1)
1118
+ //escape quotemarks
1119
+ .split('"').join('" + chr(34) + "');
1120
+ return [
1121
+ state.sourceNode(this.tokens.regexLiteral, [
1122
+ 'CreateObject("roRegex", ',
1123
+ `"${pattern}", `,
1124
+ `"${flags}"`,
1125
+ ')'
1126
+ ])
1127
+ ];
1128
+ }
1129
+ walk(visitor, options) {
1130
+ //nothing to walk
1131
+ }
1132
+ }
1133
+ exports.RegexLiteralExpression = RegexLiteralExpression;
1134
+ class TypeExpression extends Expression {
1135
+ constructor(tokens, namespaceName) {
1136
+ super();
1137
+ this.tokens = tokens;
1138
+ this.namespaceName = namespaceName;
1139
+ this.range = util_1.default.createBoundingRange(this.tokens.type);
1140
+ }
1141
+ /**
1142
+ * The this TypeExpression refers to
1143
+ */
1144
+ get type() {
1145
+ if (this._type) {
1146
+ return this._type;
1147
+ }
1148
+ this._type = this.getType(Parser_1.ParseMode.BrighterScript);
1149
+ return this._type;
1150
+ }
1151
+ /**
1152
+ * Derive a BscType from the type token
1153
+ * Can deal with multiple brackets to make multidimensional arrays, eg. float[][]
1154
+ * Defaults to `DynamicType`
1155
+ */
1156
+ getType(parseMode = Parser_1.ParseMode.BrighterScript) {
1157
+ let exprType = this.tokens.type
1158
+ ? util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName)
1159
+ : new DynamicType_1.DynamicType();
1160
+ return exprType;
1161
+ }
1162
+ /**
1163
+ * Is this a valid, (eg. known) type?
1164
+ */
1165
+ isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
1166
+ return !!util_1.default.tokenToBscType(this.tokens.type, parseMode === Parser_1.ParseMode.BrighterScript, this.namespaceName);
1167
+ }
1168
+ /**
1169
+ * Gives a human readable string that says the type
1170
+ * @returns text to display to show the type
1171
+ */
1172
+ getText() {
1173
+ let result = this.tokens.type.text;
1174
+ return result;
1175
+ }
1176
+ transpile(state) {
1177
+ let result = [];
1178
+ //type declaration
1179
+ result.push(state.sourceNode({ range: this.range }, this.type.toTypeString(state.typeContext)));
1180
+ return result;
1181
+ }
1182
+ walk(visitor, options) {
1183
+ //nothing to walk
1184
+ }
1185
+ }
1186
+ exports.TypeExpression = TypeExpression;
1187
+ class ArrayTypeExpression extends TypeExpression {
1188
+ constructor(innerTypes, // this is an array so that in the future when we support union types
1189
+ bracketTokens, namespaceName) {
1190
+ super({}, namespaceName);
1191
+ this.innerTypes = innerTypes;
1192
+ this.bracketTokens = bracketTokens;
1193
+ this.namespaceName = namespaceName;
1194
+ this.range = util_1.default.createBoundingRange(this.bracketTokens.leftBracket, this.bracketTokens.rightBracket, ...this.innerTypes);
1195
+ }
1196
+ /*
1197
+ * TODO - Support union types
1198
+ */
1199
+ get defaultTypeExpression() {
1200
+ return this.innerTypes[0];
1201
+ }
1202
+ /**
1203
+ * Derive a BscType from the type token
1204
+ * Returns an array type with the inner types based on the inner type expressions
1205
+ */
1206
+ getType(parseMode = Parser_1.ParseMode.BrighterScript) {
1207
+ const innerBscTypes = this.innerTypes.map(inner => inner.getType(parseMode));
1208
+ return new ArrayType_1.ArrayType(...innerBscTypes);
1209
+ }
1210
+ /**
1211
+ * Is this a valid, (eg. known) type?
1212
+ */
1213
+ isValidType(parseMode = Parser_1.ParseMode.BrighterScript) {
1214
+ if (parseMode === Parser_1.ParseMode.BrighterScript) {
1215
+ return this.innerTypes.reduce((validSoFar, innerType) => {
1216
+ return validSoFar && innerType.isValidType(parseMode);
1217
+ }, true);
1218
+ }
1219
+ return false;
1220
+ }
1221
+ /**
1222
+ * Gives a human readable string that says the type
1223
+ * @returns text to display to show the type
1224
+ */
1225
+ getText() {
1226
+ return this.defaultTypeExpression.getText() + '[]';
1227
+ }
1228
+ walk(visitor, options) {
1229
+ if (options.walkMode & visitors_1.InternalWalkMode.walkExpressions) {
1230
+ for (let i = 0; i < this.innerTypes.length; i++) {
1231
+ (0, visitors_1.walk)(this.innerTypes, i, visitor, options, this);
1232
+ }
1233
+ }
1234
+ }
1235
+ }
1236
+ exports.ArrayTypeExpression = ArrayTypeExpression;
1067
1237
  function expressionToValue(expr, strict) {
1068
1238
  if (!expr) {
1069
1239
  return null;
1070
1240
  }
1071
- if (reflection_1.isUnaryExpression(expr) && reflection_1.isLiteralNumber(expr.right)) {
1241
+ if ((0, reflection_1.isUnaryExpression)(expr) && (0, reflection_1.isLiteralNumber)(expr.right)) {
1072
1242
  return numberExpressionToValue(expr.right, expr.operator.text);
1073
1243
  }
1074
- if (reflection_1.isLiteralString(expr)) {
1244
+ if ((0, reflection_1.isLiteralString)(expr)) {
1075
1245
  //remove leading and trailing quotes
1076
1246
  return expr.token.text.replace(/^"/, '').replace(/"$/, '');
1077
1247
  }
1078
- if (reflection_1.isLiteralNumber(expr)) {
1248
+ if ((0, reflection_1.isLiteralNumber)(expr)) {
1079
1249
  return numberExpressionToValue(expr);
1080
1250
  }
1081
- if (reflection_1.isLiteralBoolean(expr)) {
1251
+ if ((0, reflection_1.isLiteralBoolean)(expr)) {
1082
1252
  return expr.token.text.toLowerCase() === 'true';
1083
1253
  }
1084
- if (reflection_1.isArrayLiteralExpression(expr)) {
1254
+ if ((0, reflection_1.isArrayLiteralExpression)(expr)) {
1085
1255
  return expr.elements
1086
- .filter(e => !reflection_1.isCommentStatement(e))
1256
+ .filter(e => !(0, reflection_1.isCommentStatement)(e))
1087
1257
  .map(e => expressionToValue(e, strict));
1088
1258
  }
1089
- if (reflection_1.isAALiteralExpression(expr)) {
1259
+ if ((0, reflection_1.isAALiteralExpression)(expr)) {
1090
1260
  return expr.elements.reduce((acc, e) => {
1091
- if (!reflection_1.isCommentStatement(e)) {
1261
+ if (!(0, reflection_1.isCommentStatement)(e)) {
1092
1262
  acc[e.keyToken.text] = expressionToValue(e.value, strict);
1093
1263
  }
1094
1264
  return acc;
@@ -1097,7 +1267,7 @@ function expressionToValue(expr, strict) {
1097
1267
  return strict ? null : expr;
1098
1268
  }
1099
1269
  function numberExpressionToValue(expr, operator = '') {
1100
- if (reflection_1.isIntegerType(expr.type) || reflection_1.isLongIntegerType(expr.type)) {
1270
+ if ((0, reflection_1.isIntegerType)(expr.type) || (0, reflection_1.isLongIntegerType)(expr.type)) {
1101
1271
  return parseInt(operator + expr.token.text);
1102
1272
  }
1103
1273
  else {