Fix handling \r\n

Close #437
This commit is contained in:
Mihai Bazon
2015-01-05 12:14:42 +02:00
parent 93a6e5780e
commit 13219cebcb

View File

@@ -206,7 +206,7 @@ var EX_EOF = {};
function tokenizer($TEXT, filename, html5_comments) {
var S = {
text : $TEXT.replace(/\r\n?|[\n\u2028\u2029]/g, "\n").replace(/\uFEFF/g, ''),
text : $TEXT.replace(/\uFEFF/g, ''),
filename : filename,
pos : 0,
tokpos : 0,
@@ -225,10 +225,15 @@ function tokenizer($TEXT, filename, html5_comments) {
var ch = S.text.charAt(S.pos++);
if (signal_eof && !ch)
throw EX_EOF;
if (ch == "\n") {
if ("\r\n\u2028\u2029".indexOf(ch) >= 0) {
S.newline_before = S.newline_before || !in_string;
++S.line;
S.col = 0;
if (!in_string && ch == "\r" && peek() == "\n") {
// treat a \r\n sequence as a single \n
++S.pos;
ch = "\n";
}
} else {
++S.col;
}