Skip to content

Make _classMembers 'private' using symbols

License

Notifications You must be signed in to change notification settings

jamiebuilds/babel-plugin-private-underscores

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

babel-plugin-private-underscores

Make _classMembers 'private' using symbols

Install

yarn add --dev babel-plugin-private-underscores

Example

Input

class Foo {
  constructor() {
    this._method();
  }

  _method() {
    // ...
  }
}

Output

let _method = Symbol('_method');
class Foo {
  constructor() {
    this[_method]();
  }

  [_method]() {
    // ...
  }
}

Usage

{
  "plugins": [
    "private-underscores"
  ]
}

Note: This is not real private, it just makes it a lot harder for people to accidentally use methods with underscores.