javascript.test.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { testTokenization } from '../test/testRunner';
  6. testTokenization('javascript', [
  7. // Keywords
  8. [
  9. {
  10. line: 'var x = function() { };',
  11. tokens: [
  12. { startIndex: 0, type: 'keyword.js' },
  13. { startIndex: 3, type: '' },
  14. { startIndex: 4, type: 'identifier.js' },
  15. { startIndex: 5, type: '' },
  16. { startIndex: 6, type: 'delimiter.js' },
  17. { startIndex: 7, type: '' },
  18. { startIndex: 8, type: 'keyword.js' },
  19. { startIndex: 16, type: 'delimiter.parenthesis.js' },
  20. { startIndex: 18, type: '' },
  21. { startIndex: 19, type: 'delimiter.bracket.js' },
  22. { startIndex: 20, type: '' },
  23. { startIndex: 21, type: 'delimiter.bracket.js' },
  24. { startIndex: 22, type: 'delimiter.js' }
  25. ]
  26. }
  27. ],
  28. [
  29. {
  30. line: ' var ',
  31. tokens: [
  32. { startIndex: 0, type: '' },
  33. { startIndex: 4, type: 'keyword.js' },
  34. { startIndex: 7, type: '' }
  35. ]
  36. }
  37. ],
  38. // identifiers
  39. [
  40. {
  41. line: 'foo;',
  42. tokens: [
  43. { startIndex: 0, type: 'identifier.js' },
  44. { startIndex: 3, type: 'delimiter.js' }
  45. ]
  46. }
  47. ],
  48. [
  49. {
  50. line: 'foo() { return 1; }',
  51. tokens: [
  52. { startIndex: 0, type: 'identifier.js' },
  53. { startIndex: 3, type: 'delimiter.parenthesis.js' },
  54. { startIndex: 5, type: '' },
  55. { startIndex: 6, type: 'delimiter.bracket.js' },
  56. { startIndex: 7, type: '' },
  57. { startIndex: 8, type: 'keyword.js' },
  58. { startIndex: 14, type: '' },
  59. { startIndex: 15, type: 'number.js' },
  60. { startIndex: 16, type: 'delimiter.js' },
  61. { startIndex: 17, type: '' },
  62. { startIndex: 18, type: 'delimiter.bracket.js' }
  63. ]
  64. }
  65. ],
  66. [
  67. {
  68. line: '#foo;',
  69. tokens: [
  70. { startIndex: 0, type: 'identifier.js' },
  71. { startIndex: 4, type: 'delimiter.js' }
  72. ]
  73. }
  74. ],
  75. [
  76. {
  77. line: '#foo() { return 1; }',
  78. tokens: [
  79. { startIndex: 0, type: 'identifier.js' },
  80. { startIndex: 4, type: 'delimiter.parenthesis.js' },
  81. { startIndex: 6, type: '' },
  82. { startIndex: 7, type: 'delimiter.bracket.js' },
  83. { startIndex: 8, type: '' },
  84. { startIndex: 9, type: 'keyword.js' },
  85. { startIndex: 15, type: '' },
  86. { startIndex: 16, type: 'number.js' },
  87. { startIndex: 17, type: 'delimiter.js' },
  88. { startIndex: 18, type: '' },
  89. { startIndex: 19, type: 'delimiter.bracket.js' }
  90. ]
  91. }
  92. ],
  93. // Comments - single line
  94. [
  95. {
  96. line: '//',
  97. tokens: [{ startIndex: 0, type: 'comment.js' }]
  98. }
  99. ],
  100. [
  101. {
  102. line: ' // a comment',
  103. tokens: [
  104. { startIndex: 0, type: '' },
  105. { startIndex: 4, type: 'comment.js' }
  106. ]
  107. }
  108. ],
  109. [
  110. {
  111. line: '// a comment',
  112. tokens: [{ startIndex: 0, type: 'comment.js' }]
  113. }
  114. ],
  115. [
  116. {
  117. line: '// a comment /*',
  118. tokens: [{ startIndex: 0, type: 'comment.js' }]
  119. }
  120. ],
  121. [
  122. {
  123. line: '// a comment /**',
  124. tokens: [{ startIndex: 0, type: 'comment.js' }]
  125. }
  126. ],
  127. [
  128. {
  129. line: '//sticky comment',
  130. tokens: [{ startIndex: 0, type: 'comment.js' }]
  131. }
  132. ],
  133. [
  134. {
  135. line: 'var x = 1; // my comment // is a nice one',
  136. tokens: [
  137. { startIndex: 0, type: 'keyword.js' },
  138. { startIndex: 3, type: '' },
  139. { startIndex: 4, type: 'identifier.js' },
  140. { startIndex: 5, type: '' },
  141. { startIndex: 6, type: 'delimiter.js' },
  142. { startIndex: 7, type: '' },
  143. { startIndex: 8, type: 'number.js' },
  144. { startIndex: 9, type: 'delimiter.js' },
  145. { startIndex: 10, type: '' },
  146. { startIndex: 11, type: 'comment.js' }
  147. ]
  148. }
  149. ],
  150. // Comments - range comment, single line
  151. [
  152. {
  153. line: '/* a simple comment */',
  154. tokens: [{ startIndex: 0, type: 'comment.js' }]
  155. }
  156. ],
  157. [
  158. {
  159. line: 'var x = /* a simple comment */ 1;',
  160. tokens: [
  161. { startIndex: 0, type: 'keyword.js' },
  162. { startIndex: 3, type: '' },
  163. { startIndex: 4, type: 'identifier.js' },
  164. { startIndex: 5, type: '' },
  165. { startIndex: 6, type: 'delimiter.js' },
  166. { startIndex: 7, type: '' },
  167. { startIndex: 8, type: 'comment.js' },
  168. { startIndex: 30, type: '' },
  169. { startIndex: 31, type: 'number.js' },
  170. { startIndex: 32, type: 'delimiter.js' }
  171. ]
  172. }
  173. ],
  174. [
  175. {
  176. line: 'x = /**/;',
  177. tokens: [
  178. { startIndex: 0, type: 'identifier.js' },
  179. { startIndex: 1, type: '' },
  180. { startIndex: 2, type: 'delimiter.js' },
  181. { startIndex: 3, type: '' },
  182. { startIndex: 4, type: 'comment.js' },
  183. { startIndex: 8, type: 'delimiter.js' }
  184. ]
  185. }
  186. ],
  187. [
  188. {
  189. line: 'x = /*/;',
  190. tokens: [
  191. { startIndex: 0, type: 'identifier.js' },
  192. { startIndex: 1, type: '' },
  193. { startIndex: 2, type: 'delimiter.js' },
  194. { startIndex: 3, type: '' },
  195. { startIndex: 4, type: 'comment.js' }
  196. ]
  197. }
  198. ],
  199. // Comments - range comment, multi lines
  200. [
  201. {
  202. line: '/* a multiline comment',
  203. tokens: [{ startIndex: 0, type: 'comment.js' }]
  204. },
  205. {
  206. line: 'can actually span',
  207. tokens: [{ startIndex: 0, type: 'comment.js' }]
  208. },
  209. {
  210. line: 'multiple lines */',
  211. tokens: [{ startIndex: 0, type: 'comment.js' }]
  212. }
  213. ],
  214. [
  215. {
  216. line: 'var x = /* start a comment',
  217. tokens: [
  218. { startIndex: 0, type: 'keyword.js' },
  219. { startIndex: 3, type: '' },
  220. { startIndex: 4, type: 'identifier.js' },
  221. { startIndex: 5, type: '' },
  222. { startIndex: 6, type: 'delimiter.js' },
  223. { startIndex: 7, type: '' },
  224. { startIndex: 8, type: 'comment.js' }
  225. ]
  226. },
  227. {
  228. line: ' a ',
  229. tokens: [{ startIndex: 0, type: 'comment.js' }]
  230. },
  231. {
  232. line: 'and end it */ var a = 2;',
  233. tokens: [
  234. { startIndex: 0, type: 'comment.js' },
  235. { startIndex: 13, type: '' },
  236. { startIndex: 14, type: 'keyword.js' },
  237. { startIndex: 17, type: '' },
  238. { startIndex: 18, type: 'identifier.js' },
  239. { startIndex: 19, type: '' },
  240. { startIndex: 20, type: 'delimiter.js' },
  241. { startIndex: 21, type: '' },
  242. { startIndex: 22, type: 'number.js' },
  243. { startIndex: 23, type: 'delimiter.js' }
  244. ]
  245. }
  246. ],
  247. // Strings
  248. [
  249. {
  250. line: "var a = 'a';",
  251. tokens: [
  252. { startIndex: 0, type: 'keyword.js' },
  253. { startIndex: 3, type: '' },
  254. { startIndex: 4, type: 'identifier.js' },
  255. { startIndex: 5, type: '' },
  256. { startIndex: 6, type: 'delimiter.js' },
  257. { startIndex: 7, type: '' },
  258. { startIndex: 8, type: 'string.js' },
  259. { startIndex: 11, type: 'delimiter.js' }
  260. ]
  261. }
  262. ],
  263. [
  264. {
  265. line: '"use strict";',
  266. tokens: [
  267. { startIndex: 0, type: 'string.js' },
  268. { startIndex: 12, type: 'delimiter.js' }
  269. ]
  270. }
  271. ],
  272. [
  273. {
  274. line: 'b = a + " \'cool\' "',
  275. tokens: [
  276. { startIndex: 0, type: 'identifier.js' },
  277. { startIndex: 1, type: '' },
  278. { startIndex: 2, type: 'delimiter.js' },
  279. { startIndex: 3, type: '' },
  280. { startIndex: 4, type: 'identifier.js' },
  281. { startIndex: 5, type: '' },
  282. { startIndex: 6, type: 'delimiter.js' },
  283. { startIndex: 7, type: '' },
  284. { startIndex: 8, type: 'string.js' }
  285. ]
  286. }
  287. ],
  288. [
  289. {
  290. line: '"escaping \\"quotes\\" is cool"',
  291. tokens: [
  292. { startIndex: 0, type: 'string.js' },
  293. { startIndex: 10, type: 'string.escape.js' },
  294. { startIndex: 12, type: 'string.js' },
  295. { startIndex: 18, type: 'string.escape.js' },
  296. { startIndex: 20, type: 'string.js' }
  297. ]
  298. }
  299. ],
  300. [
  301. {
  302. line: "'''",
  303. tokens: [
  304. { startIndex: 0, type: 'string.js' },
  305. { startIndex: 2, type: 'string.invalid.js' }
  306. ]
  307. }
  308. ],
  309. [
  310. {
  311. line: "'\\''",
  312. tokens: [
  313. { startIndex: 0, type: 'string.js' },
  314. { startIndex: 1, type: 'string.escape.js' },
  315. { startIndex: 3, type: 'string.js' }
  316. ]
  317. }
  318. ],
  319. [
  320. {
  321. line: "'be careful \\not to escape'",
  322. tokens: [
  323. { startIndex: 0, type: 'string.js' },
  324. { startIndex: 12, type: 'string.escape.js' },
  325. { startIndex: 14, type: 'string.js' }
  326. ]
  327. }
  328. ],
  329. // Numbers
  330. [
  331. {
  332. line: '0',
  333. tokens: [{ startIndex: 0, type: 'number.js' }]
  334. }
  335. ],
  336. [
  337. {
  338. line: ' 0',
  339. tokens: [
  340. { startIndex: 0, type: '' },
  341. { startIndex: 1, type: 'number.js' }
  342. ]
  343. }
  344. ],
  345. [
  346. {
  347. line: ' 0 ',
  348. tokens: [
  349. { startIndex: 0, type: '' },
  350. { startIndex: 1, type: 'number.js' },
  351. { startIndex: 2, type: '' }
  352. ]
  353. }
  354. ],
  355. [
  356. {
  357. line: '0 ',
  358. tokens: [
  359. { startIndex: 0, type: 'number.js' },
  360. { startIndex: 1, type: '' }
  361. ]
  362. }
  363. ],
  364. [
  365. {
  366. line: '0+0',
  367. tokens: [
  368. { startIndex: 0, type: 'number.js' },
  369. { startIndex: 1, type: 'delimiter.js' },
  370. { startIndex: 2, type: 'number.js' }
  371. ]
  372. }
  373. ],
  374. [
  375. {
  376. line: '100+10',
  377. tokens: [
  378. { startIndex: 0, type: 'number.js' },
  379. { startIndex: 3, type: 'delimiter.js' },
  380. { startIndex: 4, type: 'number.js' }
  381. ]
  382. }
  383. ],
  384. [
  385. {
  386. line: '0 + 0',
  387. tokens: [
  388. { startIndex: 0, type: 'number.js' },
  389. { startIndex: 1, type: '' },
  390. { startIndex: 2, type: 'delimiter.js' },
  391. { startIndex: 3, type: '' },
  392. { startIndex: 4, type: 'number.js' }
  393. ]
  394. }
  395. ],
  396. [
  397. {
  398. line: '0123',
  399. tokens: [{ startIndex: 0, type: 'number.octal.js' }]
  400. }
  401. ],
  402. [
  403. {
  404. line: '01239',
  405. tokens: [
  406. { startIndex: 0, type: 'number.octal.js' },
  407. { startIndex: 4, type: 'number.js' }
  408. ]
  409. }
  410. ],
  411. [
  412. {
  413. line: '0o123',
  414. tokens: [{ startIndex: 0, type: 'number.octal.js' }]
  415. }
  416. ],
  417. [
  418. {
  419. line: '0O123',
  420. tokens: [{ startIndex: 0, type: 'number.octal.js' }]
  421. }
  422. ],
  423. [
  424. {
  425. line: '0x',
  426. tokens: [
  427. { startIndex: 0, type: 'number.js' },
  428. { startIndex: 1, type: 'identifier.js' }
  429. ]
  430. }
  431. ],
  432. [
  433. {
  434. line: '0x123',
  435. tokens: [{ startIndex: 0, type: 'number.hex.js' }]
  436. }
  437. ],
  438. [
  439. {
  440. line: '0X123',
  441. tokens: [{ startIndex: 0, type: 'number.hex.js' }]
  442. }
  443. ],
  444. [
  445. {
  446. line: '0b101',
  447. tokens: [{ startIndex: 0, type: 'number.binary.js' }]
  448. }
  449. ],
  450. [
  451. {
  452. line: '0B101',
  453. tokens: [{ startIndex: 0, type: 'number.binary.js' }]
  454. }
  455. ],
  456. // Bigint
  457. [
  458. {
  459. line: '0n',
  460. tokens: [{ startIndex: 0, type: 'number.js' }]
  461. }
  462. ],
  463. [
  464. {
  465. line: ' 0n',
  466. tokens: [
  467. { startIndex: 0, type: '' },
  468. { startIndex: 1, type: 'number.js' }
  469. ]
  470. }
  471. ],
  472. [
  473. {
  474. line: ' 0n ',
  475. tokens: [
  476. { startIndex: 0, type: '' },
  477. { startIndex: 1, type: 'number.js' },
  478. { startIndex: 3, type: '' }
  479. ]
  480. }
  481. ],
  482. [
  483. {
  484. line: '0n ',
  485. tokens: [
  486. { startIndex: 0, type: 'number.js' },
  487. { startIndex: 2, type: '' }
  488. ]
  489. }
  490. ],
  491. [
  492. {
  493. line: '0n+0n',
  494. tokens: [
  495. { startIndex: 0, type: 'number.js' },
  496. { startIndex: 2, type: 'delimiter.js' },
  497. { startIndex: 3, type: 'number.js' }
  498. ]
  499. }
  500. ],
  501. [
  502. {
  503. line: '100n+10n',
  504. tokens: [
  505. { startIndex: 0, type: 'number.js' },
  506. { startIndex: 4, type: 'delimiter.js' },
  507. { startIndex: 5, type: 'number.js' }
  508. ]
  509. }
  510. ],
  511. [
  512. {
  513. line: '0n + 0n',
  514. tokens: [
  515. { startIndex: 0, type: 'number.js' },
  516. { startIndex: 2, type: '' },
  517. { startIndex: 3, type: 'delimiter.js' },
  518. { startIndex: 4, type: '' },
  519. { startIndex: 5, type: 'number.js' }
  520. ]
  521. }
  522. ],
  523. [
  524. {
  525. line: '0b101n',
  526. tokens: [{ startIndex: 0, type: 'number.binary.js' }]
  527. }
  528. ],
  529. [
  530. {
  531. line: '0123n',
  532. tokens: [{ startIndex: 0, type: 'number.octal.js' }]
  533. }
  534. ],
  535. [
  536. {
  537. line: '0o123n',
  538. tokens: [{ startIndex: 0, type: 'number.octal.js' }]
  539. }
  540. ],
  541. [
  542. {
  543. line: '0x123n',
  544. tokens: [{ startIndex: 0, type: 'number.hex.js' }]
  545. }
  546. ],
  547. // Regular Expressions
  548. [
  549. {
  550. line: '//',
  551. tokens: [{ startIndex: 0, type: 'comment.js' }]
  552. }
  553. ],
  554. [
  555. {
  556. line: '/**/',
  557. tokens: [{ startIndex: 0, type: 'comment.js' }]
  558. }
  559. ],
  560. [
  561. {
  562. line: '/***/',
  563. tokens: [{ startIndex: 0, type: 'comment.doc.js' }]
  564. }
  565. ],
  566. [
  567. {
  568. line: '5 / 3;',
  569. tokens: [
  570. { startIndex: 0, type: 'number.js' },
  571. { startIndex: 1, type: '' },
  572. { startIndex: 2, type: 'delimiter.js' },
  573. { startIndex: 3, type: '' },
  574. { startIndex: 4, type: 'number.js' },
  575. { startIndex: 5, type: 'delimiter.js' }
  576. ]
  577. }
  578. ],
  579. // Advanced regular expressions
  580. [
  581. {
  582. line: '1 / 2; /* comment',
  583. tokens: [
  584. { startIndex: 0, type: 'number.js' },
  585. { startIndex: 1, type: '' },
  586. { startIndex: 2, type: 'delimiter.js' },
  587. { startIndex: 3, type: '' },
  588. { startIndex: 4, type: 'number.js' },
  589. { startIndex: 5, type: 'delimiter.js' },
  590. { startIndex: 6, type: '' },
  591. { startIndex: 7, type: 'comment.js' }
  592. ]
  593. }
  594. ],
  595. [
  596. {
  597. line: '1 / 2 / x / b;',
  598. tokens: [
  599. { startIndex: 0, type: 'number.js' },
  600. { startIndex: 1, type: '' },
  601. { startIndex: 2, type: 'delimiter.js' },
  602. { startIndex: 3, type: '' },
  603. { startIndex: 4, type: 'number.js' },
  604. { startIndex: 5, type: '' },
  605. { startIndex: 6, type: 'delimiter.js' },
  606. { startIndex: 7, type: '' },
  607. { startIndex: 8, type: 'identifier.js' },
  608. { startIndex: 9, type: '' },
  609. { startIndex: 10, type: 'delimiter.js' },
  610. { startIndex: 11, type: '' },
  611. { startIndex: 12, type: 'identifier.js' },
  612. { startIndex: 13, type: 'delimiter.js' }
  613. ]
  614. }
  615. ],
  616. [
  617. {
  618. line: "x = /foo/.test('')",
  619. tokens: [
  620. { startIndex: 0, type: 'identifier.js' },
  621. { startIndex: 1, type: '' },
  622. { startIndex: 2, type: 'delimiter.js' },
  623. { startIndex: 3, type: '' },
  624. { startIndex: 4, type: 'regexp.js' },
  625. { startIndex: 9, type: 'delimiter.js' },
  626. { startIndex: 10, type: 'identifier.js' },
  627. { startIndex: 14, type: 'delimiter.parenthesis.js' },
  628. { startIndex: 15, type: 'string.js' },
  629. { startIndex: 17, type: 'delimiter.parenthesis.js' }
  630. ]
  631. }
  632. ],
  633. [
  634. {
  635. line: '/foo/',
  636. tokens: [{ startIndex: 0, type: 'regexp.js' }]
  637. }
  638. ],
  639. [
  640. {
  641. line: '/foo/g',
  642. tokens: [
  643. { startIndex: 0, type: 'regexp.js' },
  644. { startIndex: 5, type: 'keyword.other.js' }
  645. ]
  646. }
  647. ],
  648. [
  649. {
  650. line: '/foo/dgimsuy',
  651. tokens: [
  652. { startIndex: 0, type: 'regexp.js' },
  653. { startIndex: 5, type: 'keyword.other.js' }
  654. ]
  655. }
  656. ],
  657. [
  658. {
  659. line: '/foo/q', // invalid flag
  660. tokens: [
  661. { startIndex: 0, type: 'delimiter.js' },
  662. { startIndex: 1, type: 'identifier.js' },
  663. { startIndex: 4, type: 'delimiter.js' },
  664. { startIndex: 5, type: 'identifier.js' }
  665. ]
  666. }
  667. ],
  668. [
  669. {
  670. line: 'x = 1 + f(2 / 3, /foo/)',
  671. tokens: [
  672. { startIndex: 0, type: 'identifier.js' },
  673. { startIndex: 1, type: '' },
  674. { startIndex: 2, type: 'delimiter.js' },
  675. { startIndex: 3, type: '' },
  676. { startIndex: 4, type: 'number.js' },
  677. { startIndex: 5, type: '' },
  678. { startIndex: 6, type: 'delimiter.js' },
  679. { startIndex: 7, type: '' },
  680. { startIndex: 8, type: 'identifier.js' },
  681. { startIndex: 9, type: 'delimiter.parenthesis.js' },
  682. { startIndex: 10, type: 'number.js' },
  683. { startIndex: 11, type: '' },
  684. { startIndex: 12, type: 'delimiter.js' },
  685. { startIndex: 13, type: '' },
  686. { startIndex: 14, type: 'number.js' },
  687. { startIndex: 15, type: 'delimiter.js' },
  688. { startIndex: 16, type: '' },
  689. { startIndex: 17, type: 'regexp.js' },
  690. { startIndex: 22, type: 'delimiter.parenthesis.js' }
  691. ]
  692. }
  693. ],
  694. [
  695. {
  696. line: 'a /ads/ b;',
  697. tokens: [
  698. { startIndex: 0, type: 'identifier.js' },
  699. { startIndex: 1, type: '' },
  700. { startIndex: 2, type: 'delimiter.js' },
  701. { startIndex: 3, type: 'identifier.js' },
  702. { startIndex: 6, type: 'delimiter.js' },
  703. { startIndex: 7, type: '' },
  704. { startIndex: 8, type: 'identifier.js' },
  705. { startIndex: 9, type: 'delimiter.js' }
  706. ]
  707. }
  708. ],
  709. [
  710. {
  711. line: '1/(2/3)/2/3;',
  712. tokens: [
  713. { startIndex: 0, type: 'number.js' },
  714. { startIndex: 1, type: 'delimiter.js' },
  715. { startIndex: 2, type: 'delimiter.parenthesis.js' },
  716. { startIndex: 3, type: 'number.js' },
  717. { startIndex: 4, type: 'delimiter.js' },
  718. { startIndex: 5, type: 'number.js' },
  719. { startIndex: 6, type: 'delimiter.parenthesis.js' },
  720. { startIndex: 7, type: 'delimiter.js' },
  721. { startIndex: 8, type: 'number.js' },
  722. { startIndex: 9, type: 'delimiter.js' },
  723. { startIndex: 10, type: 'number.js' },
  724. { startIndex: 11, type: 'delimiter.js' }
  725. ]
  726. }
  727. ],
  728. [
  729. {
  730. line: '{ key: 123 }',
  731. tokens: [
  732. { startIndex: 0, type: 'delimiter.bracket.js' },
  733. { startIndex: 1, type: '' },
  734. { startIndex: 2, type: 'identifier.js' },
  735. { startIndex: 5, type: 'delimiter.js' },
  736. { startIndex: 6, type: '' },
  737. { startIndex: 7, type: 'number.js' },
  738. { startIndex: 10, type: '' },
  739. { startIndex: 11, type: 'delimiter.bracket.js' }
  740. ]
  741. }
  742. ],
  743. [
  744. {
  745. line: '[1,2,3]',
  746. tokens: [
  747. { startIndex: 0, type: 'delimiter.square.js' },
  748. { startIndex: 1, type: 'number.js' },
  749. { startIndex: 2, type: 'delimiter.js' },
  750. { startIndex: 3, type: 'number.js' },
  751. { startIndex: 4, type: 'delimiter.js' },
  752. { startIndex: 5, type: 'number.js' },
  753. { startIndex: 6, type: 'delimiter.square.js' }
  754. ]
  755. }
  756. ],
  757. [
  758. {
  759. line: 'foo(123);',
  760. tokens: [
  761. { startIndex: 0, type: 'identifier.js' },
  762. { startIndex: 3, type: 'delimiter.parenthesis.js' },
  763. { startIndex: 4, type: 'number.js' },
  764. { startIndex: 7, type: 'delimiter.parenthesis.js' },
  765. { startIndex: 8, type: 'delimiter.js' }
  766. ]
  767. }
  768. ],
  769. [
  770. {
  771. line: '{a:{b:[]}}',
  772. tokens: [
  773. { startIndex: 0, type: 'delimiter.bracket.js' },
  774. { startIndex: 1, type: 'identifier.js' },
  775. { startIndex: 2, type: 'delimiter.js' },
  776. { startIndex: 3, type: 'delimiter.bracket.js' },
  777. { startIndex: 4, type: 'identifier.js' },
  778. { startIndex: 5, type: 'delimiter.js' },
  779. { startIndex: 6, type: 'delimiter.square.js' },
  780. { startIndex: 8, type: 'delimiter.bracket.js' }
  781. ]
  782. }
  783. ],
  784. [
  785. {
  786. line: 'x = "[{()}]"',
  787. tokens: [
  788. { startIndex: 0, type: 'identifier.js' },
  789. { startIndex: 1, type: '' },
  790. { startIndex: 2, type: 'delimiter.js' },
  791. { startIndex: 3, type: '' },
  792. { startIndex: 4, type: 'string.js' }
  793. ]
  794. }
  795. ],
  796. [
  797. {
  798. line: 'test ? 1 : 2',
  799. tokens: [
  800. { startIndex: 0, type: 'identifier.js' },
  801. { startIndex: 4, type: '' },
  802. { startIndex: 5, type: 'delimiter.js' },
  803. { startIndex: 6, type: '' },
  804. { startIndex: 7, type: 'number.js' },
  805. { startIndex: 8, type: '' },
  806. { startIndex: 9, type: 'delimiter.js' },
  807. { startIndex: 10, type: '' },
  808. { startIndex: 11, type: 'number.js' }
  809. ]
  810. }
  811. ],
  812. [
  813. {
  814. line: 'couldBeNullish ?? 1',
  815. tokens: [
  816. { startIndex: 0, type: 'identifier.js' },
  817. { startIndex: 14, type: '' },
  818. { startIndex: 15, type: 'delimiter.js' },
  819. { startIndex: 17, type: '' },
  820. { startIndex: 18, type: 'number.js' }
  821. ]
  822. }
  823. ],
  824. [
  825. {
  826. line: "`${5 + 'x' + 3}a${4}`",
  827. tokens: [
  828. { startIndex: 0, type: 'string.js' },
  829. { startIndex: 1, type: 'delimiter.bracket.js' },
  830. { startIndex: 3, type: 'number.js' },
  831. { startIndex: 4, type: '' },
  832. { startIndex: 5, type: 'delimiter.js' },
  833. { startIndex: 6, type: '' },
  834. { startIndex: 7, type: 'string.js' },
  835. { startIndex: 10, type: '' },
  836. { startIndex: 11, type: 'delimiter.js' },
  837. { startIndex: 12, type: '' },
  838. { startIndex: 13, type: 'number.js' },
  839. { startIndex: 14, type: 'delimiter.bracket.js' },
  840. { startIndex: 15, type: 'string.js' },
  841. { startIndex: 16, type: 'delimiter.bracket.js' },
  842. { startIndex: 18, type: 'number.js' },
  843. { startIndex: 19, type: 'delimiter.bracket.js' },
  844. { startIndex: 20, type: 'string.js' }
  845. ]
  846. }
  847. ]
  848. ]);