Skip to content

Commit

Permalink
Prevent tokenizer from getting confused by yield outside of a generator
Browse files Browse the repository at this point in the history
By using information the parser has. Not ideal, won't work for the
plain tokenizer, but so it goes.

Closes acornjs#552
  • Loading branch information
marijnh committed Sep 11, 2018
1 parent 1a07466 commit 22585b1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,12 @@ pp.parseExpression = function(noIn, refDestructuringErrors) {
// operators like `+=`.

pp.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
if (this.inGenerator && this.isContextual("yield")) return this.parseYield()
if (this.isContextual("yield")) {
if (this.inGenerator) return this.parseYield()
// The tokenizer will assume an expression is allowed after
// `yield`, but this isn't that kind of yield
else this.exprAllowed = false
}

let ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1
if (refDestructuringErrors) {
Expand Down
2 changes: 2 additions & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -16247,3 +16247,5 @@ test("function f() { var x; function x() {} }", {}, {ecmaVersion: 6, sourceType:
test("a.of / 2", {}, {ecmaVersion: 6})

test("let x = 1; x = 2", {}, {ecmaVersion: 6})

test("function *f2() { () => yield / 1 }", {}, {ecmaVersion: 6})

0 comments on commit 22585b1

Please sign in to comment.