[Pkg-javascript-commits] [uglifyjs] 436/491: configure `rename` with CLI (#2802)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:52:01 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 cff3bf49142e5d99ad07e182169a73f985b7b652
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Jan 17 15:12:22 2018 +0800

    configure `rename` with CLI (#2802)
---
 bin/uglifyjs               |  8 ++++++--
 test/input/rename/input.js |  6 ++++++
 test/mocha/cli.js          | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/bin/uglifyjs b/bin/uglifyjs
index 9a3257e..2ff1feb 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -43,6 +43,7 @@ program.option("-d, --define <expr>[=value]", "Global definitions.", parse_js("d
 program.option("--ie8", "Support non-standard Internet Explorer 8.");
 program.option("--keep-fnames", "Do not mangle/drop function names. Useful for code relying on Function.prototype.name.");
 program.option("--name-cache <file>", "File to hold mangled name mappings.");
+program.option("--rename", "Force symbol expansion.");
 program.option("--no-rename", "Disable symbol expansion.");
 program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
 program.option("--source-map [options]", "Enable source map/specify source map options.", parse_source_map());
@@ -62,13 +63,11 @@ if (!program.output && program.sourceMap && program.sourceMap.url != "inline") {
     "compress",
     "ie8",
     "mangle",
-    "rename",
     "sourceMap",
     "toplevel",
     "wrap"
 ].forEach(function(name) {
     if (name in program) {
-        if (name == "rename" && program[name]) return;
         options[name] = program[name];
     }
 });
@@ -121,6 +120,11 @@ if (program.parse) {
         fatal("ERROR: inline source map only works with built-in parser");
     }
 }
+if (~program.rawArgs.indexOf("--rename")) {
+    options.rename = true;
+} else if (!program.rename) {
+    options.rename = false;
+}
 var convert_path = function(name) {
     return name;
 };
diff --git a/test/input/rename/input.js b/test/input/rename/input.js
new file mode 100644
index 0000000..ef6daed
--- /dev/null
+++ b/test/input/rename/input.js
@@ -0,0 +1,6 @@
+function f(x) {
+    return g(x);
+    function g(x) {
+        return x;
+    }
+}
diff --git a/test/mocha/cli.js b/test/mocha/cli.js
index 85b2e8c..671d700 100644
--- a/test/mocha/cli.js
+++ b/test/mocha/cli.js
@@ -650,4 +650,36 @@ describe("bin/uglifyjs", function () {
             done();
         });
     });
+    it("Should work with explicit --rename", function(done) {
+        var command = uglifyjscmd + " test/input/rename/input.js --rename";
+        exec(command, function(err, stdout, stderr) {
+            if (err) throw err;
+            assert.strictEqual(stdout, "function f(a){return b(a);function b(c){return c}}\n");
+            done();
+        });
+    });
+    it("Should work with explicit --no-rename", function(done) {
+        var command = uglifyjscmd + " test/input/rename/input.js -mc --no-rename";
+        exec(command, function(err, stdout, stderr) {
+            if (err) throw err;
+            assert.strictEqual(stdout, "function f(n){return function(n){return n}(n)}\n");
+            done();
+        });
+    });
+    it("Should work with implicit --rename", function(done) {
+        var command = uglifyjscmd + " test/input/rename/input.js -mc";
+        exec(command, function(err, stdout, stderr) {
+            if (err) throw err;
+            assert.strictEqual(stdout, "function f(n){return n}\n");
+            done();
+        });
+    });
+    it("Should work with implicit --no-rename", function(done) {
+        var command = uglifyjscmd + " test/input/rename/input.js -c";
+        exec(command, function(err, stdout, stderr) {
+            if (err) throw err;
+            assert.strictEqual(stdout, "function f(x){return function(x){return x}(x)}\n");
+            done();
+        });
+    });
 });

-- 
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