aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2017-11-28 14:39:00 +0800
committerGitHub <noreply@github.com>2017-11-28 14:39:00 +0800
commit206a54a7461b76683d690fd7016943fcb461a4fa (patch)
treeed2f873b5e56fac4f37e631829239c9ca05f5bca
parent32def5ebf5c9157937dcf802ce71fb9d1d3bc189 (diff)
downloadtracifyjs-206a54a7461b76683d690fd7016943fcb461a4fa.tar.gz
tracifyjs-206a54a7461b76683d690fd7016943fcb461a4fa.zip
fix nested `hoist_props` substitution (#2523)
fixes #2519
-rw-r--r--lib/compress.js3
-rw-r--r--test/compress/hoist_props.js31
2 files changed, 33 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js
index f49f0b24..5b26de8b 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -2797,7 +2797,7 @@ merge(Compressor.prototype, {
if (!compressor.option("hoist_props") || compressor.has_directive("use asm")) return self;
var top_retain = self instanceof AST_Toplevel && compressor.top_retain || return_false;
var defs_by_id = Object.create(null);
- return self.transform(new TreeTransformer(function(node) {
+ return self.transform(new TreeTransformer(function(node, descend) {
if (node instanceof AST_VarDef) {
var sym = node.name, def, value;
if (sym.scope === self
@@ -2807,6 +2807,7 @@ merge(Compressor.prototype, {
&& !top_retain(def)
&& (value = sym.fixed_value()) === node.value
&& value instanceof AST_Object) {
+ descend(node, this);
var defs = new Dictionary();
var assignments = [];
value.properties.forEach(function(prop) {
diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js
index b2dd0270..a46033d5 100644
--- a/test/compress/hoist_props.js
+++ b/test/compress/hoist_props.js
@@ -633,3 +633,34 @@ issue_2508_5: {
}
expect_stdout: true
}
+
+issue_2519: {
+ options = {
+ collapse_vars: true,
+ evaluate: true,
+ hoist_props: true,
+ reduce_vars: true,
+ unused: true,
+ }
+ input: {
+ function testFunc() {
+ var dimensions = {
+ minX: 5,
+ maxX: 6,
+ };
+ var scale = 1;
+ var d = {
+ x: (dimensions.maxX + dimensions.minX) / 2,
+ };
+ return d.x * scale;
+ }
+ console.log(testFunc());
+ }
+ expect: {
+ function testFunc() {
+ return 1 * ((6 + 5) / 2);
+ }
+ console.log(testFunc());
+ }
+ expect_stdout: "5.5"
+}