Parse raw elements, attributes, and web components in rsx (#2655)

* parse raw elements and attributes in rsx

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
Evan AlmloffandJonathan Kelley authored and GitHub committed 2024-07-23 16:48:40 -07:00
1 parent fa4e5dbf62
commit 3bb9a535d8
6 files changed
+42 -9

No files matched your search

+16
View File
@@ -5,6 +5,11 @@ use internment::Intern;
use proc_macro2::TokenStream as TokenStream2;
use std::{fmt::Debug, hash::Hash};
use syn::{
ext::IdentExt,
parse::{Parse, ParseBuffer},
Ident,
};
/// interns a object into a static object, resusing the value if it already exists
#[cfg(feature = "hot_reload")]
@@ -27,3 +32,14 @@ impl PrettyUnparse for TokenStream2 {
prettier_please::unparse_expr(&parsed)
}
}
/// Parse a raw ident and return a new ident with the r# prefix added
pub fn parse_raw_ident(parse_buffer: &ParseBuffer) -> syn::Result<Ident> {
// First try to parse as a normal ident
if let Ok(ident) = Ident::parse(parse_buffer) {
return Ok(ident);
}
// If that fails, try to parse as a raw ident
let ident = Ident::parse_any(parse_buffer)?;
Ok(Ident::new_raw(&ident.to_string(), ident.span()))
}