diff --git a/README.md b/README.md index 496c755a..e46aa017 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,8 @@ The available options are: `pure_funcs` List of functions that can be safely removed when their return values are 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: `builtins` Mangle property names that overlaps with standard JavaScript globals. @@ -83,6 +84,7 @@ The available options are: with DOM properties. `ignore_quoted` Only mangle unquoted properies. `regex` Only mangle matched property names. + `reserved` List of names that should not be mangled. -b, --beautify [options] Beautify output/specify output options: `beautify` Enabled with `--beautify` by default. `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). 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: - uglifyjs ... -m except=[$,require,exports] + uglifyjs ... -m reserved=[$,require,exports] to prevent the `require`, `exports` and `$` names from being changed. @@ -716,7 +718,7 @@ Other options: ##### 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 default). @@ -741,7 +743,7 @@ Other options: UglifyJS.minify("tst.js").code; // '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;' UglifyJS.minify("tst.js", { mangle: { toplevel: true } }).code; diff --git a/lib/minify.js b/lib/minify.js index 7d5c9578..fe762db6 100644 --- a/lib/minify.js +++ b/lib/minify.js @@ -53,10 +53,10 @@ function minify(files, options) { options.mangle = defaults(options.mangle, { cache: null, eval: false, - except: [], ie8: false, keep_fnames: false, properties: false, + reserved: [], toplevel: false, }, true); } diff --git a/lib/scope.js b/lib/scope.js index 53c2b5b8..2ffca25a 100644 --- a/lib/scope.js +++ b/lib/scope.js @@ -325,8 +325,8 @@ AST_Scope.DEFMETHOD("next_mangled", function(options){ if (!is_identifier(m)) continue; // skip over "do" // https://github.com/mishoo/UglifyJS2/issues/242 -- do not - // shadow a name excepted from mangling. - if (options.except.indexOf(m) >= 0) continue; + // shadow a name reserved from mangling. + if (options.reserved.indexOf(m) >= 0) continue; // we must ensure that the mangled name does not shadow a name // 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){ return defaults(options, { eval : false, - except : [], ie8 : false, keep_fnames : false, + reserved : [], toplevel : false, }); }); @@ -410,7 +410,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ options = this._default_mangler_options(options); // Never mangle arguments - options.except.push('arguments'); + options.reserved.push('arguments'); // We only need to mangle declaration nodes. Special logic wired // 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) { this.globals.each(function(symbol){ - if (options.except.indexOf(symbol.name) < 0) { + if (options.reserved.indexOf(symbol.name) < 0) { to_mangle.push(symbol); } }); @@ -438,7 +438,7 @@ AST_Toplevel.DEFMETHOD("mangle_names", function(options){ if (node instanceof AST_Scope) { var p = tw.parent(), a = []; node.variables.each(function(symbol){ - if (options.except.indexOf(symbol.name) < 0) { + if (options.reserved.indexOf(symbol.name) < 0) { a.push(symbol); } });