Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error message on html! macro with multiple roots #21

Open
derekdreery opened this issue Nov 29, 2018 · 3 comments
Open

Error message on html! macro with multiple roots #21

derekdreery opened this issue Nov 29, 2018 · 3 comments

Comments

@derekdreery
Copy link
Contributor

If you do

html!(
  <div>"First element"</div>
  <div>"Illegal second element"</div>
)

you get

error: proc-macro derive panicked
   --> src/views.rs:122:5
    |
122 | /     html!(
123 | |         <div class="prices-table-title" id="products-cupcakes">"cupcakes"</div>
124 | |         <div class="prices-image" id="cookies-cream-cupcakes">""</div>
125 | |         <div class="prices-table">
...   |
134 | |             <br/>"Trial flavours available upon request"</div>
135 | |     )
    | |_____^
    |
    = help: message: index out of bounds: the len is 0 but the index is 0
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Maybe the panic could say "all invocations of the html! macro must have exactly 1 root element".

@derekdreery
Copy link
Contributor Author

^^ You don't get that exact error - I copied it from a trial website I'm making :'D

@bodil
Copy link
Owner

bodil commented Nov 30, 2018

I'm wondering if I should try and get it to actually accept this and return an iterator of elements - like, there's the <> syntax for this sort of thing in JSX (#18) but that's strictly just to tell the JS parser that a JSX block is starting, but the macro invocation serves that purpose here.

@derekdreery
Copy link
Contributor Author

That would be awesome, currently I'm doing something like

fn view_fn() -> Vec<Box<dyn Node>> {
    return vec![
        html!(<p>"Part one"</p>),
        html!(<p>"Part two"</p>),
    ];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants