@@ -3871,7 +3871,12 @@ fn get_ascii_only_ident(sym: &str, may_need_quote: bool, target: EsVersion) -> C
3871
3871
while let Some ( c) = iter. next ( ) {
3872
3872
match c {
3873
3873
'\x00' => {
3874
- buf. push_str ( "\\ x00" ) ;
3874
+ if may_need_quote {
3875
+ need_quote = true ;
3876
+ let _ = write ! ( buf, "\\ x00" ) ;
3877
+ } else {
3878
+ let _ = write ! ( buf, "\\ u0000" ) ;
3879
+ }
3875
3880
}
3876
3881
'\u{0008}' => buf. push_str ( "\\ b" ) ,
3877
3882
'\u{000c}' => buf. push_str ( "\\ f" ) ,
@@ -3959,20 +3964,31 @@ fn get_ascii_only_ident(sym: &str, may_need_quote: bool, target: EsVersion) -> C
3959
3964
buf. push ( '"' ) ;
3960
3965
}
3961
3966
'\x01' ..='\x0f' if !first => {
3962
- let _ = write ! ( buf, "\\ x0{:x}" , c as u8 ) ;
3967
+ if may_need_quote {
3968
+ need_quote = true ;
3969
+ let _ = write ! ( buf, "\\ x{:x}" , c as u8 ) ;
3970
+ } else {
3971
+ let _ = write ! ( buf, "\\ u00{:x}" , c as u8 ) ;
3972
+ }
3963
3973
}
3964
3974
'\x10' ..='\x1f' if !first => {
3965
- let _ = write ! ( buf, "\\ x{:x}" , c as u8 ) ;
3975
+ if may_need_quote {
3976
+ need_quote = true ;
3977
+ let _ = write ! ( buf, "\\ x{:x}" , c as u8 ) ;
3978
+ } else {
3979
+ let _ = write ! ( buf, "\\ u00{:x}" , c as u8 ) ;
3980
+ }
3966
3981
}
3967
3982
'\x20' ..='\x7e' => {
3968
3983
buf. push ( c) ;
3969
3984
}
3970
3985
'\u{7f}' ..='\u{ff}' => {
3971
3986
if may_need_quote {
3972
3987
need_quote = true ;
3988
+ let _ = write ! ( buf, "\\ x{:x}" , c as u8 ) ;
3989
+ } else {
3990
+ let _ = write ! ( buf, "\\ u00{:x}" , c as u8 ) ;
3973
3991
}
3974
-
3975
- let _ = write ! ( buf, "\\ x{:x}" , c as u8 ) ;
3976
3992
}
3977
3993
'\u{2028}' => {
3978
3994
buf. push_str ( "\\ u2028" ) ;
0 commit comments