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 1 commit
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
11 changes: 7 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 mustVarOrExpr = t.isForStatement(path.parent) && path.key !== "body";
liuxingbaoyu marked this conversation as resolved.
Show resolved Hide resolved

let tail: t.VariableDeclaration | null = null;
const nodesOut = [];
for (const node of nodes) {
Expand All @@ -640,7 +639,11 @@ export function convertVariableDeclaration(
if (!node.loc) {
node.loc = nodeLoc;
}
nodesOut.push(node);
nodesOut.push(
node.type === "ExpressionStatement" && mustVarOrExpr
liuxingbaoyu marked this conversation as resolved.
Show resolved Hide resolved
? node.expression
: node,
);
}

if (nodesOut.length === 1) {
Expand Down
@@ -0,0 +1 @@
for ( let x in a ) for ( var { } = x ; ; ) ;
liuxingbaoyu marked this conversation as resolved.
Show resolved Hide resolved
liuxingbaoyu marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,5 @@
for (var x in a) {
for (babelHelpers.objectDestructuringEmpty(x);;) {
;
}
}