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

@babel/plugin-transform-for-of

Package Overview
Dependencies
Maintainers
5
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@babel/plugin-transform-for-of - npm Package Compare versions

Comparing version 7.0.0-beta.46 to 7.0.0-beta.47

165

lib/index.js

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

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

@@ -20,3 +20,3 @@ _helperPluginUtils = function _helperPluginUtils() {

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

@@ -30,9 +30,9 @@ _core = function _core() {

var _default = (0, _helperPluginUtils().declare)(function (api, options) {
var _default = (0, _helperPluginUtils().declare)((api, options) => {
api.assertVersion(7);
var loose = options.loose,
assumeArray = options.assumeArray;
const loose = options.loose,
assumeArray = options.assumeArray;
if (loose === true && assumeArray === true) {
throw new Error("The loose and assumeArray options cannot be used together in @babel/plugin-transform-for-of");
throw new Error(`The loose and assumeArray options cannot be used together in @babel/plugin-transform-for-of`);
}

@@ -43,11 +43,11 @@

visitor: {
ForOfStatement: function ForOfStatement(path) {
var scope = path.scope;
var _path$node = path.node,
left = _path$node.left,
right = _path$node.right,
body = _path$node.body;
var i = scope.generateUidIdentifier("i");
var array = scope.maybeGenerateMemoised(right, true);
var inits = [_core().types.variableDeclarator(i, _core().types.numericLiteral(0))];
ForOfStatement(path) {
const scope = path.scope;
const _path$node = path.node,
left = _path$node.left,
right = _path$node.right,
body = _path$node.body;
const i = scope.generateUidIdentifier("i");
let array = scope.maybeGenerateMemoised(right, true);
const inits = [_core().types.variableDeclarator(i, _core().types.numericLiteral(0))];

@@ -60,5 +60,5 @@ if (array) {

var item = _core().types.memberExpression(_core().types.cloneNode(array), _core().types.cloneNode(i), true);
const item = _core().types.memberExpression(_core().types.cloneNode(array), _core().types.cloneNode(i), true);
var assignment;
let assignment;

@@ -72,3 +72,3 @@ if (_core().types.isVariableDeclaration(left)) {

var block = _core().types.toBlock(body);
const block = _core().types.toBlock(body);

@@ -78,2 +78,3 @@ block.body.unshift(assignment);

}
}

@@ -83,15 +84,56 @@ };

var pushComputedProps = loose ? pushComputedPropsLoose : pushComputedPropsSpec;
var buildForOfArray = (0, _core().template)("\n for (var KEY = 0; KEY < ARR.length; KEY++) BODY;\n ");
var buildForOfLoose = (0, _core().template)("\n for (var LOOP_OBJECT = OBJECT,\n IS_ARRAY = Array.isArray(LOOP_OBJECT),\n INDEX = 0,\n LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) {\n INTERMEDIATE;\n if (IS_ARRAY) {\n if (INDEX >= LOOP_OBJECT.length) break;\n ID = LOOP_OBJECT[INDEX++];\n } else {\n INDEX = LOOP_OBJECT.next();\n if (INDEX.done) break;\n ID = INDEX.value;\n }\n }\n ");
var buildForOf = (0, _core().template)("\n var ITERATOR_COMPLETION = true;\n var ITERATOR_HAD_ERROR_KEY = false;\n var ITERATOR_ERROR_KEY = undefined;\n try {\n for (\n var ITERATOR_KEY = OBJECT[Symbol.iterator](), STEP_KEY;\n !(ITERATOR_COMPLETION = (STEP_KEY = ITERATOR_KEY.next()).done);\n ITERATOR_COMPLETION = true\n ) {}\n } catch (err) {\n ITERATOR_HAD_ERROR_KEY = true;\n ITERATOR_ERROR_KEY = err;\n } finally {\n try {\n if (!ITERATOR_COMPLETION && ITERATOR_KEY.return != null) {\n ITERATOR_KEY.return();\n }\n } finally {\n if (ITERATOR_HAD_ERROR_KEY) {\n throw ITERATOR_ERROR_KEY;\n }\n }\n }\n ");
const pushComputedProps = loose ? pushComputedPropsLoose : pushComputedPropsSpec;
const buildForOfArray = (0, _core().template)(`
for (var KEY = 0; KEY < ARR.length; KEY++) BODY;
`);
const buildForOfLoose = (0, _core().template)(`
for (var LOOP_OBJECT = OBJECT,
IS_ARRAY = Array.isArray(LOOP_OBJECT),
INDEX = 0,
LOOP_OBJECT = IS_ARRAY ? LOOP_OBJECT : LOOP_OBJECT[Symbol.iterator]();;) {
INTERMEDIATE;
if (IS_ARRAY) {
if (INDEX >= LOOP_OBJECT.length) break;
ID = LOOP_OBJECT[INDEX++];
} else {
INDEX = LOOP_OBJECT.next();
if (INDEX.done) break;
ID = INDEX.value;
}
}
`);
const buildForOf = (0, _core().template)(`
var ITERATOR_COMPLETION = true;
var ITERATOR_HAD_ERROR_KEY = false;
var ITERATOR_ERROR_KEY = undefined;
try {
for (
var ITERATOR_KEY = OBJECT[Symbol.iterator](), STEP_KEY;
!(ITERATOR_COMPLETION = (STEP_KEY = ITERATOR_KEY.next()).done);
ITERATOR_COMPLETION = true
) {}
} catch (err) {
ITERATOR_HAD_ERROR_KEY = true;
ITERATOR_ERROR_KEY = err;
} finally {
try {
if (!ITERATOR_COMPLETION && ITERATOR_KEY.return != null) {
ITERATOR_KEY.return();
}
} finally {
if (ITERATOR_HAD_ERROR_KEY) {
throw ITERATOR_ERROR_KEY;
}
}
}
`);
function _ForOfStatementArray(path) {
var node = path.node,
scope = path.scope;
var nodes = [];
var right = node.right;
const node = path.node,
scope = path.scope;
const nodes = [];
let right = node.right;
if (!_core().types.isIdentifier(right) || !scope.hasBinding(right.name)) {
var uid = scope.generateUid("arr");
const uid = scope.generateUid("arr");
nodes.push(_core().types.variableDeclaration("var", [_core().types.variableDeclarator(_core().types.identifier(uid), right)]));

@@ -101,4 +143,4 @@ right = _core().types.identifier(uid);

var iterationKey = scope.generateUidIdentifier("i");
var loop = buildForOfArray({
const iterationKey = scope.generateUidIdentifier("i");
let loop = buildForOfArray({
BODY: node.body,

@@ -113,5 +155,5 @@ KEY: iterationKey,

var iterationValue = _core().types.memberExpression(_core().types.cloneNode(right), _core().types.cloneNode(iterationKey), true);
const iterationValue = _core().types.memberExpression(_core().types.cloneNode(right), _core().types.cloneNode(iterationKey), true);
var left = node.left;
const left = node.left;

@@ -143,4 +185,4 @@ if (_core().types.isVariableDeclaration(left)) {

visitor: {
ForOfStatement: function ForOfStatement(path, state) {
var right = path.get("right");
ForOfStatement(path, state) {
const right = path.get("right");

@@ -152,7 +194,7 @@ if (right.isArrayExpression() || right.isGenericType("Array") || _core().types.isArrayTypeAnnotation(right.getTypeAnnotation())) {

var node = path.node;
var build = pushComputedProps(path, state);
var declar = build.declar;
var loop = build.loop;
var block = loop.body;
const node = path.node;
const build = pushComputedProps(path, state);
const declar = build.declar;
const loop = build.loop;
const block = loop.body;
path.ensureBlock();

@@ -177,2 +219,3 @@

}
}

@@ -182,7 +225,7 @@ };

function pushComputedPropsLoose(path, file) {
var node = path.node,
scope = path.scope,
parent = path.parent;
var left = node.left;
var declar, id, intermediate;
const node = path.node,
scope = path.scope,
parent = path.parent;
const left = node.left;
let declar, id, intermediate;

@@ -197,8 +240,8 @@ if (_core().types.isIdentifier(left) || _core().types.isPattern(left) || _core().types.isMemberExpression(left)) {

} else {
throw file.buildCodeFrameError(left, "Unknown node type " + left.type + " in ForStatement");
throw file.buildCodeFrameError(left, `Unknown node type ${left.type} in ForStatement`);
}
var iteratorKey = scope.generateUidIdentifier("iterator");
var isArrayKey = scope.generateUidIdentifier("isArray");
var loop = buildForOfLoose({
const iteratorKey = scope.generateUidIdentifier("iterator");
const isArrayKey = scope.generateUidIdentifier("isArray");
const loop = buildForOfLoose({
LOOP_OBJECT: iteratorKey,

@@ -212,5 +255,5 @@ IS_ARRAY: isArrayKey,

var isLabeledParent = _core().types.isLabeledStatement(parent);
const isLabeledParent = _core().types.isLabeledStatement(parent);
var labeled;
let labeled;

@@ -230,10 +273,10 @@ if (isLabeledParent) {

function pushComputedPropsSpec(path, file) {
var node = path.node,
scope = path.scope,
parent = path.parent;
var left = node.left;
var declar;
var stepKey = scope.generateUid("step");
const node = path.node,
scope = path.scope,
parent = path.parent;
const left = node.left;
let declar;
const stepKey = scope.generateUid("step");
var stepValue = _core().types.memberExpression(_core().types.identifier(stepKey), _core().types.identifier("value"));
const stepValue = _core().types.memberExpression(_core().types.identifier(stepKey), _core().types.identifier("value"));

@@ -245,6 +288,6 @@ if (_core().types.isIdentifier(left) || _core().types.isPattern(left) || _core().types.isMemberExpression(left)) {

} else {
throw file.buildCodeFrameError(left, "Unknown node type " + left.type + " in ForStatement");
throw file.buildCodeFrameError(left, `Unknown node type ${left.type} in ForStatement`);
}
var template = buildForOf({
const template = buildForOf({
ITERATOR_HAD_ERROR_KEY: scope.generateUidIdentifier("didIteratorError"),

@@ -258,6 +301,6 @@ ITERATOR_COMPLETION: scope.generateUidIdentifier("iteratorNormalCompletion"),

var isLabeledParent = _core().types.isLabeledStatement(parent);
const isLabeledParent = _core().types.isLabeledStatement(parent);
var tryBody = template[3].block.body;
var loop = tryBody[0];
const tryBody = template[3].block.body;
const loop = tryBody[0];

@@ -264,0 +307,0 @@ if (isLabeledParent) {

{
"name": "@babel/plugin-transform-for-of",
"version": "7.0.0-beta.46",
"version": "7.0.0-beta.47",
"description": "Compile ES2015 for...of to ES5",

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

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