@babel/plugin-proposal-decorators
Advanced tools
Comparing version 7.17.0 to 7.17.2
@@ -273,8 +273,15 @@ "use strict"; | ||
let requiresStaticInit = false; | ||
let hasComputedProps = false; | ||
const decoratedPrivateMethods = new Set(); | ||
let protoInitLocal, staticInitLocal, classInitLocal, classLocal; | ||
const assignments = []; | ||
const scopeParent = path.scope.parent; | ||
const memoiseExpression = (expression, hint) => { | ||
const localEvaluatedId = scopeParent.generateDeclaredUidIdentifier(hint); | ||
assignments.push(_core.types.assignmentExpression("=", localEvaluatedId, expression)); | ||
return _core.types.cloneNode(localEvaluatedId); | ||
}; | ||
if (classDecorators) { | ||
classInitLocal = path.scope.parent.generateDeclaredUidIdentifier("initClass"); | ||
classInitLocal = scopeParent.generateDeclaredUidIdentifier("initClass"); | ||
const [localId, classPath] = replaceClassWithVar(path); | ||
@@ -284,2 +291,8 @@ path = classPath; | ||
path.node.decorators = null; | ||
for (const classDecorator of classDecorators) { | ||
if (!scopeParent.isStatic(classDecorator.expression)) { | ||
classDecorator.expression = memoiseExpression(classDecorator.expression, "dec"); | ||
} | ||
} | ||
} else { | ||
@@ -299,9 +312,29 @@ if (!path.node.id) { | ||
let { | ||
const { | ||
node | ||
} = element; | ||
const decorators = element.get("decorators"); | ||
const hasDecorators = Array.isArray(decorators) && decorators.length > 0; | ||
if (hasDecorators) { | ||
for (const decoratorPath of decorators) { | ||
if (!scopeParent.isStatic(decoratorPath.node.expression)) { | ||
decoratorPath.node.expression = memoiseExpression(decoratorPath.node.expression, "dec"); | ||
} | ||
} | ||
} | ||
const isComputed = "computed" in element.node && element.node.computed === true; | ||
if (isComputed) { | ||
if (!scopeParent.isStatic(node.key)) { | ||
node.key = memoiseExpression(node.key, "computedKey"); | ||
} | ||
} | ||
const kind = getElementKind(element); | ||
const { | ||
key | ||
} = element.node; | ||
const kind = getElementKind(element); | ||
const decorators = element.get("decorators"); | ||
} = node; | ||
const isPrivate = key.type === "PrivateName"; | ||
const isComputed = "computed" in element.node && element.node.computed === true; | ||
const isStatic = !!element.node.static; | ||
@@ -312,3 +345,3 @@ let name = "computedKey"; | ||
name = key.id.name; | ||
} else if (key.type === "Identifier") { | ||
} else if (!isComputed && key.type === "Identifier") { | ||
name = key.name; | ||
@@ -323,15 +356,3 @@ } | ||
if (isComputed) { | ||
const keyPath = element.get("key"); | ||
const localComputedNameId = keyPath.scope.parent.generateDeclaredUidIdentifier(name); | ||
keyPath.replaceWith(localComputedNameId); | ||
elementDecoratorInfo.push({ | ||
localComputedNameId: _core.types.cloneNode(localComputedNameId), | ||
keyNode: _core.types.cloneNode(key) | ||
}); | ||
key = localComputedNameId; | ||
hasComputedProps = true; | ||
} | ||
if (Array.isArray(decorators) && decorators.length > 0) { | ||
if (hasDecorators) { | ||
let locals; | ||
@@ -445,27 +466,2 @@ let privateMethods; | ||
if (hasComputedProps) { | ||
const assignments = []; | ||
for (const info of elementDecoratorInfo) { | ||
if (isDecoratorInfo(info)) { | ||
const { | ||
decorators | ||
} = info; | ||
const newDecorators = []; | ||
for (const decorator of decorators) { | ||
const localComputedNameId = path.scope.parent.generateDeclaredUidIdentifier("dec"); | ||
assignments.push(_core.types.assignmentExpression("=", localComputedNameId, decorator)); | ||
newDecorators.push(_core.types.cloneNode(localComputedNameId)); | ||
} | ||
info.decorators = newDecorators; | ||
} else { | ||
assignments.push(_core.types.assignmentExpression("=", info.localComputedNameId, info.keyNode)); | ||
} | ||
} | ||
path.insertBefore(assignments); | ||
} | ||
const elementDecorations = generateDecorationExprs(elementDecoratorInfo); | ||
@@ -477,8 +473,4 @@ | ||
if (classDecorators) { | ||
locals.push(classLocal, classInitLocal); | ||
} | ||
if (requiresProtoInit) { | ||
protoInitLocal = path.scope.parent.generateDeclaredUidIdentifier("initProto"); | ||
protoInitLocal = scopeParent.generateDeclaredUidIdentifier("initProto"); | ||
locals.push(protoInitLocal); | ||
@@ -524,3 +516,3 @@ | ||
if (requiresStaticInit) { | ||
staticInitLocal = path.scope.parent.generateDeclaredUidIdentifier("initStatic"); | ||
staticInitLocal = scopeParent.generateDeclaredUidIdentifier("initStatic"); | ||
locals.push(staticInitLocal); | ||
@@ -551,2 +543,3 @@ } | ||
if (classDecorators) { | ||
locals.push(classLocal, classInitLocal); | ||
const statics = []; | ||
@@ -611,2 +604,3 @@ let staticBlocks = []; | ||
originalClass.body.body.unshift(_core.types.staticBlock([_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.arrayPattern(locals), _core.types.callExpression(state.addHelper("applyDecs"), [_core.types.thisExpression(), elementDecorations, classDecorations]))), requiresStaticInit && _core.types.expressionStatement(_core.types.callExpression(_core.types.cloneNode(staticInitLocal), [_core.types.thisExpression()]))].filter(Boolean))); | ||
path.insertBefore(assignments); | ||
path.scope.crawl(); | ||
@@ -613,0 +607,0 @@ return path; |
{ | ||
"name": "@babel/plugin-proposal-decorators", | ||
"version": "7.17.0", | ||
"version": "7.17.2", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
@@ -23,3 +23,3 @@ "license": "MIT", | ||
"dependencies": { | ||
"@babel/helper-create-class-features-plugin": "^7.17.0", | ||
"@babel/helper-create-class-features-plugin": "^7.17.1", | ||
"@babel/helper-plugin-utils": "^7.16.7", | ||
@@ -34,3 +34,3 @@ "@babel/helper-replace-supers": "^7.16.7", | ||
"devDependencies": { | ||
"@babel/core": "^7.17.0", | ||
"@babel/core": "^7.17.2", | ||
"@babel/helper-plugin-test-runner": "^7.16.7", | ||
@@ -37,0 +37,0 @@ "@babel/traverse": "^7.17.0", |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
44695
714