aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMihai Bazon <mihai@bazon.net>2012-08-23 10:39:33 +0300
committerMihai Bazon <mihai@bazon.net>2012-08-23 10:39:33 +0300
commit8d233c38d485020bdb9d86865cf50a8199fbfc27 (patch)
tree9b192a90d50772d2c2e5b8ed493e0ba3dbe66e23
parent95b18e54a4632cc06a4fb36fbf631c6b1d852892 (diff)
downloadtracifyjs-8d233c38d485020bdb9d86865cf50a8199fbfc27.tar.gz
tracifyjs-8d233c38d485020bdb9d86865cf50a8199fbfc27.zip
fix current_col and force a newline every 32K (support options.max_line_len)
-rw-r--r--lib/output.js12
1 files changed, 10 insertions, 2 deletions
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;