@babel/plugin-transform-for-of
Advanced tools
Comparing version 7.17.12 to 7.18.1
@@ -14,2 +14,17 @@ "use strict"; | ||
function buildLoopBody(path, declar, newBody) { | ||
let block; | ||
const bodyPath = path.get("body"); | ||
const body = newBody != null ? newBody : bodyPath.node; | ||
if (_core.types.isBlockStatement(body) && Object.keys(path.getBindingIdentifiers()).some(id => bodyPath.scope.hasOwnBinding(id))) { | ||
block = _core.types.blockStatement([declar, body]); | ||
} else { | ||
block = _core.types.toBlock(body); | ||
block.body.unshift(declar); | ||
} | ||
return block; | ||
} | ||
var _default = (0, _helperPluginUtils.declare)((api, options) => { | ||
@@ -85,13 +100,3 @@ var _options$assumeArray, _options$allowArrayLi, _api$assumption; | ||
let blockBody; | ||
const body = path.get("body"); | ||
if (body.isBlockStatement() && Object.keys(path.getBindingIdentifiers()).some(id => body.scope.hasOwnBinding(id))) { | ||
blockBody = _core.types.blockStatement([assignment, body.node]); | ||
} else { | ||
blockBody = _core.types.toBlock(body.node); | ||
blockBody.body.unshift(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)), blockBody)); | ||
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))); | ||
} | ||
@@ -146,6 +151,5 @@ | ||
_core.types.ensureBlock(loop); | ||
const iterationValue = _core.types.memberExpression(_core.types.cloneNode(right), _core.types.cloneNode(iterationKey), true); | ||
let declar; | ||
const left = node.left; | ||
@@ -155,7 +159,8 @@ | ||
left.declarations[0].init = iterationValue; | ||
loop.body.body.unshift(left); | ||
declar = left; | ||
} else { | ||
loop.body.body.unshift(_core.types.expressionStatement(_core.types.assignmentExpression("=", left, iterationValue))); | ||
declar = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, iterationValue)); | ||
} | ||
loop.body = buildLoopBody(path, declar, loop.body); | ||
return loop; | ||
@@ -197,4 +202,2 @@ } | ||
path.ensureBlock(); | ||
node.body.body.unshift(declar); | ||
const nodes = builder.build({ | ||
@@ -206,3 +209,3 @@ CREATE_ITERATOR_HELPER: state.addHelper(builder.helper), | ||
OBJECT: node.right, | ||
BODY: node.body | ||
BODY: buildLoopBody(path, declar) | ||
}); | ||
@@ -209,0 +212,0 @@ const container = builder.getContainer(nodes); |
{ | ||
"name": "@babel/plugin-transform-for-of", | ||
"version": "7.17.12", | ||
"version": "7.18.1", | ||
"description": "Compile ES2015 for...of to ES5", | ||
@@ -26,3 +26,3 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/core": "^7.17.12", | ||
"@babel/core": "^7.18.0", | ||
"@babel/helper-plugin-test-runner": "^7.16.7" | ||
@@ -29,0 +29,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14747
333