From 88f6ff38d156fac213191e9e5cbe735819686a08 Mon Sep 17 00:00:00 2001 From: kzc Date: Wed, 21 Sep 2016 08:39:29 -0400 Subject: [PATCH] [ES6] fix template string escaping of \${...} --- lib/output.js | 2 +- test/compress/template-string.js | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/output.js b/lib/output.js index 232723aa..cacd5f2f 100644 --- a/lib/output.js +++ b/lib/output.js @@ -409,7 +409,7 @@ function OutputStream(options) { print(encoded); }, print_template_string_chars: function(str) { - var encoded = encode_string(str, '`'); + var encoded = encode_string(str, '`').replace(/\${/g, "\\${"); return print(encoded.substr(1, encoded.length - 2)); }, encode_string : encode_string, diff --git a/test/compress/template-string.js b/test/compress/template-string.js index df4ff897..20f7f0c4 100644 --- a/test/compress/template-string.js +++ b/test/compress/template-string.js @@ -329,3 +329,15 @@ check_escaped_chars: { } expect_exact: "var foo=` `;"; } + +escape_dollar_curly: { + options = { + evaluate: true + } + input: { + console.log(`\$\{ beep \}`) + console.log(`${1-0}\${2-0}$\{3-0}${4-0}`) + console.log(`$${""}{not an expression}`) + } + expect_exact: "console.log(`\\${ beep }`);console.log(`1\\${2-0}\\${3-0}4`);console.log(`\\${not an expression}`);" +}