Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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

Package Overview
Dependencies
Maintainers
4
Versions
110
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.21.4-esm to 7.21.4-esm.1

66

lib/decorators.js

@@ -1,16 +0,8 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.buildDecoratedClass = buildDecoratedClass;
exports.hasDecorators = hasDecorators;
exports.hasOwnDecorators = hasOwnDecorators;
var _core = require("@babel/core");
var _helperReplaceSupers = require("@babel/helper-replace-supers");
var _helperFunctionName = require("@babel/helper-function-name");
function hasOwnDecorators(node) {
import { types as t, template } from "@babel/core";
import ReplaceSupers from "@babel/helper-replace-supers";
import nameFunction from "@babel/helper-function-name";
export function hasOwnDecorators(node) {
return !!(node.decorators && node.decorators.length);
}
function hasDecorators(node) {
export function hasDecorators(node) {
return hasOwnDecorators(node) || node.body.body.some(hasOwnDecorators);

@@ -20,6 +12,6 @@ }

if (!value) return null;
return _core.types.objectProperty(_core.types.identifier(key), value);
return t.objectProperty(t.identifier(key), value);
}
function method(key, body) {
return _core.types.objectMethod("method", _core.types.identifier(key), [], _core.types.blockStatement(body));
return t.objectMethod("method", t.identifier(key), [], t.blockStatement(body));
}

@@ -29,3 +21,3 @@ function takeDecorators(node) {

if (node.decorators && node.decorators.length > 0) {
result = _core.types.arrayExpression(node.decorators.map(decorator => decorator.expression));
result = t.arrayExpression(node.decorators.map(decorator => decorator.expression));
}

@@ -38,6 +30,6 @@ node.decorators = undefined;

return node.key;
} else if (_core.types.isIdentifier(node.key)) {
return _core.types.stringLiteral(node.key.name);
} else if (t.isIdentifier(node.key)) {
return t.stringLiteral(node.key.name);
} else {
return _core.types.stringLiteral(String(node.key.value));
return t.stringLiteral(String(node.key.value));
}

@@ -61,3 +53,3 @@ }

