fix `unsafe` evaluation of `AST_Sub` (#2389)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 22 Oct 2017 05:14:15 +0000 (13:14 +0800)
committerGitHub <noreply@github.com>
Sun, 22 Oct 2017 05:14:15 +0000 (13:14 +0800)
lib/compress.js
test/compress/properties.js

index cef5d75..6a40ef2 100644 (file)
@@ -4468,6 +4468,7 @@ merge(Compressor.prototype, {
                 });
             }
         }
+        if (is_lhs(self, compressor.parent())) return self;
         var ev = self.evaluate(compressor);
         if (ev !== self) {
             ev = make_node_from_constant(ev, self).optimize(compressor);
index c8a8569..45f870d 100644 (file)
@@ -805,7 +805,7 @@ issue_2256: {
     }
 }
 
-lhs_prop: {
+lhs_prop_1: {
     options = {
         evaluate: true,
         unsafe: true,
@@ -822,3 +822,22 @@ lhs_prop: {
     }
     expect_stdout: "2"
 }
+
+lhs_prop_2: {
+    options = {
+        evaluate: true,
+        inline: true,
+        reduce_vars: true,
+        side_effects: true,
+        unsafe: true,
+        unused: true,
+    }
+    input: {
+        (function(a) {
+            a[2] = "g";
+        })("abc");
+    }
+    expect: {
+        "abc"[2] = "g";
+    }
+}