rename except to reserved

This commit is contained in:
alexlamsl 2017-04-15 15:49:08 +08:00
parent ca71d8846c
commit f6d964dce5
3 changed files with 14 additions and 12 deletions

View File

@ -74,7 +74,8 @@ The available options are:
`pure_funcs` List of functions that can be safely `pure_funcs` List of functions that can be safely
removed when their return values are removed when their return values are
not used. not used.
-m, --mangle [options] Mangle names/specify mangler options. -m, --mangle [options] Mangle names/specify mangler options:
`reserved` List of names that should not be mangled.
--mangle-props [options] Mangle properties/specify mangler options: --mangle-props [options] Mangle properties/specify mangler options:
`builtins` Mangle property names that overlaps `builtins` Mangle property names that overlaps
with standard JavaScript globals. with standard JavaScript globals.
@ -83,6 +84,7 @@ The available options are:
with DOM properties. with DOM properties.
`ignore_quoted` Only mangle unquoted properies. `ignore_quoted` Only mangle unquoted properies.
`regex` Only mangle matched property names. `regex` Only mangle matched property names.
`reserved` List of names that should not be mangled.
-b, --beautify [options] Beautify output/specify output options: -b, --beautify [options] Beautify output/specify output options:
`beautify` Enabled with `--beautify` by default. `beautify` Enabled with `--beautify` by default.
`preamble` Preamble to prepend to the output. You `preamble` Preamble to prepend to the output. You
@ -203,10 +205,10 @@ To enable the mangler you need to pass `--mangle` (`-m`). The following
(disabled by default). (disabled by default).
When mangling is enabled but you want to prevent certain names from being When mangling is enabled but you want to prevent certain names from being
mangled, you can declare those names with `--mangle except` — pass a mangled, you can declare those names with `--mangle reserved` — pass a
comma-separated list of names. For example: comma-separated list of names. For example:
uglifyjs ... -m except=[$,require,exports] uglifyjs ... -m reserved=[$,require,exports]
to prevent the `require`, `exports` and `$` names from being changed. to prevent the `require`, `exports` and `$` names from being changed.
@ -716,7 +718,7 @@ Other options:
##### mangle ##### mangle
- `except` - pass an array of identifiers that should be excluded from mangling - `reserved` - pass an array of identifiers that should be excluded from mangling
- `toplevel` — mangle names declared in the toplevel scope (disabled by - `toplevel` — mangle names declared in the toplevel scope (disabled by
default). default).
@ -741,7 +743,7 @@ Other options:
UglifyJS.minify("tst.js").code; UglifyJS.minify("tst.js").code;
// 'function funcName(a,n){}var globalVar;' // 'function funcName(a,n){}var globalVar;'
UglifyJS.minify("tst.js", { mangle: { except: ['firstLongName'] } }).code; UglifyJS.minify("tst.js", { mangle: { reserved: ['firstLongName'] } }).code;
// 'function funcName(firstLongName,a){}var globalVar;' // 'function funcName(firstLongName,a){}var globalVar;'
UglifyJS.minify("tst.js", { mangle: { toplevel: true } }).code; UglifyJS.minify("tst.js", { mangle: { toplevel: true } }).code;

View File

@ -53,10 +53,10 @@ function minify(files, options) {
options.mangle = defaults(options.mangle, { options.mangle = defaults(options.mangle, {
cache: null, cache: null,
eval: false, eval: false,
except: [],
ie8: false, ie8: false,
keep_fnames: false, keep_fnames: false,
properties: false, properties: false,
reserved: [],
toplevel: false, toplevel: false,
}, true); }, true);
} }

View File

@ -325,8 +325,8 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){
if (!is_identifier(m)) continue; // skip over "do" if (!is_identifier(m)) continue; // skip over "do"
// https://github.com/mishoo/UglifyJS2/issues/242 -- do not // https://github.com/mishoo/UglifyJS2/issues/242 -- do not
// shadow a name excepted from mangling. // shadow a name reserved from mangling.
if (options.except.indexOf(m) >= 0) continue; if (options.reserved.indexOf(m) >= 0) continue;
// we must ensure that the mangled name does not shadow a name // we must ensure that the mangled name does not shadow a name
// from some parent scope that is referenced in this or in // from some parent scope that is referenced in this or in
@ -399,9 +399,9 @@ AST_Symbol.DEFMETHOD("global", function(){
AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){ AST_Toplevel.DEFMETHOD("_default_mangler_options", function(options){
return defaults(options, { return defaults(options, {
eval : false, eval : false,
except : [],
ie8 : false, ie8 : false,
keep_fnames : false, keep_fnames : false,
reserved : [],
toplevel : false, toplevel : false,
}); });
}); });
@ -410,7 +410,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
options = this._default_mangler_options(options); options = this._default_mangler_options(options);
// Never mangle arguments // Never mangle arguments
options.except.push('arguments'); options.reserved.push('arguments');
// We only need to mangle declaration nodes. Special logic wired // We only need to mangle declaration nodes. Special logic wired
// into the code generator will display the mangled name if it's // into the code generator will display the mangled name if it's
@ -421,7 +421,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
if (options.cache) { if (options.cache) {
this.globals.each(function(symbol){ this.globals.each(function(symbol){
if (options.except.indexOf(symbol.name) < 0) { if (options.reserved.indexOf(symbol.name) < 0) {
to_mangle.push(symbol); to_mangle.push(symbol);
} }
}); });
@ -438,7 +438,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){
if (node instanceof AST_Scope) { if (node instanceof AST_Scope) {
var p = tw.parent(), a = []; var p = tw.parent(), a = [];
node.variables.each(function(symbol){ node.variables.each(function(symbol){
if (options.except.indexOf(symbol.name) < 0) { if (options.reserved.indexOf(symbol.name) < 0) {
a.push(symbol); a.push(symbol);
} }
}); });