report top-level default options (#3797)
This commit is contained in:
23
bin/uglifyjs
23
bin/uglifyjs
@@ -23,12 +23,29 @@ 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 toplevels = [];
|
||||
var padding = "";
|
||||
var options = UglifyJS.default_options();
|
||||
for (var option in options) {
|
||||
text.push("--" + (option == "output" ? "beautify" : option == "sourceMap" ? "source-map" : option) + " options:");
|
||||
text.push(format_object(options[option]));
|
||||
for (var name in options) {
|
||||
var option = options[name];
|
||||
if (option && typeof option == "object") {
|
||||
text.push("--" + ({
|
||||
output: "beautify",
|
||||
sourceMap: "source-map",
|
||||
}[name] || name) + " options:");
|
||||
text.push(format_object(option));
|
||||
text.push("");
|
||||
} else {
|
||||
if (padding.length < name.length) padding = Array(name.length + 1).join(" ");
|
||||
toplevels.push([ {
|
||||
keep_fnames: "keep-fnames",
|
||||
nameCache: "name-cache",
|
||||
}[name] || name, option ]);
|
||||
}
|
||||
}
|
||||
toplevels.forEach(function(tokens) {
|
||||
text.push("--" + tokens[0] + padding.slice(tokens[0].length - 2) + tokens[1]);
|
||||
});
|
||||
return text.join("\n");
|
||||
};
|
||||
program.option("-p, --parse <options>", "Specify parser options.", parse_js());
|
||||
|
||||
@@ -87,9 +87,11 @@ DefaultsError.prototype.name = "DefaultsError";
|
||||
configure_error_stack(DefaultsError);
|
||||
|
||||
function defaults(args, defs, croak) {
|
||||
for (var i in args) if (HOP(args, i)) {
|
||||
if (croak && !HOP(defs, i)) throw new DefaultsError("`" + i + "` is not a supported option", defs);
|
||||
defs[i] = args[i];
|
||||
if (croak) for (var i in args) {
|
||||
if (HOP(args, i) && !HOP(defs, i)) throw new DefaultsError("`" + i + "` is not a supported option", defs);
|
||||
}
|
||||
for (var i in args) {
|
||||
if (HOP(args, i)) defs[i] = args[i];
|
||||
}
|
||||
return defs;
|
||||
}
|
||||
|
||||
@@ -1045,10 +1045,8 @@ function log_suspects(minify_options, component) {
|
||||
}
|
||||
|
||||
function log_suspects_global(options) {
|
||||
var o = {};
|
||||
UglifyJS.minify("", o);
|
||||
var suspects = Object.keys(o).filter(function(component) {
|
||||
return typeof o[component] != "object";
|
||||
var suspects = Object.keys(default_options).filter(function(component) {
|
||||
return typeof default_options[component] != "object";
|
||||
}).filter(function(component) {
|
||||
var m = JSON.parse(options);
|
||||
m[component] = false;
|
||||
@@ -1115,7 +1113,10 @@ function log(options) {
|
||||
errorln(JSON.stringify(JSON.parse(options), null, 2));
|
||||
errorln();
|
||||
if (!ok && typeof uglify_code == "string") {
|
||||
Object.keys(default_options).forEach(log_suspects.bind(null, JSON.parse(options)));
|
||||
Object.keys(default_options).filter(function(component) {
|
||||
var defs = default_options[component];
|
||||
return defs && typeof defs == "object";
|
||||
}).forEach(log_suspects.bind(null, JSON.parse(options)));
|
||||
log_suspects_global(options);
|
||||
errorln("!!!!!! Failed... round " + round);
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ function infer_options(options) {
|
||||
}
|
||||
|
||||
exports.default_options = function() {
|
||||
var defs = {};
|
||||
Object.keys(infer_options({ 0: 0 })).forEach(function(component) {
|
||||
var defs = infer_options({ 0: 0 });
|
||||
Object.keys(defs).forEach(function(component) {
|
||||
var options = {};
|
||||
options[component] = { 0: 0 };
|
||||
if (options = infer_options(options)) {
|
||||
|
||||
Reference in New Issue
Block a user