A small codemod to "undecorate" Class Declarations that have decorators, for use with JSCodeshift.
For more on why this was created, see my blog post: Undecorate Your Decorators
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
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:
@withParam('myParam')
@noParam
@taggedTemplate`my tagged template string`
class MyClass { }
const MyClass = withParam('myParam')(noParam(taggedTemplate`my tagged template string`(class MyClass { })));
- 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).
- react-codemod - For examples and where this repo structure is based off of.
- ASTExplorer - For an excellent playground.
- Yehuda Katz and Brian Terlson - For the decorator proposal, of course.