Socket
Socket
Sign inDemoInstall

@babel/plugin-transform-for-of

Package Overview
Dependencies
54
Maintainers
4
Versions
80
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.21.4-esm.2 to 7.21.4-esm.3

71

lib/index.js

@@ -1,4 +0,10 @@

import { declare } from "@babel/helper-plugin-utils";
import { template, types as t } from "@babel/core";
import transformWithoutHelper from "./no-helper-implementation.js";
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _helperPluginUtils = require("@babel/helper-plugin-utils");
var _core = require("@babel/core");
var _noHelperImplementation = require("./no-helper-implementation");
function buildLoopBody(path, declar, newBody) {

@@ -8,6 +14,6 @@ let block;

const body = newBody != null ? newBody : bodyPath.node;
if (t.isBlockStatement(body) && Object.keys(path.getBindingIdentifiers()).some(id => bodyPath.scope.hasOwnBinding(id))) {
block = t.blockStatement([declar, body]);
if (_core.types.isBlockStatement(body) && Object.keys(path.getBindingIdentifiers()).some(id => bodyPath.scope.hasOwnBinding(id))) {
block = _core.types.blockStatement([declar, body]);
} else {
block = t.toBlock(body);
block = _core.types.toBlock(body);
block.body.unshift(declar);

@@ -17,3 +23,3 @@ }

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

@@ -61,17 +67,17 @@ api.assertVersion(7);

let array = scope.maybeGenerateMemoised(right, true);
const inits = [t.variableDeclarator(i, t.numericLiteral(0))];
const inits = [_core.types.variableDeclarator(i, _core.types.numericLiteral(0))];
if (array) {
inits.push(t.variableDeclarator(array, right));
inits.push(_core.types.variableDeclarator(array, right));
} else {
array = right;
}
const item = t.memberExpression(t.cloneNode(array), t.cloneNode(i), true);
const item = _core.types.memberExpression(_core.types.cloneNode(array), _core.types.cloneNode(i), true);
let assignment;
if (t.isVariableDeclaration(left)) {
if (_core.types.isVariableDeclaration(left)) {
assignment = left;
assignment.declarations[0].init = item;
} else {
assignment = t.expressionStatement(t.assignmentExpression("=", left, item));
assignment = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, item));
}
path.replaceWith(t.forStatement(t.variableDeclaration("let", inits), t.binaryExpression("<", t.cloneNode(i), t.memberExpression(t.cloneNode(array), t.identifier("length"))), t.updateExpression("++", t.cloneNode(i)), buildLoopBody(path, assignment)));
path.replaceWith(_core.types.forStatement(_core.types.variableDeclaration("let", inits), _core.types.binaryExpression("<", _core.types.cloneNode(i), _core.types.memberExpression(_core.types.cloneNode(array), _core.types.identifier("length"))), _core.types.updateExpression("++", _core.types.cloneNode(i)), buildLoopBody(path, assignment)));
}

@@ -81,10 +87,10 @@ }

}
const buildForOfArray = template`
const buildForOfArray = (0, _core.template)`
for (var KEY = 0, NAME = ARR; KEY < NAME.length; KEY++) BODY;
`;
const buildForOfNoIteratorClosing = template.statements`
const buildForOfNoIteratorClosing = _core.template.statements`
for (var ITERATOR_HELPER = CREATE_ITERATOR_HELPER(OBJECT, ARRAY_LIKE_IS_ITERABLE), STEP_KEY;
!(STEP_KEY = ITERATOR_HELPER()).done;) BODY;
`;
const buildForOf = template.statements`
const buildForOf = _core.template.statements`
var ITERATOR_HELPER = CREATE_ITERATOR_HELPER(OBJECT, ARRAY_LIKE_IS_ITERABLE), STEP_KEY;

