14
lib/parse.js
14
lib/parse.js
@@ -255,6 +255,16 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
return S.text.substr(S.pos, str.length) == str;
|
return S.text.substr(S.pos, str.length) == str;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function find_eol() {
|
||||||
|
var text = S.text;
|
||||||
|
for (var i = S.pos, n = S.text.length; i < n; ++i) {
|
||||||
|
var ch = text[i];
|
||||||
|
if (ch == '\n' || ch == '\r')
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
|
||||||
function find(what, signal_eof) {
|
function find(what, signal_eof) {
|
||||||
var pos = S.text.indexOf(what, S.pos);
|
var pos = S.text.indexOf(what, S.pos);
|
||||||
if (signal_eof && pos == -1) throw EX_EOF;
|
if (signal_eof && pos == -1) throw EX_EOF;
|
||||||
@@ -410,7 +420,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
|
|
||||||
function skip_line_comment(type) {
|
function skip_line_comment(type) {
|
||||||
var regex_allowed = S.regex_allowed;
|
var regex_allowed = S.regex_allowed;
|
||||||
var i = find("\n"), ret;
|
var i = find_eol(), ret;
|
||||||
if (i == -1) {
|
if (i == -1) {
|
||||||
ret = S.text.substr(S.pos);
|
ret = S.text.substr(S.pos);
|
||||||
S.pos = S.text.length;
|
S.pos = S.text.length;
|
||||||
@@ -427,7 +437,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) {
|
|||||||
var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function(){
|
var skip_multiline_comment = with_eof_error("Unterminated multiline comment", function(){
|
||||||
var regex_allowed = S.regex_allowed;
|
var regex_allowed = S.regex_allowed;
|
||||||
var i = find("*/", true);
|
var i = find("*/", true);
|
||||||
var text = S.text.substring(S.pos, i);
|
var text = S.text.substring(S.pos, i).replace(/\r\n|\r/g, '\n');
|
||||||
var a = text.split("\n"), n = a.length;
|
var a = text.split("\n"), n = a.length;
|
||||||
// update stream position
|
// update stream position
|
||||||
S.pos = i + 2;
|
S.pos = i + 2;
|
||||||
|
|||||||
34
test/mocha/line-endings.js
Normal file
34
test/mocha/line-endings.js
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
var Uglify = require('../../');
|
||||||
|
var assert = require("assert");
|
||||||
|
|
||||||
|
describe("line-endings", function() {
|
||||||
|
var options = {
|
||||||
|
fromString: true,
|
||||||
|
mangle: false,
|
||||||
|
compress: false,
|
||||||
|
output: {
|
||||||
|
beautify: false,
|
||||||
|
comments: /^!/,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var expected_code = '/*!one\n2\n3*/\nfunction f(x){if(x)return 3}';
|
||||||
|
|
||||||
|
it("Should parse LF line endings", function() {
|
||||||
|
var js = '/*!one\n2\n3*///comment\nfunction f(x) {\n if (x)\n//comment\n return 3;\n}\n';
|
||||||
|
var result = Uglify.minify(js, options);
|
||||||
|
assert.strictEqual(result.code, expected_code);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should parse CR/LF line endings", function() {
|
||||||
|
var js = '/*!one\r\n2\r\n3*///comment\r\nfunction f(x) {\r\n if (x)\r\n//comment\r\n return 3;\r\n}\r\n';
|
||||||
|
var result = Uglify.minify(js, options);
|
||||||
|
assert.strictEqual(result.code, expected_code);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should parse CR line endings", function() {
|
||||||
|
var js = '/*!one\r2\r3*///comment\rfunction f(x) {\r if (x)\r//comment\r return 3;\r}\r';
|
||||||
|
var result = Uglify.minify(js, options);
|
||||||
|
assert.strictEqual(result.code, expected_code);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user