diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 0d31e14bec..6526eb464a 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -126,12 +126,18 @@ export default class ExpressionParser extends LValParser { ): N.Expression { const startPos = this.state.start; const startLoc = this.state.startLoc; - if (this.match(tt._yield) && this.state.inGenerator) { - let left = this.parseYield(noIn); - if (afterLeftParse) { - left = afterLeftParse.call(this, left, startPos, startLoc); + if (this.isContextual("yield")) { + if (this.state.inGenerator) { + let left = this.parseYield(noIn); + if (afterLeftParse) { + left = afterLeftParse.call(this, left, startPos, startLoc); + } + return left; + } else { + // The tokenizer will assume an expression is allowed after + // `yield`, but this isn't that kind of yield + this.state.exprAllowed = false; } - return left; } const oldCommaAfterSpreadAt = this.state.commaAfterSpreadAt; @@ -145,7 +151,7 @@ export default class ExpressionParser extends LValParser { failOnShorthandAssign = true; } - if (this.match(tt.parenL) || this.match(tt.name) || this.match(tt._yield)) { + if (this.match(tt.parenL) || this.match(tt.name)) { this.state.potentialArrowAt = this.state.start; } @@ -412,7 +418,13 @@ export default class ExpressionParser extends LValParser { // Parse unary operators, both prefix and postfix. parseMaybeUnary(refShorthandDefaultPos: ?Pos): N.Expression { - if (this.state.type.prefix) { + if ( + this.isContextual("await") && + (this.state.inAsync || + (!this.state.inFunction && this.options.allowAwaitOutsideFunction)) + ) { + return this.parseAwait(); + } else if (this.state.type.prefix) { const node = this.startNode(); const update = this.match(tt.incDec); node.operator = this.state.value; @@ -841,29 +853,12 @@ export default class ExpressionParser extends LValParser { this.next(); return this.finishNode(node, "ThisExpression"); - case tt._yield: - if (this.state.inGenerator) this.unexpected(); - case tt.name: { node = this.startNode(); - const allowAwait = - this.state.value === "await" && - (this.state.inAsync || - (!this.state.inFunction && this.options.allowAwaitOutsideFunction)); - const containsEsc = this.state.containsEsc; - const allowYield = this.shouldAllowYieldIdentifier(); - const id = this.parseIdentifier(allowAwait || allowYield); + const id = this.parseIdentifier(); - if (id.name === "await") { - if ( - this.state.inAsync || - this.inModule || - (!this.state.inFunction && this.options.allowAwaitOutsideFunction) - ) { - return this.parseAwait(node); - } - } else if ( + if ( !containsEsc && id.name === "async" && this.match(tt._function) && @@ -1832,17 +1827,14 @@ export default class ExpressionParser extends LValParser { if (isExpression) { node.body = this.parseMaybeAssign(); } else { - // Start a new scope with regard to labels and the `inGenerator` + // Start a new scope with regard to labels // flag (restore them to their old value afterwards). - const oldInGen = this.state.inGenerator; const oldInFunc = this.state.inFunction; const oldLabels = this.state.labels; - this.state.inGenerator = node.generator; this.state.inFunction = true; this.state.labels = []; node.body = this.parseBlock(true); this.state.inFunction = oldInFunc; - this.state.inGenerator = oldInGen; this.state.labels = oldLabels; } @@ -1952,15 +1944,6 @@ export default class ExpressionParser extends LValParser { } parseIdentifierName(pos: number, liberal?: boolean): string { - if (!liberal) { - this.checkReservedWord( - this.state.value, - this.state.start, - !!this.state.type.keyword, - false, - ); - } - let name: string; if (this.match(tt.name)) { @@ -1985,11 +1968,17 @@ export default class ExpressionParser extends LValParser { throw this.unexpected(); } - if (!liberal && name === "await" && this.state.inAsync) { - this.raise(pos, "invalid use of await inside of an async function"); + if (!liberal) { + this.checkReservedWord( + name, + this.state.start, + !!this.state.type.keyword, + false, + ); } this.next(); + return name; } @@ -1999,18 +1988,17 @@ export default class ExpressionParser extends LValParser { checkKeywords: boolean, isBinding: boolean, ): void { - if ( - this.state.strict && - (isStrictReservedWord(word) || - (isBinding && isStrictBindReservedWord(word))) - ) { - this.raise(startLoc, word + " is a reserved word in strict mode"); - } - if (this.state.inGenerator && word === "yield") { this.raise( startLoc, - "yield is a reserved word inside generator functions", + "Can not use 'yield' as identifier inside a generator", + ); + } + + if (this.state.inAsync && word === "await") { + this.raise( + startLoc, + "Can not use 'await' as identifier inside an async function", ); } @@ -2022,20 +2010,40 @@ export default class ExpressionParser extends LValParser { } if (this.isReservedWord(word) || (checkKeywords && isKeyword(word))) { + if (!this.state.inAsync && word === "await") { + this.raise( + startLoc, + "Can not use keyword 'await' outside an async function", + ); + } this.raise(startLoc, word + " is a reserved word"); } + + if ( + this.state.strict && + (isStrictReservedWord(word) || + (isBinding && isStrictBindReservedWord(word))) + ) { + this.raise(startLoc, word + " is a reserved word in strict mode"); + } } // Parses await expression inside async function. - parseAwait(node: N.AwaitExpression): N.AwaitExpression { - // istanbul ignore next: this condition is checked at the call site so won't be hit here + parseAwait(): N.AwaitExpression { + const node = this.startNode(); + if ( - !this.state.inAsync && - (this.state.inFunction || !this.options.allowAwaitOutsideFunction) + this.state.maybeInArrowParameters && + // We only set yieldOrAwaitInPossibleArrowParameters if we haven't already + // found a possible invalid AwaitExpression. + !this.state.yieldOrAwaitInPossibleArrowParameters ) { - this.unexpected(); + this.state.yieldOrAwaitInPossibleArrowParameters = node; } + + this.next(); + if (this.state.inParameters) { this.raise( node.start, @@ -2048,14 +2056,6 @@ export default class ExpressionParser extends LValParser { "await* has been removed from the async functions proposal. Use Promise.all() instead.", ); } - if ( - this.state.maybeInArrowParameters && - // We only set yieldOrAwaitInPossibleArrowParameters if we haven't already - // found a possible invalid AwaitExpression. - !this.state.yieldOrAwaitInPossibleArrowParameters - ) { - this.state.yieldOrAwaitInPossibleArrowParameters = node; - } node.argument = this.parseMaybeUnary(); return this.finishNode(node, "AwaitExpression"); diff --git a/packages/babel-parser/src/parser/lval.js b/packages/babel-parser/src/parser/lval.js index 2d1f13ad2e..4781ed04b7 100644 --- a/packages/babel-parser/src/parser/lval.js +++ b/packages/babel-parser/src/parser/lval.js @@ -14,16 +14,14 @@ import type { SpreadElement, } from "../types"; import type { Pos, Position } from "../util/location"; +import { + isStrictReservedWord, + isStrictBindReservedWord, +} from "../util/identifier"; import { NodeUtils } from "./node"; export default class LValParser extends NodeUtils { // Forward-declaration: defined in expression.js - +checkReservedWord: ( - word: string, - startLoc: number, - checkKeywords: boolean, - isBinding: boolean, - ) => void; +parseIdentifier: (liberal?: boolean) => Identifier; +parseMaybeAssign: ( noIn?: ?boolean, @@ -224,22 +222,11 @@ export default class LValParser extends NodeUtils { return this.finishNode(node, "RestElement"); } - shouldAllowYieldIdentifier(): boolean { - return ( - this.match(tt._yield) && !this.state.strict && !this.state.inGenerator - ); - } - - parseBindingIdentifier(): Identifier { - return this.parseIdentifier(this.shouldAllowYieldIdentifier()); - } - // Parses lvalue (assignable) atom. parseBindingAtom(): Pattern { switch (this.state.type) { - case tt._yield: case tt.name: - return this.parseBindingIdentifier(); + return this.parseIdentifier(); case tt.bracketL: { const node = this.startNode(); @@ -347,7 +334,16 @@ export default class LValParser extends NodeUtils { ): void { switch (expr.type) { case "Identifier": - this.checkReservedWord(expr.name, expr.start, false, true); + if ( + this.state.strict && + (isStrictReservedWord(expr.name) || + isStrictBindReservedWord(expr.name)) + ) { + this.raise( + expr.start, + expr.name + " is a reserved word in strict mode", + ); + } if (checkClashes) { // we need to prefix this with an underscore for the cases where we have a key of diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 48578310a0..f7c4ff88ef 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -975,17 +975,9 @@ export default class StatementParser extends ExpressionParser { this.initFunction(node, isAsync); - if (this.match(tt.star)) { - node.generator = true; - this.next(); - } + node.generator = this.eat(tt.star); - if ( - isStatement && - !optionalId && - !this.match(tt.name) && - !this.match(tt._yield) - ) { + if (isStatement && !optionalId && !this.match(tt.name)) { this.unexpected(); } @@ -1002,8 +994,8 @@ export default class StatementParser extends ExpressionParser { this.state.inAsync = isAsync; this.state.inGenerator = node.generator; } - if (this.match(tt.name) || this.match(tt._yield)) { - node.id = this.parseBindingIdentifier(); + if (this.match(tt.name)) { + node.id = this.parseIdentifier(); } if (isStatement) { this.state.inAsync = isAsync; diff --git a/packages/babel-parser/src/tokenizer/index.js b/packages/babel-parser/src/tokenizer/index.js index b3ef098539..270614a16e 100644 --- a/packages/babel-parser/src/tokenizer/index.js +++ b/packages/babel-parser/src/tokenizer/index.js @@ -1360,7 +1360,6 @@ export default class Tokenizer extends LocationParser { // `tt.name`. if ( prevType === tt._return || - prevType === tt._yield || (prevType === tt.name && this.state.exprAllowed) ) { return lineBreak.test( diff --git a/packages/babel-parser/src/tokenizer/types.js b/packages/babel-parser/src/tokenizer/types.js index 07a85c30db..ea9f15c708 100644 --- a/packages/babel-parser/src/tokenizer/types.js +++ b/packages/babel-parser/src/tokenizer/types.js @@ -190,7 +190,6 @@ export const keywords = Object.create(null, { extends: makeKeywordProps("extends", { beforeExpr }), export: makeKeywordProps("export"), import: makeKeywordProps("import", { startsExpr }), - yield: makeKeywordProps("yield", { beforeExpr, startsExpr }), null: makeKeywordProps("null", { startsExpr }), true: makeKeywordProps("true", { startsExpr }), false: makeKeywordProps("false", { startsExpr }), diff --git a/packages/babel-parser/src/util/identifier.js b/packages/babel-parser/src/util/identifier.js index 631f9d0394..ce550ed1be 100644 --- a/packages/babel-parser/src/util/identifier.js +++ b/packages/babel-parser/src/util/identifier.js @@ -62,7 +62,6 @@ const keywords = new Set([ "extends", "export", "import", - "yield", "super", ]); diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/357/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/357/options.json index d295c5a3a3..c148ada0c7 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/357/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/357/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:0)" + "throws": "Can not use keyword 'await' outside an async function (1:0)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/359/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/359/options.json index dfa11a2d85..fa250ba921 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/359/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/359/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:6)" + "throws": "Can not use keyword 'await' outside an async function (1:6)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/361/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/361/options.json index 6a60772f96..fd81c5071d 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/361/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/361/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:8)" + "throws": "Can not use keyword 'await' outside an async function (1:8)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/363/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/363/options.json index e9917bc908..a72d4ab0ff 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/363/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/363/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:15)" + "throws": "Can not use keyword 'await' outside an async function (1:15)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/365/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/365/options.json index e703907857..18d9310bd1 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/365/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/365/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:9)" + "throws": "Can not use keyword 'await' outside an async function (1:9)" } diff --git a/packages/babel-parser/test/fixtures/es2015/uncategorised/367/options.json b/packages/babel-parser/test/fixtures/es2015/uncategorised/367/options.json index dfa11a2d85..fa250ba921 100644 --- a/packages/babel-parser/test/fixtures/es2015/uncategorised/367/options.json +++ b/packages/babel-parser/test/fixtures/es2015/uncategorised/367/options.json @@ -1,4 +1,4 @@ { "sourceType": "module", - "throws": "await is a reserved word (1:6)" + "throws": "Can not use keyword 'await' outside an async function (1:6)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/input.js b/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/input.js new file mode 100644 index 0000000000..49ee007baa --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/input.js @@ -0,0 +1,3 @@ +function* wrap() { + class A {*yield() {}} +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/output.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/output.json new file mode 100644 index 0000000000..c646340e65 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-class-wrapped/output.json @@ -0,0 +1,194 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "wrap" + }, + "name": "wrap" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "start": 23, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "id": { + "type": "Identifier", + "start": 29, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 11 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 31, + "end": 44, + "loc": { + "start": { + "line": 2, + "column": 12 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 32, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "static": false, + "kind": "method", + "key": { + "type": "Identifier", + "start": 33, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 19 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "computed": false, + "id": null, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 41, + "end": 43, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 24 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-function-declaration-inside-generator/options.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-function-declaration-inside-generator/options.json index f14f9cb540..37d7f62549 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/function-name-function-declaration-inside-generator/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-function-declaration-inside-generator/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (2:11)" + "throws": "Can not use 'yield' as identifier inside a generator (2:11)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-expression/options.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-expression/options.json index 9a7dc6156a..72f8d0e0e4 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-expression/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-expression/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:11)" + "throws": "Can not use 'yield' as identifier inside a generator (1:11)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/input.js b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/input.js new file mode 100644 index 0000000000..40ee514dea --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/input.js @@ -0,0 +1,3 @@ +function* wrap() { + ({*yield() {}}) +} diff --git a/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/output.json b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/output.json new file mode 100644 index 0000000000..6856b64eb1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/function-name-generator-wrapped/output.json @@ -0,0 +1,180 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "wrap" + }, + "name": "wrap" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 17, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 23, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "expression": { + "type": "ObjectExpression", + "start": 24, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 5 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 25, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "method": true, + "key": { + "type": "Identifier", + "start": 26, + "end": 31, + "loc": { + "start": { + "line": 2, + "column": 7 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 34, + "end": 36, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "body": [], + "directives": [] + } + } + ], + "extra": { + "parenthesized": true, + "parenStart": 23 + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/input.js b/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/input.js new file mode 100644 index 0000000000..da0a10b54a --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/input.js @@ -0,0 +1 @@ +function *f2() { () => yield / 1 } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/output.json b/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/output.json new file mode 100644 index 0000000000..7b6b61f8c0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/input-not-followed-by-regex/output.json @@ -0,0 +1,175 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "f2" + }, + "name": "f2" + }, + "generator": true, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 15, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 17, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 17, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BinaryExpression", + "start": 23, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "left": { + "type": "Identifier", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "operator": "/", + "right": { + "type": "NumericLiteral", + "start": 31, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator-method/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator-method/options.json index 9a7dc6156a..72f8d0e0e4 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator-method/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator-method/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:11)" + "throws": "Can not use 'yield' as identifier inside a generator (1:11)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator/options.json b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator/options.json index 6cd6ffe02c..dcab4205d3 100644 --- a/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator/options.json +++ b/packages/babel-parser/test/fixtures/es2015/yield/parameter-name-generator/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:13)" + "throws": "Can not use 'yield' as identifier inside a generator (1:13)" } diff --git a/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/input.js b/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/input.js new file mode 100644 index 0000000000..79676acd5f --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/input.js @@ -0,0 +1 @@ +var yield = 2 diff --git a/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/output.json b/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/output.json new file mode 100644 index 0000000000..b0139b0da8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/es2015/yield/yield-as-identifier/output.json @@ -0,0 +1,105 @@ +{ + "type": "File", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "yield" + }, + "name": "yield" + }, + "init": { + "type": "NumericLiteral", + "start": 12, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/options.json index 1bb312254c..022428647f 100644 --- a/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/options.json +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-async-function-expression-name/options.json @@ -1,3 +1,3 @@ { - "throws": "invalid use of await inside of an async function (1:16)" + "throws": "Can not use 'await' as identifier inside an async function (1:16)" } diff --git a/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/options.json b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/options.json index 1eadbc9edb..d45274982d 100644 --- a/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/options.json +++ b/packages/babel-parser/test/fixtures/es2017/async-functions/await-function-declaration-name-inside-async-function/options.json @@ -1,3 +1,3 @@ { - "throws": "invalid use of await inside of an async function (2:11)" + "throws": "Can not use 'await' as identifier inside an async function (2:11)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-catch/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-catch/options.json index f6b6c33f1a..8c287a1d5b 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-catch/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-catch/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:30)" + "throws": "Can not use 'yield' as identifier inside a generator (1:30)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-declaration/options.json index afe3c715ca..3ceff8546d 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:26)" + "throws": "Can not use 'yield' as identifier inside a generator (1:26)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-export-default/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-export-default/options.json index afbed324e9..b5a3c5be23 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-export-default/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-export-default/options.json @@ -1,3 +1,4 @@ { - "throws": "'import' and 'export' may appear only with 'sourceType: \"module\"' (1:0)" + "sourceType": "module", + "throws": "yield is a reserved word in strict mode (1:25)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json index 5dcc4a8923..c32eaf81f2 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-name/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:10)" + "throws": "Can not use 'yield' as identifier inside a generator (1:10)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json index 0db4ce4adc..28b7349106 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-parameter/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:12)" + "throws": "Can not use 'yield' as identifier inside a generator (1:12)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json index c689509a34..aef4d7f4f9 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-expression-rest/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:18)" + "throws": "Can not use 'yield' as identifier inside a generator (1:18)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-function-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-function-declaration/options.json index c6514361e1..6993832643 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-function-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-function-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:25)" + "throws": "Can not use 'yield' as identifier inside a generator (1:25)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-lexical-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-lexical-declaration/options.json index f5e8c7d85f..ad818f81f1 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-lexical-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-lexical-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:20)" + "throws": "Can not use 'yield' as identifier inside a generator (1:20)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json index 0db4ce4adc..28b7349106 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-parameter/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:12)" + "throws": "Can not use 'yield' as identifier inside a generator (1:12)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json index 3d2ca09a60..c811689d9a 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-rest/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:24)" + "throws": "Can not use 'yield' as identifier inside a generator (1:24)" } diff --git a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-variable-declaration/options.json b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-variable-declaration/options.json index f5e8c7d85f..ad818f81f1 100644 --- a/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-variable-declaration/options.json +++ b/packages/babel-parser/test/fixtures/esprima/es2015-yield/invalid-yield-generator-variable-declaration/options.json @@ -1,3 +1,3 @@ { - "throws": "yield is a reserved word inside generator functions (1:20)" + "throws": "Can not use 'yield' as identifier inside a generator (1:20)" } diff --git a/scripts/tests/test262/test262_whitelist.txt b/scripts/tests/test262/test262_whitelist.txt index 2ec29e8b03..dc9c15ac6d 100644 --- a/scripts/tests/test262/test262_whitelist.txt +++ b/scripts/tests/test262/test262_whitelist.txt @@ -649,7 +649,6 @@ language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-let.js language/block-scope/syntax/redeclaration/var-redeclaration-attempt-after-let.js(strict mode) language/expressions/assignment/destructuring/obj-prop-__proto__dup.js(default) language/expressions/assignment/destructuring/obj-prop-__proto__dup.js(strict mode) -language/expressions/assignment/dstr/obj-id-identifier-yield-ident-valid.js(default) language/expressions/async-arrow-function/await-as-param-ident-nested-arrow-parameter-position.js(default) language/expressions/async-arrow-function/await-as-param-ident-nested-arrow-parameter-position.js(strict mode) language/expressions/async-arrow-function/await-as-param-nested-arrow-parameter-position.js(default) @@ -795,8 +794,6 @@ language/expressions/object/method-definition/private-name-early-error-gen-insid language/expressions/object/method-definition/private-name-early-error-gen-inside-class.js(strict mode) language/expressions/object/method-definition/private-name-early-error-method-inside-class.js(default) language/expressions/object/method-definition/private-name-early-error-method-inside-class.js(strict mode) -language/expressions/object/yield-non-strict-access.js(default) -language/expressions/object/yield-non-strict-syntax.js(default) language/expressions/postfix-decrement/arguments-nostrict.js(default) language/expressions/postfix-decrement/eval-nostrict.js(default) language/expressions/postfix-increment/arguments-nostrict.js(default) @@ -1150,7 +1147,6 @@ language/statements/for-of/dstr/array-rest-before-elision.js(default) language/statements/for-of/dstr/array-rest-before-elision.js(strict mode) language/statements/for-of/dstr/array-rest-elision-invalid.js(default) language/statements/for-of/dstr/array-rest-elision-invalid.js(strict mode) -language/statements/for-of/dstr/obj-id-identifier-yield-ident-valid.js(default) language/statements/for-of/head-const-bound-names-dup.js(default) language/statements/for-of/head-const-bound-names-dup.js(strict mode) language/statements/for-of/head-const-bound-names-in-stmt.js(default) @@ -1170,8 +1166,6 @@ language/statements/for/head-let-bound-names-in-stmt.js(strict mode) language/statements/function/dflt-params-duplicates.js(default) language/statements/generators/dflt-params-duplicates.js(default) language/statements/labeled/let-identifier-with-newline.js(default) -language/statements/labeled/value-yield-non-strict-escaped.js(default) -language/statements/labeled/value-yield-non-strict.js(default) language/statements/let/redeclaration-error-from-within-strict-mode-function.js(default) language/statements/switch/syntax/redeclaration/async-function-name-redeclaration-attempt-with-async-function.js(default) language/statements/switch/syntax/redeclaration/async-function-name-redeclaration-attempt-with-async-function.js(strict mode)