/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
- module.exports = {
- todo: {
- 'ES6: Destructured Parameters': true,
- 'Harmony Invalid syntax': true,
- },
- sections: {
- 'Function Expression': [
- '(function(){}())',
- 'var x = function(){}.bind(this)',
- ],
- 'Invalid syntax': [
- {
- content: '{',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `}`'
- }
- }
- },
- {
- content: '}',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token }',
- actual: 'Unexpected token `}`, expected the start of a statement'
- }
- }
- },
- '3ea',
- '3in []',
- '3e',
- {
- content: '3e+',
- explanation: "Esprima counts comments in its loc, Flow doesn't",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 3,
- actual: '0-2'
- },
- }
- },
- {
- content: '3e-',
- explanation: "Esprima counts comments in its loc, Flow doesn't",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 3,
- actual: '0-2'
- },
- }
- },
- '3x',
- '3x0',
- '0x',
- {
- content: '09',
- explanation: "Spec doesn't support this but every implementation does",
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Unexpected token ILLEGAL',
- actual: undefined
- },
- }
- },
- '01a',
- '3in[]',
- '0x3in[]',
- '"Hello\nWorld"',
- 'x\\',
- 'var x = /(s/g',
- '/',
- '/test',
- '/test\n/',
- /* TODO uncomment when esprima is fixed
- * https://code.google.com/p/esprima/issues/detail?id=604
- {
- content: 'var x = /[a-z]/\\ux',
- explanation: "10.8.5.1 disallows unicode escape flags",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 18,
- actual: '15-16'
- },
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Invalid regular expression',
- actual: 'Unexpected token ILLEGAL'
- },
- }
- },
- {
- content: 'var x = /[a-z]/\\\\ux',
- explanation: "10.8.5.1 disallows unicode escape flags",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 19,
- actual: '15-16'
- },
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Invalid regular expression',
- actual: 'Unexpected token ILLEGAL'
- },
- }
- },
- */
- '3 = 4',
- 'func() = 4',
- {
- content: '(1 + 1) = 10',
- explanation: "Esprima counts parens in its loc, Flow doesn't",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 7,
- actual: '1-6'
- },
- }
- },
- '"\\u{110000}"',
- {
- content: '"\\u{}"',
- explanation: "Flow's lexer complains at the beginning of a bad escape",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 4,
- actual: '2-3'
- },
- }
- },
- {
- content: '"\\u{FFFF"',
- explanation: "Flow's lexer complains at the beginning of a bad escape",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 9,
- actual: '2-3'
- },
- }
- },
- {
- content: '"\\u{FFZ}"',
- explanation: "Flow's lexer complains at the beginning of a bad escape",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 7,
- actual: '2-3'
- },
- }
- },
- 'x\\',
- '1++',
- '1--',
- '++1',
- '--1',
- {
- content: 'for((1 + 1) in list) process(x);',
- explanation: "Esprima counts comments in its loc, Flow doesn't",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 11,
- actual: '5-10'
- },
- }
- },
- {
- content: '[',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `]`'
- }
- }
- },
- {
- content: '[,',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `]`'
- }
- }
- },
- {
- content: '1 + {',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `}`'
- }
- }
- },
- {
- content: '1 + { t:t ',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `}`'
- }
- }
- },
- {
- content: '1 + { t:t,',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `}`'
- }
- }
- },
- 'var x = /\n/',
- 'var x = "\n',
- {
- content: 'var if = 42',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token if',
- actual: 'Unexpected token `if`'
- }
- }
- },
- {
- content: 'i #= 42',
- explanation: "# is no longer illegal in Flow, since we support private class fields. " +
- "Instead, it is unexpected since we are not parsing a member expression " +
- "or class property.",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ILLEGAL',
- actual: 'Unexpected token `#`, expected the end of an expression statement (`;`)'
- },
- }
- },
- 'i + 2 = 42',
- '+i = 42',
- '1 + (',
- {
- content: '\n\n\n{',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `}`'
- }
- }
- },
- {
- content: '\n/* Some multiline\ncomment */\n)',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token )',
- actual: 'Unexpected token `)`, expected the start of a statement'
- }
- }
- },
- {
- content: '{ set 1 }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected number',
- actual: 'Unexpected number, expected the end of an expression statement (`;`)'
- }
- }
- },
- {
- content: '{ get 2 }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected number',
- actual: 'Unexpected number, expected the end of an expression statement (`;`)'
- }
- }
- },
- {
- content: '({ set: s(if) { } })',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token if',
- actual: 'Unexpected token `if`'
- }
- }
- },
- {
- content: '({ set s(.) { } })',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token .',
- actual: 'Unexpected token `.`, expected an identifier'
- }
- }
- },
- {
- content: '({ set s() { } })',
- explanation: "Esprima error isn't great",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 9,
- actual: '7-8'
- },
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token )',
- actual: 'Setter should have exactly one parameter'
- }
- }
- },
- {
- content: '({ set: s() { } })',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token {',
- actual: 'Unexpected token `{`, expected the token `,`'
- }
- }
- },
- {
- content: '({ set: s(a, b) { } })',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token {',
- actual: 'Unexpected token `{`, expected the token `,`'
- }
- }
- },
- {
- content: '({ get: g(d) { } })',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token {',
- actual: 'Unexpected token `{`, expected the token `,`'
- }
- }
- },
- {
- content: '({ get i() { }, i: 42 })',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Object literal may not have data and accessor property with the same name',
- actual: undefined,
- }
- }
- },
- {
- content: '({ i: 42, get i() { } })',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Object literal may not have data and accessor property with the same name',
- actual: undefined,
- }
- }
- },
- {
- content: '({ set i(x) { }, i: 42 })',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Object literal may not have data and accessor property with the same name',
- actual: undefined,
- }
- }
- },
- {
- content: '({ i: 42, set i(x) { } })',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Object literal may not have data and accessor property with the same name',
- actual: undefined,
- }
- }
- },
- {
- content: '({ get i() { }, get i() { } })',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Object literal may not have multiple get/set accessors with the same name',
- actual: undefined,
- }
- }
- },
- {
- content: '({ set i(x) { }, set i(x) { } })',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Object literal may not have multiple get/set accessors with the same name',
- actual: undefined,
- }
- }
- },
- {
- content: '((a)) => 42',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token =>',
- actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)'
- }
- }
- },
- {
- content: '(a, (b)) => 42',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token =>',
- actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)'
- }
- }
- },
- {
- content: '"use strict"; (eval = 10) => 42',
- explanation: "This is an arrow function error, not an assignment "+
- "error",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Assignment to eval or arguments is not allowed in strict mode',
- actual: 'Parameter name eval or arguments is not allowed in strict mode',
- },
- },
- },
- // strict mode, using eval when IsSimpleParameterList is true
- {
- content: '"use strict"; eval => 42',
- explanation: "Esprima error loc is crazy here",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 24,
- actual: '14-18'
- },
- }
- },
- // strict mode, using arguments when IsSimpleParameterList is true
- {
- content: '"use strict"; arguments => 42',
- explanation: "Esprima doesn't point to the bad argument",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 29,
- actual: '14-23'
- },
- }
- },
- // strict mode, using eval when IsSimpleParameterList is true
- {
- content: '"use strict"; (eval, a) => 42',
- explanation: "Esprima error loc is crazy here",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 29,
- actual: '15-19'
- },
- }
- },
- // strict mode, using arguments when IsSimpleParameterList is true
- {
- content: '"use strict"; (arguments, a) => 42',
- explanation: "Esprima doesn't point to the bad argument",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 34,
- actual: '15-24'
- },
- }
- },
- {
- content: '"use strict"; (a, a) => 42',
- explanation: "Esprima counts parens in its loc, Flow doesn't",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 20,
- actual: '18-19'
- },
- }
- },
- '"use strict"; (a) => 00',
- {
- content: '() <= 42',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token <=',
- actual: 'Unexpected token `<=`, expected the token `=>`'
- }
- }
- },
- {
- content: '() ? 42',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ?',
- actual: 'Unexpected token `?`, expected the token `=>`'
- }
- }
- },
- {
- content: '() + 42',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token +',
- actual: 'Unexpected token `+`, expected the token `=>`'
- }
- }
- },
- {
- content: '(...x) + 42',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token +',
- actual: 'Unexpected token `+`, expected the token `=>`'
- }
- }
- },
- {
- content: '()++',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ++',
- actual: 'Unexpected token `++`, expected the token `=>`'
- }
- }
- },
- {
- content: '()()',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token (',
- actual: 'Unexpected token `(`, expected the token `=>`'
- }
- }
- },
- {
- content: '(10) => 00',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token =>',
- actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)'
- }
- }
- },
- {
- content: '(10, 20) => 00',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token =>',
- actual: 'Unexpected token `=>`, expected the end of an expression statement (`;`)'
- }
- }
- },
- {
- content: '"use strict"; (eval) => 42',
- explanation: "Esprima error loc is crazy here",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 26,
- actual: '15-19'
- },
- }
- },
- {
- content: '(eval) => { "use strict"; 42 }',
- explanation: "Esprima error loc is crazy here",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 30,
- actual: '1-5'
- },
- }
- },
- {
- content: 'function t(if) { }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token if',
- actual: 'Unexpected token `if`'
- }
- }
- },
- {
- content: 'function t(true) { }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token true',
- actual: 'Unexpected token `true`'
- }
- }
- },
- {
- content: 'function t(false) { }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token false',
- actual: 'Unexpected token `false`'
- }
- }
- },
- {
- content: 'function t(null) { }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token null',
- actual: 'Unexpected token `null`'
- }
- }
- },
- {
- content: 'function null() { }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token null',
- actual: 'Unexpected token `null`'
- }
- }
- },
- {
- content: 'function true() { }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token true',
- actual: 'Unexpected token `true`'
- }
- }
- },
- {
- content: 'function false() { }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token false',
- actual: 'Unexpected token `false`'
- }
- }
- },
- {
- content: 'function if() { }',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token if',
- actual: 'Unexpected token `if`'
- }
- }
- },
- {
- content: 'a b;',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected identifier',
- actual: 'Unexpected identifier, expected the end of an expression statement (`;`)'
- }
- }
- },
- {
- content: 'if.a;',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token .',
- actual: 'Unexpected token `.`, expected the token `(`'
- }
- }
- },
- {
- content: 'a if;',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token if',
- actual: 'Unexpected token `if`, expected the end of an expression statement (`;`)'
- }
- }
- },
- {
- content: 'a class;',
- explanation: 'class is no longer a future reserved word',
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected reserved word',
- actual: 'Unexpected token `class`, expected the end of an expression statement (`;`)',
- },
- },
- },
- 'break\n',
- {
- content: 'break 1;',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected number',
- actual: 'Unexpected number, expected an identifier'
- }
- }
- },
- 'continue\n',
- {
- content: 'continue 2;',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected number',
- actual: 'Unexpected number, expected an identifier'
- }
- }
- },
- 'throw',
- {
- content: 'throw;',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ;',
- actual: 'Unexpected token `;`'
- }
- }
- },
- 'throw\n',
- {
- content: 'for (var i, i2 in {});',
- explanation: "Esprima counts comments in its loc, Flow doesn't",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 15,
- actual: '5-14'
- },
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token in',
- actual: 'Invalid left-hand side in for-in'
- },
- }
- },
- {
- content: 'for ((i in {}));',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token )',
- actual: 'Unexpected token `)`, expected the token `;`'
- }
- }
- },
- 'for (i + 1 in {});',
- 'for (+i in {});',
- {
- content: 'if(false)',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the start of a statement'
- }
- }
- },
- {
- content: 'if(false) doThis(); else',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the start of a statement'
- }
- }
- },
- {
- content: 'do',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the start of a statement'
- }
- }
- },
- {
- content: 'while(false)',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the start of a statement'
- }
- }
- },
- {
- content: 'for(;;)',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the start of a statement'
- }
- }
- },
- {
- content: 'with(x)',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the start of a statement'
- }
- }
- },
- 'try { }',
- 'const x = 12, y;',
- 'const x, y = 12;',
- 'const x;',
- {
- content: 'if(true) let a = 1;',
- explanation: "The let keyword is parsed as an identifer. " +
- "It's the a that causes the error",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 9,
- actual: '13-14'
- },
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token let',
- actual: 'Unexpected identifier, expected the end of an expression statement (`;`)',
- },
- }
- },
- {
- content: 'if(true) const a = 1;',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token const',
- actual: 'Unexpected token `const`'
- }
- }
- },
- {
- content: 'switch (c) { default: default: }',
- explanation: "Esprima points after the duplicate default",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 30,
- actual: '22-29'
- },
- }
- },
- {
- content: 'new X()."s"',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected string',
- actual: 'Unexpected string, expected an identifier'
- }
- }
- },
- '/*',
- '/*\n\n\n',
- '/**',
- '/*\n\n*',
- '/*hello',
- '/*hello *',
- {
- content: '\n]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- {
- content: '\r]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- {
- content: '\r\n]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- {
- content: '\n\r]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- {
- content: '//\r\n]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- {
- content: '//\n\r]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- '/a\\\n/',
- {
- content: '//\r \n]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- {
- content: '/*\r\n*/]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- {
- content: '/*\n\r*/]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- {
- content: '/*\r \n*/]',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token ]',
- actual: 'Unexpected token `]`, expected the start of a statement'
- }
- }
- },
- '\\\\',
- '\\x',
- {
- content: '"\\',
- explanation: "Esprima has a non-existent location for the eof",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 3,
- actual: '2-2'
- },
- }
- },
- '"\\u',
- {
- content: 'try { } catch() {}',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token )',
- actual: 'Unexpected token `)`, expected an identifier'
- }
- }
- },
- 'return',
- 'break',
- 'continue',
- 'switch (x) { default: continue; }',
- {
- content: 'do { x } *',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token *',
- actual: 'Unexpected token `*`, expected the token `while`'
- }
- }
- },
- 'while (true) { break x; }',
- 'while (true) { continue x; }',
- 'x: while (true) { (function () { break x; }); }',
- 'x: while (true) { (function () { continue x; }); }',
- 'x: while (true) { (function () { break; }); }',
- 'x: while (true) { (function () { continue; }); }',
- {
- content: 'x: while (true) { x: while (true) { } }',
- explanation: "Esprima points to the location after the second colon",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 20,
- actual: '18-19'
- },
- }
- },
- '(function () { \'use strict\'; delete i; }())',
- '(function () { \'use strict\'; with (i); }())',
- {
- content: 'function hello() {\'use strict\'; ({ i: 42, i: 42 }) }',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Duplicate data property in object literal not allowed in strict mode',
- actual: undefined,
- }
- }
- },
- {
- content: 'function hello() {\'use strict\'; ({ hasOwnProperty: 42, hasOwnProperty: 42 }) }',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Duplicate data property in object literal not allowed in strict mode',
- actual: undefined,
- }
- }
- },
- 'function hello() {\'use strict\'; var eval = 10; }',
- 'function hello() {\'use strict\'; var arguments = 10; }',
- 'function hello() {\'use strict\'; try { } catch (eval) { } }',
- 'function hello() {\'use strict\'; try { } catch (arguments) { } }',
- 'function hello() {\'use strict\'; eval = 10; }',
- 'function hello() {\'use strict\'; arguments = 10; }',
- 'function hello() {\'use strict\'; ++eval; }',
- 'function hello() {\'use strict\'; --eval; }',
- 'function hello() {\'use strict\'; ++arguments; }',
- 'function hello() {\'use strict\'; --arguments; }',
- 'function hello() {\'use strict\'; eval++; }',
- 'function hello() {\'use strict\'; eval--; }',
- 'function hello() {\'use strict\'; arguments++; }',
- 'function hello() {\'use strict\'; arguments--; }',
- 'function hello() {\'use strict\'; function eval() { } }',
- 'function hello() {\'use strict\'; function arguments() { } }',
- 'function eval() {\'use strict\'; }',
- 'function arguments() {\'use strict\'; }',
- 'function hello() {\'use strict\'; (function eval() { }()) }',
- 'function hello() {\'use strict\'; (function arguments() { }()) }',
- '(function eval() {\'use strict\'; })()',
- '(function arguments() {\'use strict\'; })()',
- 'function hello() {\'use strict\'; ({ s: function eval() { } }); }',
- '(function package() {\'use strict\'; })()',
- 'function hello() {\'use strict\'; ({ i: 10, set s(eval) { } }); }',
- 'function hello() {\'use strict\'; ({ set s(eval) { } }); }',
- 'function hello() {\'use strict\'; ({ s: function s(eval) { } }); }',
- 'function hello(eval) {\'use strict\';}',
- 'function hello(arguments) {\'use strict\';}',
- 'function hello() { \'use strict\'; function inner(eval) {} }',
- 'function hello() { \'use strict\'; function inner(arguments) {} }',
- ' "\\1"; \'use strict\';',
- 'function hello() { \'use strict\'; "\\1"; }',
- 'function hello() { \'use strict\'; 021; }',
- 'function hello() { \'use strict\'; ({ "\\1": 42 }); }',
- 'function hello() { \'use strict\'; ({ 021: 42 }); }',
- 'function hello() { "octal directive\\1"; "use strict"; }',
- 'function hello() { "octal directive\\1"; "octal directive\\2"; "use strict"; }',
- 'function hello() { "use strict"; function inner() { "octal directive\\1"; } }',
- 'function hello() { "use strict"; var implements; }',
- 'function hello() { "use strict"; var interface; }',
- 'function hello() { "use strict"; var package; }',
- 'function hello() { "use strict"; var private; }',
- 'function hello() { "use strict"; var protected; }',
- 'function hello() { "use strict"; var public; }',
- 'function hello() { "use strict"; var static; }',
- 'function hello() { "use strict"; var yield; }',
- 'function hello() { "use strict"; var let; }',
- 'function hello(static) { "use strict"; }',
- 'function static() { "use strict"; }',
- 'function eval(a) { "use strict"; }',
- 'function arguments(a) { "use strict"; }',
- 'var yield',
- {
- content: 'var let',
- explanation: "Bug in esprima. This should be allowed",
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Unexpected token let',
- actual: undefined
- },
- }
- },
- '"use strict"; function static() { }',
- 'function a(t, t) { "use strict"; }',
- 'function a(eval) { "use strict"; }',
- 'function a(package) { "use strict"; }',
- 'function a() { "use strict"; function b(t, t) { }; }',
- '(function a(t, t) { "use strict"; })',
- 'function a() { "use strict"; (function b(t, t) { }); }',
- // Duplicates are forbidden if IsSimpleParameterList is false, and rest
- // params, patterns, and defaults all make the params non-simple
- {
- content: '(t, t, ...rest) => 42',
- explanation: "Esprima points to the end of the params not to the "+
- "bad param itself",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 15,
- actual: '4-5'
- },
- }
- },
- {
- content: '(t, t, [b]) => 42',
- explanation: "Esprima points to the end of the params not to the "+
- "bad param itself",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 11,
- actual: '4-5'
- },
- }
- },
- {
- content: '(t, t, {b}) => 42',
- explanation: "Esprima points to the end of the params not to the "+
- "bad param itself",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 11,
- actual: '4-5'
- },
- }
- },
- {
- content: '(t, t, b=1) => 42',
- explanation: "Esprima points to the end of the params not to the "+
- "bad param itself",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 11,
- actual: '4-5'
- },
- }
- },
- '(function a(eval) { "use strict"; })',
- '(function a(package) { "use strict"; })',
- {
- content: '__proto__: __proto__: 42;',
- explanation: "Esprima points to the location after the second colon",
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 21,
- actual: '11-20'
- },
- }
- },
- '"use strict"; function t(__proto__, __proto__) { }',
- {
- content: '"use strict"; x = { __proto__: 42, __proto__: 43 }',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Duplicate data property in object literal not allowed in strict mode',
- actual: undefined,
- }
- }
- },
- {
- content: '"use strict"; x = { get __proto__() { }, __proto__: 43 }',
- explanation: 'Esprima-fb is wrong, ES6 allows duplicates',
- expected_differences: {
- 'root.errors': {
- type: 'Flow found no error',
- expected: 'Line 1: Object literal may not have data and accessor property with the same name',
- actual: undefined,
- }
- }
- },
- {
- content: 'var',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected an identifier'
- }
- }
- },
- {
- content: 'let',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected an identifier'
- }
- }
- },
- {
- content: 'const',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected an identifier'
- }
- }
- },
- {
- content: '{ ; ; ',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `}`'
- }
- }
- },
- {
- content: 'function t() { ; ; ',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected end of input',
- actual: 'Unexpected end of input, expected the token `}`'
- }
- }
- },
- {
- content: 'let let',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token let',
- actual: 'Unexpected token `let`'
- }
- }
- },
- {
- content: 'const let=4',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token let',
- actual: 'Unexpected token `let`'
- }
- }
- },
- {
- content: 'for (let let=4;;) {}',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token let',
- actual: 'Unexpected token `let`'
- }
- }
- },
- {
- content: 'for (let in arr) {}',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token in',
- actual: 'Unexpected token `in`'
- }
- }
- },
- {
- content: 'for (let let in arr) {}',
- explanation: "Improved error message",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token let',
- actual: 'Unexpected token `let`'
- }
- }
- },
- {
- content: 'class let { }',
- explanation: "Esprima counts comments in its loc, Flow doesn't",
- expected_differences: {
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Unexpected token let',
- actual: 'Use of future reserved word in strict mode'
- },
- }
- },
- 'class A { foo() { let let } }',
- {
- content: 'function foo([a.a]) {}',
- explanation: 'Esprima is off by one, flow fails to parse it',
- expected_differences: {
- 'root.errors.0.column': {
- type: 'Wrong error column',
- expected: 18,
- actual: '15-16'
- },
- 'root.errors.0.message': {
- type: 'Wrong error message',
- expected: 'Invalid left-hand side in formals list',
- actual: 'Unexpected token `.`, expected the token `,`',
- }
- },
- },
- {
- content: 'var f = function ([a.a]) {}…