For #1307.
.describe("name-cache", "File to hold mangled names mappings")
.describe("pure-funcs", "List of functions that can be safely removed if their return value is not used")
.describe("dump-spidermonkey-ast", "Dump SpiderMonkey AST to stdout.")
+ .describe("wrap-iife", "Wrap IIFEs in parenthesis. Note: this disables the negate_iife compression option")
.alias("p", "prefix")
.alias("o", "output")
.boolean("bare-returns")
.boolean("keep-fnames")
.boolean("reserve-domprops")
+ .boolean("wrap-iife")
.wrap(80)
if (MANGLE) MANGLE.keep_fnames = true;
}
+if (ARGS.wrap_iife) {
+ if (COMPRESS) COMPRESS.negate_iife = false;
+ OUTPUT_OPTIONS.wrap_iife = true;
+}
+
if (BEAUTIFY)
UglifyJS.merge(OUTPUT_OPTIONS, BEAUTIFY);
screw_ie8 : true,
preamble : null,
quote_style : 0,
- keep_quoted_props: false
+ keep_quoted_props: false,
+ wrap_iife : false,
}, true);
// Convert comment option to RegExp if neccessary and set up comments filter
// a function expression needs parens around it when it's provably
// the first token to appear in a statement.
PARENS(AST_Function, function(output){
- return first_in_statement(output);
+ if (first_in_statement(output)) {
+ return true;
+ }
+
+ if (output.option('wrap_iife')) {
+ var p = output.parent();
+ console.log()
+ return p instanceof AST_Call && p.expression === this;
+ }
+
+ return false;
});
// same goes for an object literal, because otherwise it would be
--- /dev/null
+wrap_iife: {
+ options = {
+ negate_iife: false,
+ }
+ beautify = {
+ wrap_iife: true,
+ }
+ input: {
+ (function() {
+ return function() {
+ console.log('test')
+ };
+ })()();
+ }
+ expect_exact: '(function(){return function(){console.log("test")}})()();'
+}
+
+wrap_iife_in_return_call: {
+ options = {
+ negate_iife: false,
+ }
+ beautify = {
+ wrap_iife: true,
+ }
+ input: {
+ (function() {
+ return (function() {
+ console.log('test')
+ })();
+ })()();
+ }
+ expect_exact: '(function(){return(function(){console.log("test")})()})()();'
+}