├── .gitignore ├── README.md ├── babel-plugin-extends-error.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/ 2 | 1.js 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## `babel-plugin-extends-error` [![npm version](https://badge.fury.io/js/babel-plugin-extends-error.svg)](http://badge.fury.io/js/babel-plugin-extends-error) 2 | 3 | The problem: `extends Error`. The stack trace isn't available when your code is transpiled with babel. 4 | 5 | ### Installation 6 | ``` 7 | npm install babel-plugin-extends-error --save 8 | ``` 9 | 10 | It requires [es6-error](https://github.com/bjyoungblood/es6-error) installed on your side. Just `npm install es6-error --save` and you're good to go. This plugin simply detects if you're extending from `Error` and converts it to `ExtendableError`. 11 | -------------------------------------------------------------------------------- /babel-plugin-extends-error.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @author Andrey K. Vital 3 | */ 4 | module.exports = function(babel) { 5 | var t = babel.types 6 | 7 | return new babel.Plugin('babel-plugin-extends-error', { 8 | visitor: { 9 | ClassDeclaration: function(node, parent) { 10 | if (node.superClass && node.superClass.name === 'Error') { 11 | node.superClass = t.callExpression(t.identifier('require'), [ 12 | t.literal('es6-error') 13 | ]) 14 | } 15 | 16 | return node 17 | } 18 | } 19 | }) 20 | } 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babel-plugin-extends-error", 3 | "version": "1.0.0", 4 | "main": "babel-plugin-extends-error.js", 5 | "authors": [ 6 | { 7 | "name": "Andrey K. Vital", 8 | "email": "andreykvital@gmail.com" 9 | } 10 | ] 11 | } 12 | --------------------------------------------------------------------------------