brighterscript 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (381) hide show
  1. package/CHANGELOG.md +542 -253
  2. package/README.md +30 -9
  3. package/bsconfig.schema.json +13 -1
  4. package/dist/BsConfig.d.ts +4 -0
  5. package/dist/Cache.d.ts +3 -8
  6. package/dist/Cache.js +9 -14
  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.js +5 -4
  15. package/dist/DependencyGraph.js.map +1 -1
  16. package/dist/DiagnosticFilterer.js +1 -1
  17. package/dist/DiagnosticFilterer.js.map +1 -1
  18. package/dist/DiagnosticMessages.d.ts +59 -4
  19. package/dist/DiagnosticMessages.js +65 -7
  20. package/dist/DiagnosticMessages.js.map +1 -1
  21. package/dist/LanguageServer.d.ts +4 -14
  22. package/dist/LanguageServer.js +40 -26
  23. package/dist/LanguageServer.js.map +1 -1
  24. package/dist/Logger.d.ts +2 -0
  25. package/dist/Logger.js +10 -8
  26. package/dist/Logger.js.map +1 -1
  27. package/dist/PluginInterface.d.ts +7 -3
  28. package/dist/PluginInterface.js +9 -0
  29. package/dist/PluginInterface.js.map +1 -1
  30. package/dist/Program.d.ts +43 -25
  31. package/dist/Program.js +180 -82
  32. package/dist/Program.js.map +1 -1
  33. package/dist/ProgramBuilder.d.ts +4 -0
  34. package/dist/ProgramBuilder.js +30 -14
  35. package/dist/ProgramBuilder.js.map +1 -1
  36. package/dist/Scope.d.ts +100 -28
  37. package/dist/Scope.js +382 -154
  38. package/dist/Scope.js.map +1 -1
  39. package/dist/SemanticTokenUtils.d.ts +14 -0
  40. package/dist/SemanticTokenUtils.js +81 -0
  41. package/dist/SemanticTokenUtils.js.map +1 -0
  42. package/dist/SymbolTable.d.ts +10 -4
  43. package/dist/SymbolTable.js +40 -13
  44. package/dist/SymbolTable.js.map +1 -1
  45. package/dist/XmlScope.d.ts +8 -3
  46. package/dist/XmlScope.js +65 -27
  47. package/dist/XmlScope.js.map +1 -1
  48. package/dist/astUtils/AstEditor.d.ts +33 -0
  49. package/dist/astUtils/AstEditor.js +107 -0
  50. package/dist/astUtils/AstEditor.js.map +1 -0
  51. package/dist/{types/FunctionType.spec.d.ts → astUtils/AstEditor.spec.d.ts} +0 -0
  52. package/dist/astUtils/AstEditor.spec.js +170 -0
  53. package/dist/astUtils/AstEditor.spec.js.map +1 -0
  54. package/dist/astUtils/creators.d.ts +24 -6
  55. package/dist/astUtils/creators.js +130 -19
  56. package/dist/astUtils/creators.js.map +1 -1
  57. package/dist/astUtils/creators.spec.js +14 -4
  58. package/dist/astUtils/creators.spec.js.map +1 -1
  59. package/dist/astUtils/reflection.d.ts +27 -8
  60. package/dist/astUtils/reflection.js +66 -1
  61. package/dist/astUtils/reflection.js.map +1 -1
  62. package/dist/astUtils/reflection.spec.js +130 -119
  63. package/dist/astUtils/reflection.spec.js.map +1 -1
  64. package/dist/astUtils/stackedVisitor.js.map +1 -1
  65. package/dist/astUtils/stackedVisitor.spec.js +13 -13
  66. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  67. package/dist/astUtils/visitors.d.ts +17 -2
  68. package/dist/astUtils/visitors.js +2 -2
  69. package/dist/astUtils/visitors.js.map +1 -1
  70. package/dist/astUtils/visitors.spec.js +31 -29
  71. package/dist/astUtils/visitors.spec.js.map +1 -1
  72. package/dist/astUtils/xml.d.ts +4 -3
  73. package/dist/astUtils/xml.js +8 -3
  74. package/dist/astUtils/xml.js.map +1 -1
  75. package/dist/bscPlugin/BscPlugin.d.ts +7 -1
  76. package/dist/bscPlugin/BscPlugin.js +28 -0
  77. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  78. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +4 -4
  79. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  80. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +26 -26
  81. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  82. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +9 -0
  83. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +97 -0
  84. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -0
  85. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +1 -0
  86. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +73 -0
  87. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -0
  88. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.d.ts +8 -0
  89. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js +52 -0
  90. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
  91. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +1 -0
  92. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +32 -0
  93. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
  94. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +9 -0
  95. package/dist/bscPlugin/validation/BrsFileValidator.js +66 -0
  96. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -0
  97. package/dist/bscPlugin/validation/ScopeValidator.d.ts +29 -0
  98. package/dist/bscPlugin/validation/ScopeValidator.js +183 -0
  99. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -0
  100. package/dist/cli.js +9 -3
  101. package/dist/cli.js.map +1 -1
  102. package/dist/diagnosticUtils.d.ts +1 -0
  103. package/dist/diagnosticUtils.js +15 -8
  104. package/dist/diagnosticUtils.js.map +1 -1
  105. package/dist/examples/plugins/removePrint.js +12 -14
  106. package/dist/examples/plugins/removePrint.js.map +1 -1
  107. package/dist/files/BrsFile.Class.spec.js +634 -145
  108. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  109. package/dist/files/BrsFile.d.ts +62 -30
  110. package/dist/files/BrsFile.js +683 -335
  111. package/dist/files/BrsFile.js.map +1 -1
  112. package/dist/files/BrsFile.spec.js +1055 -449
  113. package/dist/files/BrsFile.spec.js.map +1 -1
  114. package/dist/files/XmlFile.d.ts +11 -10
  115. package/dist/files/XmlFile.js +33 -26
  116. package/dist/files/XmlFile.js.map +1 -1
  117. package/dist/files/XmlFile.spec.js +302 -237
  118. package/dist/files/XmlFile.spec.js.map +1 -1
  119. package/dist/files/tests/imports.spec.js +44 -42
  120. package/dist/files/tests/imports.spec.js.map +1 -1
  121. package/dist/files/tests/optionalChaning.spec.d.ts +1 -0
  122. package/dist/files/tests/optionalChaning.spec.js +88 -0
  123. package/dist/files/tests/optionalChaning.spec.js.map +1 -0
  124. package/dist/globalCallables.d.ts +3 -1
  125. package/dist/globalCallables.js +424 -152
  126. package/dist/globalCallables.js.map +1 -1
  127. package/dist/index.d.ts +13 -3
  128. package/dist/index.js +23 -4
  129. package/dist/index.js.map +1 -1
  130. package/dist/interfaces.d.ts +129 -16
  131. package/dist/lexer/Lexer.d.ts +19 -1
  132. package/dist/lexer/Lexer.js +127 -21
  133. package/dist/lexer/Lexer.js.map +1 -1
  134. package/dist/lexer/Lexer.spec.js +657 -536
  135. package/dist/lexer/Lexer.spec.js.map +1 -1
  136. package/dist/lexer/Token.d.ts +2 -2
  137. package/dist/lexer/TokenKind.d.ts +13 -1
  138. package/dist/lexer/TokenKind.js +60 -3
  139. package/dist/lexer/TokenKind.js.map +1 -1
  140. package/dist/parser/BrsTranspileState.d.ts +7 -0
  141. package/dist/parser/BrsTranspileState.js +9 -0
  142. package/dist/parser/BrsTranspileState.js.map +1 -1
  143. package/dist/parser/Expression.d.ts +150 -34
  144. package/dist/parser/Expression.js +337 -150
  145. package/dist/parser/Expression.js.map +1 -1
  146. package/dist/parser/Parser.Class.spec.js +189 -89
  147. package/dist/parser/Parser.Class.spec.js.map +1 -1
  148. package/dist/parser/Parser.d.ts +152 -29
  149. package/dist/parser/Parser.js +1095 -501
  150. package/dist/parser/Parser.js.map +1 -1
  151. package/dist/parser/Parser.spec.js +687 -266
  152. package/dist/parser/Parser.spec.js.map +1 -1
  153. package/dist/parser/SGParser.d.ts +41 -4
  154. package/dist/parser/SGParser.js +186 -175
  155. package/dist/parser/SGParser.js.map +1 -1
  156. package/dist/parser/SGParser.spec.js +35 -22
  157. package/dist/parser/SGParser.spec.js.map +1 -1
  158. package/dist/parser/SGTypes.d.ts +206 -38
  159. package/dist/parser/SGTypes.js +470 -161
  160. package/dist/parser/SGTypes.js.map +1 -1
  161. package/dist/parser/SGTypes.spec.d.ts +1 -0
  162. package/dist/parser/SGTypes.spec.js +351 -0
  163. package/dist/parser/SGTypes.spec.js.map +1 -0
  164. package/dist/parser/Statement.d.ts +194 -40
  165. package/dist/parser/Statement.js +597 -160
  166. package/dist/parser/Statement.js.map +1 -1
  167. package/dist/parser/Statement.spec.js +11 -11
  168. package/dist/parser/Statement.spec.js.map +1 -1
  169. package/dist/parser/TranspileState.d.ts +1 -1
  170. package/dist/parser/TranspileState.js +15 -7
  171. package/dist/parser/TranspileState.js.map +1 -1
  172. package/dist/parser/tests/Parser.spec.d.ts +10 -9
  173. package/dist/parser/tests/Parser.spec.js +15 -11
  174. package/dist/parser/tests/Parser.spec.js.map +1 -1
  175. package/dist/parser/tests/controlFlow/For.spec.js +60 -60
  176. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  177. package/dist/parser/tests/controlFlow/ForEach.spec.js +40 -39
  178. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  179. package/dist/parser/tests/controlFlow/If.spec.js +213 -194
  180. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  181. package/dist/parser/tests/controlFlow/While.spec.js +37 -37
  182. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  183. package/dist/parser/tests/expression/Additive.spec.js +30 -30
  184. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  185. package/dist/parser/tests/expression/ArrayLiterals.spec.js +119 -119
  186. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  187. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +162 -138
  188. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  189. package/dist/parser/tests/expression/Boolean.spec.js +24 -24
  190. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  191. package/dist/parser/tests/expression/Call.spec.js +41 -40
  192. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  193. package/dist/parser/tests/expression/Exponential.spec.js +17 -17
  194. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  195. package/dist/parser/tests/expression/Function.spec.js +256 -256
  196. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  197. package/dist/parser/tests/expression/Indexing.spec.js +87 -87
  198. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  199. package/dist/parser/tests/expression/Multiplicative.spec.js +37 -37
  200. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  201. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +75 -63
  202. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  203. package/dist/parser/tests/expression/PrefixUnary.spec.js +41 -41
  204. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  205. package/dist/parser/tests/expression/Primary.spec.js +41 -41
  206. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  207. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
  208. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +171 -0
  209. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
  210. package/dist/parser/tests/expression/Relational.spec.js +43 -43
  211. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  212. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +9 -9
  213. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  214. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +28 -28
  215. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  216. package/dist/parser/tests/expression/TernaryExpression.spec.js +102 -102
  217. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  218. package/dist/parser/tests/statement/AssignmentOperators.spec.js +36 -36
  219. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  220. package/dist/parser/tests/statement/Declaration.spec.js +44 -44
  221. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  222. package/dist/parser/tests/statement/Dim.spec.js +21 -21
  223. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  224. package/dist/parser/tests/statement/Enum.spec.d.ts +1 -0
  225. package/dist/parser/tests/statement/Enum.spec.js +840 -0
  226. package/dist/parser/tests/statement/Enum.spec.js.map +1 -0
  227. package/dist/parser/tests/statement/For.spec.d.ts +1 -0
  228. package/dist/parser/tests/statement/For.spec.js +46 -0
  229. package/dist/parser/tests/statement/For.spec.js.map +1 -0
  230. package/dist/parser/tests/statement/ForEach.spec.d.ts +1 -0
  231. package/dist/parser/tests/statement/ForEach.spec.js +37 -0
  232. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -0
  233. package/dist/parser/tests/statement/Function.spec.js +198 -197
  234. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  235. package/dist/parser/tests/statement/Goto.spec.js +15 -14
  236. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  237. package/dist/parser/tests/statement/Increment.spec.js +50 -50
  238. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  239. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
  240. package/dist/parser/tests/statement/InterfaceStatement.spec.js +254 -0
  241. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
  242. package/dist/parser/tests/statement/LibraryStatement.spec.js +17 -17
  243. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  244. package/dist/parser/tests/statement/Misc.spec.js +108 -106
  245. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  246. package/dist/parser/tests/statement/PrintStatement.spec.js +40 -40
  247. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  248. package/dist/parser/tests/statement/ReturnStatement.spec.js +46 -46
  249. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  250. package/dist/parser/tests/statement/Set.spec.js +83 -83
  251. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  252. package/dist/parser/tests/statement/Stop.spec.js +12 -11
  253. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  254. package/dist/parser/tests/statement/Throw.spec.js +5 -5
  255. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  256. package/dist/parser/tests/statement/TryCatch.spec.js +15 -13
  257. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  258. package/dist/preprocessor/Chunk.d.ts +1 -1
  259. package/dist/preprocessor/Chunk.js.map +1 -1
  260. package/dist/preprocessor/Manifest.d.ts +5 -5
  261. package/dist/preprocessor/Manifest.js +14 -35
  262. package/dist/preprocessor/Manifest.js.map +1 -1
  263. package/dist/preprocessor/Manifest.spec.d.ts +1 -0
  264. package/dist/preprocessor/Manifest.spec.js +78 -103
  265. package/dist/preprocessor/Manifest.spec.js.map +1 -1
  266. package/dist/preprocessor/Preprocessor.d.ts +1 -1
  267. package/dist/preprocessor/Preprocessor.js +8 -8
  268. package/dist/preprocessor/Preprocessor.js.map +1 -1
  269. package/dist/preprocessor/Preprocessor.spec.js +49 -49
  270. package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
  271. package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
  272. package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
  273. package/dist/roku-types/data.json +21891 -0
  274. package/dist/roku-types/index.d.ts +6776 -0
  275. package/dist/roku-types/index.js +11 -0
  276. package/dist/roku-types/index.js.map +1 -0
  277. package/dist/types/ArrayType.d.ts +8 -5
  278. package/dist/types/ArrayType.js +52 -12
  279. package/dist/types/ArrayType.js.map +1 -1
  280. package/dist/types/ArrayType.spec.js +72 -11
  281. package/dist/types/ArrayType.spec.js.map +1 -1
  282. package/dist/types/BooleanType.d.ts +4 -2
  283. package/dist/types/BooleanType.js +9 -4
  284. package/dist/types/BooleanType.js.map +1 -1
  285. package/dist/types/BooleanType.spec.js +5 -3
  286. package/dist/types/BooleanType.spec.js.map +1 -1
  287. package/dist/types/BscType.d.ts +20 -5
  288. package/dist/types/BscType.js +24 -0
  289. package/dist/types/BscType.js.map +1 -1
  290. package/dist/types/CustomType.d.ts +8 -6
  291. package/dist/types/CustomType.js +20 -11
  292. package/dist/types/CustomType.js.map +1 -1
  293. package/dist/types/DoubleType.d.ts +2 -0
  294. package/dist/types/DoubleType.js +14 -9
  295. package/dist/types/DoubleType.js.map +1 -1
  296. package/dist/types/DoubleType.spec.js +5 -3
  297. package/dist/types/DoubleType.spec.js.map +1 -1
  298. package/dist/types/DynamicType.d.ts +2 -0
  299. package/dist/types/DynamicType.js +6 -2
  300. package/dist/types/DynamicType.js.map +1 -1
  301. package/dist/types/DynamicType.spec.js +2 -2
  302. package/dist/types/DynamicType.spec.js.map +1 -1
  303. package/dist/types/FloatType.d.ts +2 -0
  304. package/dist/types/FloatType.js +14 -9
  305. package/dist/types/FloatType.js.map +1 -1
  306. package/dist/types/FloatType.spec.js +4 -2
  307. package/dist/types/FloatType.spec.js.map +1 -1
  308. package/dist/types/FunctionType.d.ts +7 -31
  309. package/dist/types/FunctionType.js +11 -57
  310. package/dist/types/FunctionType.js.map +1 -1
  311. package/dist/types/IntegerType.d.ts +2 -0
  312. package/dist/types/IntegerType.js +14 -9
  313. package/dist/types/IntegerType.js.map +1 -1
  314. package/dist/types/IntegerType.spec.js +5 -3
  315. package/dist/types/IntegerType.spec.js.map +1 -1
  316. package/dist/types/InterfaceType.d.ts +13 -4
  317. package/dist/types/InterfaceType.js +48 -8
  318. package/dist/types/InterfaceType.js.map +1 -1
  319. package/dist/types/InterfaceType.spec.d.ts +1 -0
  320. package/dist/types/InterfaceType.spec.js +194 -0
  321. package/dist/types/InterfaceType.spec.js.map +1 -0
  322. package/dist/types/InvalidType.d.ts +4 -2
  323. package/dist/types/InvalidType.js +10 -5
  324. package/dist/types/InvalidType.js.map +1 -1
  325. package/dist/types/InvalidType.spec.js +4 -2
  326. package/dist/types/InvalidType.spec.js.map +1 -1
  327. package/dist/types/LazyType.d.ts +8 -7
  328. package/dist/types/LazyType.js +22 -10
  329. package/dist/types/LazyType.js.map +1 -1
  330. package/dist/types/LongIntegerType.d.ts +2 -0
  331. package/dist/types/LongIntegerType.js +14 -9
  332. package/dist/types/LongIntegerType.js.map +1 -1
  333. package/dist/types/LongIntegerType.spec.js +4 -2
  334. package/dist/types/LongIntegerType.spec.js.map +1 -1
  335. package/dist/types/ObjectType.d.ts +8 -4
  336. package/dist/types/ObjectType.js +9 -4
  337. package/dist/types/ObjectType.js.map +1 -1
  338. package/dist/types/ObjectType.spec.js +2 -2
  339. package/dist/types/ObjectType.spec.js.map +1 -1
  340. package/dist/types/StringType.d.ts +4 -2
  341. package/dist/types/StringType.js +9 -4
  342. package/dist/types/StringType.js.map +1 -1
  343. package/dist/types/StringType.spec.js +4 -2
  344. package/dist/types/StringType.spec.js.map +1 -1
  345. package/dist/types/TypedFunctionType.d.ts +28 -0
  346. package/dist/types/TypedFunctionType.js +88 -0
  347. package/dist/types/TypedFunctionType.js.map +1 -0
  348. package/dist/types/TypedFunctionType.spec.d.ts +1 -0
  349. package/dist/types/TypedFunctionType.spec.js +37 -0
  350. package/dist/types/TypedFunctionType.spec.js.map +1 -0
  351. package/dist/types/UninitializedType.js +3 -3
  352. package/dist/types/UninitializedType.js.map +1 -1
  353. package/dist/types/VoidType.d.ts +4 -2
  354. package/dist/types/VoidType.js +8 -4
  355. package/dist/types/VoidType.js.map +1 -1
  356. package/dist/types/VoidType.spec.js +2 -2
  357. package/dist/types/VoidType.spec.js.map +1 -1
  358. package/dist/types/helpers.d.ts +42 -0
  359. package/dist/types/helpers.js +118 -0
  360. package/dist/types/helpers.js.map +1 -0
  361. package/dist/util.d.ts +87 -16
  362. package/dist/util.js +339 -94
  363. package/dist/util.js.map +1 -1
  364. package/dist/validators/ClassValidator.d.ts +19 -2
  365. package/dist/validators/ClassValidator.js +163 -102
  366. package/dist/validators/ClassValidator.js.map +1 -1
  367. package/package.json +26 -15
  368. package/dist/astUtils/index.d.ts +0 -7
  369. package/dist/astUtils/index.js +0 -26
  370. package/dist/astUtils/index.js.map +0 -1
  371. package/dist/lexer/index.d.ts +0 -3
  372. package/dist/lexer/index.js +0 -17
  373. package/dist/lexer/index.js.map +0 -1
  374. package/dist/parser/index.d.ts +0 -3
  375. package/dist/parser/index.js +0 -16
  376. package/dist/parser/index.js.map +0 -1
  377. package/dist/preprocessor/index.d.ts +0 -3
  378. package/dist/preprocessor/index.js +0 -16
  379. package/dist/preprocessor/index.js.map +0 -1
  380. package/dist/types/FunctionType.spec.js +0 -23
  381. package/dist/types/FunctionType.spec.js.map +0 -1
