Add negate_iife option to the code generator.

See discussion in a9511dfbe5
This commit is contained in:
Mihai Bazon
2013-05-22 21:22:14 +03:00
parent 9fc8a52142
commit 9fc6796d2a
2 changed files with 7 additions and 2 deletions

View File

@@ -287,6 +287,10 @@ can pass additional arguments that control the code output:
you pass `false` then whenever possible we will use a newline instead of a you pass `false` then whenever possible we will use a newline instead of a
semicolon, leading to more readable output of uglified code (size before semicolon, leading to more readable output of uglified code (size before
gzip could be smaller; size after gzip insignificantly larger). gzip could be smaller; size after gzip insignificantly larger).
- `negate-iife` (default `!beautify`) -- prefer negation, rather than
parens, for "Immediately-Called Function Expressions". This defaults to
`true` when beautification is off, and `false` if beautification is on;
pass it manually to force a value.
### Keeping copyright notices or other comments ### Keeping copyright notices or other comments

View File

@@ -60,7 +60,8 @@ function OutputStream(options) {
bracketize : false, bracketize : false,
semicolons : true, semicolons : true,
comments : false, comments : false,
preserve_line : false preserve_line : false,
negate_iife : !(options && options.beautify),
}, true); }, true);
var indentation = 0; var indentation = 0;
@@ -352,7 +353,7 @@ function OutputStream(options) {
var self = this, generator = self._codegen; var self = this, generator = self._codegen;
stream.push_node(self); stream.push_node(self);
var needs_parens = self.needs_parens(stream); var needs_parens = self.needs_parens(stream);
var fc = self instanceof AST_Function && !stream.option("beautify"); var fc = self instanceof AST_Function && stream.option("negate_iife");
if (force_parens || (needs_parens && !fc)) { if (force_parens || (needs_parens && !fc)) {
stream.with_parens(function(){ stream.with_parens(function(){
self.add_comments(stream); self.add_comments(stream);