brighterscript 0.66.0-alpha.9 → 0.67.1

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 (472) hide show
  1. package/CHANGELOG.md +123 -73
  2. package/README.md +14 -418
  3. package/dist/BsConfig.d.ts +25 -2
  4. package/dist/Cache.js +3 -3
  5. package/dist/Cache.js.map +1 -1
  6. package/dist/CodeActionUtil.d.ts +3 -3
  7. package/dist/CodeActionUtil.js.map +1 -1
  8. package/dist/CommentFlagProcessor.d.ts +3 -4
  9. package/dist/CommentFlagProcessor.js +4 -3
  10. package/dist/CommentFlagProcessor.js.map +1 -1
  11. package/dist/DependencyGraph.js +8 -8
  12. package/dist/DependencyGraph.js.map +1 -1
  13. package/dist/DiagnosticFilterer.d.ts +8 -4
  14. package/dist/DiagnosticFilterer.js +71 -38
  15. package/dist/DiagnosticFilterer.js.map +1 -1
  16. package/dist/DiagnosticMessages.d.ts +15 -36
  17. package/dist/DiagnosticMessages.js +15 -61
  18. package/dist/DiagnosticMessages.js.map +1 -1
  19. package/dist/DiagnosticSeverityAdjuster.js +3 -0
  20. package/dist/DiagnosticSeverityAdjuster.js.map +1 -1
  21. package/dist/FunctionScope.d.ts +2 -3
  22. package/dist/FunctionScope.js +0 -3
  23. package/dist/FunctionScope.js.map +1 -1
  24. package/dist/LanguageServer.d.ts +1 -2
  25. package/dist/LanguageServer.js +31 -35
  26. package/dist/LanguageServer.js.map +1 -1
  27. package/dist/Logger.d.ts +5 -9
  28. package/dist/Logger.js +18 -22
  29. package/dist/Logger.js.map +1 -1
  30. package/dist/PluginInterface.d.ts +13 -15
  31. package/dist/PluginInterface.js +16 -70
  32. package/dist/PluginInterface.js.map +1 -1
  33. package/dist/Program.d.ts +105 -138
  34. package/dist/Program.js +479 -702
  35. package/dist/Program.js.map +1 -1
  36. package/dist/ProgramBuilder.d.ts +8 -19
  37. package/dist/ProgramBuilder.js +85 -89
  38. package/dist/ProgramBuilder.js.map +1 -1
  39. package/dist/Scope.d.ts +56 -46
  40. package/dist/Scope.js +281 -217
  41. package/dist/Scope.js.map +1 -1
  42. package/dist/Stopwatch.js +1 -1
  43. package/dist/Stopwatch.js.map +1 -1
  44. package/dist/SymbolTable.d.ts +12 -68
  45. package/dist/SymbolTable.js +28 -213
  46. package/dist/SymbolTable.js.map +1 -1
  47. package/dist/XmlScope.d.ts +5 -7
  48. package/dist/XmlScope.js +36 -76
  49. package/dist/XmlScope.js.map +1 -1
  50. package/dist/astUtils/{Editor.d.ts → AstEditor.d.ts} +1 -6
  51. package/dist/astUtils/{Editor.js → AstEditor.js} +3 -9
  52. package/dist/astUtils/AstEditor.js.map +1 -0
  53. package/dist/astUtils/{Editor.spec.js → AstEditor.spec.js} +6 -10
  54. package/dist/astUtils/AstEditor.spec.js.map +1 -0
  55. package/dist/astUtils/creators.d.ts +8 -19
  56. package/dist/astUtils/creators.js +22 -54
  57. package/dist/astUtils/creators.js.map +1 -1
  58. package/dist/astUtils/creators.spec.js +0 -10
  59. package/dist/astUtils/creators.spec.js.map +1 -1
  60. package/dist/astUtils/reflection.d.ts +45 -81
  61. package/dist/astUtils/reflection.js +157 -220
  62. package/dist/astUtils/reflection.js.map +1 -1
  63. package/dist/astUtils/reflection.spec.js +19 -96
  64. package/dist/astUtils/reflection.spec.js.map +1 -1
  65. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  66. package/dist/astUtils/visitors.d.ts +14 -18
  67. package/dist/astUtils/visitors.js +9 -22
  68. package/dist/astUtils/visitors.js.map +1 -1
  69. package/dist/astUtils/visitors.spec.js +9 -62
  70. package/dist/astUtils/visitors.spec.js.map +1 -1
  71. package/dist/astUtils/xml.d.ts +9 -9
  72. package/dist/astUtils/xml.js +6 -6
  73. package/dist/astUtils/xml.js.map +1 -1
  74. package/dist/bscPlugin/BscPlugin.d.ts +8 -11
  75. package/dist/bscPlugin/BscPlugin.js +21 -29
  76. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  77. package/dist/bscPlugin/CallExpressionInfo.d.ts +6 -5
  78. package/dist/bscPlugin/CallExpressionInfo.js +2 -2
  79. package/dist/bscPlugin/CallExpressionInfo.js.map +1 -1
  80. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +11 -11
  81. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  82. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +4 -4
  83. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  84. package/dist/bscPlugin/completions/CompletionsProcessor.d.ts +1 -49
  85. package/dist/bscPlugin/completions/CompletionsProcessor.js +23 -424
  86. package/dist/bscPlugin/completions/CompletionsProcessor.js.map +1 -1
  87. package/dist/bscPlugin/definition/DefinitionProvider.d.ts +13 -0
  88. package/dist/bscPlugin/definition/DefinitionProvider.js +200 -0
  89. package/dist/bscPlugin/definition/DefinitionProvider.js.map +1 -0
  90. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +87 -0
  91. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +1 -0
  92. package/dist/bscPlugin/hover/HoverProcessor.d.ts +3 -7
  93. package/dist/bscPlugin/hover/HoverProcessor.js +88 -128
  94. package/dist/bscPlugin/hover/HoverProcessor.js.map +1 -1
  95. package/dist/bscPlugin/hover/HoverProcessor.spec.js +24 -336
  96. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +1 -1
  97. package/dist/bscPlugin/references/ReferencesProvider.d.ts +12 -0
  98. package/dist/bscPlugin/references/ReferencesProvider.js +56 -0
  99. package/dist/bscPlugin/references/ReferencesProvider.js.map +1 -0
  100. package/dist/bscPlugin/references/ReferencesProvider.spec.js +51 -0
  101. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +1 -0
  102. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.d.ts +0 -1
  103. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js +5 -49
  104. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.js.map +1 -1
  105. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -22
  106. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +1 -1
  107. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.d.ts +7 -0
  108. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js +22 -0
  109. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.js.map +1 -0
  110. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +290 -0
  111. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +1 -0
  112. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.d.ts +7 -0
  113. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js +26 -0
  114. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.js.map +1 -0
  115. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +245 -0
  116. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +1 -0
  117. package/dist/bscPlugin/symbols/symbolUtils.d.ts +5 -0
  118. package/dist/bscPlugin/symbols/symbolUtils.js +140 -0
  119. package/dist/bscPlugin/symbols/symbolUtils.js.map +1 -0
  120. package/dist/bscPlugin/transpile/{BrsFileTranspileProcessor.d.ts → BrsFilePreTranspileProcessor.d.ts} +2 -4
  121. package/dist/bscPlugin/transpile/{BrsFileTranspileProcessor.js → BrsFilePreTranspileProcessor.js} +15 -36
  122. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.js.map +1 -0
  123. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +46 -0
  124. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +1 -0
  125. package/dist/bscPlugin/validation/BrsFileValidator.d.ts +1 -0
  126. package/dist/bscPlugin/validation/BrsFileValidator.js +30 -41
  127. package/dist/bscPlugin/validation/BrsFileValidator.js.map +1 -1
  128. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +2 -2
  129. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +1 -1
  130. package/dist/bscPlugin/validation/ProgramValidator.d.ts +3 -3
  131. package/dist/bscPlugin/validation/ProgramValidator.js +6 -6
  132. package/dist/bscPlugin/validation/ProgramValidator.js.map +1 -1
  133. package/dist/bscPlugin/validation/ScopeValidator.d.ts +6 -28
  134. package/dist/bscPlugin/validation/ScopeValidator.js +166 -387
  135. package/dist/bscPlugin/validation/ScopeValidator.js.map +1 -1
  136. package/dist/bscPlugin/validation/XmlFileValidator.js +9 -9
  137. package/dist/bscPlugin/validation/XmlFileValidator.js.map +1 -1
  138. package/dist/diagnosticUtils.d.ts +2 -3
  139. package/dist/diagnosticUtils.js +5 -5
  140. package/dist/diagnosticUtils.js.map +1 -1
  141. package/dist/examples/plugins/removePrint.js +1 -1
  142. package/dist/examples/plugins/removePrint.js.map +1 -1
  143. package/dist/files/BrsFile.Class.spec.js +143 -114
  144. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  145. package/dist/files/BrsFile.d.ts +61 -83
  146. package/dist/files/BrsFile.js +559 -612
  147. package/dist/files/BrsFile.js.map +1 -1
  148. package/dist/files/BrsFile.spec.js +1365 -1201
  149. package/dist/files/BrsFile.spec.js.map +1 -1
  150. package/dist/files/XmlFile.d.ts +28 -56
  151. package/dist/files/XmlFile.js +103 -89
  152. package/dist/files/XmlFile.js.map +1 -1
  153. package/dist/files/XmlFile.spec.js +179 -122
  154. package/dist/files/XmlFile.spec.js.map +1 -1
  155. package/dist/files/tests/imports.spec.js +19 -29
  156. package/dist/files/tests/imports.spec.js.map +1 -1
  157. package/dist/files/tests/optionalChaning.spec.js +14 -14
  158. package/dist/files/tests/optionalChaning.spec.js.map +1 -1
  159. package/dist/globalCallables.js +83 -88
  160. package/dist/globalCallables.js.map +1 -1
  161. package/dist/index.d.ts +1 -9
  162. package/dist/index.js +1 -9
  163. package/dist/index.js.map +1 -1
  164. package/dist/interfaces.d.ts +173 -423
  165. package/dist/interfaces.js +0 -24
  166. package/dist/interfaces.js.map +1 -1
  167. package/dist/lexer/Lexer.d.ts +9 -15
  168. package/dist/lexer/Lexer.js +35 -46
  169. package/dist/lexer/Lexer.js.map +1 -1
  170. package/dist/lexer/Lexer.spec.js +48 -40
  171. package/dist/lexer/Lexer.spec.js.map +1 -1
  172. package/dist/lexer/Token.d.ts +1 -5
  173. package/dist/lexer/Token.js +1 -1
  174. package/dist/lexer/Token.js.map +1 -1
  175. package/dist/lexer/TokenKind.d.ts +0 -6
  176. package/dist/lexer/TokenKind.js +2 -14
  177. package/dist/lexer/TokenKind.js.map +1 -1
  178. package/dist/logging.d.ts +9 -0
  179. package/dist/logging.js +16 -0
  180. package/dist/logging.js.map +1 -0
  181. package/dist/parser/AstNode.d.ts +6 -90
  182. package/dist/parser/AstNode.js +5 -96
  183. package/dist/parser/AstNode.js.map +1 -1
  184. package/dist/parser/AstNode.spec.js.map +1 -1
  185. package/dist/parser/BrsTranspileState.d.ts +3 -4
  186. package/dist/parser/BrsTranspileState.js +2 -3
  187. package/dist/parser/BrsTranspileState.js.map +1 -1
  188. package/dist/parser/Expression.d.ts +114 -137
  189. package/dist/parser/Expression.js +244 -373
  190. package/dist/parser/Expression.js.map +1 -1
  191. package/dist/parser/Parser.Class.spec.js +19 -46
  192. package/dist/parser/Parser.Class.spec.js.map +1 -1
  193. package/dist/parser/Parser.d.ts +18 -14
  194. package/dist/parser/Parser.js +196 -175
  195. package/dist/parser/Parser.js.map +1 -1
  196. package/dist/parser/Parser.spec.d.ts +0 -2
  197. package/dist/parser/Parser.spec.js +10 -674
  198. package/dist/parser/Parser.spec.js.map +1 -1
  199. package/dist/parser/SGParser.d.ts +6 -44
  200. package/dist/parser/SGParser.js +198 -194
  201. package/dist/parser/SGParser.js.map +1 -1
  202. package/dist/parser/SGParser.spec.js +11 -14
  203. package/dist/parser/SGParser.spec.js.map +1 -1
  204. package/dist/parser/SGTypes.d.ts +52 -280
  205. package/dist/parser/SGTypes.js +185 -562
  206. package/dist/parser/SGTypes.js.map +1 -1
  207. package/dist/parser/Statement.d.ts +140 -172
  208. package/dist/parser/Statement.js +201 -337
  209. package/dist/parser/Statement.js.map +1 -1
  210. package/dist/parser/Statement.spec.js.map +1 -1
  211. package/dist/parser/TranspileState.d.ts +3 -2
  212. package/dist/parser/TranspileState.js +8 -10
  213. package/dist/parser/TranspileState.js.map +1 -1
  214. package/dist/parser/tests/Parser.spec.js +3 -5
  215. package/dist/parser/tests/Parser.spec.js.map +1 -1
  216. package/dist/parser/tests/controlFlow/For.spec.js +8 -16
  217. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  218. package/dist/parser/tests/controlFlow/ForEach.spec.js +6 -12
  219. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  220. package/dist/parser/tests/controlFlow/While.spec.js +4 -8
  221. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  222. package/dist/parser/tests/expression/Call.spec.js +4 -4
  223. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  224. package/dist/parser/tests/expression/Indexing.spec.js +25 -0
  225. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  226. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +73 -29
  227. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  228. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +10 -10
  229. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -1
  230. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +24 -24
  231. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  232. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +47 -35
  233. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  234. package/dist/parser/tests/expression/TernaryExpression.spec.js +83 -36
  235. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  236. package/dist/parser/tests/expression/UnaryExpression.spec.js +2 -2
  237. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +1 -1
  238. package/dist/parser/tests/statement/ConstStatement.spec.js +26 -27
  239. package/dist/parser/tests/statement/ConstStatement.spec.js.map +1 -1
  240. package/dist/parser/tests/statement/Continue.spec.js +2 -2
  241. package/dist/parser/tests/statement/Continue.spec.js.map +1 -1
  242. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  243. package/dist/parser/tests/statement/Enum.spec.js +393 -90
  244. package/dist/parser/tests/statement/Enum.spec.js.map +1 -1
  245. package/dist/parser/tests/statement/For.spec.js +6 -6
  246. package/dist/parser/tests/statement/For.spec.js.map +1 -1
  247. package/dist/parser/tests/statement/ForEach.spec.js +4 -4
  248. package/dist/parser/tests/statement/ForEach.spec.js.map +1 -1
  249. package/dist/parser/tests/statement/Function.spec.js +1 -1
  250. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  251. package/dist/parser/tests/statement/InterfaceStatement.spec.js +18 -18
  252. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -1
  253. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  254. package/dist/parser/tests/statement/PrintStatement.spec.js +13 -16
  255. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  256. package/dist/parser/tests/statement/ReturnStatement.spec.js +3 -5
  257. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  258. package/dist/parser/tests/statement/Set.spec.js +13 -26
  259. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  260. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  261. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  262. package/dist/preprocessor/Chunk.js +1 -2
  263. package/dist/preprocessor/Chunk.js.map +1 -1
  264. package/dist/preprocessor/Preprocessor.d.ts +3 -4
  265. package/dist/preprocessor/Preprocessor.js +3 -3
  266. package/dist/preprocessor/Preprocessor.js.map +1 -1
  267. package/dist/preprocessor/PreprocessorParser.js +8 -1
  268. package/dist/preprocessor/PreprocessorParser.js.map +1 -1
  269. package/dist/roku-types/data.json +293 -243
  270. package/dist/roku-types/index.d.ts +38 -17
  271. package/dist/types/ArrayType.d.ts +4 -9
  272. package/dist/types/ArrayType.js +24 -72
  273. package/dist/types/ArrayType.js.map +1 -1
  274. package/dist/types/ArrayType.spec.js +10 -39
  275. package/dist/types/ArrayType.spec.js.map +1 -1
  276. package/dist/types/BooleanType.d.ts +4 -8
  277. package/dist/types/BooleanType.js +8 -19
  278. package/dist/types/BooleanType.js.map +1 -1
  279. package/dist/types/BooleanType.spec.js +3 -9
  280. package/dist/types/BooleanType.spec.js.map +1 -1
  281. package/dist/types/BscType.d.ts +2 -29
  282. package/dist/types/BscType.js +0 -113
  283. package/dist/types/BscType.js.map +1 -1
  284. package/dist/types/CustomType.d.ts +9 -0
  285. package/dist/types/CustomType.js +32 -0
  286. package/dist/types/CustomType.js.map +1 -0
  287. package/dist/types/DoubleType.d.ts +4 -8
  288. package/dist/types/DoubleType.js +20 -23
  289. package/dist/types/DoubleType.js.map +1 -1
  290. package/dist/types/DoubleType.spec.js +3 -11
  291. package/dist/types/DoubleType.spec.js.map +1 -1
  292. package/dist/types/DynamicType.d.ts +3 -9
  293. package/dist/types/DynamicType.js +2 -18
  294. package/dist/types/DynamicType.js.map +1 -1
  295. package/dist/types/DynamicType.spec.js +4 -15
  296. package/dist/types/DynamicType.spec.js.map +1 -1
  297. package/dist/types/FloatType.d.ts +4 -8
  298. package/dist/types/FloatType.js +20 -23
  299. package/dist/types/FloatType.js.map +1 -1
  300. package/dist/types/FloatType.spec.js +3 -3
  301. package/dist/types/FloatType.spec.js.map +1 -1
  302. package/dist/types/FunctionType.d.ts +20 -10
  303. package/dist/types/FunctionType.js +52 -27
  304. package/dist/types/FunctionType.js.map +1 -1
  305. package/dist/types/FunctionType.spec.js +23 -0
  306. package/dist/types/FunctionType.spec.js.map +1 -0
  307. package/dist/types/IntegerType.d.ts +4 -8
  308. package/dist/types/IntegerType.js +20 -23
  309. package/dist/types/IntegerType.js.map +1 -1
  310. package/dist/types/IntegerType.spec.js +3 -7
  311. package/dist/types/IntegerType.spec.js.map +1 -1
  312. package/dist/types/InterfaceType.d.ts +10 -12
  313. package/dist/types/InterfaceType.js +48 -23
  314. package/dist/types/InterfaceType.js.map +1 -1
  315. package/dist/types/InterfaceType.spec.js +45 -82
  316. package/dist/types/InterfaceType.spec.js.map +1 -1
  317. package/dist/types/InvalidType.d.ts +4 -7
  318. package/dist/types/InvalidType.js +8 -18
  319. package/dist/types/InvalidType.js.map +1 -1
  320. package/dist/types/InvalidType.spec.js +3 -7
  321. package/dist/types/InvalidType.spec.js.map +1 -1
  322. package/dist/types/LongIntegerType.d.ts +4 -8
  323. package/dist/types/LongIntegerType.js +20 -23
  324. package/dist/types/LongIntegerType.js.map +1 -1
  325. package/dist/types/LongIntegerType.spec.js +3 -9
  326. package/dist/types/LongIntegerType.spec.js.map +1 -1
  327. package/dist/types/ObjectType.d.ts +4 -8
  328. package/dist/types/ObjectType.js +7 -21
  329. package/dist/types/ObjectType.js.map +1 -1
  330. package/dist/types/ObjectType.spec.js +2 -2
  331. package/dist/types/ObjectType.spec.js.map +1 -1
  332. package/dist/types/StringType.d.ts +4 -11
  333. package/dist/types/StringType.js +8 -23
  334. package/dist/types/StringType.js.map +1 -1
  335. package/dist/types/StringType.spec.js +2 -2
  336. package/dist/types/StringType.spec.js.map +1 -1
  337. package/dist/types/UninitializedType.d.ts +3 -7
  338. package/dist/types/UninitializedType.js +3 -14
  339. package/dist/types/UninitializedType.js.map +1 -1
  340. package/dist/types/VoidType.d.ts +4 -8
  341. package/dist/types/VoidType.js +8 -18
  342. package/dist/types/VoidType.js.map +1 -1
  343. package/dist/types/VoidType.spec.js +2 -2
  344. package/dist/types/VoidType.spec.js.map +1 -1
  345. package/dist/util.d.ts +43 -104
  346. package/dist/util.js +243 -640
  347. package/dist/util.js.map +1 -1
  348. package/dist/validators/ClassValidator.d.ts +6 -1
  349. package/dist/validators/ClassValidator.js +61 -20
  350. package/dist/validators/ClassValidator.js.map +1 -1
  351. package/package.json +13 -11
  352. package/dist/ActionPipeline.d.ts +0 -10
  353. package/dist/ActionPipeline.js +0 -40
  354. package/dist/ActionPipeline.js.map +0 -1
  355. package/dist/AstValidationSegmenter.d.ts +0 -25
  356. package/dist/AstValidationSegmenter.js +0 -150
  357. package/dist/AstValidationSegmenter.js.map +0 -1
  358. package/dist/CacheVerifier.d.ts +0 -7
  359. package/dist/CacheVerifier.js +0 -20
  360. package/dist/CacheVerifier.js.map +0 -1
  361. package/dist/astUtils/Editor.js.map +0 -1
  362. package/dist/astUtils/Editor.spec.js.map +0 -1
  363. package/dist/bscPlugin/FileWriter.d.ts +0 -6
  364. package/dist/bscPlugin/FileWriter.js +0 -24
  365. package/dist/bscPlugin/FileWriter.js.map +0 -1
  366. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js +0 -1658
  367. package/dist/bscPlugin/completions/CompletionsProcessor.spec.js.map +0 -1
  368. package/dist/bscPlugin/fileProviders/FileProvider.d.ts +0 -9
  369. package/dist/bscPlugin/fileProviders/FileProvider.js +0 -51
  370. package/dist/bscPlugin/fileProviders/FileProvider.js.map +0 -1
  371. package/dist/bscPlugin/serialize/BslibInjector.spec.js +0 -19
  372. package/dist/bscPlugin/serialize/BslibInjector.spec.js.map +0 -1
  373. package/dist/bscPlugin/serialize/BslibManager.d.ts +0 -9
  374. package/dist/bscPlugin/serialize/BslibManager.js +0 -40
  375. package/dist/bscPlugin/serialize/BslibManager.js.map +0 -1
  376. package/dist/bscPlugin/serialize/FileSerializer.d.ts +0 -9
  377. package/dist/bscPlugin/serialize/FileSerializer.js +0 -72
  378. package/dist/bscPlugin/serialize/FileSerializer.js.map +0 -1
  379. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.js.map +0 -1
  380. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js +0 -41
  381. package/dist/bscPlugin/transpile/BrsFileTranspileProcessor.spec.js.map +0 -1
  382. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.d.ts +0 -11
  383. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js +0 -53
  384. package/dist/bscPlugin/transpile/XmlFilePreTranspileProcessor.js.map +0 -1
  385. package/dist/bscPlugin/validation/ScopeValidator.spec.js +0 -2004
  386. package/dist/bscPlugin/validation/ScopeValidator.spec.js.map +0 -1
  387. package/dist/files/AssetFile.d.ts +0 -26
  388. package/dist/files/AssetFile.js +0 -26
  389. package/dist/files/AssetFile.js.map +0 -1
  390. package/dist/files/Factory.d.ts +0 -25
  391. package/dist/files/Factory.js +0 -22
  392. package/dist/files/Factory.js.map +0 -1
  393. package/dist/files/File.d.ts +0 -106
  394. package/dist/files/File.js +0 -16
  395. package/dist/files/File.js.map +0 -1
  396. package/dist/files/LazyFileData.d.ts +0 -20
  397. package/dist/files/LazyFileData.js +0 -54
  398. package/dist/files/LazyFileData.js.map +0 -1
  399. package/dist/files/LazyFileData.spec.js +0 -27
  400. package/dist/files/LazyFileData.spec.js.map +0 -1
  401. package/dist/parser/tests/expression/TypeExpression.spec.js +0 -127
  402. package/dist/parser/tests/expression/TypeExpression.spec.js.map +0 -1
  403. package/dist/types/AssociativeArrayType.d.ts +0 -11
  404. package/dist/types/AssociativeArrayType.js +0 -52
  405. package/dist/types/AssociativeArrayType.js.map +0 -1
  406. package/dist/types/BaseFunctionType.d.ts +0 -9
  407. package/dist/types/BaseFunctionType.js +0 -25
  408. package/dist/types/BaseFunctionType.js.map +0 -1
  409. package/dist/types/BscTypeKind.d.ts +0 -25
  410. package/dist/types/BscTypeKind.js +0 -30
  411. package/dist/types/BscTypeKind.js.map +0 -1
  412. package/dist/types/BuiltInInterfaceAdder.d.ts +0 -23
  413. package/dist/types/BuiltInInterfaceAdder.js +0 -160
  414. package/dist/types/BuiltInInterfaceAdder.js.map +0 -1
  415. package/dist/types/BuiltInInterfaceAdder.spec.d.ts +0 -1
  416. package/dist/types/BuiltInInterfaceAdder.spec.js +0 -116
  417. package/dist/types/BuiltInInterfaceAdder.spec.js.map +0 -1
  418. package/dist/types/ClassType.d.ts +0 -17
  419. package/dist/types/ClassType.js +0 -58
  420. package/dist/types/ClassType.js.map +0 -1
  421. package/dist/types/ClassType.spec.d.ts +0 -1
  422. package/dist/types/ClassType.spec.js +0 -77
  423. package/dist/types/ClassType.spec.js.map +0 -1
  424. package/dist/types/ComponentType.d.ts +0 -26
  425. package/dist/types/ComponentType.js +0 -83
  426. package/dist/types/ComponentType.js.map +0 -1
  427. package/dist/types/EnumType.d.ts +0 -40
  428. package/dist/types/EnumType.js +0 -81
  429. package/dist/types/EnumType.js.map +0 -1
  430. package/dist/types/EnumType.spec.d.ts +0 -1
  431. package/dist/types/EnumType.spec.js +0 -33
  432. package/dist/types/EnumType.spec.js.map +0 -1
  433. package/dist/types/InheritableType.d.ts +0 -28
  434. package/dist/types/InheritableType.js +0 -152
  435. package/dist/types/InheritableType.js.map +0 -1
  436. package/dist/types/NamespaceType.d.ts +0 -12
  437. package/dist/types/NamespaceType.js +0 -28
  438. package/dist/types/NamespaceType.js.map +0 -1
  439. package/dist/types/ReferenceType.d.ts +0 -63
  440. package/dist/types/ReferenceType.js +0 -423
  441. package/dist/types/ReferenceType.js.map +0 -1
  442. package/dist/types/ReferenceType.spec.d.ts +0 -1
  443. package/dist/types/ReferenceType.spec.js +0 -137
  444. package/dist/types/ReferenceType.spec.js.map +0 -1
  445. package/dist/types/TypedFunctionType.d.ts +0 -33
  446. package/dist/types/TypedFunctionType.js +0 -106
  447. package/dist/types/TypedFunctionType.js.map +0 -1
  448. package/dist/types/TypedFunctionType.spec.d.ts +0 -1
  449. package/dist/types/TypedFunctionType.spec.js +0 -122
  450. package/dist/types/TypedFunctionType.spec.js.map +0 -1
  451. package/dist/types/UnionType.d.ts +0 -20
  452. package/dist/types/UnionType.js +0 -123
  453. package/dist/types/UnionType.js.map +0 -1
  454. package/dist/types/UnionType.spec.d.ts +0 -1
  455. package/dist/types/UnionType.spec.js +0 -130
  456. package/dist/types/UnionType.spec.js.map +0 -1
  457. package/dist/types/helper.spec.d.ts +0 -1
  458. package/dist/types/helper.spec.js +0 -145
  459. package/dist/types/helper.spec.js.map +0 -1
  460. package/dist/types/helpers.d.ts +0 -24
  461. package/dist/types/helpers.js +0 -178
  462. package/dist/types/helpers.js.map +0 -1
  463. package/dist/types/index.d.ts +0 -22
  464. package/dist/types/index.js +0 -39
  465. package/dist/types/index.js.map +0 -1
  466. /package/dist/astUtils/{Editor.spec.d.ts → AstEditor.spec.d.ts} +0 -0
  467. /package/dist/bscPlugin/{completions/CompletionsProcessor.spec.d.ts → definition/DefinitionProvider.spec.d.ts} +0 -0
  468. /package/dist/bscPlugin/{serialize/BslibInjector.spec.d.ts → references/ReferencesProvider.spec.d.ts} +0 -0
  469. /package/dist/bscPlugin/{transpile/BrsFileTranspileProcessor.spec.d.ts → symbols/DocumentSymbolProcessor.spec.d.ts} +0 -0
  470. /package/dist/bscPlugin/{validation/ScopeValidator.spec.d.ts → symbols/WorkspaceSymbolProcessor.spec.d.ts} +0 -0
  471. /package/dist/{files/LazyFileData.spec.d.ts → bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts} +0 -0
  472. /package/dist/{parser/tests/expression/TypeExpression.spec.d.ts → types/FunctionType.spec.d.ts} +0 -0
package/dist/util.js CHANGED
@@ -13,40 +13,23 @@ 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
17
  const IntegerType_1 = require("./types/IntegerType");
18
+ const InvalidType_1 = require("./types/InvalidType");
17
19
  const LongIntegerType_1 = require("./types/LongIntegerType");
18
20
  const ObjectType_1 = require("./types/ObjectType");
19
21
  const StringType_1 = require("./types/StringType");
20
22
  const VoidType_1 = require("./types/VoidType");
21
23
  const Parser_1 = require("./parser/Parser");
22
- const Logger_1 = require("./Logger");
24
+ const logging_1 = require("./logging");
23
25
  const TokenKind_1 = require("./lexer/TokenKind");
24
26
  const reflection_1 = require("./astUtils/reflection");
25
27
  const visitors_1 = require("./astUtils/visitors");
28
+ const CustomType_1 = require("./types/CustomType");
26
29
  const source_map_1 = require("source-map");
27
30
  const requireRelative = require("require-relative");
28
- const AstNode_1 = require("./parser/AstNode");
29
- const creators_1 = require("./astUtils/creators");
30
- const FunctionType_1 = require("./types/FunctionType");
31
- const ArrayType_1 = require("./types/ArrayType");
32
- const SymbolTable_1 = require("./SymbolTable");
33
- const AssociativeArrayType_1 = require("./types/AssociativeArrayType");
34
- const ComponentType_1 = require("./types/ComponentType");
35
- const diagnosticUtils_1 = require("./diagnosticUtils");
36
- const ReferenceType_1 = require("./types/ReferenceType");
31
+ const roku_types_1 = require("./roku-types");
37
32
  class Util {
38
- constructor() {
39
- /**
40
- * A cache of `Range` objects. The key is a 52bit integer created from the 4 range integers and leveraging bitshifting.
41
- * The whole point of this cache is to reduce garbage collection churn, so we didn't want to use string concatenation for the key
42
- */
43
- this.rangeCache = new Map();
44
- /**
45
- * A cache of `Position` objects. The key is a 26bit integer created from line and character and leveraging bitshifting
46
- * The whole point of this cache is to reduce garbage collection churn, so we didn't want to use string concatenation for the key
47
- */
48
- this.positionCache = new Map();
49
- }
50
33
  clearConsole() {
51
34
  // process.stdout.write('\x1Bc');
52
35
  }
@@ -87,16 +70,18 @@ class Util {
87
70
  * Determine if this path is a directory
88
71
  */
89
72
  isDirectorySync(dirPath) {
90
- return fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory();
73
+ return dirPath !== undefined && fs.existsSync(dirPath) && fs.lstatSync(dirPath).isDirectory();
91
74
  }
92
75
  /**
93
76
  * Given a pkg path of any kind, transform it to a roku-specific pkg path (i.e. "pkg:/some/path.brs")
94
77
  */
95
78
  sanitizePkgPath(pkgPath) {
96
- //convert all slashes to forwardslash
97
- pkgPath = pkgPath.replace(/[\/\\]+/g, '/');
98
- //ensure every path has the leading pkg:/
99
- return 'pkg:/' + pkgPath.replace(/^pkg:\//i, '');
79
+ pkgPath = pkgPath.replace(/\\/g, '/');
80
+ //if there's no protocol, assume it's supposed to start with `pkg:/`
81
+ if (!this.startsWithProtocol(pkgPath)) {
82
+ pkgPath = 'pkg:/' + pkgPath;
83
+ }
84
+ return pkgPath;
100
85
  }
101
86
  /**
102
87
  * Determine if the given path starts with a protocol
@@ -106,10 +91,10 @@ class Util {
106
91
  }
107
92
  /**
108
93
  * Given a pkg path of any kind, transform it to a roku-specific pkg path (i.e. "pkg:/some/path.brs")
109
- * @deprecated use `sanitizePkgPath instead. Will be removed in v1
110
94
  */
111
95
  getRokuPkgPath(pkgPath) {
112
- return this.sanitizePkgPath(pkgPath);
96
+ pkgPath = pkgPath.replace(/\\/g, '/');
97
+ return 'pkg:/' + pkgPath;
113
98
  }
114
99
  /**
115
100
  * Given a path to a file/directory, replace all path separators with the current system's version.
@@ -228,6 +213,9 @@ class Util {
228
213
  if (result.cwd) {
229
214
  result.cwd = path.resolve(projectFileCwd, result.cwd);
230
215
  }
216
+ if (result.stagingDir) {
217
+ result.stagingDir = path.resolve(projectFileCwd, result.stagingDir);
218
+ }
231
219
  return result;
232
220
  }
233
221
  }
@@ -275,6 +263,7 @@ class Util {
275
263
  throw err;
276
264
  }
277
265
  else {
266
+ //justification: `result` is set as long as `err` is not set and vice versa
278
267
  return result;
279
268
  }
280
269
  }
@@ -297,7 +286,7 @@ class Util {
297
286
  result.project = config.project;
298
287
  }
299
288
  if (result.project) {
300
- let configFile = this.loadConfigFile(result.project, null, config === null || config === void 0 ? void 0 : config.cwd);
289
+ let configFile = this.loadConfigFile(result.project, undefined, config === null || config === void 0 ? void 0 : config.cwd);
301
290
  result = Object.assign(result, configFile);
302
291
  }
303
292
  //override the defaults with the specified options
@@ -310,40 +299,50 @@ class Util {
310
299
  */
311
300
  normalizeConfig(config) {
312
301
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
313
- config = config || {};
314
- config.cwd = (_a = config.cwd) !== null && _a !== void 0 ? _a : process.cwd();
315
- config.deploy = config.deploy === true ? true : false;
316
- //use default files array from rokuDeploy
317
- config.files = (_b = config.files) !== null && _b !== void 0 ? _b : [...roku_deploy_1.DefaultFiles];
318
- config.createPackage = config.createPackage === false ? false : true;
319
- let rootFolderName = path.basename(config.cwd);
320
- config.outFile = (_c = config.outFile) !== null && _c !== void 0 ? _c : `./out/${rootFolderName}.zip`;
321
- config.sourceMap = config.sourceMap === true;
322
- config.username = (_d = config.username) !== null && _d !== void 0 ? _d : 'rokudev';
323
- config.watch = config.watch === true ? true : false;
324
- config.emitFullPaths = config.emitFullPaths === true ? true : false;
325
- config.retainStagingDir = (_e = config.retainStagingDir) !== null && _e !== void 0 ? _e : false;
326
- config.copyToStaging = config.copyToStaging === false ? false : true;
327
- config.ignoreErrorCodes = (_f = config.ignoreErrorCodes) !== null && _f !== void 0 ? _f : [];
328
- config.diagnosticSeverityOverrides = (_g = config.diagnosticSeverityOverrides) !== null && _g !== void 0 ? _g : {};
329
- config.diagnosticFilters = (_h = config.diagnosticFilters) !== null && _h !== void 0 ? _h : [];
330
- config.plugins = (_j = config.plugins) !== null && _j !== void 0 ? _j : [];
331
- config.autoImportComponentScript = config.autoImportComponentScript === true ? true : false;
332
- config.showDiagnosticsInConsole = config.showDiagnosticsInConsole === false ? false : true;
333
- config.sourceRoot = config.sourceRoot ? standardizePath(config.sourceRoot) : undefined;
334
- config.allowBrighterScriptInBrightScript = config.allowBrighterScriptInBrightScript === true ? true : false;
335
- config.emitDefinitions = config.emitDefinitions === true ? true : false;
336
- config.removeParameterTypes = config.removeParameterTypes === true ? true : false;
302
+ config = config !== null && config !== void 0 ? config : {};
303
+ const cwd = (_a = config.cwd) !== null && _a !== void 0 ? _a : process.cwd();
304
+ const rootFolderName = path.basename(cwd);
305
+ const retainStagingDir = ((_b = config.retainStagingDir) !== null && _b !== void 0 ? _b : config.retainStagingFolder) === true ? true : false;
306
+ let logLevel = logging_1.LogLevel.log;
337
307
  if (typeof config.logLevel === 'string') {
338
- config.logLevel = Logger_1.LogLevel[config.logLevel.toLowerCase()];
308
+ logLevel = (_c = logging_1.LogLevel[config.logLevel.toLowerCase()]) !== null && _c !== void 0 ? _c : logging_1.LogLevel.log;
339
309
  }
340
- config.logLevel = (_k = config.logLevel) !== null && _k !== void 0 ? _k : Logger_1.LogLevel.log;
341
- config.bslibDestinationDir = (_l = config.bslibDestinationDir) !== null && _l !== void 0 ? _l : 'source';
342
- if (config.bslibDestinationDir !== 'source') {
310
+ let bslibDestinationDir = (_d = config.bslibDestinationDir) !== null && _d !== void 0 ? _d : 'source';
311
+ if (bslibDestinationDir !== 'source') {
343
312
  // strip leading and trailing slashes
344
- config.bslibDestinationDir = config.bslibDestinationDir.replace(/^(\/*)(.*?)(\/*)$/, '$2');
345
- }
346
- return config;
313
+ bslibDestinationDir = bslibDestinationDir.replace(/^(\/*)(.*?)(\/*)$/, '$2');
314
+ }
315
+ const configWithDefaults = {
316
+ cwd: cwd,
317
+ deploy: config.deploy === true ? true : false,
318
+ //use default files array from rokuDeploy
319
+ files: (_e = config.files) !== null && _e !== void 0 ? _e : [...roku_deploy_1.DefaultFiles],
320
+ createPackage: config.createPackage === false ? false : true,
321
+ outFile: (_f = config.outFile) !== null && _f !== void 0 ? _f : `./out/${rootFolderName}.zip`,
322
+ sourceMap: config.sourceMap === true,
323
+ username: (_g = config.username) !== null && _g !== void 0 ? _g : 'rokudev',
324
+ watch: config.watch === true ? true : false,
325
+ emitFullPaths: config.emitFullPaths === true ? true : false,
326
+ retainStagingDir: retainStagingDir,
327
+ retainStagingFolder: retainStagingDir,
328
+ copyToStaging: config.copyToStaging === false ? false : true,
329
+ ignoreErrorCodes: (_h = config.ignoreErrorCodes) !== null && _h !== void 0 ? _h : [],
330
+ diagnosticSeverityOverrides: (_j = config.diagnosticSeverityOverrides) !== null && _j !== void 0 ? _j : {},
331
+ diagnosticFilters: (_k = config.diagnosticFilters) !== null && _k !== void 0 ? _k : [],
332
+ plugins: (_l = config.plugins) !== null && _l !== void 0 ? _l : [],
333
+ pruneEmptyCodeFiles: config.pruneEmptyCodeFiles === true ? true : false,
334
+ autoImportComponentScript: config.autoImportComponentScript === true ? true : false,
335
+ showDiagnosticsInConsole: config.showDiagnosticsInConsole === false ? false : true,
336
+ sourceRoot: config.sourceRoot ? standardizePath(config.sourceRoot) : undefined,
337
+ allowBrighterScriptInBrightScript: config.allowBrighterScriptInBrightScript === true ? true : false,
338
+ emitDefinitions: config.emitDefinitions === true ? true : false,
339
+ removeParameterTypes: config.removeParameterTypes === true ? true : false,
340
+ logLevel: logLevel,
341
+ bslibDestinationDir: bslibDestinationDir
342
+ };
343
+ //mutate `config` in case anyone is holding a reference to the incomplete one
344
+ const merged = Object.assign(config, configWithDefaults);
345
+ return merged;
347
346
  }
348
347
  /**
349
348
  * Get the root directory from options.
@@ -391,9 +390,13 @@ class Util {
391
390
  * compute the pkg path for the target relative to the source file's location
392
391
  */
393
392
  getPkgPathFromTarget(containingFilePathAbsolute, targetPath) {
394
- //if the target starts with 'pkg:', it's an absolute path. Return as is
395
- if (targetPath.startsWith('pkg:/')) {
396
- targetPath = targetPath.substring(5);
393
+ var _a;
394
+ // https://regex101.com/r/w7CG2N/1
395
+ const regexp = /^(?:pkg|libpkg):(\/)?/i;
396
+ const [fullScheme, slash] = (_a = regexp.exec(targetPath)) !== null && _a !== void 0 ? _a : [];
397
+ //if the target starts with 'pkg:' or 'libpkg:' then it's an absolute path. Return as is
398
+ if (slash) {
399
+ targetPath = targetPath.substring(fullScheme.length);
397
400
  if (targetPath === '') {
398
401
  return null;
399
402
  }
@@ -401,7 +404,8 @@ class Util {
401
404
  return path.normalize(targetPath);
402
405
  }
403
406
  }
404
- if (targetPath === 'pkg:') {
407
+ //if the path is exactly `pkg:` or `libpkg:`
408
+ if (targetPath === fullScheme && !slash) {
405
409
  return null;
406
410
  }
407
411
  //remove the filename
@@ -545,65 +549,6 @@ class Util {
545
549
  }
546
550
  return 0;
547
551
  }
548
- /**
549
- * Combine all the documentation found before a token (i.e. comment tokens)
550
- */
551
- getTokenDocumentation(tokens, token) {
552
- const comments = [];
553
- const idx = tokens === null || tokens === void 0 ? void 0 : tokens.indexOf(token);
554
- if (!idx || idx === -1) {
555
- return undefined;
556
- }
557
- for (let i = idx - 1; i >= 0; i--) {
558
- const token = tokens[i];
559
- //skip whitespace and newline chars
560
- if (token.kind === TokenKind_1.TokenKind.Comment) {
561
- comments.push(token);
562
- }
563
- else if (token.kind === TokenKind_1.TokenKind.Newline || token.kind === TokenKind_1.TokenKind.Whitespace) {
564
- //skip these tokens
565
- continue;
566
- //any other token means there are no more comments
567
- }
568
- else {
569
- break;
570
- }
571
- }
572
- if (comments.length > 0) {
573
- return comments.reverse().map(x => x.text.replace(/^('|rem)/i, '').trim()).map(line => {
574
- if (line.startsWith('@')) {
575
- // Handle jsdoc/brightscriptdoc tags specially
576
- // make sure they are on their own markdown line, and add italics
577
- const firstSpaceIndex = line.indexOf(' ');
578
- if (firstSpaceIndex === -1) {
579
- return `\n_${line}_`;
580
- }
581
- const firstWord = line.substring(0, firstSpaceIndex);
582
- return `\n_${firstWord}_ ${line.substring(firstSpaceIndex + 1)}`;
583
- }
584
- return line;
585
- }).join('\n');
586
- }
587
- }
588
- /**
589
- * Combine all the documentation for a node - uses the AstNode's leadingTrivia property
590
- */
591
- getNodeDocumentation(node) {
592
- if (!node) {
593
- return;
594
- }
595
- const leadingTrivia = node.getLeadingTrivia();
596
- return this.getTokenDocumentation(leadingTrivia, leadingTrivia[leadingTrivia.length - 1]);
597
- }
598
- /**
599
- * Prefixes a component name so it can be used as type in the symbol table, without polluting available symbols
600
- *
601
- * @param sgNodeName the Name of the component
602
- * @returns the node name, prefixed with `roSGNode`
603
- */
604
- getSgNodeTypeName(sgNodeName) {
605
- return 'roSGNode' + sgNodeName;
606
- }
607
552
  /**
608
553
  * Parse an xml file and get back a javascript object containing its results
609
554
  */
@@ -745,12 +690,11 @@ class Util {
745
690
  //this diagnostic is affected by this flag
746
691
  if (diagnostic.range && this.rangeContains(flag.affectedRange, diagnostic.range.start)) {
747
692
  //if the flag acts upon this diagnostic's code
748
- if (flag.codes === null || flag.codes.includes(diagnosticCode)) {
693
+ if (flag.codes === null || (diagnosticCode !== undefined && flag.codes.includes(diagnosticCode))) {
749
694
  return true;
750
695
  }
751
696
  }
752
697
  }
753
- return false;
754
698
  }
755
699
  /**
756
700
  * Walks up the chain to find the closest bsconfig.json file
@@ -827,7 +771,11 @@ class Util {
827
771
  * Get a location object back by extracting location information from other objects that contain location
828
772
  */
829
773
  getRange(startObj, endObj) {
830
- return exports.util.createRangeFromPositions(startObj.range.start, endObj.range.end);
774
+ var _a, _b;
775
+ if (!(startObj === null || startObj === void 0 ? void 0 : startObj.range) || !(endObj === null || endObj === void 0 ? void 0 : endObj.range)) {
776
+ return undefined;
777
+ }
778
+ return exports.util.createRangeFromPositions((_a = startObj.range) === null || _a === void 0 ? void 0 : _a.start, (_b = endObj.range) === null || _b === void 0 ? void 0 : _b.end);
831
779
  }
832
780
  /**
833
781
  * If the two items both start on the same line
@@ -844,7 +792,7 @@ class Util {
844
792
  * If the two items have lines that touch
845
793
  */
846
794
  linesTouch(first, second) {
847
- if (first && second && (first.range.start.line === second.range.start.line ||
795
+ if (first && second && (first.range !== undefined) && (second.range !== undefined) && (first.range.start.line === second.range.start.line ||
848
796
  first.range.start.line === second.range.end.line ||
849
797
  first.range.end.line === second.range.start.line ||
850
798
  first.range.end.line === second.range.end.line)) {
@@ -871,7 +819,8 @@ class Util {
871
819
  */
872
820
  getScriptImportAtPosition(scriptImports, position) {
873
821
  let scriptImport = scriptImports.find((x) => {
874
- return x.filePathRange.start.line === position.line &&
822
+ return x.filePathRange &&
823
+ x.filePathRange.start.line === position.line &&
875
824
  //column between start and end
876
825
  position.character >= x.filePathRange.start.character &&
877
826
  position.character <= x.filePathRange.end.character;
@@ -915,7 +864,9 @@ class Util {
915
864
  rangeLines.push(lines[i]);
916
865
  }
917
866
  const lastLine = rangeLines.pop();
918
- rangeLines.push(lastLine.substring(0, endCharacter));
867
+ if (lastLine !== undefined) {
868
+ rangeLines.push(lastLine.substring(0, endCharacter));
869
+ }
919
870
  return rangeLines.join('\n');
920
871
  }
921
872
  /**
@@ -931,23 +882,31 @@ class Util {
931
882
  * Helper for creating `Range` objects. Prefer using this function because vscode-languageserver's `Range.create()` is significantly slower
932
883
  */
933
884
  createRange(startLine, startCharacter, endLine, endCharacter) {
934
- // eslint-disable-next-line no-bitwise
935
- const key = (startLine << 39) + (startCharacter << 26) + (endLine << 13) + endCharacter;
936
- let range = this.rangeCache.get(key);
937
- if (!range) {
938
- range = {
939
- start: this.createPosition(startLine, startCharacter),
940
- end: this.createPosition(endLine, endCharacter)
941
- };
942
- this.rangeCache.set(key, range);
943
- }
944
- return range;
885
+ return {
886
+ start: {
887
+ line: startLine,
888
+ character: startCharacter
889
+ },
890
+ end: {
891
+ line: endLine,
892
+ character: endCharacter
893
+ }
894
+ };
945
895
  }
946
896
  /**
947
897
  * Create a `Range` from two `Position`s
948
898
  */
949
899
  createRangeFromPositions(startPosition, endPosition) {
950
- return this.createRange(startPosition.line, startPosition.character, endPosition.line, endPosition.character);
900
+ return {
901
+ start: {
902
+ line: startPosition.line,
903
+ character: startPosition.character
904
+ },
905
+ end: {
906
+ line: endPosition.line,
907
+ character: endPosition.character
908
+ }
909
+ };
951
910
  }
952
911
  /**
953
912
  * Given a list of ranges, create a range that starts with the first non-null lefthand range, and ends with the first non-null
@@ -977,7 +936,8 @@ class Util {
977
936
  }
978
937
  }
979
938
  if (leftmostRange) {
980
- return this.createRangeFromPositions(leftmostRange.start, rightmostRange.end);
939
+ //if we don't have a rightmost range, use the leftmost range for both the start and end
940
+ return this.createRangeFromPositions(leftmostRange.start, rightmostRange ? rightmostRange.end : leftmostRange.end);
981
941
  }
982
942
  else {
983
943
  return undefined;
@@ -987,17 +947,10 @@ class Util {
987
947
  * Create a `Position` object. Prefer this over `Position.create` for performance reasons
988
948
  */
989
949
  createPosition(line, character) {
990
- // eslint-disable-next-line no-bitwise
991
- const key = (line << 13) + character;
992
- let position = this.positionCache.get(key);
993
- if (!position) {
994
- position = {
995
- line: line,
996
- character: character
997
- };
998
- this.positionCache.set(key, position);
999
- }
1000
- return position;
950
+ return {
951
+ line: line,
952
+ character: character
953
+ };
1001
954
  }
1002
955
  /**
1003
956
  * Convert a list of tokens into a string, including their leading whitespace
@@ -1013,36 +966,37 @@ class Util {
1013
966
  /**
1014
967
  * Convert a token into a BscType
1015
968
  */
1016
- tokenToBscType(token) {
969
+ tokenToBscType(token, allowCustomType = true) {
1017
970
  // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
1018
971
  switch (token.kind) {
1019
972
  case TokenKind_1.TokenKind.Boolean:
1020
973
  return new BooleanType_1.BooleanType(token.text);
1021
974
  case TokenKind_1.TokenKind.True:
1022
975
  case TokenKind_1.TokenKind.False:
1023
- return BooleanType_1.BooleanType.instance;
976
+ return new BooleanType_1.BooleanType();
1024
977
  case TokenKind_1.TokenKind.Double:
1025
978
  return new DoubleType_1.DoubleType(token.text);
1026
979
  case TokenKind_1.TokenKind.DoubleLiteral:
1027
- return DoubleType_1.DoubleType.instance;
980
+ return new DoubleType_1.DoubleType();
1028
981
  case TokenKind_1.TokenKind.Dynamic:
1029
982
  return new DynamicType_1.DynamicType(token.text);
1030
983
  case TokenKind_1.TokenKind.Float:
1031
984
  return new FloatType_1.FloatType(token.text);
1032
985
  case TokenKind_1.TokenKind.FloatLiteral:
1033
- return FloatType_1.FloatType.instance;
986
+ return new FloatType_1.FloatType();
1034
987
  case TokenKind_1.TokenKind.Function:
1035
- return new FunctionType_1.FunctionType(token.text);
988
+ //TODO should there be a more generic function type without a signature that's assignable to all other function types?
989
+ return new FunctionType_1.FunctionType(new DynamicType_1.DynamicType(token.text));
1036
990
  case TokenKind_1.TokenKind.Integer:
1037
991
  return new IntegerType_1.IntegerType(token.text);
1038
992
  case TokenKind_1.TokenKind.IntegerLiteral:
1039
- return IntegerType_1.IntegerType.instance;
993
+ return new IntegerType_1.IntegerType();
1040
994
  case TokenKind_1.TokenKind.Invalid:
1041
- return DynamicType_1.DynamicType.instance; // TODO: use InvalidType better new InvalidType(token.text);
995
+ return new InvalidType_1.InvalidType(token.text);
1042
996
  case TokenKind_1.TokenKind.LongInteger:
1043
997
  return new LongIntegerType_1.LongIntegerType(token.text);
1044
998
  case TokenKind_1.TokenKind.LongIntegerLiteral:
1045
- return LongIntegerType_1.LongIntegerType.instance;
999
+ return new LongIntegerType_1.LongIntegerType();
1046
1000
  case TokenKind_1.TokenKind.Object:
1047
1001
  return new ObjectType_1.ObjectType(token.text);
1048
1002
  case TokenKind_1.TokenKind.String:
@@ -1051,7 +1005,7 @@ class Util {
1051
1005
  case TokenKind_1.TokenKind.TemplateStringExpressionBegin:
1052
1006
  case TokenKind_1.TokenKind.TemplateStringExpressionEnd:
1053
1007
  case TokenKind_1.TokenKind.TemplateStringQuasi:
1054
- return StringType_1.StringType.instance;
1008
+ return new StringType_1.StringType();
1055
1009
  case TokenKind_1.TokenKind.Void:
1056
1010
  return new VoidType_1.VoidType(token.text);
1057
1011
  case TokenKind_1.TokenKind.Identifier:
@@ -1060,16 +1014,14 @@ class Util {
1060
1014
  return new BooleanType_1.BooleanType(token.text);
1061
1015
  case 'double':
1062
1016
  return new DoubleType_1.DoubleType(token.text);
1063
- case 'dynamic':
1064
- return new DynamicType_1.DynamicType(token.text);
1065
1017
  case 'float':
1066
1018
  return new FloatType_1.FloatType(token.text);
1067
1019
  case 'function':
1068
- return new FunctionType_1.FunctionType(token.text);
1020
+ return new FunctionType_1.FunctionType(new DynamicType_1.DynamicType(token.text));
1069
1021
  case 'integer':
1070
1022
  return new IntegerType_1.IntegerType(token.text);
1071
1023
  case 'invalid':
1072
- return DynamicType_1.DynamicType.instance; // TODO: use InvalidType better new InvalidType(token.text);
1024
+ return new InvalidType_1.InvalidType(token.text);
1073
1025
  case 'longinteger':
1074
1026
  return new LongIntegerType_1.LongIntegerType(token.text);
1075
1027
  case 'object':
@@ -1079,246 +1031,14 @@ class Util {
1079
1031
  case 'void':
1080
1032
  return new VoidType_1.VoidType(token.text);
1081
1033
  }
1082
- }
1083
- }
1084
- /**
1085
- * Deciphers the correct types for fields based on docs
1086
- * https://developer.roku.com/en-ca/docs/references/scenegraph/xml-elements/interface.md
1087
- * @param typeDescriptor the type descriptor from the docs
1088
- * @returns {BscType} the known type, or dynamic
1089
- */
1090
- getNodeFieldType(typeDescriptor, lookupTable) {
1091
- const typeDescriptorLower = typeDescriptor.toLowerCase().trim();
1092
- const bscType = this.tokenToBscType((0, creators_1.createToken)(TokenKind_1.TokenKind.Identifier, typeDescriptorLower));
1093
- if (bscType) {
1094
- return bscType;
1095
- }
1096
- if (typeDescriptorLower.startsWith('array of ')) {
1097
- let arrayOfTypeName = typeDescriptorLower.substring(9); //cut off beginning 'array of'
1098
- if (arrayOfTypeName.endsWith('s')) {
1099
- // remove "s" in "floats", etc.
1100
- arrayOfTypeName = arrayOfTypeName.substring(0, arrayOfTypeName.length - 1);
1101
- }
1102
- if (arrayOfTypeName.endsWith('\'')) {
1103
- // remove "'" in "float's", etc.
1104
- arrayOfTypeName = arrayOfTypeName.substring(0, arrayOfTypeName.length - 1);
1105
- }
1106
- let arrayType = this.getNodeFieldType(arrayOfTypeName, lookupTable);
1107
- return new ArrayType_1.ArrayType(arrayType);
1108
- }
1109
- else if (typeDescriptorLower.startsWith('option ')) {
1110
- const actualTypeName = typeDescriptorLower.substring('option '.length); //cut off beginning 'option '
1111
- return this.getNodeFieldType(actualTypeName, lookupTable);
1112
- }
1113
- else if (typeDescriptorLower.startsWith('value ')) {
1114
- const actualTypeName = typeDescriptorLower.substring('value '.length); //cut off beginning 'value '
1115
- return this.getNodeFieldType(actualTypeName, lookupTable);
1116
- }
1117
- else if (typeDescriptorLower === 'uri') {
1118
- return StringType_1.StringType.instance;
1119
- }
1120
- else if (typeDescriptorLower === 'vector2d' || typeDescriptorLower === 'floatarray') {
1121
- return new ArrayType_1.ArrayType(FloatType_1.FloatType.instance);
1122
- }
1123
- else if (typeDescriptorLower === 'intarray') {
1124
- return new ArrayType_1.ArrayType(IntegerType_1.IntegerType.instance);
1125
- }
1126
- else if (typeDescriptorLower === 'boolarray') {
1127
- return new ArrayType_1.ArrayType(BooleanType_1.BooleanType.instance);
1128
- }
1129
- else if (typeDescriptorLower === 'stringarray' || typeDescriptorLower === 'strarray') {
1130
- return new ArrayType_1.ArrayType(StringType_1.StringType.instance);
1131
- }
1132
- else if (typeDescriptorLower === 'int') {
1133
- return IntegerType_1.IntegerType.instance;
1134
- }
1135
- else if (typeDescriptorLower === 'time') {
1136
- return FloatType_1.FloatType.instance;
1137
- }
1138
- else if (typeDescriptorLower === 'str') {
1139
- return StringType_1.StringType.instance;
1140
- }
1141
- else if (typeDescriptorLower === 'bool') {
1142
- return BooleanType_1.BooleanType.instance;
1143
- }
1144
- else if (typeDescriptorLower === 'assocarray' || typeDescriptorLower === 'associative array') {
1145
- return new AssociativeArrayType_1.AssociativeArrayType();
1146
- }
1147
- else if (typeDescriptorLower === 'node') {
1148
- return ComponentType_1.ComponentType.instance;
1149
- }
1150
- else if (typeDescriptorLower === 'nodearray') {
1151
- return new ArrayType_1.ArrayType(ComponentType_1.ComponentType.instance);
1152
- }
1153
- else if (lookupTable) {
1154
- //try doing a lookup
1155
- return lookupTable.getSymbolType(typeDescriptorLower, { flags: SymbolTable_1.SymbolTypeFlag.typetime });
1156
- }
1157
- // TODO: Handle 'rect2d', 'rect2dArray', 'color', 'colorarray', 'time'
1158
- return DynamicType_1.DynamicType.instance;
1159
- }
1160
- /**
1161
- * Return the type of the result of a binary operator
1162
- * Note: compound assignments (eg. +=) internally use a binary expression, so that's why TokenKind.PlusEqual, etc. are here too
1163
- */
1164
- binaryOperatorResultType(leftType, operator, rightType) {
1165
- if (((0, reflection_1.isAnyReferenceType)(leftType) && !leftType.isResolvable()) ||
1166
- ((0, reflection_1.isAnyReferenceType)(rightType) && !rightType.isResolvable())) {
1167
- return new ReferenceType_1.BinaryOperatorReferenceType(leftType, operator, rightType, (lhs, op, rhs) => {
1168
- return this.binaryOperatorResultType(lhs, op, rhs);
1169
- });
1170
- }
1171
- if ((0, reflection_1.isEnumMemberType)(leftType)) {
1172
- leftType = leftType.underlyingType;
1173
- }
1174
- if ((0, reflection_1.isEnumMemberType)(rightType)) {
1175
- rightType = rightType.underlyingType;
1176
- }
1177
- let hasDouble = (0, reflection_1.isDoubleType)(leftType) || (0, reflection_1.isDoubleType)(rightType);
1178
- let hasFloat = (0, reflection_1.isFloatType)(leftType) || (0, reflection_1.isFloatType)(rightType);
1179
- let hasLongInteger = (0, reflection_1.isLongIntegerType)(leftType) || (0, reflection_1.isLongIntegerType)(rightType);
1180
- let hasInvalid = (0, reflection_1.isInvalidType)(leftType) || (0, reflection_1.isInvalidType)(rightType);
1181
- let hasDynamic = (0, reflection_1.isDynamicType)(leftType) || (0, reflection_1.isDynamicType)(rightType);
1182
- let bothNumbers = (0, reflection_1.isNumberType)(leftType) && (0, reflection_1.isNumberType)(rightType);
1183
- let bothStrings = (0, reflection_1.isStringType)(leftType) && (0, reflection_1.isStringType)(rightType);
1184
- let eitherBooleanOrNum = ((0, reflection_1.isNumberType)(leftType) || (0, reflection_1.isBooleanType)(leftType)) && ((0, reflection_1.isNumberType)(rightType) || (0, reflection_1.isBooleanType)(rightType));
1185
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
1186
- switch (operator.kind) {
1187
- // Math operators
1188
- case TokenKind_1.TokenKind.Plus:
1189
- case TokenKind_1.TokenKind.PlusEqual:
1190
- if (bothStrings) {
1191
- // "string" + "string" is the only binary expression allowed with strings
1192
- return StringType_1.StringType.instance;
1193
- }
1194
- // eslint-disable-next-line no-fallthrough
1195
- case TokenKind_1.TokenKind.Minus:
1196
- case TokenKind_1.TokenKind.MinusEqual:
1197
- case TokenKind_1.TokenKind.Star:
1198
- case TokenKind_1.TokenKind.StarEqual:
1199
- case TokenKind_1.TokenKind.Mod:
1200
- if (bothNumbers) {
1201
- if (hasDouble) {
1202
- return DoubleType_1.DoubleType.instance;
1203
- }
1204
- else if (hasFloat) {
1205
- return FloatType_1.FloatType.instance;
1206
- }
1207
- else if (hasLongInteger) {
1208
- return LongIntegerType_1.LongIntegerType.instance;
1209
- }
1210
- return IntegerType_1.IntegerType.instance;
1211
- }
1212
- break;
1213
- case TokenKind_1.TokenKind.Forwardslash:
1214
- case TokenKind_1.TokenKind.ForwardslashEqual:
1215
- if (bothNumbers) {
1216
- if (hasDouble) {
1217
- return DoubleType_1.DoubleType.instance;
1218
- }
1219
- else if (hasFloat) {
1220
- return FloatType_1.FloatType.instance;
1221
- }
1222
- else if (hasLongInteger) {
1223
- return LongIntegerType_1.LongIntegerType.instance;
1224
- }
1225
- return FloatType_1.FloatType.instance;
1226
- }
1227
- break;
1228
- case TokenKind_1.TokenKind.Backslash:
1229
- case TokenKind_1.TokenKind.BackslashEqual:
1230
- if (bothNumbers) {
1231
- if (hasLongInteger) {
1232
- return LongIntegerType_1.LongIntegerType.instance;
1233
- }
1234
- return IntegerType_1.IntegerType.instance;
1235
- }
1236
- break;
1237
- case TokenKind_1.TokenKind.Caret:
1238
- if (bothNumbers) {
1239
- if (hasDouble || hasLongInteger) {
1240
- return DoubleType_1.DoubleType.instance;
1241
- }
1242
- else if (hasFloat) {
1243
- return FloatType_1.FloatType.instance;
1244
- }
1245
- return IntegerType_1.IntegerType.instance;
1246
- }
1247
- break;
1248
- // Bitshift operators
1249
- case TokenKind_1.TokenKind.LeftShift:
1250
- case TokenKind_1.TokenKind.LeftShiftEqual:
1251
- case TokenKind_1.TokenKind.RightShift:
1252
- case TokenKind_1.TokenKind.RightShiftEqual:
1253
- if (bothNumbers) {
1254
- if (hasLongInteger) {
1255
- return LongIntegerType_1.LongIntegerType.instance;
1256
- }
1257
- // Bitshifts are allowed with non-integer numerics
1258
- // but will always truncate to ints
1259
- return IntegerType_1.IntegerType.instance;
1260
- }
1261
- break;
1262
- // Comparison operators
1263
- // All comparison operators result in boolean
1264
- case TokenKind_1.TokenKind.Equal:
1265
- case TokenKind_1.TokenKind.LessGreater:
1266
- // = and <> can accept invalid / dynamic
1267
- if (hasDynamic || hasInvalid || bothStrings || eitherBooleanOrNum) {
1268
- return BooleanType_1.BooleanType.instance;
1269
- }
1270
- break;
1271
- case TokenKind_1.TokenKind.Greater:
1272
- case TokenKind_1.TokenKind.Less:
1273
- case TokenKind_1.TokenKind.GreaterEqual:
1274
- case TokenKind_1.TokenKind.LessEqual:
1275
- if (bothStrings || bothNumbers) {
1276
- return BooleanType_1.BooleanType.instance;
1277
- }
1278
- break;
1279
- // Logical operators
1280
- case TokenKind_1.TokenKind.Or:
1281
- case TokenKind_1.TokenKind.And:
1282
- if (eitherBooleanOrNum) {
1283
- return BooleanType_1.BooleanType.instance;
1034
+ if (allowCustomType) {
1035
+ return new CustomType_1.CustomType(token.text);
1284
1036
  }
1285
- break;
1286
1037
  }
1287
- return DynamicType_1.DynamicType.instance;
1288
- }
1289
- /**
1290
- * Return the type of the result of a binary operator
1291
- */
1292
- unaryOperatorResultType(operator, exprType) {
1293
- // eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
1294
- switch (operator.kind) {
1295
- // Math operators
1296
- case TokenKind_1.TokenKind.Minus:
1297
- if ((0, reflection_1.isNumberType)(exprType)) {
1298
- // a negative number will be the same type, eg, double->double, int->int, etc.
1299
- return exprType;
1300
- }
1301
- break;
1302
- case TokenKind_1.TokenKind.Not:
1303
- if ((0, reflection_1.isBooleanType)(exprType)) {
1304
- return BooleanType_1.BooleanType.instance;
1305
- }
1306
- else if ((0, reflection_1.isNumberType)(exprType)) {
1307
- //numbers can be "notted"
1308
- // by default they go to ints, except longints, which stay that way
1309
- if ((0, reflection_1.isLongIntegerType)(exprType)) {
1310
- return LongIntegerType_1.LongIntegerType.instance;
1311
- }
1312
- return IntegerType_1.IntegerType.instance;
1313
- }
1314
- break;
1315
- }
1316
- return DynamicType_1.DynamicType.instance;
1317
1038
  }
1318
1039
  /**
1319
1040
  * Get the extension for the given file path. Basically the part after the final dot, except for
1320
1041
  * `d.bs` which is treated as single extension
1321
- * @returns the file extension (i.e. ".d.bs", ".bs", ".brs", ".xml", ".jpg", etc...)
1322
1042
  */
1323
1043
  getExtension(filePath) {
1324
1044
  filePath = filePath.toLowerCase();
@@ -1326,14 +1046,17 @@ class Util {
1326
1046
  return '.d.bs';
1327
1047
  }
1328
1048
  else {
1329
- return path.extname(filePath).toLowerCase();
1049
+ const idx = filePath.lastIndexOf('.');
1050
+ if (idx > -1) {
1051
+ return filePath.substring(idx);
1052
+ }
1330
1053
  }
1331
1054
  }
1332
1055
  /**
1333
1056
  * Load and return the list of plugins
1334
1057
  */
1335
1058
  loadPlugins(cwd, pathOrModules, onError) {
1336
- const logger = new Logger_1.Logger();
1059
+ const logger = (0, logging_1.createLogger)();
1337
1060
  return pathOrModules.reduce((acc, pathOrModule) => {
1338
1061
  if (typeof pathOrModule === 'string') {
1339
1062
  try {
@@ -1349,6 +1072,10 @@ class Util {
1349
1072
  else if (typeof theExport === 'function') {
1350
1073
  plugin = theExport();
1351
1074
  }
1075
+ else {
1076
+ //this should never happen; somehow an invalid plugin has made it into here
1077
+ throw new Error(`TILT: Encountered an invalid plugin: ${String(plugin)}`);
1078
+ }
1352
1079
  if (!plugin.name) {
1353
1080
  plugin.name = pathOrModule;
1354
1081
  }
@@ -1370,7 +1097,7 @@ class Util {
1370
1097
  * Gathers expressions, variables, and unique names from an expression.
1371
1098
  * This is mostly used for the ternary expression
1372
1099
  */
1373
- getExpressionInfo(expression) {
1100
+ getExpressionInfo(expression, file) {
1374
1101
  const expressions = [expression];
1375
1102
  const variableExpressions = [];
1376
1103
  const uniqueVarNames = new Set();
@@ -1390,11 +1117,14 @@ class Util {
1390
1117
  });
1391
1118
  //handle the expression itself (for situations when expression is a VariableExpression)
1392
1119
  expressionWalker(expression);
1393
- return { expressions: expressions, varExpressions: variableExpressions, uniqueVarNames: [...uniqueVarNames] };
1394
- }
1395
- concatAnnotationLeadingTrivia(stmt, otherTrivia) {
1396
- var _a, _b;
1397
- return [...((_b = (_a = stmt.annotations) === null || _a === void 0 ? void 0 : _a.map(anno => anno.getLeadingTrivia()).flat()) !== null && _b !== void 0 ? _b : []), ...otherTrivia];
1120
+ const scope = file.program.getFirstScopeForFile(file);
1121
+ const filteredVarNames = [...uniqueVarNames].filter((varName) => {
1122
+ const varNameLower = varName.toLowerCase();
1123
+ // TODO: include namespaces in this filter
1124
+ return !scope.getEnumMap().has(varNameLower) &&
1125
+ !scope.getConstMap().has(varNameLower);
1126
+ });
1127
+ return { expressions: expressions, varExpressions: variableExpressions, uniqueVarNames: filteredVarNames };
1398
1128
  }
1399
1129
  /**
1400
1130
  * Create a SourceNode that maps every line to itself. Useful for creating maps for files
@@ -1410,12 +1140,51 @@ class Util {
1410
1140
  }
1411
1141
  return new source_map_1.SourceNode(null, null, source, chunks);
1412
1142
  }
1143
+ /**
1144
+ * Creates a new SGAttribute object, but keeps the existing Range references (since those shouldn't ever get changed directly)
1145
+ */
1146
+ cloneSGAttribute(attr, value) {
1147
+ return {
1148
+ key: {
1149
+ text: attr.key.text,
1150
+ range: attr.range
1151
+ },
1152
+ value: {
1153
+ text: value,
1154
+ range: attr.value.range
1155
+ },
1156
+ range: attr.range
1157
+ };
1158
+ }
1413
1159
  /**
1414
1160
  * Converts a path into a standardized format (drive letter to lower, remove extra slashes, use single slash type, resolve relative parts, etc...)
1415
1161
  */
1416
1162
  standardizePath(thePath) {
1417
1163
  return exports.util.driveLetterToLower((0, roku_deploy_1.standardizePath)(thePath));
1418
1164
  }
1165
+ /**
1166
+ * Copy the version of bslib from local node_modules to the staging folder
1167
+ */
1168
+ async copyBslibToStaging(stagingDir, bslibDestinationDir = 'source') {
1169
+ //copy bslib to the output directory
1170
+ await fsExtra.ensureDir(standardizePath(`${stagingDir}/${bslibDestinationDir}`));
1171
+ // eslint-disable-next-line
1172
+ const bslib = require('@rokucommunity/bslib');
1173
+ let source = bslib.source;
1174
+ //apply the `bslib_` prefix to the functions
1175
+ let match;
1176
+ const positions = [];
1177
+ const regexp = /^(\s*(?:function|sub)\s+)([a-z0-9_]+)/mg;
1178
+ // eslint-disable-next-line no-cond-assign
1179
+ while (match = regexp.exec(source)) {
1180
+ positions.push(match.index + match[1].length);
1181
+ }
1182
+ for (let i = positions.length - 1; i >= 0; i--) {
1183
+ const position = positions[i];
1184
+ source = source.slice(0, position) + 'bslib_' + source.slice(position);
1185
+ }
1186
+ await fsExtra.writeFile(`${stagingDir}/${bslibDestinationDir}/bslib.brs`, source);
1187
+ }
1419
1188
  /**
1420
1189
  * Given a Diagnostic or BsDiagnostic, return a deep clone of the diagnostic.
1421
1190
  * @param diagnostic the diagnostic to clone
@@ -1423,20 +1192,11 @@ class Util {
1423
1192
  */
1424
1193
  toDiagnostic(diagnostic, relatedInformationFallbackLocation) {
1425
1194
  var _a;
1426
- let relatedInformation = (_a = diagnostic.relatedInformation) !== null && _a !== void 0 ? _a : [];
1427
- if (relatedInformation.length > diagnosticUtils_1.MAX_RELATED_INFOS_COUNT) {
1428
- const relatedInfoLength = relatedInformation.length;
1429
- relatedInformation = relatedInformation.slice(0, diagnosticUtils_1.MAX_RELATED_INFOS_COUNT);
1430
- relatedInformation.push({
1431
- message: `...and ${relatedInfoLength - diagnosticUtils_1.MAX_RELATED_INFOS_COUNT} more`,
1432
- location: exports.util.createLocation(' ', exports.util.createRange(0, 0, 0, 0))
1433
- });
1434
- }
1435
1195
  return {
1436
1196
  severity: diagnostic.severity,
1437
1197
  range: diagnostic.range,
1438
1198
  message: diagnostic.message,
1439
- relatedInformation: relatedInformation.map(x => {
1199
+ relatedInformation: (_a = diagnostic.relatedInformation) === null || _a === void 0 ? void 0 : _a.map(x => {
1440
1200
  //clone related information just in case a plugin added circular ref info here
1441
1201
  const clone = Object.assign({}, x);
1442
1202
  if (!clone.location) {
@@ -1451,7 +1211,7 @@ class Util {
1451
1211
  }
1452
1212
  return clone;
1453
1213
  //filter out null relatedInformation items
1454
- }).filter(x => x),
1214
+ }).filter((x) => Boolean(x)),
1455
1215
  code: diagnostic.code,
1456
1216
  source: 'brs'
1457
1217
  };
@@ -1537,71 +1297,33 @@ class Util {
1537
1297
  * @returns an array of the parts of the dotted get. If not fully a dotted get, then returns undefined
1538
1298
  */
1539
1299
  getAllDottedGetParts(node) {
1540
- //this is a hot function and has been optimized. Don't rewrite unless necessary
1541
1300
  const parts = [];
1542
1301
  let nextPart = node;
1543
- loop: while (nextPart) {
1544
- switch (nextPart === null || nextPart === void 0 ? void 0 : nextPart.kind) {
1545
- case AstNode_1.AstNodeKind.AssignmentStatement:
1546
- return [node.name];
1547
- case AstNode_1.AstNodeKind.DottedGetExpression:
1548
- parts.push(nextPart === null || nextPart === void 0 ? void 0 : nextPart.name);
1549
- nextPart = nextPart.obj;
1550
- continue;
1551
- case AstNode_1.AstNodeKind.CallExpression:
1552
- nextPart = nextPart.callee;
1553
- continue;
1554
- case AstNode_1.AstNodeKind.TypeExpression:
1555
- nextPart = nextPart.expression;
1556
- continue;
1557
- case AstNode_1.AstNodeKind.VariableExpression:
1558
- parts.push(nextPart === null || nextPart === void 0 ? void 0 : nextPart.name);
1559
- break loop;
1560
- case AstNode_1.AstNodeKind.LiteralExpression:
1561
- parts.push(nextPart === null || nextPart === void 0 ? void 0 : nextPart.token);
1562
- break loop;
1563
- case AstNode_1.AstNodeKind.IndexedGetExpression:
1564
- nextPart = nextPart.obj;
1565
- continue;
1566
- case AstNode_1.AstNodeKind.FunctionParameterExpression:
1567
- return [nextPart.name];
1568
- case AstNode_1.AstNodeKind.GroupingExpression:
1569
- parts.push((0, creators_1.createIdentifier)('()', nextPart.range));
1570
- break loop;
1571
- default:
1572
- //we found a non-DottedGet expression, so return because this whole operation is invalid.
1573
- return undefined;
1302
+ while (nextPart) {
1303
+ if ((0, reflection_1.isAssignmentStatement)(node)) {
1304
+ return [node.name];
1305
+ }
1306
+ else if ((0, reflection_1.isDottedGetExpression)(nextPart)) {
1307
+ parts.push(nextPart === null || nextPart === void 0 ? void 0 : nextPart.name);
1308
+ nextPart = nextPart.obj;
1309
+ }
1310
+ else if ((0, reflection_1.isNamespacedVariableNameExpression)(nextPart)) {
1311
+ nextPart = nextPart.expression;
1312
+ }
1313
+ else if ((0, reflection_1.isVariableExpression)(nextPart)) {
1314
+ parts.push(nextPart === null || nextPart === void 0 ? void 0 : nextPart.name);
1315
+ break;
1316
+ }
1317
+ else if ((0, reflection_1.isFunctionParameterExpression)(nextPart)) {
1318
+ return [nextPart.name];
1319
+ }
1320
+ else {
1321
+ //we found a non-DottedGet expression, so return because this whole operation is invalid.
1322
+ return undefined;
1574
1323
  }
1575
1324
  }
1576
1325
  return parts.reverse();
1577
1326
  }
1578
- /**
1579
- * Given an expression, return all the DottedGet name parts as a string.
1580
- * Mostly used to convert namespaced item full names to a strings
1581
- */
1582
- getAllDottedGetPartsAsString(node, parseMode = Parser_1.ParseMode.BrighterScript) {
1583
- var _a, _b;
1584
- //this is a hot function and has been optimized. Don't rewrite unless necessary
1585
- /* eslint-disable no-var */
1586
- var sep = parseMode === Parser_1.ParseMode.BrighterScript ? '.' : '_';
1587
- const parts = (_a = this.getAllDottedGetParts(node)) !== null && _a !== void 0 ? _a : [];
1588
- var result = (_b = parts[0]) === null || _b === void 0 ? void 0 : _b.text;
1589
- for (var i = 1; i < parts.length; i++) {
1590
- result += sep + parts[i].text;
1591
- }
1592
- return result;
1593
- /* eslint-enable no-var */
1594
- }
1595
- stringJoin(strings, separator) {
1596
- var _a;
1597
- // eslint-disable-next-line no-var
1598
- var result = (_a = strings[0]) !== null && _a !== void 0 ? _a : '';
1599
- // eslint-disable-next-line no-var
1600
- for (var i = 1; i < strings.length; i++) {
1601
- result += separator + strings[i];
1602
- }
1603
- return result;
1604
- }
1605
1327
  /**
1606
1328
  * Break an expression into each part.
1607
1329
  */
@@ -1615,7 +1337,7 @@ class Util {
1615
1337
  else if ((0, reflection_1.isCallExpression)(nextPart) || (0, reflection_1.isCallfuncExpression)(nextPart)) {
1616
1338
  nextPart = nextPart.callee;
1617
1339
  }
1618
- else if ((0, reflection_1.isTypeExpression)(nextPart)) {
1340
+ else if ((0, reflection_1.isNamespacedVariableNameExpression)(nextPart)) {
1619
1341
  nextPart = nextPart.expression;
1620
1342
  }
1621
1343
  else {
@@ -1631,37 +1353,36 @@ class Util {
1631
1353
  getDottedGetPath(expression) {
1632
1354
  let parts = [];
1633
1355
  let nextPart = expression;
1634
- loop: while (nextPart) {
1635
- switch (nextPart === null || nextPart === void 0 ? void 0 : nextPart.kind) {
1636
- case AstNode_1.AstNodeKind.DottedGetExpression:
1637
- parts.push(nextPart);
1638
- nextPart = nextPart.obj;
1639
- continue;
1640
- case AstNode_1.AstNodeKind.IndexedGetExpression:
1641
- case AstNode_1.AstNodeKind.XmlAttributeGetExpression:
1642
- nextPart = nextPart.obj;
1643
- parts = [];
1644
- continue;
1645
- case AstNode_1.AstNodeKind.CallExpression:
1646
- case AstNode_1.AstNodeKind.CallfuncExpression:
1647
- nextPart = nextPart.callee;
1648
- parts = [];
1649
- continue;
1650
- case AstNode_1.AstNodeKind.NewExpression:
1651
- nextPart = nextPart.call.callee;
1652
- parts = [];
1653
- continue;
1654
- case AstNode_1.AstNodeKind.TypeExpression:
1655
- nextPart = nextPart.expression;
1656
- continue;
1657
- case AstNode_1.AstNodeKind.VariableExpression:
1658
- parts.push(nextPart);
1659
- break loop;
1660
- default:
1661
- return [];
1356
+ while (nextPart) {
1357
+ if ((0, reflection_1.isDottedGetExpression)(nextPart)) {
1358
+ parts.unshift(nextPart);
1359
+ nextPart = nextPart.obj;
1360
+ }
1361
+ else if ((0, reflection_1.isIndexedGetExpression)(nextPart) || (0, reflection_1.isXmlAttributeGetExpression)(nextPart)) {
1362
+ nextPart = nextPart.obj;
1363
+ parts = [];
1364
+ }
1365
+ else if ((0, reflection_1.isCallExpression)(nextPart) || (0, reflection_1.isCallfuncExpression)(nextPart)) {
1366
+ nextPart = nextPart.callee;
1367
+ parts = [];
1368
+ }
1369
+ else if ((0, reflection_1.isNewExpression)(nextPart)) {
1370
+ nextPart = nextPart.call.callee;
1371
+ parts = [];
1372
+ }
1373
+ else if ((0, reflection_1.isNamespacedVariableNameExpression)(nextPart)) {
1374
+ nextPart = nextPart.expression;
1375
+ }
1376
+ else if ((0, reflection_1.isVariableExpression)(nextPart)) {
1377
+ parts.unshift(nextPart);
1378
+ break;
1379
+ }
1380
+ else {
1381
+ parts = [];
1382
+ break;
1662
1383
  }
1663
1384
  }
1664
- return parts.reverse();
1385
+ return parts;
1665
1386
  }
1666
1387
  /**
1667
1388
  * Returns an integer if valid, or undefined. Eliminates checking for NaN
@@ -1685,152 +1406,34 @@ class Util {
1685
1406
  validateTooDeepFile(file) {
1686
1407
  var _a;
1687
1408
  //find any files nested too deep
1688
- let destPath = (_a = file === null || file === void 0 ? void 0 : file.destPath) === null || _a === void 0 ? void 0 : _a.toString();
1689
- let rootFolder = destPath === null || destPath === void 0 ? void 0 : destPath.replace(/^pkg:/, '').split(/[\\\/]/)[0].toLowerCase();
1409
+ let pkgPath = (_a = file.pkgPath) !== null && _a !== void 0 ? _a : file.pkgPath.toString();
1410
+ let rootFolder = pkgPath.replace(/^pkg:/, '').split(/[\\\/]/)[0].toLowerCase();
1690
1411
  if ((0, reflection_1.isBrsFile)(file) && rootFolder !== 'source') {
1691
1412
  return;
1692
1413
  }
1693
1414
  if ((0, reflection_1.isXmlFile)(file) && rootFolder !== 'components') {
1694
1415
  return;
1695
1416
  }
1696
- let fileDepth = this.getParentDirectoryCount(destPath);
1417
+ let fileDepth = this.getParentDirectoryCount(pkgPath);
1697
1418
  if (fileDepth >= 8) {
1698
1419
  file.addDiagnostics([Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.detectedTooDeepFileSource(fileDepth)), { file: file, range: this.createRange(0, 0, 0, Number.MAX_VALUE) })]);
1699
1420
  }
1700
1421
  }
1701
1422
  /**
1702
- * Find the index of the last item in the array that matches.
1423
+ * Wraps SourceNode's constructor to be compatible with the TranspileResult type
1703
1424
  */
1704
- findLastIndex(array, matcher) {
1705
- for (let i = array.length - 1; i >= 0; i--) {
1706
- if (matcher(array[i])) {
1707
- return i;
1708
- }
1709
- }
1425
+ sourceNodeFromTranspileResult(line, column, source, chunks, name) {
1426
+ // we can use a typecast rather than actually transforming the data because SourceNode
1427
+ // accepts a more permissive type than its typedef states
1428
+ return new source_map_1.SourceNode(line, column, source, chunks, name);
1710
1429
  }
1711
- processTypeChain(typeChain) {
1712
- var _a, _b, _c, _d;
1713
- let fullChainName = '';
1714
- let fullErrorName = '';
1715
- let itemName = '';
1716
- let previousTypeName = '';
1717
- let parentTypeName = '';
1718
- let errorRange;
1719
- let containsDynamic = false;
1720
- for (let i = 0; i < typeChain.length; i++) {
1721
- const chainItem = typeChain[i];
1722
- const dotSep = (_b = (_a = chainItem.separatorToken) === null || _a === void 0 ? void 0 : _a.text) !== null && _b !== void 0 ? _b : '.';
1723
- if (i > 0) {
1724
- fullChainName += dotSep;
1725
- }
1726
- fullChainName += chainItem.name;
1727
- parentTypeName = previousTypeName;
1728
- fullErrorName = previousTypeName ? `${previousTypeName}${dotSep}${chainItem.name}` : chainItem.name;
1729
- previousTypeName = (_d = (_c = chainItem.type) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : '';
1730
- itemName = chainItem.name;
1731
- containsDynamic = containsDynamic || ((0, reflection_1.isDynamicType)(chainItem.type) && !(0, reflection_1.isAnyReferenceType)(chainItem.type));
1732
- if (!chainItem.isResolved) {
1733
- errorRange = chainItem.range;
1734
- break;
1735
- }
1736
- }
1737
- return {
1738
- itemName: itemName,
1739
- itemParentTypeName: parentTypeName,
1740
- fullNameOfItem: fullErrorName,
1741
- fullChainName: fullChainName,
1742
- range: errorRange,
1743
- containsDynamic: containsDynamic
1744
- };
1745
- }
1746
- isInTypeExpression(expression) {
1747
- //TODO: this is much faster than node.findAncestor(), but may need to be updated for "complicated" type expressions
1748
- if ((0, reflection_1.isTypeExpression)(expression) ||
1749
- (0, reflection_1.isTypeExpression)(expression.parent) ||
1750
- (0, reflection_1.isTypedArrayExpression)(expression) ||
1751
- (0, reflection_1.isTypedArrayExpression)(expression.parent)) {
1430
+ isBuiltInType(typeName) {
1431
+ const typeNameLower = typeName.toLowerCase();
1432
+ if (typeNameLower.startsWith('rosgnode')) {
1433
+ // NOTE: this is unsafe and only used to avoid validation errors in backported v1 type syntax
1752
1434
  return true;
1753
1435
  }
1754
- if ((0, reflection_1.isBinaryExpression)(expression.parent)) {
1755
- let currentExpr = expression.parent;
1756
- while ((0, reflection_1.isBinaryExpression)(currentExpr) && currentExpr.operator.kind === TokenKind_1.TokenKind.Or) {
1757
- currentExpr = currentExpr.parent;
1758
- }
1759
- return (0, reflection_1.isTypeExpression)(currentExpr) || (0, reflection_1.isTypedArrayExpression)(currentExpr);
1760
- }
1761
- return false;
1762
- }
1763
- setContainsUnresolvedSymbol(symbolLowerNameSet, symbol) {
1764
- var _a, _b;
1765
- const possibleOriginalSymbolNamesLower = [];
1766
- let nameSoFar = '';
1767
- for (const tce of symbol.typeChain) {
1768
- if (nameSoFar.length > 0) {
1769
- nameSoFar += '.';
1770
- }
1771
- nameSoFar += tce.name.toLowerCase();
1772
- possibleOriginalSymbolNamesLower.push(nameSoFar);
1773
- }
1774
- const possibleNamespace = (_b = (_a = symbol.containingNamespaces) === null || _a === void 0 ? void 0 : _a.join('.')) !== null && _b !== void 0 ? _b : '';
1775
- for (const possibleNameLower of possibleOriginalSymbolNamesLower) {
1776
- if (symbolLowerNameSet.has(possibleNameLower)) {
1777
- return true;
1778
- }
1779
- if (possibleNamespace) {
1780
- const fullName = possibleNamespace + '.' + possibleNameLower;
1781
- if (symbolLowerNameSet.has(fullName.toLowerCase())) {
1782
- return true;
1783
- }
1784
- }
1785
- }
1786
- return false;
1787
- }
1788
- truncate(options) {
1789
- var _a, _b, _c, _d, _e, _f, _g;
1790
- let leadingText = options.leadingText;
1791
- let items = (_a = options === null || options === void 0 ? void 0 : options.items) !== null && _a !== void 0 ? _a : [];
1792
- let trailingText = (_b = options === null || options === void 0 ? void 0 : options.trailingText) !== null && _b !== void 0 ? _b : '';
1793
- let maxLength = (_c = options === null || options === void 0 ? void 0 : options.maxLength) !== null && _c !== void 0 ? _c : 160;
1794
- let itemSeparator = (_d = options === null || options === void 0 ? void 0 : options.itemSeparator) !== null && _d !== void 0 ? _d : ', ';
1795
- let partBuilder = (_e = options === null || options === void 0 ? void 0 : options.partBuilder) !== null && _e !== void 0 ? _e : ((x) => x.toString());
1796
- let parts = [];
1797
- let length = leadingText.length + ((_f = trailingText === null || trailingText === void 0 ? void 0 : trailingText.length) !== null && _f !== void 0 ? _f : 0);
1798
- //calculate the max number of items we could fit in the given space
1799
- for (let i = 0; i < items.length; i++) {
1800
- let part = partBuilder(items[i]);
1801
- if (i > 0) {
1802
- part = itemSeparator + part;
1803
- }
1804
- parts.push(part);
1805
- length += part.length;
1806
- //exit the loop if we've maxed out our length
1807
- if (length >= maxLength) {
1808
- break;
1809
- }
1810
- }
1811
- let message;
1812
- //we have enough space to include all the parts
1813
- if (parts.length >= items.length) {
1814
- message = leadingText + parts.join('') + trailingText;
1815
- //we require truncation
1816
- }
1817
- else {
1818
- //account for truncation message length including max possible "more" items digits, trailing text length, and the separator between last item and trailing text
1819
- length = leadingText.length + `...and ${items.length} more`.length + itemSeparator.length + ((_g = trailingText === null || trailingText === void 0 ? void 0 : trailingText.length) !== null && _g !== void 0 ? _g : 0);
1820
- message = leadingText;
1821
- for (let i = 0; i < parts.length; i++) {
1822
- //always include at least 2 items. if this part would overflow the max, then skip it and finalize the message
1823
- if (i > 1 && length + parts[i].length > maxLength) {
1824
- message += itemSeparator + `...and ${items.length - i} more` + trailingText;
1825
- return message;
1826
- }
1827
- else {
1828
- message += parts[i];
1829
- length += parts[i].length;
1830
- }
1831
- }
1832
- }
1833
- return message;
1436
+ return roku_types_1.components[typeNameLower] || roku_types_1.interfaces[typeNameLower] || roku_types_1.events[typeNameLower];
1834
1437
  }
1835
1438
  }
1836
1439
  exports.Util = Util;