Added a mangle properties option

This commit is contained in:
Jeremy Marzka
2016-01-17 21:54:09 -05:00
committed by Richard van Velzen
parent b5a7197ae5
commit 799509e145
2 changed files with 23 additions and 11 deletions

View File

@@ -626,6 +626,9 @@ Other options:
- `mangle` — pass `false` to skip mangling names. - `mangle` — pass `false` to skip mangling names.
- `mangleProperties` (default `false`) — pass an object to specify custom
mangle property options.
- `output` (default `null`) — pass an object if you wish to specify - `output` (default `null`) — pass an object if you wish to specify
additional [output options][codegen]. The defaults are optimized additional [output options][codegen]. The defaults are optimized
for best compression. for best compression.

View File

@@ -39,6 +39,8 @@ exports.minify = function(files, options) {
fromString : false, fromString : false,
warnings : false, warnings : false,
mangle : {}, mangle : {},
mangleProperties : false,
nameCache : null,
output : null, output : null,
compress : {} compress : {}
}); });
@@ -77,14 +79,21 @@ exports.minify = function(files, options) {
toplevel = toplevel.transform(sq); toplevel = toplevel.transform(sq);
} }
// 3. mangle // 3. mangle properties
if (options.mangleProperties || options.nameCache) {
options.mangleProperties.cache = UglifyJS.readNameCache(options.nameCache, "props");
toplevel = UglifyJS.mangle_properties(toplevel, options.mangleProperties);
UglifyJS.writeNameCache(options.nameCache, "props", options.mangleProperties.cache);
}
// 4. mangle
if (options.mangle) { if (options.mangle) {
toplevel.figure_out_scope(options.mangle); toplevel.figure_out_scope(options.mangle);
toplevel.compute_char_frequency(options.mangle); toplevel.compute_char_frequency(options.mangle);
toplevel.mangle_names(options.mangle); toplevel.mangle_names(options.mangle);
} }
// 4. output // 5. output
var inMap = options.inSourceMap; var inMap = options.inSourceMap;
var output = {}; var output = {};
if (typeof options.inSourceMap == "string") { if (typeof options.inSourceMap == "string") {