diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-02-01 18:29:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-02 02:29:43 +0800 |
commit | 7110c6923b8ef82f295f5d9ff9d42d2f88432810 (patch) | |
tree | 94758b380b5deecd59be324fffc429f429dbc663 | |
parent | b27b6807cb01b6068cecda435b6b6b2a2ef5af07 (diff) | |
download | tracifyjs-7110c6923b8ef82f295f5d9ff9d42d2f88432810.tar.gz tracifyjs-7110c6923b8ef82f295f5d9ff9d42d2f88432810.zip |
fix corner case in `templates` (#4607)
fixes #4606
-rw-r--r-- | lib/compress.js | 4 | ||||
-rw-r--r-- | test/compress/templates.js | 15 |
2 files changed, 18 insertions, 1 deletions
diff --git a/lib/compress.js b/lib/compress.js index ac7aa3e0..001f2e14 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -9956,7 +9956,9 @@ merge(Compressor.prototype, { var node = exprs[i]; var ev = node.evaluate(compressor); if (ev === node) continue; - ev = "" + ev; + ev = ("" + ev).replace(/\r|\\|`/g, function(s) { + return "\\" + (s == "\r" ? "r" : s); + }); if (ev.length > node.print_to_string().length + 3) continue; exprs.splice(i, 1); strs.splice(i, 2, strs[i] + ev + strs[i + 1]); diff --git a/test/compress/templates.js b/test/compress/templates.js index 3b0e983c..3c7957f8 100644 --- a/test/compress/templates.js +++ b/test/compress/templates.js @@ -222,3 +222,18 @@ issue_4604: { expect_stdout: "PASS" node_version: ">=4" } + +issue_4606: { + options = { + evaluate: true, + templates: true, + } + input: { + console.log(`${typeof A} ${"\r"} ${"\\"} ${"`"}`); + } + expect: { + console.log(`${typeof A} \r \\ \``); + } + expect_stdout: "undefined \r \\ `" + node_version: ">=4" +} |