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 7.22.5 to 8.0.0-alpha.0

78

lib/index.js

@@ -1,55 +0,23 @@

"use strict";
import { types } from '@babel/core';
import { declare } from '@babel/helper-plugin-utils';
import '@babel/template';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _core = require("@babel/core");
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _template = require("@babel/template");
{
var DefineAccessorHelper = _template.default.expression.ast`
function (type, obj, key, fn) {
var desc = { configurable: true, enumerable: true };
desc[type] = fn;
return Object.defineProperty(obj, key, desc);
}
`;
DefineAccessorHelper._compact = true;
}
var _default = (0, _helperPluginUtils.declare)((api, options) => {
var _api$assumption;
var index = declare((api, options) => {
api.assertVersion(7);
const setComputedProperties = (_api$assumption = api.assumption("setComputedProperties")) != null ? _api$assumption : options.loose;
const setComputedProperties = api.assumption("setComputedProperties") ?? options.loose;
const pushComputedProps = setComputedProperties ? pushComputedPropsLoose : pushComputedPropsSpec;
function buildDefineAccessor(state, type, obj, key, fn) {
{
let helper;
if (state.availableHelper("defineAccessor")) {
helper = state.addHelper("defineAccessor");
} else {
const file = state.file;
helper = file.get("fallbackDefineAccessorHelper");
if (!helper) {
const id = file.scope.generateUidIdentifier("defineAccessor");
file.scope.push({
id,
init: DefineAccessorHelper
});
file.set("fallbackDefineAccessorHelper", helper = id);
}
helper = _core.types.cloneNode(helper);
}
return _core.types.callExpression(helper, [_core.types.stringLiteral(type), obj, key, fn]);
return types.callExpression(state.addHelper("defineAccessor"), [types.stringLiteral(type), obj, key, fn]);
}
}
function getValue(prop) {
if (_core.types.isObjectProperty(prop)) {
if (types.isObjectProperty(prop)) {
return prop.value;
} else if (_core.types.isObjectMethod(prop)) {
return _core.types.functionExpression(null, prop.params, prop.body, prop.generator, prop.async);
} else if (types.isObjectMethod(prop)) {
return types.functionExpression(null, prop.params, prop.body, prop.generator, prop.async);
}
}
function pushAssign(objId, prop, body) {
body.push(_core.types.expressionStatement(_core.types.assignmentExpression("=", _core.types.memberExpression(_core.types.cloneNode(objId), prop.key, prop.computed || _core.types.isLiteral(prop.key)), getValue(prop))));
body.push(types.expressionStatement(types.assignmentExpression("=", types.memberExpression(types.cloneNode(objId), prop.key, prop.computed || types.isLiteral(prop.key)), getValue(prop))));
}

@@ -64,3 +32,3 @@ function pushAccessorDefine({

const kind = prop.kind;
const key = !prop.computed && _core.types.isIdentifier(prop.key) ? _core.types.stringLiteral(prop.key.name) : prop.key;
const key = !prop.computed && types.isIdentifier(prop.key) ? types.stringLiteral(prop.key.name) : prop.key;
const value = getValue(prop);

@@ -70,3 +38,3 @@ if (computedProps.length === 1) {

} else {
body.push(_core.types.expressionStatement(buildDefineAccessor(state, kind, _core.types.cloneNode(objId), key, value)));
body.push(types.expressionStatement(buildDefineAccessor(state, kind, types.cloneNode(objId), key, value)));
}

@@ -76,7 +44,7 @@ }

for (const prop of info.computedProps) {
if (_core.types.isObjectMethod(prop) && (prop.kind === "get" || prop.kind === "set")) {
if (types.isObjectMethod(prop) && (prop.kind === "get" || prop.kind === "set")) {
const single = pushAccessorDefine(info, prop);
if (single) return single;
} else {
pushAssign(_core.types.cloneNode(info.objId), prop, info.body);
pushAssign(types.cloneNode(info.objId), prop, info.body);
}

@@ -93,4 +61,4 @@ }

for (const prop of computedProps) {
const key = _core.types.toComputedKey(prop);
if (_core.types.isObjectMethod(prop) && (prop.kind === "get" || prop.kind === "set")) {
const key = types.toComputedKey(prop);
if (types.isObjectMethod(prop) && (prop.kind === "get" || prop.kind === "set")) {
const single = pushAccessorDefine(info, prop);

@@ -101,5 +69,5 @@ if (single) return single;

if (computedProps.length === 1) {
return _core.types.callExpression(state.addHelper("defineProperty"), [info.initPropExpression, key, value]);
return types.callExpression(state.addHelper("defineProperty"), [info.initPropExpression, key, value]);
} else {
body.push(_core.types.expressionStatement(_core.types.callExpression(state.addHelper("defineProperty"), [_core.types.cloneNode(objId), key, value])));
body.push(types.expressionStatement(types.callExpression(state.addHelper("defineProperty"), [types.cloneNode(objId), key, value])));
}

@@ -129,3 +97,3 @@ }

for (const prop of node.properties) {
if (_core.types.isSpreadElement(prop)) {
if (types.isSpreadElement(prop)) {
continue;

@@ -143,5 +111,5 @@ }

const objId = scope.generateUidIdentifierBasedOnNode(parent);
const initPropExpression = _core.types.objectExpression(initProps);
const initPropExpression = types.objectExpression(initProps);
const body = [];
body.push(_core.types.variableDeclaration("var", [_core.types.variableDeclarator(objId, initPropExpression)]));
body.push(types.variableDeclaration("var", [types.variableDeclarator(objId, initPropExpression)]));
const single = pushComputedProps({

@@ -158,3 +126,3 @@ scope,

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

@@ -167,4 +135,4 @@ }

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

@@ -20,17 +20,21 @@ "repository": {

"dependencies": {
"@babel/helper-plugin-utils": "^7.22.5",
"@babel/template": "^7.22.5"
"@babel/helper-plugin-utils": "^8.0.0-alpha.0",
"@babel/template": "^8.0.0-alpha.0"
},
"peerDependencies": {
"@babel/core": "^7.0.0-0"
"@babel/core": "^8.0.0-alpha.0"
},
"devDependencies": {
"@babel/core": "^7.22.5",
"@babel/helper-plugin-test-runner": "^7.22.5"
"@babel/core": "^8.0.0-alpha.0",
"@babel/helper-plugin-test-runner": "^8.0.0-alpha.0"
},
"engines": {
"node": ">=6.9.0"
"node": "^16.20.0 || ^18.16.0 || >=20.0.0"
},
"author": "The Babel Team (https://babel.dev/team)",
"type": "commonjs"
"exports": {
".": "./lib/index.js",
"./package.json": "./package.json"
},
"type": "module"
}

@@ -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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc