0.1.0 • Published 3 years ago
babel-plugin-transform-private-class-members v0.1.0
babel-plugin-transform-private-class-members
Mangle JavaScript private class members.
Installation
$ npm install babel-plugin-transform-private-class-members
Usage
Via .babelrc
(Recommended)
.babelrc
{
"plugins": ["babel-plugin-transform-private-class-members"]
}
Via CLI
$ babel --plugins babel-plugin-transform-private-class-members script.js
Via Node API
require("babel-core").transform("code", {
plugins: ["babel-plugin-transform-private-class-members"]
});
Example
Input file:
class Rectangle {
result = null;
constructor(height, width) {
this._height = height;
this._width = width;
}
area() {
if (this.result === null) {
this.result = this._calcArea();
}
return this.result;
}
_calcArea() {
return this._height * this._width;
}
}
Output:
class Rectangle {
result = null;
constructor(height, width) {
this.$1 = height;
this.$2 = width;
}
area() {
if (this.result === null) {
this.result = this.$3();
}
return this.result;
}
$3() {
return this.$1 * this.$2;
}
}
Options
Option | Description | Default |
---|---|---|
blacklist | A RegEx defining which members to ignore | [ /^_super./, /^_.*/, /^$/, /^^_.*/ ] |
memoize | Keep mangle position and keys for another transform | false |
onlyClass | Replace only private class members and properties | true |
License
This plugin is licensed under the MIT license. See LICENSE.
0.1.0
3 years ago