From 21b3c890a1dab21156f358bf388a2f9f507d1711 Mon Sep 17 00:00:00 2001 From: Jacob Kristhammar Date: Tue, 9 Sep 2014 13:02:50 +0200 Subject: [PATCH 1/2] Use uglify source map token names if missing --- lib/sourcemap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sourcemap.js b/lib/sourcemap.js index 663ef12e..948e3b39 100644 --- a/lib/sourcemap.js +++ b/lib/sourcemap.js @@ -70,7 +70,7 @@ function SourceMap(options) { source = info.source; orig_line = info.line; orig_col = info.column; - name = info.name; + name = info.name || name; } generator.addMapping({ generated : { line: gen_line + options.dest_line_diff, column: gen_col }, From f36a1eaa8b5203ab7e4616108c33a0b68668a8db Mon Sep 17 00:00:00 2001 From: Mihai Bazon Date: Mon, 20 Oct 2014 18:12:13 +0300 Subject: [PATCH 2/2] Add option to allow return outside of functions. Close #288 --- bin/uglifyjs | 9 ++++++--- lib/parse.js | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/bin/uglifyjs b/bin/uglifyjs index 3a3318b2..fc33f96f 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -64,6 +64,7 @@ You need to pass an argument to this option to specify the name that your module .describe("v", "Verbose") .describe("V", "Print version number and exit.") .describe("noerr", "Don't throw an error for unknown options in -c, -b or -m.") + .describe("bare-returns", "Allow return outside of functions. Useful when minifying CommonJS modules.") .alias("p", "prefix") .alias("o", "output") @@ -100,6 +101,7 @@ You need to pass an argument to this option to specify the name that your module .boolean("lint") .boolean("V") .boolean("noerr") + .boolean("bare-returns") .wrap(80) @@ -275,9 +277,10 @@ async.eachLimit(files, 1, function (file, cb) { else { try { TOPLEVEL = UglifyJS.parse(code, { - filename : file, - toplevel : TOPLEVEL, - expression : ARGS.expr, + filename : file, + toplevel : TOPLEVEL, + expression : ARGS.expr, + bare_returns : ARGS.bare_returns, }); } catch(ex) { if (ex instanceof UglifyJS.JS_Parse_Error) { diff --git a/lib/parse.js b/lib/parse.js index de982b1e..931e5f66 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -609,6 +609,7 @@ function parse($TEXT, options) { toplevel : null, expression : false, html5_comments : true, + bare_returns : false, }); var S = { @@ -788,7 +789,7 @@ function parse($TEXT, options) { return if_(); case "return": - if (S.in_function == 0) + if (S.in_function == 0 && !options.bare_returns) croak("'return' outside of function"); return new AST_Return({ value: ( is("punc", ";")