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

Support for attributes w/ a dash #197

Closed
wants to merge 1 commit into from

Conversation

sherodtaylor
Copy link

@sherodtaylor sherodtaylor commented May 23, 2024

My attempt at issue #105

@sherodtaylor sherodtaylor changed the title update to have tags Support for attributes w/ a dash May 23, 2024
@sherodtaylor
Copy link
Author

sherodtaylor commented May 23, 2024

I'm kind of stuck debugging the macro

simple output RUSTFLAGS="-Zproc-macro-backtrace" cargo test

  Compiling html-macro-test v0.1.0 (/Users/staylor279/code/percy/crates/html-macro-test)
warning: `percy-dom` (lib) generated 1 warning
thread '<unnamed>' panicked at library/proc_macro/src/bridge/symbol.rs:52:29:
`"hx-trigger"` is not a valid identifier
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: proc macro panicked
  --> crates/html-macro-test/src/tests/all_tests.rs:35:20
   |
35 |         generated: html! { <a hx-trigger="click"></a> },
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = help: message: `"hx-trigger"` is not a valid identifier	

Output with backtrace RUST_BACKTRACE=full RUSTFLAGS="-Zproc-macro-backtrace" cargo test

warning: `percy-dom` (lib) generated 1 warning
   Compiling html-macro-test v0.1.0 (/Users/staylor279/code/percy/crates/html-macro-test)
thread '<unnamed>' panicked at library/proc_macro/src/bridge/symbol.rs:52:29:
`"hx-trigger"` is not a valid identifier
stack backtrace:
   0:        0x107565080 - std::backtrace_rs::backtrace::libunwind::trace::h7e181c7a01a98ba9
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:        0x107565080 - std::backtrace_rs::backtrace::trace_unsynchronized::h5d1f48c6edc00030
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:        0x107565080 - std::sys_common::backtrace::_print_fmt::h9f3c4567c93cd78e
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/sys_common/backtrace.rs:68:5
   3:        0x107565080 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h4e8451aa4ebfb5ff
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/sys_common/backtrace.rs:44:22
   4:        0x10757a81c - core::fmt::rt::Argument::fmt::h5e5019a892b695bd
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/core/src/fmt/rt.rs:165:63
   5:        0x10757a81c - core::fmt::write::hf3884bd029f6cc35
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/core/src/fmt/mod.rs:1169:21
   6:        0x1075634a8 - std::io::Write::write_fmt::hed661a84cebe2dd6
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/io/mod.rs:1835:15
   7:        0x107564ed8 - std::sys_common::backtrace::_print::h94d3b0f42a22c797
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/sys_common/backtrace.rs:47:5
   8:        0x107564ed8 - std::sys_common::backtrace::print::hbc3a91e400ee844d
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/sys_common/backtrace.rs:34:9
   9:        0x107566344 - std::panicking::default_hook::{{closure}}::h9004021f8ce24a60
  10:        0x107566038 - std::panicking::default_hook::h0b8973d6357e258c
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/panicking.rs:298:9
  11:        0x107566c28 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::ha26f26fdcc1a8e51
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/alloc/src/boxed.rs:2077:9
  12:        0x107566c28 - std::panicking::rust_panic_with_hook::h9d0b6287353b54cc
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/panicking.rs:799:13
  13:        0x10756662c - std::panicking::begin_panic_handler::{{closure}}::h340df470dcd2c831
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/panicking.rs:664:13
  14:        0x107565504 - std::sys_common::backtrace::__rust_end_short_backtrace::h3f752db9a2187ac2
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/sys_common/backtrace.rs:171:18
  15:        0x10756639c - rust_begin_unwind
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/std/src/panicking.rs:652:5
  16:        0x107582a84 - core::panicking::panic_fmt::h61cb4c084dcf0edf
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/core/src/panicking.rs:72:14
  17:        0x10754753c - proc_macro::bridge::symbol::Symbol::new_ident::{{closure}}::h382bd6685f2962cb
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/proc_macro/src/bridge/symbol.rs:52:29
  18:        0x10754753c - core::result::Result<T,E>::unwrap_or_else::h23d9065fadf788fa
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/core/src/result.rs:1435:23
  19:        0x10754753c - proc_macro::bridge::symbol::Symbol::new_ident::h64348c27ad4aeaf9
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/proc_macro/src/bridge/symbol.rs:52:10
  20:        0x107549a94 - proc_macro::Ident::new::h9d524309f43d1a1e
                               at /rustc/791adf759cc065316f054961875052d5bc03e16c/library/proc_macro/src/lib.rs:1091:18
  21:        0x107533f34 - proc_macro2::imp::Ident::new_checked::h191ea521e506cb1e
  22:        0x107539618 - proc_macro2::Ident::new::hf5ce127e01445872
  23:        0x10743f140 - html_macro::tag::parse_ident_or_keyword::habdd721817b2fe60

@chinedufn
Copy link
Owner

You can try adding a test case to this list. That should help with being able to more easily figure out what's going on

/// Verify that we can parse opening tags.
///
/// ## Testing Approach
/// - Iterate over macro tokens
/// - Assert that the `Tag::Open` has the expected name, such as "div".
/// - Assert that the `Tag::Open` is detected as self-closing, such as with "<br />".
/// - Assert that the `Tag::Open` has the expected attributes, such as "<div id="hello">.
#[test]
fn open_tag_tests() {
let tests = [
// Verify that we can parse an open tag that does not have any attributes.
(
quote! { <div> },
ExpectedTag {
name: "div",
attributes: vec![],
is_self_closing: false,
}
),
// Verify that we can parse a self-closing open tag that does not have any attributes.
(
quote! { <br /> },
ExpectedTag {
name: "br",
attributes: vec![],
is_self_closing: true,
}
),
// Verify that we can parse an open tag that has one attribute.
(
quote! { <div id="hello"> },
ExpectedTag {
name: "div",
attributes: vec![("id", "hello")],
is_self_closing: false,
},
)
];

Let me know if I can help. I haven't looked at your diff yet.

Also, please update the PR body with an example of what this PR makes possible.

Something like:


For example, the following is now possible:

html! {
    <div aria-disabled="true"></div>
}

Please also update your PR body to start with "This commit ...".

As in, a brief explanation of what this PR does.

@chinedufn
Copy link
Owner

Closing in favor of #199

@chinedufn chinedufn closed this Jun 3, 2024
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

Successfully merging this pull request may close these issues.

2 participants