Fix semicolon printing when restricting max line length
authorRichard van Velzen <rvanvelzen@experty.com>
Wed, 29 Jul 2015 15:57:18 +0000 (17:57 +0200)
committerRichard van Velzen <rvanvelzen@experty.com>
Thu, 30 Jul 2015 14:13:32 +0000 (16:13 +0200)
Fixes #755

lib/output.js

index 1d67b1b..396c6a2 100644 (file)
@@ -161,6 +161,8 @@ function OutputStream(options) {
         str = String(str);
         var ch = str.charAt(0);
         if (might_need_semicolon) {
+            might_need_semicolon = false;
+
             if ((!ch || ";}".indexOf(ch) < 0) && !/[;]$/.test(last)) {
                 if (options.semicolons || requireSemicolonChars(ch)) {
                     OUTPUT += ";";
@@ -171,11 +173,17 @@ function OutputStream(options) {
                     current_pos++;
                     current_line++;
                     current_col = 0;
+
+                    if (/^\s+$/.test(str)) {
+                        // reset the semicolon flag, since we didn't print one
+                        // now and might still have to later
+                        might_need_semicolon = true;
+                    }
                 }
+
                 if (!options.beautify)
                     might_need_space = false;
             }
-            might_need_semicolon = false;
         }
 
         if (!options.beautify && options.preserve_line && stack[stack.length - 1]) {