🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

class-props-codemod

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

class-props-codemod

Transform old-style assigned static properties to class static properties

latest
Source
npmnpm
Version
0.0.7
Version published
Weekly downloads
2
-71.43%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

codemod

FAQs

Package last updated on 17 Jan 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts