diff --git a/lib/ast.js b/lib/ast.js index 974d4c1b..1ac58bae 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -446,7 +446,7 @@ var AST_PrefixedTemplateString = DEFNODE("PrefixedTemplateString", "template_str var AST_TemplateString = DEFNODE("TemplateString", "segments", { $documentation: "A template string literal", $propdoc: { - segments: "[AST_TemplateSegment|AST_Expression]* One or more segments, starting with AST_TemplateSegment. AST_Expression may follow AST_TemplateSegment, but each AST_Expression must be followed by AST_TemplateSegment." + segments: "[AST_Node*] One or more segments, starting with AST_TemplateSegment. AST_Node may follow AST_TemplateSegment, but each AST_Node must be followed by AST_TemplateSegment." }, _walk: function(visitor) { return visitor._visit(this, function(){ diff --git a/lib/parse.js b/lib/parse.js index 04a6502b..bb9bdf1f 100644 --- a/lib/parse.js +++ b/lib/parse.js @@ -509,8 +509,11 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } var content = "", raw = "", ch, tok; next(true, true); - while ((ch = next(true, true)) !== "`") { - if (ch === "$" && peek() === "{") { + while ((ch = next(true, true)) != "`") { + if (ch == "\r") { + if (peek() == "\n") ++S.pos; + ch = "\n"; + } else if (ch == "$" && peek() == "{") { next(true, true); S.brace_counter++; tok = token(begin ? "template_head" : "template_substitution", content); @@ -521,7 +524,7 @@ function tokenizer($TEXT, filename, html5_comments, shebang) { } raw += ch; - if (ch === "\\") { + if (ch == "\\") { var tmp = S.pos; ch = read_escaped_char(); raw += S.text.substr(tmp, S.pos - tmp); diff --git a/test/mocha/template-string.js b/test/mocha/template-string.js index d0a936ff..1170e3e6 100644 --- a/test/mocha/template-string.js +++ b/test/mocha/template-string.js @@ -30,4 +30,13 @@ describe("Template string", function() { assert.throws(exec(tests[i]), fail, tests[i]); } }); + it("Should process all line terminators as LF", function() { + [ + "`a\rb`", + "`a\nb`", + "`a\r\nb`", + ].forEach(function(code) { + assert.strictEqual(uglify.parse(code).print_to_string(), "`a\\nb`;"); + }); + }); });