@@ -121,11 +127,11 @@ try {

});
t.inherits(loop, node);
const iterationValue = t.memberExpression(t.cloneNode(right), t.cloneNode(iterationKey), true);
_core.types.inherits(loop, node);
const iterationValue = _core.types.memberExpression(_core.types.cloneNode(right), _core.types.cloneNode(iterationKey), true);
let declar;
const left = node.left;
if (t.isVariableDeclaration(left)) {
if (_core.types.isVariableDeclaration(left)) {
left.declarations[0].init = iterationValue;
declar = left;
} else {
declar = t.expressionStatement(t.assignmentExpression("=", left, iterationValue));
declar = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, iterationValue));
}

@@ -140,3 +146,3 @@ loop.body = buildLoopBody(path, declar, loop.body);

const right = path.get("right");
if (right.isArrayExpression() || right.isGenericType("Array") || t.isArrayTypeAnnotation(right.getTypeAnnotation())) {
if (right.isArrayExpression() || right.isGenericType("Array") || _core.types.isArrayTypeAnnotation(right.getTypeAnnotation())) {
path.replaceWith(_ForOfStatementArray(path));

@@ -146,3 +152,3 @@ return;

if (!state.availableHelper(builder.helper)) {
transformWithoutHelper(skipIteratorClosing, path, state);
(0, _noHelperImplementation.default)(skipIteratorClosing, path, state);
return;

@@ -158,7 +164,7 @@ }

const stepKey = scope.generateUid("step");
const stepValue = t.memberExpression(t.identifier(stepKey), t.identifier("value"));
if (t.isVariableDeclaration(left)) {
declar = t.variableDeclaration(left.kind, [t.variableDeclarator(left.declarations[0].id, stepValue)]);
const stepValue = _core.types.memberExpression(_core.types.identifier(stepKey), _core.types.identifier("value"));
if (_core.types.isVariableDeclaration(left)) {
declar = _core.types.variableDeclaration(left.kind, [_core.types.variableDeclarator(left.declarations[0].id, stepValue)]);
} else {
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
declar = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, stepValue));
}

@@ -168,4 +174,4 @@ const nodes = builder.build({

ITERATOR_HELPER: scope.generateUidIdentifier("iterator"),
ARRAY_LIKE_IS_ITERABLE: arrayLikeIsIterable ? t.booleanLiteral(true) : null,
STEP_KEY: t.identifier(stepKey),
ARRAY_LIKE_IS_ITERABLE: arrayLikeIsIterable ? _core.types.booleanLiteral(true) : null,
STEP_KEY: _core.types.identifier(stepKey),
OBJECT: node.right,

@@ -175,6 +181,6 @@ BODY: buildLoopBody(path, declar)

const container = builder.getContainer(nodes);
t.inherits(container[0], node);
t.inherits(container[0].body, node.body);
if (t.isLabeledStatement(parent)) {
container[0] = t.labeledStatement(parent.label, container[0]);
_core.types.inherits(container[0], node);
_core.types.inherits(container[0].body, node.body);
if (_core.types.isLabeledStatement(parent)) {
container[0] = _core.types.labeledStatement(parent.label, container[0]);
path.parentPath.replaceWithMultiple(nodes);

@@ -189,3 +195,4 @@ path.skip();

});
exports.default = _default;
//# sourceMappingURL=index.js.map

@@ -1,3 +0,9 @@

import { template, types as t } from "@babel/core";
export default function transformWithoutHelper(loose, path, state) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = transformWithoutHelper;
var _core = require("@babel/core");
function transformWithoutHelper(loose, path, state) {
const pushComputedProps = loose ? pushComputedPropsLoose : pushComputedPropsSpec;

@@ -16,4 +22,4 @@ const {

block.body.push(...node.body.body);
t.inherits(loop, node);
t.inherits(loop.body, node.body);
_core.types.inherits(loop, node);
_core.types.inherits(loop.body, node.body);
if (build.replaceParent) {

@@ -26,3 +32,3 @@ path.parentPath.replaceWithMultiple(build.node);

}
const buildForOfLoose = template.statement(`
const buildForOfLoose = _core.template.statement(`
for (var LOOP_OBJECT = OBJECT,

@@ -43,3 +49,3 @@ IS_ARRAY = Array.isArray(LOOP_OBJECT),

`);
const buildForOf = template.statements(`
const buildForOf = _core.template.statements(`
var ITERATOR_COMPLETION = true;

@@ -79,9 +85,9 @@ var ITERATOR_HAD_ERROR_KEY = false;

let declar, id, intermediate;
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
if (_core.types.isIdentifier(left) || _core.types.isPattern(left) || _core.types.isMemberExpression(left)) {
id = left;
intermediate = null;
} else if (t.isVariableDeclaration(left)) {
} else if (_core.types.isVariableDeclaration(left)) {
id = scope.generateUidIdentifier("ref");
declar = t.variableDeclaration(left.kind, [t.variableDeclarator(left.declarations[0].id, t.identifier(id.name))]);
intermediate = t.variableDeclaration("var", [t.variableDeclarator(t.identifier(id.name))]);
declar = _core.types.variableDeclaration(left.kind, [_core.types.variableDeclarator(left.declarations[0].id, _core.types.identifier(id.name))]);
intermediate = _core.types.variableDeclaration("var", [_core.types.variableDeclarator(_core.types.identifier(id.name))]);
} else {

@@ -100,6 +106,6 @@ throw state.buildCodeFrameError(left, `Unknown node type ${left.type} in ForStatement`);

});
const isLabeledParent = t.isLabeledStatement(parent);
const isLabeledParent = _core.types.isLabeledStatement(parent);
let labeled;
if (isLabeledParent) {
labeled = t.labeledStatement(parent.label, loop);
labeled = _core.types.labeledStatement(parent.label, loop);
}

@@ -122,7 +128,7 @@ return {

const stepKey = scope.generateUid("step");
const stepValue = t.memberExpression(t.identifier(stepKey), t.identifier("value"));
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) {
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
} else if (t.isVariableDeclaration(left)) {
declar = t.variableDeclaration(left.kind, [t.variableDeclarator(left.declarations[0].id, stepValue)]);
const stepValue = _core.types.memberExpression(_core.types.identifier(stepKey), _core.types.identifier("value"));
if (_core.types.isIdentifier(left) || _core.types.isPattern(left) || _core.types.isMemberExpression(left)) {
declar = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, stepValue));
} else if (_core.types.isVariableDeclaration(left)) {
declar = _core.types.variableDeclaration(left.kind, [_core.types.variableDeclarator(left.declarations[0].id, stepValue)]);
} else {

@@ -136,10 +142,10 @@ throw state.buildCodeFrameError(left, `Unknown node type ${left.type} in ForStatement`);

ITERATOR_KEY: scope.generateUidIdentifier("iterator"),
STEP_KEY: t.identifier(stepKey),
STEP_KEY: _core.types.identifier(stepKey),
OBJECT: node.right
});
const isLabeledParent = t.isLabeledStatement(parent);
const isLabeledParent = _core.types.isLabeledStatement(parent);
const tryBody = template[3].block.body;
const loop = tryBody[0];
if (isLabeledParent) {
tryBody[0] = t.labeledStatement(parent.label, loop);
tryBody[0] = _core.types.labeledStatement(parent.label, loop);
}

@@ -146,0 +152,0 @@ return {

{
"name": "@babel/plugin-transform-for-of",
"version": "7.21.4-esm.2",
"version": "7.21.4-esm.3",
"description": "Compile ES2015 for...of to ES5",

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

"dependencies": {
"@babel/helper-plugin-utils": "7.21.4-esm.2"
"@babel/helper-plugin-utils": "7.21.4-esm.3"
},

@@ -27,4 +27,4 @@ "peerDependencies": {

"devDependencies": {
"@babel/core": "7.21.4-esm.2",
"@babel/helper-plugin-test-runner": "7.21.4-esm.2"
"@babel/core": "7.21.4-esm.3",
"@babel/helper-plugin-test-runner": "7.21.4-esm.3"
},

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

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc