Skip to content

Commit 37d3e4f

Browse files
authored
fix corner case in if_return (#5675)
1 parent 43ec350 commit 37d3e4f

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

Diff for: lib/compress.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1828,12 +1828,11 @@ Compressor.prototype.compress = function(node) {
18281828
return wrap ? make_sequence(orig, [ make_node(AST_Number, orig, { value: 0 }), val ]) : val;
18291829
}
18301830

1831-
function merge_expression(base, target, scope) {
1831+
function merge_expression(base, target) {
18321832
var fixed_by_id = new Dictionary();
18331833
base.walk(new TreeWalker(function(node) {
18341834
if (!(node instanceof AST_SymbolRef)) return;
18351835
var def = node.definition();
1836-
if (scope && def.scope.resolve() !== scope) return;
18371836
var fixed = node.fixed;
18381837
if (!fixed || !fixed_by_id.has(def.id)) {
18391838
fixed_by_id.set(def.id, fixed);
@@ -3836,7 +3835,7 @@ Compressor.prototype.compress = function(node) {
38363835
case 2:
38373836
value = value.tail_node();
38383837
}
3839-
merge_expression(value, jump.value, scope);
3838+
merge_expression(value, jump.value);
38403839
}
38413840

38423841
function next_index(i) {

Diff for: test/compress/if_return.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ switch_return_5: {
18341834
]
18351835
}
18361836

1837-
merged_references: {
1837+
merged_references_1: {
18381838
options = {
18391839
if_return: true,
18401840
reduce_vars: true,
@@ -1861,6 +1861,36 @@ merged_references: {
18611861
expect_stdout: "PASS"
18621862
}
18631863

1864+
merged_references_2: {
1865+
options = {
1866+
if_return: true,
1867+
reduce_vars: true,
1868+
toplevel: true,
1869+
unused: true,
1870+
}
1871+
input: {
1872+
A = "PASS";
1873+
var a;
1874+
console.log(function(b) {
1875+
if (a = b)
1876+
return console && a;
1877+
a = FAIL;
1878+
return console && a;
1879+
}(A));
1880+
}
1881+
expect: {
1882+
A = "PASS";
1883+
var a;
1884+
console.log(function(b) {
1885+
if (a = b);
1886+
else
1887+
a = FAIL;
1888+
return console && a;
1889+
}(A));
1890+
}
1891+
expect_stdout: "PASS"
1892+
}
1893+
18641894
issue_5583: {
18651895
options = {
18661896
conditionals: true,

0 commit comments

Comments
 (0)