brighterscript 1.0.0-alpha.1 → 1.0.0-alpha.13

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 (316) hide show
  1. package/CHANGELOG.md +362 -248
  2. package/README.md +2 -2
  3. package/bsconfig.schema.json +1 -1
  4. package/dist/CodeActionUtil.d.ts +11 -2
  5. package/dist/CodeActionUtil.js +17 -3
  6. package/dist/CodeActionUtil.js.map +1 -1
  7. package/dist/CommentFlagProcessor.d.ts +4 -4
  8. package/dist/CommentFlagProcessor.js +5 -3
  9. package/dist/CommentFlagProcessor.js.map +1 -1
  10. package/dist/DependencyGraph.js.map +1 -1
  11. package/dist/DiagnosticCollection.js +2 -2
  12. package/dist/DiagnosticCollection.js.map +1 -1
  13. package/dist/DiagnosticFilterer.js +3 -3
  14. package/dist/DiagnosticFilterer.js.map +1 -1
  15. package/dist/DiagnosticMessages.d.ts +15 -5
  16. package/dist/DiagnosticMessages.js +19 -9
  17. package/dist/DiagnosticMessages.js.map +1 -1
  18. package/dist/LanguageServer.d.ts +11 -10
  19. package/dist/LanguageServer.js +87 -58
  20. package/dist/LanguageServer.js.map +1 -1
  21. package/dist/Logger.d.ts +2 -0
  22. package/dist/Logger.js +5 -3
  23. package/dist/Logger.js.map +1 -1
  24. package/dist/Program.d.ts +76 -46
  25. package/dist/Program.js +254 -180
  26. package/dist/Program.js.map +1 -1
  27. package/dist/ProgramBuilder.d.ts +7 -7
  28. package/dist/ProgramBuilder.js +37 -43
  29. package/dist/ProgramBuilder.js.map +1 -1
  30. package/dist/Scope.d.ts +33 -23
  31. package/dist/Scope.js +222 -147
  32. package/dist/Scope.js.map +1 -1
  33. package/dist/SemanticTokenUtils.d.ts +14 -0
  34. package/dist/SemanticTokenUtils.js +81 -0
  35. package/dist/SemanticTokenUtils.js.map +1 -0
  36. package/dist/SymbolTable.d.ts +9 -3
  37. package/dist/SymbolTable.js +40 -13
  38. package/dist/SymbolTable.js.map +1 -1
  39. package/dist/XmlScope.d.ts +7 -2
  40. package/dist/XmlScope.js +67 -29
  41. package/dist/XmlScope.js.map +1 -1
  42. package/dist/astUtils/AstEditor.d.ts +27 -0
  43. package/dist/astUtils/AstEditor.js +97 -0
  44. package/dist/astUtils/AstEditor.js.map +1 -0
  45. package/dist/astUtils/AstEditor.spec.d.ts +1 -0
  46. package/dist/astUtils/AstEditor.spec.js +133 -0
  47. package/dist/astUtils/AstEditor.spec.js.map +1 -0
  48. package/dist/astUtils/creators.d.ts +15 -1
  49. package/dist/astUtils/creators.js +39 -9
  50. package/dist/astUtils/creators.js.map +1 -1
  51. package/dist/astUtils/creators.spec.js +4 -4
  52. package/dist/astUtils/creators.spec.js.map +1 -1
  53. package/dist/astUtils/index.js +1 -1
  54. package/dist/astUtils/reflection.d.ts +20 -8
  55. package/dist/astUtils/reflection.js +42 -1
  56. package/dist/astUtils/reflection.js.map +1 -1
  57. package/dist/astUtils/reflection.spec.js +115 -115
  58. package/dist/astUtils/reflection.spec.js.map +1 -1
  59. package/dist/astUtils/stackedVisitor.js.map +1 -1
  60. package/dist/astUtils/stackedVisitor.spec.js +13 -13
  61. package/dist/astUtils/stackedVisitor.spec.js.map +1 -1
  62. package/dist/astUtils/visitors.js +1 -1
  63. package/dist/astUtils/visitors.js.map +1 -1
  64. package/dist/astUtils/visitors.spec.js +28 -28
  65. package/dist/astUtils/visitors.spec.js.map +1 -1
  66. package/dist/astUtils/xml.d.ts +4 -3
  67. package/dist/astUtils/xml.js +8 -3
  68. package/dist/astUtils/xml.js.map +1 -1
  69. package/dist/bscPlugin/BscPlugin.d.ts +2 -1
  70. package/dist/bscPlugin/BscPlugin.js +4 -0
  71. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  72. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js +5 -6
  73. package/dist/bscPlugin/codeActions/CodeActionsProcessor.js.map +1 -1
  74. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +30 -30
  75. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +1 -1
  76. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.d.ts +7 -0
  77. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js +63 -0
  78. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.js.map +1 -0
  79. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.d.ts +1 -0
  80. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js +45 -0
  81. package/dist/bscPlugin/semanticTokens/SemanticTokensProcessor.spec.js.map +1 -0
  82. package/dist/diagnosticUtils.d.ts +1 -0
  83. package/dist/diagnosticUtils.js +14 -7
  84. package/dist/diagnosticUtils.js.map +1 -1
  85. package/dist/examples/plugins/removePrint.js +2 -2
  86. package/dist/examples/plugins/removePrint.js.map +1 -1
  87. package/dist/files/BrsFile.Class.spec.js +486 -71
  88. package/dist/files/BrsFile.Class.spec.js.map +1 -1
  89. package/dist/files/BrsFile.d.ts +48 -23
  90. package/dist/files/BrsFile.js +403 -233
  91. package/dist/files/BrsFile.js.map +1 -1
  92. package/dist/files/BrsFile.spec.js +367 -316
  93. package/dist/files/BrsFile.spec.js.map +1 -1
  94. package/dist/files/XmlFile.d.ts +13 -6
  95. package/dist/files/XmlFile.js +27 -21
  96. package/dist/files/XmlFile.js.map +1 -1
  97. package/dist/files/XmlFile.spec.js +274 -228
  98. package/dist/files/XmlFile.spec.js.map +1 -1
  99. package/dist/files/tests/imports.spec.js +49 -49
  100. package/dist/files/tests/imports.spec.js.map +1 -1
  101. package/dist/globalCallables.d.ts +3 -1
  102. package/dist/globalCallables.js +359 -87
  103. package/dist/globalCallables.js.map +1 -1
  104. package/dist/index.js +2 -1
  105. package/dist/index.js.map +1 -1
  106. package/dist/interfaces.d.ts +51 -14
  107. package/dist/lexer/Lexer.d.ts +14 -1
  108. package/dist/lexer/Lexer.js +91 -21
  109. package/dist/lexer/Lexer.js.map +1 -1
  110. package/dist/lexer/Lexer.spec.js +187 -132
  111. package/dist/lexer/Lexer.spec.js.map +1 -1
  112. package/dist/lexer/Token.d.ts +2 -2
  113. package/dist/lexer/TokenKind.d.ts +7 -1
  114. package/dist/lexer/TokenKind.js +51 -3
  115. package/dist/lexer/TokenKind.js.map +1 -1
  116. package/dist/lexer/index.js +2 -1
  117. package/dist/lexer/index.js.map +1 -1
  118. package/dist/parser/BrsTranspileState.d.ts +7 -0
  119. package/dist/parser/BrsTranspileState.js +10 -1
  120. package/dist/parser/BrsTranspileState.js.map +1 -1
  121. package/dist/parser/Expression.d.ts +23 -5
  122. package/dist/parser/Expression.js +124 -75
  123. package/dist/parser/Expression.js.map +1 -1
  124. package/dist/parser/Parser.Class.spec.js +159 -60
  125. package/dist/parser/Parser.Class.spec.js.map +1 -1
  126. package/dist/parser/Parser.d.ts +114 -26
  127. package/dist/parser/Parser.js +471 -126
  128. package/dist/parser/Parser.js.map +1 -1
  129. package/dist/parser/Parser.spec.js +396 -235
  130. package/dist/parser/Parser.spec.js.map +1 -1
  131. package/dist/parser/SGParser.d.ts +41 -4
  132. package/dist/parser/SGParser.js +186 -175
  133. package/dist/parser/SGParser.js.map +1 -1
  134. package/dist/parser/SGParser.spec.js +35 -22
  135. package/dist/parser/SGParser.spec.js.map +1 -1
  136. package/dist/parser/SGTypes.d.ts +206 -38
  137. package/dist/parser/SGTypes.js +470 -161
  138. package/dist/parser/SGTypes.js.map +1 -1
  139. package/dist/parser/SGTypes.spec.d.ts +1 -0
  140. package/dist/parser/SGTypes.spec.js +351 -0
  141. package/dist/parser/SGTypes.spec.js.map +1 -0
  142. package/dist/parser/Statement.d.ts +92 -18
  143. package/dist/parser/Statement.js +287 -58
  144. package/dist/parser/Statement.js.map +1 -1
  145. package/dist/parser/Statement.spec.js +11 -11
  146. package/dist/parser/Statement.spec.js.map +1 -1
  147. package/dist/parser/TranspileState.d.ts +1 -1
  148. package/dist/parser/TranspileState.js +15 -7
  149. package/dist/parser/TranspileState.js.map +1 -1
  150. package/dist/parser/index.js +1 -1
  151. package/dist/parser/tests/Parser.spec.d.ts +8 -7
  152. package/dist/parser/tests/Parser.spec.js +12 -8
  153. package/dist/parser/tests/Parser.spec.js.map +1 -1
  154. package/dist/parser/tests/controlFlow/For.spec.js +50 -50
  155. package/dist/parser/tests/controlFlow/For.spec.js.map +1 -1
  156. package/dist/parser/tests/controlFlow/ForEach.spec.js +31 -31
  157. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +1 -1
  158. package/dist/parser/tests/controlFlow/If.spec.js +174 -156
  159. package/dist/parser/tests/controlFlow/If.spec.js.map +1 -1
  160. package/dist/parser/tests/controlFlow/While.spec.js +32 -32
  161. package/dist/parser/tests/controlFlow/While.spec.js.map +1 -1
  162. package/dist/parser/tests/expression/Additive.spec.js +21 -21
  163. package/dist/parser/tests/expression/Additive.spec.js.map +1 -1
  164. package/dist/parser/tests/expression/ArrayLiterals.spec.js +105 -105
  165. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +1 -1
  166. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +148 -124
  167. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +1 -1
  168. package/dist/parser/tests/expression/Boolean.spec.js +17 -17
  169. package/dist/parser/tests/expression/Boolean.spec.js.map +1 -1
  170. package/dist/parser/tests/expression/Call.spec.js +30 -30
  171. package/dist/parser/tests/expression/Call.spec.js.map +1 -1
  172. package/dist/parser/tests/expression/Exponential.spec.js +16 -16
  173. package/dist/parser/tests/expression/Exponential.spec.js.map +1 -1
  174. package/dist/parser/tests/expression/Function.spec.js +247 -247
  175. package/dist/parser/tests/expression/Function.spec.js.map +1 -1
  176. package/dist/parser/tests/expression/Indexing.spec.js +73 -73
  177. package/dist/parser/tests/expression/Indexing.spec.js.map +1 -1
  178. package/dist/parser/tests/expression/Multiplicative.spec.js +36 -36
  179. package/dist/parser/tests/expression/Multiplicative.spec.js.map +1 -1
  180. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +59 -47
  181. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +1 -1
  182. package/dist/parser/tests/expression/PrefixUnary.spec.js +35 -35
  183. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +1 -1
  184. package/dist/parser/tests/expression/Primary.spec.js +26 -26
  185. package/dist/parser/tests/expression/Primary.spec.js.map +1 -1
  186. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +1 -0
  187. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +170 -0
  188. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +1 -0
  189. package/dist/parser/tests/expression/Relational.spec.js +42 -42
  190. package/dist/parser/tests/expression/Relational.spec.js.map +1 -1
  191. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +8 -8
  192. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +1 -1
  193. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +12 -12
  194. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +1 -1
  195. package/dist/parser/tests/expression/TernaryExpression.spec.js +100 -100
  196. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +1 -1
  197. package/dist/parser/tests/statement/AssignmentOperators.spec.js +35 -35
  198. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +1 -1
  199. package/dist/parser/tests/statement/Declaration.spec.js +39 -39
  200. package/dist/parser/tests/statement/Declaration.spec.js.map +1 -1
  201. package/dist/parser/tests/statement/Dim.spec.js +21 -21
  202. package/dist/parser/tests/statement/Dim.spec.js.map +1 -1
  203. package/dist/parser/tests/statement/Function.spec.js +192 -192
  204. package/dist/parser/tests/statement/Function.spec.js.map +1 -1
  205. package/dist/parser/tests/statement/Goto.spec.js +11 -11
  206. package/dist/parser/tests/statement/Goto.spec.js.map +1 -1
  207. package/dist/parser/tests/statement/Increment.spec.js +46 -46
  208. package/dist/parser/tests/statement/Increment.spec.js.map +1 -1
  209. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +1 -0
  210. package/dist/parser/tests/statement/InterfaceStatement.spec.js +61 -0
  211. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +1 -0
  212. package/dist/parser/tests/statement/LibraryStatement.spec.js +10 -10
  213. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +1 -1
  214. package/dist/parser/tests/statement/Misc.spec.js +37 -36
  215. package/dist/parser/tests/statement/Misc.spec.js.map +1 -1
  216. package/dist/parser/tests/statement/PrintStatement.spec.js +30 -30
  217. package/dist/parser/tests/statement/PrintStatement.spec.js.map +1 -1
  218. package/dist/parser/tests/statement/ReturnStatement.spec.js +43 -43
  219. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +1 -1
  220. package/dist/parser/tests/statement/Set.spec.js +69 -69
  221. package/dist/parser/tests/statement/Set.spec.js.map +1 -1
  222. package/dist/parser/tests/statement/Stop.spec.js +9 -9
  223. package/dist/parser/tests/statement/Stop.spec.js.map +1 -1
  224. package/dist/parser/tests/statement/Throw.spec.js +5 -5
  225. package/dist/parser/tests/statement/Throw.spec.js.map +1 -1
  226. package/dist/parser/tests/statement/TryCatch.spec.js +13 -13
  227. package/dist/parser/tests/statement/TryCatch.spec.js.map +1 -1
  228. package/dist/preprocessor/Chunk.js.map +1 -1
  229. package/dist/preprocessor/Manifest.d.ts +1 -1
  230. package/dist/preprocessor/Preprocessor.js +1 -1
  231. package/dist/preprocessor/Preprocessor.js.map +1 -1
  232. package/dist/preprocessor/Preprocessor.spec.js +49 -49
  233. package/dist/preprocessor/Preprocessor.spec.js.map +1 -1
  234. package/dist/preprocessor/PreprocessorParser.spec.js +72 -72
  235. package/dist/preprocessor/PreprocessorParser.spec.js.map +1 -1
  236. package/dist/preprocessor/index.js +1 -1
  237. package/dist/types/ArrayType.js +5 -4
  238. package/dist/types/ArrayType.js.map +1 -1
  239. package/dist/types/ArrayType.spec.js +8 -8
  240. package/dist/types/ArrayType.spec.js.map +1 -1
  241. package/dist/types/BooleanType.js +3 -3
  242. package/dist/types/BooleanType.js.map +1 -1
  243. package/dist/types/BooleanType.spec.js +2 -2
  244. package/dist/types/BooleanType.spec.js.map +1 -1
  245. package/dist/types/BscType.d.ts +19 -5
  246. package/dist/types/BscType.js +9 -0
  247. package/dist/types/BscType.js.map +1 -1
  248. package/dist/types/CustomType.d.ts +8 -5
  249. package/dist/types/CustomType.js +17 -6
  250. package/dist/types/CustomType.js.map +1 -1
  251. package/dist/types/DoubleType.js +8 -8
  252. package/dist/types/DoubleType.js.map +1 -1
  253. package/dist/types/DoubleType.spec.js +2 -2
  254. package/dist/types/DoubleType.spec.js.map +1 -1
  255. package/dist/types/DynamicType.js +1 -1
  256. package/dist/types/DynamicType.js.map +1 -1
  257. package/dist/types/DynamicType.spec.js +2 -2
  258. package/dist/types/DynamicType.spec.js.map +1 -1
  259. package/dist/types/FloatType.d.ts +1 -1
  260. package/dist/types/FloatType.js +8 -8
  261. package/dist/types/FloatType.js.map +1 -1
  262. package/dist/types/FloatType.spec.js +2 -2
  263. package/dist/types/FloatType.spec.js.map +1 -1
  264. package/dist/types/FunctionType.d.ts +5 -11
  265. package/dist/types/FunctionType.js +24 -13
  266. package/dist/types/FunctionType.js.map +1 -1
  267. package/dist/types/FunctionType.spec.js +11 -5
  268. package/dist/types/FunctionType.spec.js.map +1 -1
  269. package/dist/types/IntegerType.d.ts +1 -1
  270. package/dist/types/IntegerType.js +8 -8
  271. package/dist/types/IntegerType.js.map +1 -1
  272. package/dist/types/IntegerType.spec.js +2 -2
  273. package/dist/types/IntegerType.spec.js.map +1 -1
  274. package/dist/types/InterfaceType.d.ts +8 -2
  275. package/dist/types/InterfaceType.js +42 -6
  276. package/dist/types/InterfaceType.js.map +1 -1
  277. package/dist/types/InterfaceType.spec.d.ts +1 -0
  278. package/dist/types/InterfaceType.spec.js +174 -0
  279. package/dist/types/InterfaceType.spec.js.map +1 -0
  280. package/dist/types/InvalidType.js +4 -4
  281. package/dist/types/InvalidType.js.map +1 -1
  282. package/dist/types/InvalidType.spec.js +2 -2
  283. package/dist/types/InvalidType.spec.js.map +1 -1
  284. package/dist/types/LazyType.d.ts +9 -7
  285. package/dist/types/LazyType.js +22 -10
  286. package/dist/types/LazyType.js.map +1 -1
  287. package/dist/types/LongIntegerType.d.ts +1 -1
  288. package/dist/types/LongIntegerType.js +8 -8
  289. package/dist/types/LongIntegerType.js.map +1 -1
  290. package/dist/types/LongIntegerType.spec.js +2 -2
  291. package/dist/types/LongIntegerType.spec.js.map +1 -1
  292. package/dist/types/ObjectType.d.ts +7 -4
  293. package/dist/types/ObjectType.js +6 -3
  294. package/dist/types/ObjectType.js.map +1 -1
  295. package/dist/types/ObjectType.spec.js +2 -2
  296. package/dist/types/ObjectType.spec.js.map +1 -1
  297. package/dist/types/StringType.js +3 -3
  298. package/dist/types/StringType.js.map +1 -1
  299. package/dist/types/StringType.spec.js +2 -2
  300. package/dist/types/StringType.spec.js.map +1 -1
  301. package/dist/types/UninitializedType.js +3 -3
  302. package/dist/types/UninitializedType.js.map +1 -1
  303. package/dist/types/VoidType.js +3 -3
  304. package/dist/types/VoidType.js.map +1 -1
  305. package/dist/types/VoidType.spec.js +2 -2
  306. package/dist/types/VoidType.spec.js.map +1 -1
  307. package/dist/types/helpers.d.ts +42 -0
  308. package/dist/types/helpers.js +113 -0
  309. package/dist/types/helpers.js.map +1 -0
  310. package/dist/util.d.ts +77 -17
  311. package/dist/util.js +247 -59
  312. package/dist/util.js.map +1 -1
  313. package/dist/validators/ClassValidator.d.ts +5 -1
  314. package/dist/validators/ClassValidator.js +59 -24
  315. package/dist/validators/ClassValidator.js.map +1 -1
  316. package/package.json +13 -13
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTypeFromDottedGetExpression = exports.getTypeFromNewExpression = exports.getTypeFromVariableExpression = exports.getTypeFromCallExpression = void 0;
4
+ const reflection_1 = require("../astUtils/reflection");
5
+ const LazyType_1 = require("./LazyType");
6
+ const UninitializedType_1 = require("./UninitializedType");
7
+ const Parser_1 = require("../parser/Parser");
8
+ const CustomType_1 = require("./CustomType");
9
+ /**
10
+ * Gets the return type of a function, taking into account that the function may not have been declared yet
11
+ * If the callee already exists in symbol table, use that return type
12
+ * otherwise, make a lazy type which will not compute its type until the file is done parsing
13
+ *
14
+ * @param call the Expression to process
15
+ * @param functionExpression the wrapping function expression
16
+ * @return the best guess type of that expression
17
+ */
18
+ function getTypeFromCallExpression(call, functionExpression) {
19
+ let calleeName = call.callee.name;
20
+ if (calleeName) {
21
+ const currentKnownType = functionExpression.symbolTable.getSymbolType(calleeName.text.toLowerCase());
22
+ if ((0, reflection_1.isFunctionType)(currentKnownType)) {
23
+ return currentKnownType.returnType;
24
+ }
25
+ if (currentKnownType) {
26
+ // this will probably only happen if a functionName has been assigned to something else previously?
27
+ return currentKnownType;
28
+ }
29
+ return new LazyType_1.LazyType((context) => {
30
+ var _a;
31
+ let futureType;
32
+ if ((0, reflection_1.isBrsFile)(context === null || context === void 0 ? void 0 : context.file)) {
33
+ const file = context.file;
34
+ futureType = (_a = file.getSymbolTypeFromToken(calleeName, functionExpression, context.scope)) === null || _a === void 0 ? void 0 : _a.type;
35
+ }
36
+ else {
37
+ // Give best guess if there is no file context
38
+ futureType = functionExpression.symbolTable.getSymbolType(calleeName.text);
39
+ }
40
+ if ((0, reflection_1.isFunctionType)(futureType)) {
41
+ return futureType.returnType;
42
+ }
43
+ return futureType;
44
+ });
45
+ }
46
+ }
47
+ exports.getTypeFromCallExpression = getTypeFromCallExpression;
48
+ /**
49
+ * Gets the type of a variable
50
+ * if it already exists in symbol table, use that type
51
+ * otherwise defer the type until first read, which will allow us to derive types from variables defined after this one (like from a loop perhaps)
52
+ *
53
+ * @param variable the Expression to process
54
+ * @param functionExpression the wrapping function expression
55
+ * @return the best guess type of that expression
56
+ */
57
+ function getTypeFromVariableExpression(variable, functionExpression) {
58
+ let variableName = variable.name.text.toLowerCase();
59
+ const currentKnownType = functionExpression.symbolTable.getSymbolType(variableName);
60
+ if ((0, reflection_1.isPrimitiveType)(currentKnownType)) {
61
+ // for "contextless" types, eg. myVar = 3.14
62
+ return currentKnownType;
63
+ }
64
+ return resolveLazyType(variable.name, functionExpression);
65
+ }
66
+ exports.getTypeFromVariableExpression = getTypeFromVariableExpression;
67
+ /**
68
+ * Gets the type of a variable
69
+ * if it already exists in symbol table, use that type
70
+ * otherwise defer the type until first read, which will allow us to derive types from variables defined after this one (like from a loop perhaps)
71
+ *
72
+ * @param newExp the Expression to process
73
+ * @param functionExpression the wrapping function expression
74
+ * @return the best guess type of that expression
75
+ */
76
+ function getTypeFromNewExpression(newExp, functionExpression) {
77
+ let className = newExp.className.getName(Parser_1.ParseMode.BrighterScript);
78
+ return new LazyType_1.LazyType((context) => {
79
+ var _a, _b, _c;
80
+ return new CustomType_1.CustomType(className, (_c = (_a = context === null || context === void 0 ? void 0 : context.scope) === null || _a === void 0 ? void 0 : _a.getClass(className, (_b = functionExpression.namespaceName) === null || _b === void 0 ? void 0 : _b.getName())) === null || _c === void 0 ? void 0 : _c.memberTable);
81
+ });
82
+ }
83
+ exports.getTypeFromNewExpression = getTypeFromNewExpression;
84
+ function resolveLazyType(currentToken, functionExpression) {
85
+ return new LazyType_1.LazyType((context) => {
86
+ var _a, _b;
87
+ let futureType;
88
+ if ((0, reflection_1.isBrsFile)(context === null || context === void 0 ? void 0 : context.file)) {
89
+ const file = context.file;
90
+ futureType = (_a = file.getSymbolTypeFromToken(currentToken, functionExpression, context.scope)) === null || _a === void 0 ? void 0 : _a.type;
91
+ }
92
+ else {
93
+ // Give best guess if there is no file context
94
+ futureType = (_b = functionExpression.symbolTable.getSymbolType(currentToken.text)) !== null && _b !== void 0 ? _b : new UninitializedType_1.UninitializedType();
95
+ }
96
+ return futureType;
97
+ });
98
+ }
99
+ /**
100
+ * Gets the type of a variable
101
+ * if it already exists in symbol table, use that type
102
+ * otherwise defer the type until first read, which will allow us to derive types from variables defined after this one (like from a loop perhaps)
103
+ *
104
+ * @param variable the Expression to process
105
+ * @param functionExpression the wrapping function expression
106
+ * @return the best guess type of that expression
107
+ */
108
+ function getTypeFromDottedGetExpression(expr, functionExpression) {
109
+ const currentToken = (0, reflection_1.isCallExpression)(expr) ? (expr.callee).name : expr.name;
110
+ return resolveLazyType(currentToken, functionExpression);
111
+ }
112
+ exports.getTypeFromDottedGetExpression = getTypeFromDottedGetExpression;
113
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/types/helpers.ts"],"names":[],"mappings":"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"}
package/dist/util.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as rokuDeploy from 'roku-deploy';
2
2
  import type { Diagnostic, Position, Range } from 'vscode-languageserver';