package/dist/util.js CHANGED
@@ -1,6 +1,6 @@
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");
@@ -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,19 @@ 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);
158
161
  if (parseErrors.length > 0) {
159
162
  let err = parseErrors[0];
160
- let diagnostic = Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.bsConfigJsonHasSyntaxErrors(jsonc_parser_1.printParseErrorCode(parseErrors[0].error))), { file: {
163
+ let diagnostic = Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.bsConfigJsonHasSyntaxErrors((0, jsonc_parser_1.printParseErrorCode)(parseErrors[0].error))), { file: {
161
164
  srcPath: configFilePath
162
165
  }, range: this.getRangeFromOffsetLength(projectFileContents, err.offset, err.length) });
163
166
  throw diagnostic; //eslint-disable-line @typescript-eslint/no-throw-literal
164
167
  }
165
- this.resolvePluginPaths(projectConfig, configFilePath);
166
168
  let projectFileCwd = path.dirname(configFilePath);
169
+ //`plugins` paths should be relative to the current bsconfig
170
+ this.resolvePathsRelativeTo(projectConfig, 'plugins', projectFileCwd);
171
+ //`require` paths should be relative to cwd
172
+ exports.util.resolvePathsRelativeTo(projectConfig, 'require', projectFileCwd);
167
173
  let result;
