Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
babel-plugin-transform-private
Advanced tools
This is a plugin provide private fields in ES6+ class. It's not like [ECMAScript Private Fields](https://github.com/tc39/proposal-private-fields) proposal but automatically transform any field which starts with '_' into a private field.
This is a plugin provide private fields in ES6+ class. It's not like ECMAScript Private Fields proposal but automatically transform any field which starts with '_' into a private field.
npm i babel-plugin-transform-private --save-dev
Config .babelrc
or package.json
{
"plugins": [
["transform-private", {
"pattern": "^_"
}],
]
}
input:
export default class Point2D{
constructor(x, y){
this._x = x;
this._y = y;
}
get XY(){
return [this._x, this._y];
}
get length(){
return Math.sqrt(this._x * this._x + this._y * this._y);
}
}
output:
const Point2D = function () {
const [$_x$, $_y$] = [Symbol("$_x$"), Symbol("$_y$")];
class Point2D {
constructor(x, y) {
this[$_x$] = x;
this[$_y$] = y;
}
get XY() {
return [this[$_x$], this[$_y$]];
}
get length() {
return Math.sqrt(this[$_x$] * this[$_x$] + this[$_y$] * this[$_y$]);
}
}
return Point2D;
}();
export default Point2D;
input:
export default class Outer {
constructor(){
this._inner = class Inner{
constructor(x){
this._x = x;
}
get X(){
return this._x;
}
}
}
get innerCls(){
return this._inner;
}
}
output:
const Outer = function () {
const [$_inner$] = [Symbol("$_inner$")];
class Outer {
constructor() {
this[$_inner$] = function () {
const [$_x$] = [Symbol("$_x$")];
return class Inner {
constructor(x) {
this[$_x$] = x;
}
get X() {
return this[$_x$];
}
};
}();
}
get innerCls() {
return this[$_inner$];
}
}
return Outer;
}();
export default Outer;
A method or a getter starts with '_' will be transforme to protected field. That means it can be accessed using super
keyword.
input:
export const Foo = class {
constructor(x, y){
this._x = x;
this._y = y;
this._zz = x + y;
}
//protected filed
get _z(){
return this._zz;
}
}
export const Bar = class extends Foo{
constructor(x, y){
super(x * 2, y * 3);
}
get z(){
return super._z; //get x*2+y*3
}
get z2(){
return super._zz; //undefined
}
}
output:
export const Foo = function () {
const [$_x$, $_y$, $_zz$, $_z$] = [Symbol("$_x$"), Symbol("$_y$"), Symbol("$_zz$"), Symbol("$_z$")];
return class {
constructor(x, y) {
this[$_x$] = x;
this[$_y$] = y;
this[$_zz$] = x + y;
}
get [$_z$]() {
return this[$_zz$];
}
};
}();
export const Bar = class extends Foo {
constructor(x, y) {
super(x * 2, y * 3);
}
get z() {
return super[Object.getOwnPropertySymbols(this.__proto__.__proto__).filter(s => String(s) === "Symbol($_z$)")[0]];
}
get z2() {
return super[Object.getOwnPropertySymbols(this.__proto__.__proto__).filter(s => String(s) === "Symbol($_zz$)")[0]];
}
};
FAQs
This is a plugin provide private fields in ES6+ class. It's not like [ECMAScript Private Fields](https://github.com/tc39/proposal-private-fields) proposal but automatically transform any field which starts with '_' into a private field.
We found that babel-plugin-transform-private demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.