brighterscript 0.72.1 → 0.72.2

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 (289) hide show
  1. package/package.json +17 -14
  2. package/dist/astUtils/AstEditor.spec.d.ts +0 -1
  3. package/dist/astUtils/AstEditor.spec.js +0 -254
  4. package/dist/astUtils/AstEditor.spec.js.map +0 -1
  5. package/dist/astUtils/creators.spec.d.ts +0 -1
  6. package/dist/astUtils/creators.spec.js +0 -21
  7. package/dist/astUtils/creators.spec.js.map +0 -1
  8. package/dist/astUtils/reflection.spec.d.ts +0 -1
  9. package/dist/astUtils/reflection.spec.js +0 -308
  10. package/dist/astUtils/reflection.spec.js.map +0 -1
  11. package/dist/astUtils/stackedVisitor.spec.d.ts +0 -1
  12. package/dist/astUtils/stackedVisitor.spec.js +0 -79
  13. package/dist/astUtils/stackedVisitor.spec.js.map +0 -1
  14. package/dist/astUtils/visitors.spec.d.ts +0 -1
  15. package/dist/astUtils/visitors.spec.js +0 -1197
  16. package/dist/astUtils/visitors.spec.js.map +0 -1
  17. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.d.ts +0 -1
  18. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +0 -1237
  19. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +0 -1
  20. package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +0 -1
  21. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +0 -171
  22. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +0 -1
  23. package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +0 -1
  24. package/dist/bscPlugin/hover/HoverProcessor.spec.js +0 -201
  25. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +0 -1
  26. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +0 -1
  27. package/dist/bscPlugin/references/ReferencesProvider.spec.js +0 -51
  28. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +0 -1
  29. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.d.ts +0 -1
  30. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js +0 -298
  31. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js.map +0 -1
  32. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +0 -1
  33. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -399
  34. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +0 -1
  35. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +0 -1
  36. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +0 -290
  37. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +0 -1
  38. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +0 -1
  39. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +0 -245
  40. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +0 -1
  41. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +0 -1
  42. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -46
  43. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
  44. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +0 -1
  45. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +0 -702
  46. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +0 -1
  47. package/dist/common/Sequencer.spec.d.ts +0 -1
  48. package/dist/common/Sequencer.spec.js +0 -75
  49. package/dist/common/Sequencer.spec.js.map +0 -1
  50. package/dist/files/BrsFile.Class.spec.d.ts +0 -1
  51. package/dist/files/BrsFile.Class.spec.js +0 -1805
  52. package/dist/files/BrsFile.Class.spec.js.map +0 -1
  53. package/dist/files/BrsFile.spec.d.ts +0 -1
  54. package/dist/files/BrsFile.spec.js +0 -4611
  55. package/dist/files/BrsFile.spec.js.map +0 -1
  56. package/dist/files/XmlFile.spec.d.ts +0 -1
  57. package/dist/files/XmlFile.spec.js +0 -1219
  58. package/dist/files/XmlFile.spec.js.map +0 -1
  59. package/dist/files/tests/imports.spec.d.ts +0 -1
  60. package/dist/files/tests/imports.spec.js +0 -241
  61. package/dist/files/tests/imports.spec.js.map +0 -1
  62. package/dist/files/tests/optionalChaning.spec.d.ts +0 -1
  63. package/dist/files/tests/optionalChaning.spec.js +0 -152
  64. package/dist/files/tests/optionalChaning.spec.js.map +0 -1
  65. package/dist/lexer/Character.spec.d.ts +0 -1
  66. package/dist/lexer/Character.spec.js +0 -27
  67. package/dist/lexer/Character.spec.js.map +0 -1
  68. package/dist/lexer/Lexer.spec.d.ts +0 -1
  69. package/dist/lexer/Lexer.spec.js +0 -1300
  70. package/dist/lexer/Lexer.spec.js.map +0 -1
  71. package/dist/lsp/ActionQueue.spec.d.ts +0 -1
  72. package/dist/lsp/ActionQueue.spec.js +0 -80
  73. package/dist/lsp/ActionQueue.spec.js.map +0 -1
  74. package/dist/lsp/DocumentManager.spec.d.ts +0 -1
  75. package/dist/lsp/DocumentManager.spec.js +0 -103
  76. package/dist/lsp/DocumentManager.spec.js.map +0 -1
  77. package/dist/lsp/PathFilterer.spec.d.ts +0 -1
  78. package/dist/lsp/PathFilterer.spec.js +0 -182
  79. package/dist/lsp/PathFilterer.spec.js.map +0 -1
  80. package/dist/lsp/Project.spec.d.ts +0 -1
  81. package/dist/lsp/Project.spec.js +0 -400
  82. package/dist/lsp/Project.spec.js.map +0 -1
  83. package/dist/lsp/ProjectManager.spec.d.ts +0 -1
  84. package/dist/lsp/ProjectManager.spec.js +0 -1183
  85. package/dist/lsp/ProjectManager.spec.js.map +0 -1
  86. package/dist/lsp/worker/MessageHandler.spec.d.ts +0 -1
  87. package/dist/lsp/worker/MessageHandler.spec.js +0 -64
  88. package/dist/lsp/worker/MessageHandler.spec.js.map +0 -1
  89. package/dist/lsp/worker/WorkerPool.spec.d.ts +0 -1
  90. package/dist/lsp/worker/WorkerPool.spec.js +0 -59
  91. package/dist/lsp/worker/WorkerPool.spec.js.map +0 -1
  92. package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +0 -2
  93. package/dist/lsp/worker/WorkerThreadProject.spec.js +0 -72
  94. package/dist/lsp/worker/WorkerThreadProject.spec.js.map +0 -1
  95. package/dist/parser/AstNode.spec.d.ts +0 -1
  96. package/dist/parser/AstNode.spec.js +0 -1452
  97. package/dist/parser/AstNode.spec.js.map +0 -1
  98. package/dist/parser/Expression.spec.d.ts +0 -1
  99. package/dist/parser/Expression.spec.js +0 -40
  100. package/dist/parser/Expression.spec.js.map +0 -1
  101. package/dist/parser/Parser.Class.spec.d.ts +0 -1
  102. package/dist/parser/Parser.Class.spec.js +0 -495
  103. package/dist/parser/Parser.Class.spec.js.map +0 -1
  104. package/dist/parser/Parser.spec.d.ts +0 -4
  105. package/dist/parser/Parser.spec.js +0 -1985
  106. package/dist/parser/Parser.spec.js.map +0 -1
  107. package/dist/parser/SGParser.spec.d.ts +0 -1
  108. package/dist/parser/SGParser.spec.js +0 -131
  109. package/dist/parser/SGParser.spec.js.map +0 -1
  110. package/dist/parser/Statement.spec.d.ts +0 -1
  111. package/dist/parser/Statement.spec.js +0 -118
  112. package/dist/parser/Statement.spec.js.map +0 -1
  113. package/dist/parser/tests/Parser.spec.d.ts +0 -19
  114. package/dist/parser/tests/Parser.spec.js +0 -38
  115. package/dist/parser/tests/Parser.spec.js.map +0 -1
  116. package/dist/parser/tests/controlFlow/For.spec.d.ts +0 -1
  117. package/dist/parser/tests/controlFlow/For.spec.js +0 -208
  118. package/dist/parser/tests/controlFlow/For.spec.js.map +0 -1
  119. package/dist/parser/tests/controlFlow/ForEach.spec.d.ts +0 -1
  120. package/dist/parser/tests/controlFlow/ForEach.spec.js +0 -143
  121. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +0 -1
  122. package/dist/parser/tests/controlFlow/If.spec.d.ts +0 -1
  123. package/dist/parser/tests/controlFlow/If.spec.js +0 -570
  124. package/dist/parser/tests/controlFlow/If.spec.js.map +0 -1
  125. package/dist/parser/tests/controlFlow/While.spec.d.ts +0 -1
  126. package/dist/parser/tests/controlFlow/While.spec.js +0 -156
  127. package/dist/parser/tests/controlFlow/While.spec.js.map +0 -1
  128. package/dist/parser/tests/expression/Additive.spec.d.ts +0 -1
  129. package/dist/parser/tests/expression/Additive.spec.js +0 -99
  130. package/dist/parser/tests/expression/Additive.spec.js.map +0 -1
  131. package/dist/parser/tests/expression/ArrayLiterals.spec.d.ts +0 -1
  132. package/dist/parser/tests/expression/ArrayLiterals.spec.js +0 -291
  133. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +0 -1
  134. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.d.ts +0 -1
  135. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +0 -401
  136. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +0 -1
  137. package/dist/parser/tests/expression/Boolean.spec.d.ts +0 -1
  138. package/dist/parser/tests/expression/Boolean.spec.js +0 -83
  139. package/dist/parser/tests/expression/Boolean.spec.js.map +0 -1
  140. package/dist/parser/tests/expression/Call.spec.d.ts +0 -1
  141. package/dist/parser/tests/expression/Call.spec.js +0 -242
  142. package/dist/parser/tests/expression/Call.spec.js.map +0 -1
  143. package/dist/parser/tests/expression/Exponential.spec.d.ts +0 -1
  144. package/dist/parser/tests/expression/Exponential.spec.js +0 -37
  145. package/dist/parser/tests/expression/Exponential.spec.js.map +0 -1
  146. package/dist/parser/tests/expression/Function.spec.d.ts +0 -1
  147. package/dist/parser/tests/expression/Function.spec.js +0 -403
  148. package/dist/parser/tests/expression/Function.spec.js.map +0 -1
  149. package/dist/parser/tests/expression/Indexing.spec.d.ts +0 -1
  150. package/dist/parser/tests/expression/Indexing.spec.js +0 -289
  151. package/dist/parser/tests/expression/Indexing.spec.js.map +0 -1
  152. package/dist/parser/tests/expression/Multiplicative.spec.d.ts +0 -1
  153. package/dist/parser/tests/expression/Multiplicative.spec.js +0 -67
  154. package/dist/parser/tests/expression/Multiplicative.spec.js.map +0 -1
  155. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.d.ts +0 -1
  156. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +0 -346
  157. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +0 -1
  158. package/dist/parser/tests/expression/PrefixUnary.spec.d.ts +0 -1
  159. package/dist/parser/tests/expression/PrefixUnary.spec.js +0 -105
  160. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +0 -1
  161. package/dist/parser/tests/expression/Primary.spec.d.ts +0 -1
  162. package/dist/parser/tests/expression/Primary.spec.js +0 -149
  163. package/dist/parser/tests/expression/Primary.spec.js.map +0 -1
  164. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +0 -1
  165. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +0 -171
  166. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +0 -1
  167. package/dist/parser/tests/expression/Relational.spec.d.ts +0 -1
  168. package/dist/parser/tests/expression/Relational.spec.js +0 -83
  169. package/dist/parser/tests/expression/Relational.spec.js.map +0 -1
  170. package/dist/parser/tests/expression/SourceLiteralExpression.spec.d.ts +0 -1
  171. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +0 -201
  172. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +0 -1
  173. package/dist/parser/tests/expression/TemplateStringExpression.spec.d.ts +0 -1
  174. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +0 -389
  175. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +0 -1
  176. package/dist/parser/tests/expression/TernaryExpression.spec.d.ts +0 -1
  177. package/dist/parser/tests/expression/TernaryExpression.spec.js +0 -876
  178. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +0 -1
  179. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +0 -1
  180. package/dist/parser/tests/expression/UnaryExpression.spec.js +0 -52
  181. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +0 -1
  182. package/dist/parser/tests/statement/AssignmentOperators.spec.d.ts +0 -1
  183. package/dist/parser/tests/statement/AssignmentOperators.spec.js +0 -79
  184. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +0 -1
  185. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +0 -1
  186. package/dist/parser/tests/statement/ConstStatement.spec.js +0 -708
  187. package/dist/parser/tests/statement/ConstStatement.spec.js.map +0 -1
  188. package/dist/parser/tests/statement/Continue.spec.d.ts +0 -1
  189. package/dist/parser/tests/statement/Continue.spec.js +0 -119
  190. package/dist/parser/tests/statement/Continue.spec.js.map +0 -1
  191. package/dist/parser/tests/statement/Declaration.spec.d.ts +0 -1
  192. package/dist/parser/tests/statement/Declaration.spec.js +0 -108
  193. package/dist/parser/tests/statement/Declaration.spec.js.map +0 -1
  194. package/dist/parser/tests/statement/Dim.spec.d.ts +0 -1
  195. package/dist/parser/tests/statement/Dim.spec.js +0 -73
  196. package/dist/parser/tests/statement/Dim.spec.js.map +0 -1
  197. package/dist/parser/tests/statement/Enum.spec.d.ts +0 -1
  198. package/dist/parser/tests/statement/Enum.spec.js +0 -1307
  199. package/dist/parser/tests/statement/Enum.spec.js.map +0 -1
  200. package/dist/parser/tests/statement/For.spec.d.ts +0 -1
  201. package/dist/parser/tests/statement/For.spec.js +0 -45
  202. package/dist/parser/tests/statement/For.spec.js.map +0 -1
  203. package/dist/parser/tests/statement/ForEach.spec.d.ts +0 -1
  204. package/dist/parser/tests/statement/ForEach.spec.js +0 -36
  205. package/dist/parser/tests/statement/ForEach.spec.js.map +0 -1
  206. package/dist/parser/tests/statement/Function.spec.d.ts +0 -1
  207. package/dist/parser/tests/statement/Function.spec.js +0 -342
  208. package/dist/parser/tests/statement/Function.spec.js.map +0 -1
  209. package/dist/parser/tests/statement/Goto.spec.d.ts +0 -1
  210. package/dist/parser/tests/statement/Goto.spec.js +0 -51
  211. package/dist/parser/tests/statement/Goto.spec.js.map +0 -1
  212. package/dist/parser/tests/statement/Increment.spec.d.ts +0 -1
  213. package/dist/parser/tests/statement/Increment.spec.js +0 -117
  214. package/dist/parser/tests/statement/Increment.spec.js.map +0 -1
  215. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +0 -1
  216. package/dist/parser/tests/statement/InterfaceStatement.spec.js +0 -102
  217. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +0 -1
  218. package/dist/parser/tests/statement/LibraryStatement.spec.d.ts +0 -1
  219. package/dist/parser/tests/statement/LibraryStatement.spec.js +0 -74
  220. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +0 -1
  221. package/dist/parser/tests/statement/Misc.spec.d.ts +0 -1
  222. package/dist/parser/tests/statement/Misc.spec.js +0 -335
  223. package/dist/parser/tests/statement/Misc.spec.js.map +0 -1
  224. package/dist/parser/tests/statement/PrintStatement.spec.d.ts +0 -1
  225. package/dist/parser/tests/statement/PrintStatement.spec.js +0 -195
  226. package/dist/parser/tests/statement/PrintStatement.spec.js.map +0 -1
  227. package/dist/parser/tests/statement/ReturnStatement.spec.d.ts +0 -1
  228. package/dist/parser/tests/statement/ReturnStatement.spec.js +0 -94
  229. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +0 -1
  230. package/dist/parser/tests/statement/Set.spec.d.ts +0 -1
  231. package/dist/parser/tests/statement/Set.spec.js +0 -218
  232. package/dist/parser/tests/statement/Set.spec.js.map +0 -1
  233. package/dist/parser/tests/statement/Stop.spec.d.ts +0 -1
  234. package/dist/parser/tests/statement/Stop.spec.js +0 -38
  235. package/dist/parser/tests/statement/Stop.spec.js.map +0 -1
  236. package/dist/parser/tests/statement/Throw.spec.d.ts +0 -1
  237. package/dist/parser/tests/statement/Throw.spec.js +0 -35
  238. package/dist/parser/tests/statement/Throw.spec.js.map +0 -1
  239. package/dist/parser/tests/statement/TryCatch.spec.d.ts +0 -1
  240. package/dist/parser/tests/statement/TryCatch.spec.js +0 -142
  241. package/dist/parser/tests/statement/TryCatch.spec.js.map +0 -1
  242. package/dist/preprocessor/Manifest.spec.d.ts +0 -1
  243. package/dist/preprocessor/Manifest.spec.js +0 -80
  244. package/dist/preprocessor/Manifest.spec.js.map +0 -1
  245. package/dist/preprocessor/Preprocessor.spec.d.ts +0 -1
  246. package/dist/preprocessor/Preprocessor.spec.js +0 -152
  247. package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
  248. package/dist/preprocessor/PreprocessorParser.spec.d.ts +0 -1
  249. package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
  250. package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
  251. package/dist/types/ArrayType.spec.d.ts +0 -1
  252. package/dist/types/ArrayType.spec.js +0 -30
  253. package/dist/types/ArrayType.spec.js.map +0 -1
  254. package/dist/types/BooleanType.spec.d.ts +0 -1
  255. package/dist/types/BooleanType.spec.js +0 -12
  256. package/dist/types/BooleanType.spec.js.map +0 -1
  257. package/dist/types/DoubleType.spec.d.ts +0 -1
  258. package/dist/types/DoubleType.spec.js +0 -12
  259. package/dist/types/DoubleType.spec.js.map +0 -1
  260. package/dist/types/DynamicType.spec.d.ts +0 -1
  261. package/dist/types/DynamicType.spec.js +0 -12
  262. package/dist/types/DynamicType.spec.js.map +0 -1
  263. package/dist/types/FloatType.spec.d.ts +0 -1
  264. package/dist/types/FloatType.spec.js +0 -12
  265. package/dist/types/FloatType.spec.js.map +0 -1
  266. package/dist/types/FunctionType.spec.d.ts +0 -1
  267. package/dist/types/FunctionType.spec.js +0 -23
  268. package/dist/types/FunctionType.spec.js.map +0 -1
  269. package/dist/types/IntegerType.spec.d.ts +0 -1
  270. package/dist/types/IntegerType.spec.js +0 -12
  271. package/dist/types/IntegerType.spec.js.map +0 -1
  272. package/dist/types/InterfaceType.spec.d.ts +0 -1
  273. package/dist/types/InterfaceType.spec.js +0 -175
  274. package/dist/types/InterfaceType.spec.js.map +0 -1
  275. package/dist/types/InvalidType.spec.d.ts +0 -1
  276. package/dist/types/InvalidType.spec.js +0 -12
  277. package/dist/types/InvalidType.spec.js.map +0 -1
  278. package/dist/types/LongIntegerType.spec.d.ts +0 -1
  279. package/dist/types/LongIntegerType.spec.js +0 -12
  280. package/dist/types/LongIntegerType.spec.js.map +0 -1
  281. package/dist/types/ObjectType.spec.d.ts +0 -1
  282. package/dist/types/ObjectType.spec.js +0 -12
  283. package/dist/types/ObjectType.spec.js.map +0 -1
  284. package/dist/types/StringType.spec.d.ts +0 -1
  285. package/dist/types/StringType.spec.js +0 -12
  286. package/dist/types/StringType.spec.js.map +0 -1
  287. package/dist/types/VoidType.spec.d.ts +0 -1
  288. package/dist/types/VoidType.spec.js +0 -12
  289. package/dist/types/VoidType.spec.js.map +0 -1
