0.0.7 • Published 8 years ago

class-props-codemod v0.0.7

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

class-props-codemod

Transform old-style assigned static properties to class static properties.

Build Status

Usage

$ npm install -g jscodeshift
$ jscodeshift PATH_TO_SOURCE --transform PATH_TO_THIS_MODULE

Example

// 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:

        // 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:

        // 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:

        // 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.

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago