improve `rename` reproducibility (#2754)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 9 Jan 2018 05:53:05 +0000 (13:53 +0800)
committerGitHub <noreply@github.com>
Tue, 9 Jan 2018 05:53:05 +0000 (13:53 +0800)
fixes #2752

lib/minify.js
test/mocha/minify.js

index a68cbf3..aad7d22 100644 (file)
@@ -141,6 +141,7 @@ function minify(files, options) {
         }
         if (timings) timings.rename = Date.now();
         if (options.rename) {
+            SymbolDef.next_id = 1;
             toplevel.figure_out_scope(options.mangle);
             toplevel.expand_names(options.mangle);
         }
index a304c5b..d696a25 100644 (file)
@@ -373,4 +373,18 @@ describe("minify", function() {
             assert.strictEqual(stat.print_to_string(), "a=x()");
         });
     });
+
+    describe("rename", function() {
+        it("Should be repeatable", function() {
+            var code = "!function(x){return x(x)}(y);";
+            for (var i = 0; i < 2; i++) {
+                assert.strictEqual(Uglify.minify(code, {
+                    compress: {
+                        toplevel: true,
+                    },
+                    rename: true,
+                }).code, "var a2;(a2=y)(a2);");
+            }
+        });
+    });
 });