Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Destructuring exceptions in nested for expressions #14841

Merged
merged 4 commits into from Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions packages/babel-plugin-transform-destructuring/src/util.ts
Expand Up @@ -327,7 +327,6 @@ export class DestructuringTransformer {
}
}
}
//

for (let i = 0; i < pattern.properties.length; i++) {
const prop = pattern.properties[i];
Expand Down Expand Up @@ -484,8 +483,6 @@ export class DestructuringTransformer {
}
}

//

this.push(pattern, ref);

return this.nodes;
Expand Down Expand Up @@ -620,6 +617,8 @@ export function convertVariableDeclaration(
}
}

const inForInit = t.isForStatement(path.parent, { init: node });

let tail: t.VariableDeclaration | null = null;
const nodesOut = [];
for (const node of nodes) {
Expand All @@ -640,7 +639,9 @@ export function convertVariableDeclaration(
if (!node.loc) {
node.loc = nodeLoc;
}
nodesOut.push(node);
nodesOut.push(
inForInit && node.type === "ExpressionStatement" ? node.expression : node,
);
}

if (nodesOut.length === 1) {
Expand Down
@@ -0,0 +1,5 @@
for ( let x in y ) for ( ; ; ) var { } = x ;

for ( let x in y ) for ( var { } = x ; ; ) ;

for ( let x in y ) for ( ; { } = x ; {} = x ) var { } = x ;
@@ -0,0 +1,19 @@
for (var x in y) {
for (;;) {
babelHelpers.objectDestructuringEmpty(x);
}
}

for (var _x in y) {
for (babelHelpers.objectDestructuringEmpty(_x);;) {
;
}
}

for (var _x2 in y) {
for (; _x3 = _x2, babelHelpers.objectDestructuringEmpty(_x3), _x3; _x4 = _x2, babelHelpers.objectDestructuringEmpty(_x4), _x4) {
var _x3, _x4;

babelHelpers.objectDestructuringEmpty(_x2);
}
}