From: Mihai Bazon Date: Thu, 23 Aug 2012 07:39:33 +0000 (+0300) Subject: fix current_col and force a newline every 32K (support options.max_line_len) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=8d233c38d485020bdb9d86865cf50a8199fbfc27;p=UglifyJS.git fix current_col and force a newline every 32K (support options.max_line_len) --- diff --git a/lib/output.js b/lib/output.js index ae4a57c6..f83a5c89 100644 --- a/lib/output.js +++ b/lib/output.js @@ -51,6 +51,7 @@ function OutputStream(options) { ascii_only : false, inline_script : false, width : 80, + max_line_len : 32000, ie_proof : true, beautify : true }); @@ -119,6 +120,11 @@ function OutputStream(options) { return last.charAt(last.length - 1); }; + function maybe_newline() { + if (options.max_line_len && current_col > options.max_line_len) + print("\n"); + }; + function print(str) { str = String(str); var ch = str.charAt(0); @@ -131,6 +137,7 @@ function OutputStream(options) { might_need_space = false; } might_need_semicolon = false; + maybe_newline(); } if (might_need_space) { if ((is_identifier_char(last_char()) @@ -143,13 +150,14 @@ function OutputStream(options) { current_pos++; } might_need_space = false; + maybe_newline(); } var a = str.split(/\r?\n/), n = a.length; current_line += n; if (n == 1) { - current_col = a[n - 1].length; - } else { current_col += a[n - 1].length; + } else { + current_col = a[n - 1].length; } current_pos += str.length; last = str;