fix formatting with raw elements
This commit is contained in:
1 parent
03413a68ab
commit
f74854b38c
2 files changed
+16
-5
No files matched your search
@@ -7,6 +7,7 @@ use quote::{quote, ToTokens, TokenStreamExt};
|
|||||||
use syn::{
|
use syn::{
|
||||||
parse::{Parse, ParseBuffer, ParseStream},
|
parse::{Parse, ParseBuffer, ParseStream},
|
||||||
punctuated::Punctuated,
|
punctuated::Punctuated,
|
||||||
|
spanned::Spanned,
|
||||||
Error, Expr, Ident, LitStr, Result, Token,
|
Error, Expr, Ident, LitStr, Result, Token,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -197,7 +198,7 @@ impl ToTokens for Element {
|
|||||||
#[derive(PartialEq, Eq, Clone, Debug, Hash)]
|
#[derive(PartialEq, Eq, Clone, Debug, Hash)]
|
||||||
pub enum ElementName {
|
pub enum ElementName {
|
||||||
Ident(Ident),
|
Ident(Ident),
|
||||||
Custom(String),
|
Custom(LitStr),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ElementName {
|
impl ElementName {
|
||||||
@@ -209,11 +210,20 @@ impl ElementName {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ElementName {
|
||||||
|
pub fn span(&self) -> Span {
|
||||||
|
match self {
|
||||||
|
ElementName::Ident(i) => i.span(),
|
||||||
|
ElementName::Custom(s) => s.span(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PartialEq<&str> for ElementName {
|
impl PartialEq<&str> for ElementName {
|
||||||
fn eq(&self, other: &&str) -> bool {
|
fn eq(&self, other: &&str) -> bool {
|
||||||
match self {
|
match self {
|
||||||
ElementName::Ident(i) => i == *other,
|
ElementName::Ident(i) => i == *other,
|
||||||
ElementName::Custom(s) => s == *other,
|
ElementName::Custom(s) => s.value() == *other,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,7 +232,7 @@ impl Display for ElementName {
|
|||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
ElementName::Ident(i) => write!(f, "{}", i),
|
ElementName::Ident(i) => write!(f, "{}", i),
|
||||||
ElementName::Custom(s) => write!(f, "{}", s),
|
ElementName::Custom(s) => write!(f, "{}", s.value()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,11 +243,13 @@ impl Parse for ElementName {
|
|||||||
if raw.len() == 1 {
|
if raw.len() == 1 {
|
||||||
Ok(ElementName::Ident(raw.into_iter().next().unwrap()))
|
Ok(ElementName::Ident(raw.into_iter().next().unwrap()))
|
||||||
} else {
|
} else {
|
||||||
|
let span = raw.span();
|
||||||
let tag = raw
|
let tag = raw
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|ident| ident.to_string())
|
.map(|ident| ident.to_string())
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.join("-");
|
.join("-");
|
||||||
|
let tag = LitStr::new(&tag, span);
|
||||||
Ok(ElementName::Custom(tag))
|
Ok(ElementName::Custom(tag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ impl Parse for BodyNode {
|
|||||||
// if this is a dash-separated path, it's a web component (custom element)
|
// if this is a dash-separated path, it's a web component (custom element)
|
||||||
let body_stream = stream.fork();
|
let body_stream = stream.fork();
|
||||||
if let Ok(ElementName::Custom(name)) = body_stream.parse::<ElementName>() {
|
if let Ok(ElementName::Custom(name)) = body_stream.parse::<ElementName>() {
|
||||||
println!("name: {}", name);
|
if name.value().contains('-') && body_stream.peek(token::Brace) {
|
||||||
if name.contains('-') && body_stream.peek(token::Brace) {
|
|
||||||
return Ok(BodyNode::Element(stream.parse::<Element>()?));
|
return Ok(BodyNode::Element(stream.parse::<Element>()?));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user