添加-e
This commit is contained in:
parent
caf96acb08
commit
a6c6c1458b
9
bin/uglifyjs
Executable file → Normal file
9
bin/uglifyjs
Executable file → Normal file
|
|
@ -47,12 +47,14 @@ program.option("--rename", "Force symbol expansion.");
|
||||||
program.option("--no-rename", "Disable symbol expansion.");
|
program.option("--no-rename", "Disable symbol expansion.");
|
||||||
program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
|
program.option("--self", "Build UglifyJS as a library (implies --wrap UglifyJS)");
|
||||||
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_js());
|
program.option("--source-map [options]", "Enable source map/specify source map options.", parse_js());
|
||||||
program.option("--timings", "Display operations run time on STDERR.")
|
program.option("--timings", "Display operations run time on STDERR.");
|
||||||
program.option("--toplevel", "Compress and/or mangle variables in toplevel scope.");
|
program.option("--toplevel", "Compress and/or mangle variables in toplevel scope.");
|
||||||
program.option("--verbose", "Print diagnostic messages.");
|
program.option("--verbose", "Print diagnostic messages.");
|
||||||
program.option("--warn", "Print warning messages.");
|
program.option("--warn", "Print warning messages.");
|
||||||
program.option("--wrap <name>", "Embed everything as a function with “exports” corresponding to “name” globally.");
|
program.option("--wrap <name>", "Embed everything as a function with “exports” corresponding to “name” globally.");
|
||||||
|
program.option("-e, --enclose [options]","Embed everything in a big function, with a configurable parameter/argument list.")
|
||||||
program.arguments("[files...]").parseArgv(process.argv);
|
program.arguments("[files...]").parseArgv(process.argv);
|
||||||
|
|
||||||
if (program.configFile) {
|
if (program.configFile) {
|
||||||
options = JSON.parse(read_file(program.configFile));
|
options = JSON.parse(read_file(program.configFile));
|
||||||
}
|
}
|
||||||
|
|
@ -142,6 +144,11 @@ if (program.verbose) {
|
||||||
} else if (program.warn) {
|
} else if (program.warn) {
|
||||||
options.warnings = true;
|
options.warnings = true;
|
||||||
}
|
}
|
||||||
|
if (program.enclose) {
|
||||||
|
// 等待完成
|
||||||
|
console.log('enclose', program.enclose);
|
||||||
|
options.enclose = program.enclose;
|
||||||
|
}
|
||||||
if (program.self) {
|
if (program.self) {
|
||||||
if (program.args.length) {
|
if (program.args.length) {
|
||||||
print_error("WARN: Ignoring input files since --self was passed");
|
print_error("WARN: Ignoring input files since --self was passed");
|
||||||
|
|
|
||||||
21
lib/ast.js
21
lib/ast.js
|
|
@ -325,6 +325,27 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", {
|
||||||
$propdoc: {
|
$propdoc: {
|
||||||
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
|
globals: "[Object/S] a map of name -> SymbolDef for all undeclared names",
|
||||||
},
|
},
|
||||||
|
wrap_enclose: function(arg_parameter_pairs) {
|
||||||
|
var self = this;
|
||||||
|
var args = [];
|
||||||
|
var parameters = [];
|
||||||
|
console.log("wrap_enclose")
|
||||||
|
arg_parameter_pairs.forEach(function(pair) {
|
||||||
|
var splitAt = pair.lastIndexOf(":");
|
||||||
|
|
||||||
|
args.push(pair.substr(0, splitAt));
|
||||||
|
parameters.push(pair.substr(splitAt + 1));
|
||||||
|
});
|
||||||
|
|
||||||
|
var wrapped_tl = "(function(" + parameters.join(",") + "){ '$ORIG'; })(" + args.join(",") + ")";
|
||||||
|
wrapped_tl = parse(wrapped_tl);
|
||||||
|
wrapped_tl = wrapped_tl.transform(new TreeTransformer(function before(node){
|
||||||
|
if (node instanceof AST_Directive && node.value == "$ORIG") {
|
||||||
|
return MAP.splice(self.body);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
return wrapped_tl;
|
||||||
|
},
|
||||||
wrap_commonjs: function(name) {
|
wrap_commonjs: function(name) {
|
||||||
var body = this.body;
|
var body = this.body;
|
||||||
var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
|
var wrapped_tl = "(function(exports){'$ORIG';})(typeof " + name + "=='undefined'?(" + name + "={}):" + name + ");";
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,7 @@ function minify(files, options) {
|
||||||
toplevel: false,
|
toplevel: false,
|
||||||
warnings: false,
|
warnings: false,
|
||||||
wrap: false,
|
wrap: false,
|
||||||
|
enclose: [],
|
||||||
}, true);
|
}, true);
|
||||||
var timings = options.timings && {
|
var timings = options.timings && {
|
||||||
start: Date.now()
|
start: Date.now()
|
||||||
|
|
@ -157,6 +158,19 @@ function minify(files, options) {
|
||||||
if (options.wrap) {
|
if (options.wrap) {
|
||||||
toplevel = toplevel.wrap_commonjs(options.wrap);
|
toplevel = toplevel.wrap_commonjs(options.wrap);
|
||||||
}
|
}
|
||||||
|
console.log("minify")
|
||||||
|
console.log(options.enclose)
|
||||||
|
if (options.enclose != null) {
|
||||||
|
var arg_parameter_list = options.enclose;
|
||||||
|
if (arg_parameter_list === true) {
|
||||||
|
arg_parameter_list = [];
|
||||||
|
}
|
||||||
|
else if (!(arg_parameter_list instanceof Array)) {
|
||||||
|
arg_parameter_list = [arg_parameter_list];
|
||||||
|
}
|
||||||
|
console.log("minify", arg_parameter_list);
|
||||||
|
toplevel = toplevel.wrap_enclose(arg_parameter_list);
|
||||||
|
}
|
||||||
if (timings) timings.rename = Date.now();
|
if (timings) timings.rename = Date.now();
|
||||||
if (options.rename) {
|
if (options.rename) {
|
||||||
toplevel.figure_out_scope(options.mangle);
|
toplevel.figure_out_scope(options.mangle);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user