Skip to content

Commit 2cdea3f

Browse files
authoredNov 29, 2023
fix(es/codegen): Wrap quote for length greater than one (#8351)
1 parent 655e95a commit 2cdea3f

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed
 

‎crates/swc_ecma_codegen/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3820,7 +3820,7 @@ fn get_ascii_only_ident(sym: &str, target: EsVersion) -> Cow<str> {
38203820
let h = ((c as u32 - 0x10000) / 0x400) + 0xd800;
38213821
let l = (c as u32 - 0x10000) % 0x400 + 0xdc00;
38223822

3823-
let _ = write!(buf, "\\u{:04X}\\u{:04X}", h, l);
3823+
let _ = write!(buf, r#""\u{:04X}\u{:04X}""#, h, l);
38243824
} else {
38253825
let _ = write!(buf, "\\u{{{:04X}}}", c as u32);
38263826
}

‎crates/swc_ecma_minifier/tests/format.rs

+22
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,25 @@ console.log("</sCrIpT>");
8282
Config::default().with_inline_script(true).with_minify(true),
8383
)
8484
}
85+
86+
#[test]
87+
fn rspack_issue_4797() {
88+
let src = r#"
89+
obj = {
90+
𝒩: "a",
91+
"𝒩": "a",
92+
𝒩: "𝒩"
93+
}
94+
"#;
95+
assert_format(
96+
src,
97+
r#"obj = {
98+
"\uD835\uDCA9": "a",
99+
"\uD835\uDCA9": "a",
100+
"\uD835\uDCA9": "\uD835\uDCA9"
101+
};"#,
102+
Config::default()
103+
.with_ascii_only(true)
104+
.with_target(EsVersion::Es5),
105+
)
106+
}

0 commit comments

Comments
 (0)
Please sign in to comment.