Add support for somewhat preserving line numbers.
authorRichard van Velzen <rvanvelzen@expert-shops.com>
Wed, 14 Nov 2012 13:04:47 +0000 (14:04 +0100)
committerMihai Bazon <mihai@bazon.net>
Wed, 14 Nov 2012 13:30:18 +0000 (15:30 +0200)
Usage: uglifyjs2 -b "beautify=0,preserve_line=1" /path/to/js

ref #46

lib/output.js

index 7309737..8f43245 100644 (file)
@@ -59,7 +59,8 @@ function OutputStream(options) {
         source_map    : null,
         bracketize    : false,
         semicolons    : true,
-        comments      : false
+        comments      : false,
+        preserve_line : false
     }, true);
 
     var indentation = 0;
@@ -154,6 +155,18 @@ function OutputStream(options) {
             might_need_semicolon = false;
             maybe_newline();
         }
+
+        if (!options.beautify && options.preserve_line && stack[stack.length - 1]) {
+            var target_line = stack[stack.length - 1].start.line;
+            while (current_line < target_line) {
+                OUTPUT += "\n";
+                current_pos++;
+                current_line++;
+                current_col = 0;
+                might_need_space = false;
+            }
+        }
+
         if (might_need_space) {
             var prev = last_char();
             if ((is_identifier_char(prev)