suggestions from @kzc
This commit is contained in:
parent
924f7bc3a9
commit
6dacae769d
|
|
@ -131,6 +131,10 @@ function Compressor(options, false_by_default) {
|
||||||
return top_retain.indexOf(def.name) >= 0;
|
return top_retain.indexOf(def.name) >= 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
if (this.options["module"]) {
|
||||||
|
this.directives["use strict"] = true;
|
||||||
|
this.options["toplevel"] = true;
|
||||||
|
}
|
||||||
var toplevel = this.options["toplevel"];
|
var toplevel = this.options["toplevel"];
|
||||||
this.toplevel = typeof toplevel == "string" ? {
|
this.toplevel = typeof toplevel == "string" ? {
|
||||||
funcs: /funcs/.test(toplevel),
|
funcs: /funcs/.test(toplevel),
|
||||||
|
|
@ -139,9 +143,6 @@ function Compressor(options, false_by_default) {
|
||||||
funcs: toplevel,
|
funcs: toplevel,
|
||||||
vars: toplevel
|
vars: toplevel
|
||||||
};
|
};
|
||||||
if (this.options['module']) {
|
|
||||||
this.directives['use strict'] = true;
|
|
||||||
}
|
|
||||||
var sequences = this.options["sequences"];
|
var sequences = this.options["sequences"];
|
||||||
this.sequences_limit = sequences == 1 ? 800 : sequences | 0;
|
this.sequences_limit = sequences == 1 ? 800 : sequences | 0;
|
||||||
this.warnings_produced = {};
|
this.warnings_produced = {};
|
||||||
|
|
|
||||||
|
|
@ -89,6 +89,7 @@ function minify(files, options) {
|
||||||
ie8: false,
|
ie8: false,
|
||||||
keep_classnames: false,
|
keep_classnames: false,
|
||||||
keep_fnames: false,
|
keep_fnames: false,
|
||||||
|
module: false,
|
||||||
properties: false,
|
properties: false,
|
||||||
reserved: [],
|
reserved: [],
|
||||||
safari10: false,
|
safari10: false,
|
||||||
|
|
|
||||||
10
lib/scope.js
10
lib/scope.js
|
|
@ -110,11 +110,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
|
||||||
|
|
||||||
// pass 1: setup scope chaining and handle definitions
|
// pass 1: setup scope chaining and handle definitions
|
||||||
var self = this;
|
var self = this;
|
||||||
var scope = null;
|
var scope = self.parent_scope = null;
|
||||||
if (options.module) {
|
|
||||||
scope = new AST_Scope(self);
|
|
||||||
}
|
|
||||||
self.parent_scope = scope;
|
|
||||||
var labels = new Dictionary();
|
var labels = new Dictionary();
|
||||||
var defun = null;
|
var defun = null;
|
||||||
var in_destructuring = null;
|
var in_destructuring = null;
|
||||||
|
|
@ -518,9 +514,13 @@ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options) {
|
||||||
ie8 : false,
|
ie8 : false,
|
||||||
keep_classnames: false,
|
keep_classnames: false,
|
||||||
keep_fnames : false,
|
keep_fnames : false,
|
||||||
|
module : false,
|
||||||
reserved : [],
|
reserved : [],
|
||||||
toplevel : false,
|
toplevel : false,
|
||||||
});
|
});
|
||||||
|
if (options["module"]) {
|
||||||
|
options.toplevel = true;
|
||||||
|
}
|
||||||
if (!Array.isArray(options.reserved)) options.reserved = [];
|
if (!Array.isArray(options.reserved)) options.reserved = [];
|
||||||
// Never mangle arguments
|
// Never mangle arguments
|
||||||
push_uniq(options.reserved, "arguments");
|
push_uniq(options.reserved, "arguments");
|
||||||
|
|
|
||||||
|
|
@ -1629,3 +1629,24 @@ module_mangle_scope: {
|
||||||
let e = 10;
|
let e = 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module_enabled: {
|
||||||
|
options = {
|
||||||
|
module: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {
|
||||||
|
module: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
let apple = 10, b = 20;
|
||||||
|
console.log(apple++, b, apple++);
|
||||||
|
export { apple };
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
let o = 10;
|
||||||
|
console.log(o++, 20, o++);
|
||||||
|
export { o as apple };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -734,6 +734,15 @@ describe("bin/uglifyjs", function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
it("Should mangle toplevel names with the --module option", function(done) {
|
||||||
|
var command = uglifyjscmd + " test/input/module/input.js --module -mc";
|
||||||
|
exec(command, function (err, stdout, stderr) {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
assert.strictEqual(stdout, "let e=1;export{e as foo};\n")
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
it("Should fail with --define a-b", function(done) {
|
it("Should fail with --define a-b", function(done) {
|
||||||
var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b";
|
var command = uglifyjscmd + " test/input/issue-505/input.js --define a-b";
|
||||||
exec(command, function (err, stdout, stderr) {
|
exec(command, function (err, stdout, stderr) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user