Skip to content

Commit

Permalink
fix for common syntax error in yield/await
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea authored and marijnh committed Sep 5, 2016
1 parent 7163d84 commit 2b82624
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/expression.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ pp.parseObj = function(isPattern, refDestructuringErrors) {
}

pp.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
if ((isGenerator || isAsync) && this.type === tt.colon)
this.unexpected()

if (this.eat(tt.colon)) {
prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc, null, refDestructuringErrors) : this.parseMaybeAssign(false, refDestructuringErrors)
prop.kind = "init"
Expand Down
3 changes: 3 additions & 0 deletions test/tests-asyncawait.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,9 @@ testFail("({async foo() { var await }})", "Can not use 'await' as identifier ins
testFail("({async foo(await) { }})", "Can not use 'await' as identifier inside an async function (1:12)", {ecmaVersion: 8})
testFail("({async foo() { return {await} }})", "Can not use 'await' as identifier inside an async function (1:24)", {ecmaVersion: 8})

// invalid syntax 'async foo: 1'
testFail("({async foo: 1})", "Unexpected token (1:11)", {ecmaVersion: 8})

//-----------------------------------------------------------------------------
// Async Methods (class)

Expand Down
3 changes: 3 additions & 0 deletions test/tests-harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -15059,3 +15059,6 @@ testFail("(function* yield() {})", "Can not use 'yield' as identifier inside a g
testFail("function* wrap() {\nfunction* yield() {}\n}", "Can not use 'yield' as identifier inside a generator (2:10)", {ecmaVersion: 6})
testFail("function* wrap() {\n({*yield() {}})\n}", "Can not use 'yield' as identifier inside a generator (2:3)", {ecmaVersion: 6})
testFail("function* wrap() {\nclass A {*yield() {}}\n}", "Can not use 'yield' as identifier inside a generator (2:10)", {ecmaVersion: 6})

// invalid syntax '*foo: 1'
testFail("({*foo: 1})", "Unexpected token (1:6)", {ecmaVersion: 6})

0 comments on commit 2b82624

Please sign in to comment.