}
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));
-program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js("mangle-props", true));
-program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js("beautify", true));
+program.option("-p, --parse <options>", "Specify parser options.", parse_js());
+program.option("-c, --compress [options]", "Enable compressor/specify compressor options.", parse_js());
+program.option("-m, --mangle [options]", "Mangle names/specify mangler options.", parse_js());
+program.option("--mangle-props [options]", "Mangle properties/specify mangler options.", parse_js());
+program.option("-b, --beautify [options]", "Beautify output/specify output options.", parse_js());
program.option("-o, --output <file>", "Output file (default STDOUT).");
program.option("--comments [filter]", "Preserve copyright comments in the output.");
program.option("--config-file <file>", "Read minify() options from JSON file.");
}
}
-function parse_js(flag, constants) {
+function parse_js(flag) {
return function(value, options) {
options = options || {};
try {
if (node instanceof UglifyJS.AST_Assign) {
var name = node.left.print_to_string();
var value = node.right;
- if (!constants) {
+ if (flag) {
options[name] = value;
} else if (value instanceof UglifyJS.AST_Array) {
options[name] = value.elements.map(to_string);
}
}));
} catch(ex) {
- options[value] = null;
+ if (flag) {
+ fatal("Error parsing arguments for '" + flag + "': " + value);
+ } else {
+ options[value] = null;
+ }
}
return options;
}
}
function parse_source_map() {
- var parse = parse_js("sourceMap", true);
+ var parse = parse_js();
return function(value, options) {
var hasContent = options && "content" in options;
var settings = parse(value, options);
done();
});
});
- it("Should work with --mangle reserved=[]", function (done) {
- var command = uglifyjscmd + ' test/input/issue-505/input.js -m reserved=[callback]';
+ it("Should work with --mangle reserved=[]", function(done) {
+ var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=[callback]";
exec(command, function (err, stdout) {
if (err) throw err;
done();
});
});
- it("Should work with --mangle reserved=false", function (done) {
- var command = uglifyjscmd + ' test/input/issue-505/input.js -m reserved=false';
+ it("Should work with --mangle reserved=false", function(done) {
+ var command = uglifyjscmd + " test/input/issue-505/input.js -m reserved=false";
exec(command, function (err, stdout) {
if (err) throw err;
done();
});
});
+ it("Should fail with --mangle-props reserved=[in]", function(done) {
+ var command = uglifyjscmd + " test/input/issue-505/input.js --mangle-props reserved=[in]";
+ exec(command, function (err, stdout, stderr) {
+ assert.ok(err);
+ assert.strictEqual(stdout, "");
+ assert.ok(/^Supported options:\n[\s\S]*?\nERROR: `reserved=\[in]` is not a supported option/.test(stderr), stderr);
+ done();
+ });
+ });
+ it("Should fail with --define a-b", function(done) {
+ var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b";
+ exec(command, function (err, stdout, stderr) {
+ assert.ok(err);
+ assert.strictEqual(stdout, "");
+ assert.strictEqual(stderr, "Error parsing arguments for 'define': a-b\n");
+ done();
+ });
+ });
});