Fix faulty compression
authorMihai Bazon <mihai@bazon.net>
Wed, 20 Nov 2013 19:13:16 +0000 (21:13 +0200)
committerMihai Bazon <mihai@bazon.net>
Wed, 20 Nov 2013 19:13:16 +0000 (21:13 +0200)
`String(x + 5)` is not always the same as `x + "5"`.  Overlooked that. :-(

Close #350

lib/compress.js
test/compress/issue-269.js

index c60ee19..3cc59e2 100644 (file)
@@ -2031,16 +2031,6 @@ merge(Compressor.prototype, {
             && self.right.getValue() === "" && self.left instanceof AST_Binary
             && self.left.operator == "+" && self.left.is_string(compressor)) {
             return self.left;
-        } else if (self.operator == "+" && self.right instanceof AST_String
-                   && self.right.getValue() === "" && self.left instanceof AST_Binary
-                   && self.left.operator == "+" && self.left.right instanceof AST_Number) {
-            return make_node(AST_Binary, self, {
-                left: self.left.left,
-                operator: "+",
-                right: make_node(AST_String, self.right, {
-                    value: String(self.left.right.value)
-                })
-            });
         }
         if (compressor.option("evaluate")) {
             if (self.operator == "+") {
index 70e82d0..1d41dea 100644 (file)
@@ -54,15 +54,13 @@ strings_concat: {
        input: {
                f(
                        String(x + 'str'),
-                       String('str' + x),
-                       String(x + 5)
+                       String('str' + x)
                );
        }
        expect: {
                f(
                        x + 'str',
-                       'str' + x,
-                       x + '5'
+                       'str' + x
                );
        }
-}
\ No newline at end of file
+}