diff --git a/README.md b/README.md index 6dea439a..30777145 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tools/node.js b/tools/node.js index f6048661..83812d18 100644 --- a/tools/node.js +++ b/tools/node.js @@ -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 }); }); }