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

@babel/plugin-transform-computed-properties

Package Overview
Dependencies
Maintainers
6
Versions
79
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.0.0-beta.43 to 7.0.0-beta.44

148

lib/index.js

@@ -9,5 +9,5 @@ "use strict";

function _helperPluginUtils() {
const data = require("@babel/helper-plugin-utils");
var data = require("@babel/helper-plugin-utils");
_helperPluginUtils = function () {
_helperPluginUtils = function _helperPluginUtils() {
return data;

@@ -20,5 +20,5 @@ };

function _core() {
const data = require("@babel/core");
var data = require("@babel/core");
_core = function () {
_core = function _core() {
return data;

@@ -30,12 +30,7 @@ };

var _default = (0, _helperPluginUtils().declare)((api, options) => {
var _default = (0, _helperPluginUtils().declare)(function (api, options) {
api.assertVersion(7);
const {
loose
} = options;
const pushComputedProps = loose ? pushComputedPropsLoose : pushComputedPropsSpec;
const buildMutatorMapAssign = (0, _core().template)(`
MUTATOR_MAP_REF[KEY] = MUTATOR_MAP_REF[KEY] || {};
MUTATOR_MAP_REF[KEY].KIND = VALUE;
`);
var loose = options.loose;
var pushComputedProps = loose ? pushComputedPropsLoose : pushComputedPropsSpec;
var buildMutatorMapAssign = (0, _core().template)("\n MUTATOR_MAP_REF[KEY] = MUTATOR_MAP_REF[KEY] || {};\n MUTATOR_MAP_REF[KEY].KIND = VALUE;\n ");

@@ -58,9 +53,8 @@ function getValue(prop) {

function pushMutatorDefine({
body,
getMutatorId,
scope
}, prop) {
let key = !prop.computed && _core().types.isIdentifier(prop.key) ? _core().types.stringLiteral(prop.key.name) : prop.key;
const maybeMemoise = scope.maybeGenerateMemoised(key);
function pushMutatorDefine(_ref, prop) {
var body = _ref.body,
getMutatorId = _ref.getMutatorId,
scope = _ref.scope;
var key = !prop.computed && _core().types.isIdentifier(prop.key) ? _core().types.stringLiteral(prop.key.name) : prop.key;
var maybeMemoise = scope.maybeGenerateMemoised(key);

@@ -72,3 +66,3 @@ if (maybeMemoise) {

body.push(...buildMutatorMapAssign({
body.push.apply(body, buildMutatorMapAssign({
MUTATOR_MAP_REF: getMutatorId(),

@@ -82,3 +76,16 @@ KEY: _core().types.cloneNode(key),

function pushComputedPropsLoose(info) {
for (const prop of info.computedProps) {
for (var _iterator = info.computedProps, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref2;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref2 = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref2 = _i.value;
}
var prop = _ref2;
if (prop.kind === "get" || prop.kind === "set") {

@@ -93,12 +100,23 @@ pushMutatorDefine(info, prop);

function pushComputedPropsSpec(info) {
const {
objId,
body,
computedProps,
state
} = info;
var objId = info.objId,
body = info.body,
computedProps = info.computedProps,
state = info.state;
for (const prop of computedProps) {
const key = _core().types.toComputedKey(prop);
for (var _iterator2 = computedProps, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
var _ref3;
if (_isArray2) {
if (_i2 >= _iterator2.length) break;
_ref3 = _iterator2[_i2++];
} else {
_i2 = _iterator2.next();
if (_i2.done) break;
_ref3 = _i2.value;
}
var prop = _ref3;
var key = _core().types.toComputedKey(prop);
if (prop.kind === "get" || prop.kind === "set") {

@@ -123,11 +141,11 @@ pushMutatorDefine(info, prop);

ObjectExpression: {
exit(path, state) {
const {
node,
parent,
scope
} = path;
let hasComputed = false;
exit: function exit(path, state) {
var node = path.node,
parent = path.parent,
scope = path.scope;
var hasComputed = false;
var _arr = node.properties;
for (const prop of node.properties) {
for (var _i3 = 0; _i3 < _arr.length; _i3++) {
var prop = _arr[_i3];
hasComputed = prop.computed === true;

@@ -138,8 +156,21 @@ if (hasComputed) break;

if (!hasComputed) return;
const initProps = [];
const computedProps = [];
let foundComputed = false;
var initProps = [];
var computedProps = [];
var foundComputed = false;
for (const prop of node.properties) {
if (prop.computed) {
for (var _iterator3 = node.properties, _isArray3 = Array.isArray(_iterator3), _i4 = 0, _iterator3 = _isArray3 ? _iterator3 : _iterator3[Symbol.iterator]();;) {
var _ref4;
if (_isArray3) {
if (_i4 >= _iterator3.length) break;
_ref4 = _iterator3[_i4++];
} else {
_i4 = _iterator3.next();
if (_i4.done) break;
_ref4 = _i4.value;
}
var _prop = _ref4;
if (_prop.computed) {
foundComputed = true;

@@ -149,17 +180,17 @@ }

if (foundComputed) {
computedProps.push(prop);
computedProps.push(_prop);
} else {
initProps.push(prop);
initProps.push(_prop);
}
}
const objId = scope.generateUidIdentifierBasedOnNode(parent);
var objId = scope.generateUidIdentifierBasedOnNode(parent);
const initPropExpression = _core().types.objectExpression(initProps);
var initPropExpression = _core().types.objectExpression(initProps);
const body = [];
var body = [];
body.push(_core().types.variableDeclaration("var", [_core().types.variableDeclarator(objId, initPropExpression)]));
let mutatorRef;
var mutatorRef;
const getMutatorId = function () {
var getMutatorId = function getMutatorId() {
if (!mutatorRef) {

@@ -173,10 +204,10 @@ mutatorRef = scope.generateUidIdentifier("mutatorMap");

const single = pushComputedProps({
scope,
objId,
body,
computedProps,
initPropExpression,
getMutatorId,
state
var single = pushComputedProps({
scope: scope,
objId: objId,
body: body,
computedProps: computedProps,
initPropExpression: initPropExpression,
getMutatorId: getMutatorId,
state: state
});

@@ -195,3 +226,2 @@

}
}

@@ -198,0 +228,0 @@ }

{
"name": "@babel/plugin-transform-computed-properties",
"version": "7.0.0-beta.43",
"version": "7.0.0-beta.44",
"description": "Compile ES2015 computed properties to ES5",

@@ -12,11 +12,11 @@ "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-computed-properties",

"dependencies": {
"@babel/helper-plugin-utils": "7.0.0-beta.43"
"@babel/helper-plugin-utils": "7.0.0-beta.44"
},
"peerDependencies": {
"@babel/core": "7.0.0-beta.43"
"@babel/core": "7.0.0-beta.44"
},
"devDependencies": {
"@babel/core": "7.0.0-beta.43",
"@babel/helper-plugin-test-runner": "7.0.0-beta.43"
"@babel/core": "7.0.0-beta.44",
"@babel/helper-plugin-test-runner": "7.0.0-beta.44"
}
}
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