Socket
Socket
Sign inDemoInstall

@babel/helper-create-class-features-plugin

Package Overview
Dependencies
Maintainers
5
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/helper-create-class-features-plugin - npm Package Compare versions

Comparing version 7.5.5 to 7.6.0

4

lib/features.js

@@ -52,6 +52,2 @@ "use strict";

}
if (path.node.static && path.node.kind !== "method") {
throw path.buildCodeFrameError("@babel/plugin-class-features doesn't support class static private accessors yet.");
}
}

@@ -58,0 +54,0 @@

146

lib/fields.js

@@ -99,2 +99,3 @@ "use strict";

} = value;
const isAccessor = getId || setId;

@@ -106,3 +107,3 @@ if (loose) {

} else if (isMethod && !isStatic) {
if (getId || setId) {
if (isAccessor) {
initNodes.push(_core().template.statement.ast`var ${id} = new WeakMap();`);

@@ -206,5 +207,6 @@ } else {

} = privateNamesMap.get(name);
const isAccessor = getId || setId;
if (isStatic) {
const helperName = isMethod ? "classStaticPrivateMethodGet" : "classStaticPrivateFieldSpecGet";
const helperName = isMethod && !isAccessor ? "classStaticPrivateMethodGet" : "classStaticPrivateFieldSpecGet";
return _core().types.callExpression(file.addHelper(helperName), [this.receiver(member), _core().types.cloneNode(classRef), _core().types.cloneNode(id)]);

@@ -214,3 +216,3 @@ }

if (isMethod) {
if (getId || setId) {
if (isAccessor) {
return _core().types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), _core().types.cloneNode(id)]);

@@ -238,7 +240,9 @@ }

method: isMethod,
setId
setId,
getId
} = privateNamesMap.get(name);
const isAccessor = getId || setId;
if (isStatic) {
const helperName = isMethod ? "classStaticPrivateMethodSet" : "classStaticPrivateFieldSpecSet";
const helperName = isMethod && !isAccessor ? "classStaticPrivateMethodSet" : "classStaticPrivateFieldSpecSet";
return _core().types.callExpression(file.addHelper(helperName), [this.receiver(member), _core().types.cloneNode(classRef), _core().types.cloneNode(id), value]);

@@ -345,5 +349,27 @@ }

function buildPrivateStaticFieldInitSpec(prop, privateNamesMap) {
const privateName = privateNamesMap.get(prop.node.key.id.name);
const {
id
} = privateNamesMap.get(prop.node.key.id.name);
id,
getId,
setId,
initAdded
} = privateName;
const isAccessor = getId || setId;
if (!prop.isProperty() && (initAdded || !isAccessor)) return;
if (isAccessor) {
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, {
initAdded: true
}));
return _core().template.statement.ast`
var ${id.name} = {
// configurable is false by default
// enumerable is false by default
// writable is false by default
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
}
`;
}
const value = prop.node.value || prop.scope.buildUndefinedNode();

@@ -382,36 +408,17 @@ return _core().template.statement.ast`

if (getId || setId) {
const isAccessor = getId || setId;
if (isAccessor) {
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, {
initAdded: true
}));
if (getId && setId) {
return _core().template.statement.ast`
Object.defineProperty(${ref}, ${id}, {
// configurable is false by default
// enumerable is false by default
// writable is false by default
get: ${getId.name},
set: ${setId.name}
});
`;
} else if (getId && !setId) {
return _core().template.statement.ast`
Object.defineProperty(${ref}, ${id}, {
// configurable is false by default
// enumerable is false by default
// writable is false by default
get: ${getId.name}
});
`;
} else if (!getId && setId) {
return _core().template.statement.ast`
Object.defineProperty(${ref}, ${id}, {
// configurable is false by default
// enumerable is false by default
// writable is false by default
set: ${setId.name}
});
`;
}
return _core().template.statement.ast`
Object.defineProperty(${ref}, ${id}, {
// configurable is false by default
// enumerable is false by default
// writable is false by default
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
});
`;
}

@@ -429,28 +436,14 @@ }

if (initAdded) return;
const isAccessor = getId || setId;
if (getId || setId) {
if (isAccessor) {
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, {
initAdded: true
}));
if (getId && setId) {
return _core().template.statement.ast`
${id}.set(${ref}, {
get: ${getId.name},
set: ${setId.name}
});
`;
} else if (getId && !setId) {
return _core().template.statement.ast`
${id}.set(${ref}, {
get: ${getId.name}
});
`;
} else if (!getId && setId) {
return _core().template.statement.ast`
${id}.set(${ref}, {
set: ${setId.name}
});
`;
}
return _core().template.statement.ast`
${id}.set(${ref}, {
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
});
`;
}

@@ -480,6 +473,28 @@

function buildPrivateStaticMethodInitLoose(ref, prop, state, privateNamesMap) {
const privateName = privateNamesMap.get(prop.node.key.id.name);
const {
id,
methodId
} = privateNamesMap.get(prop.node.key.id.name);
methodId,
getId,
setId,
initAdded
} = privateName;
if (initAdded) return;
const isAccessor = getId || setId;
if (isAccessor) {
privateNamesMap.set(prop.node.key.id.name, Object.assign({}, privateName, {
initAdded: true
}));
return _core().template.statement.ast`
Object.defineProperty(${ref}, ${id}, {
// configurable is false by default
// enumerable is false by default
// writable is false by default
get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},
set: ${setId ? setId.name : prop.scope.buildUndefinedNode()}
})
`;
}
return _core().template.statement.ast`

@@ -632,3 +647,4 @@ Object.defineProperty(${ref}, ${id}, {

needsClassRef = true;
staticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, loose));
staticNodes.push(buildPrivateStaticFieldInitSpec(prop, privateNamesMap));
staticNodes.unshift(buildPrivateMethodDeclaration(prop, privateNamesMap, loose));
break;

@@ -638,4 +654,4 @@

needsClassRef = true;
staticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, loose));
staticNodes.push(buildPrivateStaticMethodInitLoose(_core().types.cloneNode(ref), prop, state, privateNamesMap));
staticNodes.unshift(buildPrivateMethodDeclaration(prop, privateNamesMap, loose));
break;

@@ -657,3 +673,3 @@

return {
staticNodes,
staticNodes: staticNodes.filter(Boolean),
instanceNodes: instanceNodes.filter(Boolean),

@@ -660,0 +676,0 @@

{
"name": "@babel/helper-create-class-features-plugin",
"version": "7.5.5",
"version": "7.6.0",
"author": "The Babel Team (https://babeljs.io/team)",

@@ -28,6 +28,6 @@ "license": "MIT",

"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/core": "^7.6.0",
"@babel/helper-plugin-test-runner": "^7.0.0"
},
"gitHead": "0407f034f09381b95e9cabefbf6b176c76485a43"
"gitHead": "cbd5a26e57758e3f748174ff84aa570e8780e85d"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc