Skip to content

Commit

Permalink
fix corner case in inline (#5537)
Browse files Browse the repository at this point in the history
fixes #5536
  • Loading branch information
alexlamsl authored Jul 1, 2022
1 parent 51deeff commit 3596b4f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
8 changes: 4 additions & 4 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -1598,8 +1598,7 @@ Compressor.prototype.compress = function(node) {
AST_Destructured.DEFMETHOD("convert_symbol", convert_destructured);
function convert_symbol(type, process) {
var node = make_node(type, this, this);
process(node, this);
return node;
return process(node, this) || node;
}
AST_SymbolDeclaration.DEFMETHOD("convert_symbol", convert_symbol);
AST_SymbolRef.DEFMETHOD("convert_symbol", convert_symbol);
Expand Down Expand Up @@ -10548,9 +10547,9 @@ Compressor.prototype.compress = function(node) {
return try_evaluate(compressor, self);

function make_void_lhs(orig) {
return make_node(AST_Dot, orig, {
return make_node(AST_Sub, orig, {
expression: make_node(AST_Array, orig, { elements: [] }),
property: "e",
property: make_node(AST_Number, orig, { value: 0 }),
});
}

Expand Down Expand Up @@ -10905,6 +10904,7 @@ Compressor.prototype.compress = function(node) {
}));

function process(ref, name) {
if (name.unused) return make_void_lhs(name);
var def = name.definition();
def.assignments++;
def.references.push(ref);
Expand Down
29 changes: 26 additions & 3 deletions test/compress/default-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ inline_side_effects_2: {
}
expect: {
var a = 42;
[ [].e = --a ] = [ console ];
[ [][0] = --a ] = [ console ];
console.log(a);
}
expect_stdout: "42"
Expand Down Expand Up @@ -1558,7 +1558,7 @@ issue_4502_4: {
(function(a, b = console.log("FAIL")) {})(..."" + console.log(42));
}
expect: {
[ , [].e = console.log("FAIL") ] = [ ..."" + console.log(42) ];
[ , [][0] = console.log("FAIL") ] = [ ..."" + console.log(42) ];
}
expect_stdout: "42"
node_version: ">=6"
Expand Down Expand Up @@ -2183,7 +2183,7 @@ issue_5340_2: {
}
expect: {
var a;
[ [].e = 0 ] = [ ({ p: a } = true).q ];
[ [][0] = 0 ] = [ ({ p: a } = true).q ];
console.log(a);
}
expect_stdout: "undefined"
Expand Down Expand Up @@ -2806,3 +2806,26 @@ issue_5533_4_drop_fargs: {
expect_stdout: "PASS"
node_version: ">=6"
}

issue_5536: {
options = {
inline: true,
keep_fargs: true,
unused: true,
}
input: {
(function*() {
(([], a = 42) => {})([]);
console.log(typeof a);
})().next();
}
expect: {
(function*() {
[ , [][0] = 0 ] = [ [] ],
void 0;
console.log(typeof a);
})().next();
}
expect_stdout: "undefined"
node_version: ">=6"
}
2 changes: 1 addition & 1 deletion test/compress/destructured.js
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,7 @@ issue_5314_2: {
A = this;
new function() {
[ {
[console.log(this === A ? "FAIL" : "PASS")]: [].e,
[console.log(this === A ? "FAIL" : "PASS")]: [][0],
} ] = [ 42 ];
}();
}
Expand Down
2 changes: 1 addition & 1 deletion test/compress/rests.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ drop_new_function: {
}
expect: {
void ([ ... {
[console.log("PASS")]: [].e,
[console.log("PASS")]: [][0],
}] = []);
}
expect_stdout: "PASS"
Expand Down
2 changes: 1 addition & 1 deletion test/compress/yields.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ drop_body: {
})([ console.log("baz") ]);
}
expect: {
[ [ , [].e = console.log("foo") ] ] = [ [ console.log("baz") ] ];
[ [ , [][0] = console.log("foo") ] ] = [ [ console.log("baz") ] ];
}
expect_stdout: [
"baz",
Expand Down

0 comments on commit 3596b4f

Please sign in to comment.