Skip to content

Commit 1891afa

Browse files
authoredNov 27, 2023
fix(es/codegen): Fix panic due to \\ud (#8346)
**Related issue:** - Closes #8345
1 parent 6e63b95 commit 1891afa

File tree

3 files changed

+8
-2
lines changed
  • crates
    • swc/tests/fixture/issues-8xxx/8345
    • swc_ecma_codegen/src

3 files changed

+8
-2
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const data = '\\ud';
2+
console.log(data);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
var data = "\\ud";
2+
console.log(data);

‎crates/swc_ecma_codegen/src/lib.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3916,9 +3916,9 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String {
39163916
2..6
39173917
};
39183918

3919-
let val_str = &inner_buf[range];
3920-
39213919
if is_valid {
3920+
let val_str = &inner_buf[range];
3921+
39223922
let v = u32::from_str_radix(val_str, 16).unwrap_or_else(|err| {
39233923
unreachable!(
39243924
"failed to parse {} as a hex value: {:?}",
@@ -3939,6 +3939,8 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String {
39393939
} else {
39403940
buf.push_str("\\\\");
39413941
}
3942+
} else {
3943+
buf.push_str("\\\\")
39423944
}
39433945
} else if is_curly {
39443946
buf.push_str("\\\\");

0 commit comments

Comments
 (0)
Please sign in to comment.