babel-plugin-remove-decorators

Babel plugin to remove all decorators from the code.

Usage no npm install needed!

<script type="module">
  import babelPluginRemoveDecorators from 'https://cdn.skypack.dev/babel-plugin-remove-decorators';
</script>

README

babel-plugin-remove-decorators

A babel plugin that removes all decorators from the code. This is useful for testing purposes. It allows you to unit test the code that has decorators attached to it.

Example

Turns this:

function classDec (){};
function methodDec (){};

@classDec
class DecoratedClass {
    @methodFoo(true)
    method() { }
}

into this:

function classDec (){};
function methodDec (){};

class DecoratedClass {
    method() { }
}

Usage

Install via NPM

$ npm install --save-dev babel-plugin-remove-decorators

See Babel's documentation on plugins.

! Ensure that you have ES7 decorator support enabled.

! You need to use the plugin with the before position specifier.

.babelrc example:

{
  "optional": ["es7.decorators"],
  "plugins": ["babel-plugin-remove-decorator:before"]
}

Run tests

$ npm test