diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index a052b64325fd5..567949256d029 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -143,6 +143,7 @@ fn unicode_escape() { test("console.log('こんにちは');", "console.log(\"こんにちは\");\n"); test("console.log('안녕하세요');", "console.log(\"안녕하세요\");\n"); test("console.log('🧑‍🤝‍🧑');", "console.log(\"🧑‍🤝‍🧑\");\n"); + test("console.log(\"\\uD800\\uD801\")", "console.log(\"\\uD800\\uD801\");\n"); } #[test] diff --git a/crates/oxc_parser/src/lexer/unicode.rs b/crates/oxc_parser/src/lexer/unicode.rs index dab7a096df828..e96269753da49 100644 --- a/crates/oxc_parser/src/lexer/unicode.rs +++ b/crates/oxc_parser/src/lexer/unicode.rs @@ -136,11 +136,9 @@ impl<'a> Lexer<'a> { self.token.lossy = true; } } - SurrogatePair::HighLow(high, low) => { - text.push_str("\\u"); - text.push_str(format!("{high:x}").as_str()); - text.push_str("\\u"); - text.push_str(format!("{low:x}").as_str()); + SurrogatePair::HighLow(_high, _low) => { + text.push_str("\u{FFFD}\u{FFFD}"); + self.token.lossy = true; } } }