[Pkg-javascript-commits] [uglifyjs] 391/491: preserve constant modification under strict mode (#2717)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:55 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit 7a6d452b548c8b7783b226f646e814d6cb0cf32b
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Thu Jan 4 15:53:53 2018 +0800

    preserve constant modification under strict mode (#2717)
---
 lib/compress.js               |  7 +++++-
 test/compress/pure_getters.js | 51 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index 85bb091..fe50416 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3279,7 +3279,12 @@ merge(Compressor.prototype, {
         });
         def(AST_Assign, function(compressor){
             var left = this.left;
-            if (left.has_side_effects(compressor)) return this;
+            if (left.has_side_effects(compressor)
+                || compressor.has_directive("use strict")
+                    && left instanceof AST_PropAccess
+                    && left.expression.is_constant()) {
+                return this;
+            }
             this.write_only = true;
             while (left instanceof AST_PropAccess) {
                 left = left.expression;
diff --git a/test/compress/pure_getters.js b/test/compress/pure_getters.js
index 7185e0c..80b0e8e 100644
--- a/test/compress/pure_getters.js
+++ b/test/compress/pure_getters.js
@@ -348,6 +348,57 @@ set_immutable_4: {
     expect_stdout: true
 }
 
+set_immutable_5: {
+    options = {
+        collapse_vars: true,
+        conditionals: true,
+        evaluate: true,
+        pure_getters: "strict",
+        reduce_funcs: true,
+        reduce_vars: true,
+        side_effects: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        "use strict";
+        var a = 1;
+        a.foo += "";
+        if (a.foo) console.log("FAIL");
+        else console.log("PASS");
+    }
+    expect: {
+        "use strict";
+        1..foo += "";
+        1..foo ? console.log("FAIL") : console.log("PASS");
+    }
+    expect_stdout: true
+}
+
+set_immutable_6: {
+    options = {
+        collapse_vars: true,
+        conditionals: true,
+        evaluate: true,
+        pure_getters: "strict",
+        reduce_funcs: true,
+        reduce_vars: true,
+        side_effects: true,
+        toplevel: true,
+        unused: true,
+    }
+    input: {
+        var a = 1;
+        a.foo += "";
+        if (a.foo) console.log("FAIL");
+        else console.log("PASS");
+    }
+    expect: {
+        1..foo ? console.log("FAIL") : console.log("PASS");
+    }
+    expect_stdout: true
+}
+
 set_mutable_1: {
     options = {
         collapse_vars: true,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list