Skip to content

Commit 2dded4b

Browse files
committed
Forbid 'new super()'
FIX: Disallow `new super()` expressions. Closes #1431
1 parent 77b3325 commit 2dded4b

2 files changed

Lines changed: 3 additions & 0 deletions

File tree

acorn/src/expression.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,8 @@ pp.parseNew = function() {
719719
}
720720
let startPos = this.start, startLoc = this.startLoc
721721
node.callee = this.parseSubscripts(this.parseExprAtom(null, false, true), startPos, startLoc, true, false)
722+
if (node.callee.type === "Super" && node.callee.start === startPos)
723+
this.raiseRecoverable(startPos, "Invalid use of 'super'")
722724
if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, this.options.ecmaVersion >= 8, false)
723725
else node.arguments = empty
724726
return this.finishNode(node, "NewExpression")

test/tests-harmony.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16430,6 +16430,7 @@ testFail("class A extends B { constructor() { super } }", "Unexpected token (1:4
1643016430
testFail("class A extends B { constructor() { super; } }", "Unexpected token (1:41)", { ecmaVersion: 6 })
1643116431
testFail("class A extends B { constructor() { (super)() } }", "Unexpected token (1:42)", { ecmaVersion: 6 })
1643216432
testFail("class A extends B { foo() { (super).foo } }", "Unexpected token (1:34)", { ecmaVersion: 6 })
16433+
testFail("class A extends B { constructor() { new super() } }", "Invalid use of 'super' (1:40)", {ecmaVersion: 6})
1643316434
test("({super: 1})", {}, { ecmaVersion: 6 })
1643416435
test("import {super as a} from 'a'", {}, { ecmaVersion: 6, sourceType: "module" })
1643516436
test("function a() {} export {a as super}", {}, { ecmaVersion: 6, sourceType: "module" })

0 commit comments

Comments
 (0)