@babel/helper-create-class-features-plugin
Advanced tools
Comparing version 7.20.7 to 7.20.12
@@ -12,3 +12,2 @@ "use strict"; | ||
var _helperFunctionName = require("@babel/helper-function-name"); | ||
function hasOwnDecorators(node) { | ||
@@ -41,4 +40,3 @@ return !!(node.decorators && node.decorators.length); | ||
} else { | ||
return _core.types.stringLiteral(String( | ||
node.key.value)); | ||
return _core.types.stringLiteral(String(node.key.value)); | ||
} | ||
@@ -109,5 +107,3 @@ } | ||
const classDecorators = takeDecorators(node); | ||
const definitions = _core.types.arrayExpression(elements.filter(element => | ||
!element.node.abstract && element.node.type !== "TSIndexSignature").map(path => extractElementDescriptor(file, node.id, superId, | ||
path))); | ||
const definitions = _core.types.arrayExpression(elements.filter(element => !element.node.abstract && element.node.type !== "TSIndexSignature").map(path => extractElementDescriptor(file, node.id, superId, path))); | ||
const wrapperCall = _core.template.expression.ast` | ||
@@ -114,0 +110,0 @@ ${addDecorateHelper(file)}( |
@@ -20,6 +20,4 @@ "use strict"; | ||
const featuresSameLoose = new Map([[FEATURES.fields, "@babel/plugin-proposal-class-properties"], [FEATURES.privateMethods, "@babel/plugin-proposal-private-methods"], [FEATURES.privateIn, "@babel/plugin-proposal-private-property-in-object"]]); | ||
const featuresKey = "@babel/plugin-class-features/featuresKey"; | ||
const looseKey = "@babel/plugin-class-features/looseKey"; | ||
const looseLowPriorityKey = "@babel/plugin-class-features/looseLowPriorityKey/#__internal__@babel/preset-env__please-overwrite-loose-instead-of-throwing"; | ||
@@ -29,8 +27,6 @@ function enableFeature(file, feature, loose) { | ||
file.set(featuresKey, file.get(featuresKey) | feature); | ||
if ( | ||
loose === "#__internal__@babel/preset-env__prefer-true-but-false-is-ok-if-it-prevents-an-error") { | ||
if (loose === "#__internal__@babel/preset-env__prefer-true-but-false-is-ok-if-it-prevents-an-error") { | ||
setLoose(file, feature, true); | ||
file.set(looseLowPriorityKey, file.get(looseLowPriorityKey) | feature); | ||
} else if ( | ||
loose === "#__internal__@babel/preset-env__prefer-false-but-true-is-ok-if-it-prevents-an-error") { | ||
} else if (loose === "#__internal__@babel/preset-env__prefer-false-but-true-is-ok-if-it-prevents-an-error") { | ||
setLoose(file, feature, false); | ||
@@ -116,4 +112,3 @@ file.set(looseLowPriorityKey, file.get(looseLowPriorityKey) | feature); | ||
} | ||
if ((publicFieldPath || privateFieldPath) && !hasFeature(file, FEATURES.fields) && | ||
!hasFeature(file, FEATURES.privateMethods)) { | ||
if ((publicFieldPath || privateFieldPath) && !hasFeature(file, FEATURES.fields) && !hasFeature(file, FEATURES.privateMethods)) { | ||
throw path.buildCodeFrameError("Class fields are not enabled. " + "Please add `@babel/plugin-proposal-class-properties` to your configuration."); | ||
@@ -120,0 +115,0 @@ } |
@@ -17,2 +17,3 @@ "use strict"; | ||
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure"); | ||
var _helperSkipTransparentExpressionWrappers = require("@babel/helper-skip-transparent-expression-wrappers"); | ||
var ts = require("./typescript"); | ||
@@ -87,7 +88,5 @@ function buildPrivateNamesMap(props) { | ||
} | ||
if (!redeclared.length) { | ||
return; | ||
} | ||
path.get("body").traverse(nestedVisitor, Object.assign({}, this, { | ||
@@ -99,3 +98,2 @@ redeclared | ||
})); | ||
path.skipKey("body"); | ||
@@ -133,3 +131,2 @@ } | ||
}); | ||
function unshadow(name, scope, innerBinding) { | ||
@@ -167,3 +164,2 @@ while ((_scope = scope) != null && _scope.hasBinding(name) && !scope.bindingIdentifierEquals(name, innerBinding)) { | ||
if (redeclared && redeclared.includes(name)) return; | ||
unshadow(this.classRef.name, path.scope, this.innerBinding); | ||
@@ -234,3 +230,2 @@ if (privateFieldsAsProperties) { | ||
const helperName = isMethod && !isAccessor ? "classStaticPrivateMethodGet" : "classStaticPrivateFieldSpecGet"; | ||
unshadow(classRef.name, member.scope, innerBinding); | ||
@@ -340,4 +335,3 @@ return _core.types.callExpression(file.addHelper(helperName), [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id)]); | ||
boundGet(member) { | ||
return _core.types.callExpression(_core.types.memberExpression(this.get(member), _core.types.identifier("bind")), | ||
[_core.types.cloneNode(member.node.object)]); | ||
return _core.types.callExpression(_core.types.memberExpression(this.get(member), _core.types.identifier("bind")), [_core.types.cloneNode(member.node.object)]); | ||
}, | ||
@@ -633,7 +627,13 @@ simpleSet(member) { | ||
} | ||
return _core.types.functionDeclaration(_core.types.cloneNode(declId), | ||
params, body, generator, async); | ||
return _core.types.functionDeclaration(_core.types.cloneNode(declId), params, body, generator, async); | ||
} | ||
const thisContextVisitor = _core.traverse.visitors.merge([{ | ||
ThisExpression(path, state) { | ||
const parent = path.findParent(path => !(0, _helperSkipTransparentExpressionWrappers.isTransparentExprWrapper)(path.node)); | ||
if (_core.types.isUnaryExpression(parent.node, { | ||
operator: "delete" | ||
})) { | ||
path.parentPath.replaceWith(_core.types.booleanLiteral(true)); | ||
return; | ||
} | ||
state.needsClassRef = true; | ||
@@ -687,3 +687,2 @@ path.replaceWith(_core.types.cloneNode(state.classRef)); | ||
} | ||
if (innerBindingRef != null && (_state$classRef = state.classRef) != null && _state$classRef.name && state.classRef.name !== (innerBindingRef == null ? void 0 : innerBindingRef.name)) { | ||
@@ -719,3 +718,2 @@ path.traverse(innerReferencesVisitor, state); | ||
prop.isClassProperty() && ts.assertFieldTransformed(prop); | ||
const isStatic = !(_core.types.isStaticBlock != null && _core.types.isStaticBlock(prop.node)) && prop.node.static; | ||
@@ -732,3 +730,2 @@ const isInstance = !isStatic; | ||
} | ||
switch (true) { | ||
@@ -747,9 +744,7 @@ case isStaticBlock: | ||
needsClassRef = true; | ||
staticNodes.push( | ||
buildPrivateFieldInitLoose(_core.types.cloneNode(ref), prop, privateNamesMap)); | ||
staticNodes.push(buildPrivateFieldInitLoose(_core.types.cloneNode(ref), prop, privateNamesMap)); | ||
break; | ||
case isStatic && isPrivate && isField && !privateFieldsAsProperties: | ||
needsClassRef = true; | ||
staticNodes.push( | ||
buildPrivateStaticFieldInitSpec(prop, privateNamesMap)); | ||
staticNodes.push(buildPrivateStaticFieldInitSpec(prop, privateNamesMap)); | ||
break; | ||
@@ -764,38 +759,27 @@ case isStatic && isPublic && isField && setPublicClassFields: | ||
needsClassRef = true; | ||
staticNodes.push( | ||
buildPublicFieldInitSpec(_core.types.cloneNode(ref), prop, state)); | ||
staticNodes.push(buildPublicFieldInitSpec(_core.types.cloneNode(ref), prop, state)); | ||
break; | ||
case isInstance && isPrivate && isField && privateFieldsAsProperties: | ||
instanceNodes.push( | ||
buildPrivateFieldInitLoose(_core.types.thisExpression(), prop, privateNamesMap)); | ||
instanceNodes.push(buildPrivateFieldInitLoose(_core.types.thisExpression(), prop, privateNamesMap)); | ||
break; | ||
case isInstance && isPrivate && isField && !privateFieldsAsProperties: | ||
instanceNodes.push(buildPrivateInstanceFieldInitSpec(_core.types.thisExpression(), | ||
prop, privateNamesMap, state)); | ||
instanceNodes.push(buildPrivateInstanceFieldInitSpec(_core.types.thisExpression(), prop, privateNamesMap, state)); | ||
break; | ||
case isInstance && isPrivate && isMethod && privateFieldsAsProperties: | ||
instanceNodes.unshift(buildPrivateMethodInitLoose(_core.types.thisExpression(), | ||
prop, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration( | ||
prop, privateNamesMap, privateFieldsAsProperties)); | ||
instanceNodes.unshift(buildPrivateMethodInitLoose(_core.types.thisExpression(), prop, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isInstance && isPrivate && isMethod && !privateFieldsAsProperties: | ||
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(_core.types.thisExpression(), | ||
prop, privateNamesMap, state)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration( | ||
prop, privateNamesMap, privateFieldsAsProperties)); | ||
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(_core.types.thisExpression(), prop, privateNamesMap, state)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isStatic && isPrivate && isMethod && !privateFieldsAsProperties: | ||
needsClassRef = true; | ||
staticNodes.unshift( | ||
buildPrivateStaticFieldInitSpec(prop, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration( | ||
prop, privateNamesMap, privateFieldsAsProperties)); | ||
staticNodes.unshift(buildPrivateStaticFieldInitSpec(prop, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
case isStatic && isPrivate && isMethod && privateFieldsAsProperties: | ||
needsClassRef = true; | ||
staticNodes.unshift(buildPrivateStaticMethodInitLoose(_core.types.cloneNode(ref), | ||
prop, state, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration( | ||
prop, privateNamesMap, privateFieldsAsProperties)); | ||
staticNodes.unshift(buildPrivateStaticMethodInitLoose(_core.types.cloneNode(ref), prop, state, privateNamesMap)); | ||
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties)); | ||
break; | ||
@@ -806,4 +790,3 @@ case isInstance && isPublic && isField && setPublicClassFields: | ||
case isInstance && isPublic && isField && !setPublicClassFields: | ||
instanceNodes.push( | ||
buildPublicFieldInitSpec(_core.types.thisExpression(), prop, state)); | ||
instanceNodes.push(buildPublicFieldInitSpec(_core.types.thisExpression(), prop, state)); | ||
break; | ||
@@ -810,0 +793,0 @@ default: |
@@ -39,3 +39,3 @@ "use strict"; | ||
var _typescript = require("./typescript"); | ||
const version = "7.20.7".split(".").reduce((v, x) => v * 1e5 + +x, 0); | ||
const version = "7.20.12".split(".").reduce((v, x) => v * 1e5 + +x, 0); | ||
const versionKey = "@babel/plugin-class-features/version"; | ||
@@ -94,4 +94,3 @@ function createClassFeaturePlugin({ | ||
for (const path of body.get("body")) { | ||
if ( | ||
(path.isClassProperty() || path.isClassMethod()) && path.node.computed) { | ||
if ((path.isClassProperty() || path.isClassMethod()) && path.node.computed) { | ||
computedPaths.push(path); | ||
@@ -146,3 +145,2 @@ } | ||
} | ||
const privateNamesMap = (0, _fields.buildPrivateNamesMap)(props); | ||
@@ -184,3 +182,2 @@ const privateNamesNodes = (0, _fields.buildPrivateNamesNodes)(privateNamesMap, privateFieldsAsProperties != null ? privateFieldsAsProperties : loose, file); | ||
} | ||
const wrappedPath = wrapClass(path); | ||
@@ -187,0 +184,0 @@ wrappedPath.insertBefore([...privateNamesNodes, ...keysNodes]); |
@@ -8,3 +8,2 @@ "use strict"; | ||
function assertFieldTransformed(path) { | ||
if (path.node.declare) { | ||
@@ -11,0 +10,0 @@ throw path.buildCodeFrameError(`TypeScript 'declare' fields must first be transformed by ` + `@babel/plugin-transform-typescript.\n` + `If you have already enabled that plugin (or '@babel/preset-typescript'), make sure ` + `that it runs before any plugin related to additional class features:\n` + ` - @babel/plugin-proposal-class-properties\n` + ` - @babel/plugin-proposal-private-methods\n` + ` - @babel/plugin-proposal-decorators`); |
{ | ||
"name": "@babel/helper-create-class-features-plugin", | ||
"version": "7.20.7", | ||
"version": "7.20.12", | ||
"author": "The Babel Team (https://babel.dev/team)", | ||
@@ -27,2 +27,3 @@ "license": "MIT", | ||
"@babel/helper-replace-supers": "^7.20.7", | ||
"@babel/helper-skip-transparent-expression-wrappers": "^7.20.0", | ||
"@babel/helper-split-export-declaration": "^7.18.6" | ||
@@ -34,3 +35,3 @@ }, | ||
"devDependencies": { | ||
"@babel/core": "^7.20.7", | ||
"@babel/core": "^7.20.12", | ||
"@babel/helper-plugin-test-runner": "^7.18.6", | ||
@@ -37,0 +38,0 @@ "@babel/plugin-syntax-class-static-block": "^7.14.5", |
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
179711
9
1390