diff --git a/bin/uglifyjs b/bin/uglifyjs index 3a3318b25c..fc33f96f64 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 de982b1e5f..931e5f6668 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", ";")