/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

Large files are truncated click here to view the full 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]) {}…