Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-computed-properties

Package Overview
Dependencies
Maintainers
4
Versions
77
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-computed-properties - npm Package Compare versions

Comparing version 8.0.0-alpha.4 to 8.0.0-alpha.5

72

lib/index.js

@@ -6,6 +6,9 @@ import { types } from '@babel/core';

var index = declare((api, options) => {
api.assertVersion(7);
api.assertVersion("8.0.0-alpha.5");
const setComputedProperties = api.assumption("setComputedProperties") ?? options.loose;
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 && types.isIdentifier(prop.key) ? types.stringLiteral(prop.key.name) : prop.key;
const fn = getValue(prop);
{

@@ -25,25 +28,19 @@ return types.callExpression(state.addHelper("defineAccessor"), [types.stringLiteral(type), obj, key, fn]);

}
function pushAccessorDefine({
body,
computedProps,
initPropExpression,
objId,
state
}, prop) {
const kind = prop.kind;
const key = !prop.computed && types.isIdentifier(prop.key) ? 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(types.expressionStatement(buildDefineAccessor(state, kind, 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 (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(types.expressionStatement(buildDefineAccessor(state, types.cloneNode(objId), prop)));
}
} else {
pushAssign(types.cloneNode(info.objId), prop, info.body);
pushAssign(types.cloneNode(objId), prop, body);
}

@@ -59,15 +56,24 @@ }

} = info;
const CHUNK_LENGTH_CAP = 10;
let currentChunk = null;
const computedPropsChunks = [];
for (const prop of computedProps) {
const key = types.toComputedKey(prop);
if (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 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 : types.cloneNode(objId);
for (const prop of chunk) {
if (types.isObjectMethod(prop) && (prop.kind === "get" || prop.kind === "set")) {
node = buildDefineAccessor(info.state, node, prop);
} else {
body.push(types.expressionStatement(types.callExpression(state.addHelper("defineProperty"), [types.cloneNode(objId), key, value])));
node = types.callExpression(state.addHelper("defineProperty"), [node, types.toComputedKey(prop), getValue(prop)]);
}
}
if (single) return node;
body.push(types.expressionStatement(node));
}

@@ -122,3 +128,5 @@ }

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

@@ -125,0 +133,0 @@ }

{
"name": "@babel/plugin-transform-computed-properties",
"version": "8.0.0-alpha.4",
"version": "8.0.0-alpha.5",
"description": "Compile ES2015 computed properties to ES5",

@@ -20,11 +20,11 @@ "repository": {

"dependencies": {
"@babel/helper-plugin-utils": "^8.0.0-alpha.4",
"@babel/template": "^8.0.0-alpha.4"
"@babel/helper-plugin-utils": "^8.0.0-alpha.5",
"@babel/template": "^8.0.0-alpha.5"
},
"peerDependencies": {
"@babel/core": "^8.0.0-alpha.4"
"@babel/core": "^8.0.0-alpha.5"
},
"devDependencies": {
"@babel/core": "^8.0.0-alpha.4",
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.4"
"@babel/core": "^8.0.0-alpha.5",
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.5"
},

@@ -31,0 +31,0 @@ "engines": {

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