Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zertosh/class-props-codemod
Transform old-style assigned static properties to class static properties
https://github.com/zertosh/class-props-codemod
Last synced: 16 days ago
JSON representation
Transform old-style assigned static properties to class static properties
- Host: GitHub
- URL: https://github.com/zertosh/class-props-codemod
- Owner: zertosh
- Created: 2015-12-21T02:06:44.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-17T16:49:47.000Z (almost 9 years ago)
- Last Synced: 2024-10-20T12:40:55.906Z (19 days ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 5
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-codemods - class-props-codemod - Transform old-style assigned static properties to class static properties. (JavaScript)
README
# class-props-codemod
Transform old-style assigned static properties to class static properties.
[![Build Status](https://travis-ci.org/zertosh/class-props-codemod.svg?branch=master)](https://travis-ci.org/zertosh/class-props-codemod)
## Usage
```sh
$ npm install -g jscodeshift
$ jscodeshift PATH_TO_SOURCE --transform PATH_TO_THIS_MODULE
```## Example
```js
// BEFORE:
class X {
method1() {}
}
X.foo = 42;// AFTER:
class X {
static foo = 42;
method1() {}
}
```## Caveats
* The transform is very conservative:
* If there are any other statements between the class definition and the assigned static properties, then it'll skip that class. Example:
```js
// This class will NOT be transformed
class X {}
someOtherStatement;
X.foo = 42;
```* If any assigned static properties reference the class in the same scope, then it'll skip that class. Example:
```js
// This class will NOT be transformed
class X {}
X.foo = 42;
X.bar = X.baz();// This class WILL BE transformed
class X {}
X.foo = 42;
X.bar = () => X.baz();
```* If a static property already exists with a name and a value, then it'll skip that class. If the static property exists, but it doesn't have a value, it will get transformed. Example:
```js
// This class will NOT be transformed
class X {
static foo = 43;
}
X.foo = 42;// This class WILL BE transformed
class X {
static foo: number;
}
X.foo = 42;
```* Newly created static properties are added to the class body in the order in which they're found. Either immediately before the first method definition or immediate after the first class property.