-
-
Notifications
You must be signed in to change notification settings - Fork 928
feat(parse/tailwind): parse data attribute selectors as dedicated syntax #8514
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| data-active:text-red-500 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| --- | ||
| source: crates/biome_tailwind_parser/tests/spec_test.rs | ||
| expression: snapshot | ||
| --- | ||
| ## Input | ||
|
|
||
| ```text | ||
| data-active:text-red-500 | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ## AST | ||
|
|
||
| ``` | ||
| TwRoot { | ||
| bom_token: missing (optional), | ||
| candidates: TwCandidateList [ | ||
| TwFullCandidate { | ||
| variants: TwVariantList [ | ||
| TwDataAttribute { | ||
| data_token: DATA_KW@0..4 "data" [] [], | ||
| minus_token: DASH@4..5 "-" [] [], | ||
| value: TwNamedValue { | ||
| value_token: TW_VALUE@5..11 "active" [] [], | ||
| }, | ||
| }, | ||
| COLON@11..12 ":" [] [], | ||
| ], | ||
| negative_token: missing (optional), | ||
| candidate: TwFunctionalCandidate { | ||
| base_token: TW_BASE@12..16 "text" [] [], | ||
| minus_token: DASH@16..17 "-" [] [], | ||
| value: TwNamedValue { | ||
| value_token: TW_VALUE@17..24 "red-500" [] [], | ||
| }, | ||
| modifier: missing (optional), | ||
| }, | ||
| excl_token: missing (optional), | ||
| }, | ||
| ], | ||
| eof_token: EOF@24..25 "" [Newline("\n")] [], | ||
| } | ||
| ``` | ||
|
|
||
| ## CST | ||
|
|
||
| ``` | ||
| 0: TW_ROOT@0..25 | ||
| 0: (empty) | ||
| 1: TW_CANDIDATE_LIST@0..24 | ||
| 0: TW_FULL_CANDIDATE@0..24 | ||
| 0: TW_VARIANT_LIST@0..12 | ||
| 0: TW_DATA_ATTRIBUTE@0..11 | ||
| 0: DATA_KW@0..4 "data" [] [] | ||
| 1: DASH@4..5 "-" [] [] | ||
| 2: TW_NAMED_VALUE@5..11 | ||
| 0: TW_VALUE@5..11 "active" [] [] | ||
| 1: COLON@11..12 ":" [] [] | ||
| 1: (empty) | ||
| 2: TW_FUNCTIONAL_CANDIDATE@12..24 | ||
| 0: TW_BASE@12..16 "text" [] [] | ||
| 1: DASH@16..17 "-" [] [] | ||
| 2: TW_NAMED_VALUE@17..24 | ||
| 0: TW_VALUE@17..24 "red-500" [] [] | ||
| 3: (empty) | ||
| 3: (empty) | ||
| 2: EOF@24..25 "" [Newline("\n")] [] | ||
|
|
||
| ``` |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| group-data-[collapsible=icon]:hidden |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| --- | ||
| source: crates/biome_tailwind_parser/tests/spec_test.rs | ||
| expression: snapshot | ||
| --- | ||
| ## Input | ||
|
|
||
| ```text | ||
| group-data-[collapsible=icon]:hidden | ||
|
|
||
| ``` | ||
|
|
||
|
|
||
| ## AST | ||
|
|
||
| ``` | ||
| TwRoot { | ||
| bom_token: missing (optional), | ||
| candidates: TwCandidateList [ | ||
| TwFullCandidate { | ||
| variants: TwVariantList [ | ||
| TwFunctionalVariant { | ||
| base_token: TW_BASE@0..5 "group" [] [], | ||
| minus_token: DASH@5..6 "-" [] [], | ||
| value: TwDataAttribute { | ||
| data_token: DATA_KW@6..10 "data" [] [], | ||
| minus_token: DASH@10..11 "-" [] [], | ||
| value: TwArbitraryValue { | ||
| l_brack_token: L_BRACKET@11..12 "[" [] [], | ||
| value_token: TW_VALUE@12..28 "collapsible=icon" [] [], | ||
| r_brack_token: R_BRACKET@28..29 "]" [] [], | ||
| }, | ||
| }, | ||
| }, | ||
| COLON@29..30 ":" [] [], | ||
| ], | ||
| negative_token: missing (optional), | ||
| candidate: TwStaticCandidate { | ||
| base_token: TW_BASE@30..36 "hidden" [] [], | ||
| }, | ||
| excl_token: missing (optional), | ||
| }, | ||
| ], | ||
| eof_token: EOF@36..37 "" [Newline("\n")] [], | ||
| } | ||
| ``` | ||
|
|
||
| ## CST | ||
|
|
||
| ``` | ||
| 0: TW_ROOT@0..37 | ||
| 0: (empty) | ||
| 1: TW_CANDIDATE_LIST@0..36 | ||
| 0: TW_FULL_CANDIDATE@0..36 | ||
| 0: TW_VARIANT_LIST@0..30 | ||
| 0: TW_FUNCTIONAL_VARIANT@0..29 | ||
| 0: TW_BASE@0..5 "group" [] [] | ||
| 1: DASH@5..6 "-" [] [] | ||
| 2: TW_DATA_ATTRIBUTE@6..29 | ||
| 0: DATA_KW@6..10 "data" [] [] | ||
| 1: DASH@10..11 "-" [] [] | ||
| 2: TW_ARBITRARY_VALUE@11..29 | ||
| 0: L_BRACKET@11..12 "[" [] [] | ||
| 1: TW_VALUE@12..28 "collapsible=icon" [] [] | ||
| 2: R_BRACKET@28..29 "]" [] [] | ||
| 1: COLON@29..30 ":" [] [] | ||
| 1: (empty) | ||
| 2: TW_STATIC_CANDIDATE@30..36 | ||
| 0: TW_BASE@30..36 "hidden" [] [] | ||
| 3: (empty) | ||
| 2: EOF@36..37 "" [Newline("\n")] [] | ||
|
|
||
| ``` |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical: Fix recursion bug by implementing separate parse function for AnyTwDataAttributeValue.
The implementation doesn't match the grammar specification. Line 150 calls
parse_value, which parsesAnyTwValue(includingTwDataAttribute). However, the grammar definesAnyTwDataAttributeValueas:This creates infinite recursion for inputs like
data-data-active:DATA_KW, callsparse_data_attributedata, expects-, callsparse_valueparse_valueseesDATA_KWagain, callsparse_data_attributeThe lexer will emit
DATA_KWfor "data" following a dash (viaconsume_after_dash), enabling this recursion.🔎 Recommended fix
Implement a separate parsing function that matches the grammar:
pub(crate) fn parse_data_attribute(p: &mut TailwindParser) -> ParsedSyntax { if !p.at(T![data]) { return Absent; } let m = p.start(); p.bump(T![data]); p.expect(T![-]); - parse_value(p).or_add_diagnostic(p, expected_value); + parse_data_attribute_value(p).or_add_diagnostic(p, expected_value); Present(m.complete(p, TW_DATA_ATTRIBUTE)) } + +fn parse_data_attribute_value(p: &mut TailwindParser) -> ParsedSyntax { + if p.at(T!['[']) { + return parse_arbitrary_value(p); + } + parse_named_value(p) +}You'll need to make
parse_arbitrary_valueandparse_named_valuecrate-visible or move this helper into value.rs.🤖 Prompt for AI Agents