diff --git a/lib/output.js b/lib/output.js index 3cd66502..b96d78a9 100644 --- a/lib/output.js +++ b/lib/output.js @@ -171,17 +171,6 @@ function OutputStream(options) { return '"' + str.replace(/\x22/g, '\\"') + '"'; } function quote_template() { - if (!options.ascii_only) { - str = str.replace(/\\(n|r|u2028|u2029)/g, function(s, c) { - switch(c) { - case "n": return "\n"; - case "r": return "\r"; - case "u2028": return "\u2028"; - case "u2029": return "\u2029"; - } - return s; - }); - } return '`' + str.replace(/`/g, '\\`') + '`'; } if (options.ascii_only) str = to_ascii(str); diff --git a/test/compress/template-string.js b/test/compress/template-string.js index 4b3acd49..d9570c0a 100644 --- a/test/compress/template-string.js +++ b/test/compress/template-string.js @@ -45,7 +45,7 @@ template_strings_without_ascii_only: { bar ↂωↂ` } - expect_exact: "var foo=`foo\n bar\n ↂωↂ`;" + expect_exact: "var foo=`foo\\n bar\\n ↂωↂ`;" } template_string_with_constant_expression: { @@ -351,7 +351,8 @@ template_starting_with_newline: { return ` this is a template string!`; }; - } expect_exact: "function foo(e){return`\nthis is a template string!`}" + } + expect_exact: "function foo(e){return`\\nthis is a template string!`}" } template_with_newline: { @@ -363,7 +364,8 @@ template_with_newline: { return `yep, this is a template string!`; }; - } expect_exact: "function foo(e){return`yep,\nthis is a template string!`}" + } + expect_exact: "function foo(e){return`yep,\\nthis is a template string!`}" } template_ending_with_newline: { @@ -375,5 +377,26 @@ template_ending_with_newline: { return `this is a template string! `; }; - } expect_exact: "function foo(e){return`this is a template string!\n`}" + } + expect_exact: "function foo(e){return`this is a template string!\\n`}" +} + +issue_1856: { + beautify = { + ascii_only: false, + } + input: { + console.log(`\\n\\r\\u2028\\u2029\n\r\u2028\u2029`); + } + expect_exact: "console.log(`\\\\n\\\\r\\\\u2028\\\\u2029\\n\\r\\u2028\\u2029`);" +} + +issue_1856_ascii_only: { + beautify = { + ascii_only: true, + } + input: { + console.log(`\\n\\r\\u2028\\u2029\n\r\u2028\u2029`); + } + expect_exact: "console.log(`\\\\n\\\\r\\\\u2028\\\\u2029\\n\\r\\u2028\\u2029`);" }