/src/parser/test/esprima_tests.js

https://github.com/facebook/flow · JavaScript · 3329 lines · 3231 code · 21 blank · 77 comment · 7 complexity · 3451c95de7a27f94a063b044bbfda077 MD5 · raw file

  1. module.exports = {
  2. todo: {
  3. 'ES6: Destructured Parameters': true,
  4. 'Harmony Invalid syntax': true,
  5. },
  6. sections: {
  7. 'Function Expression': [
  8. '(function(){}())',
  9. 'var x = function(){}.bind(this)',
  10. ],
  11. 'Invalid syntax': [
  12. {
  13. content: '{',
  14. explanation: "Improved error message",
  15. expected_differences: {
  16. 'root.errors.0.message': {
  17. type: 'Wrong error message',
  18. expected: 'Unexpected end of input',
  19. actual: 'Unexpected end of input, expected the token `}`'
  20. }
  21. }
  22. },
  23. {
  24. content: '}',
  25. explanation: "Improved error message",
  26. expected_differences: {
  27. 'root.errors.0.message': {
  28. type: 'Wrong error message',
  29. expected: 'Unexpected token }',
  30. actual: 'Unexpected token `}`, expected the start of a statement'
  31. }
  32. }
  33. },
  34. '3ea',
  35. '3in []',
  36. '3e',
  37. {
  38. content: '3e+',
  39. explanation: "Esprima counts comments in its loc, Flow doesn't",
  40. expected_differences: {
  41. 'root.errors.0.column': {
  42. type: 'Wrong error column',
  43. expected: 3,
  44. actual: '0-2'
  45. },
  46. }
  47. },
  48. {
  49. content: '3e-',
  50. explanation: "Esprima counts comments in its loc, Flow doesn't",
  51. expected_differences: {
  52. 'root.errors.0.column': {
  53. type: 'Wrong error column',
  54. expected: 3,
  55. actual: '0-2'
  56. },
  57. }
  58. },
  59. '3x',
  60. '3x0',
  61. '0x',
  62. {
  63. content: '09',
  64. explanation: "Spec doesn't support this but every implementation does",
  65. expected_differences: {
  66. 'root.errors': {
  67. type: 'Flow found no error',
  68. expected: 'Line 1: Unexpected token ILLEGAL',
  69. actual: undefined
  70. },
  71. }
  72. },
  73. '01a',
  74. '3in[]',
  75. '0x3in[]',
  76. '"Hello\nWorld"',
  77. 'x\\',
  78. 'var x = /(s/g',
  79. '/',
  80. '/test',
  81. '/test\n/',
  82. /* TODO uncomment when esprima is fixed
  83. * https://code.google.com/p/esprima/issues/detail?id=604
  84. {
  85. content: 'var x = /[a-z]/\\ux',
  86. explanation: "10.8.5.1 disallows unicode escape flags",
  87. expected_differences: {
  88. 'root.errors.0.column': {
  89. type: 'Wrong error column',
  90. expected: 18,
  91. actual: '15-16'
  92. },
  93. 'root.errors.0.message': {
  94. type: 'Wrong error message',
  95. expected: 'Invalid regular expression',
  96. actual: 'Unexpected token ILLEGAL'
  97. },
  98. }
  99. },
  100. {
  101. content: 'var x = /[a-z]/\\\\ux',
  102. explanation: "10.8.5.1 disallows unicode escape flags",
  103. expected_differences: {
  104. 'root.errors.0.column': {
  105. type: 'Wrong error column',
  106. expected: 19,
  107. actual: '15-16'
  108. },
  109. 'root.errors.0.message': {
  110. type: 'Wrong error message',
  111. expected: 'Invalid regular expression',
  112. actual: 'Unexpected token ILLEGAL'
  113. },
  114. }
  115. },
  116. */
  117. '3 = 4',
  118. 'func() = 4',
  119. {
  120. content: '(1 + 1) = 10',
  121. explanation: "Esprima counts parens in its loc, Flow doesn't",
  122. expected_differences: {
  123. 'root.errors.0.column': {
  124. type: 'Wrong error column',
  125. expected: 7,
  126. actual: '1-6'
  127. },
  128. }
  129. },
  130. '"\\u{110000}"',
  131. {
  132. content: '"\\u{}"',
  133. explanation: "Flow's lexer complains at the beginning of a bad escape",
  134. expected_differences: {
  135. 'root.errors.0.column': {
  136. type: 'Wrong error column',
  137. expected: 4,
  138. actual: '2-3'
  139. },
  140. }
  141. },
  142. {
  143. content: '"\\u{FFFF"',
  144. explanation: "Flow's lexer complains at the beginning of a bad escape",
  145. expected_differences: {
  146. 'root.errors.0.column': {
  147. type: 'Wrong error column',
  148. expected: 9,
  149. actual: '2-3'
  150. },
  151. }
  152. },
  153. {
  154. content: '"\\u{FFZ}"',
  155. explanation: "Flow's lexer complains at the beginning of a bad escape",
  156. expected_differences: {
  157. 'root.errors.0.column': {
  158. type: 'Wrong error column',
  159. expected: 7,
  160. actual: '2-3'
  161. },
  162. }
  163. },
  164. 'x\\',
  165. '1++',
  166. '1--',
  167. '++1',
  168. '--1',
  169. {
  170. content: 'for((1 + 1) in list) process(x);',
  171. explanation: "Esprima counts comments in its loc, Flow doesn't",
  172. expected_differences: {
  173. 'root.errors.0.column': {
  174. type: 'Wrong error column',
  175. expected: 11,
  176. actual: '5-10'
  177. },
  178. }
  179. },
  180. {
  181. content: '[',
  182. explanation: "Improved error message",
  183. expected_differences: {
  184. 'root.errors.0.message': {
  185. type: 'Wrong error message',
  186. expected: 'Unexpected end of input',
  187. actual: 'Unexpected end of input, expected the token `]`'
  188. }
  189. }
  190. },
  191. {
  192. content: '[,',
  193. explanation: "Improved error message",
  194. expected_differences: {
  195. 'root.errors.0.message': {
  196. type: 'Wrong error message',
  197. expected: 'Unexpected end of input',
  198. actual: 'Unexpected end of input, expected the token `]`'
  199. }
  200. }
  201. },
  202. {
  203. content: '1 + {',
  204. explanation: "Improved error message",
  205. expected_differences: {
  206. 'root.errors.0.message': {
  207. type: 'Wrong error message',
  208. expected: 'Unexpected end of input',
  209. actual: 'Unexpected end of input, expected the token `}`'
  210. }
  211. }
  212. },
  213. {
  214. content: '1 + { t:t ',
  215. explanation: "Improved error message",
  216. expected_differences: {
  217. 'root.errors.0.message': {
  218. type: 'Wrong error message',
  219. expected: 'Unexpected end of input',
  220. actual: 'Unexpected end of input, expected the token `}`'
  221. }
  222. }
  223. },
  224. {
  225. content: '1 + { t:t,',
  226. explanation: "Improved error message",
  227. expected_differences: {
  228. 'root.errors.0.message': {
  229. type: 'Wrong error message',
  230. expected: 'Unexpected end of input',
  231. actual: 'Unexpected end of input, expected the token `}`'
  232. }
  233. }
  234. },
  235. 'var x = /\n/',
  236. 'var x = "\n',
  237. {
  238. content: 'var if = 42',
  239. explanation: "Improved error message",
  240. expected_differences: {
  241. 'root.errors.0.message': {
  242. type: 'Wrong error message',
  243. expected: 'Unexpected token if',
  244. actual: 'Unexpected token `if`'
  245. }
  246. }
  247. },
  248. {
  249. content: 'i #= 42',
  250. explanation: "# is no longer illegal in Flow, since we support private class fields. " +
  251. "Instead, it is unexpected since we are not parsing a member expression " +
  252. "or class property.",
  253. expected_differences: {
  254. 'root.errors.0.message': {
  255. type: 'Wrong error message',
  256. expected: 'Unexpected token ILLEGAL',
  257. actual: 'Unexpected token `#`, expected the end of an expression statement (`;`)'
  258. },
  259. }
  260. },
  261. 'i + 2 = 42',
  262. '+i = 42',
  263. '1 + (',
  264. {
  265. content: '\n\n\n{',
  266. explanation: "Improved error message",
  267. expected_differences: {
  268. 'root.errors.0.message': {
  269. type: 'Wrong error message',
  270. expected: 'Unexpected end of input',
  271. actual: 'Unexpected end of input, expected the token `}`'
  272. }
  273. }
  274. },
  275. {
  276. content: '\n/* Some multiline\ncomment */\n)',
  277. explanation: "Improved error message",
  278. expected_differences: {
  279. 'root.errors.0.message': {
  280. type: 'Wrong error message',
  281. expected: 'Unexpected token )',
  282. actual: 'Unexpected token `)`, expected the start of a statement'
  283. }
  284. }
  285. },
  286. {
  287. content: '{ set 1 }',
  288. explanation: "Improved error message",
  289. expected_differences: {
  290. 'root.errors.0.message': {
  291. type: 'Wrong error message',
  292. expected: 'Unexpected number',
  293. actual: 'Unexpected number, expected the end of an expression statement (`;`)'
  294. }
  295. }
  296. },
  297. {
  298. content: '{ get 2 }',
  299. explanation: "Improved error message",
  300. expected_differences: {
  301. 'root.errors.0.message': {
  302. type: 'Wrong error message',
  303. expected: 'Unexpected number',
  304. actual: 'Unexpected number, expected the end of an expression statement (`;`)'
  305. }
  306. }
  307. },
  308. {
  309. content: '({ set: s(if) { } })',
  310. explanation: "Improved error message",
  311. expected_differences: {
  312. 'root.errors.0.message': {
  313. type: 'Wrong error message',
  314. expected: 'Unexpected token if',
  315. actual: 'Unexpected token `if`'
  316. }
  317. }
  318. },
  319. {
  320. content: '({ set s(.) { } })',
  321. explanation: "Improved error message",
  322. expected_differences: {
  323. 'root.errors.0.message': {
  324. type: 'Wrong error message',
  325. expected: 'Unexpected token .',
  326. actual: 'Unexpected token `.`, expected an identifier'
  327. }
  328. }
  329. },
  330. {
  331. content: '({ set s() { } })',
  332. explanation: "Esprima error isn't great",
  333. expected_differences: {
  334. 'root.errors.0.column': {
  335. type: 'Wrong error column',
  336. expected: 9,
  337. actual: '7-8'
  338. },
  339. 'root.errors.0.message': {
  340. type: 'Wrong error message',
  341. expected: 'Unexpected token )',
  342. actual: 'Setter should have exactly one parameter'
  343. }
  344. }
  345. },
  346. {
  347. content: '({ set: s() { } })',
  348. explanation: "Improved error message",
  349. expected_differences: {
  350. 'root.errors.0.message': {
  351. type: 'Wrong error message',
  352. expected: 'Unexpected token {',
  353. actual: 'Unexpected token `{`, expected the token `,`'
  354. }
  355. }
  356. },
  357. {
  358. content: '({ set: s(a, b) { } })',
  359. explanation: "Improved error message",
  360. expected_differences: {
  361. 'root.errors.0.message': {
  362. type: 'Wrong error message',
  363. expected: 'Unexpected token {',
  364. actual: 'Unexpected token `{`, expected the token `,`'
  365. }
  366. }
  367. },
  368. {
  369. content: '({ get: g(d) { } })',
  370. explanation: "Improved error message",
  371. expected_differences: {
  372. 'root.errors.0.message': {
  373. type: 'Wrong error message',
  374. expected: 'Unexpected token {',
  375. actual: 'Unexpected token `{`, expected the token `,`'
  376. }
  377. }
  378. },
  379. {
  380. content: '({ get i() { }, i: 42 })',
  381. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  382. expected_differences: {
  383. 'root.errors': {
  384. type: 'Flow found no error',
  385. expected: 'Line 1: Object literal may not have data and accessor property with the same name',
  386. actual: undefined,
  387. }
  388. }
  389. },
  390. {
  391. content: '({ i: 42, get i() { } })',
  392. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  393. expected_differences: {
  394. 'root.errors': {
  395. type: 'Flow found no error',
  396. expected: 'Line 1: Object literal may not have data and accessor property with the same name',
  397. actual: undefined,
  398. }
  399. }
  400. },
  401. {
  402. content: '({ set i(x) { }, i: 42 })',
  403. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  404. expected_differences: {
  405. 'root.errors': {
  406. type: 'Flow found no error',
  407. expected: 'Line 1: Object literal may not have data and accessor property with the same name',
  408. actual: undefined,
  409. }
  410. }
  411. },
  412. {
  413. content: '({ i: 42, set i(x) { } })',
  414. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  415. expected_differences: {
  416. 'root.errors': {
  417. type: 'Flow found no error',
  418. expected: 'Line 1: Object literal may not have data and accessor property with the same name',
  419. actual: undefined,
  420. }
  421. }
  422. },
  423. {
  424. content: '({ get i() { }, get i() { } })',
  425. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  426. expected_differences: {
  427. 'root.errors': {
  428. type: 'Flow found no error',
  429. expected: 'Line 1: Object literal may not have multiple get/set accessors with the same name',
  430. actual: undefined,
  431. }
  432. }
  433. },
  434. {
  435. content: '({ set i(x) { }, set i(x) { } })',
  436. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  437. expected_differences: {
  438. 'root.errors': {
  439. type: 'Flow found no error',
  440. expected: 'Line 1: Object literal may not have multiple get/set accessors with the same name',
  441. actual: undefined,
  442. }
  443. }
  444. },
  445. {
  446. content: '((a)) => 42',
  447. explanation: "Improved error message",
  448. expected_differences: {
  449. 'root.errors.0.message': {
  450. type: 'Wrong error message',
  451. expected: 'Unexpected token =>',
  452. actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)'
  453. }
  454. }
  455. },
  456. {
  457. content: '(a, (b)) => 42',
  458. explanation: "Improved error message",
  459. expected_differences: {
  460. 'root.errors.0.message': {
  461. type: 'Wrong error message',
  462. expected: 'Unexpected token =>',
  463. actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)'
  464. }
  465. }
  466. },
  467. {
  468. content: '"use strict"; (eval = 10) => 42',
  469. explanation: "This is an arrow function error, not an assignment "+
  470. "error",
  471. expected_differences: {
  472. 'root.errors.0.message': {
  473. type: 'Wrong error message',
  474. expected: 'Assignment to eval or arguments is not allowed in strict mode',
  475. actual: 'Parameter name eval or arguments is not allowed in strict mode',
  476. },
  477. },
  478. },
  479. // strict mode, using eval when IsSimpleParameterList is true
  480. {
  481. content: '"use strict"; eval => 42',
  482. explanation: "Esprima error loc is crazy here",
  483. expected_differences: {
  484. 'root.errors.0.column': {
  485. type: 'Wrong error column',
  486. expected: 24,
  487. actual: '14-18'
  488. },
  489. }
  490. },
  491. // strict mode, using arguments when IsSimpleParameterList is true
  492. {
  493. content: '"use strict"; arguments => 42',
  494. explanation: "Esprima doesn't point to the bad argument",
  495. expected_differences: {
  496. 'root.errors.0.column': {
  497. type: 'Wrong error column',
  498. expected: 29,
  499. actual: '14-23'
  500. },
  501. }
  502. },
  503. // strict mode, using eval when IsSimpleParameterList is true
  504. {
  505. content: '"use strict"; (eval, a) => 42',
  506. explanation: "Esprima error loc is crazy here",
  507. expected_differences: {
  508. 'root.errors.0.column': {
  509. type: 'Wrong error column',
  510. expected: 29,
  511. actual: '15-19'
  512. },
  513. }
  514. },
  515. // strict mode, using arguments when IsSimpleParameterList is true
  516. {
  517. content: '"use strict"; (arguments, a) => 42',
  518. explanation: "Esprima doesn't point to the bad argument",
  519. expected_differences: {
  520. 'root.errors.0.column': {
  521. type: 'Wrong error column',
  522. expected: 34,
  523. actual: '15-24'
  524. },
  525. }
  526. },
  527. {
  528. content: '"use strict"; (a, a) => 42',
  529. explanation: "Esprima counts parens in its loc, Flow doesn't",
  530. expected_differences: {
  531. 'root.errors.0.column': {
  532. type: 'Wrong error column',
  533. expected: 20,
  534. actual: '18-19'
  535. },
  536. }
  537. },
  538. '"use strict"; (a) => 00',
  539. {
  540. content: '() <= 42',
  541. explanation: "Improved error message",
  542. expected_differences: {
  543. 'root.errors.0.message': {
  544. type: 'Wrong error message',
  545. expected: 'Unexpected token <=',
  546. actual: 'Unexpected token `<=`, expected the token `=>`'
  547. }
  548. }
  549. },
  550. {
  551. content: '() ? 42',
  552. explanation: "Improved error message",
  553. expected_differences: {
  554. 'root.errors.0.message': {
  555. type: 'Wrong error message',
  556. expected: 'Unexpected token ?',
  557. actual: 'Unexpected token `?`, expected the token `=>`'
  558. }
  559. }
  560. },
  561. {
  562. content: '() + 42',
  563. explanation: "Improved error message",
  564. expected_differences: {
  565. 'root.errors.0.message': {
  566. type: 'Wrong error message',
  567. expected: 'Unexpected token +',
  568. actual: 'Unexpected token `+`, expected the token `=>`'
  569. }
  570. }
  571. },
  572. {
  573. content: '(...x) + 42',
  574. explanation: "Improved error message",
  575. expected_differences: {
  576. 'root.errors.0.message': {
  577. type: 'Wrong error message',
  578. expected: 'Unexpected token +',
  579. actual: 'Unexpected token `+`, expected the token `=>`'
  580. }
  581. }
  582. },
  583. {
  584. content: '()++',
  585. explanation: "Improved error message",
  586. expected_differences: {
  587. 'root.errors.0.message': {
  588. type: 'Wrong error message',
  589. expected: 'Unexpected token ++',
  590. actual: 'Unexpected token `++`, expected the token `=>`'
  591. }
  592. }
  593. },
  594. {
  595. content: '()()',
  596. explanation: "Improved error message",
  597. expected_differences: {
  598. 'root.errors.0.message': {
  599. type: 'Wrong error message',
  600. expected: 'Unexpected token (',
  601. actual: 'Unexpected token `(`, expected the token `=>`'
  602. }
  603. }
  604. },
  605. {
  606. content: '(10) => 00',
  607. explanation: "Improved error message",
  608. expected_differences: {
  609. 'root.errors.0.message': {
  610. type: 'Wrong error message',
  611. expected: 'Unexpected token =>',
  612. actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)'
  613. }
  614. }
  615. },
  616. {
  617. content: '(10, 20) => 00',
  618. explanation: "Improved error message",
  619. expected_differences: {
  620. 'root.errors.0.message': {
  621. type: 'Wrong error message',
  622. expected: 'Unexpected token =>',
  623. actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)'
  624. }
  625. }
  626. },
  627. {
  628. content: '"use strict"; (eval) => 42',
  629. explanation: "Esprima error loc is crazy here",
  630. expected_differences: {
  631. 'root.errors.0.column': {
  632. type: 'Wrong error column',
  633. expected: 26,
  634. actual: '15-19'
  635. },
  636. }
  637. },
  638. {
  639. content: '(eval) => { "use strict"; 42 }',
  640. explanation: "Esprima error loc is crazy here",
  641. expected_differences: {
  642. 'root.errors.0.column': {
  643. type: 'Wrong error column',
  644. expected: 30,
  645. actual: '1-5'
  646. },
  647. }
  648. },
  649. {
  650. content: 'function t(if) { }',
  651. explanation: "Improved error message",
  652. expected_differences: {
  653. 'root.errors.0.message': {
  654. type: 'Wrong error message',
  655. expected: 'Unexpected token if',
  656. actual: 'Unexpected token `if`'
  657. }
  658. }
  659. },
  660. {
  661. content: 'function t(true) { }',
  662. explanation: "Improved error message",
  663. expected_differences: {
  664. 'root.errors.0.message': {
  665. type: 'Wrong error message',
  666. expected: 'Unexpected token true',
  667. actual: 'Unexpected token `true`'
  668. }
  669. }
  670. },
  671. {
  672. content: 'function t(false) { }',
  673. explanation: "Improved error message",
  674. expected_differences: {
  675. 'root.errors.0.message': {
  676. type: 'Wrong error message',
  677. expected: 'Unexpected token false',
  678. actual: 'Unexpected token `false`'
  679. }
  680. }
  681. },
  682. {
  683. content: 'function t(null) { }',
  684. explanation: "Improved error message",
  685. expected_differences: {
  686. 'root.errors.0.message': {
  687. type: 'Wrong error message',
  688. expected: 'Unexpected token null',
  689. actual: 'Unexpected token `null`'
  690. }
  691. }
  692. },
  693. {
  694. content: 'function null() { }',
  695. explanation: "Improved error message",
  696. expected_differences: {
  697. 'root.errors.0.message': {
  698. type: 'Wrong error message',
  699. expected: 'Unexpected token null',
  700. actual: 'Unexpected token `null`'
  701. }
  702. }
  703. },
  704. {
  705. content: 'function true() { }',
  706. explanation: "Improved error message",
  707. expected_differences: {
  708. 'root.errors.0.message': {
  709. type: 'Wrong error message',
  710. expected: 'Unexpected token true',
  711. actual: 'Unexpected token `true`'
  712. }
  713. }
  714. },
  715. {
  716. content: 'function false() { }',
  717. explanation: "Improved error message",
  718. expected_differences: {
  719. 'root.errors.0.message': {
  720. type: 'Wrong error message',
  721. expected: 'Unexpected token false',
  722. actual: 'Unexpected token `false`'
  723. }
  724. }
  725. },
  726. {
  727. content: 'function if() { }',
  728. explanation: "Improved error message",
  729. expected_differences: {
  730. 'root.errors.0.message': {
  731. type: 'Wrong error message',
  732. expected: 'Unexpected token if',
  733. actual: 'Unexpected token `if`'
  734. }
  735. }
  736. },
  737. {
  738. content: 'a b;',
  739. explanation: "Improved error message",
  740. expected_differences: {
  741. 'root.errors.0.message': {
  742. type: 'Wrong error message',
  743. expected: 'Unexpected identifier',
  744. actual: 'Unexpected identifier, expected the end of an expression statement (`;`)'
  745. }
  746. }
  747. },
  748. {
  749. content: 'if.a;',
  750. explanation: "Improved error message",
  751. expected_differences: {
  752. 'root.errors.0.message': {
  753. type: 'Wrong error message',
  754. expected: 'Unexpected token .',
  755. actual: 'Unexpected token `.`, expected the token `(`'
  756. }
  757. }
  758. },
  759. {
  760. content: 'a if;',
  761. explanation: "Improved error message",
  762. expected_differences: {
  763. 'root.errors.0.message': {
  764. type: 'Wrong error message',
  765. expected: 'Unexpected token if',
  766. actual: 'Unexpected token `if`, expected the end of an expression statement (`;`)'
  767. }
  768. }
  769. },
  770. {
  771. content: 'a class;',
  772. explanation: 'class is no longer a future reserved word',
  773. expected_differences: {
  774. 'root.errors.0.message': {
  775. type: 'Wrong error message',
  776. expected: 'Unexpected reserved word',
  777. actual: 'Unexpected token `class`, expected the end of an expression statement (`;`)',
  778. },
  779. },
  780. },
  781. 'break\n',
  782. {
  783. content: 'break 1;',
  784. explanation: "Improved error message",
  785. expected_differences: {
  786. 'root.errors.0.message': {
  787. type: 'Wrong error message',
  788. expected: 'Unexpected number',
  789. actual: 'Unexpected number, expected an identifier'
  790. }
  791. }
  792. },
  793. 'continue\n',
  794. {
  795. content: 'continue 2;',
  796. explanation: "Improved error message",
  797. expected_differences: {
  798. 'root.errors.0.message': {
  799. type: 'Wrong error message',
  800. expected: 'Unexpected number',
  801. actual: 'Unexpected number, expected an identifier'
  802. }
  803. }
  804. },
  805. 'throw',
  806. {
  807. content: 'throw;',
  808. explanation: "Improved error message",
  809. expected_differences: {
  810. 'root.errors.0.message': {
  811. type: 'Wrong error message',
  812. expected: 'Unexpected token ;',
  813. actual: 'Unexpected token `;`'
  814. }
  815. }
  816. },
  817. 'throw\n',
  818. {
  819. content: 'for (var i, i2 in {});',
  820. explanation: "Esprima counts comments in its loc, Flow doesn't",
  821. expected_differences: {
  822. 'root.errors.0.column': {
  823. type: 'Wrong error column',
  824. expected: 15,
  825. actual: '5-14'
  826. },
  827. 'root.errors.0.message': {
  828. type: 'Wrong error message',
  829. expected: 'Unexpected token in',
  830. actual: 'Invalid left-hand side in for-in'
  831. },
  832. }
  833. },
  834. {
  835. content: 'for ((i in {}));',
  836. explanation: "Improved error message",
  837. expected_differences: {
  838. 'root.errors.0.message': {
  839. type: 'Wrong error message',
  840. expected: 'Unexpected token )',
  841. actual: 'Unexpected token `)`, expected the token `;`'
  842. }
  843. }
  844. },
  845. 'for (i + 1 in {});',
  846. 'for (+i in {});',
  847. {
  848. content: 'if(false)',
  849. explanation: "Improved error message",
  850. expected_differences: {
  851. 'root.errors.0.message': {
  852. type: 'Wrong error message',
  853. expected: 'Unexpected end of input',
  854. actual: 'Unexpected end of input, expected the start of a statement'
  855. }
  856. }
  857. },
  858. {
  859. content: 'if(false) doThis(); else',
  860. explanation: "Improved error message",
  861. expected_differences: {
  862. 'root.errors.0.message': {
  863. type: 'Wrong error message',
  864. expected: 'Unexpected end of input',
  865. actual: 'Unexpected end of input, expected the start of a statement'
  866. }
  867. }
  868. },
  869. {
  870. content: 'do',
  871. explanation: "Improved error message",
  872. expected_differences: {
  873. 'root.errors.0.message': {
  874. type: 'Wrong error message',
  875. expected: 'Unexpected end of input',
  876. actual: 'Unexpected end of input, expected the start of a statement'
  877. }
  878. }
  879. },
  880. {
  881. content: 'while(false)',
  882. explanation: "Improved error message",
  883. expected_differences: {
  884. 'root.errors.0.message': {
  885. type: 'Wrong error message',
  886. expected: 'Unexpected end of input',
  887. actual: 'Unexpected end of input, expected the start of a statement'
  888. }
  889. }
  890. },
  891. {
  892. content: 'for(;;)',
  893. explanation: "Improved error message",
  894. expected_differences: {
  895. 'root.errors.0.message': {
  896. type: 'Wrong error message',
  897. expected: 'Unexpected end of input',
  898. actual: 'Unexpected end of input, expected the start of a statement'
  899. }
  900. }
  901. },
  902. {
  903. content: 'with(x)',
  904. explanation: "Improved error message",
  905. expected_differences: {
  906. 'root.errors.0.message': {
  907. type: 'Wrong error message',
  908. expected: 'Unexpected end of input',
  909. actual: 'Unexpected end of input, expected the start of a statement'
  910. }
  911. }
  912. },
  913. 'try { }',
  914. 'const x = 12, y;',
  915. 'const x, y = 12;',
  916. 'const x;',
  917. {
  918. content: 'if(true) let a = 1;',
  919. explanation: "The let keyword is parsed as an identifer. " +
  920. "It's the a that causes the error",
  921. expected_differences: {
  922. 'root.errors.0.column': {
  923. type: 'Wrong error column',
  924. expected: 9,
  925. actual: '13-14'
  926. },
  927. 'root.errors.0.message': {
  928. type: 'Wrong error message',
  929. expected: 'Unexpected token let',
  930. actual: 'Unexpected identifier, expected the end of an expression statement (`;`)',
  931. },
  932. }
  933. },
  934. {
  935. content: 'if(true) const a = 1;',
  936. explanation: "Improved error message",
  937. expected_differences: {
  938. 'root.errors.0.message': {
  939. type: 'Wrong error message',
  940. expected: 'Unexpected token const',
  941. actual: 'Unexpected token `const`'
  942. }
  943. }
  944. },
  945. {
  946. content: 'switch (c) { default: default: }',
  947. explanation: "Esprima points after the duplicate default",
  948. expected_differences: {
  949. 'root.errors.0.column': {
  950. type: 'Wrong error column',
  951. expected: 30,
  952. actual: '22-29'
  953. },
  954. }
  955. },
  956. {
  957. content: 'new X()."s"',
  958. explanation: "Improved error message",
  959. expected_differences: {
  960. 'root.errors.0.message': {
  961. type: 'Wrong error message',
  962. expected: 'Unexpected string',
  963. actual: 'Unexpected string, expected an identifier'
  964. }
  965. }
  966. },
  967. '/*',
  968. '/*\n\n\n',
  969. '/**',
  970. '/*\n\n*',
  971. '/*hello',
  972. '/*hello *',
  973. {
  974. content: '\n]',
  975. explanation: "Improved error message",
  976. expected_differences: {
  977. 'root.errors.0.message': {
  978. type: 'Wrong error message',
  979. expected: 'Unexpected token ]',
  980. actual: 'Unexpected token `]`, expected the start of a statement'
  981. }
  982. }
  983. },
  984. {
  985. content: '\r]',
  986. explanation: "Improved error message",
  987. expected_differences: {
  988. 'root.errors.0.message': {
  989. type: 'Wrong error message',
  990. expected: 'Unexpected token ]',
  991. actual: 'Unexpected token `]`, expected the start of a statement'
  992. }
  993. }
  994. },
  995. {
  996. content: '\r\n]',
  997. explanation: "Improved error message",
  998. expected_differences: {
  999. 'root.errors.0.message': {
  1000. type: 'Wrong error message',
  1001. expected: 'Unexpected token ]',
  1002. actual: 'Unexpected token `]`, expected the start of a statement'
  1003. }
  1004. }
  1005. },
  1006. {
  1007. content: '\n\r]',
  1008. explanation: "Improved error message",
  1009. expected_differences: {
  1010. 'root.errors.0.message': {
  1011. type: 'Wrong error message',
  1012. expected: 'Unexpected token ]',
  1013. actual: 'Unexpected token `]`, expected the start of a statement'
  1014. }
  1015. }
  1016. },
  1017. {
  1018. content: '//\r\n]',
  1019. explanation: "Improved error message",
  1020. expected_differences: {
  1021. 'root.errors.0.message': {
  1022. type: 'Wrong error message',
  1023. expected: 'Unexpected token ]',
  1024. actual: 'Unexpected token `]`, expected the start of a statement'
  1025. }
  1026. }
  1027. },
  1028. {
  1029. content: '//\n\r]',
  1030. explanation: "Improved error message",
  1031. expected_differences: {
  1032. 'root.errors.0.message': {
  1033. type: 'Wrong error message',
  1034. expected: 'Unexpected token ]',
  1035. actual: 'Unexpected token `]`, expected the start of a statement'
  1036. }
  1037. }
  1038. },
  1039. '/a\\\n/',
  1040. {
  1041. content: '//\r \n]',
  1042. explanation: "Improved error message",
  1043. expected_differences: {
  1044. 'root.errors.0.message': {
  1045. type: 'Wrong error message',
  1046. expected: 'Unexpected token ]',
  1047. actual: 'Unexpected token `]`, expected the start of a statement'
  1048. }
  1049. }
  1050. },
  1051. {
  1052. content: '/*\r\n*/]',
  1053. explanation: "Improved error message",
  1054. expected_differences: {
  1055. 'root.errors.0.message': {
  1056. type: 'Wrong error message',
  1057. expected: 'Unexpected token ]',
  1058. actual: 'Unexpected token `]`, expected the start of a statement'
  1059. }
  1060. }
  1061. },
  1062. {
  1063. content: '/*\n\r*/]',
  1064. explanation: "Improved error message",
  1065. expected_differences: {
  1066. 'root.errors.0.message': {
  1067. type: 'Wrong error message',
  1068. expected: 'Unexpected token ]',
  1069. actual: 'Unexpected token `]`, expected the start of a statement'
  1070. }
  1071. }
  1072. },
  1073. {
  1074. content: '/*\r \n*/]',
  1075. explanation: "Improved error message",
  1076. expected_differences: {
  1077. 'root.errors.0.message': {
  1078. type: 'Wrong error message',
  1079. expected: 'Unexpected token ]',
  1080. actual: 'Unexpected token `]`, expected the start of a statement'
  1081. }
  1082. }
  1083. },
  1084. '\\\\',
  1085. '\\x',
  1086. {
  1087. content: '"\\',
  1088. explanation: "Esprima has a non-existent location for the eof",
  1089. expected_differences: {
  1090. 'root.errors.0.column': {
  1091. type: 'Wrong error column',
  1092. expected: 3,
  1093. actual: '2-2'
  1094. },
  1095. }
  1096. },
  1097. '"\\u',
  1098. {
  1099. content: 'try { } catch() {}',
  1100. explanation: "Improved error message",
  1101. expected_differences: {
  1102. 'root.errors.0.message': {
  1103. type: 'Wrong error message',
  1104. expected: 'Unexpected token )',
  1105. actual: 'Unexpected token `)`, expected an identifier'
  1106. }
  1107. }
  1108. },
  1109. 'return',
  1110. 'break',
  1111. 'continue',
  1112. 'switch (x) { default: continue; }',
  1113. {
  1114. content: 'do { x } *',
  1115. explanation: "Improved error message",
  1116. expected_differences: {
  1117. 'root.errors.0.message': {
  1118. type: 'Wrong error message',
  1119. expected: 'Unexpected token *',
  1120. actual: 'Unexpected token `*`, expected the token `while`'
  1121. }
  1122. }
  1123. },
  1124. 'while (true) { break x; }',
  1125. 'while (true) { continue x; }',
  1126. 'x: while (true) { (function () { break x; }); }',
  1127. 'x: while (true) { (function () { continue x; }); }',
  1128. 'x: while (true) { (function () { break; }); }',
  1129. 'x: while (true) { (function () { continue; }); }',
  1130. {
  1131. content: 'x: while (true) { x: while (true) { } }',
  1132. explanation: "Esprima points to the location after the second colon",
  1133. expected_differences: {
  1134. 'root.errors.0.column': {
  1135. type: 'Wrong error column',
  1136. expected: 20,
  1137. actual: '18-19'
  1138. },
  1139. }
  1140. },
  1141. '(function () { \'use strict\'; delete i; }())',
  1142. '(function () { \'use strict\'; with (i); }())',
  1143. {
  1144. content: 'function hello() {\'use strict\'; ({ i: 42, i: 42 }) }',
  1145. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  1146. expected_differences: {
  1147. 'root.errors': {
  1148. type: 'Flow found no error',
  1149. expected: 'Line 1: Duplicate data property in object literal not allowed in strict mode',
  1150. actual: undefined,
  1151. }
  1152. }
  1153. },
  1154. {
  1155. content: 'function hello() {\'use strict\'; ({ hasOwnProperty: 42, hasOwnProperty: 42 }) }',
  1156. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  1157. expected_differences: {
  1158. 'root.errors': {
  1159. type: 'Flow found no error',
  1160. expected: 'Line 1: Duplicate data property in object literal not allowed in strict mode',
  1161. actual: undefined,
  1162. }
  1163. }
  1164. },
  1165. 'function hello() {\'use strict\'; var eval = 10; }',
  1166. 'function hello() {\'use strict\'; var arguments = 10; }',
  1167. 'function hello() {\'use strict\'; try { } catch (eval) { } }',
  1168. 'function hello() {\'use strict\'; try { } catch (arguments) { } }',
  1169. 'function hello() {\'use strict\'; eval = 10; }',
  1170. 'function hello() {\'use strict\'; arguments = 10; }',
  1171. 'function hello() {\'use strict\'; ++eval; }',
  1172. 'function hello() {\'use strict\'; --eval; }',
  1173. 'function hello() {\'use strict\'; ++arguments; }',
  1174. 'function hello() {\'use strict\'; --arguments; }',
  1175. 'function hello() {\'use strict\'; eval++; }',
  1176. 'function hello() {\'use strict\'; eval--; }',
  1177. 'function hello() {\'use strict\'; arguments++; }',
  1178. 'function hello() {\'use strict\'; arguments--; }',
  1179. 'function hello() {\'use strict\'; function eval() { } }',
  1180. 'function hello() {\'use strict\'; function arguments() { } }',
  1181. 'function eval() {\'use strict\'; }',
  1182. 'function arguments() {\'use strict\'; }',
  1183. 'function hello() {\'use strict\'; (function eval() { }()) }',
  1184. 'function hello() {\'use strict\'; (function arguments() { }()) }',
  1185. '(function eval() {\'use strict\'; })()',
  1186. '(function arguments() {\'use strict\'; })()',
  1187. 'function hello() {\'use strict\'; ({ s: function eval() { } }); }',
  1188. '(function package() {\'use strict\'; })()',
  1189. 'function hello() {\'use strict\'; ({ i: 10, set s(eval) { } }); }',
  1190. 'function hello() {\'use strict\'; ({ set s(eval) { } }); }',
  1191. 'function hello() {\'use strict\'; ({ s: function s(eval) { } }); }',
  1192. 'function hello(eval) {\'use strict\';}',
  1193. 'function hello(arguments) {\'use strict\';}',
  1194. 'function hello() { \'use strict\'; function inner(eval) {} }',
  1195. 'function hello() { \'use strict\'; function inner(arguments) {} }',
  1196. ' "\\1"; \'use strict\';',
  1197. 'function hello() { \'use strict\'; "\\1"; }',
  1198. 'function hello() { \'use strict\'; 021; }',
  1199. 'function hello() { \'use strict\'; ({ "\\1": 42 }); }',
  1200. 'function hello() { \'use strict\'; ({ 021: 42 }); }',
  1201. 'function hello() { "octal directive\\1"; "use strict"; }',
  1202. 'function hello() { "octal directive\\1"; "octal directive\\2"; "use strict"; }',
  1203. 'function hello() { "use strict"; function inner() { "octal directive\\1"; } }',
  1204. 'function hello() { "use strict"; var implements; }',
  1205. 'function hello() { "use strict"; var interface; }',
  1206. 'function hello() { "use strict"; var package; }',
  1207. 'function hello() { "use strict"; var private; }',
  1208. 'function hello() { "use strict"; var protected; }',
  1209. 'function hello() { "use strict"; var public; }',
  1210. 'function hello() { "use strict"; var static; }',
  1211. 'function hello() { "use strict"; var yield; }',
  1212. 'function hello() { "use strict"; var let; }',
  1213. 'function hello(static) { "use strict"; }',
  1214. 'function static() { "use strict"; }',
  1215. 'function eval(a) { "use strict"; }',
  1216. 'function arguments(a) { "use strict"; }',
  1217. 'var yield',
  1218. {
  1219. content: 'var let',
  1220. explanation: "Bug in esprima. This should be allowed",
  1221. expected_differences: {
  1222. 'root.errors': {
  1223. type: 'Flow found no error',
  1224. expected: 'Line 1: Unexpected token let',
  1225. actual: undefined
  1226. },
  1227. }
  1228. },
  1229. '"use strict"; function static() { }',
  1230. 'function a(t, t) { "use strict"; }',
  1231. 'function a(eval) { "use strict"; }',
  1232. 'function a(package) { "use strict"; }',
  1233. 'function a() { "use strict"; function b(t, t) { }; }',
  1234. '(function a(t, t) { "use strict"; })',
  1235. 'function a() { "use strict"; (function b(t, t) { }); }',
  1236. // Duplicates are forbidden if IsSimpleParameterList is false, and rest
  1237. // params, patterns, and defaults all make the params non-simple
  1238. {
  1239. content: '(t, t, ...rest) => 42',
  1240. explanation: "Esprima points to the end of the params not to the "+
  1241. "bad param itself",
  1242. expected_differences: {
  1243. 'root.errors.0.column': {
  1244. type: 'Wrong error column',
  1245. expected: 15,
  1246. actual: '4-5'
  1247. },
  1248. }
  1249. },
  1250. {
  1251. content: '(t, t, [b]) => 42',
  1252. explanation: "Esprima points to the end of the params not to the "+
  1253. "bad param itself",
  1254. expected_differences: {
  1255. 'root.errors.0.column': {
  1256. type: 'Wrong error column',
  1257. expected: 11,
  1258. actual: '4-5'
  1259. },
  1260. }
  1261. },
  1262. {
  1263. content: '(t, t, {b}) => 42',
  1264. explanation: "Esprima points to the end of the params not to the "+
  1265. "bad param itself",
  1266. expected_differences: {
  1267. 'root.errors.0.column': {
  1268. type: 'Wrong error column',
  1269. expected: 11,
  1270. actual: '4-5'
  1271. },
  1272. }
  1273. },
  1274. {
  1275. content: '(t, t, b=1) => 42',
  1276. explanation: "Esprima points to the end of the params not to the "+
  1277. "bad param itself",
  1278. expected_differences: {
  1279. 'root.errors.0.column': {
  1280. type: 'Wrong error column',
  1281. expected: 11,
  1282. actual: '4-5'
  1283. },
  1284. }
  1285. },
  1286. '(function a(eval) { "use strict"; })',
  1287. '(function a(package) { "use strict"; })',
  1288. {
  1289. content: '__proto__: __proto__: 42;',
  1290. explanation: "Esprima points to the location after the second colon",
  1291. expected_differences: {
  1292. 'root.errors.0.column': {
  1293. type: 'Wrong error column',
  1294. expected: 21,
  1295. actual: '11-20'
  1296. },
  1297. }
  1298. },
  1299. '"use strict"; function t(__proto__, __proto__) { }',
  1300. {
  1301. content: '"use strict"; x = { __proto__: 42, __proto__: 43 }',
  1302. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  1303. expected_differences: {
  1304. 'root.errors': {
  1305. type: 'Flow found no error',
  1306. expected: 'Line 1: Duplicate data property in object literal not allowed in strict mode',
  1307. actual: undefined,
  1308. }
  1309. }
  1310. },
  1311. {
  1312. content: '"use strict"; x = { get __proto__() { }, __proto__: 43 }',
  1313. explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
  1314. expected_differences: {
  1315. 'root.errors': {
  1316. type: 'Flow found no error',
  1317. expected: 'Line 1: Object literal may not have data and accessor property with the same name',
  1318. actual: undefined,
  1319. }
  1320. }
  1321. },
  1322. {
  1323. content: 'var',
  1324. explanation: "Improved error message",
  1325. expected_differences: {
  1326. 'root.errors.0.message': {
  1327. type: 'Wrong error message',
  1328. expected: 'Unexpected end of input',
  1329. actual: 'Unexpected end of input, expected an identifier'
  1330. }
  1331. }
  1332. },
  1333. {
  1334. content: 'let',
  1335. explanation: "Improved error message",
  1336. expected_differences: {
  1337. 'root.errors.0.message': {
  1338. type: 'Wrong error message',
  1339. expected: 'Unexpected end of input',
  1340. actual: 'Unexpected end of input, expected an identifier'
  1341. }
  1342. }
  1343. },
  1344. {
  1345. content: 'const',
  1346. explanation: "Improved error message",
  1347. expected_differences: {
  1348. 'root.errors.0.message': {
  1349. type: 'Wrong error message',
  1350. expected: 'Unexpected end of input',
  1351. actual: 'Unexpected end of input, expected an identifier'
  1352. }
  1353. }
  1354. },
  1355. {
  1356. content: '{ ; ; ',
  1357. explanation: "Improved error message",
  1358. expected_differences: {
  1359. 'root.errors.0.message': {
  1360. type: 'Wrong error message',
  1361. expected: 'Unexpected end of input',
  1362. actual: 'Unexpected end of input, expected the token `}`'
  1363. }
  1364. }
  1365. },
  1366. {
  1367. content: 'function t() { ; ; ',
  1368. explanation: "Improved error message",
  1369. expected_differences: {
  1370. 'root.errors.0.message': {
  1371. type: 'Wrong error message',
  1372. expected: 'Unexpected end of input',
  1373. actual: 'Unexpected end of input, expected the token `}`'
  1374. }
  1375. }
  1376. },
  1377. {
  1378. content: 'let let',
  1379. explanation: "Improved error message",
  1380. expected_differences: {
  1381. 'root.errors.0.message': {
  1382. type: 'Wrong error message',
  1383. expected: 'Unexpected token let',
  1384. actual: 'Unexpected token `let`'
  1385. }
  1386. }
  1387. },
  1388. {
  1389. content: 'const let=4',
  1390. explanation: "Improved error message",
  1391. expected_differences: {
  1392. 'root.errors.0.message': {
  1393. type: 'Wrong error message',
  1394. expected: 'Unexpected token let',
  1395. actual: 'Unexpected token `let`'
  1396. }
  1397. }
  1398. },
  1399. {
  1400. content: 'for (let let=4;;) {}',
  1401. explanation: "Improved error message",
  1402. expected_differences: {
  1403. 'root.errors.0.message': {
  1404. type: 'Wrong error message',
  1405. expected: 'Unexpected token let',
  1406. actual: 'Unexpected token `let`'
  1407. }
  1408. }
  1409. },
  1410. {
  1411. content: 'for (let in arr) {}',
  1412. explanation: "Improved error message",
  1413. expected_differences: {
  1414. 'root.errors.0.message': {
  1415. type: 'Wrong error message',
  1416. expected: 'Unexpected token in',
  1417. actual: 'Unexpected token `in`'
  1418. }
  1419. }
  1420. },
  1421. {
  1422. content: 'for (let let in arr) {}',
  1423. explanation: "Improved error message",
  1424. expected_differences: {
  1425. 'root.errors.0.message': {
  1426. type: 'Wrong error message',
  1427. expected: 'Unexpected token let',
  1428. actual: 'Unexpected token `let`'
  1429. }
  1430. }
  1431. },
  1432. {
  1433. content: 'class let { }',
  1434. explanation: "Esprima counts comments in its loc, Flow doesn't",
  1435. expected_differences: {
  1436. 'root.errors.0.message': {
  1437. type: 'Wrong error message',
  1438. expected: 'Unexpected token let',
  1439. actual: 'Use of future reserved word in strict mode'
  1440. },
  1441. }
  1442. },
  1443. 'class A { foo() { let let } }',
  1444. {
  1445. content: 'function foo([a.a]) {}',
  1446. explanation: 'Esprima is off by one, flow fails to parse it',
  1447. expected_differences: {
  1448. 'root.errors.0.column': {
  1449. type: 'Wrong error column',
  1450. expected: 18,
  1451. actual: '15-16'
  1452. },
  1453. 'root.errors.0.message': {
  1454. type: 'Wrong error message',
  1455. expected: 'Invalid left-hand side in formals list',
  1456. actual: 'Unexpected token `.`, expected the token `,`',
  1457. }
  1458. },
  1459. },
  1460. {
  1461. content: 'var f = function ([a.a]) {}',
  1462. explanation: 'Esprima is off by one, flow fails to parse it',
  1463. expected_differences: {
  1464. 'root.errors.0.column': {
  1465. type: 'Wrong error column',
  1466. expected: 23,
  1467. actual: '20-21'
  1468. },
  1469. 'root.errors.0.message': {
  1470. type: 'Wrong error message',
  1471. expected: 'Invalid left-hand side in formals list',
  1472. actual: 'Unexpected token `.`, expected the token `,`',
  1473. }
  1474. },
  1475. },
  1476. ],
  1477. 'JSX': [
  1478. '<n:a n:v />',
  1479. '<a n:foo="bar"> {value} <b><c /></b></a>',
  1480. '<a b={" "} c=" " d="&amp;" />',
  1481. '<日本語></日本語>',
  1482. '<AbC-def\n test="&#x0026;&#38;">\nbar\nbaz\n</AbC-def>',
  1483. '<a b={x ? <c /> : <d />} />',
  1484. '<div>@test content</div>',
  1485. '<div><br />7x invalid-js-identifier</div>',
  1486. '<div {...props} />',
  1487. '<div {...props} post="attribute" />',
  1488. '<div pre="leading" pre2="attribute" {...props}></div>',
  1489. '<a> </a>',
  1490. ],
  1491. 'Invalid JSX Syntax': [
  1492. '<a b=d />',
  1493. '<a></b>',
  1494. '<a foo="bar',
  1495. {
  1496. content: '<a:b.c></a:b.c>',
  1497. explanation: "Improved error message",
  1498. expected_differences: {
  1499. 'root.errors.0.message': {
  1500. type: 'Wrong error message',
  1501. expected: 'Unexpected token .',
  1502. actual: 'Unexpected token `.`, expected an identifier'
  1503. }
  1504. }
  1505. },
  1506. {
  1507. content: '<a.b:c></a.b:c>',
  1508. explanation: "Improved error message",
  1509. expected_differences: {
  1510. 'root.errors.0.message': {
  1511. type: 'Wrong error message',
  1512. expected: 'Unexpected token :',
  1513. actual: 'Unexpected token `:`, expected an identifier'
  1514. }
  1515. }
  1516. },
  1517. '<a.b.c></a>',
  1518. {
  1519. content: '<.a></.a>',
  1520. explanation: "Improved error message",
  1521. expected_differences: {
  1522. 'root.errors.0.message': {
  1523. type: 'Wrong error message',
  1524. expected: 'Unexpected token .',
  1525. actual: 'Unexpected token `.`, expected an identifier'
  1526. }
  1527. }
  1528. },
  1529. {
  1530. content: '<a[foo]></a[foo]>',
  1531. explanation: "Improved error message",
  1532. expected_differences: {
  1533. 'root.errors.0.message': {
  1534. type: 'Wrong error message',
  1535. expected: 'Unexpected token [',
  1536. actual: 'Unexpected token `[`, expected an identifier'
  1537. }
  1538. }
  1539. },
  1540. {
  1541. content: '<a[\'foo\']></a[\'foo\']>',
  1542. explanation: "Improved error message",
  1543. expected_differences: {
  1544. 'root.errors.0.message': {
  1545. type: 'Wrong error message',
  1546. expected: 'Unexpected token [',
  1547. actual: 'Unexpected token `[`, expected an identifier'
  1548. }
  1549. }
  1550. },
  1551. '<a><a />',
  1552. {
  1553. content: '<a>{"str";}</a>',
  1554. explanation: "Improved error message",
  1555. expected_differences: {
  1556. 'root.errors.0.message': {
  1557. type: 'Wrong error message',
  1558. expected: 'Unexpected token ;',
  1559. actual: 'Unexpected token `;`, expected the token `}`'
  1560. }
  1561. }
  1562. },
  1563. {
  1564. content: '<span className="a", id="b" />',
  1565. explanation: "Improved error message",
  1566. expected_differences: {
  1567. 'root.errors.0.message': {
  1568. type: 'Wrong error message',
  1569. expected: 'Unexpected token ,',
  1570. actual: 'Unexpected token `,`, expected an identifier'
  1571. }
  1572. }
  1573. },
  1574. {
  1575. content: '<div className"app">',
  1576. explanation: "Improved error message",
  1577. expected_differences: {
  1578. 'root.errors.0.message': {
  1579. type: 'Wrong error message',
  1580. expected: 'Unexpected string',
  1581. actual: 'Unexpected string, expected an identifier'
  1582. }
  1583. }
  1584. },
  1585. {
  1586. content: '<div {props} />',
  1587. explanation: "Improved error message",
  1588. expected_differences: {
  1589. 'root.errors.0.message': {
  1590. type: 'Wrong error message',
  1591. expected: 'Unexpected identifier',
  1592. actual: 'Unexpected identifier, expected the token `...`'
  1593. }
  1594. }
  1595. },
  1596. {
  1597. content: '<div>stuff</div {...props}>',
  1598. explanation: "Improved error message",
  1599. expected_differences: {
  1600. 'root.errors.0.message': {
  1601. type: 'Wrong error message',
  1602. expected: 'Unexpected token {',
  1603. actual: 'Unexpected token `{`, expected the token `>`'
  1604. }
  1605. }
  1606. },
  1607. {
  1608. content: '<div {...props}>stuff</div {...props}>',
  1609. explanation: "Improved error message",
  1610. expected_differences: {
  1611. 'root.errors.0.message': {
  1612. type: 'Wrong error message',
  1613. expected: 'Unexpected token {',
  1614. actual: 'Unexpected token `{`, expected the token `>`'
  1615. }
  1616. }
  1617. },
  1618. '<div><a/><b/><c/>',
  1619. ],
  1620. 'ES6 Unicode Code Point Escape Sequence': [
  1621. '"\\u{714E}\\u{8336}"',
  1622. '"\\u{20BB7}\\u{91CE}\\u{5BB6}"'
  1623. ],
  1624. // ECMAScript 6th Syntax, 11.1. 9 Template Literals
  1625. 'ES6 Template Strings': [
  1626. '`Hello\rworld`',
  1627. '`foo ${\n "bar"\n} baz`',
  1628. '`foo ${/* a */ "bar" /* b */} baz`',
  1629. '( foo)`bar`',
  1630. '[...a.b`hi`.c`bye`]',
  1631. 'foo`foo`.bar`bar`.baz',
  1632. 'foo`bar``baz`',
  1633. 'foo`foo`()',
  1634. ],
  1635. // ECMAScript 6th Syntax, 13.2 Arrow Function Definitions
  1636. 'ES6: Arrow Function': [
  1637. '([a, , b]) => 42',
  1638. {
  1639. content: '([a.a]) => 42',
  1640. explanation: 'Flow fails to parse it correctly',
  1641. expected_differences: {
  1642. 'root.errors.0.column': {
  1643. type: 'Wrong error column',
  1644. expected: 7,
  1645. actual: '8-10'
  1646. },
  1647. 'root.errors.0.message': {
  1648. type: 'Wrong error message',
  1649. expected: 'Invalid left-hand side in formals list',
  1650. actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)',
  1651. }
  1652. },
  1653. },
  1654. // I don't see why this should be an error. 14.2.9
  1655. {
  1656. content: '(a, a) => 42',
  1657. explanation: "Esprima counts parens in its loc, Flow doesn't",
  1658. expected_differences: {
  1659. 'root.errors': {
  1660. type: 'Flow found no error',
  1661. expected: 'Line 1: Strict mode function may not have duplicate parameter names',
  1662. actual: undefined
  1663. },
  1664. }
  1665. },
  1666. '([...a]) => 42',
  1667. '({...a}) => 42',
  1668. ],
  1669. // http://wiki.ecmascript.org/doku.php?id=harmony:destructuring
  1670. 'Harmony: Destructuring': [
  1671. '[a, b] = [b, a]',
  1672. '({ responseText: text }) = res',
  1673. 'const {a} = {}',
  1674. 'const [a] = []',
  1675. 'let {a} = {}',
  1676. 'let [a] = []',
  1677. 'var {a} = {}',
  1678. 'var [a] = []',
  1679. 'const {a:b} = {}',
  1680. 'let {a:b} = {}',
  1681. 'var {a:b} = {}',
  1682. 'var f = function({node, guestStatus}) {}',
  1683. ],
  1684. // http://wiki.ecmascript.org/doku.php?id=strawman:maximally_minimal_classes
  1685. 'Harmony: Class (strawman)': [
  1686. 'var A = class extends B {}',
  1687. 'class type {}',
  1688. 'class A extends class B extends C {} {}',
  1689. {
  1690. content: 'class A {get() {}}',
  1691. explanation: "Esprima-fb doesn't include params in " +
  1692. "FunctionExpression location",
  1693. expected_differences: {
  1694. 'root.body.0.body.body.0.value.range.0': {
  1695. type: 'Wrong number',
  1696. expected: 15,
  1697. actual: 12,
  1698. },
  1699. 'root.body.0.body.body.0.value.loc.start.column': {
  1700. type: 'Wrong number',
  1701. expected: 15,
  1702. actual: 12,
  1703. },
  1704. },
  1705. },
  1706. {
  1707. content: 'class A { static get() {}}',
  1708. explanation: "Esprima-fb doesn't include params in " +
  1709. "FunctionExpression location",
  1710. expected_differences: {
  1711. 'root.body.0.body.body.0.value.range.0': {
  1712. type: 'Wrong number',
  1713. expected: 23,
  1714. actual: 20,
  1715. },
  1716. 'root.body.0.body.body.0.value.loc.start.column': {
  1717. type: 'Wrong number',
  1718. expected: 23,
  1719. actual: 20,
  1720. },
  1721. },
  1722. },
  1723. {
  1724. content: 'class A extends B {get foo() {}}',
  1725. explanation: "Esprima-fb doesn't include params in " +
  1726. "FunctionExpression location",
  1727. expected_differences: {
  1728. 'root.body.0.body.body.0.value.range.0': {
  1729. type: 'Wrong number',
  1730. expected: 29,
  1731. actual: 26,
  1732. },
  1733. 'root.body.0.body.body.0.value.loc.start.column': {
  1734. type: 'Wrong number',
  1735. expected: 29,
  1736. actual: 26,
  1737. },
  1738. },
  1739. },
  1740. {
  1741. content: 'class A extends B { static get foo() {}}',
  1742. explanation: "Esprima-fb doesn't include params in " +
  1743. "FunctionExpression location",
  1744. expected_differences: {
  1745. 'root.body.0.body.body.0.value.range.0': {
  1746. type: 'Wrong number',
  1747. expected: 37,
  1748. actual: 34,
  1749. },
  1750. 'root.body.0.body.body.0.value.loc.start.column': {
  1751. type: 'Wrong number',
  1752. expected: 37,
  1753. actual: 34,
  1754. },
  1755. },
  1756. },
  1757. {
  1758. content: 'class A {set a(v) {}}',
  1759. explanation: "Esprima-fb doesn't include params in " +
  1760. "FunctionExpression location",
  1761. expected_differences: {
  1762. 'root.body.0.body.body.0.value.range.0': {
  1763. type: 'Wrong number',
  1764. expected: 18,
  1765. actual: 14,
  1766. },
  1767. 'root.body.0.body.body.0.value.loc.start.column': {
  1768. type: 'Wrong number',
  1769. expected: 18,
  1770. actual: 14,
  1771. },
  1772. },
  1773. },
  1774. {
  1775. content: 'class A { static set a(v) {}}',
  1776. explanation: "Esprima-fb doesn't include params in " +
  1777. "FunctionExpression location",
  1778. expected_differences: {
  1779. 'root.body.0.body.body.0.value.range.0': {
  1780. type: 'Wrong number',
  1781. expected: 26,
  1782. actual: 22,
  1783. },
  1784. 'root.body.0.body.body.0.value.loc.start.column': {
  1785. type: 'Wrong number',
  1786. expected: 26,
  1787. actual: 22,
  1788. },
  1789. },
  1790. },
  1791. {
  1792. content: 'class A {set(v) {};}',
  1793. explanation: "Esprima-fb doesn't include params in " +
  1794. "FunctionExpression location",
  1795. expected_differences: {
  1796. 'root.body.0.body.body.0.value.range.0': {
  1797. type: 'Wrong number',
  1798. expected: 16,
  1799. actual: 12,
  1800. },
  1801. 'root.body.0.body.body.0.value.loc.start.column': {
  1802. type: 'Wrong number',
  1803. expected: 16,
  1804. actual: 12,
  1805. },
  1806. },
  1807. },
  1808. {
  1809. content: 'class A { static set(v) {};}',
  1810. explanation: "Esprima-fb doesn't include params in " +
  1811. "FunctionExpression location",
  1812. expected_differences: {
  1813. 'root.body.0.body.body.0.value.range.0': {
  1814. type: 'Wrong number',
  1815. expected: 24,
  1816. actual: 20,
  1817. },
  1818. 'root.body.0.body.body.0.value.loc.start.column': {
  1819. type: 'Wrong number',
  1820. expected: 24,
  1821. actual: 20,
  1822. },
  1823. },
  1824. },
  1825. {
  1826. content: 'class A {*gen(v) { yield v; }}',
  1827. explanation: "Esprima-fb doesn't include params in " +
  1828. "FunctionExpression location",
  1829. expected_differences: {
  1830. 'root.body.0.body.body.0.value.range.0': {
  1831. type: 'Wrong number',
  1832. expected: 17,
  1833. actual: 13,
  1834. },
  1835. 'root.body.0.body.body.0.value.loc.start.column': {
  1836. type: 'Wrong number',
  1837. expected: 17,
  1838. actual: 13,
  1839. },
  1840. },
  1841. },
  1842. {
  1843. content: 'class A { static *gen(v) { yield v; }}',
  1844. explanation: "Esprima-fb doesn't include params in " +
  1845. "FunctionExpression location",
  1846. expected_differences: {
  1847. 'root.body.0.body.body.0.value.range.0': {
  1848. type: 'Wrong number',
  1849. expected: 25,
  1850. actual: 21,
  1851. },
  1852. 'root.body.0.body.body.0.value.loc.start.column': {
  1853. type: 'Wrong number',
  1854. expected: 25,
  1855. actual: 21,
  1856. },
  1857. },
  1858. },
  1859. {
  1860. content: '"use strict"; (class A {constructor() { super() }})',
  1861. explanation: "Esprima counts the implicit semicolon in its loc, " +
  1862. "Flow doesn't. Esprima-fb also doesn't include params in " +
  1863. "FunctionExpression location. It also mishandles `super`",
  1864. expected_differences: {
  1865. 'root.body.1.expression.body.body.0.value.body.body.0.loc.end.column': {
  1866. type: 'Wrong number',
  1867. expected: 48,
  1868. actual: 47
  1869. },
  1870. 'root.body.1.expression.body.body.0.value.body.body.0.range.1': {
  1871. type: 'Wrong number',
  1872. expected: 48,
  1873. actual: 47
  1874. },
  1875. 'root.body.1.expression.body.body.0.value.range.0': {
  1876. type: 'Wrong number',
  1877. expected: 38,
  1878. actual: 35,
  1879. },
  1880. 'root.body.1.expression.body.body.0.value.loc.start.column': {
  1881. type: 'Wrong number',
  1882. expected: 38,
  1883. actual: 35,
  1884. },
  1885. 'root.body.1.expression.body.body.0.value.body.body.0.expression.callee.type': {
  1886. type: 'Wrong string',
  1887. expected: 'Identifier',
  1888. actual: 'Super',
  1889. },
  1890. 'root.body.1.expression.body.body.0.value.body.body.0.expression.callee.name': {
  1891. type: 'Missing property'
  1892. },
  1893. 'root.body.1.expression.body.body.0.value.body.body.0.expression.callee.typeAnnotation': {
  1894. type: 'Missing property'
  1895. },
  1896. 'root.body.1.expression.body.body.0.value.body.body.0.expression.callee.optional': {
  1897. type: 'Missing property'
  1898. },
  1899. }
  1900. },
  1901. {
  1902. content: 'class A {static foo() {}}',
  1903. explanation: "Esprima-fb doesn't include params in " +
  1904. "FunctionExpression location",
  1905. expected_differences: {
  1906. 'root.body.0.body.body.0.value.range.0': {
  1907. type: 'Wrong number',
  1908. expected: 22,
  1909. actual: 19,
  1910. },
  1911. 'root.body.0.body.body.0.value.loc.start.column': {
  1912. type: 'Wrong number',
  1913. expected: 22,
  1914. actual: 19,
  1915. },
  1916. },
  1917. },
  1918. {
  1919. content: 'class A {foo() {} static bar() {}}',
  1920. explanation: "Esprima-fb doesn't include params in " +
  1921. "FunctionExpression location",
  1922. expected_differences: {
  1923. 'root.body.0.body.body.0.value.range.0': {
  1924. type: 'Wrong number',
  1925. expected: 15,
  1926. actual: 12,
  1927. },
  1928. 'root.body.0.body.body.0.value.loc.start.column': {
  1929. type: 'Wrong number',
  1930. expected: 15,
  1931. actual: 12,
  1932. },
  1933. 'root.body.0.body.body.1.value.range.0': {
  1934. type: 'Wrong number',
  1935. expected: 31,
  1936. actual: 28,
  1937. },
  1938. 'root.body.0.body.body.1.value.loc.start.column': {
  1939. type: 'Wrong number',
  1940. expected: 31,
  1941. actual: 28,
  1942. },
  1943. },
  1944. },
  1945. {
  1946. content: 'class A { foo() {} bar() {}}',
  1947. explanation: "Esprima-fb doesn't include params in " +
  1948. "FunctionExpression location",
  1949. expected_differences: {
  1950. 'root.body.0.body.body.0.value.range.0': {
  1951. type: 'Wrong number',
  1952. expected: 16,
  1953. actual: 13,
  1954. },
  1955. 'root.body.0.body.body.0.value.loc.start.column': {
  1956. type: 'Wrong number',
  1957. expected: 16,
  1958. actual: 13,
  1959. },
  1960. 'root.body.0.body.body.1.value.range.0': {
  1961. type: 'Wrong number',
  1962. expected: 25,
  1963. actual: 22,
  1964. },
  1965. 'root.body.0.body.body.1.value.loc.start.column': {
  1966. type: 'Wrong number',
  1967. expected: 25,
  1968. actual: 22,
  1969. },
  1970. },
  1971. },
  1972. {
  1973. content: 'class A { get foo() {} set foo(v) {}}',
  1974. explanation: "Esprima-fb doesn't include params in " +
  1975. "FunctionExpression location",
  1976. expected_differences: {
  1977. 'root.body.0.body.body.0.value.range.0': {
  1978. type: 'Wrong number',
  1979. expected: 20,
  1980. actual: 17,
  1981. },
  1982. 'root.body.0.body.body.0.value.loc.start.column': {
  1983. type: 'Wrong number',
  1984. expected: 20,
  1985. actual: 17,
  1986. },
  1987. 'root.body.0.body.body.1.value.range.0': {
  1988. type: 'Wrong number',
  1989. expected: 34,
  1990. actual: 30,
  1991. },
  1992. 'root.body.0.body.body.1.value.loc.start.column': {
  1993. type: 'Wrong number',
  1994. expected: 34,
  1995. actual: 30,
  1996. },
  1997. },
  1998. },
  1999. {
  2000. content: 'class A { static get foo() {} get foo() {}}',
  2001. explanation: "Esprima-fb doesn't include params in " +
  2002. "FunctionExpression location",
  2003. expected_differences: {
  2004. 'root.body.0.body.body.0.value.range.0': {
  2005. type: 'Wrong number',
  2006. expected: 27,
  2007. actual: 24,
  2008. },
  2009. 'root.body.0.body.body.0.value.loc.start.column': {
  2010. type: 'Wrong number',
  2011. expected: 27,
  2012. actual: 24,
  2013. },
  2014. 'root.body.0.body.body.1.value.range.0': {
  2015. type: 'Wrong number',
  2016. expected: 40,
  2017. actual: 37,
  2018. },
  2019. 'root.body.0.body.body.1.value.loc.start.column': {
  2020. type: 'Wrong number',
  2021. expected: 40,
  2022. actual: 37,
  2023. },
  2024. },
  2025. },
  2026. {
  2027. content: 'class A { static get foo() {} static get bar() {} }',
  2028. explanation: "Esprima-fb doesn't include params in " +
  2029. "FunctionExpression location",
  2030. expected_differences: {
  2031. 'root.body.0.body.body.0.value.range.0': {
  2032. type: 'Wrong number',
  2033. expected: 27,
  2034. actual: 24,
  2035. },
  2036. 'root.body.0.body.body.0.value.loc.start.column': {
  2037. type: 'Wrong number',
  2038. expected: 27,
  2039. actual: 24,
  2040. },
  2041. 'root.body.0.body.body.1.value.range.0': {
  2042. type: 'Wrong number',
  2043. expected: 47,
  2044. actual: 44,
  2045. },
  2046. 'root.body.0.body.body.1.value.loc.start.column': {
  2047. type: 'Wrong number',
  2048. expected: 47,
  2049. actual: 44,
  2050. },
  2051. },
  2052. },
  2053. {
  2054. content: 'class A { static get foo() {} static set foo(v) {} get foo() {} set foo(v) {}}',
  2055. explanation: "Esprima-fb doesn't include params in " +
  2056. "FunctionExpression location",
  2057. expected_differences: {
  2058. 'root.body.0.body.body.0.value.range.0': {
  2059. type: 'Wrong number',
  2060. expected: 27,
  2061. actual: 24,
  2062. },
  2063. 'root.body.0.body.body.0.value.loc.start.column': {
  2064. type: 'Wrong number',
  2065. expected: 27,
  2066. actual: 24,
  2067. },
  2068. 'root.body.0.body.body.1.value.range.0': {
  2069. type: 'Wrong number',
  2070. expected: 48,
  2071. actual: 44,
  2072. },
  2073. 'root.body.0.body.body.1.value.loc.start.column': {
  2074. type: 'Wrong number',
  2075. expected: 48,
  2076. actual: 44,
  2077. },
  2078. 'root.body.0.body.body.2.value.range.0': {
  2079. type: 'Wrong number',
  2080. expected: 61,
  2081. actual: 58,
  2082. },
  2083. 'root.body.0.body.body.2.value.loc.start.column': {
  2084. type: 'Wrong number',
  2085. expected: 61,
  2086. actual: 58,
  2087. },
  2088. 'root.body.0.body.body.3.value.range.0': {
  2089. type: 'Wrong number',
  2090. expected: 75,
  2091. actual: 71,
  2092. },
  2093. 'root.body.0.body.body.3.value.loc.start.column': {
  2094. type: 'Wrong number',
  2095. expected: 75,
  2096. actual: 71,
  2097. },
  2098. },
  2099. },
  2100. {
  2101. content: 'class A { set foo(v) {} get foo() {} }',
  2102. explanation: "Esprima-fb doesn't include params in " +
  2103. "FunctionExpression location",
  2104. expected_differences: {
  2105. 'root.body.0.body.body.0.value.range.0': {
  2106. type: 'Wrong number',
  2107. expected: 21,
  2108. actual: 17,
  2109. },
  2110. 'root.body.0.body.body.0.value.loc.start.column': {
  2111. type: 'Wrong number',
  2112. expected: 21,
  2113. actual: 17,
  2114. },
  2115. 'root.body.0.body.body.1.value.range.0': {
  2116. type: 'Wrong number',
  2117. expected: 34,
  2118. actual: 31,
  2119. },
  2120. 'root.body.0.body.body.1.value.loc.start.column': {
  2121. type: 'Wrong number',
  2122. expected: 34,
  2123. actual: 31,
  2124. },
  2125. },
  2126. },
  2127. {
  2128. content: 'class A { [x]() {} }',
  2129. explanation: "Esprima-fb doesn't include params in " +
  2130. "FunctionExpression location",
  2131. expected_differences: {
  2132. 'root.body.0.body.body.0.value.range.0': {
  2133. type: 'Wrong number',
  2134. expected: 16,
  2135. actual: 13,
  2136. },
  2137. 'root.body.0.body.body.0.value.loc.start.column': {
  2138. type: 'Wrong number',
  2139. expected: 16,
  2140. actual: 13,
  2141. },
  2142. },
  2143. },
  2144. {
  2145. content: 'class A { [1+1]() {} }',
  2146. explanation: "Esprima-fb doesn't include params in " +
  2147. "FunctionExpression location",
  2148. expected_differences: {
  2149. 'root.body.0.body.body.0.value.range.0': {
  2150. type: 'Wrong number',
  2151. expected: 18,
  2152. actual: 15,
  2153. },
  2154. 'root.body.0.body.body.0.value.loc.start.column': {
  2155. type: 'Wrong number',
  2156. expected: 18,
  2157. actual: 15,
  2158. },
  2159. },
  2160. },
  2161. {
  2162. content: 'class A { get [1+1]() {} }',
  2163. explanation: "Esprima-fb doesn't include params in " +
  2164. "FunctionExpression location",
  2165. expected_differences: {
  2166. 'root.body.0.body.body.0.value.range.0': {
  2167. type: 'Wrong number',
  2168. expected: 22,
  2169. actual: 19,
  2170. },
  2171. 'root.body.0.body.body.0.value.loc.start.column': {
  2172. type: 'Wrong number',
  2173. expected: 22,
  2174. actual: 19,
  2175. },
  2176. },
  2177. },
  2178. {
  2179. content: 'class A { static get [1+1]() {} }',
  2180. explanation: "Esprima-fb doesn't include params in " +
  2181. "FunctionExpression location",
  2182. expected_differences: {
  2183. 'root.body.0.body.body.0.value.range.0': {
  2184. type: 'Wrong number',
  2185. expected: 29,
  2186. actual: 26,
  2187. },
  2188. 'root.body.0.body.body.0.value.loc.start.column': {
  2189. type: 'Wrong number',
  2190. expected: 29,
  2191. actual: 26,
  2192. },
  2193. },
  2194. },
  2195. {
  2196. content: 'class A { static() {} }',
  2197. explanation: 'Our version of esprima is outdated',
  2198. expected_differences: {
  2199. 'root.errors': {
  2200. type: 'Flow found no error',
  2201. expected: 'Line 1: Unexpected token )',
  2202. actual: undefined,
  2203. },
  2204. },
  2205. },
  2206. {
  2207. content: 'class A { static static() {} }',
  2208. explanation: "Esprima-fb doesn't include params in " +
  2209. "FunctionExpression location",
  2210. expected_differences: {
  2211. 'root.body.0.body.body.0.value.range.0': {
  2212. type: 'Wrong number',
  2213. expected: 26,
  2214. actual: 23,
  2215. },
  2216. 'root.body.0.body.body.0.value.loc.start.column': {
  2217. type: 'Wrong number',
  2218. expected: 26,
  2219. actual: 23,
  2220. },
  2221. },
  2222. },
  2223. ],
  2224. 'ES6: Computed Properties': [
  2225. '({[x]: 10})',
  2226. '({["x" + "y"]: 10})',
  2227. '({[x]: function() {}})',
  2228. '({[x]: 10, y: 20})',
  2229. {
  2230. content: '({get [x]() {}, set [x](v) {}})',
  2231. explanation: "Esprima-fb doesn't include params in " +
  2232. "FunctionExpression location",
  2233. expected_differences: {
  2234. 'root.body.0.expression.properties.0.value.range.0': {
  2235. type: 'Wrong number',
  2236. expected: 12,
  2237. actual: 9,
  2238. },
  2239. 'root.body.0.expression.properties.0.value.loc.start.column': {
  2240. type: 'Wrong number',
  2241. expected: 12,
  2242. actual: 9,
  2243. },
  2244. 'root.body.0.expression.properties.1.value.range.0': {
  2245. type: 'Wrong number',
  2246. expected: 27,
  2247. actual: 23,
  2248. },
  2249. 'root.body.0.expression.properties.1.value.loc.start.column': {
  2250. type: 'Wrong number',
  2251. expected: 27,
  2252. actual: 23,
  2253. },
  2254. },
  2255. },
  2256. {
  2257. content: '({[x]() {}})',
  2258. explanation: "Esprima-fb doesn't include params in " +
  2259. "FunctionExpression location",
  2260. expected_differences: {
  2261. 'root.body.0.expression.properties.0.value.range.0': {
  2262. type: 'Wrong number',
  2263. expected: 8,
  2264. actual: 5,
  2265. },
  2266. 'root.body.0.expression.properties.0.value.loc.start.column': {
  2267. type: 'Wrong number',
  2268. expected: 8,
  2269. actual: 5,
  2270. },
  2271. },
  2272. },
  2273. // These tests fail due to computed Properties
  2274. // 'var {[x]: y} = {y}',
  2275. // 'function f({[x]: y}) {}',
  2276. {
  2277. content: 'var x = {*[test]() { yield *v; }}',
  2278. explanation: "Esprima-fb doesn't include params in " +
  2279. "FunctionExpression location",
  2280. expected_differences: {
  2281. 'root.body.0.declarations.0.init.properties.0.value.range.0': {
  2282. type: 'Wrong number',
  2283. expected: 19,
  2284. actual: 16,
  2285. },
  2286. 'root.body.0.declarations.0.init.properties.0.value.loc.start.column': {
  2287. type: 'Wrong number',
  2288. expected: 19,
  2289. actual: 16,
  2290. },
  2291. },
  2292. },
  2293. ],
  2294. 'ES6: Default parameters': [
  2295. 'function f([x] = [1]) {}',
  2296. 'function f({x} = {x: 10}) {}',
  2297. 'f = function({x} = {x: 10}) {}',
  2298. '({f: function({x} = {x: 10}) {}})',
  2299. {
  2300. content: '({f({x} = {x: 10}) {}})',
  2301. explanation: "Esprima-fb doesn't include params in " +
  2302. "FunctionExpression location",
  2303. expected_differences: {
  2304. 'root.body.0.expression.properties.0.value.range.0': {
  2305. type: 'Wrong number',
  2306. expected: 19,
  2307. actual: 3,
  2308. },
  2309. 'root.body.0.expression.properties.0.value.loc.start.column': {
  2310. type: 'Wrong number',
  2311. expected: 19,
  2312. actual: 3,
  2313. },
  2314. },
  2315. },
  2316. {
  2317. content: '(class {f({x} = {x: 10}) {}})',
  2318. explanation: "Esprima-fb doesn't include params in " +
  2319. "FunctionExpression location",
  2320. expected_differences: {
  2321. 'root.body.0.expression.body.body.0.value.range.0': {
  2322. type: 'Wrong number',
  2323. expected: 25,
  2324. actual: 9,
  2325. },
  2326. 'root.body.0.expression.body.body.0.value.loc.start.column': {
  2327. type: 'Wrong number',
  2328. expected: 25,
  2329. actual: 9,
  2330. },
  2331. },
  2332. },
  2333. '(({x} = {x: 10}) => {})',
  2334. {
  2335. content: 'x = { f(a=1) {} }',
  2336. explanation: "Esprima-fb doesn't include params in " +
  2337. "FunctionExpression location",
  2338. expected_differences: {
  2339. 'root.body.0.expression.right.properties.0.value.range.0': {
  2340. type: 'Wrong number',
  2341. expected: 13,
  2342. actual: 7,
  2343. },
  2344. 'root.body.0.expression.right.properties.0.value.loc.start.column': {
  2345. type: 'Wrong number',
  2346. expected: 13,
  2347. actual: 7,
  2348. },
  2349. },
  2350. },
  2351. ],
  2352. 'ES6: Destructured Parameters': [
  2353. 'function x([ a, b ]){}',
  2354. 'function x({ a, b }){}',
  2355. '"use strict"; function x({ a }){ "use strict"; }',
  2356. 'function x(a, { a }){}',
  2357. 'function x(...[ a, b ]){}',
  2358. 'function x({ a: { w, x }, b: [y, z] }, ...[a, b, c]){}',
  2359. '(function x([ a, b ]){})',
  2360. '(function x({ a, b }){})',
  2361. '(function x(...[ a, b ]){})',
  2362. '(function x({ a: { w, x }, b: [y, z] }, ...[a, b, c]){})',
  2363. '({ x([ a, b ]){} })',
  2364. '({ x(...[ a, b ]){} })',
  2365. '({ x({ a: { w, x }, b: [y, z] }, ...[a, b, c]){} })',
  2366. '(...a) => {}',
  2367. '(a, ...b) => {}',
  2368. '({ a }) => {}',
  2369. '({ a }, ...b) => {}',
  2370. '(...[a, b]) => {}',
  2371. '(a, ...[b]) => {}',
  2372. '({ a: [a, b] }, ...c) => {}',
  2373. '({ a: b, c }, [d, e], ...f) => {}'
  2374. ],
  2375. 'ES6: SpreadElement': [
  2376. '[...a] = b',
  2377. '[a, ...b] = c',
  2378. '[{ a, b }, ...c] = d',
  2379. '[a, ...[b, c]] = d',
  2380. 'var [...a] = b',
  2381. 'var [a, ...b] = c',
  2382. 'var [{ a, b }, ...c] = d',
  2383. 'var [a, ...[b, c]] = d',
  2384. 'func(...a)',
  2385. 'func(a, ...b)',
  2386. 'new foo(...a)',
  2387. 'new foo(a, ...b)',
  2388. 'function foo(...a){}',
  2389. 'function foo(a, ...b){}',
  2390. {
  2391. content: 'function foo(a, ...a){}',
  2392. explanation: "esprima-fb doesn't catch this",
  2393. expected_differences: {
  2394. 'root.errors.0.message': {
  2395. type: 'Wrong error message',
  2396. expected: undefined,
  2397. actual: 'Strict mode function may not have duplicate parameter names',
  2398. },
  2399. 'root.errors.0.line': {
  2400. type: 'Wrong error line',
  2401. expected: undefined,
  2402. actual: 1,
  2403. },
  2404. 'root.errors.0.column': {
  2405. type: 'Wrong error column',
  2406. expected: undefined,
  2407. actual: 20,
  2408. },
  2409. }
  2410. }
  2411. ],
  2412. // https://gist.github.com/sebmarkbage/aa849c7973cb4452c547
  2413. 'ES7 Proposal: Spread Properties': [
  2414. 'let z = {...x}',
  2415. 'z = {x, ...y}',
  2416. '({x, ...y, a, ...b, c})',
  2417. ],
  2418. 'Harmony Invalid syntax': [
  2419. '"\\u{110000}"',
  2420. '[v] += ary',
  2421. '[2] = 42',
  2422. '({ obj:20 }) = 42',
  2423. '( { get x() {} } ) = 0',
  2424. 'x \n is y',
  2425. 'x \n isnt y',
  2426. 'function default() {}',
  2427. 'function hello() {\'use strict\'; ({ i: 10, s(eval) { } }); }',
  2428. 'function a() { "use strict"; ({ b(t, t) { } }); }',
  2429. 'var super',
  2430. 'var default',
  2431. 'let default',
  2432. 'const default',
  2433. '({ v: eval }) = obj',
  2434. '({ v: arguments }) = obj',
  2435. 'for (var i = function() { return 10 in [] } in list) process(x);',
  2436. 'for (let x = 42 in list) process(x);',
  2437. 'for (let x = 42 of list) process(x);',
  2438. 'module\n"crypto" {}',
  2439. 'module foo from bar',
  2440. 'module 42',
  2441. 'module foo bar',
  2442. 'module "crypto" { module "e" {} }',
  2443. 'module "x" { export * from foo }',
  2444. 'import foo',
  2445. 'import { foo, bar }',
  2446. 'import foo from bar',
  2447. '((a)) => 42',
  2448. '(a, (b)) => 42',
  2449. '"use strict"; (eval = 10) => 42',
  2450. // strict mode, using eval when IsSimpleParameterList is true
  2451. '"use strict"; eval => 42',
  2452. // strict mode, using arguments when IsSimpleParameterList is true
  2453. '"use strict"; arguments => 42',
  2454. // strict mode, using eval when IsSimpleParameterList is true
  2455. '"use strict"; (eval, a) => 42',
  2456. // strict mode, using arguments when IsSimpleParameterList is true
  2457. '"use strict"; (arguments, a) => 42',
  2458. // strict mode, using eval when IsSimpleParameterList is false
  2459. '"use strict"; (eval, a = 10) => 42',
  2460. '(a, a) => 42',
  2461. '"use strict"; (a, a) => 42',
  2462. '"use strict"; (a) => 00',
  2463. '() <= 42',
  2464. '(10) => 00',
  2465. '(10, 20) => 00',
  2466. 'yield v',
  2467. 'yield 10',
  2468. 'yield* 10',
  2469. 'e => yield* 10',
  2470. '(function () { yield* 10 })',
  2471. '(function() { "use strict"; f(yield v) })',
  2472. 'var obj = { *test** }',
  2473. 'class A extends yield B { }',
  2474. 'class default',
  2475. '`test',
  2476. 'switch `test`',
  2477. '`hello ${10 `test`',
  2478. '`hello ${10;test`',
  2479. 'function a() 1 // expression closure is not supported',
  2480. '[a,b if (a)] // (a,b)',
  2481. 'for each (let x in {}) {};',
  2482. '[x for (let x in [])]',
  2483. '[x for (const x in [])]',
  2484. '[x for (var x in [])]',
  2485. '[a,b for (a in [])] // (a,b) ',
  2486. '[x if (x)] // block required',
  2487. 'var a = [x if (x)]',
  2488. '[for (x in [])] // no espression',
  2489. '({ "chance" }) = obj',
  2490. '({ 42 }) = obj',
  2491. 'function f(a, ...b = 0)',
  2492. 'function x(...{ a }){}',
  2493. '"use strict"; function x(a, { a }){}',
  2494. '"use strict"; function x({ b: { a } }, [{ b: { a } }]){}',
  2495. '"use strict"; function x(a, ...[a]){}',
  2496. '(...a, b) => {}',
  2497. '([ 5 ]) => {}',
  2498. '({ 5 }) => {}',
  2499. '(...[ 5 ]) => {}',
  2500. '[...{ a }] = b',
  2501. '[...a, b] = c',
  2502. 'func(...a, b)',
  2503. 'let {...a, b} = x',
  2504. '(function({...a, b}) {})',
  2505. '({ t(eval) { "use strict"; } });',
  2506. '"use strict"; `${test}\\02`;',
  2507. '[...a, ] = b',
  2508. 'if (b,...a, );',
  2509. '(b, ...a)',
  2510. 'module "Universe" { ; ; ',
  2511. 'switch (cond) { case 10: let a = 20; ',
  2512. '"use strict"; (eval) => 42',
  2513. '(eval) => { "use strict"; 42 }',
  2514. '({ get test() { } }) => 42'
  2515. ],
  2516. 'Type Annotations': [
  2517. 'a = class Foo<T> { }',
  2518. 'a = class Foo<T> extends Bar<T> {}',
  2519. 'a=function<T,S>() {}',
  2520. {
  2521. content: 'a={set fooProp(value:number){}}',
  2522. explanation: "Esprima-fb doesn't include params in " +
  2523. "FunctionExpression location",
  2524. expected_differences: {
  2525. 'root.body.0.expression.right.properties.0.value.range.0': {
  2526. type: 'Wrong number',
  2527. expected: 28,
  2528. actual: 14,
  2529. },
  2530. 'root.body.0.expression.right.properties.0.value.loc.start.column': {
  2531. type: 'Wrong number',
  2532. expected: 28,
  2533. actual: 14,
  2534. },
  2535. },
  2536. },
  2537. {
  2538. content: 'class Array { concat(items:number | string) {}; }',
  2539. explanation: "Esprima-fb doesn't include params in " +
  2540. "FunctionExpression location",
  2541. expected_differences: {
  2542. 'root.body.0.body.body.0.value.range.0': {
  2543. type: 'Wrong number',
  2544. expected: 44,
  2545. actual: 20,
  2546. },
  2547. 'root.body.0.body.body.0.value.loc.start.column': {
  2548. type: 'Wrong number',
  2549. expected: 44,
  2550. actual: 20,
  2551. },
  2552. },
  2553. },
  2554. 'class Foo { [1 + 1]: string; }',
  2555. 'class Foo { 123:string; }',
  2556. {
  2557. content: 'class Foo { "bar"<T>() { } }',
  2558. explanation: "Esprima-fb doesn't include params in " +
  2559. "FunctionExpression location",
  2560. expected_differences: {
  2561. 'root.body.0.body.body.0.value.range.0': {
  2562. type: 'Wrong number',
  2563. expected: 23,
  2564. actual: 17,
  2565. },
  2566. 'root.body.0.body.body.0.value.loc.start.column': {
  2567. type: 'Wrong number',
  2568. expected: 23,
  2569. actual: 17,
  2570. },
  2571. },
  2572. },
  2573. 'class Foo { "prop1":string; }',
  2574. 'class Foo { [prop1]: string; }' ,
  2575. 'class Foo { prop1:string; prop2:number; }',
  2576. 'class Foo { static prop1:string; prop2:number; }',
  2577. {
  2578. content: 'class Foo {set fooProp(value:number){}}',
  2579. explanation: "Esprima-fb doesn't include params in " +
  2580. "FunctionExpression location",
  2581. expected_differences: {
  2582. 'root.body.0.body.body.0.value.range.0': {
  2583. type: 'Wrong number',
  2584. expected: 36,
  2585. actual: 22,
  2586. },
  2587. 'root.body.0.body.body.0.value.loc.start.column': {
  2588. type: 'Wrong number',
  2589. expected: 36,
  2590. actual: 22,
  2591. },
  2592. },
  2593. },
  2594. 'class Foo<T> {}',
  2595. {
  2596. content: 'class Foo<T> { bar<U>():number { return 42; }}',
  2597. explanation: "Esprima-fb doesn't include params in " +
  2598. "FunctionExpression location",
  2599. expected_differences: {
  2600. 'root.body.0.body.body.0.value.range.0': {
  2601. type: 'Wrong number',
  2602. expected: 31,
  2603. actual: 18,
  2604. },
  2605. 'root.body.0.body.body.0.value.loc.start.column': {
  2606. type: 'Wrong number',
  2607. expected: 31,
  2608. actual: 18,
  2609. },
  2610. },
  2611. },
  2612. 'class Foo<T> extends Bar<T> {}',
  2613. 'class Foo<T> extends mixin(Bar) {}',
  2614. 'function foo(): {} {}',
  2615. 'function foo():(_:bool) => number{}',
  2616. 'function foo():(_?:bool) => number{}',
  2617. 'function foo(callback: (_1:bool, _2:string) => number){}',
  2618. 'function foo(callback: (_:bool) => number){}',
  2619. 'function foo(callback: () => number){}',
  2620. 'function foo(callback: () => void){}',
  2621. 'function foo(nullableNum: ?number){}',
  2622. 'function foo():number{}',
  2623. 'function foo(numVal: any){}',
  2624. 'function foo(numVal: number){}',
  2625. 'function foo(numVal: number, strVal: string){}',
  2626. 'function foo(numVal: number, untypedVal){}',
  2627. 'function foo(numVal: number, x: number){}',
  2628. 'function foo(requiredParam, optParam?) {}',
  2629. 'function foo(requiredParam, optParam?=123) {}',
  2630. 'function foo<T>() {}',
  2631. 'function foo<T,S>() {}',
  2632. 'function foo(...typedRest: Array<number>){}',
  2633. 'function foo(untypedVal, numVal: number){}',
  2634. 'function foo():() => void{}',
  2635. 'function foo([x]: Array<string>) {}',
  2636. 'var a:Array<number> = [1, 2, 3]',
  2637. 'var a:(...rest:Array<number>) => number',
  2638. 'var bar: (str:number, i:number)=> string = foo;',
  2639. 'var numVal:number;',
  2640. 'var numVal:number = otherNumVal;',
  2641. 'var [x]: Array<string> = [ "hello" ];',
  2642. 'var x : number | string = 4;',
  2643. 'var x : number & string = 4;',
  2644. 'var x : () => number | () => string = fn;',
  2645. 'var x : () => number & () => string = fn;',
  2646. 'var x: typeof Y | number = Y;',
  2647. 'var x: typeof Y & number = Y;',
  2648. 'var x: typeof Y = Y;',
  2649. ],
  2650. 'Tuples': [ /* TODO */ ],
  2651. 'Type Aliases': [
  2652. 'type FBID = number;',
  2653. 'type FBID = number',
  2654. 'type Arr<T> = Array<T>;',
  2655. ],
  2656. 'Interfaces': [
  2657. 'interface A {}',
  2658. 'interface A<T, S> {}',
  2659. 'interface A extends B {}',
  2660. 'interface A extends B, C {}',
  2661. 'interface A<T> extends B<T> {}',
  2662. 'class Foo implements Bar {}',
  2663. 'class Foo extends Bar implements Bat, Man<number> {}',
  2664. 'class Foo extends class Bar implements Bat {} {}',
  2665. 'class Foo extends class Bar implements Bat {} implements Man {}',
  2666. ],
  2667. 'Array Types': [
  2668. 'var x: number[];',
  2669. 'var x: ?number[];',
  2670. {
  2671. content: 'var x: (?number)[];',
  2672. explanation: 'Flow does not count parens in its locs',
  2673. expected_differences: {
  2674. 'root.body.0.declarations.0.id.typeAnnotation.typeAnnotation.loc.start.column': {
  2675. type: 'Wrong number',
  2676. expected: 7,
  2677. actual: 8,
  2678. },
  2679. 'root.body.0.declarations.0.id.typeAnnotation.typeAnnotation.range.0': {
  2680. type: 'Wrong number',
  2681. expected: 7,
  2682. actual: 8,
  2683. }
  2684. }
  2685. },
  2686. 'var x: () => number[];',
  2687. {
  2688. content: 'var x: (() => number)[];',
  2689. explanation: 'Flow does not count parens in its locs',
  2690. expected_differences: {
  2691. 'root.body.0.declarations.0.id.typeAnnotation.typeAnnotation.loc.start.column': {
  2692. type: 'Wrong number',
  2693. expected: 7,
  2694. actual: 8,
  2695. },
  2696. 'root.body.0.declarations.0.id.typeAnnotation.typeAnnotation.range.0': {
  2697. type: 'Wrong number',
  2698. expected: 7,
  2699. actual: 8,
  2700. }
  2701. }
  2702. },
  2703. 'var x: typeof A[];',
  2704. ],
  2705. 'Export': {
  2706. 'options': { sourceType: "module" },
  2707. 'tests': [
  2708. {
  2709. content: 'export var x, y',
  2710. explanation: 'esprima-fb is outdated',
  2711. expected_differences: {
  2712. 'root.body.0.type': {
  2713. type: 'Wrong string',
  2714. expected: 'ExportDeclaration',
  2715. actual: 'ExportNamedDeclaration',
  2716. },
  2717. 'root.body.0.default': {
  2718. type: 'Missing property',
  2719. },
  2720. },
  2721. },
  2722. {
  2723. content: 'export let x, y',
  2724. explanation: 'esprima-fb is outdated',
  2725. expected_differences: {
  2726. 'root.body.0.type': {
  2727. type: 'Wrong string',
  2728. expected: 'ExportDeclaration',
  2729. actual: 'ExportNamedDeclaration',
  2730. },
  2731. 'root.body.0.default': {
  2732. type: 'Missing property',
  2733. },
  2734. },
  2735. },
  2736. 'export const x, y',
  2737. {
  2738. content: 'export class A {}',
  2739. explanation: 'esprima-fb is outdated',
  2740. expected_differences: {
  2741. 'root.body.0.type': {
  2742. type: 'Wrong string',
  2743. expected: 'ExportDeclaration',
  2744. actual: 'ExportNamedDeclaration',
  2745. },
  2746. 'root.body.0.default': {
  2747. type: 'Missing property',
  2748. },
  2749. },
  2750. },
  2751. {
  2752. content: 'export default 1 + 1;',
  2753. explanation: 'esprima-fb is outdated',
  2754. expected_differences: {
  2755. 'root.body.0.type': {
  2756. type: 'Wrong string',
  2757. expected: 'ExportDeclaration',
  2758. actual: 'ExportDefaultDeclaration',
  2759. },
  2760. 'root.body.0.default': {
  2761. type: 'Missing property',
  2762. },
  2763. 'root.body.0.specifiers': {
  2764. type: 'Missing property',
  2765. },
  2766. 'root.body.0.source': {
  2767. type: 'Missing property',
  2768. },
  2769. },
  2770. },
  2771. {
  2772. content: 'export default 1 + 1',
  2773. explanation: 'esprima-fb is outdated',
  2774. expected_differences: {
  2775. 'root.body.0.type': {
  2776. type: 'Wrong string',
  2777. expected: 'ExportDeclaration',
  2778. actual: 'ExportDefaultDeclaration',
  2779. },
  2780. 'root.body.0.default': {
  2781. type: 'Missing property',
  2782. },
  2783. 'root.body.0.specifiers': {
  2784. type: 'Missing property',
  2785. },
  2786. 'root.body.0.source': {
  2787. type: 'Missing property',
  2788. },
  2789. },
  2790. },
  2791. /* Esprima parses default exports wrong
  2792. 'export default function foo() {}',
  2793. 'export default function *foo() {}',
  2794. 'export default class {};',
  2795. 'export default class A {};',
  2796. */
  2797. ]
  2798. },
  2799. 'Invalid Exports': {
  2800. 'options': { sourceType: "module" },
  2801. 'tests': [
  2802. /* Esprima doesn't parse nameless exported classes yet
  2803. 'export class {}',
  2804. */
  2805. {
  2806. content: 'export function {}',
  2807. explanation: "Improved error message",
  2808. expected_differences: {
  2809. 'root.errors.0.message': {
  2810. type: 'Wrong error message',
  2811. expected: 'Unexpected token {',
  2812. actual: 'Unexpected token `{`, expected an identifier'
  2813. }
  2814. }
  2815. },
  2816. /* Esprima parses default exports wrong
  2817. 'export default class A {}',
  2818. */
  2819. ],
  2820. },
  2821. 'Import': {
  2822. 'options': { sourceType: "module" },
  2823. 'tests': [
  2824. 'import defaultbinding, {} from "MyModule";',
  2825. /* TODO Esprima should support these
  2826. 'import defaultbinding, {x,} from "MyModule";',
  2827. */
  2828. 'import defaultbinding, {x,y} from "MyModule";',
  2829. 'import defaultbinding, {x as z} from "MyModule";',
  2830. 'import defaultbinding, {x, y as z} from "MyModule";',
  2831. // These aren't import types
  2832. 'import type from "MyModule"',
  2833. 'import type, {} from "MyModule"',
  2834. 'import type, * as namespace from "MyModule"',
  2835. 'import {type} from "MyModule"',
  2836. 'import {type as type} from "MyModule"',
  2837. // Other pseudo keywords
  2838. 'import of from "MyModule"',
  2839. 'import {of} from "MyModule"',
  2840. 'import declare from "MyModule"',
  2841. 'import {declare} from "MyModule"',
  2842. 'import async from "MyModule"',
  2843. 'import {async} from "MyModule"',
  2844. 'import {of as of} from "MyModule"',
  2845. 'import {declare as declare} from "MyModule"',
  2846. 'import {async as async} from "MyModule"',
  2847. ],
  2848. },
  2849. 'Import Type': {
  2850. 'options': { sourceType: "module" },
  2851. 'tests': [
  2852. 'import type defaultbinding from "MyModule";',
  2853. /* TODO This is invalid; Esprima should also error
  2854. 'import type * as namespace from "MyModule";',
  2855. */
  2856. 'import type {} from "MyModule";',
  2857. 'import type defaultbinding, {} from "MyModule";',
  2858. /* TODO Esprima should support these
  2859. 'import type {x,} from "MyModule";',
  2860. 'import type defaultbinding, {x,} from "MyModule";',
  2861. */
  2862. 'import type {x} from "MyModule";',
  2863. 'import type {x,y} from "MyModule";',
  2864. 'import type {x as z} from "MyModule";',
  2865. 'import type {x, y as z} from "MyModule";',
  2866. 'import type defaultbinding, * as namespace from "MyModule";',
  2867. 'import type defaultbinding, {x} from "MyModule";',
  2868. 'import type defaultbinding, {x,y} from "MyModule";',
  2869. 'import type defaultbinding, {x as z} from "MyModule";',
  2870. 'import type defaultbinding, {x, y as z} from "MyModule";',
  2871. ],
  2872. },
  2873. 'Import Typeof': {
  2874. 'options': { sourceType: "module" },
  2875. 'tests': [
  2876. 'import typeof defaultbinding from "MyModule";',
  2877. 'import typeof {} from "MyModule";',
  2878. 'import typeof defaultbinding, {} from "MyModule";',
  2879. /* TODO Esprima should support these
  2880. 'import typeof {x,} from "MyModule";',
  2881. 'import typeof defaultbinding, {x,} from "MyModule";',
  2882. */
  2883. 'import typeof {x} from "MyModule";',
  2884. 'import typeof {x,y} from "MyModule";',
  2885. 'import typeof {x as z} from "MyModule";',
  2886. 'import typeof {x, y as z} from "MyModule";',
  2887. 'import typeof defaultbinding, {x} from "MyModule";',
  2888. 'import typeof defaultbinding, {x,y} from "MyModule";',
  2889. 'import typeof defaultbinding, {x as z} from "MyModule";',
  2890. 'import typeof defaultbinding, {x, y as z} from "MyModule";',
  2891. ],
  2892. },
  2893. 'Declare Statements': [
  2894. 'declare var foo',
  2895. 'declare var foo;',
  2896. 'declare var foo: number;',
  2897. 'declare function foo(): void',
  2898. 'declare function foo(): void;',
  2899. 'declare function foo<T>(): void;',
  2900. 'declare function foo(x: number, y: string): void;',
  2901. ],
  2902. 'Invalid Declare Statements': [
  2903. {
  2904. content: 'declare function foo();',
  2905. explanation: "Improved error message",
  2906. expected_differences: {
  2907. 'root.errors.0.message': {
  2908. type: 'Wrong error message',
  2909. expected: 'Unexpected token ;',
  2910. actual: 'Unexpected token `;`, expected the token `:`'
  2911. }
  2912. }
  2913. },
  2914. ],
  2915. 'Declare Module': [
  2916. 'declare module A {}',
  2917. 'declare module "./a/b.js" {}',
  2918. 'declare module A { declare var x: number; }',
  2919. 'declare module A { declare function foo(): number; }',
  2920. ],
  2921. 'Invalid Declare Module': [
  2922. {
  2923. content: 'declare Module A {}',
  2924. explanation: "Improved error message",
  2925. expected_differences: {
  2926. 'root.errors.0.message': {
  2927. type: 'Wrong error message',
  2928. expected: 'Unexpected identifier',
  2929. actual: 'Unexpected identifier, expected the end of an expression statement (`;`)'
  2930. }
  2931. }
  2932. },
  2933. {
  2934. content: 'declare module {}',
  2935. explanation: "Improved error message",
  2936. expected_differences: {
  2937. 'root.errors.0.message': {
  2938. type: 'Wrong error message',
  2939. expected: 'Unexpected token {',
  2940. actual: 'Unexpected token `{`, expected an identifier'
  2941. }
  2942. }
  2943. },
  2944. '"use strict"; declare module "\\01" {}',
  2945. {
  2946. content: 'declare module A { declare module B {} }',
  2947. explanation: "We realize the error as soon as we see the B",
  2948. expected_differences: {
  2949. 'root.errors.0.column': {
  2950. type: 'Wrong error column',
  2951. expected: 19,
  2952. actual: '34-35'
  2953. },
  2954. 'root.errors.0.message': {
  2955. type: 'Wrong error message',
  2956. expected: 'Unexpected identifier',
  2957. actual: 'Unexpected identifier, expected the token `.`'
  2958. }
  2959. }
  2960. },
  2961. {
  2962. content: 'declare module A { export default 1 +1; }',
  2963. explanation: 'export is no longer a future reserved word',
  2964. expected_differences: {
  2965. 'root.errors.0.message': {
  2966. type: 'Wrong error message',
  2967. expected: 'Unexpected reserved word',
  2968. actual: 'Unexpected token `export`, expected the token `declare`',
  2969. },
  2970. },
  2971. },
  2972. ],
  2973. 'Type Grouping': [
  2974. 'var a: (number)',
  2975. {
  2976. content: 'var a: (() => number) | () => string',
  2977. explanation: 'Esprima counts the parens in the type locs',
  2978. expected_differences: {
  2979. 'root.body.0.declarations.0.id.typeAnnotation.typeAnnotation.range.0': {
  2980. type: 'Wrong number',
  2981. expected: 7,
  2982. actual: 8
  2983. },
  2984. 'root.body.0.declarations.0.id.typeAnnotation.typeAnnotation.loc.start.column': {
  2985. type: 'Wrong number',
  2986. expected: 7,
  2987. actual: 8
  2988. }
  2989. }
  2990. },
  2991. 'var a: (A | B)',
  2992. 'var a: (typeof A)',
  2993. 'var a: Array<(number)>',
  2994. 'var a: ([]) = []',
  2995. 'var a: (A)',
  2996. 'var a: (A.B)',
  2997. 'var a: (A<T>)',
  2998. 'var a: (A | B)',
  2999. 'var a: (A & B)',
  3000. ],
  3001. 'Bounded Polymorphism': [
  3002. 'function foo<T: Foo>() {}',
  3003. {
  3004. content: 'class Foo<T: Bar>() {}',
  3005. explanation: "Improved error message",
  3006. expected_differences: {
  3007. 'root.errors.0.message': {
  3008. type: 'Wrong error message',
  3009. expected: 'Unexpected token (',
  3010. actual: 'Unexpected token `(`, expected the token `{`'
  3011. }
  3012. }
  3013. },
  3014. ],
  3015. 'Async/Await': [
  3016. 'try { foo(); } catch (async) { bar(); }',
  3017. 'try { foo(); } catch (await) { bar(); }',
  3018. {
  3019. content: 'var x = { async() { bar(); }}',
  3020. explanation: "Esprima-fb doesn't include params in " +
  3021. "FunctionExpression location",
  3022. expected_differences: {
  3023. 'root.body.0.declarations.0.init.properties.0.value.range.0': {
  3024. type: 'Wrong number',
  3025. expected: 18,
  3026. actual: 15,
  3027. },
  3028. 'root.body.0.declarations.0.init.properties.0.value.loc.start.column': {
  3029. type: 'Wrong number',
  3030. expected: 18,
  3031. actual: 15,
  3032. },
  3033. },
  3034. },
  3035. {
  3036. content: 'var x = { set async(v) { }, get async() { return "foo";}, }',
  3037. explanation: "Esprima-fb doesn't include params in " +
  3038. "FunctionExpression location",
  3039. expected_differences: {
  3040. 'root.body.0.declarations.0.init.properties.0.value.range.0': {
  3041. type: 'Wrong number',
  3042. expected: 23,
  3043. actual: 19,
  3044. },
  3045. 'root.body.0.declarations.0.init.properties.0.value.loc.start.column': {
  3046. type: 'Wrong number',
  3047. expected: 23,
  3048. actual: 19,
  3049. },
  3050. 'root.body.0.declarations.0.init.properties.1.value.range.0': {
  3051. type: 'Wrong number',
  3052. expected: 40,
  3053. actual: 37,
  3054. },
  3055. 'root.body.0.declarations.0.init.properties.1.value.loc.start.column': {
  3056. type: 'Wrong number',
  3057. expected: 40,
  3058. actual: 37,
  3059. },
  3060. },
  3061. },
  3062. {
  3063. content: 'var x = { set await(v) { }, get await() { return "foo";}, }',
  3064. explanation: "Esprima-fb doesn't include params in " +
  3065. "FunctionExpression location",
  3066. expected_differences: {
  3067. 'root.body.0.declarations.0.init.properties.0.value.range.0': {
  3068. type: 'Wrong number',
  3069. expected: 23,
  3070. actual: 19,
  3071. },
  3072. 'root.body.0.declarations.0.init.properties.0.value.loc.start.column': {
  3073. type: 'Wrong number',
  3074. expected: 23,
  3075. actual: 19,
  3076. },
  3077. 'root.body.0.declarations.0.init.properties.1.value.range.0': {
  3078. type: 'Wrong number',
  3079. expected: 40,
  3080. actual: 37,
  3081. },
  3082. 'root.body.0.declarations.0.init.properties.1.value.loc.start.column': {
  3083. type: 'Wrong number',
  3084. expected: 40,
  3085. actual: 37,
  3086. },
  3087. },
  3088. },
  3089. 'class async { }',
  3090. {
  3091. content: 'class async { async() { } }',
  3092. explanation: "Esprima-fb doesn't include params in " +
  3093. "FunctionExpression location",
  3094. expected_differences: {
  3095. 'root.body.0.body.body.0.value.range.0': {
  3096. type: 'Wrong number',
  3097. expected: 22,
  3098. actual: 19,
  3099. },
  3100. 'root.body.0.body.body.0.value.loc.start.column': {
  3101. type: 'Wrong number',
  3102. expected: 22,
  3103. actual: 19,
  3104. },
  3105. },
  3106. },
  3107. {
  3108. content: 'class async { async async() { await foo; } }',
  3109. explanation: "Esprima-fb doesn't include params in " +
  3110. "FunctionExpression location",
  3111. expected_differences: {
  3112. 'root.body.0.body.body.0.value.range.0': {
  3113. type: 'Wrong number',
  3114. expected: 28,
  3115. actual: 25,
  3116. },
  3117. 'root.body.0.body.body.0.value.loc.start.column': {
  3118. type: 'Wrong number',
  3119. expected: 28,
  3120. actual: 25,
  3121. },
  3122. },
  3123. },
  3124. {
  3125. content: 'class await { await() { } }',
  3126. explanation: "Esprima-fb doesn't include params in " +
  3127. "FunctionExpression location",
  3128. expected_differences: {
  3129. 'root.body.0.body.body.0.value.range.0': {
  3130. type: 'Wrong number',
  3131. expected: 22,
  3132. actual: 19,
  3133. },
  3134. 'root.body.0.body.body.0.value.loc.start.column': {
  3135. type: 'Wrong number',
  3136. expected: 22,
  3137. actual: 19,
  3138. },
  3139. },
  3140. },
  3141. {
  3142. content: 'class A { set async(v) { } get async() { return "foo";} }',
  3143. explanation: "Esprima-fb doesn't include params in " +
  3144. "FunctionExpression location",
  3145. expected_differences: {
  3146. 'root.body.0.body.body.0.value.range.0': {
  3147. type: 'Wrong number',
  3148. expected: 23,
  3149. actual: 19,
  3150. },
  3151. 'root.body.0.body.body.0.value.loc.start.column': {
  3152. type: 'Wrong number',
  3153. expected: 23,
  3154. actual: 19,
  3155. },
  3156. 'root.body.0.body.body.1.value.range.0': {
  3157. type: 'Wrong number',
  3158. expected: 39,
  3159. actual: 36,
  3160. },
  3161. 'root.body.0.body.body.1.value.loc.start.column': {
  3162. type: 'Wrong number',
  3163. expected: 39,
  3164. actual: 36,
  3165. },
  3166. },
  3167. },
  3168. {
  3169. content: 'class A { set await(v) { } get await() { return "foo";} }',
  3170. explanation: "Esprima-fb doesn't include params in " +
  3171. "FunctionExpression location",
  3172. expected_differences: {
  3173. 'root.body.0.body.body.0.value.range.0': {
  3174. type: 'Wrong number',
  3175. expected: 23,
  3176. actual: 19,
  3177. },
  3178. 'root.body.0.body.body.0.value.loc.start.column': {
  3179. type: 'Wrong number',
  3180. expected: 23,
  3181. actual: 19,
  3182. },
  3183. 'root.body.0.body.body.1.value.range.0': {
  3184. type: 'Wrong number',
  3185. expected: 39,
  3186. actual: 36,
  3187. },
  3188. 'root.body.0.body.body.1.value.loc.start.column': {
  3189. type: 'Wrong number',
  3190. expected: 39,
  3191. actual: 36,
  3192. },
  3193. },
  3194. },
  3195. {
  3196. content: 'y = async function() { return await bar; } ()',
  3197. explanation: 'Babel has no problem with this, and it seems ' +
  3198. 'perfectly sensical',
  3199. expected_differences: {
  3200. 'root.errors': {
  3201. type: 'Flow found no error',
  3202. expected: 'Line 1: Unexpected token (',
  3203. actual: undefined,
  3204. },
  3205. },
  3206. },
  3207. 'async function f() { return 1; }',
  3208. 'async function foo() { await 1; }',
  3209. {
  3210. content: 'var x = { async m() { await 1; } };',
  3211. explanation: "Esprima-fb doesn't include params in " +
  3212. "FunctionExpression location",
  3213. expected_differences: {
  3214. 'root.body.0.declarations.0.init.properties.0.value.range.0': {
  3215. type: 'Wrong number',
  3216. expected: 20,
  3217. actual: 17,
  3218. },
  3219. 'root.body.0.declarations.0.init.properties.0.value.loc.start.column': {
  3220. type: 'Wrong number',
  3221. expected: 20,
  3222. actual: 17,
  3223. },
  3224. },
  3225. },
  3226. 'function async() { }',
  3227. {
  3228. content: 'async function foo() { return await foo + await bar + 5; }',
  3229. explanation: 'Works in Babel and the spec appears to allow it',
  3230. expected_differences: {
  3231. 'root.errors': {
  3232. type: 'Flow found no error',
  3233. expected: 'Line 1: Unexpected identifier',
  3234. actual: undefined,
  3235. },
  3236. },
  3237. },
  3238. 'var x = async function bar() { await foo; }',
  3239. {
  3240. content: 'async function foo() { return await; }',
  3241. explanation: "Improved error message",
  3242. expected_differences: {
  3243. 'root.errors.0.message': {
  3244. type: 'Wrong error message',
  3245. expected: 'Unexpected token ;',
  3246. actual: 'Unexpected token `;`'
  3247. }
  3248. }
  3249. },
  3250. 'var x = async (a, b) => await a;',
  3251. 'var x = async a => await a;',
  3252. 'foo(async () => await bar);',
  3253. 'var x = async\ny => y',
  3254. {
  3255. content: 'class A { async bar() { await foo; } }',
  3256. explanation: "Esprima-fb doesn't include params in " +
  3257. "FunctionExpression location",
  3258. expected_differences: {
  3259. 'root.body.0.body.body.0.value.range.0': {
  3260. type: 'Wrong number',
  3261. expected: 22,
  3262. actual: 19,
  3263. },
  3264. 'root.body.0.body.body.0.value.loc.start.column': {
  3265. type: 'Wrong number',
  3266. expected: 22,
  3267. actual: 19,
  3268. },
  3269. },
  3270. },
  3271. {
  3272. content: 'var x = { async "foo"() { await y; } }',
  3273. explanation: "Esprima-fb doesn't include params in " +
  3274. "FunctionExpression location",
  3275. expected_differences: {
  3276. 'root.body.0.declarations.0.init.properties.0.value.range.0': {
  3277. type: 'Wrong number',
  3278. expected: 24,
  3279. actual: 21,
  3280. },
  3281. 'root.body.0.declarations.0.init.properties.0.value.loc.start.column': {
  3282. type: 'Wrong number',
  3283. expected: 24,
  3284. actual: 21,
  3285. },
  3286. },
  3287. },
  3288. {
  3289. content: 'var x = { async 123() { await y; } }',
  3290. explanation: "Esprima-fb doesn't include params in " +
  3291. "FunctionExpression location",
  3292. expected_differences: {
  3293. 'root.body.0.declarations.0.init.properties.0.value.range.0': {
  3294. type: 'Wrong number',
  3295. expected: 22,
  3296. actual: 19,
  3297. },
  3298. 'root.body.0.declarations.0.init.properties.0.value.loc.start.column': {
  3299. type: 'Wrong number',
  3300. expected: 22,
  3301. actual: 19,
  3302. },
  3303. },
  3304. },
  3305. ],
  3306. }
  3307. };