Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-computed-properties

Package Overview
Dependencies
54
Maintainers
4
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.22.5 to 7.23.3

73

lib/index.js

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

}
var _default = (0, _helperPluginUtils.declare)((api, options) => {
var _default = exports.default = (0, _helperPluginUtils.declare)((api, options) => {
var _api$assumption;

@@ -26,3 +26,6 @@ api.assertVersion(7);

const pushComputedProps = setComputedProperties ? pushComputedPropsLoose : pushComputedPropsSpec;
function buildDefineAccessor(state, type, obj, key, fn) {
function buildDefineAccessor(state, obj, prop) {
const type = prop.kind;
const key = !prop.computed && _core.types.isIdentifier(prop.key) ? _core.types.stringLiteral(prop.key.name) : prop.key;
const fn = getValue(prop);
{

@@ -58,25 +61,19 @@ let helper;

}
function pushAccessorDefine({
body,
computedProps,
initPropExpression,
objId,
state
}, prop) {
const kind = prop.kind;
const key = !prop.computed && _core.types.isIdentifier(prop.key) ? _core.types.stringLiteral(prop.key.name) : prop.key;
const value = getValue(prop);
if (computedProps.length === 1) {
return buildDefineAccessor(state, kind, initPropExpression, key, value);
} else {
body.push(_core.types.expressionStatement(buildDefineAccessor(state, kind, _core.types.cloneNode(objId), key, value)));
}
}
function pushComputedPropsLoose(info) {
for (const prop of info.computedProps) {
const {
computedProps,
state,
initPropExpression,
objId,
body
} = info;
for (const prop of computedProps) {
if (_core.types.isObjectMethod(prop) && (prop.kind === "get" || prop.kind === "set")) {
const single = pushAccessorDefine(info, prop);
if (single) return single;
if (computedProps.length === 1) {
return buildDefineAccessor(state, initPropExpression, prop);
} else {
body.push(_core.types.expressionStatement(buildDefineAccessor(state, _core.types.cloneNode(objId), prop)));
}
} else {
pushAssign(_core.types.cloneNode(info.objId), prop, info.body);
pushAssign(_core.types.cloneNode(objId), prop, body);
}

@@ -92,15 +89,24 @@ }

} = info;
const CHUNK_LENGTH_CAP = 10;
let currentChunk = null;
const computedPropsChunks = [];
for (const prop of computedProps) {
const key = _core.types.toComputedKey(prop);
if (_core.types.isObjectMethod(prop) && (prop.kind === "get" || prop.kind === "set")) {
const single = pushAccessorDefine(info, prop);
if (single) return single;
} else {
const value = getValue(prop);
if (computedProps.length === 1) {
return _core.types.callExpression(state.addHelper("defineProperty"), [info.initPropExpression, key, value]);
if (!currentChunk || currentChunk.length === CHUNK_LENGTH_CAP) {
currentChunk = [];
computedPropsChunks.push(currentChunk);
}
currentChunk.push(prop);
}
for (const chunk of computedPropsChunks) {
const single = computedPropsChunks.length === 1;
let node = single ? info.initPropExpression : _core.types.cloneNode(objId);
for (const prop of chunk) {
if (_core.types.isObjectMethod(prop) && (prop.kind === "get" || prop.kind === "set")) {
node = buildDefineAccessor(info.state, node, prop);
} else {
body.push(_core.types.expressionStatement(_core.types.callExpression(state.addHelper("defineProperty"), [_core.types.cloneNode(objId), key, value])));
node = _core.types.callExpression(state.addHelper("defineProperty"), [node, _core.types.toComputedKey(prop), getValue(prop)]);
}
}
if (single) return node;
body.push(_core.types.expressionStatement(node));
}

@@ -155,3 +161,5 @@ }

} else {
body.push(_core.types.expressionStatement(_core.types.cloneNode(objId)));
if (setComputedProperties) {
body.push(_core.types.expressionStatement(_core.types.cloneNode(objId)));
}
path.replaceWithMultiple(body);

@@ -164,4 +172,3 @@ }

});
exports.default = _default;
//# sourceMappingURL=index.js.map
{
"name": "@babel/plugin-transform-computed-properties",
"version": "7.22.5",
"version": "7.23.3",
"description": "Compile ES2015 computed properties to ES5",

@@ -21,3 +21,3 @@ "repository": {

"@babel/helper-plugin-utils": "^7.22.5",
"@babel/template": "^7.22.5"
"@babel/template": "^7.22.15"
},

@@ -28,3 +28,3 @@ "peerDependencies": {

"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/core": "^7.23.3",
"@babel/helper-plugin-test-runner": "^7.22.5"

@@ -31,0 +31,0 @@ },

@@ -5,3 +5,3 @@ # @babel/plugin-transform-computed-properties

See our website [@babel/plugin-transform-computed-properties](https://babeljs.io/docs/en/babel-plugin-transform-computed-properties) for more information.
See our website [@babel/plugin-transform-computed-properties](https://babeljs.io/docs/babel-plugin-transform-computed-properties) for more information.

@@ -8,0 +8,0 @@ ## Install

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc