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
package/dist/Scope.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Scope = void 0;
4
- const path = require("path");
5
4
  const vscode_languageserver_1 = require("vscode-languageserver");
6
5
  const chalk_1 = require("chalk");
7
6
  const DiagnosticMessages_1 = require("./DiagnosticMessages");
@@ -14,6 +13,10 @@ const vscode_uri_1 = require("vscode-uri");
14
13
  const Logger_1 = require("./Logger");
15
14
  const reflection_1 = require("./astUtils/reflection");
16
15
  const SymbolTable_1 = require("./SymbolTable");
16
+ const UninitializedType_1 = require("./types/UninitializedType");
17
+ const ObjectType_1 = require("./types/ObjectType");
18
+ const BscType_1 = require("./types/BscType");
19
+ const DynamicType_1 = require("./types/DynamicType");
17
20
  /**
18
21
  * A class to keep track of all declarations within a given scope (like source scope, component scope)
19
22
  */
@@ -51,6 +54,14 @@ class Scope {
51
54
  var _a;
52
55
  return (_a = this.getClassFileLink(className, containingNamespace)) === null || _a === void 0 ? void 0 : _a.item;
53
56
  }
57
+ /**
58
+ * A cache of a map of tokens -> TokenSymbolLookups, which are the result of getSymbolTypeFromToken()
59
+ * Sometimes the lookup of symbols may take a while if there are lazyTypes or multiple tokens in a chain
60
+ * By caching the result of this lookup, subsequent lookups of the same tokens are quicker
61
+ */
62
+ get symbolCache() {
63
+ return this.cache.getOrAdd('symbolCache', () => new Map());
64
+ }
54
65
  /**
55
66
  * Get a class and its containing file by the class name
56
67
  * @param className - The class name, including the namespace of the class if possible
@@ -67,9 +78,24 @@ class Scope {
67
78
  return cls;
68
79
  }
69
80
  /**
81
+ * Gets the parent class of the given class
82
+ * @param klass - The class to get the parent of, if possible
83
+ */
84
+ getParentClass(klass) {
85
+ if (klass === null || klass === void 0 ? void 0 : klass.hasParentClass()) {
86
+ const lowerParentClassNames = klass.getPossibleFullParentNames().map(name => name.toLowerCase());
87
+ for (const lowerParentClassName of lowerParentClassNames) {
88
+ const foundParent = this.getClassMap().get(lowerParentClassName);
89
+ if (foundParent) {
90
+ return foundParent.item;
91
+ }
92
+ }
93
+ }
94
+ }
95
+ /**
70
96
  * Tests if a class exists with the specified name
71
97
  * @param className - the all-lower-case namespace-included class name
72
- * @param namespaceName - teh current namespace name
98
+ * @param namespaceName - the current namespace name
73
99
  */