@@ -1,1985 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.failStatementType = exports.rangeToArray = void 0;
4
- const chai_config_spec_1 = require("../chai-config.spec");
5
- const Lexer_1 = require("../lexer/Lexer");
6
- const TokenKind_1 = require("../lexer/TokenKind");
7
- const Expression_1 = require("./Expression");
8
- const Parser_1 = require("./Parser");
9
- const Statement_1 = require("./Statement");
10
- const vscode_languageserver_1 = require("vscode-languageserver");
11
- const DiagnosticMessages_1 = require("../DiagnosticMessages");
12
- const reflection_1 = require("../astUtils/reflection");
13
- const testHelpers_spec_1 = require("../testHelpers.spec");
14
- const BrsTranspileState_1 = require("./BrsTranspileState");
15
- const source_map_1 = require("source-map");
16
- const BrsFile_1 = require("../files/BrsFile");
17
- const Program_1 = require("../Program");
18
- const visitors_1 = require("../astUtils/visitors");
19
- describe('parser', () => {
20
- it('emits empty object when empty token list is provided', () => {
21
- (0, chai_config_spec_1.expect)(Parser_1.Parser.parse([])).to.deep.include({
22
- statements: [],
23
- diagnostics: []
24
- });
25
- });
26
- describe('findReferences', () => {
27
- it('gets called if references are missing', () => {
28
- const parser = Parser_1.Parser.parse(`
29
- sub main()
30
- end sub
31
-
32
- sub UnusedFunction()
33
- end sub
34
- `);
35
- (0, chai_config_spec_1.expect)(parser.references.functionStatements.map(x => x.name.text)).to.eql([
36
- 'main',
37
- 'UnusedFunction'
38
- ]);
39
- //simulate a tree-shaking plugin by removing the `UnusedFunction`
40
- parser.ast.statements.splice(1);
41
- //tell the parser we modified the AST and need to regenerate references
42
- parser.invalidateReferences();
43
- (0, chai_config_spec_1.expect)(parser['_references']).not.to.exist;
44
- //calling `references` automatically regenerates the references
45
- (0, chai_config_spec_1.expect)(parser.references.functionStatements.map(x => x.name.text)).to.eql([
46
- 'main'
47
- ]);
48
- });
49
- function expressionsToStrings(expressions) {
50
- return [...expressions.values()].map(x => {
51
- const file = new BrsFile_1.BrsFile('', '', new Program_1.Program({}));
52
- const state = new BrsTranspileState_1.BrsTranspileState(file);
53
- return new source_map_1.SourceNode(null, null, null, x.transpile(state)).toString();
54
- });
55
- }
56
- it('works for references.expressions', () => {
57
- const parser = Parser_1.Parser.parse(`
58
- b += "plus-equal"
59
- a += 1 + 2
60
- b += getValue1() + getValue2()
61
- increment++
62
- decrement--
63
- some.node@.doCallfunc()
64
- bravo(3 + 4).jump(callMe())
65
- obj = {
66
- val1: someValue
67
- }
68
- arr = [
69
- one
70
- ]
71
- thing = alpha.bravo
72
- alpha.charlie()
73
- delta(alpha.delta)
74
- call1().a.b.call2()
75
- class Person
76
- name as string = "bob"
77
- end class
78
- function thing(p1 = name.space.getSomething())
79
-
80
- end function
81
- `);
82
- const expected = [
83
- '"plus-equal"',
84
- 'b',
85
- 'b += "plus-equal"',
86
- '1',
87
- '2',
88
- 'a',
89
- 'a += 1 + 2',
90
- 'getValue1()',
91
- 'getValue2()',
92
- 'b',
93
- 'b += getValue1() + getValue2()',
94
- 'increment++',
95
- 'decrement--',
96
- //currently the "toString" does a transpile, so that's why this is different.
97
- 'some.node.callfunc("doCallfunc", invalid)',
98
- '3',
99
- '4',
100
- '3 + 4',
101
- 'callMe()',
102
- 'bravo(3 + 4).jump(callMe())',
103
- 'someValue',
104
- '{\n val1: someValue\n}',
105
- 'one',
106
- '[\n one\n]',
107
- 'alpha.bravo',
108
- 'alpha.charlie()',
109
- 'alpha.delta',
110
- 'delta(alpha.delta)',
111
- 'call1().a.b.call2()',
112
- '"bob"',
113
- 'name.space.getSomething()'
114
- ];
115
- (0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions)).to.eql(expected);
116
- //tell the parser we modified the AST and need to regenerate references
117
- parser.invalidateReferences();
118
- (0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions).sort()).to.eql(expected.sort());
119
- });
120
- it('works for references.expressions', () => {
121
- const parser = Parser_1.Parser.parse(`
122
- value = true or type(true) = "something" or Enums.A.Value = "value" and Enum1.Value = Name.Space.Enum2.Value
123
- `);
124
- const expected = [
125
- 'true',
126
- 'type(true)',
127
- '"something"',
128
- 'true',
129
- 'Enums.A.Value',
130
- '"value"',
131
- 'Enum1.Value',
132
- 'Name.Space.Enum2.Value',
133
- 'true or type(true) = "something" or Enums.A.Value = "value" and Enum1.Value = Name.Space.Enum2.Value'
134
- ];
135
- (0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions)).to.eql(expected);
136
- //tell the parser we modified the AST and need to regenerate references
137
- parser.invalidateReferences();
138
- (0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions).sort()).to.eql(expected.sort());
139
- });
140
- it('works for logical expression', () => {
141
- const parser = Parser_1.Parser.parse(`
142
- value = Enums.A.Value = "value"
143
- `);
144
- const expected = [
145
- 'Enums.A.Value',
146
- '"value"',
147
- 'Enums.A.Value = "value"'
148
- ];
149
- (0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions)).to.eql(expected);
150
- //tell the parser we modified the AST and need to regenerate references
151
- parser.invalidateReferences();
152
- (0, chai_config_spec_1.expect)(expressionsToStrings(parser.references.expressions).sort()).to.eql(expected.sort());
153
- });
154
- });
155
- describe('callfunc operator', () => {
156
- it('is not allowed in brightscript mode', () => {
157
- var _a;
158
- let parser = parse(`
159
- sub main(node as dynamic)
160
- node@.doSomething(1, 2)
161
- end sub
162
- `, Parser_1.ParseMode.BrightScript);
163
- (0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('callfunc operator').message);
164
- });
165
- it('does not cause parse errors', () => {
166
- var _a, _b, _c, _d, _e;
167
- let parser = parse(`
168
- sub main(node as dynamic)
169
- node@.doSomething(1, 2)
170
- end sub
171
- `, Parser_1.ParseMode.BrighterScript);
172
- (0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
173
- (0, chai_config_spec_1.expect)((_e = (_d = (_c = (_b = parser.statements[0]) === null || _b === void 0 ? void 0 : _b.func) === null || _c === void 0 ? void 0 : _c.body) === null || _d === void 0 ? void 0 : _d.statements[0]) === null || _e === void 0 ? void 0 : _e.expression).to.be.instanceof(Expression_1.CallfuncExpression);
174
- });
175
- });
176
- describe('optional chaining operator', () => {
177
- function getExpression(text, options) {
178
- const parser = parse(text, options === null || options === void 0 ? void 0 : options.parseMode);
179
- (0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
180
- const expressions = [...parser.references.expressions];
181
- if (options === null || options === void 0 ? void 0 : options.matcher) {
182
- return expressions.find(options.matcher);
183
- }
184
- else {
185
- return expressions[0];
186
- }
187
- }
188
- it('works for ?.', () => {
189
- const expression = getExpression(`value = person?.name`);
190
- (0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.DottedGetExpression);
191
- (0, chai_config_spec_1.expect)(expression.dot.kind).to.eql(TokenKind_1.TokenKind.QuestionDot);
192
- });
193
- it('works for ?[', () => {
194
- const expression = getExpression(`value = person?["name"]`, { matcher: reflection_1.isIndexedGetExpression });
195
- (0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.IndexedGetExpression);
196
- (0, chai_config_spec_1.expect)(expression.openingSquare.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftSquare);
197
- (0, chai_config_spec_1.expect)(expression.questionDotToken).not.to.exist;
198
- });
199
- it('works for ?.[', () => {
200
- var _a;
201
- const expression = getExpression(`value = person?.["name"]`, { matcher: reflection_1.isIndexedGetExpression });
202
- (0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.IndexedGetExpression);
203
- (0, chai_config_spec_1.expect)(expression.openingSquare.kind).to.eql(TokenKind_1.TokenKind.LeftSquareBracket);
204
- (0, chai_config_spec_1.expect)((_a = expression.questionDotToken) === null || _a === void 0 ? void 0 : _a.kind).to.eql(TokenKind_1.TokenKind.QuestionDot);
205
- });
206
- it('works for ?@', () => {
207
- const expression = getExpression(`value = someXml?@someAttr`);
208
- (0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.XmlAttributeGetExpression);
209
- (0, chai_config_spec_1.expect)(expression.at.kind).to.eql(TokenKind_1.TokenKind.QuestionAt);
210
- });
211
- it('works for ?(', () => {
212
- const expression = getExpression(`value = person.getName?()`);
213
- (0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.CallExpression);
214
- (0, chai_config_spec_1.expect)(expression.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
215
- });
216
- it('works for print statements using question mark', () => {
217
- const { statements } = parse(`
218
- ?[1]
219
- ?(1+1)
220
- `);
221
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceOf(Statement_1.PrintStatement);
222
- (0, chai_config_spec_1.expect)(statements[1]).to.be.instanceOf(Statement_1.PrintStatement);
223
- });
224
- //TODO enable this once we properly parse IIFEs
225
- it.skip('works for ?( in anonymous function', () => {
226
- const expression = getExpression(`thing = (function() : end function)?()`);
227
- (0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.CallExpression);
228
- (0, chai_config_spec_1.expect)(expression.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
229
- });
230
- it('works for ?( in new call', () => {
231
- const expression = getExpression(`thing = new Person?()`, { parseMode: Parser_1.ParseMode.BrighterScript });
232
- (0, chai_config_spec_1.expect)(expression).to.be.instanceOf(Expression_1.NewExpression);
233
- (0, chai_config_spec_1.expect)(expression.call.openingParen.kind).to.eql(TokenKind_1.TokenKind.QuestionLeftParen);
234
- });
235
- it('distinguishes between optional chaining and ternary expression', () => {
236
- const parser = parse(`
237
- sub main()
238
- name = person?["name"]
239
- isTrue = true
240
- key = isTrue ? ["name"] : ["age"]
241
- end sub
242
- `, Parser_1.ParseMode.BrighterScript);
243
- (0, chai_config_spec_1.expect)(parser.references.assignmentStatements[0].value).is.instanceof(Expression_1.IndexedGetExpression);
244
- (0, chai_config_spec_1.expect)(parser.references.assignmentStatements[2].value).is.instanceof(Expression_1.TernaryExpression);
245
- });
246
- it('distinguishes between optional chaining and ternary expression', () => {
247
- const parser = parse(`
248
- sub main()
249
- 'optional chain. the lack of whitespace between ? and [ matters
250
- key = isTrue ?["name"] : getDefault()
251
- 'ternary
252
- key = isTrue ? ["name"] : getDefault()
253
- end sub
254
- `, Parser_1.ParseMode.BrighterScript);
255
- (0, chai_config_spec_1.expect)(parser.references.assignmentStatements[0].value).is.instanceof(Expression_1.IndexedGetExpression);
256
- (0, chai_config_spec_1.expect)(parser.references.assignmentStatements[1].value).is.instanceof(Expression_1.TernaryExpression);
257
- });
258
- });
259
- describe('diagnostic locations', () => {
260
- it('tracks basic diagnostic locations', () => {
261
- (0, chai_config_spec_1.expect)(parse(`
262
- sub main()
263
- call()a
264
- end sub
265
- `).diagnostics.map(x => rangeToArray(x.range))).to.eql([
266
- [2, 26, 2, 27],
267
- [2, 27, 2, 28]
268
- ]);
269
- });
270
- it.skip('handles edge cases', () => {
271
- var _a, _b;
272
- let diagnostics = parse(`
273
- function BuildCommit()
274
- return "6c5cdf1"
275
- end functionasdf
276
- `).diagnostics;
277
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist.and.to.eql(DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression().message);
278
- (0, chai_config_spec_1.expect)((_b = diagnostics[0]) === null || _b === void 0 ? void 0 : _b.range).to.eql(vscode_languageserver_1.Range.create(3, 20, 3, 32));
279
- });
280
- });
281
- describe('parse', () => {
282
- it('supports ungrouped iife in assignment', () => {
283
- const parser = parse(`
284
- sub main()
285
- result = sub()
286
- end sub()
287
- result = function()
288
- end function()
289
- end sub
290
- `);
291
- (0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
292
- });
293
- it('supports grouped iife in assignment', () => {
294
- const parser = parse(`
295
- sub main()
296
- result = (sub()
297
- end sub)()
298
- result = (function()
299
- end function)()
300
- end sub
301
- `);
302
- (0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
303
- });
304
- it('supports returning iife call', () => {
305
- const parser = parse(`
306
- sub main()
307
- return (sub()
308
- end sub)()
309
- end sub
310
- `);
311
- (0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
312
- });
313
- it('supports using "interface" as parameter name', () => {
314
- var _a;
315
- (0, chai_config_spec_1.expect)((_a = parse(`
316
- sub main(interface as object)
317
- end sub
318
- `, Parser_1.ParseMode.BrighterScript).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
319
- });
320
- it('does not scrap the entire function when encountering unknown parameter type', () => {
321
- const parser = parse(`
322
- sub test(param1 as unknownType)
323
- end sub
324
- `);
325
- (0, testHelpers_spec_1.expectDiagnostics)(parser, [Object.assign({}, DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid('param1', 'unknownType'))]);
326
- (0, chai_config_spec_1.expect)((0, reflection_1.isFunctionStatement)(parser.ast.statements[0])).to.be.true;
327
- });
328
- describe('namespace', () => {
329
- it('allows namespaces declared inside other namespaces', () => {
330
- const parser = parse(`
331
- namespace Level1
332
- namespace Level2.Level3
333
- sub main()
334
- end sub
335
- end namespace
336
- end namespace
337
- `, Parser_1.ParseMode.BrighterScript);
338
- (0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
339
- // We expect these names to be "as given" in this context, because we aren't evaluating a full program.
340
- (0, chai_config_spec_1.expect)(parser.references.namespaceStatements.map(statement => statement.getName(Parser_1.ParseMode.BrighterScript))).to.deep.equal([
341
- 'Level1.Level2.Level3',
342
- 'Level1'
343
- ]);
344
- });
345
- it('parses empty namespace', () => {
346
- var _a;
347
- let { statements, diagnostics } = parse(`
348
- namespace Name.Space
349
- end namespace
350
- `, Parser_1.ParseMode.BrighterScript);
351
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
352
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
353
- });
354
- it('includes body', () => {
355
- var _a;
356
- let { statements, diagnostics } = parse(`
357
- namespace Name.Space
358
- sub main()
359
- end sub
360
- end namespace
361
- `, Parser_1.ParseMode.BrighterScript);
362
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
363
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
364
- (0, chai_config_spec_1.expect)(statements[0].body.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
365
- });
366
- it('supports comments and newlines', () => {
367
- var _a;
368
- let { diagnostics } = parse(`
369
- namespace Name.Space 'comment
370
-
371
- 'comment
372
-
373
- sub main() 'comment
374
- end sub 'comment
375
- 'comment
376
-
377
- 'comment
378
- end namespace 'comment
379
- `, Parser_1.ParseMode.BrighterScript);
380
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
381
- });
382
- it('catches missing name', () => {
383
- var _a;
384
- let { diagnostics } = parse(`
385
- namespace
386
- end namespace
387
- `, Parser_1.ParseMode.BrighterScript);
388
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('namespace').message);
389
- });
390
- it('recovers after missing `end namespace`', () => {
391
- var _a, _b, _c;
392
- let parser = parse(`
393
- namespace Name.Space
394
- sub main()
395
- end sub
396
- `, Parser_1.ParseMode.BrighterScript);
397
- (0, chai_config_spec_1.expect)(parser.ast.statements[0]).to.be.instanceof(Statement_1.NamespaceStatement);
398
- (0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.couldNotFindMatchingEndKeyword('namespace').message);
399
- (0, chai_config_spec_1.expect)((_c = (_b = parser.ast.statements[0]) === null || _b === void 0 ? void 0 : _b.body) === null || _c === void 0 ? void 0 : _c.statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
400
- });
401
- it('adds diagnostic when encountering namespace in brightscript mode', () => {
402
- var _a;
403
- let parser = Parser_1.Parser.parse(`
404
- namespace Name.Space
405
- end namespace
406
- `);
407
- (0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('namespace').message);
408
- });
409
- });
410
- it('supports << operator', () => {
411
- var _a;
412
- (0, chai_config_spec_1.expect)((_a = parse(`
413
- sub main()
414
- print ((r << 24) + (g << 16) + (b << 8) + a)
415
- end sub
416
- `).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
417
- });
418
- it('supports >> operator', () => {
419
- var _a;
420
- (0, chai_config_spec_1.expect)((_a = parse(`
421
- sub main()
422
- print ((r >> 24) + (g >> 16) + (b >> 8) + a)
423
- end sub
424
- `).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
425
- });
426
- it('allows global function names with same as token to be called', () => {
427
- var _a;
428
- (0, chai_config_spec_1.expect)((_a = parse(`
429
- sub main()
430
- print string(123)
431
- end sub
432
- `).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
433
- });
434
- it('supports @ symbol between names', () => {
435
- var _a;
436
- let parser = parse(`
437
- sub main()
438
- firstName = personXml@firstName
439
- age = personXml.firstChild@age
440
- end sub
441
- `);
442
- (0, chai_config_spec_1.expect)((_a = parser.diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
443
- let statements = parser.statements[0].func.body.statements;
444
- let first = statements[0].value;
445
- (0, chai_config_spec_1.expect)(first).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
446
- (0, chai_config_spec_1.expect)(first.name.text).to.equal('firstName');
447
- (0, chai_config_spec_1.expect)(first.at.text).to.equal('@');
448
- (0, chai_config_spec_1.expect)(first.obj.name.text).to.equal('personXml');
449
- let second = statements[1].value;
450
- (0, chai_config_spec_1.expect)(second).to.be.instanceof(Expression_1.XmlAttributeGetExpression);
451
- (0, chai_config_spec_1.expect)(second.name.text).to.equal('age');
452
- (0, chai_config_spec_1.expect)(second.at.text).to.equal('@');
453
- (0, chai_config_spec_1.expect)(second.obj.name.text).to.equal('firstChild');
454
- });
455
- it('does not allow chaining of @ symbols', () => {
456
- let parser = parse(`
457
- sub main()
458
- personXml = invalid
459
- name = personXml@name@age@shoeSize
460
- end sub
461
- `);
462
- (0, chai_config_spec_1.expect)(parser.diagnostics).not.to.be.empty;
463
- });
464
- it('unknown function type does not invalidate rest of function', () => {
465
- let { statements, diagnostics } = parse(`
466
- function log() as UNKNOWN_TYPE
467
- end function
468
- `, Parser_1.ParseMode.BrightScript);
469
- (0, chai_config_spec_1.expect)(diagnostics.length).to.be.greaterThan(0);
470
- (0, chai_config_spec_1.expect)(statements[0]).to.exist;
471
- });
472
- it('unknown function type is not a problem in Brighterscript mode', () => {
473
- let { statements, diagnostics } = parse(`
474
- function log() as UNKNOWN_TYPE
475
- end function
476
- `, Parser_1.ParseMode.BrighterScript);
477
- (0, chai_config_spec_1.expect)(diagnostics.length).to.equal(0);
478
- (0, chai_config_spec_1.expect)(statements[0]).to.exist;
479
- });
480
- it('allows namespaced function type in Brighterscript mode', () => {
481
- let { statements, diagnostics } = parse(`
482
- function log() as SOME_NAMESPACE.UNKNOWN_TYPE
483
- end function
484
- `, Parser_1.ParseMode.BrighterScript);
485
- (0, chai_config_spec_1.expect)(diagnostics.length).to.equal(0);
486
- (0, chai_config_spec_1.expect)(statements[0]).to.exist;
487
- });
488
- it('allows custom parameter types in BrighterscriptMode', () => {
489
- let { statements, diagnostics } = parse(`
490
- sub foo(value as UNKNOWN_TYPE)
491
- end sub
492
- `, Parser_1.ParseMode.BrighterScript);
493
- (0, chai_config_spec_1.expect)(diagnostics.length).to.equal(0);
494
- (0, chai_config_spec_1.expect)(statements[0]).to.exist;
495
- });
496
- it('does not allow custom parameter types in Brightscript Mode', () => {
497
- let { diagnostics } = parse(`
498
- sub foo(value as UNKNOWN_TYPE)
499
- end sub
500
- `, Parser_1.ParseMode.BrightScript);
501
- (0, chai_config_spec_1.expect)(diagnostics.length).not.to.equal(0);
502
- });
503
- it('allows custom namespaced parameter types in BrighterscriptMode', () => {
504
- let { statements, diagnostics } = parse(`
505
- sub foo(value as SOME_NAMESPACE.UNKNOWN_TYPE)
506
- end sub
507
- `, Parser_1.ParseMode.BrighterScript);
508
- (0, chai_config_spec_1.expect)(diagnostics.length).to.equal(0);
509
- (0, chai_config_spec_1.expect)(statements[0]).to.exist;
510
- });
511
- it('works with conditionals', () => {
512
- var _a;
513
- (0, chai_config_spec_1.expect)((_a = parse(`
514
- function printNumber()
515
- if true then
516
- print 1
517
- else if true
518
- return false
519
- end if
520
- end function
521
- `).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
522
- });
523
- it('supports single-line if statements', () => {
524
- var _a;
525
- (0, chai_config_spec_1.expect)((_a = parse(`If true Then print "error" : Stop`).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
526
- });
527
- it('works with excess newlines', () => {
528
- var _a;
529
- let { tokens } = Lexer_1.Lexer.scan('function boolToNumber() as string\n\n' +
530
- ' if true then\n\n' +
531
- ' print 1\n\n' +
532
- ' elseif true then\n\n' +
533
- ' print 0\n\n' +
534
- ' else\n\n' +
535
- ' print 1\n\n' +
536
- ' end if\n\n' +
537
- 'end function\n\n');
538
- (0, chai_config_spec_1.expect)((_a = Parser_1.Parser.parse(tokens).diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.not.exist;
539
- });
540
- it('does not invalidate entire file when line ends with a period', () => {
541
- let { tokens } = Lexer_1.Lexer.scan(`
542
- sub main()
543
- person.a
544
- end sub
545
-
546
- `);
547
- let { diagnostics } = Parser_1.Parser.parse(tokens);
548
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(1, 'Error count should be 0');
549
- });
550
- it.skip('allows printing object with trailing period', () => {
551
- let { tokens } = Lexer_1.Lexer.scan(`print a.`);
552
- let { statements, diagnostics } = Parser_1.Parser.parse(tokens);
553
- let printStatement = statements[0];
554
- (0, chai_config_spec_1.expect)(diagnostics).to.be.empty;
555
- (0, chai_config_spec_1.expect)(printStatement).to.be.instanceof(Statement_1.PrintStatement);
556
- (0, chai_config_spec_1.expect)(printStatement.expressions[0]).to.be.instanceof(Expression_1.DottedGetExpression);
557
- });
558
- describe('comments', () => {
559
- it('combines multi-line comments', () => {
560
- let { tokens } = Lexer_1.Lexer.scan(`
561
- 'line 1
562
- 'line 2
563
- 'line 3
564
- `);
565
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
566
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
567
- (0, chai_config_spec_1.expect)(statements[0].text).to.equal(`'line 1\n'line 2\n'line 3`);
568
- });
569
- it('does not combile comments separated by newlines', () => {
570
- let { tokens } = Lexer_1.Lexer.scan(`
571
- 'line 1
572
-
573
- 'line 2
574
-
575
- 'line 3
576
- `);
577
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
578
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
579
- (0, chai_config_spec_1.expect)(statements).to.be.lengthOf(3);
580
- (0, chai_config_spec_1.expect)(statements[0].text).to.equal(`'line 1`);
581
- (0, chai_config_spec_1.expect)(statements[1].text).to.equal(`'line 2`);
582
- (0, chai_config_spec_1.expect)(statements[2].text).to.equal(`'line 3`);
583
- });
584
- it('works after print statement', () => {
585
- let { tokens } = Lexer_1.Lexer.scan(`
586
- sub main()
587
- print "hi" 'comment 1
588
- end sub
589
- `);
590
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
591
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
592
- (0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 1`);
593
- });
594
- it('declaration-level', () => {
595
- let { tokens } = Lexer_1.Lexer.scan(`
596
- 'comment 1
597
- function a()
598
- end function
599
- 'comment 2
600
- `);
601
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
602
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
603
- (0, chai_config_spec_1.expect)(statements[0].text).to.equal(`'comment 1`);
604
- (0, chai_config_spec_1.expect)(statements[2].text).to.equal(`'comment 2`);
605
- });
606
- it('works in aa literal as its own statement', () => {
607
- let { tokens } = Lexer_1.Lexer.scan(`
608
- obj = {
609
- "name": true,
610
- 'comment
611
- }
612
- `);
613
- let { diagnostics } = Parser_1.Parser.parse(tokens);
614
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be 0');
615
- });
616
- it('parses after function call', () => {
617
- let { tokens } = Lexer_1.Lexer.scan(`
618
- sub Main()
619
- name = "Hello"
620
- DoSomething(name) 'comment 1
621
- end sub
622
- `);
623
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
624
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
625
- (0, chai_config_spec_1.expect)(statements[0].func.body.statements[2].text).to.equal(`'comment 1`);
626
- });
627
- it('function', () => {
628
- let { tokens } = Lexer_1.Lexer.scan(`
629
- function a() 'comment 1
630
- 'comment 2
631
- num = 1
632
- 'comment 3
633
- end function 'comment 4
634
- `);
635
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
636
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
637
- (0, chai_config_spec_1.expect)(statements[0].func.body.statements[0].text).to.equal(`'comment 1`);
638
- (0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 2`);
639
- (0, chai_config_spec_1.expect)(statements[0].func.body.statements[3].text).to.equal(`'comment 3`);
640
- (0, chai_config_spec_1.expect)(statements[1].text).to.equal(`'comment 4`);
641
- });
642
- it('if statement`', () => {
643
- let { tokens } = Lexer_1.Lexer.scan(`
644
- function a()
645
- if true then 'comment 1
646
- 'comment 2
647
- print "hello"
648
- 'comment 3
649
- else if true then 'comment 4
650
- 'comment 5
651
- print "hello"
652
- 'comment 6
653
- else 'comment 7
654
- 'comment 8
655
- print "hello"
656
- 'comment 9
657
- end if 'comment 10
658
- end function
659
- `);
660
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
661
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Should have zero diagnostics');
662
- let fnSmt = statements[0];
663
- if ((0, reflection_1.isFunctionStatement)(fnSmt)) {
664
- let ifStmt = fnSmt.func.body.statements[0];
665
- if ((0, reflection_1.isIfStatement)(ifStmt)) {
666
- expectCommentWithText(ifStmt.thenBranch.statements[0], `'comment 1`);
667
- expectCommentWithText(ifStmt.thenBranch.statements[1], `'comment 2`);
668
- expectCommentWithText(ifStmt.thenBranch.statements[3], `'comment 3`);
669
- let elseIfBranch = ifStmt.elseBranch;
670
- if ((0, reflection_1.isIfStatement)(elseIfBranch)) {
671
- expectCommentWithText(elseIfBranch.thenBranch.statements[0], `'comment 4`);
672
- expectCommentWithText(elseIfBranch.thenBranch.statements[1], `'comment 5`);
673
- expectCommentWithText(elseIfBranch.thenBranch.statements[3], `'comment 6`);
674
- let elseBranch = elseIfBranch.elseBranch;
675
- if ((0, reflection_1.isBlock)(elseBranch)) {
676
- expectCommentWithText(elseBranch.statements[0], `'comment 7`);
677
- expectCommentWithText(elseBranch.statements[1], `'comment 8`);
678
- expectCommentWithText(elseBranch.statements[3], `'comment 9`);
679
- }
680
- else {
681
- failStatementType(elseBranch, 'Block');
682
- }
683
- }
684
- else {
685
- failStatementType(elseIfBranch, 'If');
686
- }
687
- expectCommentWithText(fnSmt.func.body.statements[1], `'comment 10`);
688
- }
689
- else {
690
- failStatementType(ifStmt, 'If');
691
- }
692
- }
693
- else {
694
- failStatementType(fnSmt, 'Function');
695
- }
696
- });
697
- it('while', () => {
698
- let { tokens } = Lexer_1.Lexer.scan(`
699
- function a()
700
- while true 'comment 1
701
- 'comment 2
702
- print "true"
703
- 'comment 3
704
- end while 'comment 4
705
- end function
706
- `);
707
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
708
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
709
- let stmt = statements[0].func.body.statements[0];
710
- (0, chai_config_spec_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
711
- (0, chai_config_spec_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
712
- (0, chai_config_spec_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
713
- (0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
714
- });
715
- it('for', () => {
716
- let { tokens } = Lexer_1.Lexer.scan(`
717
- function a()
718
- for i = 0 to 10 step 1 'comment 1
719
- 'comment 2
720
- print 1
721
- 'comment 3
722
- end for 'comment 4
723
- end function
724
- `);
725
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
726
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
727
- let stmt = statements[0].func.body.statements[0];
728
- (0, chai_config_spec_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
729
- (0, chai_config_spec_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
730
- (0, chai_config_spec_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
731
- (0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
732
- });
733
- it('for each', () => {
734
- let { tokens } = Lexer_1.Lexer.scan(`
735
- function a()
736
- for each val in [1,2,3] 'comment 1
737
- 'comment 2
738
- print 1
739
- 'comment 3
740
- end for 'comment 4
741
- end function
742
- `);
743
- let { diagnostics, statements } = Parser_1.Parser.parse(tokens);
744
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(0, 'Error count should be zero');
745
- let stmt = statements[0].func.body.statements[0];
746
- (0, chai_config_spec_1.expect)(stmt.body.statements[0].text).to.equal(`'comment 1`);
747
- (0, chai_config_spec_1.expect)(stmt.body.statements[1].text).to.equal(`'comment 2`);
748
- (0, chai_config_spec_1.expect)(stmt.body.statements[3].text).to.equal(`'comment 3`);
749
- (0, chai_config_spec_1.expect)(statements[0].func.body.statements[1].text).to.equal(`'comment 4`);
750
- });
751
- });
752
- });
753
- describe('reservedWords', () => {
754
- describe('`then`', () => {
755
- it('is not allowed as a local identifier', () => {
756
- let { diagnostics } = parse(`
757
- sub main()
758
- then = true
759
- end sub
760
- `);
761
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(1);
762
- });
763
- it('is allowed as an AA property name', () => {
764
- var _a;
765
- let { diagnostics } = parse(`
766
- sub main()
767
- person = {
768
- then: true
769
- }
770
- person.then = false
771
- print person.then
772
- end sub
773
- `);
774
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
775
- });
776
- it('allows `mod` as an AA literal property', () => {
777
- const parser = parse(`
778
- sub main()
779
- person = {
780
- mod: true
781
- }
782
- person.mod = false
783
- print person.mod
784
- end sub
785
- `);
786
- (0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
787
- });
788
- it('converts aa literal property TokenKind to Identifier', () => {
789
- const parser = parse(`
790
- sub main()
791
- person = {
792
- mod: true
793
- and: true
794
- }
795
- end sub
796
- `);
797
- (0, testHelpers_spec_1.expectZeroDiagnostics)(parser);
798
- const elements = [];
799
- parser.ast.walk((0, visitors_1.createVisitor)({
800
- AAMemberExpression: (node) => {
801
- elements.push(node);
802
- }
803
- }), {
804
- walkMode: visitors_1.WalkMode.visitAllRecursive
805
- });
806
- (0, chai_config_spec_1.expect)(elements.map(x => x.keyToken.kind)).to.eql([TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.Identifier]);
807
- });
808
- });
809
- it('"end" is not allowed as a local identifier', () => {
810
- let { diagnostics } = parse(`
811
- sub main()
812
- end = true
813
- end sub
814
- `);
815
- (0, chai_config_spec_1.expect)(diagnostics).to.be.length.greaterThan(0);
816
- });
817
- it('none of them can be used as local variables', () => {
818
- let reservedWords = new Set(TokenKind_1.ReservedWords);
819
- //remove the rem keyword because it's a comment...won't cause error
820
- reservedWords.delete('rem');
821
- for (let reservedWord of reservedWords) {
822
- let { tokens } = Lexer_1.Lexer.scan(`
823
- sub main()
824
- ${reservedWord} = true
825
- end sub
826
- `);
827
- let { diagnostics } = Parser_1.Parser.parse(tokens);
828
- (0, chai_config_spec_1.expect)(diagnostics, `assigning to reserved word "${reservedWord}" should have been an error`).to.be.length.greaterThan(0);
829
- }
830
- });
831
- describe('unreferencable builtins as parameter names', () => {
832
- it('flags `function f(Box)` (parameter name)', () => {
833
- let { diagnostics } = parse(`function f(Box)\nend function`);
834
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('Box')]);
835
- });
836
- it('flags `function f(CreateObject)` (parameter name)', () => {
837
- let { diagnostics } = parse(`function f(CreateObject)\nend function`);
838
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('CreateObject')]);
839
- });
840
- it('flags `function f(GetGlobalAA)` (parameter name)', () => {
841
- let { diagnostics } = parse(`function f(GetGlobalAA)\nend function`);
842
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('GetGlobalAA')]);
843
- });
844
- it('flags `function f(GetLastRunCompileError)` (parameter name)', () => {
845
- let { diagnostics } = parse(`function f(GetLastRunCompileError)\nend function`);
846
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('GetLastRunCompileError')]);
847
- });
848
- it('flags `function f(GetLastRunRunTimeError)` (parameter name)', () => {
849
- let { diagnostics } = parse(`function f(GetLastRunRunTimeError)\nend function`);
850
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('GetLastRunRunTimeError')]);
851
- });
852
- it('flags `function f(ObjFun)` (parameter name)', () => {
853
- let { diagnostics } = parse(`function f(ObjFun)\nend function`);
854
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('ObjFun')]);
855
- });
856
- it('flags `function f(Pos)` (parameter name)', () => {
857
- let { diagnostics } = parse(`function f(Pos)\nend function`);
858
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('Pos')]);
859
- });
860
- it('flags `function f(Run)` (parameter name)', () => {
861
- let { diagnostics } = parse(`function f(Run)\nend function`);
862
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('Run')]);
863
- });
864
- it('flags `function f(Tab)` (parameter name)', () => {
865
- let { diagnostics } = parse(`function f(Tab)\nend function`);
866
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('Tab')]);
867
- });
868
- it('flags `function f(type)` (parameter name)', () => {
869
- let { diagnostics } = parse(`function f(type)\nend function`);
870
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('type')]);
871
- });
872
- it('flags `function f(eval)` (parameter name)', () => {
873
- let { diagnostics } = parse(`function f(eval)\nend function`);
874
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('eval')]);
875
- });
876
- });
877
- });
878
- describe('import keyword', () => {
879
- it('parses without errors', () => {
880
- var _a;
881
- let { statements, diagnostics } = parse(`
882
- import "somePath"
883
- `, Parser_1.ParseMode.BrighterScript);
884
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
885
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
886
- });
887
- it('catches import statements used in brightscript files', () => {
888
- var _a;
889
- let { statements, diagnostics } = parse(`
890
- import "somePath"
891
- `, Parser_1.ParseMode.BrightScript);
892
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.eql(DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('import statements').message);
893
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
894
- });
895
- it('catchs missing file path', () => {
896
- var _a;
897
- let { statements, diagnostics } = parse(`
898
- import
899
- `, Parser_1.ParseMode.BrighterScript);
900
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedStringLiteralAfterKeyword('import').message);
901
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.ImportStatement);
902
- });
903
- });
904
- describe('Annotations', () => {
905
- it('parses with error if malformed', () => {
906
- var _a;
907
- let { diagnostics } = parse(`
908
- @
909
- sub main()
910
- end sub
911
- `, Parser_1.ParseMode.BrighterScript);
912
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('@').message);
913
- });
914
- it('properly handles empty annotation above class method', () => {
915
- var _a;
916
- //this code used to cause an infinite loop, so the fact that the test passes/fails on its own is a success!
917
- let { diagnostics } = parse(`
918
- class Person
919
- @
920
- sub new()
921
- end sub
922
- end class
923
- `, Parser_1.ParseMode.BrighterScript);
924
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.expectedIdentifier().message);
925
- });
926
- it('parses with error if annotation is not followed by a statement', () => {
927
- var _a, _b, _c, _d;
928
- let { diagnostics } = parse(`
929
- sub main()
930
- @meta2
931
- end sub
932
- class MyClass
933
- @meta3
934
- @meta4
935
- end class
936
- @meta1
937
- `, Parser_1.ParseMode.BrighterScript);
938
- (0, chai_config_spec_1.expect)(diagnostics.length).to.equal(4);
939
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
940
- (0, chai_config_spec_1.expect)((_b = diagnostics[1]) === null || _b === void 0 ? void 0 : _b.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
941
- (0, chai_config_spec_1.expect)((_c = diagnostics[2]) === null || _c === void 0 ? void 0 : _c.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
942
- (0, chai_config_spec_1.expect)((_d = diagnostics[3]) === null || _d === void 0 ? void 0 : _d.message).to.equal(DiagnosticMessages_1.DiagnosticMessages.unusedAnnotation().message);
943
- });
944
- it('attaches an annotation to next statement', () => {
945
- var _a;
946
- let { statements, diagnostics } = parse(`
947
- @meta1
948
- function main()
949
- end function
950
-
951
- @meta2 sub init()
952
- end sub
953
- `, Parser_1.ParseMode.BrighterScript);
954
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
955
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
956
- let fn = statements[0];
957
- (0, chai_config_spec_1.expect)(fn.annotations).to.exist;
958
- (0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
959
- (0, chai_config_spec_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta1');
960
- (0, chai_config_spec_1.expect)(fn.annotations[0].name).to.equal('meta1');
961
- (0, chai_config_spec_1.expect)(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
962
- fn = statements[1];
963
- (0, chai_config_spec_1.expect)(fn.annotations).to.exist;
964
- (0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
965
- (0, chai_config_spec_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta2');
966
- });
967
- it('attaches annotations inside a function body', () => {
968
- var _a, _b;
969
- let { statements, diagnostics } = parse(`
970
- function main()
971
- @meta1
972
- print "hello"
973
- end function
974
- `, Parser_1.ParseMode.BrighterScript);
975
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
976
- let fn = statements[0];
977
- let fnStatements = fn.func.body.statements;
978
- let stat = fnStatements[0];
979
- (0, chai_config_spec_1.expect)(stat).to.exist;
980
- (0, chai_config_spec_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
981
- (0, chai_config_spec_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
982
- });
983
- it('attaches multiple annotations to next statement', () => {
984
- var _a;
985
- let { statements, diagnostics } = parse(`
986
- @meta1
987
- @meta2 @meta3
988
- function main()
989
- end function
990
- `, Parser_1.ParseMode.BrighterScript);
991
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
992
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
993
- let fn = statements[0];
994
- (0, chai_config_spec_1.expect)(fn.annotations).to.exist;
995
- (0, chai_config_spec_1.expect)(fn.annotations.length).to.equal(3);
996
- (0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
997
- (0, chai_config_spec_1.expect)(fn.annotations[1]).to.be.instanceof(Expression_1.AnnotationExpression);
998
- (0, chai_config_spec_1.expect)(fn.annotations[2]).to.be.instanceof(Expression_1.AnnotationExpression);
999
- });
1000
- it('allows annotations with parameters', () => {
1001
- var _a;
1002
- let { statements, diagnostics } = parse(`
1003
- @meta1("arg", 2, true, { prop: "value" })
1004
- function main()
1005
- end function
1006
- `, Parser_1.ParseMode.BrighterScript);
1007
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1008
- let fn = statements[0];
1009
- (0, chai_config_spec_1.expect)(fn.annotations).to.exist;
1010
- (0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1011
- (0, chai_config_spec_1.expect)(fn.annotations[0].nameToken.text).to.equal('meta1');
1012
- (0, chai_config_spec_1.expect)(fn.annotations[0].call).to.be.instanceof(Expression_1.CallExpression);
1013
- });
1014
- it('attaches annotations to a class', () => {
1015
- var _a, _b;
1016
- let { statements, diagnostics } = parse(`
1017
- @meta1
1018
- class MyClass
1019
- function main()
1020
- print "hello"
1021
- end function
1022
- end class
1023
- `, Parser_1.ParseMode.BrighterScript);
1024
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1025
- let cs = statements[0];
1026
- (0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
1027
- (0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1028
- });
1029
- it('attaches annotations to multiple clases', () => {
1030
- var _a, _b, _c;
1031
- let { statements, diagnostics } = parse(`
1032
- @meta1
1033
- class MyClass
1034
- function main()
1035
- print "hello"
1036
- end function
1037
- end class
1038
- @meta2
1039
- class MyClass2
1040
- function main()
1041
- print "hello"
1042
- end function
1043
- end class
1044
- `, Parser_1.ParseMode.BrighterScript);
1045
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1046
- let cs = statements[0];
1047
- (0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
1048
- (0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1049
- (0, chai_config_spec_1.expect)(cs.annotations[0].name).to.equal('meta1');
1050
- let cs2 = statements[1];
1051
- (0, chai_config_spec_1.expect)((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
1052
- (0, chai_config_spec_1.expect)(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1053
- (0, chai_config_spec_1.expect)(cs2.annotations[0].name).to.equal('meta2');
1054
- });
1055
- it('attaches annotations to a namespaced class', () => {
1056
- var _a, _b;
1057
- let { statements, diagnostics } = parse(`
1058
- namespace ns
1059
- @meta1
1060
- class MyClass
1061
- function main()
1062
- print "hello"
1063
- end function
1064
- end class
1065
- end namespace
1066
- `, Parser_1.ParseMode.BrighterScript);
1067
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1068
- let ns = statements[0];
1069
- let cs = ns.body.statements[0];
1070
- (0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
1071
- (0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1072
- });
1073
- it('attaches annotations to a namespaced class - multiple', () => {
1074
- var _a, _b, _c;
1075
- let { statements, diagnostics } = parse(`
1076
- namespace ns
1077
- @meta1
1078
- class MyClass
1079
- function main()
1080
- print "hello"
1081
- end function
1082
- end class
1083
- @meta2
1084
- class MyClass2
1085
- function main()
1086
- print "hello"
1087
- end function
1088
- end class
1089
- end namespace
1090
- `, Parser_1.ParseMode.BrighterScript);
1091
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1092
- let ns = statements[0];
1093
- let cs = ns.body.statements[0];
1094
- (0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
1095
- (0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1096
- (0, chai_config_spec_1.expect)(cs.annotations[0].name).to.equal('meta1');
1097
- let cs2 = ns.body.statements[1];
1098
- (0, chai_config_spec_1.expect)((_c = cs2.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(1);
1099
- (0, chai_config_spec_1.expect)(cs2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1100
- (0, chai_config_spec_1.expect)(cs2.annotations[0].name).to.equal('meta2');
1101
- });
1102
- it('attaches annotations to a class constructor', () => {
1103
- var _a, _b;
1104
- let { statements, diagnostics } = parse(`
1105
- class MyClass
1106
- @meta1
1107
- function new()
1108
- print "hello"
1109
- end function
1110
- function methodA()
1111
- print "hello"
1112
- end function
1113
- end class
1114
- `, Parser_1.ParseMode.BrighterScript);
1115
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1116
- let cs = statements[0];
1117
- let stat = cs.body[0];
1118
- (0, chai_config_spec_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
1119
- (0, chai_config_spec_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1120
- });
1121
- it('attaches annotations to a class methods', () => {
1122
- var _a, _b;
1123
- let { statements, diagnostics } = parse(`
1124
- class MyClass
1125
- function new()
1126
- print "hello"
1127
- end function
1128
- @meta1
1129
- function methodA()
1130
- print "hello"
1131
- end function
1132
- end class
1133
- `, Parser_1.ParseMode.BrighterScript);
1134
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1135
- let cs = statements[0];
1136
- let stat = cs.body[1];
1137
- (0, chai_config_spec_1.expect)((_b = stat.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(1);
1138
- (0, chai_config_spec_1.expect)(stat.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1139
- });
1140
- it('attaches annotations to a class methods, fields and constructor', () => {
1141
- var _a, _b, _c, _d, _e;
1142
- let { statements, diagnostics } = parse(`
1143
- @meta2
1144
- @meta1
1145
- class MyClass
1146
- @meta3
1147
- @meta4
1148
- function new()
1149
- print "hello"
1150
- end function
1151
- @meta5
1152
- @meta6
1153
- function methodA()
1154
- print "hello"
1155
- end function
1156
-
1157
- @meta5
1158
- @meta6
1159
- public foo="bar"
1160
- end class
1161
- `, Parser_1.ParseMode.BrighterScript);
1162
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1163
- let cs = statements[0];
1164
- (0, chai_config_spec_1.expect)((_b = cs.annotations) === null || _b === void 0 ? void 0 : _b.length).to.equal(2);
1165
- (0, chai_config_spec_1.expect)(cs.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1166
- let stat1 = cs.body[0];
1167
- let stat2 = cs.body[1];
1168
- let f1 = cs.body[2];
1169
- (0, chai_config_spec_1.expect)((_c = stat1.annotations) === null || _c === void 0 ? void 0 : _c.length).to.equal(2);
1170
- (0, chai_config_spec_1.expect)(stat1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1171
- (0, chai_config_spec_1.expect)((_d = stat2.annotations) === null || _d === void 0 ? void 0 : _d.length).to.equal(2);
1172
- (0, chai_config_spec_1.expect)(stat2.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1173
- (0, chai_config_spec_1.expect)((_e = f1.annotations) === null || _e === void 0 ? void 0 : _e.length).to.equal(2);
1174
- (0, chai_config_spec_1.expect)(f1.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1175
- });
1176
- it('ignores annotations on commented out lines', () => {
1177
- var _a;
1178
- let { statements, diagnostics } = parse(`
1179
- '@meta1
1180
- ' @meta1
1181
- function new()
1182
- print "hello"
1183
- end function
1184
- `, Parser_1.ParseMode.BrighterScript);
1185
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1186
- let cs = statements[0];
1187
- (0, chai_config_spec_1.expect)(cs.annotations).to.be.undefined;
1188
- });
1189
- it('can convert argument of an annotation to JS types', () => {
1190
- var _a;
1191
- let { statements, diagnostics } = parse(`
1192
- @meta1
1193
- function main()
1194
- end function
1195
-
1196
- @meta2(
1197
- "arg", 2, true,
1198
- { prop: "value" }, [1, 2],
1199
- sub()
1200
- end sub
1201
- )
1202
- sub init()
1203
- end sub
1204
- `, Parser_1.ParseMode.BrighterScript);
1205
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1206
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
1207
- let fn = statements[0];
1208
- (0, chai_config_spec_1.expect)(fn.annotations).to.exist;
1209
- (0, chai_config_spec_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([]);
1210
- (0, chai_config_spec_1.expect)(statements[1]).to.be.instanceof(Statement_1.FunctionStatement);
1211
- fn = statements[1];
1212
- (0, chai_config_spec_1.expect)(fn.annotations).to.exist;
1213
- (0, chai_config_spec_1.expect)(fn.annotations[0]).to.be.instanceof(Expression_1.AnnotationExpression);
1214
- (0, chai_config_spec_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([
1215
- 'arg', 2, true,
1216
- { prop: 'value' }, [1, 2],
1217
- null
1218
- ]);
1219
- let allArgs = fn.annotations[0].getArguments(false);
1220
- (0, chai_config_spec_1.expect)(allArgs.pop()).to.be.instanceOf(Expression_1.FunctionExpression);
1221
- });
1222
- it('can handle negative numbers', () => {
1223
- var _a;
1224
- let { statements, diagnostics } = parse(`
1225
- @meta(-100)
1226
- function main()
1227
- end function
1228
-
1229
- sub init()
1230
- end sub
1231
- `, Parser_1.ParseMode.BrighterScript);
1232
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).not.to.exist;
1233
- (0, chai_config_spec_1.expect)(statements[0]).to.be.instanceof(Statement_1.FunctionStatement);
1234
- let fn = statements[0];
1235
- (0, chai_config_spec_1.expect)(fn.annotations).to.exist;
1236
- (0, chai_config_spec_1.expect)(fn.annotations[0].getArguments()).to.deep.equal([-100]);
1237
- });
1238
- });
1239
- describe('grouped type expressions', () => {
1240
- it('is not allowed in brightscript mode', () => {
1241
- let parser = parse(`
1242
- sub main(param as (string or integer))
1243
- print param
1244
- end sub
1245
- `, Parser_1.ParseMode.BrightScript);
1246
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(parser.diagnostics, [DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid('param', '(')]);
1247
- });
1248
- it('allows group type expressions in parameters', () => {
1249
- let { diagnostics } = parse(`
1250
- sub main(param as (string or integer))
1251
- print param
1252
- end sub
1253
- `, Parser_1.ParseMode.BrighterScript);
1254
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1255
- });
1256
- it('allows group type expressions in type casts', () => {
1257
- let { diagnostics } = parse(`
1258
- sub main(val)
1259
- printThing(val as (string or integer))
1260
- end sub
1261
- sub printThing(thing as (string or integer))
1262
- print thing
1263
- end sub
1264
- `, Parser_1.ParseMode.BrighterScript);
1265
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1266
- });
1267
- it('allows union of grouped type expressions', () => {
1268
- let { diagnostics } = parse(`
1269
- sub main(param as (string or integer) or (float or dynamic))
1270
- print param
1271
- end sub
1272
- `, Parser_1.ParseMode.BrighterScript);
1273
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1274
- });
1275
- it('allows nested grouped type expressions', () => {
1276
- let { diagnostics } = parse(`
1277
- sub main(param as ((string or integer) or (float or dynamic)))
1278
- print param
1279
- end sub
1280
- `, Parser_1.ParseMode.BrighterScript);
1281
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1282
- });
1283
- it('allows complicated grouped type expression', () => {
1284
- let { diagnostics } = parse(`
1285
- sub main(param as (({name as string} and {age as integer}) or (string and SomeInterface) or Klass and roAssociativeArray) )
1286
- print param
1287
- end sub
1288
- `, Parser_1.ParseMode.BrighterScript);
1289
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1290
- });
1291
- });
1292
- describe('union types', () => {
1293
- it('is not allowed in brightscript mode', () => {
1294
- let parser = parse(`
1295
- sub main(param as string or integer)
1296
- print param
1297
- end sub
1298
- `, Parser_1.ParseMode.BrightScript);
1299
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(parser.diagnostics, [DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()]);
1300
- });
1301
- it('allows union types in parameters', () => {
1302
- let { diagnostics } = parse(`
1303
- sub main(param as string or integer)
1304
- print param
1305
- end sub
1306
- `, Parser_1.ParseMode.BrighterScript);
1307
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1308
- });
1309
- it('allows union types in type casts', () => {
1310
- let { diagnostics } = parse(`
1311
- sub main(val)
1312
- printThing(val as string or integer)
1313
- end sub
1314
- sub printThing(thing as string or integer)
1315
- print thing
1316
- end sub
1317
- `, Parser_1.ParseMode.BrighterScript);
1318
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1319
- });
1320
- });
1321
- describe('intersection types', () => {
1322
- it('is not allowed in brightscript mode', () => {
1323
- let parser = parse(`
1324
- sub main(param as string and integer)
1325
- print param
1326
- end sub
1327
- `, Parser_1.ParseMode.BrightScript);
1328
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(parser.diagnostics, [DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()]);
1329
- });
1330
- it('allows intersection types in parameters', () => {
1331
- let { diagnostics } = parse(`
1332
- sub main(param as string and integer)
1333
- print param
1334
- end sub
1335
- `, Parser_1.ParseMode.BrighterScript);
1336
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1337
- });
1338
- it('allows intersection types in type casts', () => {
1339
- let { diagnostics } = parse(`
1340
- sub main(val)
1341
- printThing(val as string and integer)
1342
- end sub
1343
- sub printThing(thing as string and integer)
1344
- print thing
1345
- end sub
1346
- `, Parser_1.ParseMode.BrighterScript);
1347
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1348
- });
1349
- describe('invalid syntax', () => {
1350
- it('flags union type with missing sides', () => {
1351
- let { diagnostics } = parse(`
1352
- sub main(param as Thing or )
1353
- print param
1354
- end sub
1355
- `, Parser_1.ParseMode.BrighterScript);
1356
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('or').message]);
1357
- });
1358
- it('flags missing type inside binary type', () => {
1359
- var _a;
1360
- let { diagnostics } = parse(`
1361
- sub main(param as string or and float)
1362
- print param
1363
- end sub
1364
- `, Parser_1.ParseMode.BrighterScript);
1365
- (0, chai_config_spec_1.expect)((_a = diagnostics[0]) === null || _a === void 0 ? void 0 : _a.message).to.exist;
1366
- });
1367
- });
1368
- });
1369
- describe('typecast statement', () => {
1370
- it('allows typecast statement ', () => {
1371
- let { ast, diagnostics } = parse(`
1372
- typeCAST m AS roAssociativeArray
1373
- `, Parser_1.ParseMode.BrighterScript);
1374
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1375
- (0, chai_config_spec_1.expect)((0, reflection_1.isTypecastStatement)(ast.statements[0])).to.be.true;
1376
- const stmt = ast.statements[0];
1377
- (0, chai_config_spec_1.expect)(stmt.tokens.typecast.text).to.eq('typeCAST');
1378
- (0, chai_config_spec_1.expect)(stmt.tokens.typecast).to.exist;
1379
- });
1380
- it('is disallowed in brightscript mode', () => {
1381
- let { diagnostics } = parse(`
1382
- typecast m AS roAssociativeArray
1383
- `, Parser_1.ParseMode.BrightScript);
1384
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
1385
- DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('typecast statements')
1386
- ]);
1387
- });
1388
- it('allows `typecast` for function name', () => {
1389
- let { ast, diagnostics } = parse(`
1390
- function typecast() as integer
1391
- return 1
1392
- end function
1393
- `, Parser_1.ParseMode.BrighterScript);
1394
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1395
- (0, chai_config_spec_1.expect)(ast.statements[0].name.text).to.eq('typecast');
1396
- });
1397
- it('allows `typecast` for variable name', () => {
1398
- let { ast, diagnostics } = parse(`
1399
- function foo() as integer
1400
- typecast = 1
1401
- return typecast
1402
- end function
1403
- `, Parser_1.ParseMode.BrighterScript);
1404
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1405
- (0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements[0].name.text).to.eq('typecast');
1406
- });
1407
- it('is allowed in function', () => {
1408
- let { diagnostics } = parse(`
1409
- function foo() as integer
1410
- typecast m as MyObject
1411
- return m.getNum()
1412
- end function
1413
- `, Parser_1.ParseMode.BrighterScript);
1414
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1415
- });
1416
- it('is allowed in function literal', () => {
1417
- let { diagnostics } = parse(`
1418
- interface PiGetter
1419
- pi as float
1420
- function getPi() as float
1421
- end interface
1422
-
1423
- function makePiGetter() as object
1424
- x = {
1425
- pi: 3.14,
1426
- getPi: function() as float
1427
- typecast m as PiGetter
1428
- return m.pi
1429
- end function
1430
- }
1431
- return x
1432
- end function
1433
- `, Parser_1.ParseMode.BrighterScript);
1434
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1435
- });
1436
- });
1437
- describe('alias statement', () => {
1438
- it('allows alias statement ', () => {
1439
- let { ast, diagnostics } = parse(`
1440
- ALIAS x = lcase
1441
- `, Parser_1.ParseMode.BrighterScript);
1442
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1443
- (0, chai_config_spec_1.expect)((0, reflection_1.isAliasStatement)(ast.statements[0])).to.be.true;
1444
- const stmt = ast.statements[0];
1445
- (0, chai_config_spec_1.expect)(stmt.tokens.alias.text).to.eq('ALIAS');
1446
- (0, chai_config_spec_1.expect)(stmt.tokens.value).to.exist;
1447
- });
1448
- it('is disallowed in brightscript mode', () => {
1449
- let { diagnostics } = parse(`
1450
- alias x = lcase
1451
- `, Parser_1.ParseMode.BrightScript);
1452
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
1453
- DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('alias statements')
1454
- ]);
1455
- });
1456
- it('allows `alias` for function name', () => {
1457
- let { ast, diagnostics } = parse(`
1458
- function alias() as integer
1459
- return 1
1460
- end function
1461
- `, Parser_1.ParseMode.BrighterScript);
1462
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1463
- (0, chai_config_spec_1.expect)(ast.statements[0].name.text).to.eq('alias');
1464
- });
1465
- it('allows `alias` for variable name', () => {
1466
- let { ast, diagnostics } = parse(`
1467
- function foo() as integer
1468
- alias = 1
1469
- return alias
1470
- end function
1471
- `, Parser_1.ParseMode.BrighterScript);
1472
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1473
- (0, chai_config_spec_1.expect)(ast.statements[0].func.body.statements[0].name.text).to.eq('alias');
1474
- });
1475
- });
1476
- describe('type statement', () => {
1477
- it('allows type statement ', () => {
1478
- let { ast, diagnostics } = parse(`
1479
- TYPE x = string
1480
- `, Parser_1.ParseMode.BrighterScript);
1481
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1482
- (0, chai_config_spec_1.expect)((0, reflection_1.isTypeStatement)(ast.statements[0])).to.be.true;
1483
- const stmt = ast.statements[0];
1484
- (0, chai_config_spec_1.expect)(stmt.tokens.type.text).to.eq('TYPE');
1485
- (0, chai_config_spec_1.expect)(stmt.tokens.value).to.exist;
1486
- });
1487
- it('is disallowed in brightscript mode', () => {
1488
- let { diagnostics } = parse(`
1489
- type x = string
1490
- `, Parser_1.ParseMode.BrightScript);
1491
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
1492
- DiagnosticMessages_1.DiagnosticMessages.bsFeatureNotSupportedInBrsFiles('type statements')
1493
- ]);
1494
- });
1495
- it('disallows `type` for function name', () => {
1496
- let { diagnostics } = parse(`
1497
- function type() as integer
1498
- return 1
1499
- end function
1500
- `, Parser_1.ParseMode.BrighterScript);
1501
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
1502
- DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('type').message
1503
- ]);
1504
- });
1505
- it('disallows `type` for variable name', () => {
1506
- let { diagnostics } = parse(`
1507
- function foo() as integer
1508
- type = 1
1509
- return type
1510
- end function
1511
- `, Parser_1.ParseMode.BrighterScript);
1512
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
1513
- DiagnosticMessages_1.DiagnosticMessages.cannotUseReservedWordAsIdentifier('type').message
1514
- ]);
1515
- });
1516
- it('has error when rhs is not a type', () => {
1517
- let { diagnostics } = parse(`
1518
- type x = 123
1519
- `, Parser_1.ParseMode.BrighterScript);
1520
- (0, testHelpers_spec_1.expectDiagnostics)(diagnostics, [
1521
- DiagnosticMessages_1.DiagnosticMessages.expectedIdentifierAfterKeyword('=').message
1522
- ]);
1523
- });
1524
- it('allows type statement with complicated type', () => {
1525
- let { ast, diagnostics } = parse(`
1526
- type x = string or CustomKlass or roAssociativeArray
1527
- `, Parser_1.ParseMode.BrighterScript);
1528
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1529
- (0, chai_config_spec_1.expect)((0, reflection_1.isTypeStatement)(ast.statements[0])).to.be.true;
1530
- const stmt = ast.statements[0];
1531
- (0, chai_config_spec_1.expect)(stmt.tokens.type.text).to.eq('type');
1532
- (0, chai_config_spec_1.expect)(stmt.tokens.value).to.exist;
1533
- });
1534
- });
1535
- describe('inline interfaces', () => {
1536
- it('inline interface param types disallowed in brightscript mode', () => {
1537
- let { diagnostics } = parse(`
1538
- sub test(foo as {x as string})
1539
- print foo.x
1540
- end sub
1541
- `, Parser_1.ParseMode.BrightScript);
1542
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
1543
- DiagnosticMessages_1.DiagnosticMessages.functionParameterTypeIsInvalid('foo', '{').message
1544
- ]);
1545
- });
1546
- it('inline interface return types disallowed in brightscript mode', () => {
1547
- let { diagnostics } = parse(`
1548
- function test() as {x as string}
1549
- print {x: "hello"}
1550
- end function
1551
- `, Parser_1.ParseMode.BrightScript);
1552
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
1553
- DiagnosticMessages_1.DiagnosticMessages.invalidFunctionReturnType('{').message
1554
- ]);
1555
- });
1556
- it('inline interface as param type', () => {
1557
- let { ast, diagnostics } = parse(`
1558
- sub test(foo as {x as string})
1559
- print foo.x
1560
- end sub
1561
- `, Parser_1.ParseMode.BrighterScript);
1562
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1563
- (0, chai_config_spec_1.expect)(ast.statements.length).to.eq(1);
1564
- });
1565
- it('inline interface as return type', () => {
1566
- let { ast, diagnostics } = parse(`
1567
- function test() as {x as string}
1568
- print {x: "hello"}
1569
- end function
1570
- `, Parser_1.ParseMode.BrighterScript);
1571
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1572
- (0, chai_config_spec_1.expect)(ast.statements.length).to.eq(1);
1573
- });
1574
- it('parses a big inline interface as param type', () => {
1575
- let { ast, diagnostics } = parse(`
1576
- sub test(foo as {
1577
- x as string,
1578
- y as {a as integer}
1579
- z})
1580
- print foo.x + y.a.toStr()
1581
- end sub
1582
- `, Parser_1.ParseMode.BrighterScript);
1583
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1584
- (0, chai_config_spec_1.expect)(ast.statements.length).to.eq(1);
1585
- });
1586
- it('allows optional members', () => {
1587
- let { ast, diagnostics } = parse(`
1588
- sub test(p as {x as string, optional y})
1589
- end sub
1590
- `, Parser_1.ParseMode.BrighterScript);
1591
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1592
- (0, chai_config_spec_1.expect)(ast.statements.length).to.eq(1);
1593
- });
1594
- it('is allowed as typecast', () => {
1595
- let { diagnostics } = parse(`
1596
- sub test(p)
1597
- print (p as {name as string}).name
1598
- end sub
1599
- `, Parser_1.ParseMode.BrighterScript);
1600
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1601
- });
1602
- it('is allowed as class and interface field', () => {
1603
- let { diagnostics } = parse(`
1604
- class Klass
1605
- x as {name as string}
1606
- end class
1607
- interface Iface
1608
- y as {age as integer}
1609
- end interface
1610
- `, Parser_1.ParseMode.BrighterScript);
1611
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1612
- });
1613
- it('can have custom type as member type', () => {
1614
- let { diagnostics } = parse(`
1615
- interface IFace
1616
- name as string
1617
- end interface
1618
- function test(z as {foo as IFace})
1619
- return z.foo.name
1620
- end function
1621
- `, Parser_1.ParseMode.BrighterScript);
1622
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1623
- });
1624
- it('can have per-member doc comment', () => {
1625
- let { diagnostics } = parse(`
1626
- interface IFace
1627
- inline as {
1628
- ' comment 1
1629
- name as string
1630
- ' comment 2
1631
- age as integer
1632
- }
1633
- end interface
1634
- function test(z as {foo as IFace})
1635
- return z.foo.inline.name
1636
- end function
1637
- `, Parser_1.ParseMode.BrighterScript);
1638
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1639
- });
1640
- it('can have string literals as members', () => {
1641
- let { diagnostics } = parse(`
1642
- function test(z as {"this is a stringliteral" as string})
1643
- return z["this is a stringliteral"]
1644
- end function
1645
- `, Parser_1.ParseMode.BrighterScript);
1646
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1647
- });
1648
- });
1649
- describe('for each with types', () => {
1650
- it('parses without errors', () => {
1651
- let { diagnostics } = parse(`
1652
- function main()
1653
- for each item as string in ["a", "b", "c"]
1654
- print item
1655
- end for
1656
- end function
1657
- `, Parser_1.ParseMode.BrighterScript);
1658
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1659
- });
1660
- it('allows complicated expressions', () => {
1661
- let { diagnostics } = parse(`
1662
- function main(data)
1663
- for each item as {a as integer or boolean, b as SomeInterface[], c as {id as string} } or string in data
1664
- print item
1665
- end for
1666
- end function
1667
- `, Parser_1.ParseMode.BrighterScript);
1668
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1669
- });
1670
- });
1671
- describe('line continuation', () => {
1672
- describe('binary operator continuation', () => {
1673
- it('is allowed after arithmetic operators in BrighterScript mode', () => {
1674
- let { diagnostics } = parse(`
1675
- sub main()
1676
- a = x +
1677
- y
1678
- b = x -
1679
- y
1680
- c = x *
1681
- y
1682
- d = x /
1683
- y
1684
- e = x \\
1685
- y
1686
- f = x mod
1687
- y
1688
- g = x ^
1689
- y
1690
- end sub
1691
- `, Parser_1.ParseMode.BrighterScript);
1692
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1693
- });
1694
- it('is allowed after boolean operators in BrighterScript mode', () => {
1695
- let { diagnostics } = parse(`
1696
- sub main()
1697
- a = isValid and
1698
- isEnabled
1699
- b = isValid or
1700
- isEnabled
1701
- end sub
1702
- `, Parser_1.ParseMode.BrighterScript);
1703
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1704
- });
1705
- it('is allowed after relational operators in BrighterScript mode', () => {
1706
- let { diagnostics } = parse(`
1707
- sub main()
1708
- a = x =
1709
- y
1710
- b = x <>
1711
- y
1712
- c = x >
1713
- y
1714
- d = x >=
1715
- y
1716
- e = x <
1717
- y
1718
- f = x <=
1719
- y
1720
- end sub
1721
- `, Parser_1.ParseMode.BrighterScript);
1722
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1723
- });
1724
- it('is not allowed in BrightScript mode', () => {
1725
- let { diagnostics } = parse(`
1726
- sub main()
1727
- result = value1 +
1728
- value2
1729
- end sub
1730
- `, Parser_1.ParseMode.BrightScript);
1731
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
1732
- DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('\n'),
1733
- DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()
1734
- ]);
1735
- });
1736
- });
1737
- describe('function call argument continuation', () => {
1738
- it('is not allowed in BrightScript mode', () => {
1739
- let { diagnostics } = parse(`
1740
- sub main()
1741
- result = foo(
1742
- arg1,
1743
- arg2
1744
- )
1745
- end sub
1746
- sub foo(a, b)
1747
- end sub
1748
- `, Parser_1.ParseMode.BrightScript);
1749
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
1750
- DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('\n'),
1751
- DiagnosticMessages_1.DiagnosticMessages.expectedRightParenAfterFunctionCallArguments(),
1752
- DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()
1753
- ]);
1754
- });
1755
- it('is allowed in BrighterScript mode', () => {
1756
- let { diagnostics } = parse(`
1757
- sub main()
1758
- result = foo(
1759
- arg1,
1760
- arg2
1761
- )
1762
- end sub
1763
- sub foo(a, b)
1764
- end sub
1765
- `, Parser_1.ParseMode.BrighterScript);
1766
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1767
- });
1768
- it('does not affect inline objects passed as arguments in BrightScript mode', () => {
1769
- let { diagnostics } = parse(`
1770
- sub main()
1771
- foo({
1772
- key: "value"
1773
- })
1774
- end sub
1775
- sub foo(a)
1776
- end sub
1777
- `, Parser_1.ParseMode.BrightScript);
1778
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1779
- });
1780
- });
1781
- describe('minFirmwareVersion >= 15.3 in BrightScript mode', () => {
1782
- it('allows binary operator continuation in BrightScript mode when minFirmwareVersion is 15.3', () => {
1783
- let { tokens } = Lexer_1.Lexer.scan(`
1784
- sub main()
1785
- result = value1 +
1786
- value2
1787
- end sub
1788
- `);
1789
- let { diagnostics } = Parser_1.Parser.parse(tokens, {
1790
- mode: Parser_1.ParseMode.BrightScript,
1791
- minFirmwareVersion: '15.3'
1792
- });
1793
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1794
- });
1795
- it('allows binary operator continuation in BrightScript mode when minFirmwareVersion is above 15.3', () => {
1796
- let { tokens } = Lexer_1.Lexer.scan(`
1797
- sub main()
1798
- result = value1 +
1799
- value2
1800
- end sub
1801
- `);
1802
- let { diagnostics } = Parser_1.Parser.parse(tokens, {
1803
- mode: Parser_1.ParseMode.BrightScript,
1804
- minFirmwareVersion: '16.0.0'
1805
- });
1806
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1807
- });
1808
- it('does not allow binary operator continuation in BrightScript mode when minFirmwareVersion is below 15.3', () => {
1809
- let { tokens } = Lexer_1.Lexer.scan(`
1810
- sub main()
1811
- result = value1 +
1812
- value2
1813
- end sub
1814
- `);
1815
- let { diagnostics } = Parser_1.Parser.parse(tokens, {
1816
- mode: Parser_1.ParseMode.BrightScript,
1817
- minFirmwareVersion: '11.0.0'
1818
- });
1819
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
1820
- DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('\n'),
1821
- DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()
1822
- ]);
1823
- });
1824
- it('allows function call argument continuation in BrightScript mode when minFirmwareVersion is 15.3', () => {
1825
- let { tokens } = Lexer_1.Lexer.scan(`
1826
- sub main()
1827
- result = foo(
1828
- arg1,
1829
- arg2
1830
- )
1831
- end sub
1832
- sub foo(a, b)
1833
- end sub
1834
- `);
1835
- let { diagnostics } = Parser_1.Parser.parse(tokens, {
1836
- mode: Parser_1.ParseMode.BrightScript,
1837
- minFirmwareVersion: '15.3.0'
1838
- });
1839
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1840
- });
1841
- it('does not allow function call argument continuation in BrightScript mode when minFirmwareVersion is below 15.3', () => {
1842
- let { tokens } = Lexer_1.Lexer.scan(`
1843
- sub main()
1844
- result = foo(
1845
- arg1,
1846
- arg2
1847
- )
1848
- end sub
1849
- sub foo(a, b)
1850
- end sub
1851
- `);
1852
- let { diagnostics } = Parser_1.Parser.parse(tokens, {
1853
- mode: Parser_1.ParseMode.BrightScript,
1854
- minFirmwareVersion: '15.2.9'
1855
- });
1856
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
1857
- DiagnosticMessages_1.DiagnosticMessages.unexpectedToken('\n'),
1858
- DiagnosticMessages_1.DiagnosticMessages.expectedRightParenAfterFunctionCallArguments(),
1859
- DiagnosticMessages_1.DiagnosticMessages.expectedStatementOrFunctionCallButReceivedExpression()
1860
- ]);
1861
- });
1862
- });
1863
- });
1864
- describe('typed functions as types', () => {
1865
- it('disallowed in brightscript mode', () => {
1866
- let { diagnostics } = parse(`
1867
- function test(func as function())
1868
- return func()
1869
- end function
1870
- `, Parser_1.ParseMode.BrightScript);
1871
- (0, testHelpers_spec_1.expectDiagnosticsIncludes)(diagnostics, [
1872
- DiagnosticMessages_1.DiagnosticMessages.unexpectedToken(')')
1873
- ]);
1874
- });
1875
- it('can be passed as param types', () => {
1876
- let { diagnostics } = parse(`
1877
- function test(func as function())
1878
- return func()
1879
- end function
1880
- `, Parser_1.ParseMode.BrighterScript);
1881
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1882
- });
1883
- it('can have a return type', () => {
1884
- let { diagnostics } = parse(`
1885
- function test(func as sub() as integer) as integer
1886
- return func()
1887
- end function
1888
- `, Parser_1.ParseMode.BrighterScript);
1889
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1890
- });
1891
- it('can use sub or function', () => {
1892
- let { diagnostics } = parse(`
1893
- function test(func as sub() as integer) as integer
1894
- return func()
1895
- end function
1896
-
1897
- function test2(func as function() as integer) as integer
1898
- return func()
1899
- end function
1900
- `, Parser_1.ParseMode.BrighterScript);
1901
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1902
- });
1903
- it('can have primitive parameters', () => {
1904
- let { diagnostics } = parse(`
1905
- function test(func as function(name as string, num as integer) as integer) as integer
1906
- return func("hello", 123)
1907
- end function
1908
- `, Parser_1.ParseMode.BrighterScript);
1909
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1910
- });
1911
- it('can have complex parameters', () => {
1912
- let { diagnostics } = parse(`
1913
- interface IFace
1914
- name as string
1915
- end interface
1916
-
1917
- function test(func as function(thing as IFace) as integer) as integer
1918
- return func({name: "hello"})
1919
- end function
1920
- `, Parser_1.ParseMode.BrighterScript);
1921
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1922
- });
1923
- it('can have compound parameters', () => {
1924
- let { diagnostics } = parse(`
1925
- interface IFace
1926
- name as string
1927
- end interface
1928
-
1929
- function test(func as function(arg1 as string or integer, arg2 as IFace) as integer) as integer
1930
- return func("hello", {name: "hello"})
1931
- end function
1932
- `, Parser_1.ParseMode.BrighterScript);
1933
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1934
- });
1935
- it('can be used as return types', () => {
1936
- let { diagnostics } = parse(`
1937
- function test() as function() as integer
1938
- return function() as integer
1939
- return 123
1940
- end function
1941
- end function
1942
- `, Parser_1.ParseMode.BrighterScript);
1943
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1944
- });
1945
- it('can have a union as return type', () => {
1946
- let { diagnostics } = parse(`
1947
- type foo = function() as integer or string
1948
- function test() as foo
1949
- return function() as integer
1950
- return 123
1951
- end function
1952
- end function
1953
- `, Parser_1.ParseMode.BrighterScript);
1954
- (0, testHelpers_spec_1.expectZeroDiagnostics)(diagnostics);
1955
- });
1956
- });
1957
- });
1958
- function parse(text, mode) {
1959
- let { tokens } = Lexer_1.Lexer.scan(text);
1960
- return Parser_1.Parser.parse(tokens, {
1961
- mode: mode
1962
- });
1963
- }
1964
- function rangeToArray(range) {
1965
- return [
1966
- range.start.line,
1967
- range.start.character,
1968
- range.end.line,
1969
- range.end.character
1970
- ];
1971
- }
1972
- exports.rangeToArray = rangeToArray;
1973
- function expectCommentWithText(stat, text) {
1974
- if ((0, reflection_1.isCommentStatement)(stat)) {
1975
- (0, chai_config_spec_1.expect)(stat.text).to.equal(text);
1976
- }
1977
- else {
1978
- failStatementType(stat, 'Comment');
1979
- }
1980
- }
1981
- function failStatementType(stat, type) {
1982
- chai_config_spec_1.assert.fail(`Statement ${stat.constructor.name} line ${stat.range.start.line} is not a ${type}`);
1983
- }
1984
- exports.failStatementType = failStatementType;
1985
- //# sourceMappingURL=Parser.spec.js.map