From a13b7defd877bd279f3ef67c1a8ab778c28ad3bb Mon Sep 17 00:00:00 2001 From: Martii Date: Sat, 6 Feb 2016 04:11:05 -0700 Subject: [PATCH] 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 --- README.md | 6 +++++- tools/node.js | 6 ++++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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 }); }); }