Skip to content

Commit

Permalink
apply babel#14240 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Feb 23, 2022
1 parent 15d6e32 commit f9fd0af
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/babel-plugin-transform-destructuring/src/util.ts
Expand Up @@ -122,8 +122,16 @@ export class DestructuringTransformer {
),
);
} else {
let nodeInit: t.Expression;

if (this.kind === "const" && init === null) {
nodeInit = this.scope.buildUndefinedNode();
} else {
nodeInit = t.cloneNode(init);
}

node = t.variableDeclaration(this.kind, [
t.variableDeclarator(id, t.cloneNode(init)),
t.variableDeclarator(id, nodeInit),
]);
}

Expand Down Expand Up @@ -170,6 +178,14 @@ export class DestructuringTransformer {
{ left, right }: t.AssignmentPattern,
valueRef: t.Expression,
) {
// handle array init hole
// const [x = 42] = [,];
// -> const x = 42;
if (valueRef === null) {
this.nodes.push(this.buildVariableAssignment(left, right));
return;
}

// we need to assign the current value of the assignment to avoid evaluating
// it more than once
const tempId = this.scope.generateUidIdentifierBasedOnNode(valueRef);
Expand Down

0 comments on commit f9fd0af

Please sign in to comment.