Class extending super-class with constructor not-containing `super()` is not caught
Closed this issue · 0 comments
overlookmotel commented
Input:
class S {}
export default class C extends S {
constructor() {}
};
Output:
const ObjectSetPrototypeOf = Object.setPrototypeOf,
S = class S {},
C = ObjectSetPrototypeOf(class C {
constructor() {}
}, S);
ObjectSetPrototypeOf(C.prototype, S.prototype);
export default C;
Attempting to construct C
in original throws error "ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor". Whereas in output, it does nothing.
This would need to be detected at runtime. It's possible for super()
to be present in the constructor without being called, so it's not possible to determine if it should be an error with static analysis. e.g.:
class C extends S { constructor() { let f = () => super(); } }
class C extends S { constructor(x) { if (x) super(); } }
class C extends S { constructor(x) { if (x) return; super(); } }
There are numerous problems with how super
is transpiled. Would be better to avoid transpiling it entirely (#48).