brighterscript 0.72.1 → 0.72.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/README.md +7 -2
  2. package/dist/LanguageServer.d.ts +2 -1
  3. package/dist/LanguageServer.js +12 -0
  4. package/dist/LanguageServer.js.map +1 -1
  5. package/dist/Program.d.ts +5 -1
  6. package/dist/Program.js +20 -0
  7. package/dist/Program.js.map +1 -1
  8. package/dist/bscPlugin/BscPlugin.d.ts +2 -1
  9. package/dist/bscPlugin/BscPlugin.js +4 -0
  10. package/dist/bscPlugin/BscPlugin.js.map +1 -1
  11. package/dist/bscPlugin/inlayHints/InlayHintProcessor.d.ts +23 -0
  12. package/dist/bscPlugin/inlayHints/InlayHintProcessor.js +183 -0
  13. package/dist/bscPlugin/inlayHints/InlayHintProcessor.js.map +1 -0
  14. package/dist/interfaces.d.ts +34 -1
  15. package/dist/lsp/LspProject.d.ts +8 -1
  16. package/dist/lsp/Project.d.ts +5 -1
  17. package/dist/lsp/Project.js +6 -0
  18. package/dist/lsp/Project.js.map +1 -1
  19. package/dist/lsp/ProjectManager.d.ts +5 -1
  20. package/dist/lsp/ProjectManager.js +12 -0
  21. package/dist/lsp/ProjectManager.js.map +1 -1
  22. package/dist/lsp/worker/WorkerThreadProject.d.ts +5 -1
  23. package/dist/lsp/worker/WorkerThreadProject.js +3 -0
  24. package/dist/lsp/worker/WorkerThreadProject.js.map +1 -1
  25. package/package.json +18 -14
  26. package/dist/astUtils/AstEditor.spec.d.ts +0 -1
  27. package/dist/astUtils/AstEditor.spec.js +0 -254
  28. package/dist/astUtils/AstEditor.spec.js.map +0 -1
  29. package/dist/astUtils/creators.spec.d.ts +0 -1
  30. package/dist/astUtils/creators.spec.js +0 -21
  31. package/dist/astUtils/creators.spec.js.map +0 -1
  32. package/dist/astUtils/reflection.spec.d.ts +0 -1
  33. package/dist/astUtils/reflection.spec.js +0 -308
  34. package/dist/astUtils/reflection.spec.js.map +0 -1
  35. package/dist/astUtils/stackedVisitor.spec.d.ts +0 -1
  36. package/dist/astUtils/stackedVisitor.spec.js +0 -79
  37. package/dist/astUtils/stackedVisitor.spec.js.map +0 -1
  38. package/dist/astUtils/visitors.spec.d.ts +0 -1
  39. package/dist/astUtils/visitors.spec.js +0 -1197
  40. package/dist/astUtils/visitors.spec.js.map +0 -1
  41. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.d.ts +0 -1
  42. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js +0 -1237
  43. package/dist/bscPlugin/codeActions/CodeActionsProcessor.spec.js.map +0 -1
  44. package/dist/bscPlugin/definition/DefinitionProvider.spec.d.ts +0 -1
  45. package/dist/bscPlugin/definition/DefinitionProvider.spec.js +0 -171
  46. package/dist/bscPlugin/definition/DefinitionProvider.spec.js.map +0 -1
  47. package/dist/bscPlugin/hover/HoverProcessor.spec.d.ts +0 -1
  48. package/dist/bscPlugin/hover/HoverProcessor.spec.js +0 -201
  49. package/dist/bscPlugin/hover/HoverProcessor.spec.js.map +0 -1
  50. package/dist/bscPlugin/references/ReferencesProvider.spec.d.ts +0 -1
  51. package/dist/bscPlugin/references/ReferencesProvider.spec.js +0 -51
  52. package/dist/bscPlugin/references/ReferencesProvider.spec.js.map +0 -1
  53. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.d.ts +0 -1
  54. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js +0 -298
  55. package/dist/bscPlugin/selectionRanges/SelectionRangesProcessor.spec.js.map +0 -1
  56. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.d.ts +0 -1
  57. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js +0 -399
  58. package/dist/bscPlugin/semanticTokens/BrsFileSemanticTokensProcessor.spec.js.map +0 -1
  59. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.d.ts +0 -1
  60. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js +0 -290
  61. package/dist/bscPlugin/symbols/DocumentSymbolProcessor.spec.js.map +0 -1
  62. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.d.ts +0 -1
  63. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js +0 -245
  64. package/dist/bscPlugin/symbols/WorkspaceSymbolProcessor.spec.js.map +0 -1
  65. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.d.ts +0 -1
  66. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js +0 -46
  67. package/dist/bscPlugin/transpile/BrsFilePreTranspileProcessor.spec.js.map +0 -1
  68. package/dist/bscPlugin/validation/BrsFileValidator.spec.d.ts +0 -1
  69. package/dist/bscPlugin/validation/BrsFileValidator.spec.js +0 -702
  70. package/dist/bscPlugin/validation/BrsFileValidator.spec.js.map +0 -1
  71. package/dist/common/Sequencer.spec.d.ts +0 -1
  72. package/dist/common/Sequencer.spec.js +0 -75
  73. package/dist/common/Sequencer.spec.js.map +0 -1
  74. package/dist/files/BrsFile.Class.spec.d.ts +0 -1
  75. package/dist/files/BrsFile.Class.spec.js +0 -1805
  76. package/dist/files/BrsFile.Class.spec.js.map +0 -1
  77. package/dist/files/BrsFile.spec.d.ts +0 -1
  78. package/dist/files/BrsFile.spec.js +0 -4611
  79. package/dist/files/BrsFile.spec.js.map +0 -1
  80. package/dist/files/XmlFile.spec.d.ts +0 -1
  81. package/dist/files/XmlFile.spec.js +0 -1219
  82. package/dist/files/XmlFile.spec.js.map +0 -1
  83. package/dist/files/tests/imports.spec.d.ts +0 -1
  84. package/dist/files/tests/imports.spec.js +0 -241
  85. package/dist/files/tests/imports.spec.js.map +0 -1
  86. package/dist/files/tests/optionalChaning.spec.d.ts +0 -1
  87. package/dist/files/tests/optionalChaning.spec.js +0 -152
  88. package/dist/files/tests/optionalChaning.spec.js.map +0 -1
  89. package/dist/lexer/Character.spec.d.ts +0 -1
  90. package/dist/lexer/Character.spec.js +0 -27
  91. package/dist/lexer/Character.spec.js.map +0 -1
  92. package/dist/lexer/Lexer.spec.d.ts +0 -1
  93. package/dist/lexer/Lexer.spec.js +0 -1300
  94. package/dist/lexer/Lexer.spec.js.map +0 -1
  95. package/dist/lsp/ActionQueue.spec.d.ts +0 -1
  96. package/dist/lsp/ActionQueue.spec.js +0 -80
  97. package/dist/lsp/ActionQueue.spec.js.map +0 -1
  98. package/dist/lsp/DocumentManager.spec.d.ts +0 -1
  99. package/dist/lsp/DocumentManager.spec.js +0 -103
  100. package/dist/lsp/DocumentManager.spec.js.map +0 -1
  101. package/dist/lsp/PathFilterer.spec.d.ts +0 -1
  102. package/dist/lsp/PathFilterer.spec.js +0 -182
  103. package/dist/lsp/PathFilterer.spec.js.map +0 -1
  104. package/dist/lsp/Project.spec.d.ts +0 -1
  105. package/dist/lsp/Project.spec.js +0 -400
  106. package/dist/lsp/Project.spec.js.map +0 -1
  107. package/dist/lsp/ProjectManager.spec.d.ts +0 -1
  108. package/dist/lsp/ProjectManager.spec.js +0 -1183
  109. package/dist/lsp/ProjectManager.spec.js.map +0 -1
  110. package/dist/lsp/worker/MessageHandler.spec.d.ts +0 -1
  111. package/dist/lsp/worker/MessageHandler.spec.js +0 -64
  112. package/dist/lsp/worker/MessageHandler.spec.js.map +0 -1
  113. package/dist/lsp/worker/WorkerPool.spec.d.ts +0 -1
  114. package/dist/lsp/worker/WorkerPool.spec.js +0 -59
  115. package/dist/lsp/worker/WorkerPool.spec.js.map +0 -1
  116. package/dist/lsp/worker/WorkerThreadProject.spec.d.ts +0 -2
  117. package/dist/lsp/worker/WorkerThreadProject.spec.js +0 -72
  118. package/dist/lsp/worker/WorkerThreadProject.spec.js.map +0 -1
  119. package/dist/parser/AstNode.spec.d.ts +0 -1
  120. package/dist/parser/AstNode.spec.js +0 -1452
  121. package/dist/parser/AstNode.spec.js.map +0 -1
  122. package/dist/parser/Expression.spec.d.ts +0 -1
  123. package/dist/parser/Expression.spec.js +0 -40
  124. package/dist/parser/Expression.spec.js.map +0 -1
  125. package/dist/parser/Parser.Class.spec.d.ts +0 -1
  126. package/dist/parser/Parser.Class.spec.js +0 -495
  127. package/dist/parser/Parser.Class.spec.js.map +0 -1
  128. package/dist/parser/Parser.spec.d.ts +0 -4
  129. package/dist/parser/Parser.spec.js +0 -1985
  130. package/dist/parser/Parser.spec.js.map +0 -1
  131. package/dist/parser/SGParser.spec.d.ts +0 -1
  132. package/dist/parser/SGParser.spec.js +0 -131
  133. package/dist/parser/SGParser.spec.js.map +0 -1
  134. package/dist/parser/Statement.spec.d.ts +0 -1
  135. package/dist/parser/Statement.spec.js +0 -118
  136. package/dist/parser/Statement.spec.js.map +0 -1
  137. package/dist/parser/tests/Parser.spec.d.ts +0 -19
  138. package/dist/parser/tests/Parser.spec.js +0 -38
  139. package/dist/parser/tests/Parser.spec.js.map +0 -1
  140. package/dist/parser/tests/controlFlow/For.spec.d.ts +0 -1
  141. package/dist/parser/tests/controlFlow/For.spec.js +0 -208
  142. package/dist/parser/tests/controlFlow/For.spec.js.map +0 -1
  143. package/dist/parser/tests/controlFlow/ForEach.spec.d.ts +0 -1
  144. package/dist/parser/tests/controlFlow/ForEach.spec.js +0 -143
  145. package/dist/parser/tests/controlFlow/ForEach.spec.js.map +0 -1
  146. package/dist/parser/tests/controlFlow/If.spec.d.ts +0 -1
  147. package/dist/parser/tests/controlFlow/If.spec.js +0 -570
  148. package/dist/parser/tests/controlFlow/If.spec.js.map +0 -1
  149. package/dist/parser/tests/controlFlow/While.spec.d.ts +0 -1
  150. package/dist/parser/tests/controlFlow/While.spec.js +0 -156
  151. package/dist/parser/tests/controlFlow/While.spec.js.map +0 -1
  152. package/dist/parser/tests/expression/Additive.spec.d.ts +0 -1
  153. package/dist/parser/tests/expression/Additive.spec.js +0 -99
  154. package/dist/parser/tests/expression/Additive.spec.js.map +0 -1
  155. package/dist/parser/tests/expression/ArrayLiterals.spec.d.ts +0 -1
  156. package/dist/parser/tests/expression/ArrayLiterals.spec.js +0 -291
  157. package/dist/parser/tests/expression/ArrayLiterals.spec.js.map +0 -1
  158. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.d.ts +0 -1
  159. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js +0 -401
  160. package/dist/parser/tests/expression/AssociativeArrayLiterals.spec.js.map +0 -1
  161. package/dist/parser/tests/expression/Boolean.spec.d.ts +0 -1
  162. package/dist/parser/tests/expression/Boolean.spec.js +0 -83
  163. package/dist/parser/tests/expression/Boolean.spec.js.map +0 -1
  164. package/dist/parser/tests/expression/Call.spec.d.ts +0 -1
  165. package/dist/parser/tests/expression/Call.spec.js +0 -242
  166. package/dist/parser/tests/expression/Call.spec.js.map +0 -1
  167. package/dist/parser/tests/expression/Exponential.spec.d.ts +0 -1
  168. package/dist/parser/tests/expression/Exponential.spec.js +0 -37
  169. package/dist/parser/tests/expression/Exponential.spec.js.map +0 -1
  170. package/dist/parser/tests/expression/Function.spec.d.ts +0 -1
  171. package/dist/parser/tests/expression/Function.spec.js +0 -403
  172. package/dist/parser/tests/expression/Function.spec.js.map +0 -1
  173. package/dist/parser/tests/expression/Indexing.spec.d.ts +0 -1
  174. package/dist/parser/tests/expression/Indexing.spec.js +0 -289
  175. package/dist/parser/tests/expression/Indexing.spec.js.map +0 -1
  176. package/dist/parser/tests/expression/Multiplicative.spec.d.ts +0 -1
  177. package/dist/parser/tests/expression/Multiplicative.spec.js +0 -67
  178. package/dist/parser/tests/expression/Multiplicative.spec.js.map +0 -1
  179. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.d.ts +0 -1
  180. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js +0 -346
  181. package/dist/parser/tests/expression/NullCoalescenceExpression.spec.js.map +0 -1
  182. package/dist/parser/tests/expression/PrefixUnary.spec.d.ts +0 -1
  183. package/dist/parser/tests/expression/PrefixUnary.spec.js +0 -105
  184. package/dist/parser/tests/expression/PrefixUnary.spec.js.map +0 -1
  185. package/dist/parser/tests/expression/Primary.spec.d.ts +0 -1
  186. package/dist/parser/tests/expression/Primary.spec.js +0 -149
  187. package/dist/parser/tests/expression/Primary.spec.js.map +0 -1
  188. package/dist/parser/tests/expression/RegexLiteralExpression.spec.d.ts +0 -1
  189. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js +0 -171
  190. package/dist/parser/tests/expression/RegexLiteralExpression.spec.js.map +0 -1
  191. package/dist/parser/tests/expression/Relational.spec.d.ts +0 -1
  192. package/dist/parser/tests/expression/Relational.spec.js +0 -83
  193. package/dist/parser/tests/expression/Relational.spec.js.map +0 -1
  194. package/dist/parser/tests/expression/SourceLiteralExpression.spec.d.ts +0 -1
  195. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js +0 -201
  196. package/dist/parser/tests/expression/SourceLiteralExpression.spec.js.map +0 -1
  197. package/dist/parser/tests/expression/TemplateStringExpression.spec.d.ts +0 -1
  198. package/dist/parser/tests/expression/TemplateStringExpression.spec.js +0 -389
  199. package/dist/parser/tests/expression/TemplateStringExpression.spec.js.map +0 -1
  200. package/dist/parser/tests/expression/TernaryExpression.spec.d.ts +0 -1
  201. package/dist/parser/tests/expression/TernaryExpression.spec.js +0 -876
  202. package/dist/parser/tests/expression/TernaryExpression.spec.js.map +0 -1
  203. package/dist/parser/tests/expression/UnaryExpression.spec.d.ts +0 -1
  204. package/dist/parser/tests/expression/UnaryExpression.spec.js +0 -52
  205. package/dist/parser/tests/expression/UnaryExpression.spec.js.map +0 -1
  206. package/dist/parser/tests/statement/AssignmentOperators.spec.d.ts +0 -1
  207. package/dist/parser/tests/statement/AssignmentOperators.spec.js +0 -79
  208. package/dist/parser/tests/statement/AssignmentOperators.spec.js.map +0 -1
  209. package/dist/parser/tests/statement/ConstStatement.spec.d.ts +0 -1
  210. package/dist/parser/tests/statement/ConstStatement.spec.js +0 -708
  211. package/dist/parser/tests/statement/ConstStatement.spec.js.map +0 -1
  212. package/dist/parser/tests/statement/Continue.spec.d.ts +0 -1
  213. package/dist/parser/tests/statement/Continue.spec.js +0 -119
  214. package/dist/parser/tests/statement/Continue.spec.js.map +0 -1
  215. package/dist/parser/tests/statement/Declaration.spec.d.ts +0 -1
  216. package/dist/parser/tests/statement/Declaration.spec.js +0 -108
  217. package/dist/parser/tests/statement/Declaration.spec.js.map +0 -1
  218. package/dist/parser/tests/statement/Dim.spec.d.ts +0 -1
  219. package/dist/parser/tests/statement/Dim.spec.js +0 -73
  220. package/dist/parser/tests/statement/Dim.spec.js.map +0 -1
  221. package/dist/parser/tests/statement/Enum.spec.d.ts +0 -1
  222. package/dist/parser/tests/statement/Enum.spec.js +0 -1307
  223. package/dist/parser/tests/statement/Enum.spec.js.map +0 -1
  224. package/dist/parser/tests/statement/For.spec.d.ts +0 -1
  225. package/dist/parser/tests/statement/For.spec.js +0 -45
  226. package/dist/parser/tests/statement/For.spec.js.map +0 -1
  227. package/dist/parser/tests/statement/ForEach.spec.d.ts +0 -1
  228. package/dist/parser/tests/statement/ForEach.spec.js +0 -36
  229. package/dist/parser/tests/statement/ForEach.spec.js.map +0 -1
  230. package/dist/parser/tests/statement/Function.spec.d.ts +0 -1
  231. package/dist/parser/tests/statement/Function.spec.js +0 -342
  232. package/dist/parser/tests/statement/Function.spec.js.map +0 -1
  233. package/dist/parser/tests/statement/Goto.spec.d.ts +0 -1
  234. package/dist/parser/tests/statement/Goto.spec.js +0 -51
  235. package/dist/parser/tests/statement/Goto.spec.js.map +0 -1
  236. package/dist/parser/tests/statement/Increment.spec.d.ts +0 -1
  237. package/dist/parser/tests/statement/Increment.spec.js +0 -117
  238. package/dist/parser/tests/statement/Increment.spec.js.map +0 -1
  239. package/dist/parser/tests/statement/InterfaceStatement.spec.d.ts +0 -1
  240. package/dist/parser/tests/statement/InterfaceStatement.spec.js +0 -102
  241. package/dist/parser/tests/statement/InterfaceStatement.spec.js.map +0 -1
  242. package/dist/parser/tests/statement/LibraryStatement.spec.d.ts +0 -1
  243. package/dist/parser/tests/statement/LibraryStatement.spec.js +0 -74
  244. package/dist/parser/tests/statement/LibraryStatement.spec.js.map +0 -1
  245. package/dist/parser/tests/statement/Misc.spec.d.ts +0 -1
  246. package/dist/parser/tests/statement/Misc.spec.js +0 -335
  247. package/dist/parser/tests/statement/Misc.spec.js.map +0 -1
  248. package/dist/parser/tests/statement/PrintStatement.spec.d.ts +0 -1
  249. package/dist/parser/tests/statement/PrintStatement.spec.js +0 -195
  250. package/dist/parser/tests/statement/PrintStatement.spec.js.map +0 -1
  251. package/dist/parser/tests/statement/ReturnStatement.spec.d.ts +0 -1
  252. package/dist/parser/tests/statement/ReturnStatement.spec.js +0 -94
  253. package/dist/parser/tests/statement/ReturnStatement.spec.js.map +0 -1
  254. package/dist/parser/tests/statement/Set.spec.d.ts +0 -1
  255. package/dist/parser/tests/statement/Set.spec.js +0 -218
  256. package/dist/parser/tests/statement/Set.spec.js.map +0 -1
  257. package/dist/parser/tests/statement/Stop.spec.d.ts +0 -1
  258. package/dist/parser/tests/statement/Stop.spec.js +0 -38
  259. package/dist/parser/tests/statement/Stop.spec.js.map +0 -1
  260. package/dist/parser/tests/statement/Throw.spec.d.ts +0 -1
  261. package/dist/parser/tests/statement/Throw.spec.js +0 -35
  262. package/dist/parser/tests/statement/Throw.spec.js.map +0 -1
  263. package/dist/parser/tests/statement/TryCatch.spec.d.ts +0 -1
  264. package/dist/parser/tests/statement/TryCatch.spec.js +0 -142
  265. package/dist/parser/tests/statement/TryCatch.spec.js.map +0 -1
  266. package/dist/preprocessor/Manifest.spec.d.ts +0 -1
  267. package/dist/preprocessor/Manifest.spec.js +0 -80
  268. package/dist/preprocessor/Manifest.spec.js.map +0 -1
  269. package/dist/preprocessor/Preprocessor.spec.d.ts +0 -1
  270. package/dist/preprocessor/Preprocessor.spec.js +0 -152
  271. package/dist/preprocessor/Preprocessor.spec.js.map +0 -1
  272. package/dist/preprocessor/PreprocessorParser.spec.d.ts +0 -1
  273. package/dist/preprocessor/PreprocessorParser.spec.js +0 -116
  274. package/dist/preprocessor/PreprocessorParser.spec.js.map +0 -1
  275. package/dist/types/ArrayType.spec.d.ts +0 -1
  276. package/dist/types/ArrayType.spec.js +0 -30
  277. package/dist/types/ArrayType.spec.js.map +0 -1
  278. package/dist/types/BooleanType.spec.d.ts +0 -1
  279. package/dist/types/BooleanType.spec.js +0 -12
  280. package/dist/types/BooleanType.spec.js.map +0 -1
  281. package/dist/types/DoubleType.spec.d.ts +0 -1
  282. package/dist/types/DoubleType.spec.js +0 -12
  283. package/dist/types/DoubleType.spec.js.map +0 -1
  284. package/dist/types/DynamicType.spec.d.ts +0 -1
  285. package/dist/types/DynamicType.spec.js +0 -12
  286. package/dist/types/DynamicType.spec.js.map +0 -1
  287. package/dist/types/FloatType.spec.d.ts +0 -1
  288. package/dist/types/FloatType.spec.js +0 -12
  289. package/dist/types/FloatType.spec.js.map +0 -1
  290. package/dist/types/FunctionType.spec.d.ts +0 -1
  291. package/dist/types/FunctionType.spec.js +0 -23
  292. package/dist/types/FunctionType.spec.js.map +0 -1
  293. package/dist/types/IntegerType.spec.d.ts +0 -1
  294. package/dist/types/IntegerType.spec.js +0 -12
  295. package/dist/types/IntegerType.spec.js.map +0 -1
  296. package/dist/types/InterfaceType.spec.d.ts +0 -1
  297. package/dist/types/InterfaceType.spec.js +0 -175
  298. package/dist/types/InterfaceType.spec.js.map +0 -1
  299. package/dist/types/InvalidType.spec.d.ts +0 -1
  300. package/dist/types/InvalidType.spec.js +0 -12
  301. package/dist/types/InvalidType.spec.js.map +0 -1
  302. package/dist/types/LongIntegerType.spec.d.ts +0 -1
  303. package/dist/types/LongIntegerType.spec.js +0 -12
  304. package/dist/types/LongIntegerType.spec.js.map +0 -1
  305. package/dist/types/ObjectType.spec.d.ts +0 -1
  306. package/dist/types/ObjectType.spec.js +0 -12
  307. package/dist/types/ObjectType.spec.js.map +0 -1
  308. package/dist/types/StringType.spec.d.ts +0 -1
  309. package/dist/types/StringType.spec.js +0 -12
  310. package/dist/types/StringType.spec.js.map +0 -1
  311. package/dist/types/VoidType.spec.d.ts +0 -1
  312. package/dist/types/VoidType.spec.js +0 -12
  313. package/dist/types/VoidType.spec.js.map +0 -1
