Skip to content

tizmagik/undecorate-codemod

Repository files navigation

undecorate-codemod Build Status

A small codemod to "undecorate" Class Declarations that have decorators, for use with JSCodeshift.

Why?

For more on why this was created, see my blog post: Undecorate Your Decorators

Setup & Run

  • npm install -g jscodeshift
  • git clone https://github.com/tizmagik/undecorate-codemod.git
  • Run npm install in the undecorate-codemod directory (or, yarn)
  • jscodeshift -t undecorate-codemod/transforms/undecorate.js <path>
  • Use the -d option for a dry-run and use -p to print the output for comparison

What's Supported

This codemod undecorates Class Declarations, for any number of decorators and works whether or not the class is a named export, default export or not exported at all. For example:

Example input:

@withParam('myParam')
@noParam
@taggedTemplate`my tagged template string`
class MyClass { }

Converts to:

const MyClass = withParam('myParam')(noParam(taggedTemplate`my tagged template string`(class MyClass { })));

Things to be aware of

  • Only supports Class Declaration decorators. It does not (yet?) support Class Property decorators.
  • It does not "desugar" exactly according to the spec, instead it "undecorates". The difference being it tries to convert the code to what you probably would have written by hand if decorators weren't available (and you weren't using a currying library).

Credit & Thanks

About

Undecorate your ESNext decorated Classes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published