brighterscript 0.66.0-alpha.8 → 0.67.0

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 +120 -71
  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 +29 -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 +82 -87
  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 +552 -607
  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 -12
  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
@@ -1,2004 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const sinonImport = require("sinon");
4
- const DiagnosticMessages_1 = require("../../DiagnosticMessages");
5
- const Program_1 = require("../../Program");
6
- const testHelpers_spec_1 = require("../../testHelpers.spec");
7
- const chai_1 = require("chai");
8
- const IntegerType_1 = require("../../types/IntegerType");
9
- const StringType_1 = require("../../types/StringType");
10
- const types_1 = require("../../types");
11
- describe('ScopeValidator', () => {
12
- let sinon = sinonImport.createSandbox();
13
- let rootDir = process.cwd();
14
- let program;
15
- beforeEach(() => {
16
- program = new Program_1.Program({
17
- rootDir: rootDir
18
- });
19
- program.createSourceScope();
20
- });
21
- afterEach(() => {
22
- sinon.restore();
23
- program.dispose();
24
- });
25
- describe('mismatchArgumentCount', () => {
26
- it('detects calling functions with too many arguments', () => {
27
- program.setFile('source/file.brs', `
28
- sub a()
29
- end sub
30
- sub b()
31
- a(1)
32
- end sub
33
- `);
34
- program.validate();
35
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
36
- DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(0, 1).message
37
- ]);
38
- });
39
- it('detects calling class constructors with too many arguments', () => {
40
- program.setFile('source/main.bs', `
41
- function noop0()
42
- end function
43
-
44
- function noop1(p1)
45
- end function
46
-
47
- sub main()
48
- noop0(1)
49
- noop1(1,2)
50
- noop1()
51
- end sub
52
- `);
53
- program.validate();
54
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
55
- DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(0, 1),
56
- DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 2),
57
- DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 0)
58
- ]);
59
- });
60
- it('detects calling functions with too few arguments', () => {
61
- program.setFile('source/file.brs', `
62
- sub a(name)
63
- end sub
64
- sub b()
65
- a()
66
- end sub
67
- `);
68
- program.validate();
69
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
70
- DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 0)
71
- ]);
72
- });
73
- it('allows skipping optional parameter', () => {
74
- program.setFile('source/file.brs', `
75
- sub a(name="Bob")
76
- end sub
77
- sub b()
78
- a()
79
- end sub
80
- `);
81
- program.validate();
82
- //should have an error
83
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
84
- });
85
- it('shows expected parameter range in error message', () => {
86
- program.setFile('source/file.brs', `
87
- sub a(age, name="Bob")
88
- end sub
89
- sub b()
90
- a()
91
- end sub
92
- `);
93
- program.validate();
94
- //should have an error
95
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
96
- DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount('1-2', 0)
97
- ]);
98
- });
99
- it('handles expressions as arguments to a function', () => {
100
- program.setFile('source/file.brs', `
101
- sub a(age, name="Bob")
102
- end sub
103
- sub b()
104
- a("cat" + "dog" + "mouse")
105
- end sub
106
- `);
107
- program.validate();
108
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
109
- });
110
- it('Catches extra arguments for expressions as arguments to a function', () => {
111
- program.setFile('source/file.brs', `
112
- sub a(age)
113
- end sub
114
- sub b()
115
- a(m.lib.movies[0], 1)
116
- end sub
117
- `);
118
- program.validate();
119
- //should have an error
120
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
121
- DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 2)
122
- ]);
123
- });
124
- it('allows any number of parameters in a function used as an argument', () => {
125
- program.setFile('source/file.brs', `
126
- sub tryManyParams(someFunc as function)
127
- someFunc(1, 2, "hello", "world")
128
- end sub
129
- `);
130
- program.validate();
131
- //should have no errors
132
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
133
- });
134
- it('checks for at least the number of non-optional args on variadic (callFunc) functions', () => {
135
- program.setFile('components/Widget.xml', (0, testHelpers_spec_1.trim) `
136
- <?xml version="1.0" encoding="utf-8" ?>
137
- <component name="Widget" extends="Group">
138
- <script uri="Widget.brs"/>
139
- <interface>
140
- <function name="someFunc" />
141
- </interface>
142
- </component>
143
- `);
144
- program.setFile('components/Widget.brs', `
145
- sub someFunc(input as object)
146
- print input
147
- end sub
148
- `);
149
- program.setFile('source/util.brs', `
150
- sub useCallFunc(input as roSGNodeWidget)
151
- input.callFunc()
152
- end sub
153
- `);
154
- program.validate();
155
- //should have an error
156
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
157
- DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount('1-32', 0)
158
- ]);
159
- });
160
- it('any number number of args on variadic (callFunc) functions', () => {
161
- program.setFile('components/Widget.xml', (0, testHelpers_spec_1.trim) `
162
- <?xml version="1.0" encoding="utf-8" ?>
163
- <component name="Widget" extends="Group">
164
- <script uri="Widget.brs"/>
165
- <interface>
166
- <function name="someFunc" />
167
- </interface>
168
- </component>
169
- `);
170
- program.setFile('components/Widget.brs', `
171
- sub someFunc(input as object)
172
- print input
173
- end sub
174
- `);
175
- program.setFile('source/util.brs', `
176
- sub useCallFunc(input as roSGNodeWidget)
177
- input.callFunc("someFunc", 1, 2, 3, {})
178
- end sub
179
- `);
180
- program.validate();
181
- //TODO: do a better job of handling callFunc() invocations!
182
- //should have an error
183
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
184
- });
185
- });
186
- describe('argumentTypeMismatch', () => {
187
- it('param `as object` supports all known types', () => {
188
- program.setFile('source/file.bs', `
189
- sub main()
190
- consoleLog(Direction.up)
191
- consoleLog(true)
192
- consoleLog(main)
193
- consoleLog(1.2)
194
- consoleLog({} as Video)
195
- consoleLog("test")
196
- end sub
197
-
198
- sub consoleLog(thing as object)
199
- print thing
200
- end sub
201
-
202
- interface Video
203
- url as string
204
- end interface
205
- enum Direction
206
- up = "up"
207
- down = "down"
208
- end enum
209
- `);
210
- program.validate();
211
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
212
- });
213
- it('`as object` var can be passed to various param types', () => {
214
- program.setFile('source/file.bs', `
215
- sub main()
216
- obj = {} as object
217
-
218
- printBoolean(obj)
219
- printClass(obj)
220
- printDouble(obj)
221
- printEnum(obj)
222
- printFloat(obj)
223
- printFunction(obj)
224
- printInteger(obj)
225
- printInterface(obj)
226
- printLongInteger(obj)
227
- printString(obj)
228
- end sub
229
-
230
- sub printBoolean(value as boolean)
231
- print value
232
- end sub
233
-
234
- class Person
235
- name as string
236
- end class
237
-
238
- sub printClass(value as Person)
239
- print value
240
- end sub
241
-
242
- sub printDouble(value as double)
243
- print value
244
- end sub
245
-
246
- enum Direction
247
- up = "up"
248
- end enum
249
-
250
- sub printEnum(value as Direction)
251
- print value
252
- end sub
253
-
254
- sub printFloat(value as float)
255
- print value
256
- end sub
257
-
258
- sub printFunction(value as function)
259
- print value
260
- print value(1)
261
- end sub
262
-
263
- interface Video
264
- url as string
265
- end interface
266
-
267
- sub printInterface(value as Video)
268
- print value
269
- end sub
270
-
271
- sub printInteger(value as integer)
272
- print value
273
- end sub
274
-
275
- sub printLongInteger(value as LongInteger)
276
- print value
277
- end sub
278
-
279
- sub printString(value as string)
280
- print value
281
- end sub
282
- `);
283
- program.validate();
284
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
285
- });
286
- it('treats string enums as strings when assigned to string vars', () => {
287
- program.setFile('source/file.bs', `
288
- sub main()
289
- printDirection(Direction.up)
290
- end sub
291
-
292
- sub printDirection(theDirection as string)
293
- print theDirection
294
- end sub
295
-
296
- enum Direction
297
- up = "up"
298
- down = "down"
299
- end enum
300
- `);
301
- program.validate();
302
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
303
- });
304
- it('does not treat strings as a string enum', () => {
305
- program.setFile('source/file.bs', `
306
- sub main()
307
- printDirection("up")
308
- end sub
309
-
310
- sub printDirection(theDirection as Direction)
311
- print theDirection
312
- end sub
313
-
314
- enum Direction
315
- up = "up"
316
- down = "down"
317
- end enum
318
-
319
- `);
320
- program.validate();
321
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
322
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('string', 'Direction').message
323
- ]);
324
- });
325
- it('supports passing enum type as enum type', () => {
326
- program.setFile('source/file.bs', `
327
- sub test(theDirection as Direction)
328
- printDirection(theDirection)
329
- end sub
330
-
331
- sub printDirection(theDirection as Direction)
332
- print theDirection
333
- end sub
334
-
335
- enum Direction
336
- up = "up"
337
- down = "down"
338
- end enum
339
- `);
340
- program.validate();
341
- (0, testHelpers_spec_1.expectDiagnostics)(program, []);
342
- });
343
- it('Catches argument type mismatches on function calls', () => {
344
- program.setFile('source/file.brs', `
345
- sub a(age as integer)
346
- end sub
347
- sub b()
348
- a("hello")
349
- end sub
350
- `);
351
- program.validate();
352
- //should have an error
353
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message)).to.include(DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('string', 'integer').message);
354
- });
355
- it('Catches argument type mismatches on function calls for functions defined in another file', () => {
356
- program.setFile('source/file.brs', `
357
- sub a(age as integer)
358
- end sub
359
- `);
360
- program.setFile('source/file2.brs', `
361
- sub b()
362
- a("hello")
363
- foo = "foo"
364
- a(foo)
365
- end sub
366
- `);
367
- program.validate();
368
- //should have an error
369
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message)).to.include(DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('string', 'integer').message);
370
- });
371
- it('catches argument type mismatches on function calls within namespaces', () => {
372
- program.setFile('source/file.bs', `
373
- namespace Name.Space
374
- sub a(param as integer)
375
- print param
376
- end sub
377
-
378
- sub b()
379
- a("hello")
380
- foo = "foo"
381
- a(foo)
382
- end sub
383
- end namespace
384
- `);
385
- program.validate();
386
- //should have an error
387
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message)).to.include(DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('string', 'integer').message);
388
- });
389
- it('catches argument type mismatches on function calls as arguments', () => {
390
- program.setFile('source/file1.bs', `
391
- sub a(param as string)
392
- print param
393
- end sub
394
-
395
- function getNum() as integer
396
- return 1
397
- end function
398
-
399
- sub b()
400
- a(getNum())
401
- end sub
402
- `);
403
- program.validate();
404
- //should have an error
405
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message)).to.include(DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('integer', 'string').message);
406
- });
407
- it('catches argument type mismatches on function calls within namespaces across files', () => {
408
- program.setFile('source/file1.bs', `
409
- namespace Name.Space
410
- function getNum() as integer
411
- return 1
412
- end function
413
-
414
- function getStr() as string
415
- return "hello"
416
- end function
417
- end namespace
418
- `);
419
- program.setFile('source/file2.bs', `
420
- namespace Name.Space
421
- sub needsInt(param as integer)
422
- print param
423
- end sub
424
-
425
- sub someFunc()
426
- needsInt(getStr())
427
- needsInt(getNum())
428
- end sub
429
- end namespace
430
- `);
431
- program.validate();
432
- //should have an error
433
- (0, chai_1.expect)(program.getDiagnostics().length).to.equal(1);
434
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message)).to.include(DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('string', 'integer').message);
435
- });
436
- it('correctly validates correct parameters that are class members', () => {
437
- program.setFile('source/main.bs', `
438
- class PiHolder
439
- pi = 3.14
440
- function getPi() as float
441
- return m.pi
442
- end function
443
- end class
444
-
445
- sub takesFloat(fl as float)
446
- end sub
447
-
448
- sub someFunc()
449
- holder = new PiHolder()
450
- takesFloat(holder.pi)
451
- takesFloat(holder.getPI())
452
- end sub`);
453
- program.validate();
454
- //should have no error
455
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
456
- });
457
- it('correctly validates wrong parameters that are class members', () => {
458
- program.setFile('source/main.bs', `
459
- class PiHolder
460
- pi = 3.14
461
- name = "hello"
462
- function getPi() as float
463
- return m.pi
464
- end function
465
- end class
466
-
467
- sub takesFloat(fl as float)
468
- end sub
469
-
470
- sub someFunc()
471
- holder = new PiHolder()
472
- takesFloat(holder.name)
473
- takesFloat(Str(holder.getPI()))
474
- end sub`);
475
- program.validate();
476
- //should have error: holder.name is string
477
- (0, chai_1.expect)(program.getDiagnostics().length).to.equal(2);
478
- (0, chai_1.expect)(program.getDiagnostics().map(x => x.message)).to.include(DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('string', 'float').message);
479
- });
480
- it('correctly validates correct parameters that are interface members', () => {
481
- program.setFile('source/main.bs', `
482
- interface IPerson
483
- height as float
484
- name as string
485
- function getWeight() as float
486
- function getAddress() as string
487
- end interface
488
-
489
- sub takesFloat(fl as float)
490
- end sub
491
-
492
- sub someFunc(person as IPerson)
493
- takesFloat(person.height)
494
- takesFloat(person.getWeight())
495
- end sub`);
496
- program.validate();
497
- //should have no error
498
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
499
- });
500
- it('correctly validates wrong parameters that are interface members', () => {
501
- program.setFile('source/main.bs', `
502
- interface IPerson
503
- isAlive as boolean
504
- function getAddress() as string
505
- end interface
506
-
507
- sub takesFloat(fl as float)
508
- end sub
509
-
510
- sub someFunc(person as IPerson)
511
- takesFloat(person.isAlive)
512
- takesFloat(person.getAddress())
513
- end sub
514
- `);
515
- program.validate();
516
- //should have 2 errors: person.name is string (not float) and person.getAddress() is object (not float)
517
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
518
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('boolean', 'float').message,
519
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('string', 'float').message
520
- ]);
521
- });
522
- it('`as object` param allows all types', () => {
523
- program.setFile('source/main.bs', `
524
- sub takesObject(obj as Object)
525
- end sub
526
-
527
- sub main()
528
- takesObject(true)
529
- takesObject(1)
530
- takesObject(1.2)
531
- takesObject(1.2#)
532
- takesObject("text")
533
- takesObject({})
534
- takesObject([])
535
- end sub
536
- `);
537
- program.validate();
538
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
539
- });
540
- it('allows conversions for arguments', () => {
541
- program.setFile('source/main.bs', `
542
- sub takesFloat(fl as float)
543
- end sub
544
-
545
- sub someFunc()
546
- takesFloat(1)
547
- end sub`);
548
- program.validate();
549
- //should have no error
550
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
551
- });
552
- it('allows subclasses as arguments', () => {
553
- program.setFile('source/main.bs', `
554
-
555
- class Animal
556
- end class
557
-
558
- class Dog extends Animal
559
- end class
560
-
561
- class Retriever extends Dog
562
- end class
563
-
564
- class Lab extends Retriever
565
- end class
566
-
567
- sub takesAnimal(thing as Animal)
568
- end sub
569
-
570
- sub someFunc()
571
- fido = new Lab()
572
- takesAnimal(fido)
573
- end sub`);
574
- program.validate();
575
- //should have no error
576
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
577
- });
578
- it('allows subclasses from namespaces as arguments', () => {
579
- program.setFile('source/main.bs', `
580
-
581
- class Outside
582
- end class
583
-
584
- class ChildOutExtendsInside extends NS.Inside
585
- end class
586
-
587
- namespace NS
588
- class Inside
589
- end class
590
-
591
- class ChildInExtendsOutside extends Outside
592
- end class
593
-
594
- class ChildInExtendsInside extends Inside
595
- sub methodTakesInside(i as Inside)
596
- end sub
597
- end class
598
-
599
- sub takesInside(klass as Inside)
600
- end sub
601
-
602
- sub testFuncInNamespace()
603
- takesOutside(new Outside())
604
- takesOutside(new NS.ChildInExtendsOutside())
605
-
606
- ' These call NS.takesInside
607
- takesInside(new NS.Inside())
608
- takesInside(new Inside())
609
- takesInside(new NS.ChildInExtendsInside())
610
- takesInside(new ChildInExtendsInside())
611
- takesInside(new ChildOutExtendsInside())
612
-
613
- child = new ChildInExtendsInside()
614
- child.methodTakesInside(new Inside())
615
- child.methodTakesInside(new ChildInExtendsInside())
616
- child.methodTakesInside(new ChildOutExtendsInside())
617
- end sub
618
-
619
- end namespace
620
-
621
- sub takesOutside(klass as Outside)
622
- end sub
623
-
624
- sub takesInside(klass as NS.Inside)
625
- end sub
626
-
627
- sub testFunc()
628
- takesOutside(new Outside())
629
- takesOutside(new NS.ChildInExtendsOutside())
630
-
631
- takesInside(new NS.Inside())
632
- takesInside(new NS.ChildInExtendsInside())
633
- takesInside(new ChildOutExtendsInside())
634
-
635
- NS.takesInside(new NS.Inside())
636
- NS.takesInside(new NS.ChildInExtendsInside())
637
- NS.takesInside(new ChildOutExtendsInside())
638
-
639
- child = new NS.ChildInExtendsInside()
640
- child.methodTakesInside(new NS.Inside())
641
- child.methodTakesInside(new NS.ChildInExtendsInside())
642
- child.methodTakesInside(new ChildOutExtendsInside())
643
- end sub`);
644
- program.validate();
645
- //should have no error
646
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
647
- });
648
- it('respects union types', () => {
649
- program.setFile('source/main.bs', `
650
- sub takesStringOrKlass(p as string or Klass)
651
- end sub
652
-
653
- class Klass
654
- end class
655
-
656
- sub someFunc()
657
- myKlass = new Klass()
658
- takesStringOrKlass("test")
659
- takesStringOrKlass(myKlass)
660
- takesStringOrKlass(1)
661
- end sub`);
662
- program.validate();
663
- //should have error when passed an integer
664
- (0, chai_1.expect)(program.getDiagnostics().length).to.equal(1);
665
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
666
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('integer', 'string or Klass').message
667
- ]);
668
- });
669
- it('validates functions assigned to variables', () => {
670
- program.setFile('source/main.bs', `
671
- sub someFunc()
672
- myFunc = function(i as integer, s as string)
673
- print i+1
674
- print s.len()
675
- end function
676
- myFunc("hello", 2)
677
- end sub`);
678
- program.validate();
679
- //should have error when passed incorrect types
680
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
681
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('string', 'integer').message,
682
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('integer', 'string').message
683
- ]);
684
- });
685
- it('allows any parameter types in a function passed as an argument', () => {
686
- program.setFile('source/file.brs', `
687
- function getStrLength(name as string) as integer
688
- return len(name)
689
- end function
690
-
691
- sub tryManyParams(someFunc as function)
692
- print someFunc(1, 2, "hello", "world")
693
- end sub
694
-
695
- sub test()
696
- tryManyParams(getStrLength)
697
- end sub
698
- `);
699
- program.validate();
700
- //should have no errors
701
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
702
- });
703
- it('allows a inline function as an argument of type function', () => {
704
- program.setFile('source/file.brs', `
705
- sub tryManyParams(someFunc as function)
706
- print someFunc(1, 2, "hello", "world")
707
- end sub
708
-
709
- sub test()
710
- tryManyParams(sub (i as integer)
711
- print i
712
- end sub)
713
- end sub
714
- `);
715
- program.validate();
716
- //should have no errors
717
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
718
- });
719
- it('validates when a non-function is used as an argument expecting a function', () => {
720
- program.setFile('source/file.brs', `
721
- sub tryManyParams(someFunc as function)
722
- print someFunc(1, 2, "hello", "world")
723
- end sub
724
-
725
- sub test()
726
- notAFunction = 3.14
727
- tryManyParams(notAFunction)
728
- end sub
729
- `);
730
- program.validate();
731
- //should have an error that the argument is not a function
732
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
733
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('float', 'function').message
734
- ]);
735
- });
736
- it('allows any variable to passed as argument to an untyped param with default type invalid', () => {
737
- program.setFile('source/util.brs', `
738
- sub doSomething(x = invalid)
739
- print x
740
- end sub
741
-
742
- sub tests()
743
- doSomething(1)
744
- doSomething(1.1)
745
- doSomething("Hello")
746
- doSomething(true)
747
- doSomething({test: true})
748
- end sub
749
- `);
750
- program.validate();
751
- //should have no errors
752
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
753
- });
754
- it('allows calling future function and save to same variable', () => {
755
- program.setFile('source/util.brs', `
756
- function getSomeInt() as integer
757
- numVal = getUntypedNum()
758
- numVal = cInt(numVal)
759
- return numVal
760
- end function
761
-
762
- function getUntypedNum()
763
- return 1
764
- end function
765
- `);
766
- program.validate();
767
- //should have no errors
768
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
769
- });
770
- it('allows union types of all compatible types as arg', () => {
771
- program.setFile('source/util.bs', `
772
- sub printIntNum(num as float or double or integer)
773
- print cInt(num)
774
- end sub
775
- `);
776
- program.validate();
777
- //should have no errors
778
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
779
- });
780
- it('allows function calls of built-in members of primitives', () => {
781
- program.setFile('source/util.brs', `
782
- sub doSomething()
783
- myStr = "Hello World"
784
- myStr = myStr.replace("World", "You")
785
- print myStr
786
- end sub
787
- `);
788
- program.validate();
789
- //should have no errors
790
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
791
- });
792
- it('validates union types of all compatible types as arg - when some do not work', () => {
793
- program.setFile('source/util.bs', `
794
- sub printIntNum(maybeNum as float or string)
795
- print cInt(maybeNum)
796
- end sub
797
- `);
798
- program.validate();
799
- //should have no errors
800
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
801
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('float or string', 'float').message
802
- ]);
803
- });
804
- it('validates function calls of built-in members of primitives', () => {
805
- program.setFile('source/util.brs', `
806
- sub doSomething()
807
- myStr = "Hello World"
808
- notAString = 3.14
809
- myStr = myStr.replace("World", notAString)
810
- print myStr
811
- end sub
812
- `);
813
- program.validate();
814
- //should have error - 2nd param should be a string, not a float
815
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
816
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('float', 'string').message
817
- ]);
818
- });
819
- it('validates method calls of classes', () => {
820
- program.setFile('source/util.bs', `
821
- class Klass
822
- sub test(input as string)
823
- end sub
824
- end class
825
-
826
- sub doSomething()
827
- k = new Klass()
828
- k.test(3.14)
829
- end sub
830
- `);
831
- program.validate();
832
- //should have error - param should be a string, not a float
833
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
834
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('float', 'string').message
835
- ]);
836
- });
837
- it('validates inside method calls of classes', () => {
838
- program.setFile('source/util.bs', `
839
- class Klass
840
- sub test(input as string)
841
- end sub
842
-
843
- sub otherTest()
844
- m.test(3.14)
845
- end sub
846
- end class
847
- `);
848
- program.validate();
849
- //should have error - param should be a string, not a float
850
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
851
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('float', 'string').message
852
- ]);
853
- });
854
- it('validates calls of a constructor', () => {
855
- program.setFile('source/util.bs', `
856
- class Klass
857
- sub new(name as string)
858
- end sub
859
- end class
860
-
861
- sub createKlass()
862
- k = new Klass(3.14)
863
- end sub
864
- `);
865
- program.validate();
866
- //should have error - param should be a string, not a float
867
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
868
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('float', 'string').message
869
- ]);
870
- });
871
- it('validates super calls in a constructor', () => {
872
- program.setFile('source/util.bs', `
873
- class Klass
874
- sub new(name as string)
875
- end sub
876
- end class
877
-
878
- class SubKlass extends Klass
879
- sub new()
880
- super(3.14)
881
- end sub
882
- end class
883
- `);
884
- program.validate();
885
- //should have error - param should be a string, not a float
886
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
887
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('float', 'string').message
888
- ]);
889
- });
890
- it('validates super calls in a class methods', () => {
891
- program.setFile('source/util.bs', `
892
- class Klass
893
- sub test(name as string)
894
- end sub
895
- end class
896
-
897
- class SubKlass extends Klass
898
- sub test2()
899
- super.test(3.14)
900
- end sub
901
- end class
902
- `);
903
- program.validate();
904
- //should have error - param should be a string, not a float
905
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
906
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('float', 'string').message
907
- ]);
908
- });
909
- it('validates a function passed as an arg', () => {
910
- program.setFile('source/util.bs', `
911
- sub foo()
912
- getPi = function()
913
- return 3.14
914
- end function
915
- bar(getPi)
916
- end sub
917
-
918
-
919
- sub bar(num as integer)
920
- print num
921
- end sub
922
- `);
923
- program.validate();
924
- //should have error - param should be a string, not a float
925
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
926
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('function () as dynamic', 'integer').message
927
- ]);
928
- });
929
- it('allows AAs that match an interface to be passed as args', () => {
930
- program.setFile('source/util.bs', `
931
- sub doStuff()
932
- takesMyIface({beta: "hello", charlie: "world"})
933
- end sub
934
-
935
- sub takesMyIface(iFace as MyIFace)
936
- end sub
937
-
938
- interface MyIFace
939
- beta as string
940
- charlie as string
941
- end interface
942
- `);
943
- program.validate();
944
- //should have error
945
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
946
- });
947
- it('validates empty AAs that are passed as args to param expecting interface', () => {
948
- program.setFile('source/util.bs', `
949
- sub doStuff()
950
- takesMyIface({})
951
- end sub
952
-
953
- sub takesMyIface(iFace as MyIFace)
954
- end sub
955
-
956
- interface MyIFace
957
- beta as string
958
- charlie as string
959
- end interface
960
- `);
961
- program.validate();
962
- //should have error
963
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
964
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('roAssociativeArray', 'MyIFace', {
965
- missingFields: [{ name: 'beta', expectedType: StringType_1.StringType.instance }, { name: 'charlie', expectedType: StringType_1.StringType.instance }]
966
- }).message
967
- ]);
968
- });
969
- it('includes data on missing fields', () => {
970
- program.setFile('source/util.bs', `
971
- sub doStuff()
972
- takesMyIface({charlie: "hello"})
973
- end sub
974
-
975
- sub takesMyIface(iFace as MyIFace)
976
- end sub
977
-
978
- interface MyIFace
979
- beta as string
980
- charlie as integer
981
- end interface
982
- `);
983
- program.validate();
984
- //should have error
985
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
986
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('roAssociativeArray', 'MyIFace', {
987
- missingFields: [{ name: 'beta', expectedType: StringType_1.StringType.instance }],
988
- fieldMismatches: [{ name: 'charlie', expectedType: IntegerType_1.IntegerType.instance, actualType: StringType_1.StringType.instance }]
989
- }).message
990
- ]);
991
- //The aa should have 'beta' and 'charlie' properties of type string and integer
992
- const diagnostics = program.getDiagnostics();
993
- (0, chai_1.expect)(diagnostics.length).to.eq(1);
994
- const data = diagnostics[0].data;
995
- (0, chai_1.expect)(data.missingFields.length).to.eq(1);
996
- (0, chai_1.expect)(data.missingFields[0].name).to.eq('beta');
997
- (0, testHelpers_spec_1.expectTypeToBe)(data.missingFields[0].expectedType, StringType_1.StringType);
998
- (0, chai_1.expect)(data.fieldMismatches.length).to.eq(1);
999
- (0, chai_1.expect)(data.fieldMismatches[0].name).to.eq('charlie');
1000
- (0, testHelpers_spec_1.expectTypeToBe)(data.fieldMismatches[0].expectedType, IntegerType_1.IntegerType);
1001
- (0, testHelpers_spec_1.expectTypeToBe)(data.fieldMismatches[0].actualType, StringType_1.StringType);
1002
- });
1003
- it('allows interfaces that have a superset of properties', () => {
1004
- program.setFile('source/util.bs', `
1005
- sub doStuff()
1006
- takesMyIface({alpha: true, beta: "hello", charlie: 1})
1007
- end sub
1008
-
1009
- sub takesMyIface(iFace as MyIFace)
1010
- end sub
1011
-
1012
- interface MyIFace
1013
- beta as string
1014
- charlie as integer
1015
- end interface
1016
- `);
1017
- program.validate();
1018
- //should have no errors
1019
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1020
- });
1021
- it('allows interfaces that have a superset of properties', () => {
1022
- program.setFile('source/util.bs', `
1023
- sub doStuff(otherFace as MyOtherFace)
1024
- takesMyIface(otherFace)
1025
- end sub
1026
-
1027
- sub takesMyIface(iFace as MyIFace)
1028
- end sub
1029
-
1030
- interface MyIFace
1031
- beta as string
1032
- charlie as integer
1033
- end interface
1034
-
1035
- interface MyOtherFace
1036
- alpha as boolean
1037
- beta as string
1038
- charlie as integer
1039
- end interface
1040
- `);
1041
- program.validate();
1042
- //should have no errors
1043
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1044
- });
1045
- it('includes data on missing fields', () => {
1046
- program.setFile('source/util.bs', `
1047
- sub doStuff()
1048
- takesMyIface({charlie: "hello"})
1049
- end sub
1050
-
1051
- sub takesMyIface(iFace as MyIFace)
1052
- end sub
1053
-
1054
- interface MyIFace
1055
- beta as string
1056
- charlie as integer
1057
- end interface
1058
- `);
1059
- program.validate();
1060
- //should have error
1061
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1062
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('roAssociativeArray', 'MyIFace', {
1063
- missingFields: [{ name: 'beta', expectedType: StringType_1.StringType.instance }],
1064
- fieldMismatches: [{ name: 'charlie', expectedType: IntegerType_1.IntegerType.instance, actualType: StringType_1.StringType.instance }]
1065
- }).message
1066
- ]);
1067
- //The aa should have 'beta' and 'charlie' properties of type string and integer
1068
- const diagnostics = program.getDiagnostics();
1069
- (0, chai_1.expect)(diagnostics.length).to.eq(1);
1070
- const data = diagnostics[0].data;
1071
- (0, chai_1.expect)(data.missingFields.length).to.eq(1);
1072
- (0, chai_1.expect)(data.missingFields[0].name).to.eq('beta');
1073
- (0, testHelpers_spec_1.expectTypeToBe)(data.missingFields[0].expectedType, StringType_1.StringType);
1074
- (0, chai_1.expect)(data.fieldMismatches.length).to.eq(1);
1075
- (0, chai_1.expect)(data.fieldMismatches[0].name).to.eq('charlie');
1076
- (0, testHelpers_spec_1.expectTypeToBe)(data.fieldMismatches[0].expectedType, IntegerType_1.IntegerType);
1077
- (0, testHelpers_spec_1.expectTypeToBe)(data.fieldMismatches[0].actualType, StringType_1.StringType);
1078
- });
1079
- describe('array compatibility', () => {
1080
- it('accepts dynamic when assigning to a roArray', () => {
1081
- program.setFile('source/util.bs', `
1082
- sub takesArray(arr as roArray)
1083
- end sub
1084
-
1085
- sub doStuff(someArray)
1086
- takesArray(someArray)
1087
- end sub
1088
- `);
1089
- program.validate();
1090
- //should have no errors
1091
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1092
- });
1093
- it('accepts roArray when assigning to a roArray', () => {
1094
- program.setFile('source/util.bs', `
1095
- sub takesArray(arr as roArray)
1096
- end sub
1097
-
1098
- sub doStuff(someArray as roArray)
1099
- takesArray(someArray)
1100
- end sub
1101
- `);
1102
- program.validate();
1103
- //should have no errors
1104
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1105
- });
1106
- it('accepts typed arrays when assigning to a roArray', () => {
1107
- program.setFile('source/util.bs', `
1108
- sub takesArray(arr as roArray)
1109
- end sub
1110
-
1111
- sub doStuff(someArray as dynamic[])
1112
- takesArray(someArray)
1113
- end sub
1114
- `);
1115
- program.validate();
1116
- //should have no errors
1117
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1118
- });
1119
- it('accepts roArray when assigning to dynamic[]', () => {
1120
- program.setFile('source/util.bs', `
1121
- sub takesArray(arr as dynamic[])
1122
- end sub
1123
-
1124
- sub doStuff(someArray as roArray)
1125
- takesArray(someArray)
1126
- end sub
1127
- `);
1128
- program.validate();
1129
- //should have no errors
1130
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1131
- });
1132
- it('accepts roArray when assigning to typed array', () => {
1133
- program.setFile('source/util.bs', `
1134
- sub takesArray(arr as string[])
1135
- end sub
1136
-
1137
- sub doStuff(someArray as roArray)
1138
- takesArray(someArray)
1139
- end sub
1140
- `);
1141
- program.validate();
1142
- //should have no errors
1143
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1144
- });
1145
- it('validates when typed array types are incompatible', () => {
1146
- program.setFile('source/util.bs', `
1147
- sub takesArray(arr as string[])
1148
- end sub
1149
-
1150
- sub doStuff(someArray as integer[])
1151
- takesArray(someArray)
1152
- end sub
1153
- `);
1154
- program.validate();
1155
- //should have errors
1156
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1157
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('Array<integer>', 'Array<string>').message
1158
- ]);
1159
- });
1160
- it('accepts when typed array types are compatible', () => {
1161
- program.setFile('source/util.bs', `
1162
- sub takesArray(arr as float[])
1163
- end sub
1164
-
1165
- sub doStuff(someArray as integer[])
1166
- takesArray(someArray)
1167
- end sub
1168
- `);
1169
- program.validate();
1170
- //should have no errors
1171
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1172
- });
1173
- });
1174
- describe('interface with optional properties', () => {
1175
- it('allows using interfaces with optional props', () => {
1176
- program.setFile('source/util.bs', `
1177
- function takesIFace(iface as MyIFace) as string
1178
- if invalid <> iface.name
1179
- return iface.name
1180
- else if invalid <> iface.data
1181
- return FormatJson(iface.data)
1182
- end if
1183
- return "no"
1184
- end function
1185
-
1186
- sub doStuff(iface as MyIFace)
1187
- print takesIFace(iface)
1188
- end sub
1189
-
1190
- interface MyIFace
1191
- optional name as string
1192
- optional data
1193
- end interface
1194
- `);
1195
- program.validate();
1196
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1197
- });
1198
- it('allows using passing AAs with missing optional properties', () => {
1199
- program.setFile('source/util.bs', `
1200
- function takesIFace(iface as MyIFace) as string
1201
- if invalid <> iface.name
1202
- return iface.name
1203
- else if invalid <> iface.data
1204
- return FormatJson(iface.data)
1205
- end if
1206
- return "no"
1207
- end function
1208
-
1209
- sub doStuff(iface as MyIFace)
1210
- print takesIFace({name: "Hello"})
1211
- end sub
1212
-
1213
- interface MyIFace
1214
- optional name as string
1215
- optional data
1216
- end interface
1217
- `);
1218
- program.validate();
1219
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1220
- });
1221
- it('disallows using AAs with bad types for optional properties', () => {
1222
- program.setFile('source/util.bs', `
1223
- function takesIFace(iface as MyIFace) as string
1224
- if invalid <> iface.name
1225
- return iface.name
1226
- else if invalid <> iface.data
1227
- return FormatJson(iface.data)
1228
- end if
1229
- return "no"
1230
- end function
1231
-
1232
- sub doStuff(iface as MyIFace)
1233
- print takesIFace({name: 3.14})
1234
- end sub
1235
-
1236
- interface MyIFace
1237
- optional name as string
1238
- optional data
1239
- end interface
1240
- `);
1241
- program.validate();
1242
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1243
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('roAssociativeArray', 'MyIFace', {
1244
- fieldMismatches: [{ name: 'name', expectedType: StringType_1.StringType.instance, actualType: types_1.FloatType.instance }]
1245
- }).message
1246
- ]);
1247
- });
1248
- it('disallows passing classes with bad types for optional properties', () => {
1249
- program.setFile('source/util.bs', `
1250
- function takesIFace(iface as MyIFace) as string
1251
- if invalid <> iface.name
1252
- return iface.name
1253
- else if invalid <> iface.data
1254
- return FormatJson(iface.data)
1255
- end if
1256
- return "no"
1257
- end function
1258
-
1259
- sub doStuff(iface as MyIFace)
1260
- k = new MyKlass()
1261
- print takesIFace(k)
1262
- end sub
1263
-
1264
- interface MyIFace
1265
- optional name as string
1266
- optional data
1267
- end interface
1268
-
1269
- class MyKlass
1270
- name as float
1271
- end class
1272
- `);
1273
- program.validate();
1274
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1275
- DiagnosticMessages_1.DiagnosticMessages.argumentTypeMismatch('MyKlass', 'MyIFace', {
1276
- fieldMismatches: [{ name: 'name', expectedType: StringType_1.StringType.instance, actualType: types_1.FloatType.instance }]
1277
- }).message
1278
- ]);
1279
- });
1280
- it('allows passing classes as args for interfaces with optional properties', () => {
1281
- program.setFile('source/util.bs', `
1282
- function takesIFace(iface as MyIFace) as string
1283
- if invalid <> iface.name
1284
- return iface.name
1285
- else if invalid <> iface.data
1286
- return FormatJson(iface.data)
1287
- end if
1288
- return "no"
1289
- end function
1290
-
1291
- sub doStuff(iface as MyIFace)
1292
- k = new MyKlass()
1293
- k2 = new MyKlass2()
1294
- print takesIFace(k)
1295
- print takesIFace(k2)
1296
- end sub
1297
-
1298
- interface MyIFace
1299
- optional name as string
1300
- optional data
1301
- end interface
1302
-
1303
- class MyKlass
1304
- data = {}
1305
- end class
1306
-
1307
- class MyKlass2
1308
- data = "test"
1309
- end class
1310
- `);
1311
- program.validate();
1312
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1313
- });
1314
- });
1315
- });
1316
- describe('cannotFindName', () => {
1317
- it('finds variables from assignments from member functions of primitive types', () => {
1318
- program.setFile('source/util.brs', `
1319
- function lcaseTrim(str)
1320
- trimmedLowerStr = lcase(str).trim()
1321
- print trimmedLowerStr
1322
- end function
1323
- `);
1324
- program.validate();
1325
- //should have no errors
1326
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1327
- });
1328
- it('validates when lhs of compound assignment does not exist', () => {
1329
- program.setFile('source/util.brs', `
1330
- sub main()
1331
- expected += chr(10) + " version=""2.0"""
1332
- end sub
1333
- `);
1334
- program.validate();
1335
- //should have error - cannot find "expected"
1336
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1337
- DiagnosticMessages_1.DiagnosticMessages.cannotFindName('expected').message
1338
- ]);
1339
- });
1340
- it('does not have a diagnostic for using a variable the result of an assignment with unresolved value', () => {
1341
- program.setFile('source/util.bs', `
1342
- sub doStuff()
1343
- myValue = UndeclaredValue
1344
- if myValue > 0
1345
- print "hello"
1346
- end if
1347
- end sub
1348
- `);
1349
- program.validate();
1350
- //should have only 1 error - cannot find "UndeclaredValue"
1351
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1352
- DiagnosticMessages_1.DiagnosticMessages.cannotFindName('UndeclaredValue').message
1353
- ]);
1354
- });
1355
- });
1356
- describe('returnTypeMismatch', () => {
1357
- it('finds when a function returns a type that is not what was declared', () => {
1358
- program.setFile('source/util.bs', `
1359
- function getPi() as float
1360
- return "apple" ' get it?
1361
- end function
1362
- `);
1363
- program.validate();
1364
- //should have error - return value should be a float, not a string
1365
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1366
- DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('string', 'float').message
1367
- ]);
1368
- });
1369
- it('finds all return statements that do not match', () => {
1370
- program.setFile('source/util.bs', `
1371
- function getPi(kind as integer) as float
1372
- if kind = 1
1373
- return "apple"
1374
- else if kind = 2
1375
- return false
1376
- else if kind = 3
1377
- return new Pie("lemon")
1378
- end if
1379
- return 3.14
1380
- end function
1381
-
1382
- class Pie
1383
- kind as string
1384
- sub new(kind as string)
1385
- m.kind = kind
1386
- end sub
1387
- end class
1388
- `);
1389
- program.validate();
1390
- //should have error - return value should be a float, not whatever else
1391
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1392
- DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('string', 'float').message,
1393
- DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('boolean', 'float').message,
1394
- DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('Pie', 'float').message
1395
- ]);
1396
- });
1397
- it('allows returning compatible types', () => {
1398
- program.setFile('source/util.bs', `
1399
- function getPi() as float
1400
- return 3 ' integers are compatible with floats
1401
- end function
1402
-
1403
- function getPie() as Pie
1404
- return new Tart("lemon") ' Tart extends Pie
1405
- end function
1406
-
1407
- class Pie
1408
- kind as string
1409
- sub new(kind as string)
1410
- m.kind = kind
1411
- end sub
1412
- end class
1413
-
1414
- class Tart extends Pie
1415
- size = "small"
1416
- end class
1417
- `);
1418
- program.validate();
1419
- //should have no errors
1420
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1421
- });
1422
- it('detects return types on void functions (subs)', () => {
1423
- program.setFile('source/util.bs', `
1424
- sub sayHello(name as string)
1425
- return "hello " + name ' return should be void in subs
1426
- end sub
1427
- `);
1428
- program.validate();
1429
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1430
- DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('string', 'void').message
1431
- ]);
1432
- });
1433
- it('detects return types on void functions', () => {
1434
- program.setFile('source/util.bs', `
1435
- function sayHello(name as string) as void
1436
- return "hello " + name ' return should be void in subs
1437
- end function
1438
- `);
1439
- program.validate();
1440
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1441
- DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('string', 'void').message
1442
- ]);
1443
- });
1444
- it('allows returning enums with the default type that matches the declared return type', () => {
1445
- program.setFile('source/util.bs', `
1446
- enum MyEnum
1447
- val1
1448
- val2
1449
- end enum
1450
-
1451
- function getInt() as integer
1452
- return MyEnum.val1
1453
- end function
1454
- `);
1455
- program.validate();
1456
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1457
- });
1458
- it('allows returning enums passed as a param with the default type that matches the declared return type', () => {
1459
- program.setFile('source/util.bs', `
1460
- enum MyEnum
1461
- val1
1462
- val2
1463
- end enum
1464
-
1465
- function getInt(enumVal as MyEnum) as integer
1466
- return enumVal
1467
- end function
1468
- `);
1469
- program.validate();
1470
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1471
- });
1472
- it('allows returning enums with the default type that matches the declared return type for string enums', () => {
1473
- program.setFile('source/util.bs', `
1474
- enum MyEnum
1475
- val1 = "hello"
1476
- val2 = "world"
1477
- end enum
1478
-
1479
- function getInt() as string
1480
- return MyEnum.val1
1481
- end function
1482
- `);
1483
- program.validate();
1484
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1485
- });
1486
- it('flags returning enums with the default type that does not matches the declared return type', () => {
1487
- program.setFile('source/util.bs', `
1488
- enum MyEnum
1489
- val1 = "hello"
1490
- val2 = "world"
1491
- end enum
1492
-
1493
- function getInt() as integer
1494
- return MyEnum.val1
1495
- end function
1496
- `);
1497
- program.validate();
1498
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1499
- DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('MyEnum', 'integer').message
1500
- ]);
1501
- });
1502
- it('flags returning enums passed as params with the default type that does not matches the declared return type', () => {
1503
- program.setFile('source/util.bs', `
1504
- enum MyEnum
1505
- val1 = "hello"
1506
- val2 = "world"
1507
- end enum
1508
-
1509
- function getInt(enumVal as MyEnum) as integer
1510
- return enumVal
1511
- end function
1512
- `);
1513
- program.validate();
1514
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1515
- DiagnosticMessages_1.DiagnosticMessages.returnTypeMismatch('MyEnum', 'integer').message
1516
- ]);
1517
- });
1518
- it('flags returning enums type', () => {
1519
- program.setFile('source/util.bs', `
1520
- enum MyEnum
1521
- val1 = "hello"
1522
- val2 = "world"
1523
- end enum
1524
-
1525
-
1526
- function getInt() as integer
1527
- return MyEnum
1528
- end function
1529
- `);
1530
- program.validate();
1531
- (0, chai_1.expect)(program.getDiagnostics().length).to.be.greaterThan(0);
1532
- });
1533
- it('allows returning an Enum', () => {
1534
- program.setFile('source/util.bs', `
1535
- enum MyEnum
1536
- val1 = "hello"
1537
- val2 = "world"
1538
- end enum
1539
-
1540
-
1541
- function getInt() as MyEnum
1542
- return MyEnum.val1
1543
- end function
1544
- `);
1545
- program.validate();
1546
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1547
- });
1548
- });
1549
- describe('assignmentTypeMismatch', () => {
1550
- it('finds when the type of the lhs is not compatible with the expected type', () => {
1551
- program.setFile('source/util.bs', `
1552
- sub doStuff(thing as iThing)
1553
- thing.name = 123
1554
- end sub
1555
-
1556
- interface iThing
1557
- name as string
1558
- end interface
1559
- `);
1560
- program.validate();
1561
- //should have error - assignment value should be a string, not a float
1562
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1563
- DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch('integer', 'string').message
1564
- ]);
1565
- });
1566
- it('allows setting a member with correct type that is a union type', () => {
1567
- program.setFile('source/util.bs', `
1568
- sub doStuff(thing as iThing)
1569
- thing.name = 123
1570
- end sub
1571
-
1572
- interface iThing
1573
- name as string or integer
1574
- end interface
1575
- `);
1576
- program.validate();
1577
- //should have no error - assignment value should be a string, not a float
1578
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1579
- });
1580
- it('finds when the rhs type is not compatible with the lhs, which is a union type', () => {
1581
- program.setFile('source/util.bs', `
1582
- sub doStuff(thing as iThing)
1583
- thing.name = false
1584
- end sub
1585
-
1586
- interface iThing
1587
- name as string or integer
1588
- end interface
1589
- `);
1590
- program.validate();
1591
- //should have error - assignment value should be a string or integer, not a boolean
1592
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1593
- DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch('boolean', 'string or integer').message
1594
- ]);
1595
- });
1596
- it('validates when trying to assign to a class method', () => {
1597
- program.setFile('source/util.bs', `
1598
- sub doStuff(myThing as Thing)
1599
- myThing.getPi = 3.14
1600
- end sub
1601
-
1602
- class Thing
1603
- function getPi() as float
1604
- return 3.14
1605
- end function
1606
- end class
1607
- `);
1608
- program.validate();
1609
- //should have error
1610
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1611
- DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch('float', 'function getPi() as float').message
1612
- ]);
1613
- });
1614
- it('allows adding new properties to a class (but why would you want to?)', () => {
1615
- program.setFile('source/util.bs', `
1616
- sub doStuff(myThing as Thing)
1617
- myThing.getPi = 3.14
1618
- end sub
1619
-
1620
- class Thing
1621
- end class
1622
- `);
1623
- program.validate();
1624
- //should have no errors
1625
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1626
- });
1627
- it('validates class constructors', () => {
1628
- program.setFile('source/util.bs', `
1629
- class Video
1630
- sub new(url as integer)
1631
- m.url = url 'this should be a compile error
1632
- end sub
1633
- public url as string
1634
- end class
1635
- `);
1636
- program.validate();
1637
- //should have errors
1638
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1639
- DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch('integer', 'string').message
1640
- ]);
1641
- });
1642
- it('validates when assigning to a sgNode', () => {
1643
- program.setFile('source/util.bs', `
1644
- sub setLabelText(label as roSGNodeLabel)
1645
- label.text = 1234
1646
- end sub
1647
-
1648
- `);
1649
- program.validate();
1650
- //should have errors
1651
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1652
- DiagnosticMessages_1.DiagnosticMessages.assignmentTypeMismatch('integer', 'string').message
1653
- ]);
1654
- });
1655
- });
1656
- describe('operatorTypeMismatch', () => {
1657
- it('finds when the type of the lhs is not compatible with the rhs type', () => {
1658
- program.setFile('source/util.bs', `
1659
- sub doStuff()
1660
- a = 1 + true
1661
- b = "hello" * 2
1662
- end sub
1663
-
1664
- `);
1665
- program.validate();
1666
- //should have errors
1667
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1668
- DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch('+', 'integer', 'boolean').message,
1669
- DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch('*', 'string', 'integer').message
1670
- ]);
1671
- });
1672
- it('allows when the type of the lhs is compatible with the rhs type', () => {
1673
- program.setFile('source/util.bs', `
1674
- sub doStuff()
1675
- a = 10 << 1
1676
- b = "hello" + "world"
1677
- c = 78 / 34
1678
- d = 100 \\ 5
1679
- thing = new Klass()
1680
- e = thing <> invalid
1681
- end sub
1682
-
1683
- class Klass
1684
- end class
1685
- `);
1686
- program.validate();
1687
- //should have no errors
1688
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1689
- });
1690
- it('allows tests against invalid', () => {
1691
- program.setFile('source/util.bs', `
1692
- sub doStuff()
1693
- thing = new Klass()
1694
- x = thing <> invalid
1695
- end sub
1696
-
1697
- class Klass
1698
- end class
1699
- `);
1700
- program.validate();
1701
- //should have no errors
1702
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1703
- });
1704
- it('disallows equality tests of classes', () => {
1705
- program.setFile('source/util.bs', `
1706
- sub doStuff()
1707
- thing = new Klass()
1708
- thing2 = new Klass()
1709
- x = thing = thing2
1710
- end sub
1711
-
1712
- class Klass
1713
- end class
1714
- `);
1715
- program.validate();
1716
- //should have errors
1717
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1718
- DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch('=', 'Klass', 'Klass').message
1719
- ]);
1720
- });
1721
- it('disallows operations between dynamic and custom types', () => {
1722
- program.setFile('source/util.bs', `
1723
- sub doStuff(input)
1724
- thing = new Klass()
1725
- x = thing + input
1726
- end sub
1727
-
1728
- class Klass
1729
- end class
1730
- `);
1731
- program.validate();
1732
- //should have errors
1733
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1734
- DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch('+', 'Klass', 'dynamic').message
1735
- ]);
1736
- });
1737
- it('allows valid operations on enum members', () => {
1738
- program.setFile('source/util.bs', `
1739
- sub makeEasterly(d as Direction)
1740
- print d + "e"
1741
- print Direction.north + "east"
1742
- end sub
1743
-
1744
- function getTax(itemAmt as ItemCost) as Float
1745
- return itemAmt * 1.15
1746
- end function
1747
-
1748
- enum Direction
1749
- north = "n"
1750
- south = "s"
1751
- end enum
1752
-
1753
- enum ItemCost
1754
- x = 99.99
1755
- y = 29.99
1756
- end enum
1757
-
1758
- `);
1759
- program.validate();
1760
- //should have no errors
1761
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1762
- });
1763
- it('finds invalid operations on enum members', () => {
1764
- program.setFile('source/util.bs', `
1765
- enum Direction
1766
- north = "n"
1767
- south = "s"
1768
- end enum
1769
-
1770
- sub makeEasterly(d as Direction)
1771
- print d + 2
1772
- print 3.14 * Direction.north
1773
- end sub
1774
- `);
1775
- program.validate();
1776
- //should have errors
1777
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1778
- DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch('+', 'Direction', 'integer').message,
1779
- DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch('*', 'float', 'Direction').message
1780
- ]);
1781
- });
1782
- it('validates unary operators', () => {
1783
- program.setFile('source/util.bs', `
1784
- sub doStuff()
1785
- x = - "hello world"
1786
- end sub
1787
- `);
1788
- program.validate();
1789
- //should have errors
1790
- (0, testHelpers_spec_1.expectDiagnostics)(program, [
1791
- DiagnosticMessages_1.DiagnosticMessages.operatorTypeMismatch('-', 'string').message
1792
- ]);
1793
- });
1794
- it('allows unary on dynamic and union types', () => {
1795
- program.setFile('source/util.bs', `
1796
- sub doStuff(x)
1797
- y = -x
1798
- print y
1799
- end sub
1800
-
1801
- sub doOtherStuff(x as float or integer)
1802
- y = -x
1803
- print y
1804
- end sub
1805
-
1806
- sub doEventMoreStuff(x as boolean or dynamic)
1807
- if not x
1808
- print "ok"
1809
- end if
1810
- end sub
1811
- `);
1812
- program.validate();
1813
- //should have no errors
1814
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1815
- });
1816
- });
1817
- describe('revalidation', () => {
1818
- it('revalidates when a enum defined in a different namespace changes', () => {
1819
- program.setFile('source/file1.bs', `
1820
- namespace Alpha
1821
- function printEnum(enumVal as Alpha.Beta.Charlie.SomeEnum) as string
1822
- return enumVal.toStr()
1823
- end function
1824
- end namespace
1825
- `);
1826
- program.setFile('source/file2.bs', `
1827
- namespace Alpha.Beta.Charlie
1828
- enum SomeEnum
1829
- val1 = 1
1830
- val2 = 2
1831
- end enum
1832
- end namespace
1833
- `);
1834
- program.validate();
1835
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1836
- program.setFile('source/file2.bs', `
1837
- namespace Alpha.Beta.Charlie
1838
- enum ChangedEnum
1839
- val1 = 1
1840
- val2 = 2
1841
- end enum
1842
- end namespace
1843
- `);
1844
- program.validate();
1845
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [DiagnosticMessages_1.DiagnosticMessages.cannotFindName('SomeEnum').message]);
1846
- });
1847
- it('revalidates when a class defined in a different namespace changes', () => {
1848
- program.setFile('source/file1.bs', `
1849
- namespace Alpha
1850
- function printEnum(myKlass as Alpha.Beta.Charlie.SomeClass) as string
1851
- return myKlass.getValue()
1852
- end function
1853
- end namespace
1854
- `);
1855
- program.setFile('source/file2.bs', `
1856
- namespace Alpha.Beta.Charlie
1857
- class SomeClass
1858
- private myValue as string
1859
- function getValue() as string
1860
- return m.myValue
1861
- end function
1862
- end class
1863
- end namespace
1864
- `);
1865
- program.validate();
1866
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1867
- program.setFile('source/file2.bs', `
1868
- namespace Alpha.Beta.Charlie
1869
- class SomeClass
1870
- private myValue as string
1871
- function getValue(lowerCase as boolean) as string
1872
- if lowerCase
1873
- return lcase(m.myValue)
1874
- end if
1875
- return m.myValue
1876
- end function
1877
- end class
1878
- end namespace
1879
- `);
1880
- program.validate();
1881
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(program, [DiagnosticMessages_1.DiagnosticMessages.mismatchArgumentCount(1, 0).message]);
1882
- });
1883
- it('validates only parts of files that need revalidation on scope validation', () => {
1884
- function validateFile(file) {
1885
- const validateFileEvent = {
1886
- program: program,
1887
- file: file
1888
- };
1889
- //emit an event to allow plugins to contribute to the file validation process
1890
- program.plugins.emit('onFileValidate', validateFileEvent);
1891
- }
1892
- const commonContents = `
1893
- sub noValidationForEachScope()
1894
- k = new KlassInSameFile()
1895
- print k.value
1896
- end sub
1897
-
1898
- class KlassInSameFile
1899
- value = 1
1900
- end class
1901
- `;
1902
- let commonBs = program.setFile('source/common.bs', commonContents);
1903
- validateFile(commonBs);
1904
- (0, chai_1.expect)(commonBs.validationSegmenter.segmentsForValidation.length).to.eq(2); // 1 func, 1 classField
1905
- (0, chai_1.expect)(commonBs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(0);
1906
- commonBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
1907
- (0, chai_1.expect)(commonBs.validationSegmenter.singleValidationSegments.size).to.eq(2); // no references needed to other files
1908
- let common2Contents = `
1909
- sub doesValidationForEachScope()
1910
- k = new KlassInDiffFile()
1911
- print k.value
1912
- end sub
1913
-
1914
- function alsoNoValidationForEachScope() as integer
1915
- return 1
1916
- end function
1917
- `;
1918
- let common2Bs = program.setFile('source/common2.bs', common2Contents);
1919
- validateFile(common2Bs);
1920
- (0, chai_1.expect)(common2Bs.validationSegmenter.segmentsForValidation.length).to.eq(2); // 2 func
1921
- (0, chai_1.expect)(common2Bs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(1);
1922
- commonBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
1923
- (0, chai_1.expect)(common2Bs.validationSegmenter.singleValidationSegments.size).to.eq(1); // alsoNoValidationForEachScope() does not reference other files
1924
- let klassContents = `
1925
- class KlassInDiffFile
1926
- value = 2
1927
- end class
1928
- `;
1929
- let klassBs = program.setFile('source/klass.bs', klassContents);
1930
- validateFile(klassBs);
1931
- (0, chai_1.expect)(klassBs.validationSegmenter.segmentsForValidation.length).to.eq(1); // 1 classField
1932
- (0, chai_1.expect)(klassBs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(0);
1933
- klassBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
1934
- (0, chai_1.expect)(klassBs.validationSegmenter.singleValidationSegments.size).to.eq(1); // does not reference other files
1935
- const widgetFileContents = `
1936
- sub init()
1937
- noValidationForEachScope()
1938
- doesValidationForEachScope()
1939
- end sub
1940
-
1941
- sub anotherFunction()
1942
- print "hello"
1943
- end sub
1944
- `;
1945
- let widgetBs = program.setFile('components/Widget.bs', widgetFileContents);
1946
- validateFile(widgetBs);
1947
- (0, chai_1.expect)(widgetBs.validationSegmenter.segmentsForValidation.length).to.eq(2); // 2 funcs
1948
- (0, chai_1.expect)(widgetBs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(1); // 1 func (init)
1949
- widgetBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
1950
- (0, chai_1.expect)(widgetBs.validationSegmenter.singleValidationSegments.size).to.eq(1); // 1 func (anotherFunction)
1951
- const diffKlassContent = `
1952
- class KlassInDiffFile
1953
- value = 3
1954
- end class
1955
- `;
1956
- let diffKlassBs = program.setFile('components/diffKlass.bs', diffKlassContent);
1957
- validateFile(diffKlassBs);
1958
- (0, chai_1.expect)(diffKlassBs.validationSegmenter.segmentsForValidation.length).to.eq(1); // 1 classField
1959
- (0, chai_1.expect)(diffKlassBs.validationSegmenter.unresolvedSegmentsSymbols.size).to.eq(0);
1960
- diffKlassBs.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.false);
1961
- (0, chai_1.expect)(diffKlassBs.validationSegmenter.singleValidationSegments.size).to.eq(1);
1962
- program.setFile('components/Widget.xml', (0, testHelpers_spec_1.trim) `
1963
- <?xml version="1.0" encoding="utf-8" ?>
1964
- <component name="Widget" extends="Group">
1965
- <script uri="Widget.bs"/>
1966
- <script uri="pkg:/source/common.bs"/>
1967
- <script uri="pkg:/source/common2.bs"/>
1968
- <script uri="diffKlass.bs"/>
1969
- </component>
1970
- `);
1971
- //reset files
1972
- commonBs = program.setFile('source/common.bs', commonContents);
1973
- common2Bs = program.setFile('source/common2.bs', common2Contents);
1974
- klassBs = program.setFile('source/klass.bs', klassContents);
1975
- widgetBs = program.setFile('components/Widget.bs', widgetFileContents);
1976
- diffKlassBs = program.setFile('components/diffKlass.bs', diffKlassContent);
1977
- program.validate();
1978
- // all segments should be validated
1979
- [commonBs, common2Bs, klassBs, widgetBs, diffKlassBs].forEach(file => {
1980
- (0, chai_1.expect)(file.validationSegmenter.validatedSegments.size).to.gte(file.validationSegmenter.segmentsForValidation.length);
1981
- file.validationSegmenter.validatedSegments.forEach(x => (0, chai_1.expect)(x).to.be.true);
1982
- });
1983
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
1984
- program.setFile('components/Widget.bs', widgetFileContents);
1985
- program.validate();
1986
- // Widget.bs has changed. it needs to totally re-validated
1987
- // and other files in the scope need to revalidate only the unresolved segments - should be source/common2.bs
1988
- // TODO: how to test this?
1989
- program.validate();
1990
- program.setFile('components/diffKlass.bs', diffKlassContent);
1991
- // diffKlass.bs has changed. it needs to totally re-validated
1992
- // no other files in scope reference it .. no other files need revalidation
1993
- // TODO: how to test this?
1994
- program.validate();
1995
- program.setFile('source/common.bs', commonContents);
1996
- // common.bs has changed. it needs to totally re-validated
1997
- // in source scope, common2.bs still has unresolves, it needs revalidation
1998
- // in widget scope, widget.bs references it
1999
- // TODO: how to test this?
2000
- program.validate();
2001
- });
2002
- });
2003
- });
2004
- //# sourceMappingURL=ScopeValidator.spec.js.map