[Pkg-javascript-commits] [uglifyjs] 16/49: Add input file glob support to minify()

Jonas Smedegaard dr at jones.dk
Fri Dec 9 11:43:25 UTC 2016


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

js pushed a commit to branch master
in repository uglifyjs.

commit dcdcfe4d39e8769e8d7504f167610883e250d266
Author: kzc <zaxxon2011 at gmail.com>
Date:   Fri Jul 29 21:27:30 2016 -0400

    Add input file glob support to minify()
---
 test/input/issue-1242/bar.es5 |  4 ++++
 test/input/issue-1242/baz.es5 |  4 ++++
 test/input/issue-1242/foo.es5 |  5 +++++
 test/input/issue-1242/qux.js  |  4 ++++
 test/mocha/glob.js            | 28 ++++++++++++++++++++++++++++
 tools/node.js                 |  1 +
 6 files changed, 46 insertions(+)

diff --git a/test/input/issue-1242/bar.es5 b/test/input/issue-1242/bar.es5
new file mode 100644
index 0000000..6e308a3
--- /dev/null
+++ b/test/input/issue-1242/bar.es5
@@ -0,0 +1,4 @@
+function bar(x) {
+    var triple = x * (2 + 1);
+    return triple;
+}
diff --git a/test/input/issue-1242/baz.es5 b/test/input/issue-1242/baz.es5
new file mode 100644
index 0000000..83c98ef
--- /dev/null
+++ b/test/input/issue-1242/baz.es5
@@ -0,0 +1,4 @@
+function baz(x) {
+    var half = x / 2;
+    return half;
+}
diff --git a/test/input/issue-1242/foo.es5 b/test/input/issue-1242/foo.es5
new file mode 100644
index 0000000..4b43907
--- /dev/null
+++ b/test/input/issue-1242/foo.es5
@@ -0,0 +1,5 @@
+var print = console.log.bind(console);
+function foo(x) {
+    var twice = x * 2;
+    print('Foo:', twice);
+}
diff --git a/test/input/issue-1242/qux.js b/test/input/issue-1242/qux.js
new file mode 100644
index 0000000..94171f3
--- /dev/null
+++ b/test/input/issue-1242/qux.js
@@ -0,0 +1,4 @@
+var a = bar(1+2);
+var b = baz(3+9);
+print('q' + 'u' + 'x', a, b);
+foo(5+6);
diff --git a/test/mocha/glob.js b/test/mocha/glob.js
new file mode 100644
index 0000000..c2fc946
--- /dev/null
+++ b/test/mocha/glob.js
@@ -0,0 +1,28 @@
+var Uglify = require('../../');
+var assert = require("assert");
+
+describe("minify() with input file globs", function() {
+    it("minify() with one input file glob string.", function() {
+        var result = Uglify.minify("test/input/issue-1242/foo.*", {
+            compress: { collapse_vars: true }
+        });
+        assert.strictEqual(result.code, 'function foo(o){print("Foo:",2*o)}var print=console.log.bind(console);');
+    });
+    it("minify() with an array of one input file glob.", function() {
+        var result = Uglify.minify([
+            "test/input/issue-1242/b*.es5",
+        ], {
+            compress: { collapse_vars: true }
+        });
+        assert.strictEqual(result.code, 'function bar(n){return 3*n}function baz(n){return n/2}');
+    });
+    it("minify() with an array of multiple input file globs.", function() {
+        var result = Uglify.minify([
+            "test/input/issue-1242/???.es5",
+            "test/input/issue-1242/*.js",
+        ], {
+            compress: { collapse_vars: true }
+        });
+        assert.strictEqual(result.code, 'function bar(n){return 3*n}function baz(n){return n/2}function foo(n){print("Foo:",2*n)}var print=console.log.bind(console);print("qux",bar(3),baz(12)),foo(11);');
+    });
+});
diff --git a/tools/node.js b/tools/node.js
index 5a14375..6712ccf 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -73,6 +73,7 @@ exports.minify = function(files, options) {
                 bare_returns: options.parse ? options.parse.bare_returns : undefined
             });
         }
+        if (!options.fromString) files = UglifyJS.simple_glob(files);
         [].concat(files).forEach(function (files, i) {
             if (typeof files === 'string') {
                 addFile(files, options.fromString ? i : files);

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