-
Notifications
You must be signed in to change notification settings - Fork 19
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
instanceof doesn't work #14
Comments
Got an example of your configuration? It should work. |
export default class ValidationError extends Error {
constructor(invalidations) {
super('Invalid input');
this.invalidations = invalidations;
this.name = 'ValidationError';
}
} try {
throw new ValidationError(['message']);
} catch(error) {
if (error instanceof ValidationError) {
console.log('ok');
} else {
throw error;
}
}
|
That example prints |
It works fine for me in Node, but not in browser |
@panganibanpj I need example code and info about your config, like I asked above. |
In my case it has something to do with using "babel-preset-env" too. Here's some package.json:
Here's the full example: extend-error.zip |
My guess would be that your usage of the It's a pain and unfortunate, but I don't think there's anything that I can explicitly do in this plugin to change that. If you're using |
I thought so too but I just tried with a different preset ( I think it's something to do with using the
I'm ok with this issue being outside the scope of this plugin, but if it would help others, I'm hoping we could track down what's going on here and mention something in the "Limitations" section of README like OP said. I've never built a plugin or preset for babel so I don't have any intuitions about this but I wouldn't mind looking into it. Any advice on where to look would be appreciated :) |
It's likely specifically the ordering between this plugin and the one that transforms class syntax, so
Right. That plugin doesn't break when the ordering changes because there isn't any dependent ordering. With this plugin, it needs to run before the classes are transformed. If you'd like to PR an update to the documentation, I'd be happy to accept it. I don't have a ton of time to focus on this plugin at the moment. |
See babel/babel#3083 for details. |
Hi! I have the same issue with the next config:
What am I doing wrong? Can you help me? |
I have same issues @sergej-s . It seems like istanbul plugin cause the issue. I add blow comment in my code. /* istanbul ignore next */ And it works. |
This should be mentioned under "Limitations" in the readme. The work-around is to compare with the
name
property instead.The text was updated successfully, but these errors were encountered: