Skip to content

Commit 3485179

Browse files
authored
fix(atoms): Fix broken quote macro (#11195)
**Description:** This PR fixes a regression of `quote!` macro caused by #11144
1 parent f27e65b commit 3485179

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

.changeset/fuzzy-bobcats-return.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
swc_core: patch
3+
swc_atoms: patch
4+
swc_ecma_quote_macros: patch
5+
---
6+
7+
chore(atoms): Fix broken quote macro

crates/swc_atoms/src/wtf8_atom.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ impl Wtf8Atom {
7979
pub fn try_into_atom(self) -> Result<Atom, Wtf8Atom> {
8080
self.0.try_into_atom().map(Atom).map_err(Wtf8Atom)
8181
}
82+
83+
/// Creates a new [Wtf8Atom] from a byte slice.
84+
///
85+
/// # Safety
86+
///
87+
/// The caller must ensure that `bytes` is a well-formed WTF-8 byte
88+
/// sequence.
89+
///
90+
/// See [hstr::wtf8::Wtf8::from_bytes_unchecked] for more details.
91+
pub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> Self {
92+
Wtf8Atom(hstr::Wtf8Atom::from(
93+
hstr::wtf8::Wtf8::from_bytes_unchecked(bytes),
94+
))
95+
}
8296
}
8397

8498
impl Deref for Wtf8Atom {

crates/swc_ecma_quote_macros/src/ast/lit.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ impl ToCode for Atom {
4141
impl ToCode for Wtf8Atom {
4242
fn to_code(&self, _: &Ctx) -> syn::Expr {
4343
let bytes_literal = LitByteStr::new(self.as_bytes(), Span::call_site());
44-
parse_quote!(swc_atoms::wtf8::Wtf8Atom::from(unsafe {
45-
swc_atoms::wtf8::Wtf8::from_bytes_unchecked(#bytes_literal)
46-
}))
44+
parse_quote!(unsafe { swc_atoms::Wtf8Atom::from_bytes_unchecked(#bytes_literal) })
4745
}
4846
}
4947

0 commit comments

Comments
 (0)