import {assert} from "./assert.js"
function isSyntaxError(src) {
try {
(0, eval)(src)
} catch (e) {
return e instanceof SyntaxError
}
return false
}
for (const body of [
"new super();",
"super(); new super(1, 2);",
"super(); new super;",
"(() => new super())();",
"super(); try { throw 1; } finally { switch (Object) { case new super(): } }",
]) {
assert(isSyntaxError(`class A extends Object { constructor() { ${body} } }`), true, body)
}
assert(isSyntaxError("class A extends Object { constructor(a = new super()) {} }"), true)
class K {
constructor(v) { this.v = v }
}
class B {}
B.prototype.K = K
class C extends B {
constructor() {
super()
this.a = new super.K(1)
this.b = new super["K"](2)
this.c = new super.K
}
}
const c = new C()
assert(c.a.v, 1)
assert(c.b.v, 2)
assert(c.c instanceof K, true)