esprima: invalid tests

Each of these tests was flagged as invalid during a run of the Shift parser over esprima’s tests. I’ve hand verified them.

  1. Early error: Functions with non-simple parameter lists may not contain a “use strict” directive
{
  "key": "declaration/function/empty-param",
  "case": "function a([], []) {'use strict';}\n"
}
  1. Early error: Exported binding “foo” is not declared
{
  "key": "ES6/export-declaration/export-named-as-default",
  "case": "export {foo as default};\n"
}
  1. Early error: Exported binding “foo” is not declared
{
  "key": "ES6/export-declaration/export-named-as-specifier",
  "case": "export {foo as bar};\n"
}
  1. Early error: Exported binding “foo” is not declared
{
  "key": "ES6/export-declaration/export-named-as-specifiers",
  "case": "export {foo as default, bar};\n"
}
  1. Early error: Exported binding “foo” is not declared
{
  "key": "ES6/export-declaration/export-named-specifier",
  "case": "export {foo};\n"
}
  1. Early error: Exported binding “foo” is not declared
{
  "key": "ES6/export-declaration/export-named-specifiers-comma",
  "case": "export {foo, bar,};\n"
}
  1. Early error: Exported binding “foo” is not declared
{
  "key": "ES6/export-declaration/export-named-specifiers",
  "case": "export {foo, bar};\n"
}
  1. esprima expects this valid program to fail
{
  "key": "ES6/object-initialiser/invalid-proto-identifier-shorthand",
  "case": "({ __proto__: null, __proto__ })\n",
  "failure": {
    "index": 29,
    "lineNumber": 1,
    "column": 30,
    "message": "Error: Line 1: Duplicate __proto__ fields are not allowed in object literals",
    "description": "Duplicate __proto__ fields are not allowed in object literals"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "ES6/object-initialiser/invalid-proto-literal-shorthand",
  "case": "({ \"__proto__\": null, __proto__ })\n",
  "failure": {
    "index": 31,
    "lineNumber": 1,
    "column": 32,
    "message": "Error: Line 1: Duplicate __proto__ fields are not allowed in object literals",
    "description": "Duplicate __proto__ fields are not allowed in object literals"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "ES6/object-initialiser/invalid-proto-shorthand-identifier",
  "case": "({ __proto__, __proto__: null })\n",
  "failure": {
    "index": 23,
    "lineNumber": 1,
    "column": 24,
    "message": "Error: Line 1: Duplicate __proto__ fields are not allowed in object literals",
    "description": "Duplicate __proto__ fields are not allowed in object literals"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "ES6/object-initialiser/invalid-proto-shorthand-literal",
  "case": "({ __proto__, \"__proto__\": null })\n",
  "failure": {
    "index": 25,
    "lineNumber": 1,
    "column": 26,
    "message": "Error: Line 1: Duplicate __proto__ fields are not allowed in object literals",
    "description": "Duplicate __proto__ fields are not allowed in object literals"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "ES6/object-initialiser/invalid-proto-shorthands",
  "case": "({ __proto__, __proto__ })\n",
  "failure": {
    "index": 23,
    "lineNumber": 1,
    "column": 24,
    "message": "Error: Line 1: Duplicate __proto__ fields are not allowed in object literals",
    "description": "Duplicate __proto__ fields are not allowed in object literals"
  }
}
{
  "key": "ES6/template-literals/literal-escape-sequences",
  "source": "`\\u{000042}\\u0042\\x42\\u0\\A\\0`"
}
  1. esprima expects this valid program to fail
{
  "key": "ES6/yield/invalid-yield-strict-function-declaration",
  "case": "function yield(){ \"use strict\"; }\n",
  "failure": {
    "index": 9,
    "lineNumber": 1,
    "column": 10,
    "message": "Error: Line 1: Use of future reserved word in strict mode",
    "description": "Use of future reserved word in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "ES6/yield/invalid-yield-strict-function-expression",
  "case": "(function yield(){ \"use strict\"; })\n",
  "failure": {
    "index": 10,
    "lineNumber": 1,
    "column": 11,
    "message": "Error: Line 1: Use of future reserved word in strict mode",
    "description": "Use of future reserved word in strict mode"
  }
}
  1. Early error: Arrow parameters must not contain yield expressions
{
  "key": "ES6/yield/yield-generator-arrow-default",
  "case": "function *g() { (x = yield) => {} }\n"
}
  1. Early error: Generator parameters must not contain yield expressions
{
  "key": "ES6/yield/yield-generator-default-parameter",
  "case": "function *g(x = yield){}\n"
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0201",
  "case": "function eval() {'use strict'; }",
  "failure": {
    "index": 9,
    "lineNumber": 1,
    "column": 10,
    "message": "Error: Line 1: Function name may not be eval or arguments in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0202",
  "case": "function arguments() {'use strict'; }",
  "failure": {
    "index": 9,
    "lineNumber": 1,
    "column": 10,
    "message": "Error: Line 1: Function name may not be eval or arguments in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0205",
  "case": "(function eval() {'use strict'; })()",
  "failure": {
    "index": 10,
    "lineNumber": 1,
    "column": 11,
    "message": "Error: Line 1: Function name may not be eval or arguments in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0206",
  "case": "(function arguments() {'use strict'; })()",
  "failure": {
    "index": 10,
    "lineNumber": 1,
    "column": 11,
    "message": "Error: Line 1: Function name may not be eval or arguments in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0208",
  "case": "(function package() {'use strict'; })()",
  "failure": {
    "index": 10,
    "lineNumber": 1,
    "column": 11,
    "message": "Error: Line 1: Use of future reserved word in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0234",
  "case": "function static() { \"use strict\"; }",
  "failure": {
    "index": 9,
    "lineNumber": 1,
    "column": 10,
    "message": "Error: Line 1: Use of future reserved word in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0235",
  "case": "function eval(a) { \"use strict\"; }",
  "failure": {
    "index": 9,
    "lineNumber": 1,
    "column": 10,
    "message": "Error: Line 1: Function name may not be eval or arguments in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0236",
  "case": "function arguments(a) { \"use strict\"; }",
  "failure": {
    "index": 9,
    "lineNumber": 1,
    "column": 10,
    "message": "Error: Line 1: Function name may not be eval or arguments in strict mode"
  }
}
  1. esprima expects this valid program to fail
{
  "key": "invalid-syntax/migrated_0259",
  "case": "function x(...{ a }){}",
  "failure": {
    "index": 14,
    "lineNumber": 1,
    "column": 15,
    "message": "Error: Line 1: Unexpected token {"
  }
}
  1. [1:17]: Invalid variable declaration in for-in statement
{
  "key": "statement/iteration/migrated_0019",
  "case": "for (var x = 42 in list) process(x);"
}
  1. [1:20]: Invalid variable declaration in for-in statement
{
  "key": "statement/iteration/migrated_0021",
  "case": "for (var x = y = z in q);"
}
  1. [1:31]: Invalid variable declaration in for-in statement
{
  "key": "statement/iteration/migrated_0022",
  "case": "for (var a = b = c = (d in e) in z);"
}
  1. [1:45]: Invalid variable declaration in for-in statement
{
  "key": "statement/iteration/migrated_0023",
  "case": "for (var i = function() { return 10 in [] } in list) process(x);"
}

(edited by @ariya: turning the list into a numbered one, for ease of reference)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 31 (12 by maintainers)

Most upvoted comments

@nenionoda, I expect your difficulty arises from conflating two unrelated questions, namely, whether a nested FunctionDeclaration (or rather its parameters and body) is included in the function code of the outer function (it is not) and whether said FunctionDeclaration is contained in the body of the outer function (it is).

These are not in conflict because they have nothing to do with each other. “Function code” is a specific term being defined, not a limitation on which source text is contained within the body of a function.

@nenionoda, your first example is certainly an error because the nested function is strict code, even though it is not part of the function code of the outer function. This is because

Function code is strict mode code if the associated FunctionDeclaration […] is contained in strict mode code […]

The second example is intended to be an error, I’m pretty sure, but the spec as written implies it is not, which is the issue I opened at tc39/ecma262#632.

@nenionoda, to understand that paragraph you also need the definition of “function code”, which I quote in that issue and above; it includes the body and parameters of the function but does not include the BindingIdentifier (nor the full FunctionDeclaration production, in my reading).

\8 and \9 are not given meaning anywhere in the spec because they do not match the grammar at all. This can be inferred by inspecting the EscapeSequence section and the LegacyOctalEscapeSequence extension to which it refers. In particular, the only production of EscapeSequence which 8 could match is CharacterEscapeSequence, where it would in turn need to match NonEscapeCharacter, which would require it to not match EscapeCharacter and therefore not match DecimalDigit (but of course it does). The LegacyOctalEscapeSequence extension doesn’t change this.

@mathiasbynens you are completely right; but i guess @michaelficarra meant that is should actually parse in esprima, but it won’t. (I am on esprima2.7.2 and can confirm it won’t parse ‘\u0AF9’ there.) I mean:

require('esprima').parse( '\u0AF9')
Error: Line 1: Unexpected token ILLEGAL
    at constructError (/home/n/node_modules/esprima/esprima.js:2406:21)
    at createError (/home/n/node_modules/esprima/esprima.js:2425:17)
    at unexpectedTokenError (/home/n/node_modules/esprima/esprima.js:2500:13)
    at throwUnexpectedToken (/home/n/node_modules/esprima/esprima.js:2504:15)
    at scanPunctuator (/home/n/node_modules/esprima/esprima.js:842:13)
    at advance (/home/n/node_modules/esprima/esprima.js:1621:16)
    at peek (/home/n/node_modules/esprima/esprima.js:1708:78)
    at parseProgram (/home/n/node_modules/esprima/esprima.js:5502:9)
    at Object.parse (/home/n/node_modules/esprima/esprima.js:5689:23)
    at repl:1:12