Create and map bare-returns into new parse property name

* Following as much previous structure as possible... see analysis at https://github.com/mishoo/UglifyJS2/issues/935#issuecomment-180712909
* Using `undefined` as default since is technically assigned elsewhere
* Note entirely sure if https://github.com/mishoo/UglifyJS2/blob/master/test/compress/return_undefined.js is the test for this or not
* Change README.md to reflect and add additional sub-note about Userscript IIFE possibility

Applies to mishoo/UglifyJS2#935
This commit is contained in:
Martii 2016-02-06 04:11:05 -07:00
parent b5a7197ae5
commit a13b7defd8
2 changed files with 9 additions and 3 deletions

View File

@ -125,7 +125,9 @@ The available options are:
--noerr Don't throw an error for unknown options in -c,
-b or -m.
--bare-returns Allow return outside of functions. Useful when
minifying CommonJS modules.
minifying CommonJS modules and Userscripts that
may be anonymous function wrapped (IIFE) by the
.user.js engine `caller`.
--keep-fnames Do not mangle/drop function names. Useful for
code relying on Function.prototype.name.
--reserved-file File containing reserved names
@ -654,6 +656,8 @@ properties are available:
- `filename` — the name of the file where this code is coming from
- `toplevel` — a `toplevel` node (as returned by a previous invocation of
`parse`)
- `bare_returns` — Allow return outside of functions. (maps to the
`--bare-returns` CLI arguments option)
The last two options are useful when you'd like to minify multiple files and
get a single file as the output and a proper source map. Our CLI tool does

View File

@ -40,7 +40,8 @@ exports.minify = function(files, options) {
warnings : false,
mangle : {},
output : null,
compress : {}
compress : {},
parse : {}
});
UglifyJS.base54.reset();
@ -60,7 +61,8 @@ exports.minify = function(files, options) {
sourcesContent[file] = code;
toplevel = UglifyJS.parse(code, {
filename: options.fromString ? i : file,
toplevel: toplevel
toplevel: toplevel,
bare_returns: options.parse ? options.parse.bare_returns : undefined
});
});
}