🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

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

Package Overview
Dependencies
Maintainers
4
Versions
119
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

to
7.22.10

3

lib/decorators.js

@@ -13,3 +13,4 @@ "use strict";

function hasOwnDecorators(node) {
return !!(node.decorators && node.decorators.length);
var _node$decorators;
return !!((_node$decorators = node.decorators) != null && _node$decorators.length);
}

@@ -16,0 +17,0 @@ function hasDecorators(node) {

@@ -664,3 +664,3 @@ "use strict";

};
function replaceThisContext(path, ref, getSuperRef, file, isStaticBlock, constantSuper, innerBindingRef) {
function replaceThisContext(path, ref, innerBindingRef) {
var _state$classRef;

@@ -672,18 +672,6 @@ const state = {

};
const replacer = new _helperReplaceSupers.default({
methodPath: path,
constantSuper,
file,
refToPreserve: ref,
getSuperRef,
getObjectRef() {
state.needsClassRef = true;
return _core.types.isStaticBlock != null && _core.types.isStaticBlock(path.node) || path.node.static ? ref : _core.types.memberExpression(ref, _core.types.identifier("prototype"));
}
});
replacer.replace();
if (isStaticBlock || path.isProperty()) {
if (!path.isMethod()) {
path.traverse(thisContextVisitor, state);
}
if (innerBindingRef != null && (_state$classRef = state.classRef) != null && _state$classRef.name && state.classRef.name !== (innerBindingRef == null ? void 0 : innerBindingRef.name)) {
if (innerBindingRef != null && (_state$classRef = state.classRef) != null && _state$classRef.name && state.classRef.name !== innerBindingRef.name) {
path.traverse(innerReferencesVisitor, state);

@@ -710,4 +698,5 @@ }

}
function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, state, setPublicClassFields, privateFieldsAsProperties, constantSuper, innerBindingRef) {
let needsClassRef = false;
function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, file, setPublicClassFields, privateFieldsAsProperties, constantSuper, innerBindingRef) {
var _ref, _ref2;
let classRefFlags = 0;
let injectSuperRef;

@@ -717,2 +706,3 @@ const staticNodes = [];

const pureStaticNodes = [];
let classBindingNode = null;
const getSuperRef = _core.types.isIdentifier(superRef) ? () => superRef : () => {

@@ -723,2 +713,4 @@ var _injectSuperRef;

};
const classRefForInnerBinding = (_ref = ref) != null ? _ref : props[0].scope.generateUidIdentifier("class");
(_ref2 = ref) != null ? _ref2 : ref = _core.types.cloneNode(innerBindingRef);
for (const prop of props) {

@@ -733,5 +725,23 @@ prop.isClassProperty() && ts.assertFieldTransformed(prop);

const isStaticBlock = prop.isStaticBlock == null ? void 0 : prop.isStaticBlock();
if (isStatic) classRefFlags |= 1;
if (isStatic || isMethod && isPrivate || isStaticBlock) {
const replaced = replaceThisContext(prop, ref, getSuperRef, state, isStaticBlock, constantSuper, innerBindingRef);
needsClassRef = needsClassRef || replaced;
new _helperReplaceSupers.default({
methodPath: prop,
constantSuper,
file: file,
refToPreserve: innerBindingRef,
getSuperRef,
getObjectRef() {
classRefFlags |= 2;
if (isStatic || isStaticBlock) {
return classRefForInnerBinding;
} else {
return _core.types.memberExpression(classRefForInnerBinding, _core.types.identifier("prototype"));
}
}
}).replace();
const replaced = replaceThisContext(prop, classRefForInnerBinding, innerBindingRef);
if (replaced) {
classRefFlags |= 2;
}
}

@@ -750,7 +760,5 @@ switch (true) {

case isStatic && isPrivate && isField && privateFieldsAsProperties:
needsClassRef = true;
staticNodes.push(buildPrivateFieldInitLoose(_core.types.cloneNode(ref), prop, privateNamesMap));
break;
case isStatic && isPrivate && isField && !privateFieldsAsProperties:
needsClassRef = true;
staticNodes.push(buildPrivateStaticFieldInitSpec(prop, privateNamesMap));

@@ -760,3 +768,2 @@ break;

if (!isNameOrLength(prop.node)) {
needsClassRef = true;
staticNodes.push(buildPublicFieldInitLoose(_core.types.cloneNode(ref), prop));

@@ -766,4 +773,3 @@ break;

case isStatic && isPublic && isField && !setPublicClassFields:
needsClassRef = true;
staticNodes.push(buildPublicFieldInitSpec(_core.types.cloneNode(ref), prop, state));
staticNodes.push(buildPublicFieldInitSpec(_core.types.cloneNode(ref), prop, file));
break;

@@ -774,3 +780,3 @@ case isInstance && isPrivate && isField && privateFieldsAsProperties:

case isInstance && isPrivate && isField && !privateFieldsAsProperties:
instanceNodes.push(buildPrivateInstanceFieldInitSpec(_core.types.thisExpression(), prop, privateNamesMap, state));
instanceNodes.push(buildPrivateInstanceFieldInitSpec(_core.types.thisExpression(), prop, privateNamesMap, file));
break;

@@ -782,7 +788,6 @@ case isInstance && isPrivate && isMethod && privateFieldsAsProperties:

case isInstance && isPrivate && isMethod && !privateFieldsAsProperties:
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(_core.types.thisExpression(), prop, privateNamesMap, state));
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(_core.types.thisExpression(), prop, privateNamesMap, file));
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties));
break;
case isStatic && isPrivate && isMethod && !privateFieldsAsProperties:
needsClassRef = true;
staticNodes.unshift(buildPrivateStaticFieldInitSpec(prop, privateNamesMap));

@@ -792,4 +797,3 @@ pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties));