168
174
  //if the project has a base file, load it
169
175
  if (projectConfig && typeof projectConfig.extends === 'string') {
@@ -191,26 +197,22 @@ class Util {
191
197
  }
192
198
  }
193
199
  /**
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
200
+ * Convert relative paths to absolute paths, relative to the given directory. Also de-dupes the paths. Modifies the array in-place
201
+ * @param paths the list of paths to be resolved and deduped
202
+ * @param relativeDir the path to the folder where the paths should be resolved relative to. This should be an absolute path
198
203
  */
199
- resolvePluginPaths(config, configFilePath) {
204
+ resolvePathsRelativeTo(collection, key, relativeDir) {
200
205
  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
- });
206
+ if (!collection[key]) {
207
+ return;
213
208
  }
209
+ const result = new Set();
210
+ for (const p of (_a = collection[key]) !== null && _a !== void 0 ? _a : []) {
211
+ if (p) {
212
+ result.add((p === null || p === void 0 ? void 0 : p.startsWith('.')) ? path.resolve(relativeDir, p) : p);
213
+ }
214
+ }
215
+ collection[key] = [...result];
214
216
  }
215
217
  /**
216
218
  * Do work within the scope of a changed current working directory
@@ -424,10 +426,10 @@ class Util {
424
426
  findBeginningVariableExpression(dottedGet) {
425
427
  let left = dottedGet;
426
428
  while (left) {
427
- if (astUtils_1.isVariableExpression(left)) {
429
+ if ((0, reflection_1.isVariableExpression)(left)) {
428
430
  return left;
429
431
  }
430
- else if (astUtils_1.isDottedGetExpression(left)) {
432
+ else if ((0, reflection_1.isDottedGetExpression)(left)) {
431
433
  left = left.obj;
432
434
  }
433
435
  else {
@@ -598,11 +600,12 @@ class Util {
598
600
  */
