GithubHelp home page GithubHelp logo

class-props-codemod's Introduction

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.

class-props-codemod's People

Contributors

zertosh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

class-props-codemod's Issues

TypeError: path must be a string

I have noticed the following error while parsing the source code of material-ui:

Processing 1 files...
Spawning 1 workers with 1 files each...
fs.js:263
  binding.open(pathModule._makeLong(path),
          ^

TypeError: path must be a string

This is because of this first error: Skipping path "src/**/**/**/*" which does not exist..
That's not really important. I just thought it would be great to let you know.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.