@babel/plugin-transform-for-of
Advanced tools
Comparing version 7.21.4-esm.3 to 7.21.4-esm.4
@@ -1,10 +0,4 @@ | ||
"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"); | ||
import { declare } from "@babel/helper-plugin-utils"; | ||
import { template, types as t } from "@babel/core"; | ||
import transformWithoutHelper from "./no-helper-implementation.js"; | ||
function buildLoopBody(path, declar, newBody) { | ||
@@ -14,6 +8,6 @@ let block; | ||
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]); | ||
if (t.isBlockStatement(body) && Object.keys(path.getBindingIdentifiers()).some(id => bodyPath.scope.hasOwnBinding(id))) { | ||
block = t.blockStatement([declar, body]); | ||
} else { | ||
block = _core.types.toBlock(body); | ||
block = t.toBlock(body); | ||
block.body.unshift(declar); | ||
@@ -23,3 +17,3 @@ } | ||
} | ||
var _default = (0, _helperPluginUtils.declare)((api, options) => { | ||
export default declare((api, options) => { | ||
var _options$assumeArray, _options$allowArrayLi, _api$assumption; | ||
@@ -67,17 +61,17 @@ api.assertVersion(7); | ||
let array = scope.maybeGenerateMemoised(right, true); | ||
const inits = [_core.types.variableDeclarator(i, _core.types.numericLiteral(0))]; | ||
const inits = [t.variableDeclarator(i, t.numericLiteral(0))]; | ||
if (array) { | ||
inits.push(_core.types.variableDeclarator(array, right)); | ||
inits.push(t.variableDeclarator(array, right)); | ||
} else { | ||
array = right; | ||
} | ||
const item = _core.types.memberExpression(_core.types.cloneNode(array), _core.types.cloneNode(i), true); | ||
const item = t.memberExpression(t.cloneNode(array), t.cloneNode(i), true); | ||
let assignment; | ||
if (_core.types.isVariableDeclaration(left)) { | ||
if (t.isVariableDeclaration(left)) { | ||
assignment = left; | ||
assignment.declarations[0].init = item; | ||
} else { | ||
assignment = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, item)); | ||
assignment = t.expressionStatement(t.assignmentExpression("=", left, item)); | ||
} | ||
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))); | ||
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))); | ||
} | ||
@@ -87,10 +81,10 @@ } | ||
} | ||
const buildForOfArray = (0, _core.template)` | ||
const buildForOfArray = template` | ||
for (var KEY = 0, NAME = ARR; KEY < NAME.length; KEY++) BODY; | ||
`; | ||
const buildForOfNoIteratorClosing = _core.template.statements` | ||
const buildForOfNoIteratorClosing = template.statements` | ||
for (var ITERATOR_HELPER = CREATE_ITERATOR_HELPER(OBJECT, ARRAY_LIKE_IS_ITERABLE), STEP_KEY; | ||
!(STEP_KEY = ITERATOR_HELPER()).done;) BODY; | ||
`; | ||
const buildForOf = _core.template.statements` | ||
const buildForOf = template.statements` | ||
var ITERATOR_HELPER = CREATE_ITERATOR_HELPER(OBJECT, ARRAY_LIKE_IS_ITERABLE), STEP_KEY; | ||
@@ -127,11 +121,11 @@ try { | ||
}); | ||
_core.types.inherits(loop, node); | ||
const iterationValue = _core.types.memberExpression(_core.types.cloneNode(right), _core.types.cloneNode(iterationKey), true); | ||
t.inherits(loop, node); | ||
const iterationValue = t.memberExpression(t.cloneNode(right), t.cloneNode(iterationKey), true); | ||
let declar; | ||
const left = node.left; | ||
if (_core.types.isVariableDeclaration(left)) { | ||
if (t.isVariableDeclaration(left)) { | ||
left.declarations[0].init = iterationValue; | ||
declar = left; | ||
} else { | ||
declar = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, iterationValue)); | ||
declar = t.expressionStatement(t.assignmentExpression("=", left, iterationValue)); | ||
} | ||
@@ -146,3 +140,3 @@ loop.body = buildLoopBody(path, declar, loop.body); | ||
const right = path.get("right"); | ||
if (right.isArrayExpression() || right.isGenericType("Array") || _core.types.isArrayTypeAnnotation(right.getTypeAnnotation())) { | ||
if (right.isArrayExpression() || right.isGenericType("Array") || t.isArrayTypeAnnotation(right.getTypeAnnotation())) { | ||
path.replaceWith(_ForOfStatementArray(path)); | ||
@@ -152,3 +146,3 @@ return; | ||
if (!state.availableHelper(builder.helper)) { | ||
(0, _noHelperImplementation.default)(skipIteratorClosing, path, state); | ||
transformWithoutHelper(skipIteratorClosing, path, state); | ||
return; | ||
@@ -164,7 +158,7 @@ } | ||
const stepKey = scope.generateUid("step"); | ||
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)]); | ||
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)]); | ||
} else { | ||
declar = _core.types.expressionStatement(_core.types.assignmentExpression("=", left, stepValue)); | ||
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue)); | ||
} | ||
@@ -174,4 +168,4 @@ const nodes = builder.build({ | ||
ITERATOR_HELPER: scope.generateUidIdentifier("iterator"), | ||
ARRAY_LIKE_IS_ITERABLE: arrayLikeIsIterable ? _core.types.booleanLiteral(true) : null, | ||
STEP_KEY: _core.types.identifier(stepKey), | ||
ARRAY_LIKE_IS_ITERABLE: arrayLikeIsIterable ? t.booleanLiteral(true) : null, | ||
STEP_KEY: t.identifier(stepKey), | ||
OBJECT: node.right, | ||
@@ -181,6 +175,6 @@ BODY: buildLoopBody(path, declar) | ||
const container = builder.getContainer(nodes); | ||
_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]); | ||
t.inherits(container[0], node); | ||
t.inherits(container[0].body, node.body); | ||
if (t.isLabeledStatement(parent)) { | ||
container[0] = t.labeledStatement(parent.label, container[0]); | ||
path.parentPath.replaceWithMultiple(nodes); | ||
@@ -195,4 +189,3 @@ path.skip(); | ||
}); | ||
exports.default = _default; | ||
//# sourceMappingURL=index.js.map |
@@ -1,9 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = transformWithoutHelper; | ||
var _core = require("@babel/core"); | ||
function transformWithoutHelper(loose, path, state) { | ||
import { template, types as t } from "@babel/core"; | ||
export default function transformWithoutHelper(loose, path, state) { | ||
const pushComputedProps = loose ? pushComputedPropsLoose : pushComputedPropsSpec; | ||
@@ -22,4 +16,4 @@ const { | ||
block.body.push(...node.body.body); | ||
_core.types.inherits(loop, node); | ||
_core.types.inherits(loop.body, node.body); | ||
t.inherits(loop, node); | ||
t.inherits(loop.body, node.body); | ||
if (build.replaceParent) { | ||
@@ -32,3 +26,3 @@ path.parentPath.replaceWithMultiple(build.node); | ||
} | ||
const buildForOfLoose = _core.template.statement(` | ||
const buildForOfLoose = template.statement(` | ||
for (var LOOP_OBJECT = OBJECT, | ||
@@ -49,3 +43,3 @@ IS_ARRAY = Array.isArray(LOOP_OBJECT), | ||
`); | ||
const buildForOf = _core.template.statements(` | ||
const buildForOf = template.statements(` | ||
var ITERATOR_COMPLETION = true; | ||
@@ -85,9 +79,9 @@ var ITERATOR_HAD_ERROR_KEY = false; | ||
let declar, id, intermediate; | ||
if (_core.types.isIdentifier(left) || _core.types.isPattern(left) || _core.types.isMemberExpression(left)) { | ||
if (t.isIdentifier(left) || t.isPattern(left) || t.isMemberExpression(left)) { | ||
id = left; | ||
intermediate = null; | ||
} else if (_core.types.isVariableDeclaration(left)) { | ||
} else if (t.isVariableDeclaration(left)) { | ||
id = scope.generateUidIdentifier("ref"); | ||
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))]); | ||
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))]); | ||
} else { | ||
@@ -106,6 +100,6 @@ throw state.buildCodeFrameError(left, `Unknown node type ${left.type} in ForStatement`); | ||
}); | ||
const isLabeledParent = _core.types.isLabeledStatement(parent); | ||
const isLabeledParent = t.isLabeledStatement(parent); | ||
let labeled; | ||
if (isLabeledParent) { | ||
labeled = _core.types.labeledStatement(parent.label, loop); | ||
labeled = t.labeledStatement(parent.label, loop); | ||
} | ||
@@ -128,7 +122,7 @@ return { | ||
const stepKey = scope.generateUid("step"); | ||
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)]); | ||
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)]); | ||
} else { | ||
@@ -142,10 +136,10 @@ throw state.buildCodeFrameError(left, `Unknown node type ${left.type} in ForStatement`); | ||
ITERATOR_KEY: scope.generateUidIdentifier("iterator"), | ||
STEP_KEY: _core.types.identifier(stepKey), | ||
STEP_KEY: t.identifier(stepKey), | ||
OBJECT: node.right | ||
}); | ||
const isLabeledParent = _core.types.isLabeledStatement(parent); | ||
const isLabeledParent = t.isLabeledStatement(parent); | ||
const tryBody = template[3].block.body; | ||
const loop = tryBody[0]; | ||
if (isLabeledParent) { | ||
tryBody[0] = _core.types.labeledStatement(parent.label, loop); | ||
tryBody[0] = t.labeledStatement(parent.label, loop); | ||
} | ||
@@ -152,0 +146,0 @@ return { |
{ | ||
"name": "@babel/plugin-transform-for-of", | ||
"version": "7.21.4-esm.3", | ||
"version": "7.21.4-esm.4", | ||
"description": "Compile ES2015 for...of to ES5", | ||
@@ -20,3 +20,3 @@ "repository": { | ||
"dependencies": { | ||
"@babel/helper-plugin-utils": "7.21.4-esm.3" | ||
"@babel/helper-plugin-utils": "7.21.4-esm.4" | ||
}, | ||
@@ -27,4 +27,4 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "7.21.4-esm.3", | ||
"@babel/helper-plugin-test-runner": "7.21.4-esm.3" | ||
"@babel/core": "7.21.4-esm.4", | ||
"@babel/helper-plugin-test-runner": "7.21.4-esm.4" | ||
}, | ||
@@ -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
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
8
41986
325
+ Added@babel/helper-plugin-utils@7.21.4-esm.4(transitive)
- Removed@babel/helper-plugin-utils@7.21.4-esm.3(transitive)