consistently reduce const safe literals

fixes #2406
This commit is contained in:
alexlamsl 2017-10-28 10:55:33 +08:00
parent 2848596280
commit 32c1258d28
2 changed files with 86 additions and 1 deletions

View File

@ -320,7 +320,7 @@ merge(Compressor.prototype, {
d.fixed = false;
} else {
var value = node.fixed_value();
if (unused) {
if (unused && !compressor.exposed(d)) {
d.single_use = value
&& d.references.length == 1
&& loop_ids[d.id] === in_loop

View File

@ -3111,3 +3111,88 @@ const_expr_2: {
}
expect_stdout: "2 2"
}
issue_2406_1: {
options = {
reduce_vars: true,
toplevel: false,
unused: true,
}
input: {
const c = {
fn: function() {
return this;
}
};
let l = {
fn: function() {
return this;
}
};
var v = {
fn: function() {
return this;
}
};
console.log(c.fn(), l.fn(), v.fn());
}
expect: {
const c = {
fn: function() {
return this;
}
};
let l = {
fn: function() {
return this;
}
};
var v = {
fn: function() {
return this;
}
};
console.log(c.fn(), l.fn(), v.fn());
}
}
issue_2406_2: {
options = {
reduce_vars: true,
toplevel: true,
unused: true,
}
input: {
const c = {
fn: function() {
return this;
}
};
let l = {
fn: function() {
return this;
}
};
var v = {
fn: function() {
return this;
}
};
console.log(c.fn(), l.fn(), v.fn());
}
expect: {
console.log({
fn: function() {
return this;
}
}.fn(), {
fn: function() {
return this;
}
}.fn(), {
fn: function() {
return this;
}
}.fn());
}
}