pub(crate) fn gen(root: &SnaxItem, document: &Ident) -> Result<TokenStream, Error> {
    // We need to cast the outer most element appropriately.
    let ty_cast = match &root {
        SnaxItem::Tag(SnaxTag { name, ..})
            | SnaxItem::SelfClosingTag(SnaxSelfClosingTag { name, .. }) =>
        {
            if starts_lowercase(name) {
                let ty = TagInfo::from_name(&name)?.type_ident();
                quote! { .dyn_into::<::web_sys::#ty>().unwrap() }
            } else {
                // Components already return the correct type
                quote! {}
            }
        }

        // The expressions already evaluates to the correct type.
        SnaxItem::Fragment(_) => quote! {},
        SnaxItem::Content(_) => quote! {},
    };

    // Generate code for the root item and put it all together.
    let gen_code = gen_item(&root)?;
    let out = quote! {{
        use wasm_bindgen::{prelude::*, JsCast};
        use web_sys::{Document};
        use domsl::{
            specialization_hack::{
                AsStrKind, NodeKind, DisplayKind, IterDisplayKind, IterNodeKind, IterStrKind, Wrap,
            }
        };

        let #DOCUMENT_IDENT: &Document = &*&#document;

        #gen_code #ty_cast
    }};

    Ok(out)
}
/// The main entry point to generate the output code.
The main entry point to generate the output code.
The main entry point to generate the output code .
pub(crate) fn gen(root: &SnaxItem, document: &Ident) -> Result<TokenStream, Error> {
    // We need to cast the outer most element appropriately.
    let ty_cast = match &root {
        SnaxItem::Tag(SnaxTag { name, ..})
            | SnaxItem::SelfClosingTag(SnaxSelfClosingTag { name, .. }) =>
        {
            if starts_lowercase(name) {
                let ty = TagInfo::from_name(&name)?.type_ident();
                quote! { .dyn_into::<::web_sys::#ty>().unwrap() }
            } else {
                // Components already return the correct type
                quote! {}
            }
        }
        // The expressions already evaluates to the correct type.
        SnaxItem::Fragment(_) => quote! {},
        SnaxItem::Content(_) => quote! {},
    };
    // Generate code for the root item and put it all together.
    let gen_code = gen_item(&root)?;
    let out = quote! {{
        use wasm_bindgen::{prelude::*, JsCast};
        use web_sys::{Document};
        use domsl::{
            specialization_hack::{
                AsStrKind, NodeKind, DisplayKind, IterDisplayKind, IterNodeKind, IterStrKind, Wrap,
            }
        };
        let #DOCUMENT_IDENT: &Document = &*&#document;
        #gen_code #ty_cast
    }};
    Ok(out)
}
pub ( crate ) fn gen ( root : & SnaxItem , document : & Ident ) -> Result < TokenStream , Error > { // We need to cast the outer most element appropriately. let ty_cast = match & root { SnaxItem :: Tag ( SnaxTag { name , .. } ) | SnaxItem :: SelfClosingTag ( SnaxSelfClosingTag { name , .. } ) => { if starts_lowercase ( name ) { let ty = TagInfo :: from_name ( & name ) ? . type_ident ( ) ; quote ! { dyn_into web_sys ty ( ) unwrap ( ) } } else { // Components already return the correct type quote ! { } } } // The expressions already evaluates to the correct type. SnaxItem :: Fragment ( _ ) => quote ! { } , SnaxItem :: Content ( _ ) => quote ! { } , } ; // Generate code for the root item and put it all together. let gen_code = gen_item ( & root ) ? ; let out = quote ! { { use wasm_bindgen { prelude JsCast } use web_sys { Document } use domsl { specialization_hack { AsStrKind NodeKind DisplayKind IterDisplayKind IterNodeKind IterStrKind Wrap } } let DOCUMENT_IDENT Document document gen_code ty_cast } } ; Ok ( out ) }
The main entry point to generate the output code.
The main entry point to generate the output code .
root
&SnaxItem
document
&Ident
root
&SnaxItem
document
&Ident