Skip to content

Commit

Permalink
fix: Destructuring empty in nested for expressions (#14841)
Browse files Browse the repository at this point in the history
* fix

* Update packages/babel-plugin-transform-destructuring/src/util.ts

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>

* review

* review

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
  • Loading branch information
liuxingbaoyu and JLHwung committed Aug 10, 2022
1 parent 73d86fe commit 614d98b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
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);
}
}

0 comments on commit 614d98b

Please sign in to comment.