@@ -1,1300 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- /* eslint no-template-curly-in-string: 0 */
4
- const chai_config_spec_1 = require("../chai-config.spec");
5
- const TokenKind_1 = require("./TokenKind");
6
- const Lexer_1 = require("./Lexer");
7
- const Token_1 = require("./Token");
8
- const Parser_spec_1 = require("../parser/Parser.spec");
9
- const vscode_languageserver_1 = require("vscode-languageserver");
10
- const util_1 = require("../util");
11
- describe('lexer', () => {
12
- it('recognizes the `const` keyword', () => {
13
- let { tokens } = Lexer_1.Lexer.scan('const');
14
- (0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
15
- TokenKind_1.TokenKind.Const,
16
- TokenKind_1.TokenKind.Eof
17
- ]);
18
- });
19
- it('recognizes namespace keywords', () => {
20
- let { tokens } = Lexer_1.Lexer.scan('namespace end namespace endnamespace end namespace');
21
- (0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
22
- TokenKind_1.TokenKind.Namespace,
23
- TokenKind_1.TokenKind.EndNamespace,
24
- TokenKind_1.TokenKind.EndNamespace,
25
- TokenKind_1.TokenKind.EndNamespace,
26
- TokenKind_1.TokenKind.Eof
27
- ]);
28
- });
29
- it('recognizes the question mark operator in various contexts', () => {
30
- expectKinds('? ?? ?. ?[ ?.[ ?( ?@', [
31
- TokenKind_1.TokenKind.Question,
32
- TokenKind_1.TokenKind.QuestionQuestion,
33
- TokenKind_1.TokenKind.QuestionDot,
34
- TokenKind_1.TokenKind.QuestionLeftSquare,
35
- TokenKind_1.TokenKind.QuestionDot,
36
- TokenKind_1.TokenKind.LeftSquareBracket,
37
- TokenKind_1.TokenKind.QuestionLeftParen,
38
- TokenKind_1.TokenKind.QuestionAt
39
- ]);
40
- });
41
- it('separates optional chain characters and LeftSquare when found at beginning of statement locations', () => {
42
- //a statement starting with a question mark is actually a print statement, so we need to keep the ? separate from [
43
- expectKinds(`?[ ?[ : ?[ ?[`, [
44
- TokenKind_1.TokenKind.Question,
45
- TokenKind_1.TokenKind.LeftSquareBracket,
46
- TokenKind_1.TokenKind.QuestionLeftSquare,
47
- TokenKind_1.TokenKind.Colon,
48
- TokenKind_1.TokenKind.Question,
49
- TokenKind_1.TokenKind.LeftSquareBracket,
50
- TokenKind_1.TokenKind.QuestionLeftSquare
51
- ]);
52
- });
53
- it('separates optional chain characters and LeftParen when found at beginning of statement locations', () => {
54
- //a statement starting with a question mark is actually a print statement, so we need to keep the ? separate from [
55
- expectKinds(`?( ?( : ?( ?(`, [
56
- TokenKind_1.TokenKind.Question,
57
- TokenKind_1.TokenKind.LeftParen,
58
- TokenKind_1.TokenKind.QuestionLeftParen,
59
- TokenKind_1.TokenKind.Colon,
60
- TokenKind_1.TokenKind.Question,
61
- TokenKind_1.TokenKind.LeftParen,
62
- TokenKind_1.TokenKind.QuestionLeftParen
63
- ]);
64
- });
65
- it('handles QuestionDot and Square properly', () => {
66
- expectKinds('?.[ ?. [', [
67
- TokenKind_1.TokenKind.QuestionDot,
68
- TokenKind_1.TokenKind.LeftSquareBracket,
69
- TokenKind_1.TokenKind.QuestionDot,
70
- TokenKind_1.TokenKind.LeftSquareBracket
71
- ]);
72
- });
73
- it('does not make conditional chaining tokens with space between', () => {
74
- expectKinds('? . ? [ ? ( ? @', [
75
- TokenKind_1.TokenKind.Question,
76
- TokenKind_1.TokenKind.Dot,
77
- TokenKind_1.TokenKind.Question,
78
- TokenKind_1.TokenKind.LeftSquareBracket,
79
- TokenKind_1.TokenKind.Question,
80
- TokenKind_1.TokenKind.LeftParen,
81
- TokenKind_1.TokenKind.Question,
82
- TokenKind_1.TokenKind.At
83
- ]);
84
- });
85
- it('recognizes the callfunc operator', () => {
86
- let { tokens } = Lexer_1.Lexer.scan('@.');
87
- (0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.Callfunc);
88
- });
89
- it('recognizes the import token', () => {
90
- let { tokens } = Lexer_1.Lexer.scan('import');
91
- (0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.Import);
92
- });
93
- it('recognizes library token', () => {
94
- let { tokens } = Lexer_1.Lexer.scan('library');
95
- (0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.Library);
96
- });
97
- it('produces an at symbol token', () => {
98
- let { tokens } = Lexer_1.Lexer.scan('@');
99
- (0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.At);
100
- });
101
- it('produces a semicolon token', () => {
102
- let { tokens } = Lexer_1.Lexer.scan(';');
103
- (0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.Semicolon);
104
- });
105
- it('emits error on unknown character type', () => {
106
- let { diagnostics } = Lexer_1.Lexer.scan('\0');
107
- (0, chai_config_spec_1.expect)(diagnostics).to.be.lengthOf(1);
108
- });
109
- it('includes an end-of-file marker', () => {
110
- let { tokens } = Lexer_1.Lexer.scan('');
111
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Eof]);
112
- });
113
- it('ignores tabs and spaces', () => {
114
- let { tokens } = Lexer_1.Lexer.scan('\t\t \t \t');
115
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Eof]);
116
- });
117
- it('retains every single newline', () => {
118
- let { tokens } = Lexer_1.Lexer.scan('\n\n\'foo\n\n\nprint 2\n\n');
119
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
120
- TokenKind_1.TokenKind.Newline,
121
- TokenKind_1.TokenKind.Newline,
122
- TokenKind_1.TokenKind.Comment,
123
- TokenKind_1.TokenKind.Newline,
124
- TokenKind_1.TokenKind.Newline,
125
- TokenKind_1.TokenKind.Newline,
126
- TokenKind_1.TokenKind.Print,
127
- TokenKind_1.TokenKind.IntegerLiteral,
128
- TokenKind_1.TokenKind.Newline,
129
- TokenKind_1.TokenKind.Newline,
130
- TokenKind_1.TokenKind.Eof
131
- ]);
132
- });
133
- it('does not insert double newlines with the windows \\r\\n newline', () => {
134
- let kinds = Lexer_1.Lexer.scan('function boolToNumber() as string\r\n' +
135
- ' if true then\r\n' +
136
- ' print 1\r\n' +
137
- ' else\r\n' +
138
- ' print 0\r\n' +
139
- ' end if\r\n' +
140
- 'end function\r\n').tokens.map(x => x.kind);
141
- (0, chai_config_spec_1.expect)(kinds).to.eql([
142
- TokenKind_1.TokenKind.Function, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.LeftParen, TokenKind_1.TokenKind.RightParen, TokenKind_1.TokenKind.As, TokenKind_1.TokenKind.String, TokenKind_1.TokenKind.Newline,
143
- TokenKind_1.TokenKind.If, TokenKind_1.TokenKind.True, TokenKind_1.TokenKind.Then, TokenKind_1.TokenKind.Newline,
144
- TokenKind_1.TokenKind.Print, TokenKind_1.TokenKind.IntegerLiteral, TokenKind_1.TokenKind.Newline,
145
- TokenKind_1.TokenKind.Else, TokenKind_1.TokenKind.Newline,
146
- TokenKind_1.TokenKind.Print, TokenKind_1.TokenKind.IntegerLiteral, TokenKind_1.TokenKind.Newline,
147
- TokenKind_1.TokenKind.EndIf, TokenKind_1.TokenKind.Newline,
148
- TokenKind_1.TokenKind.EndFunction, TokenKind_1.TokenKind.Newline,
149
- TokenKind_1.TokenKind.Eof
150
- ]);
151
- });
152
- it('computes range properly both with and without whitespace', () => {
153
- let withoutWhitespace = Lexer_1.Lexer.scan(`sub Main()\n bob = true\nend sub`).tokens
154
- .map(x => (0, Parser_spec_1.rangeToArray)(x.range));
155
- let withWhitespace = Lexer_1.Lexer.scan(`sub Main()\n bob = true\nend sub`).tokens
156
- //filter out the whitespace...we only care that it was computed during the scan
157
- .filter(x => x.kind !== TokenKind_1.TokenKind.Whitespace)
158
- .map(x => (0, Parser_spec_1.rangeToArray)(x.range));
159
- /*eslint-disable */
160
- let expectedLocations = [
161
- [0, 0, 0, 3],
162
- [0, 4, 0, 8],
163
- [0, 8, 0, 9],
164
- [0, 9, 0, 10],
165
- [0, 10, 0, 11],
166
- [1, 4, 1, 7],
167
- [1, 8, 1, 9],
168
- [1, 10, 1, 14],
169
- [1, 14, 1, 15],
170
- [2, 0, 2, 7],
171
- [2, 7, 2, 8] //Eof
172
- ];
173
- /*eslint-enable*/
174
- (0, chai_config_spec_1.expect)(withoutWhitespace, 'Without whitespace').to.eql(expectedLocations);
175
- (0, chai_config_spec_1.expect)(withWhitespace, 'With whitespace').to.eql(expectedLocations);
176
- });
177
- it('retains original line endings', () => {
178
- let { tokens } = Lexer_1.Lexer.scan('print "hello"\r\nprint "world"\n');
179
- (0, chai_config_spec_1.expect)([
180
- tokens[2].text.charCodeAt(0),
181
- tokens[2].text.charCodeAt(1)
182
- ], 'should contain \\r\\n').to.eql([13, 10]);
183
- (0, chai_config_spec_1.expect)(tokens[5].text.charCodeAt(0), 'should contain \\r\\n').to.eql(10);
184
- });
185
- it('correctly splits the elseif token', () => {
186
- let { tokens } = Lexer_1.Lexer.scan('else if elseif else if');
187
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
188
- TokenKind_1.TokenKind.Else,
189
- TokenKind_1.TokenKind.If,
190
- TokenKind_1.TokenKind.Else,
191
- TokenKind_1.TokenKind.If,
192
- TokenKind_1.TokenKind.Else,
193
- TokenKind_1.TokenKind.If,
194
- TokenKind_1.TokenKind.Eof
195
- ]);
196
- });
197
- it('gives the `as` keyword its own TokenKind', () => {
198
- let { tokens } = Lexer_1.Lexer.scan('as');
199
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.As, TokenKind_1.TokenKind.Eof]);
200
- });
201
- it('gives the `stop` keyword its own TokenKind', () => {
202
- let { tokens } = Lexer_1.Lexer.scan('stop');
203
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Stop, TokenKind_1.TokenKind.Eof]);
204
- });
205
- it('does not alias \'?\' to \'print\' - the parser will do that', () => {
206
- let { tokens } = Lexer_1.Lexer.scan('?2');
207
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Question, TokenKind_1.TokenKind.IntegerLiteral, TokenKind_1.TokenKind.Eof]);
208
- });
209
- describe('comments', () => {
210
- it('does not include carriage return character', () => {
211
- let tokens = Lexer_1.Lexer.scan(`'someComment\r\nprint "hello"`).tokens;
212
- (0, chai_config_spec_1.expect)(tokens[0].text).to.equal(`'someComment`);
213
- });
214
- it('includes the comment characters in the text', () => {
215
- let text = Lexer_1.Lexer.scan(`
216
- 'comment
217
- REM some comment
218
- `).tokens
219
- .filter(x => ![TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Eof].includes(x.kind))
220
- .map(x => x.text);
221
- (0, chai_config_spec_1.expect)(text).to.eql([
222
- `'comment`,
223
- 'REM some comment'
224
- ]);
225
- });
226
- it('tracks the correct location', () => {
227
- let tokens = Lexer_1.Lexer.scan(`
228
- sub main() 'first comment
229
- k = 2 ' second comment
230
- REM third comment
231
- end sub
232
- `, {
233
- includeWhitespace: true
234
- }).tokens.map(x => [...(0, Parser_spec_1.rangeToArray)(x.range), x.text]);
235
- (0, chai_config_spec_1.expect)(tokens).to.eql([
236
- [0, 0, 0, 1, '\n'],
237
- [1, 0, 1, 16, ' '],
238
- [1, 16, 1, 19, 'sub'],
239
- [1, 19, 1, 20, ' '],
240
- [1, 20, 1, 24, 'main'],
241
- [1, 24, 1, 25, '('],
242
- [1, 25, 1, 26, ')'],
243
- [1, 26, 1, 27, ' '],
244
- [1, 27, 1, 41, `'first comment`],
245
- [1, 41, 1, 42, '\n'],
246
- [2, 0, 2, 20, ' '],
247
- [2, 20, 2, 21, 'k'],
248
- [2, 21, 2, 22, ' '],
249
- [2, 22, 2, 23, '='],
250
- [2, 23, 2, 24, ' '],
251
- [2, 24, 2, 25, '2'],
252
- [2, 25, 2, 26, ' '],
253
- [2, 26, 2, 42, `' second comment`],
254
- [2, 42, 2, 43, '\n'],
255
- [3, 0, 3, 20, ' '],
256
- [3, 20, 3, 37, 'REM third comment'],
257
- [3, 37, 3, 38, '\n'],
258
- [4, 0, 4, 16, ' '],
259
- [4, 16, 4, 23, 'end sub'],
260
- [4, 23, 4, 24, '\n'],
261
- [5, 0, 5, 12, ' '],
262
- [5, 12, 5, 13, ''] //EOF
263
- ]);
264
- });
265
- it('tracks the correct location for comments', () => {
266
- let tokens = Lexer_1.Lexer.scan(`
267
- 'comment
268
- REM some comment
269
- `).tokens.filter(x => ![TokenKind_1.TokenKind.Newline, TokenKind_1.TokenKind.Eof].includes(x.kind));
270
- (0, chai_config_spec_1.expect)(tokens[0].range).to.eql(vscode_languageserver_1.Range.create(1, 16, 1, 24));
271
- (0, chai_config_spec_1.expect)(tokens[1].range).to.eql(vscode_languageserver_1.Range.create(2, 16, 2, 32));
272
- });
273
- it('finds correct location for newlines', () => {
274
- let tokens = Lexer_1.Lexer.scan('sub\nsub\r\nsub\n\n').tokens
275
- //ignore the Eof token
276
- .filter(x => x.kind !== TokenKind_1.TokenKind.Eof);
277
- (0, chai_config_spec_1.expect)(tokens.map(x => x.range)).to.eql([
278
- vscode_languageserver_1.Range.create(0, 0, 0, 3),
279
- vscode_languageserver_1.Range.create(0, 3, 0, 4),
280
- vscode_languageserver_1.Range.create(1, 0, 1, 3),
281
- vscode_languageserver_1.Range.create(1, 3, 1, 5),
282
- vscode_languageserver_1.Range.create(2, 0, 2, 3),
283
- vscode_languageserver_1.Range.create(2, 3, 2, 4),
284
- vscode_languageserver_1.Range.create(3, 0, 3, 1) // /n
285
- ]);
286
- });
287
- it('finds correct location for comment after if statement', () => {
288
- let { tokens } = Lexer_1.Lexer.scan(`
289
- sub a()
290
- if true then
291
- print false
292
- else if true then
293
- print "true"
294
- else
295
- print "else"
296
- end if 'comment
297
- end sub
298
- `);
299
- let comments = tokens.filter(x => x.kind === TokenKind_1.TokenKind.Comment);
300
- (0, chai_config_spec_1.expect)(comments).to.be.lengthOf(1);
301
- (0, chai_config_spec_1.expect)(comments[0].range).to.eql(vscode_languageserver_1.Range.create(8, 27, 8, 35));
302
- });
303
- it('ignores everything after `\'`', () => {
304
- let { tokens } = Lexer_1.Lexer.scan('= \' (');
305
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Comment, TokenKind_1.TokenKind.Eof]);
306
- });
307
- it('ignores everything after `REM`', () => {
308
- let { tokens } = Lexer_1.Lexer.scan('= REM (');
309
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Comment, TokenKind_1.TokenKind.Eof]);
310
- });
311
- it('ignores everything after `rem`', () => {
312
- let { tokens } = Lexer_1.Lexer.scan('= rem (');
313
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.Comment, TokenKind_1.TokenKind.Eof]);
314
- });
315
- }); // comments
316
- describe('non-literals', () => {
317
- it('reads parens & braces', () => {
318
- let { tokens } = Lexer_1.Lexer.scan('(){}');
319
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
320
- TokenKind_1.TokenKind.LeftParen,
321
- TokenKind_1.TokenKind.RightParen,
322
- TokenKind_1.TokenKind.LeftCurlyBrace,
323
- TokenKind_1.TokenKind.RightCurlyBrace,
324
- TokenKind_1.TokenKind.Eof
325
- ]);
326
- });
327
- it('reads operators', () => {
328
- let { tokens } = Lexer_1.Lexer.scan('^ - + * MOD / \\ -- ++');
329
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
330
- TokenKind_1.TokenKind.Caret,
331
- TokenKind_1.TokenKind.Minus,
332
- TokenKind_1.TokenKind.Plus,
333
- TokenKind_1.TokenKind.Star,
334
- TokenKind_1.TokenKind.Mod,
335
- TokenKind_1.TokenKind.Forwardslash,
336
- TokenKind_1.TokenKind.Backslash,
337
- TokenKind_1.TokenKind.MinusMinus,
338
- TokenKind_1.TokenKind.PlusPlus,
339
- TokenKind_1.TokenKind.Eof
340
- ]);
341
- });
342
- it('reads bitshift operators', () => {
343
- let { tokens } = Lexer_1.Lexer.scan('<< >> <<');
344
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
345
- TokenKind_1.TokenKind.LeftShift,
346
- TokenKind_1.TokenKind.RightShift,
347
- TokenKind_1.TokenKind.LeftShift,
348
- TokenKind_1.TokenKind.Eof
349
- ]);
350
- });
351
- it('reads bitshift assignment operators', () => {
352
- let { tokens } = Lexer_1.Lexer.scan('<<= >>=');
353
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
354
- TokenKind_1.TokenKind.LeftShiftEqual,
355
- TokenKind_1.TokenKind.RightShiftEqual,
356
- TokenKind_1.TokenKind.Eof
357
- ]);
358
- });
359
- it('reads comparators', () => {
360
- let { tokens } = Lexer_1.Lexer.scan('< <= > >= = <>');
361
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
362
- TokenKind_1.TokenKind.Less,
363
- TokenKind_1.TokenKind.LessEqual,
364
- TokenKind_1.TokenKind.Greater,
365
- TokenKind_1.TokenKind.GreaterEqual,
366
- TokenKind_1.TokenKind.Equal,
367
- TokenKind_1.TokenKind.LessGreater,
368
- TokenKind_1.TokenKind.Eof
369
- ]);
370
- });
371
- }); // non-literals
372
- describe('string literals', () => {
373
- it('produces string literal tokens', () => {
374
- let { tokens } = Lexer_1.Lexer.scan(`"hello world"`);
375
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([TokenKind_1.TokenKind.StringLiteral, TokenKind_1.TokenKind.Eof]);
376
- });
377
- it(`safely escapes " literals`, () => {
378
- let { tokens } = Lexer_1.Lexer.scan(`"the cat says ""meow"""`);
379
- (0, chai_config_spec_1.expect)(tokens[0].kind).to.equal(TokenKind_1.TokenKind.StringLiteral);
380
- });
381
- it('captures text to end of line for unterminated strings with LF', () => {
382
- let { tokens } = Lexer_1.Lexer.scan(`"unterminated!\n`);
383
- (0, chai_config_spec_1.expect)(tokens[0].kind).to.eql(TokenKind_1.TokenKind.StringLiteral);
384
- });
385
- it('captures text to end of line for unterminated strings with CRLF', () => {
386
- let { tokens } = Lexer_1.Lexer.scan(`"unterminated!\r\n`);
387
- (0, chai_config_spec_1.expect)(tokens[0].text).to.equal('"unterminated!');
388
- });
389
- it('disallows multiline strings', () => {
390
- let { diagnostics } = Lexer_1.Lexer.scan(`"multi-line\n\n`);
391
- (0, chai_config_spec_1.expect)(diagnostics.map(err => err.message)).to.deep.equal([
392
- 'Unterminated string at end of line'
393
- ]);
394
- });
395
- });
396
- // template string literals
397
- describe('template string literals', () => {
398
- it('supports escaped chars', () => {
399
- let { tokens } = Lexer_1.Lexer.scan('`\\n\\`\\r\\n`');
400
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
401
- TokenKind_1.TokenKind.BackTick,
402
- TokenKind_1.TokenKind.TemplateStringQuasi,
403
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
404
- TokenKind_1.TokenKind.TemplateStringQuasi,
405
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
406
- TokenKind_1.TokenKind.TemplateStringQuasi,
407
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
408
- TokenKind_1.TokenKind.TemplateStringQuasi,
409
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
410
- TokenKind_1.TokenKind.TemplateStringQuasi,
411
- TokenKind_1.TokenKind.BackTick,
412
- TokenKind_1.TokenKind.Eof
413
- ]);
414
- (0, chai_config_spec_1.expect)(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
415
- 10,
416
- 96,
417
- 13,
418
- 10
419
- ]);
420
- });
421
- it('prevents expressions when escaping the dollar sign', () => {
422
- let { tokens } = Lexer_1.Lexer.scan('`\\${just text}`');
423
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
424
- TokenKind_1.TokenKind.BackTick,
425
- TokenKind_1.TokenKind.TemplateStringQuasi,
426
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
427
- TokenKind_1.TokenKind.TemplateStringQuasi,
428
- TokenKind_1.TokenKind.BackTick,
429
- TokenKind_1.TokenKind.Eof
430
- ]);
431
- });
432
- it('supports escaping unicode char codes', () => {
433
- let { tokens } = Lexer_1.Lexer.scan('`\\c1\\c12\\c123`');
434
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
435
- TokenKind_1.TokenKind.BackTick,
436
- TokenKind_1.TokenKind.TemplateStringQuasi,
437
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
438
- TokenKind_1.TokenKind.TemplateStringQuasi,
439
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
440
- TokenKind_1.TokenKind.TemplateStringQuasi,
441
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
442
- TokenKind_1.TokenKind.TemplateStringQuasi,
443
- TokenKind_1.TokenKind.BackTick,
444
- TokenKind_1.TokenKind.Eof
445
- ]);
446
- (0, chai_config_spec_1.expect)(tokens.map(x => x.charCode).filter(x => !!x)).to.eql([
447
- 1,
448
- 12,
449
- 123
450
- ]);
451
- });
452
- it('converts doublequote to EscapedCharCodeLiteral', () => {
453
- let { tokens } = Lexer_1.Lexer.scan('`"`');
454
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
455
- TokenKind_1.TokenKind.BackTick,
456
- TokenKind_1.TokenKind.TemplateStringQuasi,
457
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
458
- TokenKind_1.TokenKind.TemplateStringQuasi,
459
- TokenKind_1.TokenKind.BackTick,
460
- TokenKind_1.TokenKind.Eof
461
- ]);
462
- (0, chai_config_spec_1.expect)(tokens[2].charCode).to.equal(34);
463
- });
464
- it(`safely escapes \` literals`, () => {
465
- let { tokens } = Lexer_1.Lexer.scan('`the cat says \\`meow\\` a lot`');
466
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
467
- TokenKind_1.TokenKind.BackTick,
468
- TokenKind_1.TokenKind.TemplateStringQuasi,
469
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
470
- TokenKind_1.TokenKind.TemplateStringQuasi,
471
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
472
- TokenKind_1.TokenKind.TemplateStringQuasi,
473
- TokenKind_1.TokenKind.BackTick,
474
- TokenKind_1.TokenKind.Eof
475
- ]);
476
- (0, chai_config_spec_1.expect)(tokens.map(x => x.text)).to.eql([
477
- '`',
478
- 'the cat says ',
479
- '\\`',
480
- 'meow',
481
- '\\`',
482
- ' a lot',
483
- '`',
484
- '' //EOF
485
- ]);
486
- });
487
- it('produces template string literal tokens', () => {
488
- let { tokens } = Lexer_1.Lexer.scan('`hello world`');
489
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
490
- TokenKind_1.TokenKind.BackTick,
491
- TokenKind_1.TokenKind.TemplateStringQuasi,
492
- TokenKind_1.TokenKind.BackTick,
493
- TokenKind_1.TokenKind.Eof
494
- ]);
495
- (0, chai_config_spec_1.expect)(tokens[1].text).to.deep.equal('hello world');
496
- });
497
- it('collects quasis outside and expressions inside of template strings', () => {
498
- let { tokens } = Lexer_1.Lexer.scan('`hello ${"world"}!`');
499
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
500
- TokenKind_1.TokenKind.BackTick,
501
- TokenKind_1.TokenKind.TemplateStringQuasi,
502
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
503
- TokenKind_1.TokenKind.StringLiteral,
504
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
505
- TokenKind_1.TokenKind.TemplateStringQuasi,
506
- TokenKind_1.TokenKind.BackTick,
507
- TokenKind_1.TokenKind.Eof
508
- ]);
509
- (0, chai_config_spec_1.expect)(tokens[1].text).to.deep.equal(`hello `);
510
- });
511
- it('real example, which is causing issues in the formatter', () => {
512
- let { tokens } = Lexer_1.Lexer.scan(`
513
- function getItemXML(item)
514
- return \`
515
- <rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
516
- <channel>
517
- <title>smithsonian</title>
518
- <item>
519
- <title>\${item.title}</title>
520
- <guid>\${item.vamsId}</guid>
521
- <media:rating scheme="urn:v-chip">\${item.ratings.first.code.name}</media:rating>
522
- </item>
523
- </channel>
524
- </rss>
525
- \`
526
- end function
527
- `);
528
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
529
- TokenKind_1.TokenKind.Newline,
530
- TokenKind_1.TokenKind.Function,
531
- TokenKind_1.TokenKind.Identifier,
532
- TokenKind_1.TokenKind.LeftParen,
533
- TokenKind_1.TokenKind.Identifier,
534
- TokenKind_1.TokenKind.RightParen,
535
- TokenKind_1.TokenKind.Newline,
536
- TokenKind_1.TokenKind.Return,
537
- TokenKind_1.TokenKind.BackTick,
538
- TokenKind_1.TokenKind.TemplateStringQuasi,
539
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
540
- TokenKind_1.TokenKind.TemplateStringQuasi,
541
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
542
- TokenKind_1.TokenKind.TemplateStringQuasi,
543
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
544
- TokenKind_1.TokenKind.TemplateStringQuasi,
545
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
546
- TokenKind_1.TokenKind.TemplateStringQuasi,
547
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
548
- TokenKind_1.TokenKind.TemplateStringQuasi,
549
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
550
- TokenKind_1.TokenKind.TemplateStringQuasi,
551
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
552
- TokenKind_1.TokenKind.TemplateStringQuasi,
553
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
554
- TokenKind_1.TokenKind.TemplateStringQuasi,
555
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
556
- TokenKind_1.TokenKind.TemplateStringQuasi,
557
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
558
- TokenKind_1.TokenKind.Identifier,
559
- TokenKind_1.TokenKind.Dot,
560
- TokenKind_1.TokenKind.Identifier,
561
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
562
- TokenKind_1.TokenKind.TemplateStringQuasi,
563
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
564
- TokenKind_1.TokenKind.TemplateStringQuasi,
565
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
566
- TokenKind_1.TokenKind.Identifier,
567
- TokenKind_1.TokenKind.Dot,
568
- TokenKind_1.TokenKind.Identifier,
569
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
570
- TokenKind_1.TokenKind.TemplateStringQuasi,
571
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
572
- TokenKind_1.TokenKind.TemplateStringQuasi,
573
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
574
- TokenKind_1.TokenKind.TemplateStringQuasi,
575
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
576
- TokenKind_1.TokenKind.TemplateStringQuasi,
577
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
578
- TokenKind_1.TokenKind.Identifier,
579
- TokenKind_1.TokenKind.Dot,
580
- TokenKind_1.TokenKind.Identifier,
581
- TokenKind_1.TokenKind.Dot,
582
- TokenKind_1.TokenKind.Identifier,
583
- TokenKind_1.TokenKind.Dot,
584
- TokenKind_1.TokenKind.Identifier,
585
- TokenKind_1.TokenKind.Dot,
586
- TokenKind_1.TokenKind.Identifier,
587
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
588
- TokenKind_1.TokenKind.TemplateStringQuasi,
589
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
590
- TokenKind_1.TokenKind.TemplateStringQuasi,
591
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
592
- TokenKind_1.TokenKind.TemplateStringQuasi,
593
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
594
- TokenKind_1.TokenKind.TemplateStringQuasi,
595
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
596
- TokenKind_1.TokenKind.TemplateStringQuasi,
597
- TokenKind_1.TokenKind.BackTick,
598
- TokenKind_1.TokenKind.Newline,
599
- TokenKind_1.TokenKind.EndFunction,
600
- TokenKind_1.TokenKind.Newline,
601
- TokenKind_1.TokenKind.Eof
602
- ]);
603
- });
604
- it('complicated example', () => {
605
- let { tokens } = Lexer_1.Lexer.scan('`hello ${"world"}!I am a ${"template" + "string"} and I am very ${["pleased"][0]} to meet you ${m.top.getChildCount()}.The end`');
606
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.eql([
607
- TokenKind_1.TokenKind.BackTick,
608
- TokenKind_1.TokenKind.TemplateStringQuasi,
609
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
610
- TokenKind_1.TokenKind.StringLiteral,
611
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
612
- TokenKind_1.TokenKind.TemplateStringQuasi,
613
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
614
- TokenKind_1.TokenKind.StringLiteral,
615
- TokenKind_1.TokenKind.Plus,
616
- TokenKind_1.TokenKind.StringLiteral,
617
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
618
- TokenKind_1.TokenKind.TemplateStringQuasi,
619
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
620
- TokenKind_1.TokenKind.LeftSquareBracket,
621
- TokenKind_1.TokenKind.StringLiteral,
622
- TokenKind_1.TokenKind.RightSquareBracket,
623
- TokenKind_1.TokenKind.LeftSquareBracket,
624
- TokenKind_1.TokenKind.IntegerLiteral,
625
- TokenKind_1.TokenKind.RightSquareBracket,
626
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
627
- TokenKind_1.TokenKind.TemplateStringQuasi,
628
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
629
- TokenKind_1.TokenKind.Identifier,
630
- TokenKind_1.TokenKind.Dot,
631
- TokenKind_1.TokenKind.Identifier,
632
- TokenKind_1.TokenKind.Dot,
633
- TokenKind_1.TokenKind.Identifier,
634
- TokenKind_1.TokenKind.LeftParen,
635
- TokenKind_1.TokenKind.RightParen,
636
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
637
- TokenKind_1.TokenKind.TemplateStringQuasi,
638
- TokenKind_1.TokenKind.BackTick,
639
- TokenKind_1.TokenKind.Eof
640
- ]);
641
- });
642
- it('allows multiline strings', () => {
643
- let { tokens } = Lexer_1.Lexer.scan('`multi-line\n\n`');
644
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
645
- TokenKind_1.TokenKind.BackTick,
646
- TokenKind_1.TokenKind.TemplateStringQuasi,
647
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
648
- TokenKind_1.TokenKind.TemplateStringQuasi,
649
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
650
- TokenKind_1.TokenKind.TemplateStringQuasi,
651
- TokenKind_1.TokenKind.BackTick,
652
- TokenKind_1.TokenKind.Eof
653
- ]);
654
- (0, chai_config_spec_1.expect)(tokens.map(x => x.text)).to.eql([
655
- '`',
656
- 'multi-line',
657
- '\n',
658
- '',
659
- '\n',
660
- '',
661
- '`',
662
- '' //EOF
663
- ]);
664
- });
665
- it('maintains proper line/column locations for multiline strings', () => {
666
- let { tokens } = Lexer_1.Lexer.scan('123 `multi\nline\r\nstrings` true\nfalse');
667
- (0, chai_config_spec_1.expect)(tokens.map(x => {
668
- return {
669
- range: x.range,
670
- kind: x.kind
671
- };
672
- })).to.eql([
673
- { range: vscode_languageserver_1.Range.create(0, 0, 0, 3), kind: TokenKind_1.TokenKind.IntegerLiteral },
674
- { range: vscode_languageserver_1.Range.create(0, 4, 0, 5), kind: TokenKind_1.TokenKind.BackTick },
675
- { range: vscode_languageserver_1.Range.create(0, 5, 0, 10), kind: TokenKind_1.TokenKind.TemplateStringQuasi },
676
- { range: vscode_languageserver_1.Range.create(0, 10, 0, 11), kind: TokenKind_1.TokenKind.EscapedCharCodeLiteral },
677
- { range: vscode_languageserver_1.Range.create(1, 0, 1, 4), kind: TokenKind_1.TokenKind.TemplateStringQuasi },
678
- { range: vscode_languageserver_1.Range.create(1, 4, 1, 5), kind: TokenKind_1.TokenKind.EscapedCharCodeLiteral },
679
- { range: vscode_languageserver_1.Range.create(1, 5, 1, 6), kind: TokenKind_1.TokenKind.EscapedCharCodeLiteral },
680
- { range: vscode_languageserver_1.Range.create(2, 0, 2, 7), kind: TokenKind_1.TokenKind.TemplateStringQuasi },
681
- { range: vscode_languageserver_1.Range.create(2, 7, 2, 8), kind: TokenKind_1.TokenKind.BackTick },
682
- { range: vscode_languageserver_1.Range.create(2, 9, 2, 13), kind: TokenKind_1.TokenKind.True },
683
- { range: vscode_languageserver_1.Range.create(2, 13, 2, 14), kind: TokenKind_1.TokenKind.Newline },
684
- { range: vscode_languageserver_1.Range.create(3, 0, 3, 5), kind: TokenKind_1.TokenKind.False },
685
- { range: vscode_languageserver_1.Range.create(3, 5, 3, 6), kind: TokenKind_1.TokenKind.Eof }
686
- ]);
687
- });
688
- it('Example that tripped up the expression tests', () => {
689
- let { tokens } = Lexer_1.Lexer.scan('`I am a complex example\n${a.isRunning(["a","b","c"])}\nmore ${m.finish(true)}`');
690
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
691
- TokenKind_1.TokenKind.BackTick,
692
- TokenKind_1.TokenKind.TemplateStringQuasi,
693
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
694
- TokenKind_1.TokenKind.TemplateStringQuasi,
695
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
696
- TokenKind_1.TokenKind.Identifier,
697
- TokenKind_1.TokenKind.Dot,
698
- TokenKind_1.TokenKind.Identifier,
699
- TokenKind_1.TokenKind.LeftParen,
700
- TokenKind_1.TokenKind.LeftSquareBracket,
701
- TokenKind_1.TokenKind.StringLiteral,
702
- TokenKind_1.TokenKind.Comma,
703
- TokenKind_1.TokenKind.StringLiteral,
704
- TokenKind_1.TokenKind.Comma,
705
- TokenKind_1.TokenKind.StringLiteral,
706
- TokenKind_1.TokenKind.RightSquareBracket,
707
- TokenKind_1.TokenKind.RightParen,
708
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
709
- TokenKind_1.TokenKind.TemplateStringQuasi,
710
- TokenKind_1.TokenKind.EscapedCharCodeLiteral,
711
- TokenKind_1.TokenKind.TemplateStringQuasi,
712
- TokenKind_1.TokenKind.TemplateStringExpressionBegin,
713
- TokenKind_1.TokenKind.Identifier,
714
- TokenKind_1.TokenKind.Dot,
715
- TokenKind_1.TokenKind.Identifier,
716
- TokenKind_1.TokenKind.LeftParen,
717
- TokenKind_1.TokenKind.True,
718
- TokenKind_1.TokenKind.RightParen,
719
- TokenKind_1.TokenKind.TemplateStringExpressionEnd,
720
- TokenKind_1.TokenKind.TemplateStringQuasi,
721
- TokenKind_1.TokenKind.BackTick,
722
- TokenKind_1.TokenKind.Eof
723
- ]);
724
- });
725
- }); // string literals
726
- describe('double literals', () => {
727
- it('respects \'#\' suffix', () => {
728
- let d = Lexer_1.Lexer.scan('123#').tokens[0];
729
- (0, chai_config_spec_1.expect)(d.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
730
- (0, chai_config_spec_1.expect)(d.text).to.eql('123#');
731
- });
732
- it('forces literals >= 10 digits into doubles', () => {
733
- let d = Lexer_1.Lexer.scan('0000000005').tokens[0];
734
- (0, chai_config_spec_1.expect)(d.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
735
- (0, chai_config_spec_1.expect)(d.text).to.eql('0000000005');
736
- });
737
- it('forces literals with \'D\' in exponent into doubles', () => {
738
- let d = Lexer_1.Lexer.scan('2.5d3').tokens[0];
739
- (0, chai_config_spec_1.expect)(d.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
740
- (0, chai_config_spec_1.expect)(d.text).to.eql('2.5d3');
741
- });
742
- it('allows digits before `.` to be elided', () => {
743
- let f = Lexer_1.Lexer.scan('.123#').tokens[0];
744
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
745
- (0, chai_config_spec_1.expect)(f.text).to.eql('.123#');
746
- });
747
- it('allows digits after `.` to be elided', () => {
748
- let f = Lexer_1.Lexer.scan('12.#').tokens[0];
749
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.DoubleLiteral);
750
- (0, chai_config_spec_1.expect)(f.text).to.eql('12.#');
751
- });
752
- });
753
- describe('float literals', () => {
754
- it('respects \'!\' suffix', () => {
755
- let f = Lexer_1.Lexer.scan('0.00000008!').tokens[0];
756
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
757
- // Floating precision will make this *not* equal
758
- (0, chai_config_spec_1.expect)(f.text).not.to.equal(8e-8);
759
- (0, chai_config_spec_1.expect)(f.text).to.eql('0.00000008!');
760
- });
761
- it('forces literals with a decimal into floats', () => {
762
- let f = Lexer_1.Lexer.scan('1.0').tokens[0];
763
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
764
- (0, chai_config_spec_1.expect)(f.text).to.equal('1.0');
765
- });
766
- it('forces literals with \'E\' in exponent into floats', () => {
767
- let f = Lexer_1.Lexer.scan('2.5e3').tokens[0];
768
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
769
- (0, chai_config_spec_1.expect)(f.text).to.eql('2.5e3');
770
- });
771
- it('supports very long numbers with !', () => {
772
- function doTest(number) {
773
- let f = Lexer_1.Lexer.scan(number).tokens[0];
774
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
775
- (0, chai_config_spec_1.expect)(f.text).to.eql(number);
776
- }
777
- doTest('0!');
778
- doTest('0!');
779
- doTest('147483648!');
780
- doTest('2147483648!');
781
- doTest('2147483648111!');
782
- doTest('2.4e-38!');
783
- doTest('2.4e-32342342342342342342342342348!');
784
- doTest('2.4e+32342342342342342342342342348!');
785
- });
786
- it('supports larger-than-supported-precision floats to be defined with exponents', () => {
787
- let f = Lexer_1.Lexer.scan('2.3659475627512424e-38').tokens[0];
788
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
789
- (0, chai_config_spec_1.expect)(f.text).to.eql('2.3659475627512424e-38');
790
- });
791
- it('allows digits before `.` to be elided', () => {
792
- let f = Lexer_1.Lexer.scan('.123').tokens[0];
793
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
794
- (0, chai_config_spec_1.expect)(f.text).to.equal('.123');
795
- });
796
- it('allows digits after `.` to be elided', () => {
797
- let f = Lexer_1.Lexer.scan('12.').tokens[0];
798
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
799
- (0, chai_config_spec_1.expect)(f.text).to.equal('12.');
800
- });
801
- });
802
- describe('long integer literals', () => {
803
- it('respects \'&\' suffix', () => {
804
- let f = Lexer_1.Lexer.scan('1&').tokens[0];
805
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.LongIntegerLiteral);
806
- (0, chai_config_spec_1.expect)(f.text).to.eql('1&');
807
- });
808
- it('supports hexadecimal literals', () => {
809
- let i = Lexer_1.Lexer.scan('&hf00d&').tokens[0];
810
- (0, chai_config_spec_1.expect)(i.kind).to.equal(TokenKind_1.TokenKind.LongIntegerLiteral);
811
- (0, chai_config_spec_1.expect)(i.text).to.equal('&hf00d&');
812
- });
813
- it('allows very long Int64 literals', () => {
814
- let li = Lexer_1.Lexer.scan('9876543210&').tokens[0];
815
- (0, chai_config_spec_1.expect)(li.kind).to.equal(TokenKind_1.TokenKind.LongIntegerLiteral);
816
- (0, chai_config_spec_1.expect)(li.text).to.equal('9876543210&');
817
- });
818
- it('forces literals with \'&\' suffix into Int64s', () => {
819
- let li = Lexer_1.Lexer.scan('123&').tokens[0];
820
- (0, chai_config_spec_1.expect)(li.kind).to.equal(TokenKind_1.TokenKind.LongIntegerLiteral);
821
- (0, chai_config_spec_1.expect)(li.text).to.deep.equal('123&');
822
- });
823
- });
824
- describe('integer literals', () => {
825
- it('respects \'%\' suffix', () => {
826
- let f = Lexer_1.Lexer.scan('1%').tokens[0];
827
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.IntegerLiteral);
828
- (0, chai_config_spec_1.expect)(f.text).to.eql('1%');
829
- });
830
- it('does not allow decimal numbers to end with %', () => {
831
- let f = Lexer_1.Lexer.scan('1.2%').tokens[0];
832
- (0, chai_config_spec_1.expect)(f.kind).to.equal(TokenKind_1.TokenKind.FloatLiteral);
833
- (0, chai_config_spec_1.expect)(f.text).to.eql('1.2');
834
- });
835
- it('supports hexadecimal literals', () => {
836
- let i = Lexer_1.Lexer.scan('&hFf').tokens[0];
837
- (0, chai_config_spec_1.expect)(i.kind).to.equal(TokenKind_1.TokenKind.IntegerLiteral);
838
- (0, chai_config_spec_1.expect)(i.text).to.deep.equal('&hFf');
839
- });
840
- it('falls back to a regular integer', () => {
841
- let i = Lexer_1.Lexer.scan('123').tokens[0];
842
- (0, chai_config_spec_1.expect)(i.kind).to.equal(TokenKind_1.TokenKind.IntegerLiteral);
843
- (0, chai_config_spec_1.expect)(i.text).to.deep.equal('123');
844
- });
845
- });
846
- describe('types', () => {
847
- it('captures type tokens', () => {
848
- (0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan(`
849
- void boolean integer longinteger float double string object interface invalid dynamic
850
- `.trim()).tokens.map(x => x.kind)).to.eql([
851
- TokenKind_1.TokenKind.Void,
852
- TokenKind_1.TokenKind.Boolean,
853
- TokenKind_1.TokenKind.Integer,
854
- TokenKind_1.TokenKind.LongInteger,
855
- TokenKind_1.TokenKind.Float,
856
- TokenKind_1.TokenKind.Double,
857
- TokenKind_1.TokenKind.String,
858
- TokenKind_1.TokenKind.Object,
859
- TokenKind_1.TokenKind.Interface,
860
- TokenKind_1.TokenKind.Invalid,
861
- TokenKind_1.TokenKind.Dynamic,
862
- TokenKind_1.TokenKind.Eof
863
- ]);
864
- });
865
- });
866
- describe('identifiers', () => {
867
- it('matches single-word keywords', () => {
868
- // test just a sample of single-word reserved words for now.
869
- // if we find any that we've missed
870
- let { tokens } = Lexer_1.Lexer.scan('and then or if else endif return true false line_num');
871
- (0, chai_config_spec_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
872
- TokenKind_1.TokenKind.And,
873
- TokenKind_1.TokenKind.Then,
874
- TokenKind_1.TokenKind.Or,
875
- TokenKind_1.TokenKind.If,
876
- TokenKind_1.TokenKind.Else,
877
- TokenKind_1.TokenKind.EndIf,
878
- TokenKind_1.TokenKind.Return,
879
- TokenKind_1.TokenKind.True,
880
- TokenKind_1.TokenKind.False,
881
- TokenKind_1.TokenKind.LineNumLiteral,
882
- TokenKind_1.TokenKind.Eof
883
- ]);
884
- });
885
- it('matches multi-word keywords', () => {
886
- let { tokens } = Lexer_1.Lexer.scan('end if end while End Sub end Function Exit wHILe');
887
- (0, chai_config_spec_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
888
- TokenKind_1.TokenKind.EndIf,
889
- TokenKind_1.TokenKind.EndWhile,
890
- TokenKind_1.TokenKind.EndSub,
891
- TokenKind_1.TokenKind.EndFunction,
892
- TokenKind_1.TokenKind.ExitWhile,
893
- TokenKind_1.TokenKind.Eof
894
- ]);
895
- });
896
- it('accepts \'exit for\' but not \'exitfor\'', () => {
897
- let { tokens } = Lexer_1.Lexer.scan('exit for exitfor');
898
- (0, chai_config_spec_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
899
- TokenKind_1.TokenKind.ExitFor,
900
- TokenKind_1.TokenKind.Identifier,
901
- TokenKind_1.TokenKind.Eof
902
- ]);
903
- });
904
- it('matches keywords with silly capitalization', () => {
905
- let { tokens } = Lexer_1.Lexer.scan('iF ELSE eNDIf FUncTioN');
906
- (0, chai_config_spec_1.expect)(tokens.map(w => w.kind)).to.deep.equal([
907
- TokenKind_1.TokenKind.If,
908
- TokenKind_1.TokenKind.Else,
909
- TokenKind_1.TokenKind.EndIf,
910
- TokenKind_1.TokenKind.Function,
911
- TokenKind_1.TokenKind.Eof
912
- ]);
913
- });
914
- it('allows alpha-numeric (plus \'_\') identifiers', () => {
915
- let identifier = Lexer_1.Lexer.scan('_abc_123_').tokens[0];
916
- (0, chai_config_spec_1.expect)(identifier.kind).to.equal(TokenKind_1.TokenKind.Identifier);
917
- (0, chai_config_spec_1.expect)(identifier.text).to.equal('_abc_123_');
918
- });
919
- it('allows identifiers with trailing type designators', () => {
920
- let { tokens } = Lexer_1.Lexer.scan('lorem$ ipsum% dolor! sit# amet&');
921
- let identifiers = tokens.filter(t => t.kind !== TokenKind_1.TokenKind.Eof);
922
- (0, chai_config_spec_1.expect)(identifiers.every(t => t.kind === TokenKind_1.TokenKind.Identifier));
923
- (0, chai_config_spec_1.expect)(identifiers.map(t => t.text)).to.deep.equal([
924
- 'lorem$',
925
- 'ipsum%',
926
- 'dolor!',
927
- 'sit#',
928
- 'amet&'
929
- ]);
930
- });
931
- });
932
- describe('conditional compilation', () => {
933
- it('reads constant declarations', () => {
934
- let { tokens } = Lexer_1.Lexer.scan('#const foo true');
935
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
936
- TokenKind_1.TokenKind.HashConst,
937
- TokenKind_1.TokenKind.Identifier,
938
- TokenKind_1.TokenKind.True,
939
- TokenKind_1.TokenKind.Eof
940
- ]);
941
- });
942
- it('handles whitespace between hash and keywords', () => {
943
- function doTest(text, ...expected) {
944
- let { tokens } = Lexer_1.Lexer.scan(text);
945
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
946
- ...expected,
947
- TokenKind_1.TokenKind.Eof
948
- ]);
949
- }
950
- //#if
951
- doTest('# if true', TokenKind_1.TokenKind.HashIf, TokenKind_1.TokenKind.True);
952
- doTest('#\tif true', TokenKind_1.TokenKind.HashIf, TokenKind_1.TokenKind.True);
953
- doTest('#\t \t\t \tif true', TokenKind_1.TokenKind.HashIf, TokenKind_1.TokenKind.True);
954
- //#else
955
- doTest('# else', TokenKind_1.TokenKind.HashElse);
956
- doTest('#\telse', TokenKind_1.TokenKind.HashElse);
957
- doTest('#\t \t\t \telse', TokenKind_1.TokenKind.HashElse);
958
- //#elseif
959
- doTest('# elseif true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
960
- doTest('#\telseif true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
961
- doTest('#\t \t\t \telseif true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
962
- //#else if
963
- doTest('# else if true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
964
- doTest('#\t elseif true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
965
- doTest('#\t \t\t \t else if true', TokenKind_1.TokenKind.HashElseIf, TokenKind_1.TokenKind.True);
966
- //#endif
967
- doTest('# endif', TokenKind_1.TokenKind.HashEndIf);
968
- doTest('#\tendif', TokenKind_1.TokenKind.HashEndIf);
969
- doTest('#\t \t\t \tendif', TokenKind_1.TokenKind.HashEndIf);
970
- //#end if
971
- doTest('# end if', TokenKind_1.TokenKind.HashEndIf);
972
- doTest('#\tend if', TokenKind_1.TokenKind.HashEndIf);
973
- doTest('#\t \t\t \tend if', TokenKind_1.TokenKind.HashEndIf);
974
- //#const
975
- doTest('# const thing=true', TokenKind_1.TokenKind.HashConst, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.True);
976
- doTest('#\tconst thing=true', TokenKind_1.TokenKind.HashConst, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.True);
977
- doTest('#\t \t\t \tconst thing=true', TokenKind_1.TokenKind.HashConst, TokenKind_1.TokenKind.Identifier, TokenKind_1.TokenKind.Equal, TokenKind_1.TokenKind.True);
978
- //#error
979
- doTest('# error', TokenKind_1.TokenKind.HashError);
980
- doTest('#\terror', TokenKind_1.TokenKind.HashError);
981
- doTest('#\t \t\t \terror', TokenKind_1.TokenKind.HashError);
982
- });
983
- it('reads constant aliases', () => {
984
- let { tokens } = Lexer_1.Lexer.scan('#const bar foo');
985
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
986
- TokenKind_1.TokenKind.HashConst,
987
- TokenKind_1.TokenKind.Identifier,
988
- TokenKind_1.TokenKind.Identifier,
989
- TokenKind_1.TokenKind.Eof
990
- ]);
991
- });
992
- it('reads conditional directives', () => {
993
- let { tokens } = Lexer_1.Lexer.scan(`
994
- #if
995
- #else if
996
- #elseif
997
- #else
998
- #end if
999
- #endif
1000
- `, {
1001
- includeWhitespace: false
1002
- });
1003
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind).filter(x => x !== TokenKind_1.TokenKind.Newline)).to.deep.equal([
1004
- TokenKind_1.TokenKind.HashIf,
1005
- TokenKind_1.TokenKind.HashElseIf,
1006
- TokenKind_1.TokenKind.HashElseIf,
1007
- TokenKind_1.TokenKind.HashElse,
1008
- TokenKind_1.TokenKind.HashEndIf,
1009
- TokenKind_1.TokenKind.HashEndIf,
1010
- TokenKind_1.TokenKind.Eof
1011
- ]);
1012
- });
1013
- it('treats text "constructor" as an identifier', () => {
1014
- let lexer = Lexer_1.Lexer.scan(`function constructor()\nend function`);
1015
- (0, chai_config_spec_1.expect)(lexer.tokens[1].kind).to.equal(TokenKind_1.TokenKind.Identifier);
1016
- });
1017
- it('reads upper case conditional directives', () => {
1018
- let { tokens } = Lexer_1.Lexer.scan(`
1019
- #IF
1020
- #ELSE IF
1021
- #ELSEIF
1022
- #ELSE
1023
- #END IF
1024
- #ENDIF
1025
- `, {
1026
- includeWhitespace: false
1027
- });
1028
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind).filter(x => x !== TokenKind_1.TokenKind.Newline)).to.deep.equal([
1029
- TokenKind_1.TokenKind.HashIf,
1030
- TokenKind_1.TokenKind.HashElseIf,
1031
- TokenKind_1.TokenKind.HashElseIf,
1032
- TokenKind_1.TokenKind.HashElse,
1033
- TokenKind_1.TokenKind.HashEndIf,
1034
- TokenKind_1.TokenKind.HashEndIf,
1035
- TokenKind_1.TokenKind.Eof
1036
- ]);
1037
- });
1038
- it('supports various spacings between #endif', () => {
1039
- let { tokens } = Lexer_1.Lexer.scan('#endif #end if #end\tif #end if #end\t\t if');
1040
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
1041
- TokenKind_1.TokenKind.HashEndIf,
1042
- TokenKind_1.TokenKind.HashEndIf,
1043
- TokenKind_1.TokenKind.HashEndIf,
1044
- TokenKind_1.TokenKind.HashEndIf,
1045
- TokenKind_1.TokenKind.HashEndIf,
1046
- TokenKind_1.TokenKind.Eof
1047
- ]);
1048
- });
1049
- it('does not require a message after #error', () => {
1050
- let { tokens } = Lexer_1.Lexer.scan('#error');
1051
- (0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
1052
- TokenKind_1.TokenKind.HashError,
1053
- TokenKind_1.TokenKind.Eof
1054
- ]);
1055
- });
1056
- it('reads forced compilation diagnostics with messages', () => {
1057
- let { tokens } = Lexer_1.Lexer.scan('#error a message goes here\n', {
1058
- includeWhitespace: true
1059
- });
1060
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
1061
- TokenKind_1.TokenKind.HashError,
1062
- TokenKind_1.TokenKind.Whitespace,
1063
- TokenKind_1.TokenKind.HashErrorMessage,
1064
- TokenKind_1.TokenKind.Newline,
1065
- TokenKind_1.TokenKind.Eof
1066
- ]);
1067
- (0, chai_config_spec_1.expect)(tokens[2].text).to.equal('a message goes here');
1068
- });
1069
- });
1070
- describe('location tracking', () => {
1071
- it('tracks starting and ending locations including whitespace', () => {
1072
- let { tokens } = Lexer_1.Lexer.scan(`sub foo()\n print "bar"\r\nend sub`, { includeWhitespace: true });
1073
- (0, chai_config_spec_1.expect)(tokens.map(t => t.range)).to.eql([
1074
- vscode_languageserver_1.Range.create(0, 0, 0, 3),
1075
- vscode_languageserver_1.Range.create(0, 3, 0, 4),
1076
- vscode_languageserver_1.Range.create(0, 4, 0, 7),
1077
- vscode_languageserver_1.Range.create(0, 7, 0, 8),
1078
- vscode_languageserver_1.Range.create(0, 8, 0, 9),
1079
- vscode_languageserver_1.Range.create(0, 9, 0, 10),
1080
- vscode_languageserver_1.Range.create(1, 0, 1, 4),
1081
- vscode_languageserver_1.Range.create(1, 4, 1, 9),
1082
- vscode_languageserver_1.Range.create(1, 9, 1, 10),
1083
- vscode_languageserver_1.Range.create(1, 10, 1, 15),
1084
- vscode_languageserver_1.Range.create(1, 15, 1, 17),
1085
- vscode_languageserver_1.Range.create(2, 0, 2, 7),
1086
- vscode_languageserver_1.Range.create(2, 7, 2, 8) // EOF
1087
- ]);
1088
- });
1089
- it('tracks starting and ending locations excluding whitespace', () => {
1090
- let { tokens } = Lexer_1.Lexer.scan(`sub foo()\n print "bar"\r\nend sub`, { includeWhitespace: false });
1091
- (0, chai_config_spec_1.expect)(tokens.map(t => t.range)).to.eql([
1092
- vscode_languageserver_1.Range.create(0, 0, 0, 3),
1093
- vscode_languageserver_1.Range.create(0, 4, 0, 7),
1094
- vscode_languageserver_1.Range.create(0, 7, 0, 8),
1095
- vscode_languageserver_1.Range.create(0, 8, 0, 9),
1096
- vscode_languageserver_1.Range.create(0, 9, 0, 10),
1097
- vscode_languageserver_1.Range.create(1, 4, 1, 9),
1098
- vscode_languageserver_1.Range.create(1, 10, 1, 15),
1099
- vscode_languageserver_1.Range.create(1, 15, 1, 17),
1100
- vscode_languageserver_1.Range.create(2, 0, 2, 7),
1101
- vscode_languageserver_1.Range.create(2, 7, 2, 8) // EOF
1102
- ]);
1103
- });
1104
- });
1105
- describe('two word keywords', () => {
1106
- it('supports various spacing between for each', () => {
1107
- let { tokens } = Lexer_1.Lexer.scan('for each for each for each for\teach for\t each for \teach for \t each');
1108
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.deep.equal([
1109
- TokenKind_1.TokenKind.ForEach,
1110
- TokenKind_1.TokenKind.ForEach,
1111
- TokenKind_1.TokenKind.ForEach,
1112
- TokenKind_1.TokenKind.ForEach,
1113
- TokenKind_1.TokenKind.ForEach,
1114
- TokenKind_1.TokenKind.ForEach,
1115
- TokenKind_1.TokenKind.ForEach,
1116
- TokenKind_1.TokenKind.Eof
1117
- ]);
1118
- });
1119
- });
1120
- it('detects rem when used as keyword', () => {
1121
- let { tokens } = Lexer_1.Lexer.scan('person.rem=true');
1122
- (0, chai_config_spec_1.expect)(tokens.map(t => t.kind)).to.eql([
1123
- TokenKind_1.TokenKind.Identifier,
1124
- TokenKind_1.TokenKind.Dot,
1125
- TokenKind_1.TokenKind.Identifier,
1126
- TokenKind_1.TokenKind.Equal,
1127
- TokenKind_1.TokenKind.True,
1128
- TokenKind_1.TokenKind.Eof
1129
- ]);
1130
- //verify the location of `rem`
1131
- (0, chai_config_spec_1.expect)(tokens.map(t => [t.range.start.character, t.range.end.character])).to.eql([
1132
- [0, 6],
1133
- [6, 7],
1134
- [7, 10],
1135
- [10, 11],
1136
- [11, 15],
1137
- [15, 16] // EOF
1138
- ]);
1139
- });
1140
- describe('isToken', () => {
1141
- it('works', () => {
1142
- let range = vscode_languageserver_1.Range.create(0, 0, 0, 2);
1143
- (0, chai_config_spec_1.expect)((0, Token_1.isToken)({ kind: TokenKind_1.TokenKind.And, text: 'and', range: range })).is.true;
1144
- (0, chai_config_spec_1.expect)((0, Token_1.isToken)({ text: 'and', range: range })).is.false;
1145
- });
1146
- });
1147
- it('recognizes enum-related keywords', () => {
1148
- (0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan('enum end enum endenum').tokens.map(x => x.kind)).to.eql([
1149
- TokenKind_1.TokenKind.Enum,
1150
- TokenKind_1.TokenKind.EndEnum,
1151
- TokenKind_1.TokenKind.EndEnum,
1152
- TokenKind_1.TokenKind.Eof
1153
- ]);
1154
- });
1155
- it('recognizes class-related keywords', () => {
1156
- (0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan('class public protected private end class endclass new override').tokens.map(x => x.kind)).to.eql([
1157
- TokenKind_1.TokenKind.Class,
1158
- TokenKind_1.TokenKind.Public,
1159
- TokenKind_1.TokenKind.Protected,
1160
- TokenKind_1.TokenKind.Private,
1161
- TokenKind_1.TokenKind.EndClass,
1162
- TokenKind_1.TokenKind.EndClass,
1163
- TokenKind_1.TokenKind.New,
1164
- TokenKind_1.TokenKind.Override,
1165
- TokenKind_1.TokenKind.Eof
1166
- ]);
1167
- });
1168
- describe('whitespace', () => {
1169
- it('preserves the exact number of whitespace characterswhitespace', () => {
1170
- let { tokens } = Lexer_1.Lexer.scan(' ', { includeWhitespace: true });
1171
- (0, chai_config_spec_1.expect)(tokens[0]).to.include({
1172
- kind: TokenKind_1.TokenKind.Whitespace,
1173
- text: ' '
1174
- });
1175
- });
1176
- it('tokenizes whitespace between things', () => {
1177
- let { tokens } = Lexer_1.Lexer.scan('sub main ( ) \n end sub', { includeWhitespace: true });
1178
- (0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
1179
- TokenKind_1.TokenKind.Sub,
1180
- TokenKind_1.TokenKind.Whitespace,
1181
- TokenKind_1.TokenKind.Identifier,
1182
- TokenKind_1.TokenKind.Whitespace,
1183
- TokenKind_1.TokenKind.LeftParen,
1184
- TokenKind_1.TokenKind.Whitespace,
1185
- TokenKind_1.TokenKind.RightParen,
1186
- TokenKind_1.TokenKind.Whitespace,
1187
- TokenKind_1.TokenKind.Newline,
1188
- TokenKind_1.TokenKind.Whitespace,
1189
- TokenKind_1.TokenKind.EndSub,
1190
- TokenKind_1.TokenKind.Eof
1191
- ]);
1192
- });
1193
- });
1194
- it('identifies brighterscript source literals', () => {
1195
- let { tokens } = Lexer_1.Lexer.scan('LINE_NUM SOURCE_FILE_PATH SOURCE_LINE_NUM FUNCTION_NAME SOURCE_FUNCTION_NAME SOURCE_NAMESPACE_NAME SOURCE_NAMESPACE_ROOT_NAME SOURCE_LOCATION PKG_PATH PKG_LOCATION');
1196
- (0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
1197
- TokenKind_1.TokenKind.LineNumLiteral,
1198
- TokenKind_1.TokenKind.SourceFilePathLiteral,
1199
- TokenKind_1.TokenKind.SourceLineNumLiteral,
1200
- TokenKind_1.TokenKind.FunctionNameLiteral,
1201
- TokenKind_1.TokenKind.SourceFunctionNameLiteral,
1202
- TokenKind_1.TokenKind.SourceNamespaceNameLiteral,
1203
- TokenKind_1.TokenKind.SourceNamespaceRootNameLiteral,
1204
- TokenKind_1.TokenKind.SourceLocationLiteral,
1205
- TokenKind_1.TokenKind.PkgPathLiteral,
1206
- TokenKind_1.TokenKind.PkgLocationLiteral,
1207
- TokenKind_1.TokenKind.Eof
1208
- ]);
1209
- });
1210
- it('properly tracks leadingWhitespace', () => {
1211
- const text = `
1212
- sub main()
1213
-
1214
- print "main"\r\n\n
1215
-
1216
- end sub
1217
- `;
1218
- const { tokens } = Lexer_1.Lexer.scan(text, { includeWhitespace: false });
1219
- (0, chai_config_spec_1.expect)(util_1.default.tokensToString(tokens)).to.equal(text);
1220
- });
1221
- it('properly detects try/catch tokens', () => {
1222
- const { tokens } = Lexer_1.Lexer.scan(`try catch endtry end try throw`, { includeWhitespace: false });
1223
- (0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
1224
- TokenKind_1.TokenKind.Try,
1225
- TokenKind_1.TokenKind.Catch,
1226
- TokenKind_1.TokenKind.EndTry,
1227
- TokenKind_1.TokenKind.EndTry,
1228
- TokenKind_1.TokenKind.Throw,
1229
- TokenKind_1.TokenKind.Eof
1230
- ]);
1231
- });
1232
- describe('regular expression literals', () => {
1233
- function testRegex(...regexps) {
1234
- regexps = regexps.map(x => x.toString());
1235
- const results = [];
1236
- for (const regexp of regexps) {
1237
- const { tokens } = Lexer_1.Lexer.scan(regexp);
1238
- results.push(tokens[0].text);
1239
- }
1240
- (0, chai_config_spec_1.expect)(results).to.eql(regexps);
1241
- }
1242
- it('recognizes regex literals', () => {
1243
- testRegex(/simple/, /SimpleWithValidFlags/g, /UnknownFlags/gi, /with spaces/s, /with(parens)and[squarebraces]/,
1244
- //lots of special characters
1245
- /.*()^$@/,
1246
- //captures quote char
1247
- /"/);
1248
- });
1249
- it('does not capture multiple divisions on one line as regex', () => {
1250
- const { tokens } = Lexer_1.Lexer.scan(`one = 1/2 + 1/4 + 1/4`, {
1251
- includeWhitespace: false
1252
- });
1253
- (0, chai_config_spec_1.expect)(tokens.map(x => x.kind)).to.eql([
1254
- TokenKind_1.TokenKind.Identifier,
1255
- TokenKind_1.TokenKind.Equal,
1256
- TokenKind_1.TokenKind.IntegerLiteral,
1257
- TokenKind_1.TokenKind.Forwardslash,
1258
- TokenKind_1.TokenKind.IntegerLiteral,
1259
- TokenKind_1.TokenKind.Plus,
1260
- TokenKind_1.TokenKind.IntegerLiteral,
1261
- TokenKind_1.TokenKind.Forwardslash,
1262
- TokenKind_1.TokenKind.IntegerLiteral,
1263
- TokenKind_1.TokenKind.Plus,
1264
- TokenKind_1.TokenKind.IntegerLiteral,
1265
- TokenKind_1.TokenKind.Forwardslash,
1266
- TokenKind_1.TokenKind.IntegerLiteral,
1267
- TokenKind_1.TokenKind.Eof
1268
- ]);
1269
- });
1270
- it('only captures alphanumeric flags', () => {
1271
- (0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan('speak(/a/)').tokens.map(x => x.kind)).to.eql([
1272
- TokenKind_1.TokenKind.Identifier,
1273
- TokenKind_1.TokenKind.LeftParen,
1274
- TokenKind_1.TokenKind.RegexLiteral,
1275
- TokenKind_1.TokenKind.RightParen,
1276
- TokenKind_1.TokenKind.Eof
1277
- ]);
1278
- });
1279
- it('handles escape characters properly', () => {
1280
- testRegex(
1281
- //an escaped forward slash right next to the end-regexp forwardslash
1282
- /\//, /\r/, /\n/, /\r\n/,
1283
- //a literal backslash in front of an escape backslash
1284
- /\\\n/);
1285
- });
1286
- });
1287
- it('detects "continue" as a keyword', () => {
1288
- (0, chai_config_spec_1.expect)(Lexer_1.Lexer.scan('continue').tokens.map(x => x.kind)).to.eql([
1289
- TokenKind_1.TokenKind.Continue,
1290
- TokenKind_1.TokenKind.Eof
1291
- ]);
1292
- });
1293
- });
1294
- function expectKinds(text, tokenKinds) {
1295
- let actual = Lexer_1.Lexer.scan(text).tokens.map(x => x.kind);
1296
- //remove the EOF token
1297
- actual.pop();
1298
- (0, chai_config_spec_1.expect)(actual).to.eql(tokenKinds);
1299
- }
1300
- //# sourceMappingURL=Lexer.spec.js.map