add builtins & domprops

fixes #1368
This commit is contained in:
alexlamsl 2017-04-15 15:20:56 +08:00
parent 66cebbf336
commit 9812cba843
4 changed files with 5620 additions and 5617 deletions

View File

@ -76,7 +76,11 @@ The available options are:
not used.
-m, --mangle [options] Mangle names/specify mangler options.
--mangle-props [options] Mangle properties/specify mangler options:
`builtins` Mangle property names that overlaps
with standard JavaScript globals.
`debug` Add debug prefix and suffix.
`domprops` Mangle property names that overlaps
with DOM properties.
`ignore_quoted` Only mangle unquoted properies.
`regex` Only mangle matched property names.
-b, --beautify [options] Beautify output/specify output options:
@ -142,12 +146,6 @@ The available options are:
specify the name that your module will take
when included in, say, a browser.
```
TODOs:
```
--reserved-file File containing reserved names
--reserve-domprops Make (most?) DOM properties reserved for
--mangle-props
```
Specify `--output` (`-o`) to declare the output file. Otherwise the output
goes to STDOUT.

View File

@ -77,6 +77,14 @@ if (program.keepFnames) {
options.keep_fnames = true;
}
if (program.mangleProps) {
if (program.mangleProps.domprops) {
delete program.mangleProps.domprops;
} else {
if (!Array.isArray(program.mangleProps.reserved)) program.mangleProps.reserved = [];
require("../tools/domprops").forEach(function(name) {
UglifyJS.push_uniq(program.mangleProps.reserved, name);
});
}
if (typeof options.mangle != "object") options.mangle = {};
options.mangle.properties = program.mangleProps;
}

View File

@ -43,16 +43,16 @@
"use strict";
function find_builtins() {
function find_builtins(reserved) {
// NaN will be included due to Number.NaN
var a = [
[
"null",
"true",
"false",
"Infinity",
"-Infinity",
"undefined",
];
].forEach(add);
[ Object, Array, Function, Number,
String, Boolean, Error, Math,
Date, RegExp
@ -63,13 +63,13 @@ function find_builtins() {
}
});
function add(name) {
push_uniq(a, name);
push_uniq(reserved, name);
}
return a;
}
function mangle_properties(ast, options) {
options = defaults(options, {
builtins: false,
cache: null,
debug: false,
ignore_quoted: false,
@ -78,9 +78,8 @@ function mangle_properties(ast, options) {
reserved: null,
});
var reserved = options.reserved;
if (reserved == null)
reserved = find_builtins();
var reserved = options.reserved || [];
if (!options.builtins) find_builtins(reserved);
var cache = options.cache;
if (cache == null) {

File diff suppressed because it is too large Load Diff