599
601
  diagnosticIsSuppressed(diagnostic) {
600
602
  var _a, _b;
603
+ const diagnosticCode = typeof diagnostic.code === 'string' ? diagnostic.code.toLowerCase() : diagnostic.code;
601
604
  for (let flag of (_b = (_a = diagnostic.file) === null || _a === void 0 ? void 0 : _a.commentFlags) !== null && _b !== void 0 ? _b : []) {
602
605
  //this diagnostic is affected by this flag
603
606
  if (this.rangeContains(flag.affectedRange, diagnostic.range.start)) {
604
607
  //if the flag acts upon this diagnostic's code
605
- if (flag.codes === null || flag.codes.includes(diagnostic.code)) {
608
+ if (flag.codes === null || flag.codes.includes(diagnosticCode)) {
606
609
  return true;
607
610
  }
608
611
  }
@@ -807,6 +810,40 @@ class Util {
807
810
  }
808
811
  };
809
812
  }
813
+ /**
814
+ * Given a list of ranges, create a range that starts with the first non-null lefthand range, and ends with the first non-null
815
+ * righthand range. Returns undefined if none of the items have a range.
816
+ */
817
+ createBoundingRange(...locatables) {
818
+ let leftmostRange;
819
+ let rightmostRange;
820
+ for (let i = 0; i < locatables.length; i++) {
821
+ //set the leftmost non-null-range item
822
+ const left = locatables[i];
823
+ //the range might be a getter, so access it exactly once
824
+ const leftRange = left === null || left === void 0 ? void 0 : left.range;
825
+ if (!leftmostRange && leftRange) {
826
+ leftmostRange = leftRange;
827
+ }
828
+ //set the rightmost non-null-range item
829
+ const right = locatables[locatables.length - 1 - i];
830
+ //the range might be a getter, so access it exactly once
831
+ const rightRange = right === null || right === void 0 ? void 0 : right.range;
832
+ if (!rightmostRange && rightRange) {
833
+ rightmostRange = rightRange;
834
+ }
835
+ //if we have both sides, quit
836
+ if (leftmostRange && rightmostRange) {
837
+ break;
838
+ }
839
+ }
840
+ if (leftmostRange) {
841
+ return this.createRangeFromPositions(leftmostRange.start, rightmostRange.end);
842
+ }
843
+ else {
844
+ return undefined;
845
+ }
846
+ }
810
847
  /**
811
848
  * Create a `Position` object. Prefer this over `Position.create` for performance reasons
812
849
  */
@@ -831,71 +868,95 @@ class Util {
831
868
  /**
832
869
  * Convert a token into a BscType
833
870
  */
834
- tokenToBscType(token, allowCustomType = true) {
871
+ tokenToBscType(token, allowBrighterscriptTypes = true, currentNamespaceName) {
835
872
  if (!token) {
836
873
  return new DynamicType_1.DynamicType();
837
874
  }
838
875
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
839
876
  switch (token.kind) {
840
- case lexer_1.TokenKind.Boolean:
841
- case lexer_1.TokenKind.True:
842
- case lexer_1.TokenKind.False:
877
+ case TokenKind_1.TokenKind.Boolean:
878
+ return new BooleanType_1.BooleanType(token.text);
879
+ case TokenKind_1.TokenKind.True:
880
+ case TokenKind_1.TokenKind.False:
843
881
  return new BooleanType_1.BooleanType();
844
- case lexer_1.TokenKind.Double:
845
- case lexer_1.TokenKind.DoubleLiteral:
882
+ case TokenKind_1.TokenKind.Double:
883
+ return new DoubleType_1.DoubleType(token.text);
884
+ case TokenKind_1.TokenKind.DoubleLiteral:
846
885
  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:
886
+ case TokenKind_1.TokenKind.Dynamic:
887
+ return new DynamicType_1.DynamicType(token.text);
888
+ case TokenKind_1.TokenKind.Float:
889
+ return new FloatType_1.FloatType(token.text);
890
+ case TokenKind_1.TokenKind.FloatLiteral:
851
891
  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:
892
+ case TokenKind_1.TokenKind.Function:
893
+ return new FunctionType_1.FunctionType();
894
+ case TokenKind_1.TokenKind.Integer:
895
+ return new IntegerType_1.IntegerType(token.text);
896
+ case TokenKind_1.TokenKind.IntegerLiteral:
857
897
  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:
898
+ case TokenKind_1.TokenKind.Invalid:
899
+ return new InvalidType_1.InvalidType(token.text);
900
+ case TokenKind_1.TokenKind.LongInteger:
901
+ return new LongIntegerType_1.LongIntegerType(token.text);
902
+ case TokenKind_1.TokenKind.LongIntegerLiteral:
862
903
  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:
904
+ case TokenKind_1.TokenKind.Object:
905
+ return new ObjectType_1.ObjectType(token.text);
906
+ case TokenKind_1.TokenKind.String:
907
+ return new StringType_1.StringType(token.text);
908
+ case TokenKind_1.TokenKind.StringLiteral:
909
+ case TokenKind_1.TokenKind.TemplateStringExpressionBegin:
910
+ case TokenKind_1.TokenKind.TemplateStringExpressionEnd:
911
+ case TokenKind_1.TokenKind.TemplateStringQuasi:
870
912
  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()) {
913
+ case TokenKind_1.TokenKind.Void:
914
+ return new VoidType_1.VoidType(token.text);
915
+ case TokenKind_1.TokenKind.Identifier:
916
+ let typeText = token.text.trim().toLowerCase();
917
+ let typeClass;
918
+ switch (typeText) {
875
919
  case 'boolean':
876
- return new BooleanType_1.BooleanType();
920
+ typeClass = new BooleanType_1.BooleanType(token.text);
921
+ break;
877
922
  case 'double':
878
- return new DoubleType_1.DoubleType();
923
+ typeClass = new DoubleType_1.DoubleType(token.text);
924
+ break;
879
925
  case 'float':
880
- return new FloatType_1.FloatType();
926
+ typeClass = new FloatType_1.FloatType(token.text);
927
+ break;
881
928
  case 'function':
882
- return new FunctionType_1.FunctionType(new DynamicType_1.DynamicType());
929
+ typeClass = new TypedFunctionType_1.TypedFunctionType(new DynamicType_1.DynamicType(token.text));
930
+ break;
883
931
  case 'integer':
884
- return new IntegerType_1.IntegerType();
932
+ typeClass = new IntegerType_1.IntegerType(token.text);
933
+ break;
885
934
  case 'invalid':
886
- return new InvalidType_1.InvalidType();
935
+ typeClass = new InvalidType_1.InvalidType(token.text);
936
+ break;
887
937
  case 'longinteger':
888
- return new LongIntegerType_1.LongIntegerType();
938
+ typeClass = new LongIntegerType_1.LongIntegerType(token.text);
939
+ break;
889
940
  case 'object':
890
- return new ObjectType_1.ObjectType();
941
+ typeClass = new ObjectType_1.ObjectType(token.text);
942
+ break;
891
943
  case 'string':
892
- return new StringType_1.StringType();
944
+ typeClass = new StringType_1.StringType(token.text);
945
+ break;
893
946
  case 'void':
894
- return new VoidType_1.VoidType();
947
+ typeClass = new VoidType_1.VoidType(token.text);
948
+ break;
949
+ case 'dynamic':
950
+ typeClass = new DynamicType_1.DynamicType(token.text);
951
+ break;
895
952
  }
896
- if (allowCustomType) {
897
- return new CustomType_1.CustomType(token.text);
953
+ if (!typeClass && allowBrighterscriptTypes) {
954
+ typeClass = new LazyType_1.LazyType((context) => {
955
+ var _a, _b;
956
+ 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();
957
+ });
898
958
  }
959
+ return typeClass;
899
960
  }
900
961
  }
901
962
  /**
@@ -976,19 +1037,22 @@ class Util {
976
1037
  const expressions = [expression];
977
1038
  const variableExpressions = [];
978
1039
  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)) {
1040
+ function expressionWalker(expression) {
1041
+ if ((0, reflection_1.isExpression)(expression)) {
983
1042
  expressions.push(expression);
984
1043
  }
985
- if (astUtils_1.isVariableExpression(expression)) {
1044
+ if ((0, reflection_1.isVariableExpression)(expression)) {
986
1045
  variableExpressions.push(expression);
987
1046
  uniqueVarNames.add(expression.name.text);
988
1047
  }
989
- }, {
990
- walkMode: astUtils_1.WalkMode.visitExpressions
1048
+ }
1049
+ // Collect all expressions. Most of these expressions are fairly small so this should be quick!
1050
+ // This should only be called during transpile time and only when we actually need it.
1051
+ expression === null || expression === void 0 ? void 0 : expression.walk(expressionWalker, {
1052
+ walkMode: visitors_1.WalkMode.visitExpressions
991
1053
  });
1054
+ //handle the expression itself (for situations when expression is a VariableExpression)
1055
+ expressionWalker(expression);
992
1056
  return { expressions: expressions, varExpressions: variableExpressions, uniqueVarNames: [...uniqueVarNames] };
993
1057
  }
994
1058
  /**
@@ -1006,20 +1070,25 @@ class Util {
1006
1070
  return new source_map_1.SourceNode(null, null, source, chunks);
1007
1071
  }
1008
1072
  /**
1009
- * Creates a new SGAttribute object, but keeps the existing Range references (since those shouldn't ever get changed directly)
1073
+ * Creates a new SGAttribute object, but keeps the existing Range references (since those should be immutable)
1010
1074
  */
1011
1075
  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
- };
1076
+ return new SGTypes_1.SGAttribute({ text: attr.tokens.key.text, range: attr.range }, { text: '=' }, { text: '"' }, { text: value, range: attr.tokens.value.range }, { text: '"' });
1077
+ }
1078
+ /**
1079
+ * Shorthand for creating a new source node
1080
+ */
1081
+ sourceNode(source, locatable, code) {
1082
+ if (code !== undefined) {
1083
+ const node = new source_map_1.SourceNode(null, null, source, code);
1084
+ if (locatable.range) {
1085
+ //convert 0-based Range line to 1-based SourceNode line
1086
+ node.line = locatable.range.start.line + 1;
1087
+ //SourceNode columns are 0-based so no conversion necessary
1088
+ node.column = locatable.range.start.character;
1089
+ }
1090
+ return node;
1091
+ }
1023
1092
  }
1024
1093
  /**
1025
1094
  * Remove leading simple protocols from a path (if present)
@@ -1033,10 +1102,13 @@ class Util {
1033
1102
  return pkgPath;
1034
1103
  }
1035
1104
  }
1105
+ /**
1106
+ * Converts a path into a standardized format (drive letter to lower, remove extra slashes, use single slash type, resolve relative parts, etc...)
1107
+ */
1036
1108
  standardizePath(thePath) {
1037
1109
  return exports.util.driveLetterToLower(rokuDeploy.standardizePath(thePath));
1038
1110
  }
1039
- /*
1111
+ /**
1040
1112
  * Copy the version of bslib from local node_modules to the staging folder
1041
1113
  */
1042
1114
  async copyBslibToStaging(stagingDir) {
@@ -1077,13 +1149,60 @@ class Util {
1077
1149
  };
1078
1150
  }
1079
1151
  /**
1080
- * Finds the array of callables from a container map, taking into account the function from which it was called
1152
+ * Gets the minimum and maximum number of allowed params
1153
+ * @param params The list of callable parameters to check
1154
+ * @returns the minimum and maximum number of allowed params
1155
+ */
1156
+ getMinMaxParamCount(params) {
1157
+ //get min/max parameter count for callable
1158
+ let minParams = 0;
1159
+ let maxParams = 0;
1160
+ let continueCheckingForRequired = true;
1161
+ for (let param of params) {
1162
+ maxParams++;
1163
+ //optional parameters must come last, so we can assume that minParams won't increase once we hit
1164
+ //the first isOptional
1165
+ if (continueCheckingForRequired && !param.isOptional) {
1166
+ minParams++;
1167
+ }
1168
+ else {
1169
+ continueCheckingForRequired = false;
1170
+ }
1171
+ }
1172
+ return { min: minParams, max: maxParams };
1173
+ }
1174
+ /**
1175
+ * Gets the minimum and maximum number of allowed params for ALL functions with the name of the function call
1176
+ * @param callablesByLowerName The map of callable containers
1177
+ * @param expCall function call expression to use for the name
1178
+ * @returns the minimum and maximum number of allowed params
1179
+ */
1180
+ getMinMaxParamCountByFunctionCall(callablesByLowerName, expCall) {
1181
+ const callablesWithThisName = this.getCallableContainersByName(callablesByLowerName, expCall);
1182
+ if ((callablesWithThisName === null || callablesWithThisName === void 0 ? void 0 : callablesWithThisName.length) > 0) {
1183
+ const paramCount = { min: exports.MAX_PARAM_COUNT, max: 0 };
1184
+ for (const callableContainer of callablesWithThisName) {
1185
+ let specificParamCount = exports.util.getMinMaxParamCount(callableContainer.callable.params);
1186
+ if (specificParamCount.max > paramCount.max) {
1187
+ paramCount.max = specificParamCount.max;
1188
+ }
1189
+ if (specificParamCount.min < paramCount.min) {
1190
+ paramCount.min = specificParamCount.min;
1191
+ }
1192
+ }
1193
+ return paramCount;
1194
+ }
1195
+ }
1196
+ /**
1197
+ * Finds the array of callables from a container map, based on the name of the function call
1081
1198
  * If the callable was called in a function in a namespace, functions in that namespace are preferred
1199
+ * @param callablesByLowerName The map of callable containers
1200
+ * @param expCall function call expression to use for the name
1082
1201
  * @return an array with callable containers - could be empty if nothing was found
1083
1202
  */
1084
- getCallableContainersFromContainerMapByFunctionCall(callablesByLowerName, expCall) {
1203
+ getCallableContainersByName(callablesByLowerName, expCall) {
1085
1204
  let callablesWithThisName = [];
1086
- const lowerName = expCall.name.toLowerCase();
1205
+ const lowerName = expCall.name.text.toLowerCase();
1087
1206
  if (expCall.functionExpression.namespaceName) {
1088
1207
  // prefer namespaced function
1089
1208
  const potentialNamespacedCallable = expCall.functionExpression.namespaceName.getName(Parser_1.ParseMode.BrightScript).toLowerCase() + '_' + lowerName;
@@ -1095,6 +1214,131 @@ class Util {
1095
1214
  }
1096
1215
  return callablesWithThisName;
1097
1216
  }
1217
+ /**
1218
+ * Sort an array of objects that have a Range
1219
+ */
1220
+ sortByRange(locatables) {
1221
+ //sort the tokens by range
1222
+ return locatables.sort((a, b) => {
1223
+ //start line
1224
+ if (a.range.start.line < b.range.start.line) {
1225
+ return -1;
1226
+ }
1227
+ if (a.range.start.line > b.range.start.line) {
1228
+ return 1;
1229
+ }
1230
+ //start char
1231
+ if (a.range.start.character < b.range.start.character) {
1232
+ return -1;
1233
+ }
1234
+ if (a.range.start.character > b.range.start.character) {
1235
+ return 1;
1236
+ }
1237
+ //end line
1238
+ if (a.range.end.line < b.range.end.line) {
1239
+ return -1;
1240
+ }
1241
+ if (a.range.end.line > b.range.end.line) {
1242
+ return 1;
1243
+ }
1244
+ //end char
1245
+ if (a.range.end.character < b.range.end.character) {
1246
+ return -1;
1247
+ }
1248
+ else if (a.range.end.character > b.range.end.character) {
1249
+ return 1;
1250
+ }
1251
+ return 0;
1252
+ });
1253
+ }
1254
+ /**
1255
+ * Split the given text and return ranges for each chunk.
1256
+ * Only works for single-line strings
1257
+ */
1258
+ splitGetRange(separator, text, range) {
1259
+ const chunks = text.split(separator);
1260
+ const result = [];
1261
+ let offset = 0;
1262
+ for (let i = 0; i < chunks.length; i++) {
1263
+ const chunk = chunks[i];
1264
+ //only keep nonzero chunks
1265
+ if (chunk.length > 0) {
1266
+ result.push({
1267
+ text: chunk,
1268
+ range: this.createRange(range.start.line, range.start.character + offset, range.end.line, range.start.character + offset + chunk.length)
1269
+ });
1270
+ }
1271
+ offset += chunk.length + separator.length;
1272
+ }
1273
+ return result;
1274
+ }
1275
+ /*
1276
+ * Wrap the given code in a markdown code fence (with the language)
1277
+ */
1278
+ mdFence(code, language = '') {
1279
+ return '```' + language + '\n' + code + '\n```';
1280
+ }
1281
+ /**
1282
+ * Finds a callable from a container map based on the name AND number of arguments
1283
+ * If the callable was called in a function in a namespace, functions in that namespace are preferred
1284
+ * The first callable that matches the name AND will accept the number of arguments given is returned
1285
+ * @return a callable containers that matches the call
1286
+ */
1287
+ getCallableContainerByFunctionCall(callablesByLowerName, expCall) {
1288
+ const callablesWithThisName = this.getCallableContainersByName(callablesByLowerName, expCall);
1289
+ if ((callablesWithThisName === null || callablesWithThisName === void 0 ? void 0 : callablesWithThisName.length) > 0) {
1290
+ for (const callableContainer of callablesWithThisName) {
1291
+ const paramCount = exports.util.getMinMaxParamCount(callableContainer.callable.params);
1292
+ if (paramCount.min <= expCall.args.length && paramCount.max >= expCall.args.length) {
1293
+ return callableContainer;
1294
+ }
1295
+ }
1296
+ }
1297
+ }
1298
+ /**
1299
+ * Gets each part of the dotted get.
1300
+ * @param expression
1301
+ * @returns an array of the parts of the dotted get. If not fully a dotted get, then returns undefined
1302
+ */
1303
+ getAllDottedGetParts(expression) {
1304
+ var _a, _b;
1305
+ const parts = [];
1306
+ let nextPart = expression;
1307
+ while (nextPart) {
1308
+ if ((0, reflection_1.isDottedGetExpression)(nextPart)) {
1309
+ parts.push((_a = nextPart === null || nextPart === void 0 ? void 0 : nextPart.name) === null || _a === void 0 ? void 0 : _a.text);
1310
+ nextPart = nextPart.obj;
1311
+ }
1312
+ else if ((0, reflection_1.isVariableExpression)(nextPart)) {
1313
+ parts.push((_b = nextPart === null || nextPart === void 0 ? void 0 : nextPart.name) === null || _b === void 0 ? void 0 : _b.text);
1314
+ break;
1315
+ }
1316
+ else {
1317
+ //we found a non-DottedGet expression, so return because this whole operation is invalid.
1318
+ return undefined;
1319
+ }
1320
+ }
1321
+ return parts.reverse();
1322
+ }
1323
+ /**
1324
+ * Returns an integer if valid, or undefined. Eliminates checking for NaN
1325
+ */
1326
+ parseInt(value) {
1327
+ const result = parseInt(value);
1328
+ if (!isNaN(result)) {
1329
+ return result;
1330
+ }
1331
+ else {
1332
+ return undefined;
1333
+ }
1334
+ }
1335
+ /**
1336
+ * Converts a range to a string in the format 1:2-3:4
1337
+ */
1338
+ rangeToString(range) {
1339
+ var _a, _b, _c, _d;
1340
+ 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}`;
1341
+ }
1098
1342
  }
1099
1343
  exports.Util = Util;
1100
1344
  /**
@@ -1111,4 +1355,5 @@ function standardizePath(stringParts, ...expressions) {
1111
1355
  exports.standardizePath = standardizePath;
1112
1356
  exports.util = new Util();
1113
1357
  exports.default = exports.util;
1358
+ exports.MAX_PARAM_COUNT = 32;
1114
1359
  //# sourceMappingURL=util.js.map