Babel plugin for native `Error` extending.
npm install babel-plugin-native-error-extend[![Build Status][ci-img]][ci]
Babel plugin for native Error extending.
Handles all ususal cases such as classic extend and constructor override.
``sh`
npm install babel-plugin-native-error-extend --save
Use it via available [plugin activation options][babel-plugins].
For .babelrc file:
`json`
{
"plugins": ["babel-plugin-native-error-extend"]
}
Then, in your code:
`js
/ 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.
- extendable-error-class
- custom-error-class
- extensible-error
- es6-error`
MIT © Ivan Nikolić
[ci]: https://github.com/niksy/babel-plugin-native-error-extend/actions?query=workflow%3ACI
[ci-img]: https://github.com/niksy/babel-plugin-native-error-extend/workflows/CI/badge.svg?branch=master
[babel-plugins]: http://babeljs.io/docs/plugins/