Skip to content

Commit

Permalink
fix(es/codegen): Wrap quote for length greater than one (#8351)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Nov 29, 2023
1 parent 655e95a commit 2cdea3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3820,7 +3820,7 @@ fn get_ascii_only_ident(sym: &str, target: EsVersion) -> Cow<str> {
let h = ((c as u32 - 0x10000) / 0x400) + 0xd800;
let l = (c as u32 - 0x10000) % 0x400 + 0xdc00;

let _ = write!(buf, "\\u{:04X}\\u{:04X}", h, l);
let _ = write!(buf, r#""\u{:04X}\u{:04X}""#, h, l);
} else {
let _ = write!(buf, "\\u{{{:04X}}}", c as u32);
}
Expand Down
22 changes: 22 additions & 0 deletions crates/swc_ecma_minifier/tests/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,25 @@ console.log("</sCrIpT>");
Config::default().with_inline_script(true).with_minify(true),
)
}

#[test]
fn rspack_issue_4797() {
let src = r#"
obj = {
𝒩: "a",
"𝒩": "a",
𝒩: "𝒩"
}
"#;
assert_format(
src,
r#"obj = {
"\uD835\uDCA9": "a",
"\uD835\uDCA9": "a",
"\uD835\uDCA9": "\uD835\uDCA9"
};"#,
Config::default()
.with_ascii_only(true)
.with_target(EsVersion::Es5),
)
}

0 comments on commit 2cdea3f

Please sign in to comment.