fix corner case in inline (#5537)

fixes #5536
This commit is contained in:
Alex Lam S.L
2022-07-01 17:10:02 +01:00
committed by GitHub
parent 51deeff72e
commit 3596b4feda
5 changed files with 33 additions and 10 deletions

View File

@@ -1598,8 +1598,7 @@ Compressor.prototype.compress = function(node) {
AST_Destructured.DEFMETHOD("convert_symbol", convert_destructured); AST_Destructured.DEFMETHOD("convert_symbol", convert_destructured);
function convert_symbol(type, process) { function convert_symbol(type, process) {
var node = make_node(type, this, this); var node = make_node(type, this, this);
process(node, this); return process(node, this) || node;
return node;
} }
AST_SymbolDeclaration.DEFMETHOD("convert_symbol", convert_symbol); AST_SymbolDeclaration.DEFMETHOD("convert_symbol", convert_symbol);
AST_SymbolRef.DEFMETHOD("convert_symbol", convert_symbol); AST_SymbolRef.DEFMETHOD("convert_symbol", convert_symbol);
@@ -10548,9 +10547,9 @@ Compressor.prototype.compress = function(node) {
return try_evaluate(compressor, self); return try_evaluate(compressor, self);
function make_void_lhs(orig) { function make_void_lhs(orig) {
return make_node(AST_Dot, orig, { return make_node(AST_Sub, orig, {
expression: make_node(AST_Array, orig, { elements: [] }), expression: make_node(AST_Array, orig, { elements: [] }),
property: "e", property: make_node(AST_Number, orig, { value: 0 }),
}); });
} }
@@ -10905,6 +10904,7 @@ Compressor.prototype.compress = function(node) {
})); }));
function process(ref, name) { function process(ref, name) {
if (name.unused) return make_void_lhs(name);
var def = name.definition(); var def = name.definition();
def.assignments++; def.assignments++;
def.references.push(ref); def.references.push(ref);

View File

@@ -541,7 +541,7 @@ inline_side_effects_2: {
} }
expect: { expect: {
var a = 42; var a = 42;
[ [].e = --a ] = [ console ]; [ [][0] = --a ] = [ console ];
console.log(a); console.log(a);
} }
expect_stdout: "42" expect_stdout: "42"
@@ -1558,7 +1558,7 @@ issue_4502_4: {
(function(a, b = console.log("FAIL")) {})(..."" + console.log(42)); (function(a, b = console.log("FAIL")) {})(..."" + console.log(42));
} }
expect: { expect: {
[ , [].e = console.log("FAIL") ] = [ ..."" + console.log(42) ]; [ , [][0] = console.log("FAIL") ] = [ ..."" + console.log(42) ];
} }
expect_stdout: "42" expect_stdout: "42"
node_version: ">=6" node_version: ">=6"
@@ -2183,7 +2183,7 @@ issue_5340_2: {
} }
expect: { expect: {
var a; var a;
[ [].e = 0 ] = [ ({ p: a } = true).q ]; [ [][0] = 0 ] = [ ({ p: a } = true).q ];
console.log(a); console.log(a);
} }
expect_stdout: "undefined" expect_stdout: "undefined"
@@ -2806,3 +2806,26 @@ issue_5533_4_drop_fargs: {
expect_stdout: "PASS" expect_stdout: "PASS"
node_version: ">=6" 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"
}

View File

@@ -3497,7 +3497,7 @@ issue_5314_2: {
A = this; A = this;
new function() { new function() {
[ { [ {
[console.log(this === A ? "FAIL" : "PASS")]: [].e, [console.log(this === A ? "FAIL" : "PASS")]: [][0],
} ] = [ 42 ]; } ] = [ 42 ];
}(); }();
} }

View File

@@ -648,7 +648,7 @@ drop_new_function: {
} }
expect: { expect: {
void ([ ... { void ([ ... {
[console.log("PASS")]: [].e, [console.log("PASS")]: [][0],
}] = []); }] = []);
} }
expect_stdout: "PASS" expect_stdout: "PASS"

View File

@@ -907,7 +907,7 @@ drop_body: {
})([ console.log("baz") ]); })([ console.log("baz") ]);
} }
expect: { expect: {
[ [ , [].e = console.log("foo") ] ] = [ [ console.log("baz") ] ]; [ [ , [][0] = console.log("foo") ] ] = [ [ console.log("baz") ] ];
} }
expect_stdout: [ expect_stdout: [
"baz", "baz",