brighterscript 0.72.1 → 0.72.3

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 (313) hide show
  1. package/README.md +7 -2
  2. package/dist/LanguageServer.d.ts +2 -1
  3. package/dist/LanguageServer.js +12 -0
  4. package/dist/LanguageServer.js.map +1 -1
  5. package/dist/Program.d.ts +5 -1
  6. package/dist/Program.js +20 -0
  7. package/dist/Program.js.map +1 -1
  8. package/dist/bscPlugin/BscPlugin.d.ts +2 -1
  9. package/dist/bscPlugin/BscPlugin.js +4 -0
  10. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  11. package/dist/bscPlugin/inlayHints/InlayHintProcessor.d.ts +23 -0
  12. package/dist/bscPlugin/inlayHints/InlayHintProcessor.js +183 -0
  13. package/dist/bscPlugin/inlayHints/InlayHintProcessor.js.map +1 -0
  14. package/dist/interfaces.d.ts +34 -1
  15. package/dist/lsp/LspProject.d.ts +8 -1
  16. package/dist/lsp/Project.d.ts +5 -1
  17. package/dist/lsp/Project.js +6 -0
  18. package/dist/lsp/Project.js.map +1 -1
  19. package/dist/lsp/ProjectManager.d.ts +5 -1
  20. package/dist/lsp/ProjectManager.js +12 -0
  21. package/dist/lsp/ProjectManager.js.map +1 -1
  22. package/dist/lsp/worker/WorkerThreadProject.d.ts +5 -1
  23. package/dist/lsp/worker/WorkerThreadProject.js +3 -0
  24. package/dist/lsp/worker/WorkerThreadProject.js.map +1 -1
  25. package/package.json +18 -14
  26. package/dist/astUtils/AstEditor.spec.d.ts +0 -1
  27. package/dist/astUtils/AstEditor.spec.js +0 -254
  28. package/dist/astUtils/AstEditor.spec.js.map +0 -1
  29. package/dist/astUtils/creators.spec.d.ts +0 -1
  30. package/dist/astUtils/creators.spec.js +0 -21
  31. package/dist/astUtils/creators.spec.js.map +0 -1
  32. package/dist/astUtils/reflection.spec.d.ts +0 -1
  33. package/dist/astUtils/reflection.spec.js +0 -308
  34. package/dist/astUtils/reflection.spec.js.map +0 -1
  35. package/dist/astUtils/stackedVisitor.spec.d.ts +0 -1
  36. package/dist/astUtils/stackedVisitor.spec.js +0 -79
  37. package/dist/astUtils/stackedVisitor.spec.js.map +0 -1
  38. package/dist/astUtils/visitors.spec.d.ts +0 -1
  39. package/dist/astUtils/visitors.spec.js +0 -1197
  40. package/dist/astUtils/visitors.spec.js.map +0 -1
  41. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.d.ts +0 -1
  42. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +0 -1237
  43. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +0 -1
  44. package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +0 -1
  45. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +0 -171
  46. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +0 -1
  47. package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +0 -1
  48. package/dist/bscPlugin/hover/HoverProcessor.spec.js +0 -201
  49. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +0 -1
  50. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +0 -1
  51. package/dist/bscPlugin/references/ReferencesProvider.spec.js +0 -51
  52. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +0 -1
  53. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.d.ts +0 -1
  54. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js +0 -298
  55. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js.map +0 -1
  56. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +0 -1
  57. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -399
  58. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +0 -1
  59. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +0 -1
  60. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +0 -290
  61. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +0 -1
  62. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +0 -1
  63. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +0 -245
  64. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +0 -1
  65. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +0 -1
  66. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -46
  67. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
  68. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +0 -1
  69. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +0 -702
  70. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +0 -1
  71. package/dist/common/Sequencer.spec.d.ts +0 -1
  72. package/dist/common/Sequencer.spec.js +0 -75
  73. package/dist/common/Sequencer.spec.js.map +0 -1
  74. package/dist/files/BrsFile.Class.spec.d.ts +0 -1
  75. package/dist/files/BrsFile.Class.spec.js +0 -1805
  76. package/dist/files/BrsFile.Class.spec.js.map +0 -1
  77. package/dist/files/BrsFile.spec.d.ts +0 -1
  78. package/dist/files/BrsFile.spec.js +0 -4611
  79. package/dist/files/BrsFile.spec.js.map +0 -1
  80. package/dist/files/XmlFile.spec.d.ts +0 -1
  81. package/dist/files/XmlFile.spec.js +0 -1219
  82. package/dist/files/XmlFile.spec.js.map +0 -1
  83. package/dist/files/tests/imports.spec.d.ts +0 -1
  84. package/dist/files/tests/imports.spec.js +0 -241
  85. package/dist/files/tests/imports.spec.js.map +0 -1
  86. package/dist/files/tests/optionalChaning.spec.d.ts +0 -1
  87. package/dist/files/tests/optionalChaning.spec.js +0 -152
  88. package/dist/files/tests/optionalChaning.spec.js.map +0 -1
  89. package/dist/lexer/Character.spec.d.ts +0 -1
  90. package/dist/lexer/Character.spec.js +0 -27
  91. package/dist/lexer/Character.spec.js.map +0 -1
  92. package/dist/lexer/Lexer.spec.d.ts +0 -1
  93. package/dist/lexer/Lexer.spec.js +0 -1300
  94. package/dist/lexer/Lexer.spec.js.map +0 -1
  95. package/dist/lsp/ActionQueue.spec.d.ts +0 -1
  96. package/dist/lsp/ActionQueue.spec.js +0 -80
  97. package/dist/lsp/ActionQueue.spec.js.map +0 -1
  98. package/dist/lsp/DocumentManager.spec.d.ts +0 -1
  99. package/dist/lsp/DocumentManager.spec.js +0 -103
  100. package/dist/lsp/DocumentManager.spec.js.map +0 -1
  101. package/dist/lsp/PathFilterer.spec.d.ts +0 -1
  102. package/dist/lsp/PathFilterer.spec.js +0 -182
  103. package/dist/lsp/PathFilterer.spec.js.map +0 -1
  104. package/dist/lsp/Project.spec.d.ts +0 -1
  105. package/dist/lsp/Project.spec.js +0 -400
  106. package/dist/lsp/Project.spec.js.map +0 -1
  107. package/dist/lsp/ProjectManager.spec.d.ts +0 -1
  108. package/dist/lsp/ProjectManager.spec.js +0 -1183
  109. package/dist/lsp/ProjectManager.spec.js.map +0 -1
  110. package/dist/lsp/worker/MessageHandler.spec.d.ts +0 -1
  111. package/dist/lsp/worker/MessageHandler.spec.js +0 -64
  112. package/dist/lsp/worker/MessageHandler.spec.js.map +0 -1
  113. package/dist/lsp/worker/WorkerPool.spec.d.ts +0 -1
  114. package/dist/lsp/worker/WorkerPool.spec.js +0 -59
  115. package/dist/lsp/worker/WorkerPool.spec.js.map +0 -1
  116. package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +0 -2
  117. package/dist/lsp/worker/WorkerThreadProject.spec.js +0 -72
  118. package/dist/lsp/worker/WorkerThreadProject.spec.js.map +0 -1
  119. package/dist/parser/AstNode.spec.d.ts +0 -1
  120. package/dist/parser/AstNode.spec.js +0 -1452
  121. package/dist/parser/AstNode.spec.js.map +0 -1
  122. package/dist/parser/Expression.spec.d.ts +0 -1
  123. package/dist/parser/Expression.spec.js +0 -40
  124. package/dist/parser/Expression.spec.js.map +0 -1
  125. package/dist/parser/Parser.Class.spec.d.ts +0 -1
  126. package/dist/parser/Parser.Class.spec.js +0 -495
  127. package/dist/parser/Parser.Class.spec.js.map +0 -1
  128. package/dist/parser/Parser.spec.d.ts +0 -4
  129. package/dist/parser/Parser.spec.js +0 -1985
  130. package/dist/parser/Parser.spec.js.map +0 -1
  131. package/dist/parser/SGParser.spec.d.ts +0 -1
  132. package/dist/parser/SGParser.spec.js +0 -131
  133. package/dist/parser/SGParser.spec.js.map +0 -1
  134. package/dist/parser/Statement.spec.d.ts +0 -1
  135. package/dist/parser/Statement.spec.js +0 -118
  136. package/dist/parser/Statement.spec.js.map +0 -1
  137. package/dist/parser/tests/Parser.spec.d.ts +0 -19
  138. package/dist/parser/tests/Parser.spec.js +0 -38
  139. package/dist/parser/tests/Parser.spec.js.map +0 -1
  140. package/dist/parser/tests/controlFlow/For.spec.d.ts +0 -1
  141. package/dist/parser/tests/controlFlow/For.spec.js +0 -208
  142. package/dist/parser/tests/controlFlow/For.spec.js.map +0 -1
  143. package/dist/parser/tests/controlFlow/ForEach.spec.d.ts +0 -1
  144. package/dist/parser/tests/controlFlow/ForEach.spec.js +0 -143
  145. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +0 -1
  146. package/dist/parser/tests/controlFlow/If.spec.d.ts +0 -1
  147. package/dist/parser/tests/controlFlow/If.spec.js +0 -570
  148. package/dist/parser/tests/controlFlow/If.spec.js.map +0 -1
  149. package/dist/parser/tests/controlFlow/While.spec.d.ts +0 -1
  150. package/dist/parser/tests/controlFlow/While.spec.js +0 -156
  151. package/dist/parser/tests/controlFlow/While.spec.js.map +0 -1
  152. package/dist/parser/tests/expression/Additive.spec.d.ts +0 -1
  153. package/dist/parser/tests/expression/Additive.spec.js +0 -99
  154. package/dist/parser/tests/expression/Additive.spec.js.map +0 -1
  155. package/dist/parser/tests/expression/ArrayLiterals.spec.d.ts +0 -1
  156. package/dist/parser/tests/expression/ArrayLiterals.spec.js +0 -291
  157. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +0 -1
  158. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.d.ts +0 -1
  159. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +0 -401
  160. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +0 -1
  161. package/dist/parser/tests/expression/Boolean.spec.d.ts +0 -1
  162. package/dist/parser/tests/expression/Boolean.spec.js +0 -83
  163. package/dist/parser/tests/expression/Boolean.spec.js.map +0 -1
  164. package/dist/parser/tests/expression/Call.spec.d.ts +0 -1
  165. package/dist/parser/tests/expression/Call.spec.js +0 -242
  166. package/dist/parser/tests/expression/Call.spec.js.map +0 -1
  167. package/dist/parser/tests/expression/Exponential.spec.d.ts +0 -1
  168. package/dist/parser/tests/expression/Exponential.spec.js +0 -37
  169. package/dist/parser/tests/expression/Exponential.spec.js.map +0 -1
  170. package/dist/parser/tests/expression/Function.spec.d.ts +0 -1
  171. package/dist/parser/tests/expression/Function.spec.js +0 -403
  172. package/dist/parser/tests/expression/Function.spec.js.map +0 -1
  173. package/dist/parser/tests/expression/Indexing.spec.d.ts +0 -1
  174. package/dist/parser/tests/expression/Indexing.spec.js +0 -289
  175. package/dist/parser/tests/expression/Indexing.spec.js.map +0 -1
  176. package/dist/parser/tests/expression/Multiplicative.spec.d.ts +0 -1
  177. package/dist/parser/tests/expression/Multiplicative.spec.js +0 -67
  178. package/dist/parser/tests/expression/Multiplicative.spec.js.map +0 -1
  179. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.d.ts +0 -1
  180. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +0 -346
  181. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +0 -1
  182. package/dist/parser/tests/expression/PrefixUnary.spec.d.ts +0 -1
  183. package/dist/parser/tests/expression/PrefixUnary.spec.js +0 -105
  184. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +0 -1
  185. package/dist/parser/tests/expression/Primary.spec.d.ts +0 -1
  186. package/dist/parser/tests/expression/Primary.spec.js +0 -149
  187. package/dist/parser/tests/expression/Primary.spec.js.map +0 -1
  188. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +0 -1
  189. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +0 -171
  190. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +0 -1
  191. package/dist/parser/tests/expression/Relational.spec.d.ts +0 -1
  192. package/dist/parser/tests/expression/Relational.spec.js +0 -83
  193. package/dist/parser/tests/expression/Relational.spec.js.map +0 -1
  194. package/dist/parser/tests/expression/SourceLiteralExpression.spec.d.ts +0 -1
  195. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +0 -201
  196. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +0 -1
  197. package/dist/parser/tests/expression/TemplateStringExpression.spec.d.ts +0 -1
  198. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +0 -389
  199. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +0 -1
  200. package/dist/parser/tests/expression/TernaryExpression.spec.d.ts +0 -1
  201. package/dist/parser/tests/expression/TernaryExpression.spec.js +0 -876
  202. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +0 -1
  203. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +0 -1
  204. package/dist/parser/tests/expression/UnaryExpression.spec.js +0 -52
  205. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +0 -1
  206. package/dist/parser/tests/statement/AssignmentOperators.spec.d.ts +0 -1
  207. package/dist/parser/tests/statement/AssignmentOperators.spec.js +0 -79
  208. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +0 -1
  209. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +0 -1
  210. package/dist/parser/tests/statement/ConstStatement.spec.js +0 -708
  211. package/dist/parser/tests/statement/ConstStatement.spec.js.map +0 -1
  212. package/dist/parser/tests/statement/Continue.spec.d.ts +0 -1
  213. package/dist/parser/tests/statement/Continue.spec.js +0 -119
  214. package/dist/parser/tests/statement/Continue.spec.js.map +0 -1
  215. package/dist/parser/tests/statement/Declaration.spec.d.ts +0 -1
  216. package/dist/parser/tests/statement/Declaration.spec.js +0 -108
  217. package/dist/parser/tests/statement/Declaration.spec.js.map +0 -1
  218. package/dist/parser/tests/statement/Dim.spec.d.ts +0 -1
  219. package/dist/parser/tests/statement/Dim.spec.js +0 -73
  220. package/dist/parser/tests/statement/Dim.spec.js.map +0 -1
  221. package/dist/parser/tests/statement/Enum.spec.d.ts +0 -1
  222. package/dist/parser/tests/statement/Enum.spec.js +0 -1307
  223. package/dist/parser/tests/statement/Enum.spec.js.map +0 -1
  224. package/dist/parser/tests/statement/For.spec.d.ts +0 -1
  225. package/dist/parser/tests/statement/For.spec.js +0 -45
  226. package/dist/parser/tests/statement/For.spec.js.map +0 -1
  227. package/dist/parser/tests/statement/ForEach.spec.d.ts +0 -1
  228. package/dist/parser/tests/statement/ForEach.spec.js +0 -36
  229. package/dist/parser/tests/statement/ForEach.spec.js.map +0 -1
  230. package/dist/parser/tests/statement/Function.spec.d.ts +0 -1
  231. package/dist/parser/tests/statement/Function.spec.js +0 -342
  232. package/dist/parser/tests/statement/Function.spec.js.map +0 -1
  233. package/dist/parser/tests/statement/Goto.spec.d.ts +0 -1
  234. package/dist/parser/tests/statement/Goto.spec.js +0 -51
  235. package/dist/parser/tests/statement/Goto.spec.js.map +0 -1
  236. package/dist/parser/tests/statement/Increment.spec.d.ts +0 -1
  237. package/dist/parser/tests/statement/Increment.spec.js +0 -117
  238. package/dist/parser/tests/statement/Increment.spec.js.map +0 -1
  239. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +0 -1
  240. package/dist/parser/tests/statement/InterfaceStatement.spec.js +0 -102
  241. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +0 -1
  242. package/dist/parser/tests/statement/LibraryStatement.spec.d.ts +0 -1
  243. package/dist/parser/tests/statement/LibraryStatement.spec.js +0 -74
  244. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +0 -1
  245. package/dist/parser/tests/statement/Misc.spec.d.ts +0 -1
  246. package/dist/parser/tests/statement/Misc.spec.js +0 -335
  247. package/dist/parser/tests/statement/Misc.spec.js.map +0 -1
  248. package/dist/parser/tests/statement/PrintStatement.spec.d.ts +0 -1
  249. package/dist/parser/tests/statement/PrintStatement.spec.js +0 -195
  250. package/dist/parser/tests/statement/PrintStatement.spec.js.map +0 -1
  251. package/dist/parser/tests/statement/ReturnStatement.spec.d.ts +0 -1
  252. package/dist/parser/tests/statement/ReturnStatement.spec.js +0 -94
  253. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +0 -1
  254. package/dist/parser/tests/statement/Set.spec.d.ts +0 -1
  255. package/dist/parser/tests/statement/Set.spec.js +0 -218
  256. package/dist/parser/tests/statement/Set.spec.js.map +0 -1
  257. package/dist/parser/tests/statement/Stop.spec.d.ts +0 -1
  258. package/dist/parser/tests/statement/Stop.spec.js +0 -38
  259. package/dist/parser/tests/statement/Stop.spec.js.map +0 -1
  260. package/dist/parser/tests/statement/Throw.spec.d.ts +0 -1
  261. package/dist/parser/tests/statement/Throw.spec.js +0 -35
  262. package/dist/parser/tests/statement/Throw.spec.js.map +0 -1
  263. package/dist/parser/tests/statement/TryCatch.spec.d.ts +0 -1
  264. package/dist/parser/tests/statement/TryCatch.spec.js +0 -142
  265. package/dist/parser/tests/statement/TryCatch.spec.js.map +0 -1
  266. package/dist/preprocessor/Manifest.spec.d.ts +0 -1
  267. package/dist/preprocessor/Manifest.spec.js +0 -80
  268. package/dist/preprocessor/Manifest.spec.js.map +0 -1
  269. package/dist/preprocessor/Preprocessor.spec.d.ts +0 -1
  270. package/dist/preprocessor/Preprocessor.spec.js +0 -152
  271. package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
  272. package/dist/preprocessor/PreprocessorParser.spec.d.ts +0 -1
  273. package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
  274. package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
  275. package/dist/types/ArrayType.spec.d.ts +0 -1
  276. package/dist/types/ArrayType.spec.js +0 -30
  277. package/dist/types/ArrayType.spec.js.map +0 -1
  278. package/dist/types/BooleanType.spec.d.ts +0 -1
  279. package/dist/types/BooleanType.spec.js +0 -12
  280. package/dist/types/BooleanType.spec.js.map +0 -1
  281. package/dist/types/DoubleType.spec.d.ts +0 -1
  282. package/dist/types/DoubleType.spec.js +0 -12
  283. package/dist/types/DoubleType.spec.js.map +0 -1
  284. package/dist/types/DynamicType.spec.d.ts +0 -1
  285. package/dist/types/DynamicType.spec.js +0 -12
  286. package/dist/types/DynamicType.spec.js.map +0 -1
  287. package/dist/types/FloatType.spec.d.ts +0 -1
  288. package/dist/types/FloatType.spec.js +0 -12
  289. package/dist/types/FloatType.spec.js.map +0 -1
  290. package/dist/types/FunctionType.spec.d.ts +0 -1
  291. package/dist/types/FunctionType.spec.js +0 -23
  292. package/dist/types/FunctionType.spec.js.map +0 -1
  293. package/dist/types/IntegerType.spec.d.ts +0 -1
  294. package/dist/types/IntegerType.spec.js +0 -12
  295. package/dist/types/IntegerType.spec.js.map +0 -1
  296. package/dist/types/InterfaceType.spec.d.ts +0 -1
  297. package/dist/types/InterfaceType.spec.js +0 -175
  298. package/dist/types/InterfaceType.spec.js.map +0 -1
  299. package/dist/types/InvalidType.spec.d.ts +0 -1
  300. package/dist/types/InvalidType.spec.js +0 -12
  301. package/dist/types/InvalidType.spec.js.map +0 -1
  302. package/dist/types/LongIntegerType.spec.d.ts +0 -1
  303. package/dist/types/LongIntegerType.spec.js +0 -12
  304. package/dist/types/LongIntegerType.spec.js.map +0 -1
  305. package/dist/types/ObjectType.spec.d.ts +0 -1
  306. package/dist/types/ObjectType.spec.js +0 -12
  307. package/dist/types/ObjectType.spec.js.map +0 -1
  308. package/dist/types/StringType.spec.d.ts +0 -1
  309. package/dist/types/StringType.spec.js +0 -12
  310. package/dist/types/StringType.spec.js.map +0 -1
  311. package/dist/types/VoidType.spec.d.ts +0 -1
  312. package/dist/types/VoidType.spec.js +0 -12
  313. package/dist/types/VoidType.spec.js.map +0 -1
