Babel plugin for native Error
extending.
Handles all ususal cases such as classic extend and constructor
override.
npm install babel-plugin-native-error-extend --save
Use it via available plugin activation options.
For .babelrc
file:
{
"plugins": ["babel-plugin-native-error-extend"]
}
Then, in your code:
/* Before */
class Becky extends Error {}
/* After */
class Becky extends Error {
constructor(message, options) {
super(message, options);
this.name = this.constructor.name;
this.message = message;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = new Error(message).stack;
}
}
}
Check test fixtures (actual and expected) for more examples.
MIT © Ivan Nikolić