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
package/dist/util.js CHANGED
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.util = exports.standardizePath = exports.Util = void 0;
3
+ exports.MAX_PARAM_COUNT = exports.util = exports.standardizePath = exports.Util = void 0;
4
4
  const fs = require("fs");
5
5
  const fsExtra = require("fs-extra");
6
6
  const jsonc_parser_1 = require("jsonc-parser");
7
7
  const path = require("path");
8
- const rokuDeploy = require("roku-deploy");
8
+ const roku_deploy_1 = require("roku-deploy");
9
9
  const vscode_uri_1 = require("vscode-uri");
10
10
  const xml2js = require("xml2js");
11
11
  const DiagnosticMessages_1 = require("./DiagnosticMessages");
@@ -13,7 +13,7 @@ const BooleanType_1 = require("./types/BooleanType");
13
13
  const DoubleType_1 = require("./types/DoubleType");
14
14
  const DynamicType_1 = require("./types/DynamicType");
15
15
  const FloatType_1 = require("./types/FloatType");
16
- const FunctionType_1 = require("./types/FunctionType");
16
+ const TypedFunctionType_1 = require("./types/TypedFunctionType");
17
17
  const IntegerType_1 = require("./types/IntegerType");
18
18
  const InvalidType_1 = require("./types/InvalidType");
19
19
  const LongIntegerType_1 = require("./types/LongIntegerType");
@@ -22,10 +22,13 @@ const StringType_1 = require("./types/StringType");
22
22
  const VoidType_1 = require("./types/VoidType");
23
23
  const Parser_1 = require("./parser/Parser");
24
24
  const Logger_1 = require("./Logger");
25
- const lexer_1 = require("./lexer");
26
- const astUtils_1 = require("./astUtils");
27
- const CustomType_1 = require("./types/CustomType");
25
+ const TokenKind_1 = require("./lexer/TokenKind");
26
+ const reflection_1 = require("./astUtils/reflection");
27
+ const visitors_1 = require("./astUtils/visitors");
28
28
  const source_map_1 = require("source-map");
29
+ const SGTypes_1 = require("./parser/SGTypes");
30
+ const LazyType_1 = require("./types/LazyType");
31
+ const FunctionType_1 = require("./types/FunctionType");
29
32
  class Util {
30
33
  clearConsole() {
31
34
  // process.stdout.write('\x1Bc');
@@ -125,7 +128,7 @@ class Util {
125
128
  colIndex++;
126
129
  }
127
130
  }
128
- return exports.util.createRange(lineIndex, colIndex, lineIndex, colIndex + length);
131
+ return this.createRange(lineIndex, colIndex, lineIndex, colIndex + length);
129
132
  }
130
133
  /**
131
134
  * Load the contents of a config file.
@@ -154,16 +157,23 @@ class Util {
154
157
  //load the project file
155
158
  let projectFileContents = fsExtra.readFileSync(configFilePath).toString();
156
159
  let parseErrors = [];
157
- let projectConfig = jsonc_parser_1.parse(projectFileContents, parseErrors);
160
+ let projectConfig = (0, jsonc_parser_1.parse)(projectFileContents, parseErrors, {
161
+ allowEmptyContent: true,
162
+ allowTrailingComma: true,
163
+ disallowComments: false
164
+ });
158
165
  if (parseErrors.length > 0) {
159
166
  let err = parseErrors[0];
160
- let diagnostic = Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.bsConfigJsonHasSyntaxErrors(jsonc_parser_1.printParseErrorCode(parseErrors[0].error))), { file: {
167
+ let diagnostic = Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.bsConfigJsonHasSyntaxErrors((0, jsonc_parser_1.printParseErrorCode)(parseErrors[0].error))), { file: {
161
168
  srcPath: configFilePath
162
169
  }, range: this.getRangeFromOffsetLength(projectFileContents, err.offset, err.length) });
163
170
  throw diagnostic; //eslint-disable-line @typescript-eslint/no-throw-literal
164
171
  }
165
- this.resolvePluginPaths(projectConfig, configFilePath);
166
172
  let projectFileCwd = path.dirname(configFilePath);
173
+ //`plugins` paths should be relative to the current bsconfig
174
+ this.resolvePathsRelativeTo(projectConfig, 'plugins', projectFileCwd);
175
+ //`require` paths should be relative to cwd
176
+ exports.util.resolvePathsRelativeTo(projectConfig, 'require', projectFileCwd);
167
177
  let result;
168
178
  //if the project has a base file, load it
169
179
  if (projectConfig && typeof projectConfig.extends === 'string') {
@@ -191,26 +201,22 @@ class Util {
191
201
  }
192
202
  }
193
203
  /**
194
- * Relative paths to scripts in plugins should be resolved relatively to the bsconfig file
195
- * and de-duplicated
196
- * @param config Parsed configuration
197
- * @param configFilePath Path of the configuration file
204
+ * Convert relative paths to absolute paths, relative to the given directory. Also de-dupes the paths. Modifies the array in-place
205
+ * @param paths the list of paths to be resolved and deduped
206
+ * @param relativeDir the path to the folder where the paths should be resolved relative to. This should be an absolute path
198
207
  */
199
- resolvePluginPaths(config, configFilePath) {
208
+ resolvePathsRelativeTo(collection, key, relativeDir) {
200
209
  var _a;
201
- if (((_a = config.plugins) === null || _a === void 0 ? void 0 : _a.length) > 0) {
202
- const relPath = path.dirname(configFilePath);
203
- const exists = {};
204
- config.plugins = config.plugins.map(p => {
205
- return (p === null || p === void 0 ? void 0 : p.startsWith('.')) ? path.resolve(relPath, p) : p;
206
- }).filter(p => {
207
- if (!p || exists[p]) {
208
- return false;
209
- }
210
- exists[p] = true;
211
- return true;
212
- });
210
+ if (!collection[key]) {
211
+ return;
212
+ }
213
+ const result = new Set();
214
+ for (const p of (_a = collection[key]) !== null && _a !== void 0 ? _a : []) {
215
+ if (p) {
216
+ result.add((p === null || p === void 0 ? void 0 : p.startsWith('.')) ? path.resolve(relativeDir, p) : p);
217
+ }
213
218
  }
219
+ collection[key] = [...result];
214
220
  }
215
221
  /**
216
222
  * Do work within the scope of a changed current working directory
@@ -270,25 +276,26 @@ class Util {
270
276
  normalizeConfig(config) {
271
277
  var _a, _b, _c, _d, _e, _f, _g, _h;
272
278
  config = config || {};
279
+ config.cwd = (_a = config.cwd) !== null && _a !== void 0 ? _a : process.cwd();
273
280
  config.deploy = config.deploy === true ? true : false;
274
- //use default options from rokuDeploy
275
- config.files = (_a = config.files) !== null && _a !== void 0 ? _a : rokuDeploy.getOptions().files;
281
+ //use default files array from rokuDeploy
282
+ config.files = (_b = config.files) !== null && _b !== void 0 ? _b : [...roku_deploy_1.DefaultFiles];
276
283
  config.createPackage = config.createPackage === false ? false : true;
277
- let rootFolderName = path.basename(process.cwd());
278
- config.outFile = (_b = config.outFile) !== null && _b !== void 0 ? _b : `./out/${rootFolderName}.zip`;
284
+ let rootFolderName = path.basename(config.cwd);
285
+ config.outFile = (_c = config.outFile) !== null && _c !== void 0 ? _c : `./out/${rootFolderName}.zip`;
279
286
  config.sourceMap = config.sourceMap === true;
280
- config.username = (_c = config.username) !== null && _c !== void 0 ? _c : 'rokudev';
287
+ config.username = (_d = config.username) !== null && _d !== void 0 ? _d : 'rokudev';
281
288
  config.watch = config.watch === true ? true : false;
282
289
  config.emitFullPaths = config.emitFullPaths === true ? true : false;
283
290
  config.retainStagingFolder = config.retainStagingFolder === true ? true : false;
284
291
  config.copyToStaging = config.copyToStaging === false ? false : true;
285
- config.ignoreErrorCodes = (_d = config.ignoreErrorCodes) !== null && _d !== void 0 ? _d : [];
286
- config.diagnosticFilters = (_e = config.diagnosticFilters) !== null && _e !== void 0 ? _e : [];
287
- config.plugins = (_f = config.plugins) !== null && _f !== void 0 ? _f : [];
292
+ config.ignoreErrorCodes = (_e = config.ignoreErrorCodes) !== null && _e !== void 0 ? _e : [];
293
+ config.diagnosticFilters = (_f = config.diagnosticFilters) !== null && _f !== void 0 ? _f : [];
294
+ config.plugins = (_g = config.plugins) !== null && _g !== void 0 ? _g : [];
288
295
  config.autoImportComponentScript = config.autoImportComponentScript === true ? true : false;
289
296
  config.showDiagnosticsInConsole = config.showDiagnosticsInConsole === false ? false : true;
290
297
  config.sourceRoot = config.sourceRoot ? standardizePath(config.sourceRoot) : undefined;
291
- config.cwd = (_g = config.cwd) !== null && _g !== void 0 ? _g : process.cwd();
298
+ config.allowBrighterScriptInBrightScript = config.allowBrighterScriptInBrightScript === true ? true : false;
292
299
  config.emitDefinitions = config.emitDefinitions === true ? true : false;
293
300
  if (typeof config.logLevel === 'string') {
294
301
  config.logLevel = Logger_1.LogLevel[config.logLevel.toLowerCase()];
@@ -387,15 +394,15 @@ class Util {
387
394
  }
388
395
  /**
389
396
  * Compute the relative path from the source file to the target file
390
- * @param pkgSourcePathAbsolute - the absolute path to the source relative to the package location
391
- * @param pkgTargetPathAbsolute - the absolute path ro the target relative to the package location
397
+ * @param pkgSrcPath - the absolute path to the source, where cwd is the package location
398
+ * @param pkgTargetPath - the absolute path to the target, where cwd is the package location
392
399
  */
393
- getRelativePath(pkgSourcePathAbsolute, pkgTargetPathAbsolute) {
394
- pkgSourcePathAbsolute = path.normalize(pkgSourcePathAbsolute);
395
- pkgTargetPathAbsolute = path.normalize(pkgTargetPathAbsolute);
400
+ getRelativePath(pkgSrcPath, pkgTargetPath) {
401
+ pkgSrcPath = path.normalize(pkgSrcPath);
402
+ pkgTargetPath = path.normalize(pkgTargetPath);
396
403
  //break by path separator
397
- let sourceParts = pkgSourcePathAbsolute.split(path.sep);
398
- let targetParts = pkgTargetPathAbsolute.split(path.sep);
404
+ let sourceParts = pkgSrcPath.split(path.sep);
405
+ let targetParts = pkgTargetPath.split(path.sep);
399
406
  let commonParts = [];
400
407
  //find their common root
401
408
  for (let i = 0; i < targetParts.length; i++) {
@@ -424,10 +431,10 @@ class Util {
424
431
  findBeginningVariableExpression(dottedGet) {
425
432
  let left = dottedGet;
426
433
  while (left) {
427
- if (astUtils_1.isVariableExpression(left)) {
434
+ if ((0, reflection_1.isVariableExpression)(left)) {
428
435
  return left;
429
436
  }
430
- else if (astUtils_1.isDottedGetExpression(left)) {
437
+ else if ((0, reflection_1.isDottedGetExpression)(left)) {
431
438
  left = left.obj;
432
439
  }
433
440
  else {
@@ -573,7 +580,7 @@ class Util {
573
580
  */
574
581
  async getFilePaths(options) {
575
582
  let rootDir = this.getRootDir(options);
576
- let files = await rokuDeploy.getFilePaths(options.files, rootDir);
583
+ let files = await roku_deploy_1.rokuDeploy.getFilePaths(options.files, rootDir);
577
584
  return files;
578
585
  }
579
586
  /**
@@ -598,11 +605,12 @@ class Util {
598
605
  */
599
606
  diagnosticIsSuppressed(diagnostic) {
600
607
  var _a, _b;
608
+ const diagnosticCode = typeof diagnostic.code === 'string' ? diagnostic.code.toLowerCase() : diagnostic.code;
601
609
  for (let flag of (_b = (_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.commentFlags) !== null && _b !== void 0 ? _b : []) {
602
610
  //this diagnostic is affected by this flag
603
611
  if (this.rangeContains(flag.affectedRange, diagnostic.range.start)) {
604
612
  //if the flag acts upon this diagnostic's code
605
- if (flag.codes === null || flag.codes.includes(diagnostic.code)) {
613
+ if (flag.codes === null || flag.codes.includes(diagnosticCode)) {
606
614
  return true;
607
615
  }
608
616
  }
@@ -807,6 +815,40 @@ class Util {
807
815
  }
808
816
  };
809
817
  }
818
+ /**
819
+ * Given a list of ranges, create a range that starts with the first non-null lefthand range, and ends with the first non-null
820
+ * righthand range. Returns undefined if none of the items have a range.
821
+ */
822
+ createBoundingRange(...locatables) {
823
+ let leftmostRange;
824
+ let rightmostRange;
825
+ for (let i = 0; i < locatables.length; i++) {
826
+ //set the leftmost non-null-range item
827
+ const left = locatables[i];
828
+ //the range might be a getter, so access it exactly once
829
+ const leftRange = left === null || left === void 0 ? void 0 : left.range;
830
+ if (!leftmostRange && leftRange) {
831
+ leftmostRange = leftRange;
832
+ }
833
+ //set the rightmost non-null-range item
834
+ const right = locatables[locatables.length - 1 - i];
835
+ //the range might be a getter, so access it exactly once
836
+ const rightRange = right === null || right === void 0 ? void 0 : right.range;
837
+ if (!rightmostRange && rightRange) {
838
+ rightmostRange = rightRange;
839
+ }
840
+ //if we have both sides, quit
841
+ if (leftmostRange && rightmostRange) {
842
+ break;
843
+ }
844
+ }
845
+ if (leftmostRange) {
846
+ return this.createRangeFromPositions(leftmostRange.start, rightmostRange.end);
847
+ }
848
+ else {
849
+ return undefined;
850
+ }
851
+ }
810
852
  /**
811
853
  * Create a `Position` object. Prefer this over `Position.create` for performance reasons
812
854
  */
@@ -831,71 +873,95 @@ class Util {
831
873
  /**
832
874
  * Convert a token into a BscType
833
875
  */
834
- tokenToBscType(token, allowCustomType = true) {
876
+ tokenToBscType(token, allowBrighterscriptTypes = true, currentNamespaceName) {
835
877
  if (!token) {
836
878
  return new DynamicType_1.DynamicType();
837
879
  }
838
880
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
839
881
  switch (token.kind) {
840
- case lexer_1.TokenKind.Boolean:
841
- case lexer_1.TokenKind.True:
842
- case lexer_1.TokenKind.False:
882
+ case TokenKind_1.TokenKind.Boolean:
883
+ return new BooleanType_1.BooleanType(token.text);
884
+ case TokenKind_1.TokenKind.True:
885
+ case TokenKind_1.TokenKind.False:
843
886
  return new BooleanType_1.BooleanType();
844
- case lexer_1.TokenKind.Double:
845
- case lexer_1.TokenKind.DoubleLiteral:
887
+ case TokenKind_1.TokenKind.Double:
888
+ return new DoubleType_1.DoubleType(token.text);
889
+ case TokenKind_1.TokenKind.DoubleLiteral:
846
890
  return new DoubleType_1.DoubleType();
847
- case lexer_1.TokenKind.Dynamic:
848
- return new DynamicType_1.DynamicType();
849
- case lexer_1.TokenKind.Float:
850
- case lexer_1.TokenKind.FloatLiteral:
891
+ case TokenKind_1.TokenKind.Dynamic:
892
+ return new DynamicType_1.DynamicType(token.text);
893
+ case TokenKind_1.TokenKind.Float:
894
+ return new FloatType_1.FloatType(token.text);
895
+ case TokenKind_1.TokenKind.FloatLiteral:
851
896
  return new FloatType_1.FloatType();
852
- case lexer_1.TokenKind.Function:
853
- //TODO should there be a more generic function type without a signature that's assignable to all other function types?
854
- return new FunctionType_1.FunctionType(new DynamicType_1.DynamicType());
855
- case lexer_1.TokenKind.Integer:
856
- case lexer_1.TokenKind.IntegerLiteral:
897
+ case TokenKind_1.TokenKind.Function:
898
+ return new FunctionType_1.FunctionType();
899
+ case TokenKind_1.TokenKind.Integer:
900
+ return new IntegerType_1.IntegerType(token.text);
901
+ case TokenKind_1.TokenKind.IntegerLiteral:
857
902
  return new IntegerType_1.IntegerType();
858
- case lexer_1.TokenKind.Invalid:
859
- return new InvalidType_1.InvalidType();
860
- case lexer_1.TokenKind.LongInteger:
861
- case lexer_1.TokenKind.LongIntegerLiteral:
903
+ case TokenKind_1.TokenKind.Invalid:
904
+ return new InvalidType_1.InvalidType(token.text);
905
+ case TokenKind_1.TokenKind.LongInteger:
906
+ return new LongIntegerType_1.LongIntegerType(token.text);
907
+ case TokenKind_1.TokenKind.LongIntegerLiteral:
862
908
  return new LongIntegerType_1.LongIntegerType();
863
- case lexer_1.TokenKind.Object:
864
- return new ObjectType_1.ObjectType();
865
- case lexer_1.TokenKind.String:
866
- case lexer_1.TokenKind.StringLiteral:
867
- case lexer_1.TokenKind.TemplateStringExpressionBegin:
868
- case lexer_1.TokenKind.TemplateStringExpressionEnd:
869
- case lexer_1.TokenKind.TemplateStringQuasi:
909
+ case TokenKind_1.TokenKind.Object:
910
+ return new ObjectType_1.ObjectType(token.text);
911
+ case TokenKind_1.TokenKind.String:
912
+ return new StringType_1.StringType(token.text);
913
+ case TokenKind_1.TokenKind.StringLiteral:
914
+ case TokenKind_1.TokenKind.TemplateStringExpressionBegin:
915
+ case TokenKind_1.TokenKind.TemplateStringExpressionEnd:
916
+ case TokenKind_1.TokenKind.TemplateStringQuasi:
870
917
  return new StringType_1.StringType();
871
- case lexer_1.TokenKind.Void:
872
- return new VoidType_1.VoidType();
873
- case lexer_1.TokenKind.Identifier:
874
- switch (token.text.toLowerCase()) {
918
+ case TokenKind_1.TokenKind.Void:
919
+ return new VoidType_1.VoidType(token.text);
920
+ case TokenKind_1.TokenKind.Identifier:
921
+ let typeText = token.text.trim().toLowerCase();
922
+ let typeClass;
923
+ switch (typeText) {
875
924
  case 'boolean':
876
- return new BooleanType_1.BooleanType();
925
+ typeClass = new BooleanType_1.BooleanType(token.text);
926
+ break;
877
927
  case 'double':
878
- return new DoubleType_1.DoubleType();
928
+ typeClass = new DoubleType_1.DoubleType(token.text);
929
+ break;
879
930
  case 'float':
880
- return new FloatType_1.FloatType();
931
+ typeClass = new FloatType_1.FloatType(token.text);
932
+ break;
881
933
  case 'function':
882
- return new FunctionType_1.FunctionType(new DynamicType_1.DynamicType());
934
+ typeClass = new TypedFunctionType_1.TypedFunctionType(new DynamicType_1.DynamicType(token.text));
935
+ break;
883
936
  case 'integer':
884
- return new IntegerType_1.IntegerType();
937
+ typeClass = new IntegerType_1.IntegerType(token.text);
938
+ break;
885
939
  case 'invalid':
886
- return new InvalidType_1.InvalidType();
940
+ typeClass = new InvalidType_1.InvalidType(token.text);
941
+ break;
887
942
  case 'longinteger':
888
- return new LongIntegerType_1.LongIntegerType();
943
+ typeClass = new LongIntegerType_1.LongIntegerType(token.text);
944
+ break;
889
945
  case 'object':
890
- return new ObjectType_1.ObjectType();
946
+ typeClass = new ObjectType_1.ObjectType(token.text);
947
+ break;
891
948
  case 'string':
892
- return new StringType_1.StringType();
949
+ typeClass = new StringType_1.StringType(token.text);
950
+ break;
893
951
  case 'void':
894
- return new VoidType_1.VoidType();
952
+ typeClass = new VoidType_1.VoidType(token.text);
953
+ break;
954
+ case 'dynamic':
955
+ typeClass = new DynamicType_1.DynamicType(token.text);
956
+ break;
895
957
  }
896
- if (allowCustomType) {
897
- return new CustomType_1.CustomType(token.text);
958
+ if (!typeClass && allowBrighterscriptTypes) {
959
+ typeClass = new LazyType_1.LazyType((context) => {
960
+ var _a, _b;
961
+ return (_b = (_a = context === null || context === void 0 ? void 0 : context.scope) === null || _a === void 0 ? void 0 : _a.getNamedTypeStatement(typeText, currentNamespaceName === null || currentNamespaceName === void 0 ? void 0 : currentNamespaceName.getName())) === null || _b === void 0 ? void 0 : _b.getThisBscType();
962
+ });
898
963
  }
964
+ return typeClass;
899
965
  }
900
966
  }
901
967
  /**
@@ -976,19 +1042,22 @@ class Util {
976
1042
  const expressions = [expression];
977
1043
  const variableExpressions = [];
978
1044
  const uniqueVarNames = new Set();
979
- // Collect all expressions. Most of these expressions are fairly small so this should be quick!
980
- // This should only be called during transpile time and only when we actually need it.
981
- expression === null || expression === void 0 ? void 0 : expression.walk((expression) => {
982
- if (astUtils_1.isExpression(expression)) {
1045
+ function expressionWalker(expression) {
1046
+ if ((0, reflection_1.isExpression)(expression)) {
983
1047
  expressions.push(expression);
984
1048
  }
985
- if (astUtils_1.isVariableExpression(expression)) {
1049
+ if ((0, reflection_1.isVariableExpression)(expression)) {
986
1050
  variableExpressions.push(expression);
987
1051
  uniqueVarNames.add(expression.name.text);
988
1052
  }
989
- }, {
990
- walkMode: astUtils_1.WalkMode.visitExpressions
1053
+ }
1054
+ // Collect all expressions. Most of these expressions are fairly small so this should be quick!
1055
+ // This should only be called during transpile time and only when we actually need it.
1056
+ expression === null || expression === void 0 ? void 0 : expression.walk(expressionWalker, {
1057
+ walkMode: visitors_1.WalkMode.visitExpressions
991
1058
  });
1059
+ //handle the expression itself (for situations when expression is a VariableExpression)
1060
+ expressionWalker(expression);
992
1061
  return { expressions: expressions, varExpressions: variableExpressions, uniqueVarNames: [...uniqueVarNames] };
993
1062
  }
994
1063
  /**
@@ -1006,20 +1075,25 @@ class Util {
1006
1075
  return new source_map_1.SourceNode(null, null, source, chunks);
1007
1076
  }
1008
1077
  /**
1009
- * Creates a new SGAttribute object, but keeps the existing Range references (since those shouldn't ever get changed directly)
1078
+ * Creates a new SGAttribute object, but keeps the existing Range references (since those should be immutable)
1010
1079
  */
1011
1080
  cloneSGAttribute(attr, value) {
1012
- return {
1013
- key: {
1014
- text: attr.key.text,
1015
- range: attr.range
1016
- },
1017
- value: {
1018
- text: value,
1019
- range: attr.value.range
1020
- },
1021
- range: attr.range
1022
- };
1081
+ return new SGTypes_1.SGAttribute({ text: attr.tokens.key.text, range: attr.range }, { text: '=' }, { text: '"' }, { text: value, range: attr.tokens.value.range }, { text: '"' });
1082
+ }
1083
+ /**
1084
+ * Shorthand for creating a new source node
1085
+ */
1086
+ sourceNode(source, locatable, code) {
1087
+ if (code !== undefined) {
1088
+ const node = new source_map_1.SourceNode(null, null, source, code);
1089
+ if (locatable.range) {
1090
+ //convert 0-based Range line to 1-based SourceNode line
1091
+ node.line = locatable.range.start.line + 1;
1092
+ //SourceNode columns are 0-based so no conversion necessary
1093
+ node.column = locatable.range.start.character;
1094
+ }
1095
+ return node;
1096
+ }
1023
1097
  }
1024
1098
  /**
1025
1099
  * Remove leading simple protocols from a path (if present)
@@ -1033,10 +1107,13 @@ class Util {
1033
1107
  return pkgPath;
1034
1108
  }
1035
1109
  }
1110
+ /**
1111
+ * Converts a path into a standardized format (drive letter to lower, remove extra slashes, use single slash type, resolve relative parts, etc...)
1112
+ */
1036
1113
  standardizePath(thePath) {
1037
- return exports.util.driveLetterToLower(rokuDeploy.standardizePath(thePath));
1114
+ return exports.util.driveLetterToLower((0, roku_deploy_1.standardizePath)(thePath));
1038
1115
  }
1039
- /*
1116
+ /**
1040
1117
  * Copy the version of bslib from local node_modules to the staging folder
1041
1118
  */
1042
1119
  async copyBslibToStaging(stagingDir) {
@@ -1077,13 +1154,60 @@ class Util {
1077
1154
  };
1078
1155
  }
1079
1156
  /**
1080
- * Finds the array of callables from a container map, taking into account the function from which it was called
1157
+ * Gets the minimum and maximum number of allowed params
1158
+ * @param params The list of callable parameters to check
1159
+ * @returns the minimum and maximum number of allowed params
1160
+ */
1161
+ getMinMaxParamCount(params) {
1162
+ //get min/max parameter count for callable
1163
+ let minParams = 0;
1164
+ let maxParams = 0;
1165
+ let continueCheckingForRequired = true;
1166
+ for (let param of params) {
1167
+ maxParams++;
1168
+ //optional parameters must come last, so we can assume that minParams won't increase once we hit
1169
+ //the first isOptional
1170
+ if (continueCheckingForRequired && !param.isOptional) {
1171
+ minParams++;
1172
+ }
1173
+ else {
1174
+ continueCheckingForRequired = false;
1175
+ }
1176
+ }
1177
+ return { min: minParams, max: maxParams };
1178
+ }
1179
+ /**
1180
+ * Gets the minimum and maximum number of allowed params for ALL functions with the name of the function call
1181
+ * @param callablesByLowerName The map of callable containers
1182
+ * @param expCall function call expression to use for the name
1183
+ * @returns the minimum and maximum number of allowed params
1184
+ */
1185
+ getMinMaxParamCountByFunctionCall(callablesByLowerName, expCall) {
1186
+ const callablesWithThisName = this.getCallableContainersByName(callablesByLowerName, expCall);
1187
+ if ((callablesWithThisName === null || callablesWithThisName === void 0 ? void 0 : callablesWithThisName.length) > 0) {
1188
+ const paramCount = { min: exports.MAX_PARAM_COUNT, max: 0 };
1189
+ for (const callableContainer of callablesWithThisName) {
1190
+ let specificParamCount = exports.util.getMinMaxParamCount(callableContainer.callable.params);
1191
+ if (specificParamCount.max > paramCount.max) {
1192
+ paramCount.max = specificParamCount.max;
1193
+ }
1194
+ if (specificParamCount.min < paramCount.min) {
1195
+ paramCount.min = specificParamCount.min;
1196
+ }
1197
+ }
1198
+ return paramCount;
1199
+ }
1200
+ }
1201
+ /**
1202
+ * Finds the array of callables from a container map, based on the name of the function call
1081
1203
  * If the callable was called in a function in a namespace, functions in that namespace are preferred
1204
+ * @param callablesByLowerName The map of callable containers
1205
+ * @param expCall function call expression to use for the name
1082
1206
  * @return an array with callable containers - could be empty if nothing was found
1083
1207
  */
1084
- getCallableContainersFromContainerMapByFunctionCall(callablesByLowerName, expCall) {
1208
+ getCallableContainersByName(callablesByLowerName, expCall) {
1085
1209
  let callablesWithThisName = [];
1086
- const lowerName = expCall.name.toLowerCase();
1210
+ const lowerName = expCall.name.text.toLowerCase();
1087
1211
  if (expCall.functionExpression.namespaceName) {
1088
1212
  // prefer namespaced function
1089
1213
  const potentialNamespacedCallable = expCall.functionExpression.namespaceName.getName(Parser_1.ParseMode.BrightScript).toLowerCase() + '_' + lowerName;
@@ -1095,6 +1219,131 @@ class Util {
1095
1219
  }
1096
1220
  return callablesWithThisName;
1097
1221
  }
1222
+ /**
1223
+ * Sort an array of objects that have a Range
1224
+ */
1225
+ sortByRange(locatables) {
1226
+ //sort the tokens by range
1227
+ return locatables.sort((a, b) => {
1228
+ //start line
1229
+ if (a.range.start.line < b.range.start.line) {
1230
+ return -1;
1231
+ }
1232
+ if (a.range.start.line > b.range.start.line) {
1233
+ return 1;
1234
+ }
1235
+ //start char
1236
+ if (a.range.start.character < b.range.start.character) {
1237
+ return -1;
1238
+ }
1239
+ if (a.range.start.character > b.range.start.character) {
1240
+ return 1;
1241
+ }
1242
+ //end line
1243
+ if (a.range.end.line < b.range.end.line) {
1244
+ return -1;
1245
+ }
1246
+ if (a.range.end.line > b.range.end.line) {
1247
+ return 1;
1248
+ }
1249
+ //end char
1250
+ if (a.range.end.character < b.range.end.character) {
1251
+ return -1;
1252
+ }
1253
+ else if (a.range.end.character > b.range.end.character) {
1254
+ return 1;
1255
+ }
1256
+ return 0;
1257
+ });
1258
+ }
1259
+ /**
1260
+ * Split the given text and return ranges for each chunk.
1261
+ * Only works for single-line strings
1262
+ */
1263
+ splitGetRange(separator, text, range) {
1264
+ const chunks = text.split(separator);
1265
+ const result = [];
1266
+ let offset = 0;
1267
+ for (let i = 0; i < chunks.length; i++) {
1268
+ const chunk = chunks[i];
1269
+ //only keep nonzero chunks
1270
+ if (chunk.length > 0) {
1271
+ result.push({
1272
+ text: chunk,
1273
+ range: this.createRange(range.start.line, range.start.character + offset, range.end.line, range.start.character + offset + chunk.length)
1274
+ });
1275
+ }
1276
+ offset += chunk.length + separator.length;
1277
+ }
1278
+ return result;
1279
+ }
1280
+ /*
1281
+ * Wrap the given code in a markdown code fence (with the language)
1282
+ */
1283
+ mdFence(code, language = '') {
1284
+ return '```' + language + '\n' + code + '\n```';
1285
+ }
1286
+ /**
1287
+ * Finds a callable from a container map based on the name AND number of arguments
1288
+ * If the callable was called in a function in a namespace, functions in that namespace are preferred
1289
+ * The first callable that matches the name AND will accept the number of arguments given is returned
1290
+ * @return a callable containers that matches the call
1291
+ */
1292
+ getCallableContainerByFunctionCall(callablesByLowerName, expCall) {
1293
+ const callablesWithThisName = this.getCallableContainersByName(callablesByLowerName, expCall);
1294
+ if ((callablesWithThisName === null || callablesWithThisName === void 0 ? void 0 : callablesWithThisName.length) > 0) {
1295
+ for (const callableContainer of callablesWithThisName) {
1296
+ const paramCount = exports.util.getMinMaxParamCount(callableContainer.callable.params);
1297
+ if (paramCount.min <= expCall.args.length && paramCount.max >= expCall.args.length) {
1298
+ return callableContainer;
1299
+ }
1300
+ }
1301
+ }
1302
+ }
1303
+ /**
1304
+ * Gets each part of the dotted get.
1305
+ * @param expression
1306
+ * @returns an array of the parts of the dotted get. If not fully a dotted get, then returns undefined
1307
+ */
1308
+ getAllDottedGetParts(expression) {
1309
+ var _a, _b;
1310
+ const parts = [];
1311
+ let nextPart = expression;
1312
+ while (nextPart) {
1313
+ if ((0, reflection_1.isDottedGetExpression)(nextPart)) {
1314
+ parts.push((_a = nextPart === null || nextPart === void 0 ? void 0 : nextPart.name) === null || _a === void 0 ? void 0 : _a.text);
1315
+ nextPart = nextPart.obj;
1316
+ }
1317
+ else if ((0, reflection_1.isVariableExpression)(nextPart)) {
1318
+ parts.push((_b = nextPart === null || nextPart === void 0 ? void 0 : nextPart.name) === null || _b === void 0 ? void 0 : _b.text);
1319
+ break;
1320
+ }
1321
+ else {
1322
+ //we found a non-DottedGet expression, so return because this whole operation is invalid.
1323
+ return undefined;
1324
+ }
1325
+ }
1326
+ return parts.reverse();
1327
+ }
1328
+ /**
1329
+ * Returns an integer if valid, or undefined. Eliminates checking for NaN
1330
+ */
1331
+ parseInt(value) {
1332
+ const result = parseInt(value);
1333
+ if (!isNaN(result)) {
1334
+ return result;
1335
+ }
1336
+ else {
1337
+ return undefined;
1338
+ }
1339
+ }
1340
+ /**
1341
+ * Converts a range to a string in the format 1:2-3:4
1342
+ */
1343
+ rangeToString(range) {
1344
+ var _a, _b, _c, _d;
1345
+ return `${(_a = range === null || range === void 0 ? void 0 : range.start) === null || _a === void 0 ? void 0 : _a.line}:${(_b = range === null || range === void 0 ? void 0 : range.start) === null || _b === void 0 ? void 0 : _b.character}-${(_c = range === null || range === void 0 ? void 0 : range.end) === null || _c === void 0 ? void 0 : _c.line}:${(_d = range === null || range === void 0 ? void 0 : range.end) === null || _d === void 0 ? void 0 : _d.character}`;
1346
+ }
1098
1347
  }
1099
1348
  exports.Util = Util;
1100
1349
  /**
@@ -1106,9 +1355,10 @@ function standardizePath(stringParts, ...expressions) {
1106
1355
  for (let i = 0; i < stringParts.length; i++) {
1107
1356
  result.push(stringParts[i], expressions[i]);
1108
1357
  }
1109
- return exports.util.standardizePath(result.join(''));
1358
+ return exports.util.driveLetterToLower((0, roku_deploy_1.standardizePath)(result.join('')));
1110
1359
  }
1111
1360
  exports.standardizePath = standardizePath;
1112
1361
  exports.util = new Util();
1113
1362
  exports.default = exports.util;
1363
+ exports.MAX_PARAM_COUNT = 32;
1114
1364
  //# sourceMappingURL=util.js.map