Skip to content

Commit 940887f

Browse files
authored
fix corner case in evaluate (#5139)
fixes #5138
1 parent 0b2573c commit 940887f

2 files changed

Lines changed: 42 additions & 4 deletions

File tree

lib/compress.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,10 +4805,11 @@ merge(Compressor.prototype, {
48054805
if (!all(fn.argnames, function(sym, index) {
48064806
if (sym instanceof AST_DefaultValue) {
48074807
if (!args) return false;
4808-
if (args[index] !== undefined) return false;
4809-
var value = sym.value._eval(compressor, ignore_side_effects, cached, depth);
4810-
if (value === sym.value) return false;
4811-
args[index] = value;
4808+
if (args[index] === undefined) {
4809+
var value = sym.value._eval(compressor, ignore_side_effects, cached, depth);
4810+
if (value === sym.value) return false;
4811+
args[index] = value;
4812+
}
48124813
sym = sym.name;
48134814
}
48144815
return !(sym instanceof AST_Destructured);
@@ -4842,6 +4843,9 @@ merge(Compressor.prototype, {
48424843
if (!args || all(fn.argnames, function(sym, i) {
48434844
return assign(sym, args[i]);
48444845
}) && !(fn.rest && !assign(fn.rest, args.slice(fn.argnames.length))) || ignore_side_effects) {
4846+
if (ignore_side_effects) fn.argnames.forEach(function(sym) {
4847+
if (sym instanceof AST_DefaultValue) sym.value.walk(scan_modified);
4848+
});
48454849
fn.evaluating = true;
48464850
val = val._eval(compressor, ignore_side_effects, cached, depth);
48474851
delete fn.evaluating;

test/compress/default-values.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,3 +1904,37 @@ issue_5065: {
19041904
expect_stdout: "PASS"
19051905
node_version: ">=6"
19061906
}
1907+
1908+
issue_5138_1: {
1909+
options = {
1910+
evaluate: true,
1911+
}
1912+
input: {
1913+
console.log(function(a, b = a = "FAIL") {
1914+
return a;
1915+
}() && "PASS");
1916+
}
1917+
expect: {
1918+
console.log(function(a, b = a = "FAIL") {
1919+
return a;
1920+
}() && "PASS");
1921+
}
1922+
expect_stdout: "PASS"
1923+
node_version: ">=6"
1924+
}
1925+
1926+
issue_5138_2: {
1927+
options = {
1928+
evaluate: true,
1929+
}
1930+
input: {
1931+
console.log(function(a, b = a = "FAIL 1") {
1932+
return a;
1933+
}(null, "FAIL 2") || "PASS");
1934+
}
1935+
expect: {
1936+
console.log((null, "PASS"));
1937+
}
1938+
expect_stdout: "PASS"
1939+
node_version: ">=6"
1940+
}

0 commit comments

Comments
 (0)