74
100
  hasClass(className, namespaceName) {
75
101
  return !!this.getClass(className, namespaceName);
@@ -83,7 +109,7 @@ class Scope {
83
109
  const map = new Map();
84
110
  this.enumerateBrsFiles((file) => {
85
111
  var _a;
86
- if (reflection_1.isBrsFile(file)) {
112
+ if ((0, reflection_1.isBrsFile)(file)) {
87
113
  for (let cls of file.parser.references.classStatements) {
88
114
  const lowerClassName = (_a = cls.getName(parser_1.ParseMode.BrighterScript)) === null || _a === void 0 ? void 0 : _a.toLowerCase();
89
115
  //only track classes with a defined name (i.e. exclude nameless malformed classes)
@@ -96,6 +122,20 @@ class Scope {
96
122
  return map;
97
123
  });
98
124
  }
125
+ getAncestorTypeList(className, namespaceName) {
126
+ var _a;
127
+ const ancestors = [];
128
+ let currentClass = (_a = this.getClassFileLink(className, namespaceName)) === null || _a === void 0 ? void 0 : _a.item;
129
+ if (currentClass) {
130
+ ancestors.push(currentClass === null || currentClass === void 0 ? void 0 : currentClass.getCustomType());
131
+ }
132
+ while (currentClass === null || currentClass === void 0 ? void 0 : currentClass.hasParentClass()) {
133
+ currentClass = this.getParentClass(currentClass);
134
+ ancestors.push(currentClass === null || currentClass === void 0 ? void 0 : currentClass.getCustomType());
135
+ }
136
+ // TODO TYPES: this should probably be cached
137
+ return ancestors;
138
+ }
99
139
  onDependenciesChanged(event) {
100
140
  this.logDebug('invalidated because dependency graph said [', event.sourceKey, '] changed');
101
141
  this.invalidate();
@@ -130,7 +170,7 @@ class Scope {
130
170
  */
131
171
  getParentScope() {
132
172
  let scope;
133
- //use the global scope if we didn't find a sope and this is not the global scope
173
+ //use the global scope if we didn't find a scope and this is not the global scope
134
174
  if (this.program.globalScope !== this) {
135
175
  scope = this.program.globalScope;
136
176
  }
@@ -154,12 +194,16 @@ class Scope {
154
194
  }
155
195
  /**
156
196
  * Get the file with the specified pkgPath
197
+ * @param filePath can be a srcPath, a pkgPath, or a destPath (same as pkgPath but without `pkg:/`)
198
+ * @param normalizePath should this function repair and standardize the path? Passing false should have a performance boost if you can guarantee your path is already sanitized
157
199
  */
158
- getFile(pathAbsolute) {
159
- pathAbsolute = util_1.standardizePath `${pathAbsolute}`;
200
+ getFile(srcPath, normalizePath = true) {
201
+ if (normalizePath) {
202
+ srcPath = (0, util_1.standardizePath) `${srcPath}`;
203
+ }
160
204
  let files = this.getAllFiles();
161
205
  for (let file of files) {
162
- if (file.pathAbsolute === pathAbsolute) {
206
+ if (file.srcPath === srcPath) {
163
207
  return file;
164
208
  }
165
209
  }
@@ -189,7 +233,7 @@ class Scope {
189
233
  }
190
234
  }
191
235
  else {
192
- let file = this.program.getFileByPkgPath(dependency);
236
+ let file = this.program.getFile(dependency, false);
193
237
  if (file) {
194
238
  result.push(file);
195
239
  }
@@ -253,7 +297,7 @@ class Scope {
253
297
  const files = this.getAllFiles();
254
298
  for (const file of files) {
255
299
  //only brs files without a typedef
256
- if (reflection_1.isBrsFile(file) && !file.hasTypedef) {
300
+ if ((0, reflection_1.isBrsFile)(file) && !file.hasTypedef) {
257
301
  callback(file);
258
302
  }
259
303
  }
@@ -265,7 +309,7 @@ class Scope {
265
309
  const files = this.getOwnFiles();
266
310
  for (const file of files) {
267
311
  //either XML components or files without a typedef
268
- if (reflection_1.isXmlFile(file) || !file.hasTypedef) {
312
+ if ((0, reflection_1.isXmlFile)(file) || !file.hasTypedef) {
269
313
  callback(file);
270
314
  }
271
315
  }
@@ -292,9 +336,8 @@ class Scope {
292
336
  * Builds a tree of namespace objects
293
337
  */
294
338
  buildNamespaceLookup() {
295
- let namespaceLookup = {};
339
+ let namespaceLookup = new Map();
296
340
  this.enumerateBrsFiles((file) => {
297
- var _a;
298
341
  for (let namespace of file.parser.references.namespaceStatements) {
299
342
  //TODO should we handle non-brighterscript?
300
343
  let name = namespace.nameExpression.getName(parser_1.ParseMode.BrighterScript);
@@ -305,25 +348,27 @@ class Scope {
305
348
  for (let part of nameParts) {
306
349
  loopName = loopName === null ? part : `${loopName}.${part}`;
307
350
  let lowerLoopName = loopName.toLowerCase();
308
- namespaceLookup[lowerLoopName] = (_a = namespaceLookup[lowerLoopName]) !== null && _a !== void 0 ? _a : {
309
- file: file,
310
- fullName: loopName,
311
- nameRange: namespace.nameExpression.range,
312
- lastPartName: part,
313
- namespaces: {},
314
- classStatements: {},
315
- functionStatements: {},
316
- statements: [],
317
- symbolTable: new SymbolTable_1.SymbolTable(this.symbolTable)
318
- };
319
- }
320
- let ns = namespaceLookup[name.toLowerCase()];
351
+ if (!namespaceLookup.has(lowerLoopName)) {
352
+ namespaceLookup.set(lowerLoopName, {
353
+ file: file,
354
+ fullName: loopName,
355
+ nameRange: namespace.nameExpression.range,
356
+ lastPartName: part,
357
+ namespaces: new Map(),
358
+ classStatements: {},
359
+ functionStatements: {},
360
+ statements: [],
361
+ symbolTable: new SymbolTable_1.SymbolTable(this.symbolTable)
362
+ });
363
+ }
364
+ }
365
+ let ns = namespaceLookup.get(name.toLowerCase());
321
366
  ns.statements.push(...namespace.body.statements);
322
367
  for (let statement of namespace.body.statements) {
323
- if (reflection_1.isClassStatement(statement)) {
368
+ if ((0, reflection_1.isClassStatement)(statement) && statement.name) {
324
369
  ns.classStatements[statement.name.text.toLowerCase()] = statement;
325
370
  }
326
- else if (reflection_1.isFunctionStatement(statement)) {
371
+ else if ((0, reflection_1.isFunctionStatement)(statement) && statement.name) {
327
372
  ns.functionStatements[statement.name.text.toLowerCase()] = statement;
328
373
  }
329
374
  }
@@ -332,14 +377,14 @@ class Scope {
332
377
  ns.symbolTable.mergeSymbolTable(namespace.symbolTable);
333
378
  }
334
379
  //associate child namespaces with their parents
335
- for (let key in namespaceLookup) {
336
- let ns = namespaceLookup[key];
380
+ for (let [, ns] of namespaceLookup) {
337
381
  let parts = ns.fullName.split('.');
338
382
  if (parts.length > 1) {
339
383
  //remove the last part
340
384
  parts.pop();
341
385
  let parentName = parts.join('.');
342
- namespaceLookup[parentName.toLowerCase()].namespaces[ns.lastPartName.toLowerCase()] = ns;
386
+ const parent = namespaceLookup.get(parentName.toLowerCase());
387
+ parent.namespaces.set(ns.lastPartName.toLowerCase(), ns);
343
388
  }
344
389
  }
345
390
  });
@@ -372,7 +417,7 @@ class Scope {
372
417
  callables = callables.sort((a, b) => {
373
418
  return (
374
419
  //sort by path
375
- a.callable.file.pathAbsolute.localeCompare(b.callable.file.pathAbsolute) ||
420
+ a.callable.file.srcPath.localeCompare(b.callable.file.srcPath) ||
376
421
  //then sort by method name
377
422
  a.callable.name.localeCompare(b.callable.name));
378
423
  });
@@ -388,17 +433,15 @@ class Scope {
388
433
  this.diagnosticFindDuplicateFunctionDeclarations(callableContainerMap);
389
434
  //detect missing and incorrect-case script imports
390
435
  this.diagnosticValidateScriptImportPaths();
391
- //enforce a series of checks on the bodies of class methods
392
- this.validateClasses();
393
436
  //do many per-file checks
394
437
  this.enumerateBrsFiles((file) => {
395
- this.diagnosticDetectCallsToUnknownFunctions(file, callableContainerMap);
396
- this.diagnosticDetectFunctionCallsWithWrongParamCount(file, callableContainerMap);
438
+ //enforce a series of checks on the bodies of class methods
439
+ this.validateClasses(file);
397
440
  this.diagnosticDetectShadowedLocalVars(file, callableContainerMap);
398
441
  this.diagnosticDetectFunctionCollisions(file);
399
442
  this.detectVariableNamespaceCollisions(file);
400
443
  this.diagnosticDetectInvalidFunctionExpressionTypes(file);
401
- this.diagnosticDetectInvalidFunctionCalls(file);
444
+ this.diagnosticDetectInvalidFunctionCalls(file, callableContainerMap);
402
445
  });
403
446
  }
404
447
  /**
@@ -409,21 +452,34 @@ class Scope {
409
452
  //clear out various lookups (they'll get regenerated on demand the next time they're requested)
410
453
  this.cache.clear();
411
454
  this.clearSymbolTable();
455
+ this.symbolCache.clear();
412
456
  }
413
457
  get symbolTable() {
414
458
  var _a, _b;
415
459
  if (!this._symbolTable) {
416
460
  this._symbolTable = new SymbolTable_1.SymbolTable((_a = this.getParentScope()) === null || _a === void 0 ? void 0 : _a.symbolTable);
461
+ this._symbolTable.addSymbol('m', null, new ObjectType_1.ObjectType(this.memberTable));
417
462
  for (let file of this.getOwnFiles()) {
418
- if (reflection_1.isBrsFile(file)) {
463
+ if ((0, reflection_1.isBrsFile)(file)) {
419
464
  this._symbolTable.mergeSymbolTable((_b = file.parser) === null || _b === void 0 ? void 0 : _b.symbolTable);
420
465
  }
421
466
  }
422
467
  }
423
468
  return this._symbolTable;
424
469
  }
470
+ get memberTable() {
471
+ var _a;
472
+ if (!this._memberTable) {
473
+ this._memberTable = new SymbolTable_1.SymbolTable((_a = this.getParentScope()) === null || _a === void 0 ? void 0 : _a.memberTable);
474
+ if (!this.getParentScope()) {
475
+ this._memberTable.addSymbol('global', null, new ObjectType_1.ObjectType());
476
+ }
477
+ }
478
+ return this._memberTable;
479
+ }
425
480
  clearSymbolTable() {
426
481
  this._symbolTable = null;
482
+ this._memberTable = null;
427
483
  }
428
484
  /**
429
485
  * Builds the current symbol table for the scope, by merging the tables for all the files in this scope.
@@ -432,21 +488,41 @@ class Scope {
432
488
  */
433
489
  linkSymbolTable() {
434
490
  var _a;
435
- for (const file of this.getOwnFiles()) {
436
- if (reflection_1.isBrsFile(file)) {
437
- (_a = file.parser) === null || _a === void 0 ? void 0 : _a.symbolTable.setParent(this.symbolTable);
491
+ for (const file of this.getAllFiles()) {
492
+ if ((0, reflection_1.isBrsFile)(file)) {
493
+ file.parser.symbolTable.setParent(this.symbolTable);
438
494
  for (const namespace of file.parser.references.namespaceStatements) {
439
495
  const namespaceNameLower = namespace.nameExpression.getName(parser_1.ParseMode.BrighterScript).toLowerCase();
440
- const namespaceSymbolTable = this.namespaceLookup[namespaceNameLower].symbolTable;
496
+ const namespaceSymbolTable = this.namespaceLookup.get(namespaceNameLower).symbolTable;
441
497
  namespace.symbolTable.setParent(namespaceSymbolTable);
442
498
  }
499
+ //TODO TYPES: build symbol tables for dotted set assignments using actual values
500
+ // Currently this is prone to call-stack issues.
501
+ // eg. m.key = "value"
502
+ for (const dotSetStmt of file.parser.references.dottedSetStatements) {
503
+ if ((0, reflection_1.isVariableExpression)(dotSetStmt.obj)) {
504
+ if (dotSetStmt.obj.getName(parser_1.ParseMode.BrighterScript).toLowerCase() === 'm') {
505
+ this.memberTable.addSymbol(dotSetStmt.name.text, dotSetStmt.range, new DynamicType_1.DynamicType());
506
+ // TODO TYPES: get actual types: getBscTypeFromExpression(dotSetStmt.value, file.parser.references.getContainingFunctionExpression(dotSetStmt.name)));
507
+ }
508
+ }
509
+ else {
510
+ // TODO TYPES: What other types of expressions could these be?
511
+ }
512
+ }
443
513
  }
444
514
  }
515
+ // also link classes
516
+ const classMap = this.getClassMap();
517
+ for (const pair of classMap) {
518
+ const classStmt = (_a = pair[1]) === null || _a === void 0 ? void 0 : _a.item;
519
+ classStmt === null || classStmt === void 0 ? void 0 : classStmt.buildSymbolTable(this.getParentClass(classStmt));
520
+ }
445
521
  }
446
522
  unlinkSymbolTable() {
447
523
  var _a;
448
524
  for (let file of this.getOwnFiles()) {
449
- if (reflection_1.isBrsFile(file)) {
525
+ if ((0, reflection_1.isBrsFile)(file)) {
450
526
  (_a = file.parser) === null || _a === void 0 ? void 0 : _a.symbolTable.setParent(null);
451
527
  for (const namespace of file.parser.references.namespaceStatements) {
452
528
  namespace.symbolTable.setParent(null);
@@ -459,24 +535,24 @@ class Scope {
459
535
  for (let func of file.parser.references.functionExpressions) {
460
536
  for (let param of func.parameters) {
461
537
  let lowerParamName = param.name.text.toLowerCase();
462
- let namespace = this.namespaceLookup[lowerParamName];
538
+ let namespace = this.namespaceLookup.get(lowerParamName);
463
539
  //see if the param matches any starting namespace part
464
540
  if (namespace) {
465
541
  this.diagnostics.push(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.parameterMayNotHaveSameNameAsNamespace(param.name.text)), { range: param.name.range, relatedInformation: [{
466
542
  message: 'Namespace declared here',
467
- location: vscode_languageserver_1.Location.create(vscode_uri_1.URI.file(namespace.file.pathAbsolute).toString(), namespace.nameRange)
543
+ location: vscode_languageserver_1.Location.create(vscode_uri_1.URI.file(namespace.file.srcPath).toString(), namespace.nameRange)
468
544
  }] }));
469
545
  }
470
546
  }
471
547
  }
472
548
  for (let assignment of file.parser.references.assignmentStatements) {
473
549
  let lowerAssignmentName = assignment.name.text.toLowerCase();
474
- let namespace = this.namespaceLookup[lowerAssignmentName];
550
+ let namespace = this.namespaceLookup.get(lowerAssignmentName);
475
551
  //see if the param matches any starting namespace part
476
552
  if (namespace) {
477
553
  this.diagnostics.push(Object.assign(Object.assign({ file: file }, DiagnosticMessages_1.DiagnosticMessages.variableMayNotHaveSameNameAsNamespace(assignment.name.text)), { range: assignment.name.range, relatedInformation: [{
478
554
  message: 'Namespace declared here',
479
- location: vscode_languageserver_1.Location.create(vscode_uri_1.URI.file(namespace.file.pathAbsolute).toString(), namespace.nameRange)
555
+ location: vscode_languageserver_1.Location.create(vscode_uri_1.URI.file(namespace.file.srcPath).toString(), namespace.nameRange)
480
556
  }] }));
481
557
  }
482
558
  }
@@ -504,20 +580,22 @@ class Scope {
504
580
  * Find function parameters and function return types that are neither built-in types or known Class references
505
581
  */
506
582
  diagnosticDetectInvalidFunctionExpressionTypes(file) {
507
- var _a, _b;
583
+ var _a, _b, _c, _d;
508
584
  for (let func of file.parser.references.functionExpressions) {
509
- if (reflection_1.isCustomType(func.returnType) && func.returnTypeToken) {
585
+ const returnType = (0, BscType_1.getTypeFromContext)(func.returnType, { file: file, scope: this, position: (_a = func.range) === null || _a === void 0 ? void 0 : _a.start });
586
+ if (!returnType && func.returnTypeToken) {
510
587
  // check if this custom type is in our class map
511
- const returnTypeName = func.returnType.name;
512
- const currentNamespaceName = (_a = func.namespaceName) === null || _a === void 0 ? void 0 : _a.getName(parser_1.ParseMode.BrighterScript);
588
+ const returnTypeName = func.returnTypeToken.text;
589
+ const currentNamespaceName = (_b = func.namespaceName) === null || _b === void 0 ? void 0 : _b.getName(parser_1.ParseMode.BrighterScript);
513
590
  if (!this.hasClass(returnTypeName, currentNamespaceName)) {
514
591
  this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.invalidFunctionReturnType(returnTypeName)), { range: func.returnTypeToken.range, file: file }));
515
592
  }
516
593
  }
517
594
  for (let param of func.parameters) {
518
- if (reflection_1.isCustomType(param.type) && param.typeToken) {
519
- const paramTypeName = param.type.name;
520
- const currentNamespaceName = (_b = func.namespaceName) === null || _b === void 0 ? void 0 : _b.getName(parser_1.ParseMode.BrighterScript);
595
+ const paramType = (0, BscType_1.getTypeFromContext)(param.type, { file: file, scope: this, position: (_c = param.range) === null || _c === void 0 ? void 0 : _c.start });
596
+ if (!paramType && param.typeToken) {
597
+ const paramTypeName = param.typeToken.text;
598
+ const currentNamespaceName = (_d = func.namespaceName) === null || _d === void 0 ? void 0 : _d.getName(parser_1.ParseMode.BrighterScript);
521
599
  if (!this.hasClass(paramTypeName, currentNamespaceName)) {
522
600
  this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid(param.name.text, paramTypeName)), { range: param.typeToken.range, file: file }));
523
601
  }
@@ -525,27 +603,92 @@ class Scope {
525
603
  }
526
604
  }
527
605
  }
528
- diagnosticDetectInvalidFunctionCalls(file) {
529
- for (let expCall of file.functionCalls) {
530
- const funcType = expCall.functionExpression.symbolTable.getSymbolType(expCall.name);
531
- if (!reflection_1.isFunctionType(funcType)) {
532
- // can not find function. Handled in a different validation function
533
- continue;
534
- }
535
- if (funcType.params.length !== expCall.args.length) {
536
- // Argument count mismatch. Handled in a different validation function
537
- continue;
538
- }
539
- for (let index = 0; index < funcType.params.length; index++) {
540
- const param = funcType.params[index];
541
- const arg = expCall.args[index];
542
- const argType = arg.type;
543
- if (!argType.isAssignableTo(param.type)) {
544
- this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch(arg.type.toTypeString(), param.type.toTypeString())), { range: arg.range, file: file }));
606
+ /**
607
+ * Find functions with either the wrong type of parameters, or the wrong number of parameters
608
+ */
609
+ diagnosticDetectInvalidFunctionCalls(file, callableContainersByLowerName) {
610
+ var _a, _b, _c, _d, _e;
611
+ if ((0, reflection_1.isBrsFile)(file)) {
612
+ for (let expCall of file.functionCalls) {
613
+ const symbolTypeInfo = file.getSymbolTypeFromToken(expCall.name, expCall.functionExpression, this);
614
+ let funcType = symbolTypeInfo.type;
615
+ if (!(0, reflection_1.isFunctionType)(funcType) && !(0, reflection_1.isDynamicType)(funcType)) {
616
+ // We don't know if this is a function. Try seeing if it is a global
617
+ const callableContainer = util_1.util.getCallableContainerByFunctionCall(callableContainersByLowerName, expCall);
618
+ if (callableContainer) {
619
+ // We found a global callable with correct number of params - use that
620
+ funcType = (_a = callableContainer.callable) === null || _a === void 0 ? void 0 : _a.type;
621
+ }
622
+ else {
623
+ const allowedParamCount = util_1.util.getMinMaxParamCountByFunctionCall(callableContainersByLowerName, expCall);
624
+ if (allowedParamCount) {
625
+ // We found a global callable, but it needs a different number of args
626
+ this.addMismatchParamCountDiagnostic(allowedParamCount, expCall, file);
627
+ continue;
628
+ }
629
+ }
630
+ }
631
+ if ((0, reflection_1.isFunctionType)(funcType)) {
632
+ // Check for Argument count mismatch.
633
+ //get min/max parameter count for callable
634
+ let paramCount = util_1.util.getMinMaxParamCount(funcType.params);
635
+ if (expCall.args.length > paramCount.max || expCall.args.length < paramCount.min) {
636
+ this.addMismatchParamCountDiagnostic(paramCount, expCall, file);
637
+ }
638
+ // Check for Argument type mismatch.
639
+ const paramTypeContext = { file: file, scope: this, position: (_b = expCall.functionExpression.range) === null || _b === void 0 ? void 0 : _b.start };
640
+ const argTypeContext = { file: file, scope: this, position: (_c = expCall.range) === null || _c === void 0 ? void 0 : _c.start };
641
+ for (let index = 0; index < funcType.params.length; index++) {
642
+ const param = funcType.params[index];
643
+ const arg = expCall.args[index];
644
+ if (!arg) {
645
+ // not enough args
646
+ break;
647
+ }
648
+ let argType = (_d = arg.type) !== null && _d !== void 0 ? _d : new UninitializedType_1.UninitializedType();
649
+ let assignable = false;
650
+ const paramType = (0, BscType_1.getTypeFromContext)(param.type, paramTypeContext);
651
+ if (!paramType) {
652
+ // other error - can not determine what type this parameter should be
653
+ continue;
654
+ }
655
+ argType = (0, BscType_1.getTypeFromContext)(argType, argTypeContext);
656
+ if ((0, reflection_1.isCustomType)(argType)) {
657
+ const lowerNamespaceName = (_e = expCall.functionExpression.namespaceName) === null || _e === void 0 ? void 0 : _e.getName().toLowerCase();
658
+ assignable = argType.isAssignableTo(paramType, argTypeContext, this.getAncestorTypeList(argType.name, lowerNamespaceName));
659
+ }
660
+ else {
661
+ assignable = argType === null || argType === void 0 ? void 0 : argType.isAssignableTo(paramType, argTypeContext);
662
+ }
663
+ if (!assignable) {
664
+ // TODO TYPES: perhaps this should be a strict mode setting?
665
+ assignable = argType === null || argType === void 0 ? void 0 : argType.isConvertibleTo(paramType, argTypeContext);
666
+ }
667
+ if (!assignable) {
668
+ this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch(argType === null || argType === void 0 ? void 0 : argType.toString(argTypeContext), paramType.toString(paramTypeContext))), { range: arg === null || arg === void 0 ? void 0 : arg.range, file: file }));
669
+ }
670
+ }
671
+ }
672
+ else if ((0, reflection_1.isInvalidType)(symbolTypeInfo.type)) {
673
+ // TODO TYPES: standard member functions like integer.ToStr() are not detectable yet.
674
+ }
675
+ else if ((0, reflection_1.isDynamicType)(symbolTypeInfo.type)) {
676
+ // maybe this is a function? who knows
677
+ }
678
+ else {
679
+ const functionNameText = symbolTypeInfo.expandedTokenText;
680
+ this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.callToUnknownFunction(functionNameText, this.name)), { range: expCall.nameRange,
681
+ //TODO detect end of expression call
682
+ file: file }));
545
683
  }
546
684
  }
547
685
  }
548
686
  }
687
+ addMismatchParamCountDiagnostic(paramCount, expCall, file) {
688
+ const minMaxParamsText = paramCount.min === paramCount.max ? paramCount.max : `${paramCount.min}-${paramCount.max}`;
689
+ const expCallArgCount = expCall.args.length;
690
+ this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(minMaxParamsText, expCallArgCount)), { range: expCall.nameRange, file: file }));
691
+ }
549
692
  getNewExpressions() {
550
693
  let result = [];
551
694
  this.enumerateBrsFiles((file) => {
@@ -557,44 +700,11 @@ class Scope {
557
700
  });
558
701
  return result;
559
702
  }
560
- validateClasses() {
703
+ validateClasses(file) {
561
704
  let validator = new ClassValidator_1.BsClassValidator();
562
- validator.validate(this);
705
+ validator.validate(this, file);
563
706
  this.diagnostics.push(...validator.diagnostics);
564
707
  }
565
- /**
566
- * Detect calls to functions with the incorrect number of parameters
567
- * @param file
568
- * @param callableContainersByLowerName
569
- */
570
- diagnosticDetectFunctionCallsWithWrongParamCount(file, callableContainersByLowerName) {
571
- //validate all function calls
572
- for (let expCall of file.functionCalls) {
573
- let callableContainersWithThisName = callableContainersByLowerName.get(expCall.name.toLowerCase());
574
- //use the first item from callablesByLowerName, because if there are more, that's a separate error
575
- let knownCallableContainer = callableContainersWithThisName ? callableContainersWithThisName[0] : undefined;
576
- if (knownCallableContainer) {
577
- //get min/max parameter count for callable
578
- let minParams = 0;
579
- let maxParams = 0;
580
- for (let param of knownCallableContainer.callable.params) {
581
- maxParams++;
582
- //optional parameters must come last, so we can assume that minParams won't increase once we hit
583
- //the first isOptional
584
- if (param.isOptional === false) {
585
- minParams++;
586
- }
587
- }
588
- let expCallArgCount = expCall.args.length;
589
- if (expCall.args.length > maxParams || expCall.args.length < minParams) {
590
- let minMaxParamsText = minParams === maxParams ? maxParams : `${minParams}-${maxParams}`;
591
- this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(minMaxParamsText, expCallArgCount)), { range: expCall.nameRange,
592
- //TODO detect end of expression call
593
- file: file }));
594
- }
595
- }
596
- }
597
- }
598
708
  /**
599
709
  * Detect local variables (vars declared within a function expression) that have the same name as scope calls
600
710
  * @param file
@@ -604,10 +714,10 @@ class Scope {
604
714
  const classMap = this.getClassMap();
605
715
  for (let func of file.parser.references.functionExpressions) {
606
716
  //every var declaration in this function expression
607
- for (let symbol of func.symbolTable.ownSymbols) {
717
+ for (let symbol of func.symbolTable.getOwnSymbols()) {
608
718
  const symbolNameLower = symbol.name.toLowerCase();
609
719
  //if the var is a function
610
- if (reflection_1.isFunctionType(symbol.type)) {
720
+ if ((0, reflection_1.isFunctionType)(symbol.type)) {
611
721
  //local var function with same name as stdlib function
612
722
  if (
613
723
  //has same name as stdlib
@@ -638,41 +748,6 @@ class Scope {
638
748
  }
639
749
  }
640
750
  }
641
- /**
642
- * Detect calls to functions that are not defined in this scope
643
- * @param file
644
- * @param callablesByLowerName
645
- */
646
- diagnosticDetectCallsToUnknownFunctions(file, callablesByLowerName) {
647
- var _a;
648
- //validate all expression calls
649
- for (let expCall of file.functionCalls) {
650
- if (reflection_1.isBrsFile(file)) {
651
- const lowerName = expCall.name.toLowerCase();
652
- //for now, skip validation on any method named "super" within `.bs` contexts.
653
- //TODO revise this logic so we know if this function call resides within a class constructor function
654
- if (file.extension === '.bs' && lowerName === 'super') {
655
- continue;
656
- }
657
- //find a local variable with this name
658
- const localSymbol = (_a = file.getFunctionExpressionAtPosition(expCall.nameRange.start)) === null || _a === void 0 ? void 0 : _a.symbolTable.getSymbol(lowerName);
659
- //if we don't already have a variable with this name.
660
- if (!localSymbol) {
661
- const callablesWithThisName = util_1.util.getCallableContainersFromContainerMapByFunctionCall(callablesByLowerName, expCall);
662
- //use the first item from callablesByLowerName, because if there are more, that's a separate error
663
- let knownCallable = callablesWithThisName ? callablesWithThisName[0] : undefined;
664
- //detect calls to unknown functions
665
- if (!knownCallable) {
666
- this.diagnostics.push(Object.assign(Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.callToUnknownFunction(expCall.name, this.name)), { range: expCall.nameRange, file: file }));
667
- }
668
- }
669
- else {
670
- //if we found a variable with the same name as the function, assume the call is "known".
671
- //If the variable is a different type, some other check should add a diagnostic for that.
672
- }
673
- }
674
- }
675
- }
676
751
  /**
677
752
  * Create diagnostics for any duplicate function declarations
678
753
  * @param callablesByLowerName
@@ -729,10 +804,10 @@ class Scope {
729
804
  getOwnScriptImports() {
730
805
  let result = [];
731
806
  this.enumerateOwnFiles((file) => {
732
- if (reflection_1.isBrsFile(file)) {
807
+ if ((0, reflection_1.isBrsFile)(file)) {
733
808
  result.push(...file.ownScriptImports);
734
809
  }
735
- else if (reflection_1.isXmlFile(file)) {
810
+ else if ((0, reflection_1.isXmlFile)(file)) {
736
811
  result.push(...file.scriptTagImports);
737
812
  }
738
813
  });
@@ -749,7 +824,7 @@ class Scope {
749
824
  //if we can't find the file
750
825
  if (!referencedFile) {
751
826
  //skip the default bslib file, it will exist at transpile time but should not show up in the program during validation cycle
752
- if (scriptImport.pkgPath === `source${path.sep}bslib.brs`) {
827
+ if (scriptImport.pkgPath === `pkg:/source/bslib.brs`) {
753
828
  continue;
754
829
  }
755
830
  let dInfo;
@@ -841,7 +916,7 @@ class Scope {
841
916
  let results = new Map();
842
917
  let filesSearched = new Set();
843
918
  for (const file of this.getAllFiles()) {
844
- if (reflection_1.isXmlFile(file) || filesSearched.has(file)) {
919
+ if ((0, reflection_1.isXmlFile)(file) || filesSearched.has(file)) {
845
920
  continue;
846
921
  }
847
922
  filesSearched.add(file);
@@ -850,7 +925,7 @@ class Scope {
850
925
  if (!results.has(s.name.text) && s.name.text.toLowerCase() !== 'new') {
851
926
  results.set(s.name.text, {
852
927
  label: s.name.text,
853
- kind: reflection_1.isClassMethodStatement(s) ? vscode_languageserver_1.CompletionItemKind.Method : vscode_languageserver_1.CompletionItemKind.Field
928
+ kind: (0, reflection_1.isClassMethodStatement)(s) ? vscode_languageserver_1.CompletionItemKind.Method : vscode_languageserver_1.CompletionItemKind.Field
854
929
  });
855
930
  }
856
931
  }