From 6ffbecb72b515d6e9e6dee1f76d8f27e4b014854 Mon Sep 17 00:00:00 2001 From: kzc Date: Sat, 18 Feb 2017 19:12:57 +0800 Subject: smarter const replacement taking name length into account closes #1459 --- lib/compress.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/compress.js') diff --git a/lib/compress.js b/lib/compress.js index b66c5582..1f710f10 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -2784,6 +2784,18 @@ merge(Compressor.prototype, { } } } + if (compressor.option("evaluate") && !isLHS(self, compressor.parent())) { + var d = self.definition(); + if (d && d.constant && d.init && d.init.is_constant(compressor)) { + var original_as_string = self.print_to_string(); + var const_node = make_node_from_constant(compressor, d.init.constant_value(compressor), self); + var const_node_as_string = const_node.print_to_string(); + var per_const_overhead = d.global || !d.references.length ? 0 + : (d.name.length + 2 + const_node_as_string.length) / d.references.length; + if (const_node_as_string.length <= original_as_string.length + per_const_overhead) + return const_node; + } + } return self; }); -- cgit v1.2.3