Repository: swc-project/swc (rust)

Issue:
String interpolation in template literals isn't correctly encoded in the output 
### Describe the bug

having some code like 
```
const t = "\\\\"; console.log(`${t}`)
```
gets converted to 
```
console.log("\\");
```
in the final output

this is an issue in some Regex 




after testing in the playground, it works in ES3 & 5 but breaks in any ES20**

### Input code

```typescript
const t = "\\\\"; console.log(`${t}`)
```


### Config

```json
{
    jsc: {
      target: 'es2022',
      minify: {
        mangle: true,
        compress: true,
        // ...userConfig,
        toplevel: true,
        module: true,
      },
    },
    minify: true,
    sourceMaps: true,
    configFile: false,
    swcrc: false,
}
```


### Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.4.8&code=H4sIAAAAAAAAA0vOzysuUShTsFXwTSzJ0CtKzEvJz9XQVLBT0DO15uJKBkunZRYBSVsFJQ17G8XoGCCI1VSyhkoWpwLpFExZqLQbVG9earlCUGq6a0WBRpmCvYKSkoIV1FxtBaWS1OISJU2ojmCYgdi0JKhUQyysTUDSCNaZn5Oql5OfrgG2UQdqjCbcISUZmUVYnImsE2g4WFVtgiYAyOGIBRgBAAA%3D&config=H4sIAAAAAAAAA41VQY7bMAy87ysCn3vY5lAUfUBvfYOgWJSjVBYNkfImWOTvpRU7m93QRi9BzNGQIjmk3l92u%2BZEbfNr9y5%2F5WOwmSDfv8VCl8T2LJYG2t5Sm8PAzbcFPdEEeRsJqul6Qxq2uQOuLNq%2F7vczo4mIBAtjtvUhBX95jNliP2QgerCJVVyWHhLTZ%2F6MZXybAM7l0X5AjGDTBmIsmZAYOsia4xZjtAOBGW1WvEw3tTkQaiEmsDA4M2QcVDy5wAGTxHxGHVhnWnSgQCFDy2EEjSaxhJZI0lPyqbCDQ%2Bm62ucvbBhtLJaVmHCuLZHbKl6PGIiNL0kr4Q1cqcENnIv7lRm8ycAlp2feCUNa6clfAKlAtETJ9qD5rSe86GmN7TeZIXmRLF8UXPStZZmgk6KaELxS2akykDlo3czgSgtTZVvtOjO8Uj4KDgx4L1pRXNNb4PaoBeXLAOgVQPprvaaqG2DuU7iCTwOxAf%2BWLFkX2Hyit3xcR%2BnSHzBuBOiBj%2Bg2DkgrGNfhLFviPKzjJTkQaYBTjxSqwPMSkAFgNLHuyydtyHiIR9NFPHysifnA9b6He5u6Ou8P%2B5JxiDBCXJPxf4zIJip3GydVL5P9NL3wUxOllcEL318%2FPRuSysvyW5NqenTlIaGqydtz8qP5OLS8HEvVmkB%2FFmKt0%2FUfj5GfKOMGAAA%3D

### SWC Info output


    Operating System:
        Platform: darwin
        Arch: arm64
        Machine Type: arm64
        Version: Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:59 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6030
        CPU: (11 cores)
            Models: Apple M3 Pro

    Binaries:
        Node: 20.11.1
        npm: 10.2.4
        Yarn: N/A
        pnpm: N/A

    Relevant Packages:
        @swc/core: 1.4.8
        @swc/helpers: N/A
        @swc/types: 0.1.6
        typescript: 5.4.3

    SWC Config:
        output: N/A
        .swcrc path: N/A

    Next.js info:
        output: N/A

### Expected behavior

for it to not modify the original strings

### Actual behavior

it modified escaped backslashes in strings 

### Version

v1.4.8

### Additional context

_No response_

Pull request:
fix(es/minifier): Fix tpl-to-string conversion
**Related issue:**

 - Closes #8773

Patch:
diff --git a/crates/swc_ecma_minifier/src/compress/pure/strings.rs b/crates/swc_ecma_minifier/src/compress/pure/strings.rs
index 169cc27552..8e177d66fc 100644
--- a/crates/swc_ecma_minifier/src/compress/pure/strings.rs
+++ b/crates/swc_ecma_minifier/src/compress/pure/strings.rs
@@ -191,6 +191,7 @@ impl Pure<'_> {
             Expr::Tpl(t) if t.quasis.len() == 1 && t.exprs.is_empty() => {
                 if let Some(value) = &t.quasis[0].cooked {
                     if value.chars().all(|c| match c {
+                        '\\' => false,
                         '\u{0020}'..='\u{007e}' => true,
                         '\n' | '\r' => self.config.force_str_for_tpl,
                         _ => false,


Test patch:
diff --git a/crates/swc/tests/fixture/issues-8xxx/8773/input/.swcrc b/crates/swc/tests/fixture/issues-8xxx/8773/input/.swcrc
new file mode 100644
index 0000000000..f00898d24b
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8773/input/.swcrc
@@ -0,0 +1,71 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "ecmascript",
+            "jsx": false
+        },
+        "target": "es2022",
+        "loose": false,
+        "minify": {
+            "compress": {
+                "arguments": false,
+                "arrows": true,
+                "booleans": true,
+                "booleans_as_integers": false,
+                "collapse_vars": true,
+                "comparisons": true,
+                "computed_props": true,
+                "conditionals": true,
+                "dead_code": true,
+                "directives": true,
+                "drop_console": false,
+                "drop_debugger": true,
+                "evaluate": true,
+                "expression": false,
+                "hoist_funs": false,
+                "hoist_props": true,
+                "hoist_vars": false,
+                "if_return": true,
+                "join_vars": true,
+                "keep_classnames": false,
+                "keep_fargs": true,
+                "keep_fnames": false,
+                "keep_infinity": false,
+                "loops": true,
+                "negate_iife": true,
+                "properties": true,
+                "reduce_funcs": false,
+                "reduce_vars": false,
+                "side_effects": true,
+                "switches": true,
+                "typeofs": true,
+                "unsafe": false,
+                "unsafe_arrows": false,
+                "unsafe_comps": false,
+                "unsafe_Function": false,
+                "unsafe_math": false,
+                "unsafe_symbols": false,
+                "unsafe_methods": false,
+                "unsafe_proto": false,
+                "unsafe_regexp": false,
+                "unsafe_undefined": false,
+                "unused": true,
+                "const_to_let": true,
+                "pristine_globals": true
+            },
+            "mangle": {
+                "toplevel": false,
+                "keep_classnames": false,
+                "keep_fnames": false,
+                "keep_private_props": false,
+                "ie8": false,
+                "safari10": false
+            }
+        }
+    },
+    "module": {
+        "type": "es6"
+    },
+    "minify": true,
+    "isModule": true
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8773/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8773/input/1.js
new file mode 100644
index 0000000000..dd0fe2c2c0
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8773/input/1.js
@@ -0,0 +1,1 @@
+const t = "\\\\"; console.log(`${t}`)
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-8xxx/8773/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8773/output/1.js
new file mode 100644
index 0000000000..4b1171496d
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-8xxx/8773/output/1.js
@@ -0,0 +1,1 @@
+console.log("\\\\");