3
3
  import type { BsConfig } from './BsConfig';
4
- import type { CallableContainer, BsDiagnostic, FileReference, CallableContainerMap, CompilerPlugin, ExpressionInfo, FunctionCall } from './interfaces';
4
+ import type { CallableContainer, BsDiagnostic, FileReference, CallableContainerMap, CompilerPlugin, ExpressionInfo, FunctionCall, CallableParam, TranspileResult } from './interfaces';
5
5
  import { BooleanType } from './types/BooleanType';
6
6
  import { DoubleType } from './types/DoubleType';
7
7
  import { DynamicType } from './types/DynamicType';
@@ -13,10 +13,11 @@ import { LongIntegerType } from './types/LongIntegerType';
13
13
  import { ObjectType } from './types/ObjectType';
14
14
  import { StringType } from './types/StringType';
15
15
  import { VoidType } from './types/VoidType';
16
- import type { DottedGetExpression, Expression, VariableExpression } from './parser/Expression';
17
- import type { Token } from './lexer';
16
+ import type { DottedGetExpression, Expression, NamespacedVariableNameExpression, VariableExpression } from './parser/Expression';
17
+ import type { Locatable, Token } from './lexer';
18
18
  import { SourceNode } from 'source-map';
19
- import type { SGAttribute } from './parser/SGTypes';
19
+ import { SGAttribute } from './parser/SGTypes';
20
+ import { LazyType } from './types/LazyType';
20
21
  export declare class Util {
21
22
  clearConsole(): void;
22
23
  /**
@@ -36,7 +37,11 @@ export declare class Util {
36
37
  /**
37
38
  * Given a pkg path of any kind, transform it to a roku-specific pkg path (i.e. "pkg:/some/path.brs")
38
39
  */
39
- getRokuPkgPath(pkgPath: string): string;
40
+ sanitizePkgPath(pkgPath: string): string;
41
+ /**
42
+ * Determine if the given path starts with a protocol
43
+ */
44
+ startsWithProtocol(path: string): boolean;
40
45
  /**
41
46
  * Given a path to a file/directory, replace all path separators with the current system's version.
42
47
  * @param filePath
@@ -104,12 +109,11 @@ export declare class Util {
104
109
  */
105
110
  getLines(text: string): string[];
106
111
  /**
107
- * Given an absolute path to a source file, and a target path,
108
- * compute the pkg path for the target relative to the source file's location
109
- * @param containingFilePathAbsolute
110
- * @param targetPath
112
+ * Compute the pkg path for the target relative to the source file's location
113
+ * @param sourcePkgPath The pkgPath of the file that contains the target path
114
+ * @param targetPath a full pkgPath, or a path relative to the containing file
111
115
  */
112
- getPkgPathFromTarget(containingFilePathAbsolute: string, targetPath: string): string;
116
+ getPkgPathFromTarget(sourcePkgPath: string, targetPath: string): string;
113
117
  /**
114
118
  * Compute the relative path from the source file to the target file
115
119
  * @param pkgSourcePathAbsolute - the absolute path to the source relative to the package location
@@ -156,8 +160,9 @@ export declare class Util {
156
160
  areArraysEqual(arr1: any[], arr2: any[]): boolean;
157
161
  /**
158
162
  * Given a file path, convert it to a URI string
163
+ * @param srcPath The absolute path to the source file on disk
159
164
  */
160
- pathToUri(pathAbsolute: string): string;
165
+ pathToUri(srcPath: string): string;
161
166
  /**
162
167
  * Get the outDir from options, taking into account cwd and absolute outFile paths
163
168
  * @param options
@@ -169,7 +174,8 @@ export declare class Util {
169
174
  getFilePaths(options: BsConfig): Promise<rokuDeploy.StandardizedFileEntry[]>;
170
175
  /**
171
176
  * Given a path to a brs file, compute the path to a theoretical d.bs file.
172
- * Only `.brs` files can have typedef path, so return undefined for everything else
177
+ * Only `.brs` files can have a typedef, so return undefined for everything else
178
+ * @param brsSrcPath The absolute path to the .brs source file on disk
173
179
  */
174
180
  getTypedefPath(brsSrcPath: string): string;
175
181
  /**
@@ -252,6 +258,13 @@ export declare class Util {
252
258
  * Create a `Range` from two `Position`s
253
259
  */
254
260
  createRangeFromPositions(startPosition: Position, endPosition: Position): Range;
261
+ /**
262
+ * Given a list of ranges, create a range that starts with the first non-null lefthand range, and ends with the first non-null
263
+ * righthand range. Returns undefined if none of the items have a range.
264
+ */
265
+ createBoundingRange(...locatables: Array<{
266
+ range?: Range;
267
+ }>): Range;
255
268
  /**
256
269
  * Create a `Position` object. Prefer this over `Position.create` for performance reasons
257
270
  */
@@ -266,7 +279,7 @@ export declare class Util {
266
279
  /**
267
280
  * Convert a token into a BscType
268
281
  */
269
- tokenToBscType(token: Token, allowCustomType?: boolean): DynamicType | ObjectType | BooleanType | DoubleType | FloatType | FunctionType | IntegerType | InvalidType | LongIntegerType | StringType | VoidType;
282
+ tokenToBscType(token: Token, allowCustomType?: boolean, currentNamespaceName?: NamespacedVariableNameExpression): DynamicType | FloatType | FunctionType | IntegerType | LongIntegerType | StringType | BooleanType | LazyType | ObjectType | DoubleType | InvalidType | VoidType;
270
283
  /**
271
284
  * Get the extension for the given file path. Basically the part after the final dot, except for
272
285
  * `d.bs` which is treated as single extension
@@ -288,12 +301,20 @@ export declare class Util {
288
301
  */
289
302
  simpleMap(source: string, src: string): SourceNode;
290
303
  /**
291
- * Creates a new SGAttribute object, but keeps the existing Range references (since those shouldn't ever get changed directly)
304
+ * Creates a new SGAttribute object, but keeps the existing Range references (since those should be immutable)
292
305
  */
293
306
  cloneSGAttribute(attr: SGAttribute, value: string): SGAttribute;
294
307
  /**
295
- * Copy the version of bslib from local node_modules to the staging folder
308
+ * Shorthand for creating a new source node
296
309
  */
310
+ sourceNode(source: string, locatable: {
311
+ range: Range;
312
+ }, code: string | SourceNode | TranspileResult): SourceNode | undefined;
313
+ /**
314
+ * Remove leading simple protocols from a path (if present)
315
+ */
316
+ removeProtocol(pkgPath: string): string;
317
+ standardizePath(thePath: string): string;
297
318
  copyBslibToStaging(stagingDir: string): Promise<void>;
298
319
  /**
299
320
  * Given a Diagnostic or BsDiagnostic, return a copy of the diagnostic
@@ -310,11 +331,45 @@ export declare class Util {
310
331
  source: string;
311
332
  };
312
333
  /**
313
- * Finds the array of callables from a container map, taking into account the function from which it was called
334
+ * Gets the minimum and maximum number of allowed params
335
+ * @param params The list of callable parameters to check
336
+ * @returns the minimum and maximum number of allowed params
337
+ */
338
+ getMinMaxParamCount(params: CallableParam[]): MinMax;
339
+ /**
340
+ * Gets the minimum and maximum number of allowed params for ALL functions with the name of the function call
341
+ * @param callablesByLowerName The map of callable containers
342
+ * @param expCall function call expression to use for the name
343
+ * @returns the minimum and maximum number of allowed params
344
+ */
345
+ getMinMaxParamCountByFunctionCall(callablesByLowerName: CallableContainerMap, expCall: FunctionCall): MinMax;
346
+ /**
347
+ * Finds the array of callables from a container map, based on the name of the function call
314
348
  * If the callable was called in a function in a namespace, functions in that namespace are preferred
349
+ * @param callablesByLowerName The map of callable containers
350
+ * @param expCall function call expression to use for the name
315
351
  * @return an array with callable containers - could be empty if nothing was found
316
352
  */
317
- getCallableContainersFromContainerMapByFunctionCall(callablesByLowerName: CallableContainerMap, expCall: FunctionCall): CallableContainer[];
353
+ getCallableContainersByName(callablesByLowerName: CallableContainerMap, expCall: FunctionCall): CallableContainer[];
354
+ /**
355
+ * Sort an array of objects that have a Range
356
+ */
357
+ sortByRange(locatables: Locatable[]): Locatable[];
358
+ /**
359
+ * Split the given text and return ranges for each chunk.
360
+ * Only works for single-line strings
361
+ */
362
+ splitGetRange(separator: string, text: string, range: Range): {
363
+ text: string;
364
+ range: Range;
365
+ }[];
366
+ /**
367
+ * Finds a callable from a container map based on the name AND number of arguments
368
+ * If the callable was called in a function in a namespace, functions in that namespace are preferred
369
+ * The first callable that matches the name AND will accept the number of arguments given is returned
370
+ * @return a callable containers that matches the call
371
+ */
372
+ getCallableContainerByFunctionCall(callablesByLowerName: CallableContainerMap, expCall: FunctionCall): CallableContainer;
318
373
  }
319
374
  /**
320
375
  * A tagged template literal function for standardizing the path. This has to be defined as standalone function since it's a tagged template literal function,
@@ -323,3 +378,8 @@ export declare class Util {
323
378
  export declare function standardizePath(stringParts: any, ...expressions: any[]): string;
324
379
  export declare let util: Util;
325
380
  export default util;
381
+ export interface MinMax {
382
+ min: number;
383
+ max: number;
384
+ }
385
+ export declare const MAX_PARAM_COUNT = 32;