wip: refactor out translation into its own crate
This commit is contained in:
1 parent
4aac2cdae1
commit
14bc007c15
9 files changed
+153
-2
No files matched your search
@@ -0,0 +1,24 @@
|
||||
use std::hash::Hash;
|
||||
|
||||
use proc_macro2::Span;
|
||||
|
||||
// A form of whitespace
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct UserComment {
|
||||
pub span: Span,
|
||||
pub comment: String,
|
||||
}
|
||||
|
||||
impl PartialEq for UserComment {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.comment == other.comment
|
||||
}
|
||||
}
|
||||
|
||||
impl Eq for UserComment {}
|
||||
|
||||
impl Hash for UserComment {
|
||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||
self.comment.hash(state);
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#[macro_use]
|
||||
mod errors;
|
||||
mod comments;
|
||||
mod component;
|
||||
mod element;
|
||||
pub mod hot_reload;
|
||||
@@ -296,6 +297,8 @@ impl DynamicMapping {
|
||||
|
||||
BodyNode::Text(text) if text.is_static() => {}
|
||||
|
||||
BodyNode::Comment(_) => {}
|
||||
|
||||
BodyNode::RawExpr(_)
|
||||
| BodyNode::Text(_)
|
||||
| BodyNode::ForLoop(_)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
use crate::comments::UserComment;
|
||||
|
||||
use super::*;
|
||||
|
||||
use proc_macro2::{Span, TokenStream as TokenStream2};
|
||||
@@ -16,6 +18,17 @@ Parse
|
||||
-> component()
|
||||
-> "text {with_args}"
|
||||
-> (0..10).map(|f| rsx!("asd")), // <--- notice the comma - must be a complete expr
|
||||
-> // some comment here (no support for slash asterisk comments - those get deleted completely)
|
||||
|
||||
|
||||
|
||||
div {
|
||||
// Comment
|
||||
div { // a comment here because it shares the line
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
#[derive(PartialEq, Eq, Clone, Debug, Hash)]
|
||||
pub enum BodyNode {
|
||||
@@ -25,6 +38,7 @@ pub enum BodyNode {
|
||||
IfChain(ExprIf),
|
||||
Text(IfmtInput),
|
||||
RawExpr(Expr),
|
||||
Comment(UserComment),
|
||||
}
|
||||
|
||||
impl BodyNode {
|
||||
@@ -40,6 +54,7 @@ impl BodyNode {
|
||||
BodyNode::RawExpr(exp) => exp.span(),
|
||||
BodyNode::ForLoop(fl) => fl.for_token.span(),
|
||||
BodyNode::IfChain(f) => f.if_token.span(),
|
||||
BodyNode::Comment(c) => c.span,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,6 +143,7 @@ impl Parse for BodyNode {
|
||||
impl ToTokens for BodyNode {
|
||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||
match &self {
|
||||
BodyNode::Comment(_) => {}
|
||||
BodyNode::Element(el) => el.to_tokens(tokens),
|
||||
BodyNode::Component(comp) => comp.to_tokens(tokens),
|
||||
BodyNode::Text(txt) => tokens.append_all(quote! {
|
||||
|
||||
Reference in new issue
Block a user