From a13b7defd877bd279f3ef67c1a8ab778c28ad3bb Mon Sep 17 00:00:00 2001 From: Martii Date: Sat, 6 Feb 2016 04:11:05 -0700 Subject: [PATCH 1/5] 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 }); }); } From b18bf2bfb4814866c415e38d4ac094fec7f10a29 Mon Sep 17 00:00:00 2001 From: Martii Date: Sat, 6 Feb 2016 06:59:55 -0700 Subject: [PATCH 2/5] Scoot the README.md reference up a few notches * The sentence below doesn't make any sense if this isn't done but deviates from the coding pattern Applies to mishoo/UglifyJS2#935 --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 99f77a35..b7824ee6 100644 --- a/README.md +++ b/README.md @@ -660,11 +660,11 @@ properties are available: - `strict` — disable automatic semicolon insertion and support for trailing comma in arrays and objects +- `bare_returns` — Allow return outside of functions. (maps to the + `--bare-returns` CLI arguments option) - `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 From 4f7b8b84d85f24e72b29b2f810dc696ca3f19018 Mon Sep 17 00:00:00 2001 From: Martii Date: Sat, 6 Feb 2016 07:14:50 -0700 Subject: [PATCH 3/5] Put in the minify option * Forgot to do this... late night coding woes Applies to mishoo/UglifyJS2#932 --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index b7824ee6..4f0c3c26 100644 --- a/README.md +++ b/README.md @@ -638,6 +638,10 @@ Other options: - `compress` (default `{}`) — pass `false` to skip compressing entirely. Pass an object to specify custom [compressor options][compressor]. +- `parse` (default `{}`) — pass an object if you wish to specify + additional [parser options][parser] + + ##### mangleProperties options - `regex` — Pass a RegExp to only mangle certain names (maps to the `--mange-regex` CLI arguments option) @@ -801,3 +805,4 @@ The `source_map_options` (optional) can contain the following properties: [sm-spec]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit [codegen]: http://lisperator.net/uglifyjs/codegen [compressor]: http://lisperator.net/uglifyjs/compress + [parser]: http://lisperator.net/uglifyjs/parser From 708f152dc02009a9409397bf7200fa75a0944c97 Mon Sep 17 00:00:00 2001 From: Martii Date: Sat, 6 Feb 2016 07:17:55 -0700 Subject: [PATCH 4/5] Add period * No idea where this page referenced is store at this time so it might need to be tweaked to the README.md Applies to mishoo/UglifyJS2#935 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f0c3c26..e44d5c25 100644 --- a/README.md +++ b/README.md @@ -639,7 +639,7 @@ Other options: Pass an object to specify custom [compressor options][compressor]. - `parse` (default `{}`) — pass an object if you wish to specify - additional [parser options][parser] + additional [parser options][parser]. ##### mangleProperties options From 0aeb280c95bfe5f40a594eb411c93121625d3d8d Mon Sep 17 00:00:00 2001 From: Martii Date: Sat, 6 Feb 2016 07:21:09 -0700 Subject: [PATCH 5/5] Whitespace adjustment * Missed this in the merge conflict on re-paste... apologies for the extra noise g'night :) Applies to mishoo/UglifyJS2#935 --- tools/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/node.js b/tools/node.js index 2035c6b4..fa8c19dc 100644 --- a/tools/node.js +++ b/tools/node.js @@ -43,7 +43,7 @@ exports.minify = function(files, options) { nameCache : null, output : null, compress : {}, - parse : {} + parse : {} }); UglifyJS.base54.reset();