From 35d0ba1fa61f9fe24aca42cae84495d3f5b210c8 Mon Sep 17 00:00:00 2001 From: Casper Date: Thu, 16 Apr 2026 22:11:28 +0200 Subject: [PATCH] Extend parser to support Vue style attribute shorthands --- src/grammar/rules.pest | 3 ++- tests/element_attributes.rs | 9 +++++++++ ...an_parse_vue_style_attribute_shorthand.snap | 18 ++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 tests/snapshots/element_attributes__it_can_parse_vue_style_attribute_shorthand.snap diff --git a/src/grammar/rules.pest b/src/grammar/rules.pest index 3d91f3a..c4fbffd 100644 --- a/src/grammar/rules.pest +++ b/src/grammar/rules.pest @@ -42,7 +42,8 @@ comment_if_end = _{ chevron_left_bang ~ "[" ~ ^"endif" ~ "]" ~ comment_tag_end } attr = { attr_key ~ (equal ~ WSP* ~ (attr_non_quoted | attr_quoted ))? } attr_quoted = ${PUSH(quote) ~ attr_value ~ POP } attr_non_quoted = @{ !quote ~ (!(WSP | chevron_right) ~ ANY)* } -attr_key = { WSP* ~ ASCII_ALPHA ~ text_chars* ~ WSP* } +attr_key = { WSP* ~ attr_key_start ~ text_chars* ~ WSP* } +attr_key_start = _{ ASCII_ALPHA | "@" | ":" } attr_value = { WSP* ~ (!PEEK ~ ANY)* ~ WSP* } // diff --git a/tests/element_attributes.rs b/tests/element_attributes.rs index 2994111..bd2a3f9 100644 --- a/tests/element_attributes.rs +++ b/tests/element_attributes.rs @@ -29,6 +29,15 @@ fn it_can_parse_attribute_key_mixed_case_symbols() -> Result<()> { assert_json_snapshot!(dom); Ok(()) } + +#[test] +fn it_can_parse_vue_style_attribute_shorthand() -> Result<()> { + let html = ""; + let dom = Dom::parse(html)?; + assert_json_snapshot!(dom); + Ok(()) +} + #[test] fn it_can_parse_multiple_attributes_single_quote() -> Result<()> { let html = "
"; diff --git a/tests/snapshots/element_attributes__it_can_parse_vue_style_attribute_shorthand.snap b/tests/snapshots/element_attributes__it_can_parse_vue_style_attribute_shorthand.snap new file mode 100644 index 0000000..eb9cf98 --- /dev/null +++ b/tests/snapshots/element_attributes__it_can_parse_vue_style_attribute_shorthand.snap @@ -0,0 +1,18 @@ +--- +source: tests/element_attributes.rs +assertion_line: 37 +expression: dom +--- +{ + "treeType": "documentFragment", + "children": [ + { + "name": "vue-style", + "variant": "normal", + "attributes": { + ":bindings": "are_not_supported", + "@attributes": "or" + } + } + ] +}