diff --git a/crates/oxc_minifier/src/peephole/replace_known_methods.rs b/crates/oxc_minifier/src/peephole/replace_known_methods.rs index 2d26f03686e7e..7f98efbd36b67 100644 --- a/crates/oxc_minifier/src/peephole/replace_known_methods.rs +++ b/crates/oxc_minifier/src/peephole/replace_known_methods.rs @@ -806,7 +806,7 @@ impl<'a> PeepholeOptimizations { Cow::Owned( s.cow_replace("\\", "\\\\") .cow_replace("`", "\\`") - .cow_replace("${", "\\${") + .cow_replace("$", "\\$") .cow_replace("\r\n", "\\r\n") .into_owned(), ) @@ -1832,6 +1832,14 @@ mod test { test_same("x = obj.concat([1,2]).concat(1)"); } + #[test] + fn test_add_template_literal() { + test("x = '$' + `{${x}}`", "x = `\\${${x}}`"); + test("x = `{${x}}` + '$'", "x = `{${x}}\\$`"); + test("x = `$` + `{${x}}`", "x = `\\${${x}}`"); + test("x = `{${x}}` + `$`", "x = `{${x}}\\$`"); + } + #[test] fn test_remove_array_literal_from_front_of_concat() { test("x = [].concat([1,2,3],1)", "x = [1,2,3,1]"); diff --git a/tasks/minsize/minsize.snap b/tasks/minsize/minsize.snap index 363e182e72dfd..710c471b876e4 100644 --- a/tasks/minsize/minsize.snap +++ b/tasks/minsize/minsize.snap @@ -21,7 +21,7 @@ Original | minified | minified | gzip | gzip | Fixture 3.20 MB | 1.01 MB | 1.01 MB | 324.12 kB | 331.56 kB | echarts.js -6.69 MB | 2.28 MB | 2.31 MB | 466.11 kB | 488.28 kB | antd.js +6.69 MB | 2.28 MB | 2.31 MB | 466.10 kB | 488.28 kB | antd.js 10.95 MB | 3.35 MB | 3.49 MB | 860.93 kB | 915.50 kB | typescript.js