Add `negate_iife` option to the code generator.
authorMihai Bazon <mihai@bazon.net>
Wed, 22 May 2013 18:22:14 +0000 (21:22 +0300)
committerMihai Bazon <mihai@bazon.net>
Wed, 22 May 2013 18:22:14 +0000 (21:22 +0300)
See discussion in a9511dfbe5c0d96d8cacb87582aa9a19737bbb98

README.md
lib/output.js

index 88dc310..749b8ce 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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
   semicolon, leading to more readable output of uglified code (size before
   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
 
index b510cb3..60a4a26 100644 (file)
@@ -60,7 +60,8 @@ function OutputStream(options) {
         bracketize    : false,
         semicolons    : true,
         comments      : false,
-        preserve_line : false
+        preserve_line : false,
+        negate_iife   : !(options && options.beautify),
     }, true);
 
     var indentation = 0;
@@ -352,7 +353,7 @@ function OutputStream(options) {
         var self = this, generator = self._codegen;
         stream.push_node(self);
         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)) {
             stream.with_parens(function(){
                 self.add_comments(stream);