Skip to content

Commit

Permalink
Fix: super is not PrimaryExpression
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed Oct 23, 2017
1 parent e70228b commit 0090c67
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/expression.js
Expand Up @@ -296,12 +296,22 @@ pp.parseExprAtom = function(refDestructuringErrors) {
case tt._super:
if (!this.inFunction)
this.raise(this.start, "'super' outside of function or class")
node = this.startNode()
this.next()
// The `super` keyword can appear at below:
// SuperProperty:
// super [ Expression ]
// super . IdentifierName
// SuperCall:
// super Arguments
if (this.type !== tt.dot && this.type !== tt.bracketL && this.type !== tt.parenL)
this.unexpected()
return this.finishNode(node, "Super")

case tt._this:
let type = this.type === tt._this ? "ThisExpression" : "Super"
node = this.startNode()
this.next()
return this.finishNode(node, type)
return this.finishNode(node, "ThisExpression")

case tt.name:
let startPos = this.start, startLoc = this.startLoc
Expand Down
8 changes: 8 additions & 0 deletions test/tests-harmony.js
Expand Up @@ -15792,3 +15792,11 @@ test("1 <!--b", {
}
}]
}, {ecmaVersion: 6, sourceType: "module"})

testFail("class A extends B { constructor() { super } }", "Unexpected token (1:42)", { ecmaVersion: 6 })
testFail("class A extends B { constructor() { super; } }", "Unexpected token (1:41)", { ecmaVersion: 6 })
testFail("class A extends B { constructor() { (super)() } }", "Unexpected token (1:42)", { ecmaVersion: 6 })
testFail("class A extends B { foo() { (super).foo } }", "Unexpected token (1:34)", { ecmaVersion: 6 })
test("({super: 1})", {}, { ecmaVersion: 6 })
test("import {super as a} from 'a'", {}, { ecmaVersion: 6, sourceType: "module" })
test("export {a as super}", {}, { ecmaVersion: 6, sourceType: "module" })

0 comments on commit 0090c67

Please sign in to comment.