Skip to content

Commit

Permalink
fix corner case in unused (#5090)
Browse files Browse the repository at this point in the history
fixes #5089
  • Loading branch information
alexlamsl committed Jul 20, 2021
1 parent 85968de commit 8926a2f
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7276,6 +7276,7 @@ merge(Compressor.prototype, {
}

function retain_lhs(node) {
if (node instanceof AST_DefaultValue) return retain_lhs(node.name);
if (node instanceof AST_Destructured) {
if (value === null) {
value = make_node(AST_Number, node, { value: 0 });
Expand All @@ -7289,7 +7290,6 @@ merge(Compressor.prototype, {
}
return make_node(AST_DestructuredObject, node, { properties: [] });
}
if (node instanceof AST_DefaultValue) node = node.name;
node.__unused = null;
return node;
}
Expand Down
4 changes: 2 additions & 2 deletions test/compress/loops.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,9 @@ evaluate: {
} while (false);
}
expect: {
for(;;)
for (;;)
a();
for(;;)
for (;;)
c();
d();
}
Expand Down
55 changes: 54 additions & 1 deletion test/compress/rests.js
Original file line number Diff line number Diff line change
Expand Up @@ -943,10 +943,63 @@ issue_4666: {
expect: {
var a = 0, b = 0;
var o = (c => +a + c)([ b ]);
for(var k in o)
for (var k in o)
b++;
console.log(1, b);
}
expect_stdout: "1 2"
node_version: ">=6"
}

issue_5089_1: {
options = {
unused: true,
}
input: {
var {
p: [] = 42,
...o
} = {
p: [],
};
console.log(o.p);
}
expect: {
var {
p: {},
...o
} = {
p: 0,
};
console.log(o.p);
}
expect_stdout: "undefined"
node_version: ">=8"
}

issue_5089_2: {
options = {
pure_getters: "strict",
unused: true,
}
input: {
var {
p: {} = null,
...o
} = {
p: {},
};
console.log(o.p);
}
expect: {
var {
p: {},
...o
} = {
p: 0,
};
console.log(o.p);
}
expect_stdout: "undefined"
node_version: ">=8"
}
2 changes: 1 addition & 1 deletion test/compress/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ while_if_break: {
}
}
expect: {
for(; a && (b && c && d, !e););
for (; a && (b && c && d, !e););
}
}

Expand Down

0 comments on commit 8926a2f

Please sign in to comment.