Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tizmagik/undecorate-codemod
Undecorate your ESNext decorated Classes
https://github.com/tizmagik/undecorate-codemod
Last synced: about 2 months ago
JSON representation
Undecorate your ESNext decorated Classes
- Host: GitHub
- URL: https://github.com/tizmagik/undecorate-codemod
- Owner: tizmagik
- License: mit
- Created: 2016-11-05T03:45:00.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-12-02T15:29:58.000Z (about 8 years ago)
- Last Synced: 2024-08-02T07:14:11.983Z (4 months ago)
- Language: JavaScript
- Size: 42 KB
- Stars: 16
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-codemods - undecorate-codemod - Transformers experimental ESNext decorators syntax to simple currying. (JavaScript)
- awesome-jscodeshift - undecorate-codemod - Transformers experimental ESNext decorators syntax to simple currying (Table of Contents / Codemods)
README
# undecorate-codemod [![Build Status](https://travis-ci.org/tizmagik/undecorate-codemod.svg)](https://travis-ci.org/tizmagik/undecorate-codemod)
A small codemod to "undecorate" Class Declarations that have [decorators](https://github.com/wycats/javascript-decorators), for use with [JSCodeshift](https://github.com/facebook/jscodeshift).
## Why?
For more on why this was created, see my blog post: [Undecorate Your Decorators](https://jeremygayed.com/undecorate-your-decorators-b7ce0196d32a#.d0qexlbjj)
## 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 `
* 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:
```js
@withParam('myParam')
@noParam
@taggedTemplate`my tagged template string`
class MyClass { }
```#### Converts to:
```js
const MyClass = withParam('myParam')(noParam(taggedTemplate`my tagged template string`(class MyClass { })));
```## Things to be aware of
- Only supports [Class Declaration](https://github.com/wycats/javascript-decorators#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
- [react-codemod](https://github.com/reactjs/react-codemod) - For examples and where this repo structure is based off of.
- [ASTExplorer](https://astexplorer.net) - For an excellent playground.
- [Yehuda Katz and Brian Terlson](https://github.com/tc39/proposals) - For the decorator proposal, of course.