diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2018-04-11 05:19:16 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-11 05:19:16 +0800 |
commit | ba7069d52b8e3eb6eca0fd5b88a20361868bb42c (patch) | |
tree | 2e732d148c6362c32a1b60da93a7ee3270047176 | |
parent | 4dd7d0e39baacdd3bf7dc87fc547df66e327f206 (diff) | |
download | tracifyjs-ba7069d52b8e3eb6eca0fd5b88a20361868bb42c.tar.gz tracifyjs-ba7069d52b8e3eb6eca0fd5b88a20361868bb42c.zip |
suppress `hoist_props` for embedded assignments (#3074)
-rw-r--r-- | lib/compress.js | 5 | ||||
-rw-r--r-- | test/compress/hoist_props.js | 32 |
2 files changed, 36 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index 66dc10cf..454ce945 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3639,7 +3639,10 @@ merge(Compressor.prototype, { 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, descend) { - if (node instanceof AST_Assign && node.operator == "=" && can_hoist(node.left, node.right, 1)) { + if (node instanceof AST_Assign + && node.operator == "=" + && node.write_only + && can_hoist(node.left, node.right, 1)) { descend(node, this); var defs = new Dictionary(); var assignments = []; diff --git a/test/compress/hoist_props.js b/test/compress/hoist_props.js index 0e399167..46af9d72 100644 --- a/test/compress/hoist_props.js +++ b/test/compress/hoist_props.js @@ -824,3 +824,35 @@ issue_3071_2_toplevel: { } expect_stdout: "1" } + +issue_3071_3: { + options = { + hoist_props: true, + reduce_vars: true, + } + input: { + var c = 0; + (function(a, b) { + (function f(o) { + var n = 2; + while (--b + (o = { + p: c++, + }) && --n > 0); + })(); + })(); + console.log(c); + } + expect: { + var c = 0; + (function(a, b) { + (function f(o) { + var n = 2; + while (--b + (o = { + p: c++, + }) && --n > 0); + })(); + })(); + console.log(c); + } + expect_stdout: "2" +} |