Add an option to wrap IIFEs in parenthesis

For #1307.
This commit is contained in:
Richard van Velzen
2016-09-30 12:27:45 +02:00
parent fc9804b909
commit e05510f3bc
3 changed files with 53 additions and 2 deletions

View File

@@ -67,7 +67,8 @@ function OutputStream(options) {
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
@@ -552,7 +553,17 @@ function OutputStream(options) {
// 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