-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Babel generated Error subclass produces instance of Error rather than instance of subclass #4485
Comments
https://stackoverflow.com/questions/33870684/why-doesnt-instanceof-work-on-instances-of-error-subclasses-under-babel-node/33877501#33877501 should cover it. We mention it here in our Caveats: https://babeljs.io/docs/usage/caveats/#classes but if you have recommendations of a better place let us know. |
It's also interesting to note that somehow, it works in node 0.10 https://gist.github.com/forivall/88d8056d87bcc566a5d02ef837d772c6 I'm curious as to how that works, and this could be noted on the caveats page as well. As far as a better place, it could go in something like "known issues"? |
I would prefer if babel would just error and not compile on attempt to subclass built-ins that can't be. That being said I don't know if work required is worth the benefits. |
We can at least make an option for that (fail when subclassing built-ins) |
Try this as a workaround: class DDoSProtectionError extends Error {
constructor () {
super ()
// a workaround to make `instanceof DDoSProtectionError` work in ES5
this.constructor = DDoSProtectionError
this.__proto__ = DDoSProtectionError.prototype
}
} |
Almost year, the problem still exists. WTF? |
? You can use #4480 (comment) |
@nicolo-ribaudo That's awesome. Note that I just fixed this issue.
Now it works. |
Input Code
Babel Configuration (.bablerc, package.json, cli command)
https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015&experimental=true&loose=false&spec=false&playground=false&code=class%20ReadError%20extends%20Error%20%7B%7D%0A%0Aalert(new%20ReadError('Boom')%20instanceof%20ReadError)%20%2F%2F%20%3D%3E%20false
Expected Behavior
should alert
true
Current Behavior
alerts
false
The text was updated successfully, but these errors were encountered: