[Pkg-javascript-commits] [uglifyjs] 108/491: implement `--help options` (#2017)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:26 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 c6c9f4f5a837bea16609b1d430e6c20687f3742b
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun May 28 18:21:44 2017 +0800

    implement `--help options` (#2017)
---
 bin/uglifyjs  | 12 ++++++++++++
 lib/parse.js  |  2 +-
 test/ufuzz.js | 29 ++++++-----------------------
 tools/node.js | 17 +++++++++++++++++
 4 files changed, 36 insertions(+), 24 deletions(-)

diff --git a/bin/uglifyjs b/bin/uglifyjs
index 158dc57..b9406e1 100755
--- a/bin/uglifyjs
+++ b/bin/uglifyjs
@@ -25,6 +25,18 @@ program.version(info.name + ' ' + info.version);
 program.parseArgv = program.parse;
 program.parse = undefined;
 if (process.argv.indexOf("ast") >= 0) program.helpInformation = UglifyJS.describe_ast;
+else if (process.argv.indexOf("options") >= 0) program.helpInformation = function() {
+    var text = [];
+    var options = UglifyJS.default_options();
+    for (var option in options) {
+        text.push("--" + (option == "output" ? "beautify" : option == "sourceMap" ? "source-map" : option) + " options:");
+        Object.keys(options[option]).forEach(function(name) {
+            text.push("  " + name);
+        });
+        text.push("");
+    }
+    return text.join("\n");
+};
 program.option("-p, --parse <options>", "Specify parser options.", parse_js("parse", true));
 program.option("-c, --compress [options]", "Enable compressor/specify compressor options.", parse_js("compress", true));
 program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js("mangle", true));
diff --git a/lib/parse.js b/lib/parse.js
index c960b49..a02fce8 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -700,7 +700,7 @@ function parse($TEXT, options) {
         shebang        : true,
         strict         : false,
         toplevel       : null,
-    });
+    }, true);
 
     var S = {
         input         : (typeof $TEXT == "string"
diff --git a/test/ufuzz.js b/test/ufuzz.js
index ff403c6..e3361e3 100644
--- a/test/ufuzz.js
+++ b/test/ufuzz.js
@@ -12,7 +12,7 @@
         stream._handle.setBlocking(true);
 });
 
-var UglifyJS = require("./node");
+var UglifyJS = require("..");
 var randomBytes = require("crypto").randomBytes;
 var sandbox = require("./sandbox");
 
@@ -962,32 +962,15 @@ function try_beautify(code, result) {
     console.log(code);
 }
 
-function infer_options(ctor) {
-    try {
-        ctor({ 0: 0 });
-    } catch (e) {
-        return e.defs;
-    }
-}
-
-var default_options = {
-    compress: infer_options(UglifyJS.Compressor),
-    mangle: {
-        "cache": null,
-        "eval": false,
-        "ie8": false,
-        "keep_fnames": false,
-        "toplevel": false,
-    },
-    output: infer_options(UglifyJS.OutputStream),
-};
+var default_options = UglifyJS.default_options();
 
 function log_suspects(minify_options, component) {
     var options = component in minify_options ? minify_options[component] : true;
     if (!options) return;
-    options = UglifyJS.defaults(options, default_options[component]);
-    var suspects = Object.keys(default_options[component]).filter(function(name) {
-        if (options[name]) {
+    if (typeof options != "object") options = {};
+    var defs = default_options[component];
+    var suspects = Object.keys(defs).filter(function(name) {
+        if ((name in options ? options : defs)[name]) {
             var m = JSON.parse(JSON.stringify(minify_options));
             var o = JSON.parse(JSON.stringify(options));
             o[name] = false;
diff --git a/tools/node.js b/tools/node.js
index 07c62d1..dc27010 100644
--- a/tools/node.js
+++ b/tools/node.js
@@ -63,3 +63,20 @@ function describe_ast() {
     doitem(AST_Node);
     return out + "\n";
 }
+
+function infer_options(options) {
+    var result = UglifyJS.minify("", options);
+    return result.error && result.error.defs;
+}
+
+UglifyJS.default_options = function() {
+    var defs = {};
+    Object.keys(infer_options({ 0: 0 })).forEach(function(component) {
+        var options = {};
+        options[component] = { 0: 0 };
+        if (options = infer_options(options)) {
+            defs[component] = options;
+        }
+    });
+    return defs;
+};

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