if (!path.isTSDeclareMethod()) {
new _helperReplaceSupers.default({
new ReplaceSupers({
methodPath: path,

@@ -70,7 +62,7 @@ objectRef: classRef,

}
const properties = [prop("kind", _core.types.stringLiteral(_core.types.isClassMethod(node) ? node.kind : "field")), prop("decorators", takeDecorators(node)), prop("static", node.static && _core.types.booleanLiteral(true)), prop("key", getKey(node))].filter(Boolean);
if (_core.types.isClassMethod(node)) {
const properties = [prop("kind", t.stringLiteral(t.isClassMethod(node) ? node.kind : "field")), prop("decorators", takeDecorators(node)), prop("static", node.static && t.booleanLiteral(true)), prop("key", getKey(node))].filter(Boolean);
if (t.isClassMethod(node)) {
const id = node.computed ? null : node.key;
const transformed = _core.types.toExpression(node);
properties.push(prop("value", (0, _helperFunctionName.default)({
const transformed = t.toExpression(node);
properties.push(prop("value", nameFunction({
node: transformed,

@@ -80,4 +72,4 @@ id,

}) || transformed));
} else if (_core.types.isClassProperty(node) && node.value) {
properties.push(method("value", _core.template.statements.ast`return ${node.value}`));
} else if (t.isClassProperty(node) && node.value) {
properties.push(method("value", template.statements.ast`return ${node.value}`));
} else {

@@ -87,3 +79,3 @@ properties.push(prop("value", scope.buildUndefinedNode()));

path.remove();
return _core.types.objectExpression(properties);
return t.objectExpression(properties);
}

@@ -93,3 +85,3 @@ function addDecorateHelper(file) {

}
function buildDecoratedClass(ref, path, elements, file) {
export function buildDecoratedClass(ref, path, elements, file) {
const {

@@ -106,3 +98,3 @@ node,

node.type = "ClassDeclaration";
if (!node.id) node.id = _core.types.cloneNode(ref);
if (!node.id) node.id = t.cloneNode(ref);
let superId;

@@ -114,9 +106,9 @@ if (superClass) {

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 wrapperCall = _core.template.expression.ast`
const definitions = t.arrayExpression(elements.filter(element => !element.node.abstract && element.node.type !== "TSIndexSignature").map(path => extractElementDescriptor(file, node.id, superId, path)));
const wrapperCall = template.expression.ast`
${addDecorateHelper(file)}(
${classDecorators || _core.types.nullLiteral()},
function (${initializeId}, ${superClass ? _core.types.cloneNode(superId) : null}) {
${classDecorators || t.nullLiteral()},
function (${initializeId}, ${superClass ? t.cloneNode(superId) : null}) {
${node}
return { F: ${_core.types.cloneNode(node.id)}, d: ${definitions} };
return { F: ${t.cloneNode(node.id)}, d: ${definitions} };
},

@@ -127,3 +119,3 @@ ${superClass}

if (!isStrict) {
wrapperCall.arguments[1].body.directives.push(_core.types.directive(_core.types.directiveLiteral("use strict")));
wrapperCall.arguments[1].body.directives.push(t.directive(t.directiveLiteral("use strict")));
}

@@ -133,7 +125,7 @@ let replacement = wrapperCall;

if (isDeclaration) {
replacement = _core.template.statement.ast`let ${ref} = ${wrapperCall}`;
replacement = template.statement.ast`let ${ref} = ${wrapperCall}`;
classPathDesc = "declarations.0.init." + classPathDesc;
}
return {
instanceNodes: [_core.template.statement.ast`${_core.types.cloneNode(initializeId)}(this)`],
instanceNodes: [template.statement.ast`${t.cloneNode(initializeId)}(this)`],
wrapClass(path) {

@@ -140,0 +132,0 @@ path.replaceWith(replacement);

@@ -1,12 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.FEATURES = void 0;
exports.enableFeature = enableFeature;
exports.isLoose = isLoose;
exports.shouldTransform = shouldTransform;
var _decorators = require("./decorators");
const FEATURES = Object.freeze({
import { hasOwnDecorators } from "./decorators.js";
export const FEATURES = Object.freeze({
fields: 1 << 1,

@@ -18,3 +9,2 @@ privateMethods: 1 << 2,

});
exports.FEATURES = FEATURES;
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"]]);

@@ -24,3 +14,3 @@ const featuresKey = "@babel/plugin-class-features/featuresKey";

const looseLowPriorityKey = "@babel/plugin-class-features/looseLowPriorityKey/#__internal__@babel/preset-env__please-overwrite-loose-instead-of-throwing";
function enableFeature(file, feature, loose) {
export function enableFeature(file, feature, loose) {
if (!hasFeature(file, feature) || canIgnoreLoose(file, feature)) {

@@ -64,3 +54,3 @@ file.set(featuresKey, file.get(featuresKey) | feature);

}
function isLoose(file, feature) {
export function isLoose(file, feature) {
return !!(file.get(looseKey) & feature);

@@ -75,3 +65,3 @@ }

}
function shouldTransform(path, file) {
export function shouldTransform(path, file) {
let decoratorPath = null;

@@ -82,7 +72,7 @@ let publicFieldPath = null;

let staticBlockPath = null;
if ((0, _decorators.hasOwnDecorators)(path.node)) {
if (hasOwnDecorators(path.node)) {
decoratorPath = path.get("decorators.0");
}
for (const el of path.get("body.body")) {
if (!decoratorPath && (0, _decorators.hasOwnDecorators)(el.node)) {
if (!decoratorPath && hasOwnDecorators(el.node)) {
decoratorPath = el.get("decorators.0");

@@ -89,0 +79,0 @@ }

@@ -1,20 +0,10 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.buildCheckInRHS = buildCheckInRHS;
exports.buildFieldsInitNodes = buildFieldsInitNodes;
exports.buildPrivateNamesMap = buildPrivateNamesMap;
exports.buildPrivateNamesNodes = buildPrivateNamesNodes;
exports.transformPrivateNamesUsage = transformPrivateNamesUsage;
var _core = require("@babel/core");
var _helperReplaceSupers = require("@babel/helper-replace-supers");
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
var _helperMemberExpressionToFunctions = require("@babel/helper-member-expression-to-functions");
var _helperOptimiseCallExpression = require("@babel/helper-optimise-call-expression");
var _helperAnnotateAsPure = require("@babel/helper-annotate-as-pure");
var _helperSkipTransparentExpressionWrappers = require("@babel/helper-skip-transparent-expression-wrappers");
var ts = require("./typescript");
function buildPrivateNamesMap(props) {
import { template, traverse, types as t } from "@babel/core";
import ReplaceSupers from "@babel/helper-replace-supers";
import environmentVisitor from "@babel/helper-environment-visitor";
import memberExpressionToFunctions from "@babel/helper-member-expression-to-functions";
import optimiseCall from "@babel/helper-optimise-call-expression";
import annotateAsPure from "@babel/helper-annotate-as-pure";
import { isTransparentExprWrapper } from "@babel/helper-skip-transparent-expression-wrappers";
import * as ts from "./typescript.js";
export function buildPrivateNamesMap(props) {
const privateNamesMap = new Map();

@@ -45,3 +35,3 @@ for (const prop of props) {

}
function buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties, privateFieldsAsSymbols, state) {
export function buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties, privateFieldsAsSymbols, state) {
const initNodes = [];

@@ -56,14 +46,14 @@ for (const [name, value] of privateNamesMap) {

const isAccessor = getId || setId;
const id = _core.types.cloneNode(value.id);
const id = t.cloneNode(value.id);
let init;
if (privateFieldsAsProperties) {
init = _core.types.callExpression(state.addHelper("classPrivateFieldLooseKey"), [_core.types.stringLiteral(name)]);
init = t.callExpression(state.addHelper("classPrivateFieldLooseKey"), [t.stringLiteral(name)]);
} else if (privateFieldsAsSymbols) {
init = _core.types.callExpression(_core.types.identifier("Symbol"), [_core.types.stringLiteral(name)]);
init = t.callExpression(t.identifier("Symbol"), [t.stringLiteral(name)]);
} else if (!isStatic) {
init = _core.types.newExpression(_core.types.identifier(!isMethod || isAccessor ? "WeakMap" : "WeakSet"), []);
init = t.newExpression(t.identifier(!isMethod || isAccessor ? "WeakMap" : "WeakSet"), []);
}
if (init) {
(0, _helperAnnotateAsPure.default)(init);
initNodes.push(_core.template.statement.ast`var ${id} = ${init}`);
annotateAsPure(init);
initNodes.push(template.statement.ast`var ${id} = ${init}`);
}

@@ -74,3 +64,3 @@ }

function privateNameVisitorFactory(visitor) {
const nestedVisitor = _core.traverse.visitors.merge([Object.assign({}, visitor), _helperEnvironmentVisitor.default]);
const nestedVisitor = traverse.visitors.merge([Object.assign({}, visitor), environmentVisitor]);
const privateNameVisitor = Object.assign({}, visitor, {

@@ -140,5 +130,5 @@ Class(path) {

}
function buildCheckInRHS(rhs, file, inRHSIsObject) {
export function buildCheckInRHS(rhs, file, inRHSIsObject) {
if (inRHSIsObject || !(file.availableHelper != null && file.availableHelper("checkInRHS"))) return rhs;
return _core.types.callExpression(file.addHelper("checkInRHS"), [rhs]);
return t.callExpression(file.addHelper("checkInRHS"), [rhs]);
}

@@ -155,3 +145,3 @@ const privateInVisitor = privateNameVisitorFactory({

if (operator !== "in") return;
if (!_core.types.isPrivateName(left)) return;
if (!t.isPrivateName(left)) return;
const {

@@ -172,4 +162,4 @@ privateFieldsAsProperties,

} = privateNamesMap.get(name);
path.replaceWith(_core.template.expression.ast`
Object.prototype.hasOwnProperty.call(${buildCheckInRHS(right, file)}, ${_core.types.cloneNode(id)})
path.replaceWith(template.expression.ast`
Object.prototype.hasOwnProperty.call(${buildCheckInRHS(right, file)}, ${t.cloneNode(id)})
`);

@@ -183,6 +173,6 @@ return;

if (isStatic) {
path.replaceWith(_core.template.expression.ast`${buildCheckInRHS(right, file)} === ${_core.types.cloneNode(this.classRef)}`);
path.replaceWith(template.expression.ast`${buildCheckInRHS(right, file)} === ${t.cloneNode(this.classRef)}`);
return;
}
path.replaceWith(_core.template.expression.ast`${_core.types.cloneNode(id)}.has(${buildCheckInRHS(right, file)})`);
path.replaceWith(template.expression.ast`${t.cloneNode(id)}.has(${buildCheckInRHS(right, file)})`);
}

@@ -209,5 +199,5 @@ });

if (this.memoiser.has(object)) {
return _core.types.cloneNode(this.memoiser.get(object));
return t.cloneNode(this.memoiser.get(object));
}
return _core.types.cloneNode(object);
return t.cloneNode(object);
},

@@ -236,3 +226,3 @@ get(member) {

unshadow(classRef.name, member.scope, innerBinding);
return _core.types.callExpression(file.addHelper(helperName), [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id)]);
return t.callExpression(file.addHelper(helperName), [this.receiver(member), t.cloneNode(classRef), t.cloneNode(id)]);
}

@@ -243,15 +233,15 @@ if (isMethod) {

if (file.availableHelper("writeOnlyError")) {
return _core.types.sequenceExpression([this.receiver(member), _core.types.callExpression(file.addHelper("writeOnlyError"), [_core.types.stringLiteral(`#${name}`)])]);
return t.sequenceExpression([this.receiver(member), t.callExpression(file.addHelper("writeOnlyError"), [t.stringLiteral(`#${name}`)])]);
}
console.warn(`@babel/helpers is outdated, update it to silence this warning.`);
}
return _core.types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), _core.types.cloneNode(id)]);
return t.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), t.cloneNode(id)]);
}
return _core.types.callExpression(file.addHelper("classPrivateMethodGet"), [this.receiver(member), _core.types.cloneNode(id), _core.types.cloneNode(methodId)]);
return t.callExpression(file.addHelper("classPrivateMethodGet"), [this.receiver(member), t.cloneNode(id), t.cloneNode(methodId)]);
}
return _core.types.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), _core.types.cloneNode(id)]);
return t.callExpression(file.addHelper("classPrivateFieldGet"), [this.receiver(member), t.cloneNode(id)]);
},
boundGet(member) {
this.memoise(member, 1);
return _core.types.callExpression(_core.types.memberExpression(this.get(member), _core.types.identifier("bind")), [this.receiver(member)]);
return t.callExpression(t.memberExpression(this.get(member), t.identifier("bind")), [this.receiver(member)]);
},

@@ -277,11 +267,11 @@ set(member, value) {

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]);
return t.callExpression(file.addHelper(helperName), [this.receiver(member), t.cloneNode(classRef), t.cloneNode(id), value]);
}
if (isMethod) {
if (setId) {
return _core.types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), _core.types.cloneNode(id), value]);
return t.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), t.cloneNode(id), value]);
}
return _core.types.sequenceExpression([this.receiver(member), value, _core.types.callExpression(file.addHelper("readOnlyError"), [_core.types.stringLiteral(`#${name}`)])]);
return t.sequenceExpression([this.receiver(member), value, t.callExpression(file.addHelper("readOnlyError"), [t.stringLiteral(`#${name}`)])]);
}
return _core.types.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), _core.types.cloneNode(id), value]);
return t.callExpression(file.addHelper("classPrivateFieldSet"), [this.receiver(member), t.cloneNode(id), value]);
},

@@ -307,13 +297,13 @@ destructureSet(member) {

}
return _core.types.memberExpression(_core.types.callExpression(helper, [this.receiver(member), _core.types.cloneNode(classRef), _core.types.cloneNode(id)]), _core.types.identifier("value"));
return t.memberExpression(t.callExpression(helper, [this.receiver(member), t.cloneNode(classRef), t.cloneNode(id)]), t.identifier("value"));
}
return _core.types.memberExpression(_core.types.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [this.receiver(member), _core.types.cloneNode(id)]), _core.types.identifier("value"));
return t.memberExpression(t.callExpression(file.addHelper("classPrivateFieldDestructureSet"), [this.receiver(member), t.cloneNode(id)]), t.identifier("value"));
},
call(member, args) {
this.memoise(member, 1);
return (0, _helperOptimiseCallExpression.default)(this.get(member), this.receiver(member), args, false);
return optimiseCall(this.get(member), this.receiver(member), args, false);
},
optionalCall(member, args) {
this.memoise(member, 1);
return (0, _helperOptimiseCallExpression.default)(this.get(member), this.receiver(member), args, true);
return optimiseCall(this.get(member), this.receiver(member), args, true);
}

@@ -333,6 +323,6 @@ };

} = member.node.property.id;
return _core.template.expression`BASE(REF, PROP)[PROP]`({
return template.expression`BASE(REF, PROP)[PROP]`({
BASE: file.addHelper("classPrivateFieldLooseBase"),
REF: _core.types.cloneNode(object),
PROP: _core.types.cloneNode(privateNamesMap.get(name).id)
REF: t.cloneNode(object),
PROP: t.cloneNode(privateNamesMap.get(name).id)
});

@@ -344,3 +334,3 @@ },

boundGet(member) {
return _core.types.callExpression(_core.types.memberExpression(this.get(member), _core.types.identifier("bind")), [_core.types.cloneNode(member.node.object)]);
return t.callExpression(t.memberExpression(this.get(member), t.identifier("bind")), [t.cloneNode(member.node.object)]);
},

@@ -354,9 +344,9 @@ simpleSet(member) {

call(member, args) {
return _core.types.callExpression(this.get(member), args);
return t.callExpression(this.get(member), args);
},
optionalCall(member, args) {
return _core.types.optionalCallExpression(this.get(member), args, true);
return t.optionalCallExpression(this.get(member), args, true);
}
};
function transformPrivateNamesUsage(ref, path, privateNamesMap, {
export function transformPrivateNamesUsage(ref, path, privateNamesMap, {
privateFieldsAsProperties,

@@ -369,3 +359,3 @@ noDocumentAll,

const handler = privateFieldsAsProperties ? privateNameHandlerLoose : privateNameHandlerSpec;
(0, _helperMemberExpressionToFunctions.default)(body, privateNameVisitor, Object.assign({
memberExpressionToFunctions(body, privateNameVisitor, Object.assign({
privateNamesMap,

@@ -391,4 +381,4 @@ classRef: ref,

const value = prop.node.value || prop.scope.buildUndefinedNode();
return inheritPropComments(_core.template.statement.ast`
Object.defineProperty(${ref}, ${_core.types.cloneNode(id)}, {
return inheritPropComments(template.statement.ast`
Object.defineProperty(${ref}, ${t.cloneNode(id)}, {
// configurable is false by default

@@ -408,3 +398,3 @@ // enumerable is false by default

if (!state.availableHelper("classPrivateFieldInitSpec")) {
return inheritPropComments(_core.template.statement.ast`${_core.types.cloneNode(id)}.set(${ref}, {
return inheritPropComments(template.statement.ast`${t.cloneNode(id)}.set(${ref}, {
// configurable is always false for private elements

@@ -418,5 +408,5 @@ // enumerable is always false for private elements

const helper = state.addHelper("classPrivateFieldInitSpec");
return inheritPropComments(_core.template.statement.ast`${helper}(
${_core.types.thisExpression()},
${_core.types.cloneNode(id)},
return inheritPropComments(template.statement.ast`${helper}(
${t.thisExpression()},
${t.cloneNode(id)},
{

@@ -442,4 +432,4 @@ writable: true,

}));
return inheritPropComments(_core.template.statement.ast`
var ${_core.types.cloneNode(id)} = {
return inheritPropComments(template.statement.ast`
var ${t.cloneNode(id)} = {
// configurable is false by default

@@ -454,4 +444,4 @@ // enumerable is false by default

const value = prop.node.value || prop.scope.buildUndefinedNode();
return inheritPropComments(_core.template.statement.ast`
var ${_core.types.cloneNode(id)} = {
return inheritPropComments(template.statement.ast`
var ${t.cloneNode(id)} = {
// configurable is false by default

@@ -475,3 +465,3 @@ // enumerable is false by default

if (methodId) {
return inheritPropComments(_core.template.statement.ast`
return inheritPropComments(template.statement.ast`
Object.defineProperty(${ref}, ${id}, {

@@ -490,3 +480,3 @@ // configurable is false by default

}));
return inheritPropComments(_core.template.statement.ast`
return inheritPropComments(template.statement.ast`
Object.defineProperty(${ref}, ${id}, {

@@ -528,3 +518,3 @@ // configurable is false by default

if (!state.availableHelper("classPrivateFieldInitSpec")) {
return inheritPropComments(_core.template.statement.ast`
return inheritPropComments(template.statement.ast`
${id}.set(${ref}, {

@@ -538,5 +528,5 @@ get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},

const helper = state.addHelper("classPrivateFieldInitSpec");
return inheritPropComments(_core.template.statement.ast`${helper}(
${_core.types.thisExpression()},
${_core.types.cloneNode(id)},
return inheritPropComments(template.statement.ast`${helper}(
${t.thisExpression()},
${t.cloneNode(id)},
{

@@ -555,9 +545,9 @@ get: ${getId ? getId.name : prop.scope.buildUndefinedNode()},

if (!state.availableHelper("classPrivateMethodInitSpec")) {
return inheritPropComments(_core.template.statement.ast`${id}.add(${ref})`, prop);
return inheritPropComments(template.statement.ast`${id}.add(${ref})`, prop);
}
}
const helper = state.addHelper("classPrivateMethodInitSpec");
return inheritPropComments(_core.template.statement.ast`${helper}(
${_core.types.thisExpression()},
${_core.types.cloneNode(id)}
return inheritPropComments(template.statement.ast`${helper}(
${t.thisExpression()},
${t.cloneNode(id)}
)`, prop);

@@ -571,3 +561,3 @@ }

const value = prop.node.value || prop.scope.buildUndefinedNode();
return inheritPropComments(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.memberExpression(ref, key, computed || _core.types.isLiteral(key)), value)), prop);
return inheritPropComments(t.expressionStatement(t.assignmentExpression("=", t.memberExpression(ref, key, computed || t.isLiteral(key)), value)), prop);
}

@@ -580,3 +570,3 @@ function buildPublicFieldInitSpec(ref, prop, state) {

const value = prop.node.value || prop.scope.buildUndefinedNode();
return inheritPropComments(_core.types.expressionStatement(_core.types.callExpression(state.addHelper("defineProperty"), [ref, computed || _core.types.isLiteral(key) ? key : _core.types.stringLiteral(key.name), value])), prop);
return inheritPropComments(t.expressionStatement(t.callExpression(state.addHelper("defineProperty"), [ref, computed || t.isLiteral(key) ? key : t.stringLiteral(key.name), value])), prop);
}

@@ -598,3 +588,3 @@ function buildPrivateStaticMethodInitLoose(ref, prop, state, privateNamesMap) {

}));
return inheritPropComments(_core.template.statement.ast`
return inheritPropComments(template.statement.ast`
Object.defineProperty(${ref}, ${id}, {

@@ -609,3 +599,3 @@ // configurable is false by default

}
return inheritPropComments(_core.template.statement.ast`
return inheritPropComments(template.statement.ast`
Object.defineProperty(${ref}, ${id}, {

@@ -652,15 +642,15 @@ // configurable is false by default

}
return inheritPropComments(_core.types.functionDeclaration(_core.types.cloneNode(declId), params, body, generator, async), prop);
return inheritPropComments(t.functionDeclaration(t.cloneNode(declId), params, body, generator, async), prop);
}
const thisContextVisitor = _core.traverse.visitors.merge([{
const thisContextVisitor = traverse.visitors.merge([{
ThisExpression(path, state) {
const parent = path.findParent(path => !(0, _helperSkipTransparentExpressionWrappers.isTransparentExprWrapper)(path.node));
if (_core.types.isUnaryExpression(parent.node, {
const parent = path.findParent(path => !isTransparentExprWrapper(path.node));
if (t.isUnaryExpression(parent.node, {
operator: "delete"
})) {
path.parentPath.replaceWith(_core.types.booleanLiteral(true));
path.parentPath.replaceWith(t.booleanLiteral(true));
return;
}
state.needsClassRef = true;
path.replaceWith(_core.types.cloneNode(state.classRef));
path.replaceWith(t.cloneNode(state.classRef));
},

@@ -681,3 +671,3 @@ MetaProperty(path) {

}
}, _helperEnvironmentVisitor.default]);
}, environmentVisitor]);
const innerReferencesVisitor = {

@@ -698,3 +688,3 @@ ReferencedIdentifier(path, state) {

};
const replacer = new _helperReplaceSupers.default({
const replacer = new ReplaceSupers({
methodPath: path,

@@ -707,3 +697,3 @@ constantSuper,

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"));
return t.isStaticBlock != null && t.isStaticBlock(path.node) || path.node.static ? ref : t.memberExpression(ref, t.identifier("prototype"));
}

@@ -733,7 +723,7 @@ });

function inheritPropComments(node, prop) {
_core.types.inheritLeadingComments(node, prop.node);
_core.types.inheritInnerComments(node, prop.node);
t.inheritLeadingComments(node, prop.node);
t.inheritInnerComments(node, prop.node);
return node;
}
function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, state, setPublicClassFields, privateFieldsAsProperties, constantSuper, innerBindingRef) {
export function buildFieldsInitNodes(ref, superRef, props, privateNamesMap, state, setPublicClassFields, privateFieldsAsProperties, constantSuper, innerBindingRef) {
let needsClassRef = false;

@@ -744,3 +734,3 @@ let injectSuperRef;

const pureStaticNodes = [];
const getSuperRef = _core.types.isIdentifier(superRef) ? () => superRef : () => {
const getSuperRef = t.isIdentifier(superRef) ? () => superRef : () => {
var _injectSuperRef;

@@ -752,3 +742,3 @@ (_injectSuperRef = injectSuperRef) != null ? _injectSuperRef : injectSuperRef = props[0].scope.generateUidIdentifierBasedOnNode(superRef);

prop.isClassProperty() && ts.assertFieldTransformed(prop);
const isStatic = !(_core.types.isStaticBlock != null && _core.types.isStaticBlock(prop.node)) && prop.node.static;
const isStatic = !(t.isStaticBlock != null && t.isStaticBlock(prop.node)) && prop.node.static;
const isInstance = !isStatic;

@@ -768,6 +758,6 @@ const isPrivate = prop.isPrivate();

const blockBody = prop.node.body;
if (blockBody.length === 1 && _core.types.isExpressionStatement(blockBody[0])) {
if (blockBody.length === 1 && t.isExpressionStatement(blockBody[0])) {
staticNodes.push(inheritPropComments(blockBody[0], prop));
} else {
staticNodes.push(_core.types.inheritsComments(_core.template.statement.ast`(() => { ${blockBody} })()`, prop.node));
staticNodes.push(t.inheritsComments(template.statement.ast`(() => { ${blockBody} })()`, prop.node));
}

@@ -778,3 +768,3 @@ break;

needsClassRef = true;
staticNodes.push(buildPrivateFieldInitLoose(_core.types.cloneNode(ref), prop, privateNamesMap));
staticNodes.push(buildPrivateFieldInitLoose(t.cloneNode(ref), prop, privateNamesMap));
break;

@@ -788,3 +778,3 @@ case isStatic && isPrivate && isField && !privateFieldsAsProperties:

needsClassRef = true;
staticNodes.push(buildPublicFieldInitLoose(_core.types.cloneNode(ref), prop));
staticNodes.push(buildPublicFieldInitLoose(t.cloneNode(ref), prop));
break;

@@ -794,16 +784,16 @@ }

needsClassRef = true;
staticNodes.push(buildPublicFieldInitSpec(_core.types.cloneNode(ref), prop, state));
staticNodes.push(buildPublicFieldInitSpec(t.cloneNode(ref), prop, state));
break;
case isInstance && isPrivate && isField && privateFieldsAsProperties:
instanceNodes.push(buildPrivateFieldInitLoose(_core.types.thisExpression(), prop, privateNamesMap));
instanceNodes.push(buildPrivateFieldInitLoose(t.thisExpression(), prop, privateNamesMap));
break;
case isInstance && isPrivate && isField && !privateFieldsAsProperties:
instanceNodes.push(buildPrivateInstanceFieldInitSpec(_core.types.thisExpression(), prop, privateNamesMap, state));
instanceNodes.push(buildPrivateInstanceFieldInitSpec(t.thisExpression(), prop, privateNamesMap, state));
break;
case isInstance && isPrivate && isMethod && privateFieldsAsProperties:
instanceNodes.unshift(buildPrivateMethodInitLoose(_core.types.thisExpression(), prop, privateNamesMap));
instanceNodes.unshift(buildPrivateMethodInitLoose(t.thisExpression(), prop, privateNamesMap));
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties));
break;
case isInstance && isPrivate && isMethod && !privateFieldsAsProperties:
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(_core.types.thisExpression(), prop, privateNamesMap, state));
instanceNodes.unshift(buildPrivateInstanceMethodInitSpec(t.thisExpression(), prop, privateNamesMap, state));
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties));

@@ -818,10 +808,10 @@ break;

needsClassRef = true;
staticNodes.unshift(buildPrivateStaticMethodInitLoose(_core.types.cloneNode(ref), prop, state, privateNamesMap));
staticNodes.unshift(buildPrivateStaticMethodInitLoose(t.cloneNode(ref), prop, state, privateNamesMap));
pureStaticNodes.push(buildPrivateMethodDeclaration(prop, privateNamesMap, privateFieldsAsProperties));
break;
case isInstance && isPublic && isField && setPublicClassFields:
instanceNodes.push(buildPublicFieldInitLoose(_core.types.thisExpression(), prop));
instanceNodes.push(buildPublicFieldInitLoose(t.thisExpression(), prop));
break;
case isInstance && isPublic && isField && !setPublicClassFields:
instanceNodes.push(buildPublicFieldInitSpec(_core.types.thisExpression(), prop, state));
instanceNodes.push(buildPublicFieldInitSpec(t.thisExpression(), prop, state));
break;

@@ -843,5 +833,5 @@ default:

path.scope.push({
id: _core.types.cloneNode(injectSuperRef)
id: t.cloneNode(injectSuperRef)
});
path.set("superClass", _core.types.assignmentExpression("=", injectSuperRef, path.node.superClass));
path.set("superClass", t.assignmentExpression("=", injectSuperRef, path.node.superClass));
}

@@ -853,3 +843,3 @@ if (!needsClassRef) return path;

});
path.replaceWith(_core.types.assignmentExpression("=", _core.types.cloneNode(ref), path.node));
path.replaceWith(t.assignmentExpression("=", t.cloneNode(ref), path.node));
} else if (!path.node.id) {

@@ -856,0 +846,0 @@ path.node.id = ref;

@@ -1,42 +0,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "FEATURES", {
enumerable: true,
get: function () {
return _features.FEATURES;
}
});
Object.defineProperty(exports, "buildCheckInRHS", {
enumerable: true,
get: function () {
return _fields.buildCheckInRHS;
}
});
exports.createClassFeaturePlugin = createClassFeaturePlugin;
Object.defineProperty(exports, "enableFeature", {
enumerable: true,
get: function () {
return _features.enableFeature;
}
});
Object.defineProperty(exports, "injectInitialization", {
enumerable: true,
get: function () {
return _misc.injectInitialization;
}
});
var _core = require("@babel/core");
var _helperFunctionName = require("@babel/helper-function-name");
var _helperSplitExportDeclaration = require("@babel/helper-split-export-declaration");
var _fields = require("./fields");
var _decorators = require("./decorators");
var _misc = require("./misc");
var _features = require("./features");
var _typescript = require("./typescript");
const version = "7.21.4-esm".split(".").reduce((v, x) => v * 1e5 + +x, 0);
import { types as t } from "@babel/core";
import nameFunction from "@babel/helper-function-name";
import splitExportDeclaration from "@babel/helper-split-export-declaration";
import { buildPrivateNamesNodes, buildPrivateNamesMap, transformPrivateNamesUsage, buildFieldsInitNodes, buildCheckInRHS } from "./fields.js";
import { buildDecoratedClass, hasDecorators } from "./decorators.js";
import { injectInitialization, extractComputedKeys } from "./misc.js";
import { enableFeature, FEATURES, isLoose, shouldTransform } from "./features.js";
import { assertFieldTransformed } from "./typescript.js";
export { FEATURES, enableFeature, injectInitialization, buildCheckInRHS };
const version = "7.21.4-esm.1".split(".").reduce((v, x) => v * 1e5 + +x, 0);
const versionKey = "@babel/plugin-class-features/version";
function createClassFeaturePlugin({
export function createClassFeaturePlugin({
name,

@@ -80,3 +51,3 @@ feature,

pre(file) {
(0, _features.enableFeature)(file, feature, loose);
enableFeature(file, feature, loose);
if (!file.get(versionKey) || file.get(versionKey) < version) {

@@ -91,7 +62,7 @@ file.set(versionKey, version);

if (file.get(versionKey) !== version) return;
if (!(0, _features.shouldTransform)(path, file)) return;
if (path.isClassDeclaration()) (0, _typescript.assertFieldTransformed)(path);
const loose = (0, _features.isLoose)(file, feature);
if (!shouldTransform(path, file)) return;
if (path.isClassDeclaration()) assertFieldTransformed(path);
const loose = isLoose(file, feature);
let constructor;
const isDecorated = (0, _decorators.hasDecorators)(path.node);
const isDecorated = hasDecorators(path.node);
const props = [];

@@ -148,10 +119,10 @@ const elements = [];

if (!innerBinding || path.isClassExpression()) {
(0, _helperFunctionName.default)(path);
nameFunction(path);
ref = path.scope.generateUidIdentifier("class");
} else {
ref = _core.types.cloneNode(path.node.id);
ref = t.cloneNode(path.node.id);
}
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, {
const privateNamesMap = buildPrivateNamesMap(props);
const privateNamesNodes = buildPrivateNamesNodes(privateNamesMap, privateFieldsAsProperties != null ? privateFieldsAsProperties : loose, privateFieldsAsSymbols != null ? privateFieldsAsSymbols : false, file);
transformPrivateNamesUsage(ref, path, privateNamesMap, {
privateFieldsAsProperties: privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose,

@@ -168,5 +139,5 @@ noDocumentAll,

wrapClass
} = (0, _decorators.buildDecoratedClass)(ref, path, elements, file));
} = buildDecoratedClass(ref, path, elements, file));
} else {
keysNodes = (0, _misc.extractComputedKeys)(path, computedPaths, file);
keysNodes = extractComputedKeys(path, computedPaths, file);
({

@@ -177,7 +148,7 @@ staticNodes,

wrapClass
} = (0, _fields.buildFieldsInitNodes)(ref, path.node.superClass, props, privateNamesMap, file, setPublicClassFields != null ? setPublicClassFields : loose, privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose, constantSuper != null ? constantSuper : loose, innerBinding));
} = buildFieldsInitNodes(ref, path.node.superClass, props, privateNamesMap, file, setPublicClassFields != null ? setPublicClassFields : loose, privateFieldsAsSymbolsOrProperties != null ? privateFieldsAsSymbolsOrProperties : loose, constantSuper != null ? constantSuper : loose, innerBinding));
}
}
if (instanceNodes.length > 0) {
(0, _misc.injectInitialization)(path, constructor, instanceNodes, (referenceVisitor, state) => {
injectInitialization(path, constructor, instanceNodes, (referenceVisitor, state) => {
{

@@ -187,3 +158,3 @@ if (isDecorated) return;

for (const prop of props) {
if (_core.types.isStaticBlock != null && _core.types.isStaticBlock(prop.node) || prop.node.static) continue;
if (t.isStaticBlock != null && t.isStaticBlock(prop.node) || prop.node.static) continue;
prop.traverse(referenceVisitor, state);

@@ -208,5 +179,5 @@ }

const decl = path.get("declaration");
if (decl.isClassDeclaration() && (0, _decorators.hasDecorators)(decl.node)) {
if (decl.isClassDeclaration() && hasDecorators(decl.node)) {
if (decl.node.id) {
(0, _helperSplitExportDeclaration.default)(path);
splitExportDeclaration(path);
} else {

@@ -213,0 +184,0 @@ decl.node.type = "ClassExpression";

@@ -1,11 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.extractComputedKeys = extractComputedKeys;
exports.injectInitialization = injectInitialization;
var _core = require("@babel/core");
var _helperEnvironmentVisitor = require("@babel/helper-environment-visitor");
const findBareSupers = _core.traverse.visitors.merge([{
import { template, traverse, types as t } from "@babel/core";
import environmentVisitor from "@babel/helper-environment-visitor";
const findBareSupers = traverse.visitors.merge([{
Super(path) {

@@ -22,3 +15,3 @@ const {

}
}, _helperEnvironmentVisitor.default]);
}, environmentVisitor]);
const referenceVisitor = {

@@ -40,4 +33,4 @@ "TSTypeAnnotation|TypeAnnotation"(path) {

const classNameTDZError = state.file.addHelper("classNameTDZError");
const throwNode = _core.types.callExpression(classNameTDZError, [_core.types.stringLiteral(path.node.name)]);
path.replaceWith(_core.types.sequenceExpression([throwNode, path.node]));
const throwNode = t.callExpression(classNameTDZError, [t.stringLiteral(path.node.name)]);
path.replaceWith(t.sequenceExpression([throwNode, path.node]));
path.skip();

@@ -49,10 +42,10 @@ }

};
function injectInitialization(path, constructor, nodes, renamer) {
export function injectInitialization(path, constructor, nodes, renamer) {
if (!nodes.length) return;
const isDerived = !!path.node.superClass;
if (!constructor) {
const newConstructor = _core.types.classMethod("constructor", _core.types.identifier("constructor"), [], _core.types.blockStatement([]));
const newConstructor = t.classMethod("constructor", t.identifier("constructor"), [], t.blockStatement([]));
if (isDerived) {
newConstructor.params = [_core.types.restElement(_core.types.identifier("args"))];
newConstructor.body.body.push(_core.template.statement.ast`super(...args)`);
newConstructor.params = [t.restElement(t.identifier("args"))];
newConstructor.body.body.push(template.statement.ast`super(...args)`);
}

@@ -75,3 +68,3 @@ [constructor] = path.get("body").unshiftContainer("body", newConstructor);

} else {
bareSuper.insertAfter(nodes.map(n => _core.types.cloneNode(n)));
bareSuper.insertAfter(nodes.map(n => t.cloneNode(n)));
}

@@ -83,3 +76,3 @@ }

}
function extractComputedKeys(path, computedPaths, file) {
export function extractComputedKeys(path, computedPaths, file) {
const declarations = [];

@@ -104,4 +97,4 @@ const state = {

});
declarations.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.cloneNode(ident), computedNode.key)));
computedNode.key = _core.types.cloneNode(ident);
declarations.push(t.expressionStatement(t.assignmentExpression("=", t.cloneNode(ident), computedNode.key)));
computedNode.key = t.cloneNode(ident);
}

@@ -108,0 +101,0 @@ }

@@ -1,8 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.assertFieldTransformed = assertFieldTransformed;
function assertFieldTransformed(path) {
export function assertFieldTransformed(path) {
if (path.node.declare) {

@@ -9,0 +3,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.21.4-esm",
"version": "7.21.4-esm.1",
"author": "The Babel Team (https://babel.dev/team)",

@@ -21,19 +21,19 @@ "license": "MIT",

"dependencies": {
"@babel/helper-annotate-as-pure": "^7.21.4-esm",
"@babel/helper-environment-visitor": "^7.21.4-esm",
"@babel/helper-function-name": "^7.21.4-esm",
"@babel/helper-member-expression-to-functions": "^7.21.4-esm",
"@babel/helper-optimise-call-expression": "^7.21.4-esm",
"@babel/helper-replace-supers": "^7.21.4-esm",
"@babel/helper-skip-transparent-expression-wrappers": "^7.21.4-esm",
"@babel/helper-split-export-declaration": "^7.21.4-esm"
"@babel/helper-annotate-as-pure": "^7.21.4-esm.1",
"@babel/helper-environment-visitor": "^7.21.4-esm.1",
"@babel/helper-function-name": "^7.21.4-esm.1",
"@babel/helper-member-expression-to-functions": "^7.21.4-esm.1",
"@babel/helper-optimise-call-expression": "^7.21.4-esm.1",
"@babel/helper-replace-supers": "^7.21.4-esm.1",
"@babel/helper-skip-transparent-expression-wrappers": "^7.21.4-esm.1",
"@babel/helper-split-export-declaration": "^7.21.4-esm.1"
},
"peerDependencies": {
"@babel/core": "^7.0.0 || 7.21.4-esm"
"@babel/core": "^7.0.0 || 7.21.4-esm.1"
},
"devDependencies": {
"@babel/core": "^7.21.4-esm",
"@babel/helper-plugin-test-runner": "^7.21.4-esm",
"@babel/core": "^7.21.4-esm.1",
"@babel/helper-plugin-test-runner": "^7.21.4-esm.1",
"@babel/plugin-syntax-class-static-block": "^7.14.5",
"@babel/preset-env": "^7.21.4-esm"
"@babel/preset-env": "^7.21.4-esm.1"
},

@@ -43,3 +43,3 @@ "engines": {

},
"type": "commonjs"
"type": "module"
}

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

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