mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
fix(str): fix hygiene of format_ident! and format_str! macros (#24886)
Avoid `use` statements in these macros, to avoid naming clashes with the user-provided input.
This commit is contained in:
1 parent
4d6f623cda
commit
e7d5c7801d
2 files changed
+6
-12
No files matched your search
@@ -603,12 +603,9 @@ macro_rules! static_ident {
|
||||
#[macro_export]
|
||||
macro_rules! format_ident {
|
||||
($alloc:expr, $($arg:tt)*) => {{
|
||||
use ::std::{write, fmt::Write};
|
||||
use $crate::{Ident, __internal::ArenaStringBuilder};
|
||||
|
||||
let mut s = ArenaStringBuilder::new_in($alloc);
|
||||
write!(s, $($arg)*).unwrap();
|
||||
Ident::from(s)
|
||||
let mut s = $crate::__internal::ArenaStringBuilder::new_in($alloc);
|
||||
::std::fmt::Write::write_fmt(&mut s, ::std::format_args!($($arg)*)).unwrap();
|
||||
$crate::Ident::from(s)
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
@@ -334,12 +334,9 @@ impl ESTree for Str<'_> {
|
||||
#[macro_export]
|
||||
macro_rules! format_str {
|
||||
($alloc:expr, $($arg:tt)*) => {{
|
||||
use ::std::{write, fmt::Write};
|
||||
use $crate::{Str, __internal::ArenaStringBuilder};
|
||||
|
||||
let mut s = ArenaStringBuilder::new_in($alloc);
|
||||
write!(s, $($arg)*).unwrap();
|
||||
Str::from(s)
|
||||
let mut s = $crate::__internal::ArenaStringBuilder::new_in($alloc);
|
||||
::std::fmt::Write::write_fmt(&mut s, ::std::format_args!($($arg)*)).unwrap();
|
||||
$crate::Str::from(s)
|
||||
}}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user