aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-01-29 17:41:15 +0800
committerGitHub <noreply@github.com>2018-01-29 17:41:15 +0800
commit541e6011af7647074a41c5a82a0a16a3d32bb8c6 (patch)
tree7cb1e3ccaec87acd38b32c8ae25084fa780b311c
parent6fa3fbeae84200c90ff47dde03545742a861be17 (diff)
downloadtracifyjs-541e6011af7647074a41c5a82a0a16a3d32bb8c6.tar.gz
tracifyjs-541e6011af7647074a41c5a82a0a16a3d32bb8c6.zip
improve symbol replacement heuristic (#2851)
-rw-r--r--lib/compress.js2
-rw-r--r--test/compress/reduce_vars.js32
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index 81af151b..d0ef5f5d 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -5237,7 +5237,7 @@ merge(Compressor.prototype, {
var name_length = d.name.length;
var overhead = 0;
if (compressor.option("unused") && !compressor.exposed(d)) {
- overhead = (name_length + 2 + value_length) / d.references.length;
+ overhead = (name_length + 2 + value_length) / (d.references.length - d.assignments);
}
d.should_replace = value_length <= name_length + overhead ? fn : false;
} else {
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 2231587d..2e562f94 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -5435,3 +5435,35 @@ lvalues_def_2: {
}
expect_stdout: "2 NaN"
}
+
+chained_assignments: {
+ options = {
+ evaluate: true,
+ inline: true,
+ reduce_vars: true,
+ sequences: true,
+ side_effects: true,
+ toplevel: true,
+ unsafe: true,
+ unused: true,
+ }
+ input: {
+ function f() {
+ var a = [0x5e, 0xad, 0xbe, 0xef];
+ var b = 0;
+ b |= a[0];
+ b <<= 8;
+ b |= a[1];
+ b <<= 8;
+ b |= a[2];
+ b <<= 8;
+ b |= a[3];
+ return b;
+ }
+ console.log(f().toString(16));
+ }
+ expect: {
+ console.log("5eadbeef");
+ }
+ expect_stdout: "5eadbeef"
+}