babel-plugin-short-private-properties

1.0.1 • Public • Published

short-private-properties

This plugin find in ES6 Classes all methods or properties with start _ and replace them with a short name.

npm AppVeyor Travis

Install

yarn add -D babel-plugin-short-private-properties
# or npm i -D babel-plugin-short-private-properties 

Input:

class A {
  constructor() {
    this._veryLondProppertyNameA = "Test class A";
    this._veryLondProppertyNameA2 = "Write A";
  }
  _getAProperty() {
    console.log(this._veryLondProppertyNameA);
  }
}
 
class B extends A {
  constructor() {
    super();
    this._veryLondProppertyNameA2 = "Overwrite B";
    this._veryLondProppertyNameB = "Test class B";
  }
  getResult() {
    this._getAProperty();
    console.log(this._veryLondProppertyNameB);
    console.log(this._veryLondProppertyNameA2);
  }
}
 
new B().getResult();
// Test class A
// Test class B
// Overwrite B

Output:

class A {
  constructor() {
    this._b = "Test class A";
    this._c = "Write A";
  }
  _d() {
    console.log(this._b);
  }
}
 
class B extends A {
  constructor() {
    super();
    this._c = "Overwrite B";
    this._e = "Test class B";
  }
  getResult() {
    this._d();
    console.log(this._e);
    console.log(this._c);
  }
}
 
new B().getResult();
// Test class A
// Test class B
// Overwrite B

Usage

Via .babelrc (Recommended)

{
  "plugins": ["babel-plugin-short-private-properties"]
}

Via CLI

$ babel --plugins babel-plugin-short-private-properties script.js

Via Node API

require("babel-core").transform("code", {
  plugins: ["babel-plugin-short-private-properties"]
});

Readme

Keywords

none

Package Sidebar

Install

npm i babel-plugin-short-private-properties

Weekly Downloads

2

Version

1.0.1

License

MIT

Last publish

Collaborators

  • retyui