babel-plugin-native-error-extend

Babel plugin for native `Error` extending.

MIT 6 个版本
安装
npm install babel-plugin-native-error-extend
yarn add babel-plugin-native-error-extend
pnpm add babel-plugin-native-error-extend
bun add babel-plugin-native-error-extend
README

babel-plugin-native-error-extend

Build Status

Babel plugin for native Error extending.

Handles all ususal cases such as classic extend and constructor override.

Install

npm install babel-plugin-native-error-extend --save

Usage

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.

Acknowledgments

License

MIT © Ivan Nikolić

版本列表
2.1.1 2023-08-22
2.1.0 2023-07-03
2.0.2 2020-12-08
2.0.1 2020-11-19
2.0.0 2020-11-06
1.0.0 2020-08-12