case isStatic && isPrivate && isMethod && privateFieldsAsProperties:
needsClassRef = true;
staticNodes.unshift(buildPrivateStaticMethodInitLoose(_core.types.cloneNode(ref), prop, state, privateNamesMap));
staticNodes.unshift(buildPrivateStaticMethodInitLoose(_core.types.cloneNode(ref), prop, file, privateNamesMap));
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties));

@@ -801,3 +805,3 @@ break;

case isInstance && isPublic && isField && !setPublicClassFields:
instanceNodes.push(buildPublicFieldInitSpec(_core.types.thisExpression(), prop, state));
instanceNodes.push(buildPublicFieldInitSpec(_core.types.thisExpression(), prop, file));
break;

@@ -808,2 +812,5 @@ default:

}
if (classRefFlags & 2 && innerBindingRef != null) {
classBindingNode = _core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(classRefForInnerBinding), _core.types.cloneNode(innerBindingRef)));
}
return {

@@ -813,2 +820,3 @@ staticNodes: staticNodes.filter(Boolean),

pureStaticNodes: pureStaticNodes.filter(Boolean),
classBindingNode,
wrapClass(path) {

@@ -825,10 +833,18 @@ for (const prop of props) {

}
if (!needsClassRef) return path;
if (path.isClassExpression()) {
path.scope.push({
id: ref
});
path.replaceWith(_core.types.assignmentExpression("=", _core.types.cloneNode(ref), path.node));
} else if (!path.node.id) {
path.node.id = ref;
if (classRefFlags !== 0) {
if (path.isClassExpression()) {
path.scope.push({
id: ref
});
path.replaceWith(_core.types.assignmentExpression("=", _core.types.cloneNode(ref), path.node));
} else {
if (innerBindingRef == null) {
path.node.id = ref;
}
if (classBindingNode != null) {
path.scope.push({
id: classRefForInnerBinding
});
}
}
}

@@ -835,0 +851,0 @@ return path;

@@ -87,8 +87,8 @@ "use strict";

if (typeof file.get(versionKey) === "number") {
file.set(versionKey, "7.22.9");
file.set(versionKey, "7.22.10");
return;
}
}
if (!file.get(versionKey) || _semver.lt(file.get(versionKey), "7.22.9")) {
file.set(versionKey, "7.22.9");
if (!file.get(versionKey) || _semver.lt(file.get(versionKey), "7.22.10")) {
file.set(versionKey, "7.22.10");
}

@@ -100,5 +100,7 @@ },

}) {
if (file.get(versionKey) !== "7.22.9") return;
var _ref;
if (file.get(versionKey) !== "7.22.10") return;
if (!(0, _features.shouldTransform)(path, file)) return;
if (path.isClassDeclaration()) (0, _typescript.assertFieldTransformed)(path);
const pathIsClassDeclaration = path.isClassDeclaration();
if (pathIsClassDeclaration) (0, _typescript.assertFieldTransformed)(path);
const loose = (0, _features.isLoose)(file, feature);

@@ -157,11 +159,10 @@ let constructor;

let ref;
if (!innerBinding || path.isClassExpression()) {
if (!innerBinding || !pathIsClassDeclaration) {
(0, _helperFunctionName.default)(path);
ref = path.scope.generateUidIdentifier("class");
} else {
ref = _core.types.cloneNode(path.node.id);
}
const classRefForDefine = (_ref = ref) != null ? _ref : _core.types.cloneNode(innerBinding);
const privateNamesMap = (0, _fields.buildPrivateNamesMap)(props);
const privateNamesNodes = (0, _fields.buildPrivateNamesNodes)(privateNamesMap, privateFieldsAsProperties != null ? privateFieldsAsProperties : loose, privateFieldsAsSymbols != null ? privateFieldsAsSymbols : false, file);
(0, _fields.transformPrivateNamesUsage)(ref, path, privateNamesMap, {
(0, _fields.transformPrivateNamesUsage)(classRefForDefine, path, privateNamesMap, {
privateFieldsAsProperties: privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose,

@@ -171,3 +172,3 @@ noDocumentAll,

}, file);
let keysNodes, staticNodes, instanceNodes, pureStaticNodes, wrapClass;
let keysNodes, staticNodes, instanceNodes, pureStaticNodes, classBindingNode, wrapClass;
{

@@ -179,3 +180,3 @@ if (isDecorated) {

wrapClass
} = (0, _decorators.buildDecoratedClass)(ref, path, elements, file));
} = (0, _decorators.buildDecoratedClass)(classRefForDefine, path, elements, file));
} else {

@@ -187,2 +188,3 @@ keysNodes = (0, _misc.extractComputedKeys)(path, computedPaths, file);

instanceNodes,
classBindingNode,
wrapClass

@@ -211,2 +213,5 @@ } = (0, _fields.buildFieldsInitNodes)(ref, path.node.superClass, props, privateNamesMap, file, setPublicClassFields != null ? setPublicClassFields : loose, privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose, constantSuper != null ? constantSuper : loose, innerBinding));

}
if (classBindingNode != null && pathIsClassDeclaration) {
wrappedPath.insertAfter(classBindingNode);
}
},

@@ -217,3 +222,3 @@ ExportDefaultDeclaration(path, {

{
if (file.get(versionKey) !== "7.22.9") return;
if (file.get(versionKey) !== "7.22.10") return;
const decl = path.get("declaration");

@@ -220,0 +225,0 @@ if (decl.isClassDeclaration() && (0, _decorators.hasDecorators)(decl.node)) {

{
"name": "@babel/helper-create-class-features-plugin",
"version": "7.22.9",
"version": "7.22.10",
"author": "The Babel Team (https://babel.dev/team)",

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

"devDependencies": {
"@babel/core": "^7.22.9",
"@babel/core": "^7.22.10",
"@babel/helper-plugin-test-runner": "^7.22.5",
"@babel/plugin-syntax-class-static-block": "^7.14.5",
"@babel/preset-env": "^7.22.9"
"@babel/preset-env": "^7.22.10"
},

@@ -41,0 +41,0 @@ "engines": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet