Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
check ascii_only first
Browse files Browse the repository at this point in the history
ahaoboy committed Dec 26, 2024

Verified

This commit was signed with the committer’s verified signature.
erikmd Erik Martin-Dorel
1 parent 5821fd7 commit 6af9b46
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -4285,7 +4285,9 @@ fn get_quoted_utf16(v: &str, ascii_only: bool, target: EsVersion) -> String {
// to make sure we output unicode that is safe for the target
// Es5 does not support code point escapes and so surrograte formula must be
// used
if target <= EsVersion::Es5 {
if !ascii_only {
let _ = write!(buf, "{}", c);
} else if target <= EsVersion::Es5 {
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
let h = ((c as u32 - 0x10000) / 0x400) + 0xd800;
let l = (c as u32 - 0x10000) % 0x400 + 0xdc00;

0 comments on commit 6af9b46

Please sign in to comment.