@babel/plugin-transform-destructuring
Advanced tools
Comparing version 7.17.12 to 7.18.0
@@ -8,2 +8,18 @@ 'use strict'; | ||
function unshiftForXStatementBody(statementPath, newStatements) { | ||
statementPath.ensureBlock(); | ||
const { | ||
scope, | ||
node | ||
} = statementPath; | ||
const bodyScopeBindings = statementPath.get("body").scope.bindings; | ||
const hasShadowedBlockScopedBindings = Object.keys(bodyScopeBindings).some(name => scope.hasBinding(name)); | ||
if (hasShadowedBlockScopedBindings) { | ||
node.body = core.types.blockStatement([...newStatements, node.body]); | ||
} else { | ||
node.body.body.unshift(...newStatements); | ||
} | ||
} | ||
function hasArrayRest(pattern) { | ||
@@ -425,3 +441,4 @@ return pattern.elements.some(elem => core.types.isRestElement(elem)); | ||
node, | ||
scope | ||
scope, | ||
parentPath | ||
} = path; | ||
@@ -441,3 +458,3 @@ const nodes = []; | ||
if (path.isCompletionRecord() || !path.parentPath.isExpressionStatement()) { | ||
if (!parentPath.isExpressionStatement() && !parentPath.isSequenceExpression() || path.isCompletionRecord()) { | ||
ref = scope.generateUidIdentifierBasedOnNode(node.right, "ref"); | ||
@@ -454,3 +471,3 @@ nodes.push(core.types.variableDeclaration("var", [core.types.variableDeclarator(ref, node.right)])); | ||
if (ref) { | ||
if (path.parentPath.isArrowFunctionExpression()) { | ||
if (parentPath.isArrowFunctionExpression()) { | ||
path.replaceWith(core.types.blockStatement([])); | ||
@@ -517,8 +534,10 @@ nodes.push(core.types.returnStatement(core.types.cloneNode(ref))); | ||
const statementBody = node.body.body; | ||
const nodes = []; | ||
if (statementBody.length === 0 && path.isCompletionRecord()) { | ||
statementBody.unshift(core.types.expressionStatement(scope.buildUndefinedNode())); | ||
nodes.unshift(core.types.expressionStatement(scope.buildUndefinedNode())); | ||
} | ||
statementBody.unshift(core.types.expressionStatement(core.types.assignmentExpression("=", left, temp))); | ||
nodes.unshift(core.types.expressionStatement(core.types.assignmentExpression("=", left, core.types.cloneNode(temp)))); | ||
unshiftForXStatementBody(path, nodes); | ||
scope.crawl(); | ||
@@ -545,5 +564,3 @@ return; | ||
destructuring.init(pattern, key); | ||
path.ensureBlock(); | ||
const block = node.body; | ||
block.body = nodes.concat(block.body); | ||
unshiftForXStatementBody(path, nodes); | ||
scope.crawl(); | ||
@@ -596,3 +613,5 @@ }, | ||
exports.buildObjectExcludingKeys = buildObjectExcludingKeys; | ||
exports["default"] = index; | ||
exports.unshiftForXStatementBody = unshiftForXStatementBody; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/plugin-transform-destructuring", | ||
"version": "7.17.12", | ||
"version": "7.18.0", | ||
"description": "Compile ES2015 destructuring to ES5", | ||
@@ -26,5 +26,5 @@ "repository": { | ||
"devDependencies": { | ||
"@babel/core": "^7.17.12", | ||
"@babel/core": "^7.18.0", | ||
"@babel/helper-plugin-test-runner": "^7.16.7", | ||
"@babel/traverse": "^7.17.12" | ||
"@babel/traverse": "^7.18.0" | ||
}, | ||
@@ -31,0 +31,0 @@ "engines": { |
Sorry, the diff of this file is not supported yet
78674
537