diff --git a/crates/swc/tests/fixture/issues-8xxx/8345/input/1.js b/crates/swc/tests/fixture/issues-8xxx/8345/input/1.js new file mode 100644 index 00000000000..c6340e77afc --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8345/input/1.js @@ -0,0 +1,2 @@ +const data = '\\ud'; +console.log(data); diff --git a/crates/swc/tests/fixture/issues-8xxx/8345/output/1.js b/crates/swc/tests/fixture/issues-8xxx/8345/output/1.js new file mode 100644 index 00000000000..37a65bc97cb --- /dev/null +++ b/crates/swc/tests/fixture/issues-8xxx/8345/output/1.js @@ -0,0 +1,2 @@ +var data = "\\ud"; +console.log(data); diff --git a/crates/swc_ecma_codegen/src/lib.rs b/crates/swc_ecma_codegen/src/lib.rs index 7691048a754..101c44b01dc 100644 --- a/crates/swc_ecma_codegen/src/lib.rs +++ b/crates/swc_ecma_codegen/src/lib.rs @@ -3916,9 +3916,9 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String { 2..6 }; - let val_str = &inner_buf[range]; - if is_valid { + let val_str = &inner_buf[range]; + let v = u32::from_str_radix(val_str, 16).unwrap_or_else(|err| { unreachable!( "failed to parse {} as a hex value: {:?}", @@ -3939,6 +3939,8 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String { } else { buf.push_str("\\\\"); } + } else { + buf.push_str("\\\\") } } else if is_curly { buf.push_str("\\\\");