Skip to content

Commit

Permalink
fix(es/minifier): Fix tpl-to-string conversion (#8778)
Browse files Browse the repository at this point in the history
**Related issue:**

 - Closes #8773
  • Loading branch information
kdy1 authored Mar 26, 2024
1 parent eec697f commit e7bca10
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
71 changes: 71 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8773/input/.swcrc
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issues-8xxx/8773/input/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const t = "\\\\"; console.log(`${t}`)
1 change: 1 addition & 0 deletions crates/swc/tests/fixture/issues-8xxx/8773/output/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("\\\\");
1 change: 1 addition & 0 deletions crates/swc_ecma_minifier/src/compress/pure/strings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e7bca10

Please sign in to comment.