@babel/helper-create-class-features-plugin
Advanced tools
Comparing version 7.24.5 to 7.24.6
@@ -91,2 +91,7 @@ "use strict"; | ||
} | ||
function assignIdForAnonymousClass(path, className) { | ||
if (!path.node.id) { | ||
path.node.id = typeof className === "string" ? _core.types.identifier(className) : path.scope.generateUidIdentifier("Class"); | ||
} | ||
} | ||
function addProxyAccessorsFor(className, element, getterKey, setterKey, targetKey, isComputed, isStatic, version) { | ||
@@ -274,3 +279,3 @@ const thisArg = (version === "2023-11" || version === "2023-05") && isStatic ? className : _core.types.thisExpression(); | ||
} | ||
decs.push(decorators[i]); | ||
decs.push(decorators[i].expression); | ||
} | ||
@@ -439,5 +444,6 @@ return { | ||
const classIdName = (_path$node$id = path.node.id) == null ? void 0 : _path$node$id.name; | ||
const usesFunctionContextOrYieldAwait = expression => { | ||
const setClassName = typeof className === "object" ? className : undefined; | ||
const usesFunctionContextOrYieldAwait = decorator => { | ||
try { | ||
_core.types.traverseFast(expression, node => { | ||
_core.types.traverseFast(decorator, node => { | ||
if (_core.types.isThisExpression(node) || _core.types.isSuper(node) || _core.types.isYieldExpression(node) || _core.types.isAwaitExpression(node) || _core.types.isIdentifier(node, { | ||
@@ -510,2 +516,3 @@ name: "arguments" | ||
} | ||
assignIdForAnonymousClass(path, className); | ||
addProxyAccessorsFor(path.node.id, newPath, getterKey, setterKey, newId, computed, isStatic, version); | ||
@@ -518,2 +525,8 @@ } | ||
if (!classDecorators && !hasElementDecorators) { | ||
if (!path.node.id && typeof className === "string") { | ||
path.node.id = _core.types.identifier(className); | ||
} | ||
if (setClassName) { | ||
path.node.body.body.unshift(createStaticBlockFromExpressions([createSetFunctionNameCall(state, setClassName)])); | ||
} | ||
return; | ||
@@ -526,7 +539,10 @@ } | ||
let decoratorReceiverId = null; | ||
function handleDecoratorExpressions(expressions) { | ||
function handleDecorators(decorators) { | ||
let hasSideEffects = false; | ||
let usesFnContext = false; | ||
const decoratorsThis = []; | ||
for (const expression of expressions) { | ||
for (const decorator of decorators) { | ||
const { | ||
expression | ||
} = decorator; | ||
let object; | ||
@@ -547,3 +563,3 @@ if ((version === "2023-11" || version === "2023-05") && _core.types.isMemberExpression(expression)) { | ||
hasSideEffects || (hasSideEffects = !scopeParent.isStatic(expression)); | ||
usesFnContext || (usesFnContext = usesFunctionContextOrYieldAwait(expression)); | ||
usesFnContext || (usesFnContext = usesFunctionContextOrYieldAwait(decorator)); | ||
} | ||
@@ -570,15 +586,15 @@ return { | ||
path.node.decorators = null; | ||
const decoratorExpressions = classDecorators.map(el => el.expression); | ||
const classDecsUsePrivateName = decoratorExpressions.some(usesPrivateField); | ||
const classDecsUsePrivateName = classDecorators.some(usesPrivateField); | ||
const { | ||
hasSideEffects, | ||
usesFnContext, | ||
decoratorsThis | ||
} = handleDecoratorExpressions(decoratorExpressions); | ||
} = handleDecorators(classDecorators); | ||
const { | ||
haveThis, | ||
decs | ||
} = generateDecorationList(decoratorExpressions, decoratorsThis, version); | ||
} = generateDecorationList(classDecorators, decoratorsThis, version); | ||
classDecorationsFlag = haveThis ? 1 : 0; | ||
classDecorations = decs; | ||
if (hasSideEffects && willExtractSomeElemDecs || classDecsUsePrivateName) { | ||
if (usesFnContext || hasSideEffects && willExtractSomeElemDecs || classDecsUsePrivateName) { | ||
classDecorationsId = memoiseExpression(_core.types.arrayExpression(classDecorations), "classDecs", classAssignments); | ||
@@ -612,5 +628,3 @@ } | ||
} else { | ||
if (!path.node.id) { | ||
path.node.id = path.scope.generateUidIdentifier("Class"); | ||
} | ||
assignIdForAnonymousClass(path, className); | ||
classIdLocal = _core.types.cloneNode(path.node.id); | ||
@@ -650,3 +664,2 @@ } | ||
if (hasDecorators) { | ||
const decoratorExpressions = decorators.map(d => d.expression); | ||
const { | ||
@@ -656,7 +669,7 @@ hasSideEffects, | ||
decoratorsThis | ||
} = handleDecoratorExpressions(decoratorExpressions); | ||
} = handleDecorators(decorators); | ||
const { | ||
decs, | ||
haveThis | ||
} = generateDecorationList(decoratorExpressions, decoratorsThis, version); | ||
} = generateDecorationList(decorators, decoratorsThis, version); | ||
decoratorsHaveThis = haveThis; | ||
@@ -736,2 +749,3 @@ decoratorsArray = decs.length === 1 ? decs[0] : _core.types.arrayExpression(decs); | ||
} else { | ||
assignIdForAnonymousClass(path, className); | ||
addProxyAccessorsFor(path.node.id, newPath, _core.types.cloneNode(key), _core.types.isAssignmentExpression(key) ? _core.types.cloneNode(key.left) : _core.types.cloneNode(key), newId, isComputed, isStatic, version); | ||
@@ -986,3 +1000,3 @@ locals = [newFieldInitId]; | ||
} | ||
applyDecsBody.push(_core.types.expressionStatement(createLocalsAssignment(elementLocals, classLocals, elementDecorations, (_classDecorationsId = classDecorationsId) != null ? _classDecorationsId : _core.types.arrayExpression(classDecorations), _core.types.numericLiteral(classDecorationsFlag), needsInstancePrivateBrandCheck ? lastInstancePrivateName : null, typeof className === "object" ? className : undefined, _core.types.cloneNode(superClass), state, version))); | ||
applyDecsBody.push(_core.types.expressionStatement(createLocalsAssignment(elementLocals, classLocals, elementDecorations, (_classDecorationsId = classDecorationsId) != null ? _classDecorationsId : _core.types.arrayExpression(classDecorations), _core.types.numericLiteral(classDecorationsFlag), needsInstancePrivateBrandCheck ? lastInstancePrivateName : null, setClassName, _core.types.cloneNode(superClass), state, version))); | ||
if (staticInitLocal) { | ||
@@ -989,0 +1003,0 @@ applyDecsBody.push(_core.types.expressionStatement(_core.types.callExpression(_core.types.cloneNode(staticInitLocal), [_core.types.thisExpression()]))); |
@@ -179,3 +179,3 @@ "use strict"; | ||
if (!privateNamesMap.has(name)) return; | ||
if (redeclared && redeclared.includes(name)) return; | ||
if (redeclared != null && redeclared.includes(name)) return; | ||
this.handle(parentPath, noDocumentAll); | ||
@@ -215,3 +215,3 @@ } | ||
if (!privateNamesMap.has(name)) return; | ||
if (redeclared && redeclared.includes(name)) return; | ||
if (redeclared != null && redeclared.includes(name)) return; | ||
unshadow(this.classRef.name, path.scope, this.innerBinding); | ||
@@ -252,2 +252,7 @@ if (privateFieldsAsProperties) { | ||
} | ||
function autoInherits(fn) { | ||
return function (member) { | ||
return _core.types.inherits(fn.apply(this, arguments), member.node); | ||
}; | ||
} | ||
const privateNameHandlerSpec = { | ||
@@ -276,3 +281,3 @@ memoise(member, count) { | ||
}, | ||
get(member) { | ||
get: autoInherits(function (member) { | ||
const { | ||
@@ -285,5 +290,6 @@ classRef, | ||
} = this; | ||
const privateName = member.node.property; | ||
const { | ||
name | ||
} = member.node.property.id; | ||
} = privateName.id; | ||
const { | ||
@@ -298,2 +304,3 @@ id, | ||
const isGetterOrSetter = getId || setId; | ||
const cloneId = id => _core.types.inherits(_core.types.cloneNode(id), privateName); | ||
if (isStatic) { | ||
@@ -303,3 +310,3 @@ unshadow(classRef.name, member.scope, innerBinding); | ||
const helperName = isMethod && !isGetterOrSetter ? "classStaticPrivateMethodGet" : "classStaticPrivateFieldSpecGet"; | ||
return _core.types.callExpression(file.addHelper(helperName), [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id)]); | ||
return _core.types.callExpression(file.addHelper(helperName), [this.receiver(member), _core.types.cloneNode(classRef), cloneId(id)]); | ||
} | ||
@@ -310,11 +317,11 @@ const receiver = this.receiver(member); | ||
if (skipCheck) { | ||
return buildStaticPrivateFieldAccess(_core.types.cloneNode(id), noUninitializedPrivateFieldAccess); | ||
return buildStaticPrivateFieldAccess(cloneId(id), noUninitializedPrivateFieldAccess); | ||
} | ||
return buildStaticPrivateFieldAccess(_core.types.callExpression(file.addHelper("assertClassBrand"), [_core.types.cloneNode(classRef), receiver, _core.types.cloneNode(id)]), noUninitializedPrivateFieldAccess); | ||
return buildStaticPrivateFieldAccess(_core.types.callExpression(file.addHelper("assertClassBrand"), [_core.types.cloneNode(classRef), receiver, cloneId(id)]), noUninitializedPrivateFieldAccess); | ||
} | ||
if (getId) { | ||
if (skipCheck) { | ||
return _core.types.callExpression(_core.types.cloneNode(getId), [receiver]); | ||
return _core.types.callExpression(cloneId(getId), [receiver]); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateGetter"), [_core.types.cloneNode(classRef), receiver, _core.types.cloneNode(getId)]); | ||
return _core.types.callExpression(file.addHelper("classPrivateGetter"), [_core.types.cloneNode(classRef), receiver, cloneId(getId)]); | ||
} | ||
@@ -326,4 +333,4 @@ if (setId) { | ||
} | ||
if (skipCheck) return _core.types.cloneNode(id); | ||
return _core.types.callExpression(file.addHelper("assertClassBrand"), [_core.types.cloneNode(classRef), receiver, _core.types.cloneNode(id)]); | ||
if (skipCheck) return cloneId(id); | ||
return _core.types.callExpression(file.addHelper("assertClassBrand"), [_core.types.cloneNode(classRef), receiver, cloneId(id)]); | ||
} | ||
@@ -336,16 +343,16 @@ if (isMethod) { | ||
if (!newHelpers(file)) { | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), _core.types.cloneNode(id)]); | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), cloneId(id)]); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateGetter"), [_core.types.cloneNode(id), this.receiver(member), _core.types.cloneNode(getId)]); | ||
return _core.types.callExpression(file.addHelper("classPrivateGetter"), [_core.types.cloneNode(id), this.receiver(member), cloneId(getId)]); | ||
} | ||
if (!newHelpers(file)) { | ||
return _core.types.callExpression(file.addHelper("classPrivateMethodGet"), [this.receiver(member), _core.types.cloneNode(id), _core.types.cloneNode(methodId)]); | ||
return _core.types.callExpression(file.addHelper("classPrivateMethodGet"), [this.receiver(member), _core.types.cloneNode(id), cloneId(methodId)]); | ||
} | ||
return _core.types.callExpression(file.addHelper("assertClassBrand"), [_core.types.cloneNode(id), this.receiver(member), _core.types.cloneNode(methodId)]); | ||
return _core.types.callExpression(file.addHelper("assertClassBrand"), [_core.types.cloneNode(id), this.receiver(member), cloneId(methodId)]); | ||
} | ||
if (newHelpers(file)) { | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldGet2"), [_core.types.cloneNode(id), this.receiver(member)]); | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldGet2"), [cloneId(id), this.receiver(member)]); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), _core.types.cloneNode(id)]); | ||
}, | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), cloneId(id)]); | ||
}), | ||
boundGet(member) { | ||
@@ -355,3 +362,3 @@ this.memoise(member, 1); | ||
}, | ||
set(member, value) { | ||
set: autoInherits(function (member, value) { | ||
const { | ||
@@ -363,5 +370,6 @@ classRef, | ||
} = this; | ||
const privateName = member.node.property; | ||
const { | ||
name | ||
} = member.node.property.id; | ||
} = privateName.id; | ||
const { | ||
@@ -375,6 +383,7 @@ id, | ||
const isGetterOrSetter = getId || setId; | ||
const cloneId = id => _core.types.inherits(_core.types.cloneNode(id), privateName); | ||
if (isStatic) { | ||
if (!newHelpers(file)) { | ||
const helperName = isMethod && !isGetterOrSetter ? "classStaticPrivateMethodSet" : "classStaticPrivateFieldSpecSet"; | ||
return _core.types.callExpression(file.addHelper(helperName), [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id), value]); | ||
return _core.types.callExpression(file.addHelper(helperName), [this.receiver(member), _core.types.cloneNode(classRef), cloneId(id), value]); | ||
} | ||
@@ -392,5 +401,5 @@ const receiver = this.receiver(member); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateSetter"), [_core.types.cloneNode(classRef), _core.types.cloneNode(setId), receiver, value]); | ||
return _core.types.callExpression(file.addHelper("classPrivateSetter"), [_core.types.cloneNode(classRef), cloneId(setId), receiver, value]); | ||
} | ||
return _core.types.assignmentExpression("=", buildStaticPrivateFieldAccess(_core.types.cloneNode(id), noUninitializedPrivateFieldAccess), skipCheck ? value : _core.types.callExpression(file.addHelper("assertClassBrand"), [_core.types.cloneNode(classRef), receiver, value])); | ||
return _core.types.assignmentExpression("=", buildStaticPrivateFieldAccess(cloneId(id), noUninitializedPrivateFieldAccess), skipCheck ? value : _core.types.callExpression(file.addHelper("assertClassBrand"), [_core.types.cloneNode(classRef), receiver, value])); | ||
} | ||
@@ -400,5 +409,5 @@ if (isMethod) { | ||
if (!newHelpers(file)) { | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), _core.types.cloneNode(id), value]); | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), cloneId(id), value]); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateSetter"), [_core.types.cloneNode(id), _core.types.cloneNode(setId), this.receiver(member), value]); | ||
return _core.types.callExpression(file.addHelper("classPrivateSetter"), [_core.types.cloneNode(id), cloneId(setId), this.receiver(member), value]); | ||
} | ||
@@ -408,6 +417,6 @@ return _core.types.sequenceExpression([this.receiver(member), value, readOnlyError(file, name)]); | ||
if (newHelpers(file)) { | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldSet2"), [_core.types.cloneNode(id), this.receiver(member), value]); | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldSet2"), [cloneId(id), this.receiver(member), value]); | ||
} | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), _core.types.cloneNode(id), value]); | ||
}, | ||
return _core.types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), cloneId(id), value]); | ||
}), | ||
destructureSet(member) { | ||
@@ -420,5 +429,6 @@ const { | ||
} = this; | ||
const privateName = member.node.property; | ||
const { | ||
name | ||
} = member.node.property.id; | ||
} = privateName.id; | ||
const { | ||
@@ -430,2 +440,3 @@ id, | ||
} = privateNamesMap.get(name); | ||
const cloneId = id => _core.types.inherits(_core.types.cloneNode(id), privateName); | ||
if (!newHelpers(file)) { | ||
@@ -438,5 +449,5 @@ if (isStatic) { | ||
} | ||
return _core.types.memberExpression(_core.types.callExpression(helper, [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id)]), _core.types.identifier("value")); | ||
return _core.types.memberExpression(_core.types.callExpression(helper, [this.receiver(member), _core.types.cloneNode(classRef), cloneId(id)]), _core.types.identifier("value")); | ||
} | ||
return _core.types.memberExpression(_core.types.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [this.receiver(member), _core.types.cloneNode(id)]), _core.types.identifier("value")); | ||
return _core.types.memberExpression(_core.types.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [this.receiver(member), cloneId(id)]), _core.types.identifier("value")); | ||
} | ||
@@ -579,3 +590,3 @@ if (isMethod && !setId) { | ||
const helper = state.addHelper("classPrivateFieldInitSpec"); | ||
return inheritPropComments(_core.types.expressionStatement(_core.types.callExpression(helper, [_core.types.thisExpression(), _core.types.cloneNode(id), newHelpers(state) ? value : _core.template.expression.ast`{ writable: true, value: ${value} }`])), prop); | ||
return inheritLoc(inheritPropComments(_core.types.expressionStatement(_core.types.callExpression(helper, [_core.types.thisExpression(), inheritLoc(_core.types.cloneNode(id), prop.node.key), newHelpers(state) ? value : _core.template.expression.ast`{ writable: true, value: ${value} }`])), prop), prop.node); | ||
} | ||
@@ -693,3 +704,3 @@ function buildPrivateStaticFieldInitSpec(prop, privateNamesMap, noUninitializedPrivateFieldAccess) { | ||
const helper = state.addHelper("classPrivateFieldInitSpec"); | ||
return inheritPropComments(_core.template.statement.ast`${helper}( | ||
return inheritLoc(inheritPropComments(_core.template.statement.ast`${helper}( | ||
${_core.types.thisExpression()}, | ||
@@ -701,3 +712,3 @@ ${_core.types.cloneNode(id)}, | ||
}, | ||
)`, prop); | ||
)`, prop), prop.node); | ||
} | ||
@@ -904,2 +915,8 @@ function buildPrivateInstanceMethodInitialization(ref, prop, privateNamesMap, state) { | ||
} | ||
function inheritLoc(node, original) { | ||
node.start = original.start; | ||
node.end = original.end; | ||
node.loc = original.loc; | ||
return node; | ||
} | ||
function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, file, setPublicClassFields, privateFieldsAsSymbolsOrProperties, noUninitializedPrivateFieldAccess, constantSuper, innerBindingRef) { | ||
@@ -906,0 +923,0 @@ var _ref, _ref2; |
@@ -100,8 +100,8 @@ "use strict"; | ||
if (typeof file.get(versionKey) === "number") { | ||
file.set(versionKey, "7.24.5"); | ||
file.set(versionKey, "7.24.6"); | ||
return; | ||
} | ||
} | ||
if (!file.get(versionKey) || _semver.lt(file.get(versionKey), "7.24.5")) { | ||
file.set(versionKey, "7.24.5"); | ||
if (!file.get(versionKey) || _semver.lt(file.get(versionKey), "7.24.6")) { | ||
file.set(versionKey, "7.24.6"); | ||
} | ||
@@ -114,3 +114,3 @@ }, | ||
var _ref; | ||
if (file.get(versionKey) !== "7.24.5") return; | ||
if (file.get(versionKey) !== "7.24.6") return; | ||
if (!(0, _features.shouldTransform)(path, file)) return; | ||
@@ -232,3 +232,3 @@ const pathIsClassDeclaration = path.isClassDeclaration(); | ||
{ | ||
if (file.get(versionKey) !== "7.24.5") return; | ||
if (file.get(versionKey) !== "7.24.6") return; | ||
const decl = path.get("declaration"); | ||
@@ -235,0 +235,0 @@ if (decl.isClassDeclaration() && (0, _decorators2.hasDecorators)(decl.node)) { |
{ | ||
"name": "@babel/helper-create-class-features-plugin", | ||
"version": "7.24.5", | ||
"version": "7.24.6", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
@@ -21,10 +21,10 @@ "license": "MIT", | ||
"dependencies": { | ||
"@babel/helper-annotate-as-pure": "^7.22.5", | ||
"@babel/helper-environment-visitor": "^7.22.20", | ||
"@babel/helper-function-name": "^7.23.0", | ||
"@babel/helper-member-expression-to-functions": "^7.24.5", | ||
"@babel/helper-optimise-call-expression": "^7.22.5", | ||
"@babel/helper-replace-supers": "^7.24.1", | ||
"@babel/helper-skip-transparent-expression-wrappers": "^7.22.5", | ||
"@babel/helper-split-export-declaration": "^7.24.5", | ||
"@babel/helper-annotate-as-pure": "^7.24.6", | ||
"@babel/helper-environment-visitor": "^7.24.6", | ||
"@babel/helper-function-name": "^7.24.6", | ||
"@babel/helper-member-expression-to-functions": "^7.24.6", | ||
"@babel/helper-optimise-call-expression": "^7.24.6", | ||
"@babel/helper-replace-supers": "^7.24.6", | ||
"@babel/helper-skip-transparent-expression-wrappers": "^7.24.6", | ||
"@babel/helper-split-export-declaration": "^7.24.6", | ||
"semver": "^6.3.1" | ||
@@ -36,5 +36,5 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.24.5", | ||
"@babel/helper-plugin-test-runner": "^7.24.1", | ||
"@babel/preset-env": "^7.24.5", | ||
"@babel/core": "^7.24.6", | ||
"@babel/helper-plugin-test-runner": "^7.24.6", | ||
"@babel/preset-env": "^7.24.6", | ||
"@types/charcodes": "^0.2.0", | ||
@@ -41,0 +41,0 @@ "charcodes": "^0.2.0" |
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
507100
3064
3
1