@@ -1,1197 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const vscode_languageserver_1 = require("vscode-languageserver");
4
- const chai_config_spec_1 = require("../chai-config.spec");
5
- const sinon = require("sinon");
6
- const Program_1 = require("../Program");
7
- const Statement_1 = require("../parser/Statement");
8
- const TokenKind_1 = require("../lexer/TokenKind");
9
- const visitors_1 = require("./visitors");
10
- const reflection_1 = require("./reflection");
11
- const creators_1 = require("./creators");
12
- const stackedVisitor_1 = require("./stackedVisitor");
13
- const AstEditor_1 = require("./AstEditor");
14
- const Parser_1 = require("../parser/Parser");
15
- const testHelpers_spec_1 = require("../testHelpers.spec");
16
- const Expression_1 = require("../parser/Expression");
17
- describe('astUtils visitors', () => {
18
- const rootDir = process.cwd();
19
- let program;
20
- const PRINTS_SRC = `
21
- sub Main()
22
- print 1
23
- print 2
24
-
25
- function exec(s)
26
- s()
27
- end function
28
-
29
- exec(sub()
30
- print 8
31
- end sub)
32
-
33
- if a = 1
34
- print 3
35
- else if a = 2
36
- print 4
37
- else
38
- print 5
39
- end if
40
-
41
- while a <> invalid
42
- print 6
43
- end while
44
-
45
- for a = 1 to 10
46
- print 7
47
- end for
48
- end sub
49
- `;
50
- const EXPRESSIONS_SRC = `
51
- sub Main()
52
- 'comment
53
- print "msg"; 3
54
- print \`expand \${var}\`
55
- a = "a"
56
- b = "b" + c
57
- m.global.x = "x"
58
- aa[10] = "aa"
59
- exec("e", some())
60
- for i = 1 to 10
61
- end for
62
- for each n in aa
63
- end for
64
- while i < 10
65
- i++
66
- end while
67
- if j > 0
68
- else if j < -10
69
- end if
70
- return invalid
71
- end sub
72
- `;
73
- beforeEach(() => {
74
- program = new Program_1.Program({ rootDir: rootDir });
75
- });
76
- afterEach(() => {
77
- program.dispose();
78
- });
79
- function functionsWalker(visitor, cancel) {
80
- return (file) => {
81
- file.parser.references.functionExpressions.some(functionExpression => {
82
- visitor(functionExpression.body, undefined);
83
- (0, visitors_1.walkStatements)(functionExpression.body, (statement, parent) => visitor(statement, parent), cancel);
84
- return cancel === null || cancel === void 0 ? void 0 : cancel.isCancellationRequested;
85
- });
86
- };
87
- }
88
- describe('Statements', () => {
89
- it('Walks through all the statements with depth', () => {
90
- const actual = [];
91
- const visitor = (0, stackedVisitor_1.createStackedVisitor)((s, stack) => {
92
- const d = stack.length;
93
- actual.push(`${s.constructor.name}:${d}`);
94
- });
95
- const walker = functionsWalker(visitor);
96
- program.plugins.add({
97
- name: 'walker',
98
- afterFileParse: file => walker(file)
99
- });
100
- program.setFile('source/main.brs', PRINTS_SRC);
101
- (0, chai_config_spec_1.expect)(actual).to.deep.equal([
102
- 'Block:0',
103
- 'PrintStatement:1',
104
- 'PrintStatement:1',
105
- 'FunctionStatement:1',
106
- 'ExpressionStatement:1',
107
- 'IfStatement:1',
108
- 'Block:2',
109
- 'PrintStatement:3',
110
- 'IfStatement:2',
111
- 'Block:3',
112
- 'PrintStatement:4',
113
- 'Block:3',
114
- 'PrintStatement:4',
115
- 'WhileStatement:1',
116
- 'Block:2',
117
- 'PrintStatement:3',
118
- 'ForStatement:1',
119
- 'AssignmentStatement:2',
120
- 'Block:2',
121
- 'PrintStatement:3',
122
- 'Block:0',
123
- 'ExpressionStatement:1',
124
- 'Block:0',
125
- 'PrintStatement:1' // print 8
126
- ]);
127
- });
128
- it('Walks through all the statements with token not cancelled', () => {
129
- const cancel = new vscode_languageserver_1.CancellationTokenSource();
130
- const actual = [];
131
- const walker = functionsWalker(s => actual.push(s.constructor.name), cancel.token);
132
- program.plugins.add({
133
- name: 'walker',
134
- afterFileParse: file => walker(file)
135
- });
136
- program.setFile('source/main.brs', PRINTS_SRC);
137
- (0, chai_config_spec_1.expect)(actual).to.deep.equal([
138
- 'Block',
139
- 'PrintStatement',
140
- 'PrintStatement',
141
- 'FunctionStatement',
142
- 'ExpressionStatement',
143
- 'IfStatement',
144
- 'Block',
145
- 'PrintStatement',
146
- 'IfStatement',
147
- 'Block',
148
- 'PrintStatement',
149
- 'Block',
150
- 'PrintStatement',
151
- 'WhileStatement',
152
- 'Block',
153
- 'PrintStatement',
154
- 'ForStatement',
155
- 'AssignmentStatement',
156
- 'Block',
157
- 'PrintStatement',
158
- 'Block',
159
- 'ExpressionStatement',
160
- 'Block',
161
- 'PrintStatement' // print 8
162
- ]);
163
- });
164
- it('Stops walking when requested', () => {
165
- const cancel = new vscode_languageserver_1.CancellationTokenSource();
166
- const actual = [];
167
- let count = 0;
168
- const walker = functionsWalker(s => {
169
- actual.push(s.constructor.name);
170
- if ((0, reflection_1.isPrintStatement)(s)) {
171
- if (++count === 4) {
172
- cancel.cancel();
173
- }
174
- }
175
- }, cancel.token);
176
- program.plugins.add({
177
- name: 'walker',
178
- afterFileParse: file => walker(file)
179
- });
180
- program.setFile('source/main.brs', PRINTS_SRC);
181
- (0, chai_config_spec_1.expect)(actual).to.deep.equal([
182
- 'Block',
183
- 'PrintStatement',
184
- 'PrintStatement',
185
- 'FunctionStatement',
186
- 'ExpressionStatement',
187
- 'IfStatement',
188
- 'Block',
189
- 'PrintStatement',
190
- 'IfStatement',
191
- 'Block',
192
- 'PrintStatement' // print 4
193
- ]);
194
- });
195
- });
196
- describe('Statement visitor', () => {
197
- it('Maps statements to individual handlers', () => {
198
- const printHandler = sinon.spy();
199
- const blockHandler = sinon.spy();
200
- const visitor = (0, visitors_1.createVisitor)({
201
- PrintStatement: printHandler,
202
- Block: blockHandler
203
- });
204
- const printStatement = new Statement_1.PrintStatement({
205
- print: (0, creators_1.createToken)(TokenKind_1.TokenKind.Print)
206
- }, []);
207
- const blockStatement = new Statement_1.Block([], vscode_languageserver_1.Range.create(0, 0, 0, 0));
208
- visitor(printStatement, undefined);
209
- visitor(blockStatement, undefined);
210
- (0, chai_config_spec_1.expect)(printHandler.callCount).to.equal(1);
211
- (0, chai_config_spec_1.expect)(printHandler.calledWith(printStatement)).to.be.true;
212
- (0, chai_config_spec_1.expect)(blockHandler.callCount).to.equal(1);
213
- (0, chai_config_spec_1.expect)(blockHandler.calledWith(blockStatement)).to.be.true;
214
- });
215
- });
216
- describe('Statement editor', () => {
217
- it('allows replacing statements', () => {
218
- const printStatement1 = new Statement_1.PrintStatement({
219
- print: (0, creators_1.createToken)(TokenKind_1.TokenKind.Print)
220
- }, []);
221
- const printStatement2 = new Statement_1.PrintStatement({
222
- print: (0, creators_1.createToken)(TokenKind_1.TokenKind.Print)
223
- }, []);
224
- const block = new Statement_1.Block([
225
- printStatement1,
226
- new Statement_1.ReturnStatement({ return: (0, creators_1.createToken)(TokenKind_1.TokenKind.Return) })
227
- ], vscode_languageserver_1.Range.create(0, 0, 0, 0));
228
- const visitor = (0, visitors_1.createVisitor)({
229
- PrintStatement: () => printStatement2
230
- });
231
- (0, visitors_1.walkStatements)(block, visitor);
232
- (0, chai_config_spec_1.expect)(block.statements[0]).to.equal(printStatement2);
233
- });
234
- it('uses the AstEditor for replacement when provided', () => {
235
- const editor = new AstEditor_1.AstEditor();
236
- const printStatement1 = new Statement_1.PrintStatement({
237
- print: (0, creators_1.createToken)(TokenKind_1.TokenKind.Print)
238
- }, []);
239
- const printStatement2 = new Statement_1.PrintStatement({
240
- print: (0, creators_1.createToken)(TokenKind_1.TokenKind.Print)
241
- }, []);
242
- const block = new Statement_1.Block([
243
- printStatement1
244
- ], vscode_languageserver_1.Range.create(0, 0, 0, 0));
245
- block.walk((0, visitors_1.createVisitor)({
246
- PrintStatement: () => printStatement2
247
- }), {
248
- walkMode: visitors_1.WalkMode.visitAll,
249
- editor: editor
250
- });
251
- (0, chai_config_spec_1.expect)(block.statements[0]).to.equal(printStatement2);
252
- editor.undoAll();
253
- (0, chai_config_spec_1.expect)(block.statements[0]).to.equal(printStatement1);
254
- });
255
- });
256
- describe('Expressions', () => {
257
- it('Walks through all expressions', () => {
258
- const actual = [];
259
- let curr;
260
- const statementVisitor = (0, stackedVisitor_1.createStackedVisitor)((statement, stack) => {
261
- curr = { statement: statement, depth: stack.length };
262
- });
263
- function expressionVisitor(expression, _) {
264
- const { statement, depth } = curr;
265
- actual.push(`${statement.constructor.name}:${depth}:${expression.constructor.name}`);
266
- }
267
- const walker = functionsWalker((statement, parentStatement) => {
268
- statementVisitor(statement, parentStatement);
269
- statement.walk(expressionVisitor, {
270
- walkMode: visitors_1.WalkMode.visitLocalExpressions
271
- });
272
- });
273
- program.plugins.add({
274
- name: 'walker',
275
- afterFileParse: (file) => walker(file)
276
- });
277
- program.setFile('source/main.brs', EXPRESSIONS_SRC);
278
- (0, chai_config_spec_1.expect)(actual).to.deep.equal([
279
- //The comment statement is weird because it can't be both a statement and expression, but is treated that way. Just ignore it for now until we refactor comments.
280
- //'CommentStatement:1:CommentStatement', // '<comment>
281
- 'PrintStatement:1:LiteralExpression',
282
- 'PrintStatement:1:LiteralExpression',
283
- 'PrintStatement:1:TemplateStringExpression',
284
- 'PrintStatement:1:TemplateStringQuasiExpression',
285
- 'PrintStatement:1:LiteralExpression',
286
- 'PrintStatement:1:VariableExpression',
287
- 'PrintStatement:1:TemplateStringQuasiExpression',
288
- 'PrintStatement:1:LiteralExpression',
289
- 'AssignmentStatement:1:LiteralExpression',
290
- 'AssignmentStatement:1:BinaryExpression',
291
- 'AssignmentStatement:1:LiteralExpression',
292
- 'AssignmentStatement:1:VariableExpression',
293
- 'DottedSetStatement:1:DottedGetExpression',
294
- 'DottedSetStatement:1:VariableExpression',
295
- 'DottedSetStatement:1:LiteralExpression',
296
- 'IndexedSetStatement:1:VariableExpression',
297
- 'IndexedSetStatement:1:LiteralExpression',
298
- 'IndexedSetStatement:1:LiteralExpression',
299
- 'ExpressionStatement:1:CallExpression',
300
- 'ExpressionStatement:1:VariableExpression',
301
- 'ExpressionStatement:1:LiteralExpression',
302
- 'ExpressionStatement:1:CallExpression',
303
- 'ExpressionStatement:1:VariableExpression',
304
- 'ForStatement:1:LiteralExpression',
305
- 'AssignmentStatement:2:LiteralExpression',
306
- 'ForEachStatement:1:VariableExpression',
307
- 'WhileStatement:1:BinaryExpression',
308
- 'WhileStatement:1:VariableExpression',
309
- 'WhileStatement:1:LiteralExpression',
310
- 'IncrementStatement:3:VariableExpression',
311
- 'IfStatement:1:BinaryExpression',
312
- 'IfStatement:1:VariableExpression',
313
- 'IfStatement:1:LiteralExpression',
314
- 'IfStatement:2:BinaryExpression',
315
- 'IfStatement:2:VariableExpression',
316
- 'IfStatement:2:UnaryExpression',
317
- 'IfStatement:2:LiteralExpression',
318
- 'ReturnStatement:1:LiteralExpression' // return <invalid>
319
- ]);
320
- });
321
- });
322
- describe('walk', () => {
323
- function testWalk(text, expectedConstructors, walkMode = visitors_1.WalkMode.visitAllRecursive) {
324
- const file = program.setFile('source/main.bs', text);
325
- const items = [];
326
- let index = 1;
327
- file.ast.walk((element) => {
328
- element._testId = index++;
329
- items.push(element);
330
- }, {
331
- walkMode: walkMode
332
- });
333
- index = 1;
334
- (0, chai_config_spec_1.expect)(items.map(x => `${x.constructor.name}:${x._testId}`)).to.eql(expectedConstructors.map(x => `${x}:${index++}`));
335
- }
336
- it('links every ast node to its parent when walked', () => {
337
- const { ast } = program.setFile('source/main.bs', `
338
- library "v30/bslCore.brs"
339
- import "source/main.bs"
340
- namespace alpha
341
- namespace beta
342
- sub charlie()
343
- delta = 1
344
- delta++
345
- delta = sub()
346
- 'do some printing
347
- print "hello"
348
- end sub
349
- delta()
350
- for i = 0 to 10 step 1
351
- exit for
352
- end for
353
- while false
354
- exit while
355
- end while
356
- if true or false then
357
- print 1.2
358
- else
359
- print 123123123123
360
- end if
361
- dim arr[1, 2]
362
- goto theLabel
363
- theLabel:
364
- return false
365
- end
366
- stop
367
- for each item in [1, 2, 3]
368
- continue for
369
- end for
370
- obj = { name: "bob"}
371
- obj.name = obj.name
372
- obj["name"] = obj["name"]
373
- obj.name = obj@firstName
374
- print (true or false)
375
- print \`true\${false}\\n\`
376
- print not true
377
- print FUNCTION_NAME
378
- print new Person()
379
- print tag\`stuff\${1}\`
380
- print true ? true : false
381
- print true ?? false
382
- print /search stuff/g
383
- try
384
- obj.bob = "carl"
385
- throw "e"
386
- catch e
387
- obj["name"] = "dale"
388
- print e
389
- end try
390
- obj@.doCallfunc(1, 2)
391
- end sub
392
- end namespace
393
- end namespace
394
- @SomeAnnotation(1, "two")
395
- interface IPerson
396
- name as string
397
- function doSomething() as string
398
- end interface
399
- class Person
400
- name as string = "bob"
401
- function doSomething(value = true) as string
402
- end function
403
- end class
404
- enum Direction
405
- up = "up"
406
- end enum
407
- enum Logical
408
- yes = 1
409
- no = 0
410
- end enum
411
- const CONST_VALUE = 1.2
412
- `);
413
- (0, testHelpers_spec_1.expectZeroDiagnostics)(program);
414
- const nodes = [];
415
- //get every expression and statement in the file
416
- ast.walk((node) => {
417
- nodes.push(node);
418
- }, { walkMode: visitors_1.WalkMode.visitAllRecursive });
419
- for (let i = 0; i < nodes.length; i++) {
420
- const node = nodes[i];
421
- //find the top-most ast node
422
- let top = node;
423
- while (top.parent) {
424
- top = top.parent;
425
- }
426
- //should be the same instance. If it doesn't then something is wrong with the .parent linking
427
- (0, chai_config_spec_1.expect)(top === ast || node === ast, `Node ${node.constructor.name} (index ${i}) has broken parent link`).to.be.true;
428
- }
429
- });
430
- it('Walks through all expressions until cancelled', () => {
431
- const file = program.setFile('source/main.bs', `
432
- sub logger(message = "nil" as string)
433
- innerLog = sub(message = "nil" as string)
434
- print message
435
- end sub
436
- innerLog(message)
437
- end sub
438
- `);
439
- const cancel = new vscode_languageserver_1.CancellationTokenSource();
440
- let count = 0;
441
- const stopIndex = 5;
442
- file.ast.walk((statement, parent) => {
443
- count++;
444
- if (count === stopIndex) {
445
- cancel.cancel();
446
- }
447
- }, {
448
- walkMode: visitors_1.WalkMode.visitAllRecursive,
449
- cancel: cancel.token
450
- });
451
- (0, chai_config_spec_1.expect)(count).to.equal(stopIndex);
452
- });
453
- it('walks if statement', () => {
454
- testWalk(`
455
- sub main()
456
- if true then
457
- print "true"
458
- else if true then
459
- print "true"
460
- else
461
- print "true"
462
- end if
463
- end sub
464
- `, [
465
- 'FunctionStatement',
466
- 'FunctionExpression',
467
- 'Block',
468
- //if
469
- 'IfStatement',
470
- 'LiteralExpression',
471
- 'Block',
472
- 'PrintStatement',
473
- 'LiteralExpression',
474
- //else if
475
- 'IfStatement',
476
- 'LiteralExpression',
477
- 'Block',
478
- 'PrintStatement',
479
- 'LiteralExpression',
480
- //else
481
- 'Block',
482
- 'PrintStatement',
483
- 'LiteralExpression'
484
- ]);
485
- });
486
- it('walks if statement without else', () => {
487
- testWalk(`
488
- sub main()
489
- if true then
490
- print "true"
491
- end if
492
- end sub
493
- `, [
494
- 'FunctionStatement',
495
- 'FunctionExpression',
496
- 'Block',
497
- 'IfStatement',
498
- 'LiteralExpression',
499
- 'Block',
500
- 'PrintStatement',
501
- 'LiteralExpression'
502
- ]);
503
- });
504
- it('walks increment statement', () => {
505
- testWalk(`
506
- sub main()
507
- age = 12
508
- age++
509
- end sub
510
- `, [
511
- 'FunctionStatement',
512
- 'FunctionExpression',
513
- 'Block',
514
- 'AssignmentStatement',
515
- 'LiteralExpression',
516
- 'IncrementStatement',
517
- 'VariableExpression'
518
- ]);
519
- });
520
- it('walks ForStatement', () => {
521
- testWalk(`
522
- sub main()
523
- for i = 0 to 10 step 1
524
- print i
525
- end for
526
- end sub
527
- `, [
528
- 'FunctionStatement',
529
- 'FunctionExpression',
530
- 'Block',
531
- 'ForStatement',
532
- 'AssignmentStatement',
533
- 'LiteralExpression',
534
- 'LiteralExpression',
535
- 'LiteralExpression',
536
- 'Block',
537
- 'PrintStatement',
538
- 'VariableExpression'
539
- ]);
540
- });
541
- it('walks ForEachStatement', () => {
542
- testWalk(`
543
- sub main()
544
- for each item in [1,2,3]
545
- print item
546
- end for
547
- end sub
548
- `, [
549
- 'FunctionStatement',
550
- 'FunctionExpression',
551
- 'Block',
552
- 'ForEachStatement',
553
- 'ArrayLiteralExpression',
554
- 'LiteralExpression',
555
- 'LiteralExpression',
556
- 'LiteralExpression',
557
- 'Block',
558
- 'PrintStatement',
559
- 'VariableExpression'
560
- ]);
561
- });
562
- it('walks dotted and indexed set statements', () => {
563
- testWalk(`
564
- sub main()
565
- person = {}
566
- person.name = "person"
567
- person["age"] = 12
568
- end sub
569
- `, [
570
- 'FunctionStatement',
571
- 'FunctionExpression',
572
- 'Block',
573
- 'AssignmentStatement',
574
- 'AALiteralExpression',
575
- 'DottedSetStatement',
576
- 'VariableExpression',
577
- 'LiteralExpression',
578
- 'IndexedSetStatement',
579
- 'VariableExpression',
580
- 'LiteralExpression',
581
- 'LiteralExpression'
582
- ]);
583
- });
584
- it('walks while loop', () => {
585
- testWalk(`
586
- sub main()
587
- while 1 + 1 = 2
588
- print "infinite"
589
- end while
590
- end sub
591
- `, [
592
- 'FunctionStatement',
593
- 'FunctionExpression',
594
- 'Block',
595
- 'WhileStatement',
596
- 'BinaryExpression',
597
- 'BinaryExpression',
598
- 'LiteralExpression',
599
- 'LiteralExpression',
600
- 'LiteralExpression',
601
- 'Block',
602
- 'PrintStatement',
603
- 'LiteralExpression'
604
- ]);
605
- });
606
- it('walks namespace', () => {
607
- testWalk(`
608
- namespace NameA.NameB
609
- end namespace
610
- `, [
611
- 'NamespaceStatement',
612
- 'NamespacedVariableNameExpression',
613
- 'DottedGetExpression',
614
- 'VariableExpression'
615
- ]);
616
- });
617
- it('walks nested functions', () => {
618
- testWalk(`
619
- sub main()
620
- print "main"
621
- inner1 = sub()
622
- print "inner1"
623
- inner2 = sub()
624
- print "inner2"
625
- inner3 = sub()
626
- print "inner3"
627
- end sub
628
- end sub
629
- end sub
630
- end sub
631
- `, [
632
- //sub main()
633
- 'FunctionStatement',
634
- 'FunctionExpression',
635
- 'Block',
636
- 'PrintStatement',
637
- 'LiteralExpression',
638
- //inner1 = sub()
639
- 'AssignmentStatement',
640
- 'FunctionExpression',
641
- 'Block',
642
- 'PrintStatement',
643
- 'LiteralExpression',
644
- //inner2 = sub()
645
- 'AssignmentStatement',
646
- 'FunctionExpression',
647
- 'Block',
648
- 'PrintStatement',
649
- 'LiteralExpression',
650
- //inner3 = sub
651
- 'AssignmentStatement',
652
- 'FunctionExpression',
653
- 'Block',
654
- 'PrintStatement',
655
- 'LiteralExpression'
656
- ]);
657
- });
658
- it('walks CallExpression', () => {
659
- testWalk(`
660
- sub main()
661
- Sleep(123)
662
- end sub
663
- `, [
664
- 'FunctionStatement',
665
- 'FunctionExpression',
666
- 'Block',
667
- 'ExpressionStatement',
668
- 'CallExpression',
669
- 'VariableExpression',
670
- 'LiteralExpression'
671
- ]);
672
- });
673
- it('walks function parameters', () => {
674
- testWalk(`
675
- sub main(arg1)
676
- speak = sub(arg1, arg2)
677
- end sub
678
- end sub
679
- `, [
680
- 'FunctionStatement',
681
- 'FunctionExpression',
682
- 'FunctionParameterExpression',
683
- 'Block',
684
- 'AssignmentStatement',
685
- 'FunctionExpression',
686
- 'FunctionParameterExpression',
687
- 'FunctionParameterExpression',
688
- 'Block'
689
- ]);
690
- });
691
- it('walks DottedGetExpression', () => {
692
- testWalk(`
693
- sub main()
694
- print person.name
695
- end sub
696
- `, [
697
- 'FunctionStatement',
698
- 'FunctionExpression',
699
- 'Block',
700
- 'PrintStatement',
701
- 'DottedGetExpression',
702
- 'VariableExpression'
703
- ]);
704
- });
705
- it('walks XmlAttributeGetExpression', () => {
706
- testWalk(`
707
- sub main()
708
- print person@name
709
- end sub
710
- `, [
711
- 'FunctionStatement',
712
- 'FunctionExpression',
713
- 'Block',
714
- 'PrintStatement',
715
- 'XmlAttributeGetExpression',
716
- 'VariableExpression'
717
- ]);
718
- });
719
- it('walks IndexedGetExpression', () => {
720
- testWalk(`
721
- sub main()
722
- print person["name"]
723
- end sub
724
- `, [
725
- 'FunctionStatement',
726
- 'FunctionExpression',
727
- 'Block',
728
- 'PrintStatement',
729
- 'IndexedGetExpression',
730
- 'VariableExpression',
731
- 'LiteralExpression'
732
- ]);
733
- });
734
- it('walks GroupingExpression', () => {
735
- testWalk(`
736
- sub main()
737
- print 1 + ( 1 + 2 )
738
- end sub
739
- `, [
740
- 'FunctionStatement',
741
- 'FunctionExpression',
742
- 'Block',
743
- 'PrintStatement',
744
- 'BinaryExpression',
745
- 'LiteralExpression',
746
- 'GroupingExpression',
747
- 'BinaryExpression',
748
- 'LiteralExpression',
749
- 'LiteralExpression'
750
- ]);
751
- });
752
- it('walks AALiteralExpression', () => {
753
- testWalk(`
754
- sub main()
755
- person = {
756
- 'comment
757
- "name": "John Doe"
758
- }
759
- end sub
760
- `, [
761
- 'FunctionStatement',
762
- 'FunctionExpression',
763
- 'Block',
764
- 'AssignmentStatement',
765
- 'AALiteralExpression',
766
- 'CommentStatement',
767
- 'AAMemberExpression',
768
- 'LiteralExpression'
769
- ]);
770
- });
771
- it('walks UnaryExpression', () => {
772
- testWalk(`
773
- sub main()
774
- isAlive = not isDead
775
- end sub
776
- `, [
777
- 'FunctionStatement',
778
- 'FunctionExpression',
779
- 'Block',
780
- 'AssignmentStatement',
781
- 'UnaryExpression',
782
- 'VariableExpression'
783
- ]);
784
- });
785
- it('walks TemplateStringExpression', () => {
786
- testWalk(`
787
- sub main()
788
- print \`Hello \${worldVar}\`
789
- end sub
790
- `, [
791
- 'FunctionStatement',
792
- 'FunctionExpression',
793
- 'Block',
794
- 'PrintStatement',
795
- 'TemplateStringExpression',
796
- 'TemplateStringQuasiExpression',
797
- 'LiteralExpression',
798
- 'VariableExpression',
799
- 'TemplateStringQuasiExpression',
800
- 'LiteralExpression'
801
- ]);
802
- });
803
- it('walks ReturnStatement with or without value', () => {
804
- testWalk(`
805
- sub main()
806
- a = 0
807
- if a = 0 then
808
- return
809
- else if a > 0 then
810
- return 1
811
- else
812
- return 'nothing
813
- end if
814
- end sub
815
- `, [
816
- 'FunctionStatement',
817
- 'FunctionExpression',
818
- 'Block',
819
- 'AssignmentStatement',
820
- 'LiteralExpression',
821
- //if
822
- 'IfStatement',
823
- 'BinaryExpression',
824
- 'VariableExpression',
825
- 'LiteralExpression',
826
- 'Block',
827
- 'ReturnStatement',
828
- //else if
829
- 'IfStatement',
830
- 'BinaryExpression',
831
- 'VariableExpression',
832
- 'LiteralExpression',
833
- 'Block',
834
- 'ReturnStatement',
835
- 'LiteralExpression',
836
- //else
837
- 'Block',
838
- 'ReturnStatement',
839
- 'CommentStatement'
840
- ]);
841
- });
842
- it('walks TaggedTemplateStringExpression', () => {
843
- testWalk(`
844
- sub main()
845
- print tag\`Hello \${worldVar}\`
846
- end sub
847
- `, [
848
- 'FunctionStatement',
849
- 'FunctionExpression',
850
- 'Block',
851
- 'PrintStatement',
852
- 'TaggedTemplateStringExpression',
853
- 'TemplateStringQuasiExpression',
854
- 'LiteralExpression',
855
- 'VariableExpression',
856
- 'TemplateStringQuasiExpression',
857
- 'LiteralExpression'
858
- ]);
859
- });
860
- it('walks CharCodeLiteral expression within TemplateLiteralExpression', () => {
861
- testWalk(`
862
- sub main()
863
- print \`\\n\`
864
- end sub
865
- `, [
866
- 'FunctionStatement',
867
- 'FunctionExpression',
868
- 'Block',
869
- 'PrintStatement',
870
- 'TemplateStringExpression',
871
- 'TemplateStringQuasiExpression',
872
- 'LiteralExpression',
873
- 'EscapedCharCodeLiteralExpression',
874
- 'LiteralExpression'
875
- ]);
876
- });
877
- it('walks NewExpression', () => {
878
- testWalk(`
879
- sub main()
880
- person = new Person()
881
- end sub
882
- `, [
883
- 'FunctionStatement',
884
- 'FunctionExpression',
885
- 'Block',
886
- 'AssignmentStatement',
887
- 'NewExpression',
888
- 'CallExpression',
889
- 'NamespacedVariableNameExpression',
890
- 'VariableExpression'
891
- ]);
892
- });
893
- it('walks CallfuncExpression', () => {
894
- testWalk(`
895
- sub main()
896
- person@.doSomething("arg1")
897
- end sub
898
- `, [
899
- 'FunctionStatement',
900
- 'FunctionExpression',
901
- 'Block',
902
- 'ExpressionStatement',
903
- 'CallfuncExpression',
904
- 'VariableExpression',
905
- 'LiteralExpression'
906
- ]);
907
- });
908
- it('walks ClassStatement', () => {
909
- testWalk(`
910
- class Person
911
- name as string
912
- age as integer = 1
913
- function getName()
914
- return m.name
915
- end function
916
- end class
917
- `, [
918
- 'ClassStatement',
919
- 'FieldStatement',
920
- 'FieldStatement',
921
- 'LiteralExpression',
922
- 'MethodStatement',
923
- 'FunctionExpression',
924
- 'Block',
925
- 'ReturnStatement',
926
- 'DottedGetExpression',
927
- 'VariableExpression'
928
- ]);
929
- });
930
- it('visits all statements and no expressions', () => {
931
- testWalk(`
932
- sub main()
933
- log = sub(message)
934
- print "hello " + message
935
- end sub
936
- log("hello" + " world")
937
- end sub
938
- `, [
939
- 'FunctionStatement',
940
- 'Block',
941
- 'AssignmentStatement',
942
- 'Block',
943
- 'PrintStatement',
944
- 'ExpressionStatement'
945
- ], visitors_1.WalkMode.visitStatementsRecursive);
946
- });
947
- it('visits all expressions and no statement', () => {
948
- testWalk(`
949
- sub main()
950
- log = sub(message)
951
- print "hello " + message
952
- end sub
953
- log("hello" + " world")
954
- end sub
955
- `, [
956
- 'FunctionExpression',
957
- 'FunctionExpression',
958
- 'FunctionParameterExpression',
959
- 'BinaryExpression',
960
- 'LiteralExpression',
961
- 'VariableExpression',
962
- 'CallExpression',
963
- 'VariableExpression',
964
- 'BinaryExpression',
965
- 'LiteralExpression',
966
- 'LiteralExpression'
967
- ], visitors_1.WalkMode.visitExpressionsRecursive);
968
- });
969
- it('provides owner and key', () => {
970
- const items = [];
971
- const { ast } = Parser_1.Parser.parse(`
972
- sub main()
973
- log = sub(message)
974
- print "hello " + message
975
- end sub
976
- log("hello" + " world")
977
- end sub
978
- `);
979
- ast.walk((astNode, parent, owner, key) => {
980
- items.push(astNode);
981
- (0, chai_config_spec_1.expect)(owner[key]).to.equal(astNode);
982
- }, {
983
- walkMode: visitors_1.WalkMode.visitAllRecursive
984
- });
985
- (0, chai_config_spec_1.expect)(items).to.be.length(17);
986
- });
987
- it('can be used to delete statements', () => {
988
- const { ast } = Parser_1.Parser.parse(`
989
- sub main()
990
- print 1
991
- print 2
992
- print 3
993
- end sub
994
- `);
995
- let callCount = 0;
996
- ast.walk((astNode, parent, owner, key) => {
997
- if ((0, reflection_1.isPrintStatement)(astNode)) {
998
- callCount++;
999
- //delete the print statement (we know owner is an array based on this specific test)
1000
- owner.splice(key, 1);
1001
- }
1002
- }, {
1003
- walkMode: visitors_1.WalkMode.visitAllRecursive
1004
- });
1005
- //the visitor should have been called for every statement
1006
- (0, chai_config_spec_1.expect)(callCount).to.eql(3);
1007
- (0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements).to.be.lengthOf(0);
1008
- });
1009
- it('walks everything when the first element is replaced', () => {
1010
- const { ast } = Parser_1.Parser.parse(`
1011
- sub main()
1012
- print 1
1013
- print 2
1014
- print 3
1015
- end sub
1016
- `);
1017
- const target = ast.findChild(reflection_1.isBlock).statements[0];
1018
- let callCount = 0;
1019
- ast.walk((astNode, parent, owner, key) => {
1020
- if ((0, reflection_1.isPrintStatement)(astNode)) {
1021
- callCount++;
1022
- }
1023
- if (astNode === target) {
1024
- owner.splice(key, 1);
1025
- }
1026
- }, {
1027
- walkMode: visitors_1.WalkMode.visitAllRecursive
1028
- });
1029
- //the visitor should have been called for every statement
1030
- (0, chai_config_spec_1.expect)(callCount).to.eql(3);
1031
- (0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements).not.to.include(target);
1032
- });
1033
- it('walks everything when the middle element is replaced', () => {
1034
- const { ast } = Parser_1.Parser.parse(`
1035
- sub main()
1036
- print 1
1037
- print 2
1038
- print 3
1039
- end sub
1040
- `);
1041
- const target = ast.findChild(reflection_1.isBlock).statements[1];
1042
- let callCount = 0;
1043
- ast.walk((astNode, parent, owner, key) => {
1044
- if ((0, reflection_1.isPrintStatement)(astNode)) {
1045
- callCount++;
1046
- }
1047
- if (astNode === target) {
1048
- owner.splice(key, 1);
1049
- }
1050
- }, {
1051
- walkMode: visitors_1.WalkMode.visitAllRecursive
1052
- });
1053
- //the visitor should have been called for every statement
1054
- (0, chai_config_spec_1.expect)(callCount).to.eql(3);
1055
- (0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements).not.to.include(target);
1056
- });
1057
- it('walks everything when the end element is replaced', () => {
1058
- const { ast } = Parser_1.Parser.parse(`
1059
- sub main()
1060
- print 1
1061
- print 2
1062
- print 3
1063
- end sub
1064
- `);
1065
- const target = ast.findChild(reflection_1.isBlock).statements[2];
1066
- let callCount = 0;
1067
- ast.walk((astNode, parent, owner, key) => {
1068
- if ((0, reflection_1.isPrintStatement)(astNode)) {
1069
- callCount++;
1070
- }
1071
- if (astNode === target) {
1072
- owner.splice(key, 1);
1073
- }
1074
- }, {
1075
- walkMode: visitors_1.WalkMode.visitAllRecursive
1076
- });
1077
- //the visitor should have been called for every statement
1078
- (0, chai_config_spec_1.expect)(callCount).to.eql(3);
1079
- (0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements).not.to.include(target);
1080
- });
1081
- it('can be used to insert statements', () => {
1082
- const { ast } = Parser_1.Parser.parse(`
1083
- sub main()
1084
- print 1
1085
- print 2
1086
- print 3
1087
- end sub
1088
- `);
1089
- let printStatementCount = 0;
1090
- let callExpressionCount = 0;
1091
- const calls = [];
1092
- ast.walk((0, visitors_1.createVisitor)({
1093
- PrintStatement: (astNode, parent, owner, key) => {
1094
- printStatementCount++;
1095
- //add another expression to the list every time. This should result in 1 the first time, 2 the second, 3 the third.
1096
- calls.push(new Statement_1.ExpressionStatement((0, creators_1.createCall)((0, creators_1.createVariableExpression)('doSomethingBeforePrint'), [
1097
- (0, creators_1.createIntegerLiteral)(callExpressionCount.toString())
1098
- ])));
1099
- owner.splice(key + 1, 0, ...calls.map(x => x.clone()));
1100
- },
1101
- CallExpression: (call) => {
1102
- callExpressionCount++;
1103
- console.log('call visitor for', call.args[0].token.text);
1104
- }
1105
- }), {
1106
- walkMode: visitors_1.WalkMode.visitAllRecursive
1107
- });
1108
- //the visitor should have been called for every statement
1109
- (0, chai_config_spec_1.expect)(printStatementCount).to.eql(3);
1110
- //since the calls were injected after each print statement, we should have 1 call for the first print, 2 for the second, and 3 for the third
1111
- (0, chai_config_spec_1.expect)(callExpressionCount).to.eql(6);
1112
- (0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements).to.be.lengthOf(9);
1113
- });
1114
- it('walks a new child when returned from a visitor', () => {
1115
- let walkedLiterals = [];
1116
- Parser_1.Parser.parse(`
1117
- sub main()
1118
- print 1 + 2
1119
- end sub
1120
- `).ast.walk((0, visitors_1.createVisitor)({
1121
- BinaryExpression: (node, parent, owner, key) => {
1122
- //replace the `1 + 2` binary expression with a new binary expression
1123
- if ((0, reflection_1.isLiteralExpression)(node.left) && node.left.token.text === '1') {
1124
- return new Expression_1.BinaryExpression((0, creators_1.createIntegerLiteral)('3'), (0, creators_1.createToken)(TokenKind_1.TokenKind.Plus), (0, creators_1.createIntegerLiteral)('4'));
1125
- }
1126
- },
1127
- LiteralExpression: (node) => {
1128
- walkedLiterals.push(node.token.text);
1129
- }
1130
- }), {
1131
- walkMode: visitors_1.WalkMode.visitAllRecursive
1132
- });
1133
- (0, chai_config_spec_1.expect)(walkedLiterals).to.eql(['3', '4']);
1134
- });
1135
- it('walks a new child when returned from a visitor and using an AstEditor', () => {
1136
- let walkedLiterals = [];
1137
- Parser_1.Parser.parse(`
1138
- sub main()
1139
- print 1 + 2
1140
- end sub
1141
- `).ast.walk((0, visitors_1.createVisitor)({
1142
- BinaryExpression: (node, parent, owner, key) => {
1143
- //replace the `1 + 2` binary expression with a new binary expression
1144
- if ((0, reflection_1.isLiteralExpression)(node.left) && node.left.token.text === '1') {
1145
- return new Expression_1.BinaryExpression((0, creators_1.createIntegerLiteral)('3'), (0, creators_1.createToken)(TokenKind_1.TokenKind.Plus), (0, creators_1.createIntegerLiteral)('4'));
1146
- }
1147
- },
1148
- LiteralExpression: (node) => {
1149
- walkedLiterals.push(node.token.text);
1150
- }
1151
- }), {
1152
- walkMode: visitors_1.WalkMode.visitAllRecursive,
1153
- editor: new AstEditor_1.AstEditor()
1154
- });
1155
- (0, chai_config_spec_1.expect)(walkedLiterals).to.eql(['3', '4']);
1156
- });
1157
- });
1158
- describe('walkArray', () => {
1159
- const one = (0, creators_1.createVariableExpression)('one');
1160
- const two = (0, creators_1.createVariableExpression)('two');
1161
- const three = (0, creators_1.createVariableExpression)('three');
1162
- const four = (0, creators_1.createVariableExpression)('four');
1163
- const five = (0, creators_1.createVariableExpression)('five');
1164
- function doTest(startingArray, expected, visitor) {
1165
- const visitedItems = [];
1166
- (0, visitors_1.walkArray)(startingArray, (item, parent, owner, key) => {
1167
- visitedItems.push(item);
1168
- return visitor === null || visitor === void 0 ? void 0 : visitor(item, parent, owner, key);
1169
- }, { walkMode: visitors_1.WalkMode.visitAllRecursive });
1170
- (0, chai_config_spec_1.expect)(visitedItems.map(x => x.name.text)).to.eql(expected.map(x => x.name.text));
1171
- }
1172
- it('walks every element in the array', () => {
1173
- doTest([one, two, three, four, five], [one, two, three, four, five]);
1174
- });
1175
- it('walks new items added to the array', () => {
1176
- doTest([one, two], [one, three, two, four], (item, parent, owner, key) => {
1177
- //insert a value after one
1178
- if (item === one) {
1179
- owner.splice(key + 1, 0, three);
1180
- //insert a value after one
1181
- }
1182
- else if (item === two) {
1183
- owner.splice(key + 1, 0, four);
1184
- }
1185
- });
1186
- });
1187
- it('triggers on nodes that were skiped due to insertions', () => {
1188
- doTest([one, two, three], [one, two, four, three], (item, parent, owner, key) => {
1189
- //insert a value after one
1190
- if (item === two) {
1191
- owner.splice(key, 0, four);
1192
- }
1193
- });
1194
- });
1195
- });
1196
- });
1197
- //# sourceMappingURL=visitors.spec.js.map