feat(parse/tailwind): parse data attribute selectors as dedicated syntax#8514
feat(parse/tailwind): parse data attribute selectors as dedicated syntax#8514
Conversation
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
98f8dc3 to
c242dce
Compare
5d2ea90 to
cb0ce1b
Compare
cb0ce1b to
fdf01d6
Compare
c242dce to
c89cfe2
Compare
fdf01d6 to
77eeab3
Compare
Parser conformance results onjs/262
jsx/babel
symbols/microsoft
ts/babel
ts/microsoft
|
CodSpeed Performance ReportMerging #8514 will improve performances by 15.31%Comparing Summary
Benchmarks breakdown
Footnotes
|
WalkthroughThis PR introduces support for Tailwind data-attribute variants. The lexer is modified to detect and specially handle "data-" sequences by introducing a dedicated Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (8)
crates/biome_tailwind_factory/src/generated/node_factory.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_factory/src/generated/syntax_factory.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/data-attribute.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_parser/tests/tailwind_specs/ok/group-data.txt.snapis excluded by!**/*.snapand included by**crates/biome_tailwind_syntax/src/generated/kind.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_syntax/src/generated/macros.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_syntax/src/generated/nodes.rsis excluded by!**/generated/**,!**/generated/**and included by**crates/biome_tailwind_syntax/src/generated/nodes_mut.rsis excluded by!**/generated/**,!**/generated/**and included by**
📒 Files selected for processing (8)
crates/biome_tailwind_parser/src/lexer/mod.rs(3 hunks)crates/biome_tailwind_parser/src/syntax/value.rs(2 hunks)crates/biome_tailwind_parser/src/syntax/variant.rs(2 hunks)crates/biome_tailwind_parser/tests/quick_test.rs(1 hunks)crates/biome_tailwind_parser/tests/tailwind_specs/ok/data-attribute.txt(1 hunks)crates/biome_tailwind_parser/tests/tailwind_specs/ok/group-data.txt(1 hunks)xtask/codegen/src/tailwind_kinds_src.rs(2 hunks)xtask/codegen/tailwind.ungram(3 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
crates/**/*.rs
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Update inline rustdoc documentation for rules, assists, and their options when adding new features or changing existing features in Rust crates
Files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/tests/quick_test.rscrates/biome_tailwind_parser/src/lexer/mod.rscrates/biome_tailwind_parser/src/syntax/value.rs
🧠 Learnings (30)
📚 Learning: 2025-12-04T13:29:49.287Z
Learnt from: dyc3
Repo: biomejs/biome PR: 8291
File: crates/biome_html_formatter/tests/specs/prettier/vue/html-vue/elastic-header.html:10-10
Timestamp: 2025-12-04T13:29:49.287Z
Learning: Files under `crates/biome_html_formatter/tests/specs/prettier` are test fixtures synced from Prettier and should not receive detailed code quality reviews (e.g., HTTP vs HTTPS, formatting suggestions, etc.). These files are test data meant to validate formatter behavior and should be preserved as-is.
Applied to files:
crates/biome_tailwind_parser/tests/tailwind_specs/ok/group-data.txtcrates/biome_tailwind_parser/tests/quick_test.rscrates/biome_tailwind_parser/tests/tailwind_specs/ok/data-attribute.txt
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Use `p.eat(token)` for optional tokens, `p.expect(token)` for required tokens, `parse_rule(p).ok(p)` for optional nodes, and `parse_rule(p).or_add_diagnostic(p, error)` for required nodes
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/lexer/mod.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Parse rules must take a mutable reference to the parser as their only parameter and return a `ParsedSyntax`
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/language_kind.rs : Add a new variant to `LanguageKind` enum in `language_kind.rs` file and implement all methods for the new language variant
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Parse rule functions must be prefixed with `parse_` and use the name defined in the grammar file, e.g., `parse_for_statement` or `parse_expression`
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Use `ConditionalParsedSyntax` for syntax that is only valid in specific contexts (e.g., strict mode, file types, language versions) and call `or_invalid_to_bogus()` to convert to a bogus node if not supported
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/tests/quick_test.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Parse rules must return `ParsedSyntax::Absent` if the rule can't predict by the next token(s) if they form the expected node, and must not progress the parser in this case
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : A parser struct must implement the `Parser` trait and save the token source, parser context, and optional parser options
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/*.ungram : Nodes for enclosing syntax errors must have the `Bogus` word, e.g., `HtmlBogusAttribute`, and must be part of a variant
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Implement error recovery in list parsing using `or_recover()` to wrap unparseable tokens in a `BOGUS_*` node and consume tokens until a recovery token is found
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/lexer/mod.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Use `ParseSeparatedList` and `ParseNodeList` for parsing lists with error recovery to avoid infinite loops
Applied to files:
crates/biome_tailwind_parser/src/syntax/variant.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Lines prefixed with `#` in rule documentation code examples will be hidden from output
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Prefix line with `#` in documentation code examples sparingly; prefer concise complete snippets
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Assist rules should detect refactoring opportunities and emit code action signals
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Set rule severity to `info` or `warn` for rules in style group
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Set rule severity to `error` for rules in correctness, security, and a11y groups
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Avoid string allocations by comparing against `&str` or using `TokenText`
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rscrates/biome_tailwind_parser/src/lexer/mod.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/Cargo.toml : Include development dependencies in `Cargo.toml` for formatter tests: `biome_formatter_test`, `biome_<language>_factory`, `biome_<language>_parser`, `biome_parser`, `biome_service`, `countme`, `iai`, `quickcheck`, `quickcheck_macros`, and `tests_macros`
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/tests/language.rs : Implement `TestFormatLanguage` trait in `tests/language.rs` for the formatter's test language
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-11-24T18:05:20.371Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:20.371Z
Learning: Applies to crates/biome_formatter/**/biome_*_formatter/tests/spec_tests.rs : Use the `tests_macros::gen_tests!` macro in `spec_tests.rs` to generate test functions for each specification file matching the pattern `tests/specs/<language>/**/*.<ext>`
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Use `ignore` code block property to exclude documentation code examples from automatic validation
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Rule documentation code blocks should be ordered as language, expect_diagnostic, options/full_options/use_options, ignore, file
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/src/**/*.rs : Invalid code examples in rule documentation must be marked with `expect_diagnostic` code block property
Applied to files:
crates/biome_tailwind_parser/tests/quick_test.rs
📚 Learning: 2025-12-19T12:53:30.399Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-12-19T12:53:30.399Z
Learning: Applies to crates/biome_analyze/**/*analyze/tests/specs/**/*valid* : Create test files prefixed with `valid` for code that should not trigger the rule
Applied to files:
crates/biome_tailwind_parser/tests/tailwind_specs/ok/data-attribute.txt
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/lexer/mod.rs : Implement a `Lexer` trait from `biome_parser` crate for the lexer struct that consumes characters from source code and emits tokens
Applied to files:
crates/biome_tailwind_parser/src/lexer/mod.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:06:03.545Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_parser/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:06:03.545Z
Learning: Applies to crates/biome_parser/**/src/**/*.rs : Implement a token source struct that wraps the lexer and implements `TokenSourceWithBufferedLexer` and `LexerWithCheckpoint` for lookahead and re-lexing capabilities
Applied to files:
crates/biome_tailwind_parser/src/lexer/mod.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : When formatting AST nodes, use mandatory tokens from the AST instead of hardcoding token strings (e.g., use `node.l_paren_token().format()` instead of `token("(")`)
Applied to files:
crates/biome_tailwind_parser/src/lexer/mod.rscrates/biome_tailwind_parser/src/syntax/value.rs
📚 Learning: 2025-10-25T07:22:18.540Z
Learnt from: ematipico
Repo: biomejs/biome PR: 7852
File: crates/biome_css_parser/src/syntax/property/mod.rs:161-168
Timestamp: 2025-10-25T07:22:18.540Z
Learning: In the Biome CSS parser, lexer token emission should not be gated behind parser options like `is_tailwind_directives_enabled()`. The lexer must emit correct tokens regardless of parser options to enable accurate diagnostics and error messages when the syntax is used incorrectly.
Applied to files:
crates/biome_tailwind_parser/src/lexer/mod.rs
📚 Learning: 2025-11-24T18:05:42.356Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_type_info/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:42.356Z
Learning: Applies to crates/biome_js_type_info/**/*.rs : Distinguish between `TypeData::Unknown` and `TypeData::UnknownKeyword` to measure inference effectiveness versus explicit user-provided unknown types
Applied to files:
crates/biome_tailwind_parser/src/lexer/mod.rs
📚 Learning: 2025-11-24T18:05:27.810Z
Learnt from: CR
Repo: biomejs/biome PR: 0
File: crates/biome_js_formatter/CONTRIBUTING.md:0-0
Timestamp: 2025-11-24T18:05:27.810Z
Learning: Applies to crates/biome_js_formatter/**/*.rs : For tokens that are not mandatory, use helper functions instead of hardcoding
Applied to files:
crates/biome_tailwind_parser/src/lexer/mod.rs
🧬 Code graph analysis (2)
crates/biome_tailwind_parser/src/syntax/variant.rs (1)
crates/biome_tailwind_parser/src/syntax/value.rs (1)
parse_value(10-21)
crates/biome_tailwind_parser/src/syntax/value.rs (1)
crates/biome_tailwind_parser/src/syntax/variant.rs (1)
parse_data_attribute(142-153)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Test Node.js API
- GitHub Check: End-to-end tests
- GitHub Check: Parser conformance
- GitHub Check: autofix
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: Documentation
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Bench (biome_tailwind_parser)
🔇 Additional comments (15)
crates/biome_tailwind_parser/tests/tailwind_specs/ok/data-attribute.txt (1)
1-1: LGTM! Good test coverage for basic data-attribute variant.The test case exercises the new data-attribute parsing path with a straightforward example.
crates/biome_tailwind_parser/tests/tailwind_specs/ok/group-data.txt (1)
1-1: LGTM! Excellent test for the shadcn use case.This test case directly addresses the motivation mentioned in the PR for supporting patterns used by shadcn.
crates/biome_tailwind_parser/tests/quick_test.rs (1)
7-7: LGTM! Test input appropriately updated.The new test input exercises the data-attribute parsing path introduced in this PR.
xtask/codegen/src/tailwind_kinds_src.rs (2)
17-17: LGTM! Keyword addition aligns with lexer changes.The "data" keyword is now properly recognised for data-attribute variant parsing.
33-34: Partial implementation noted.The commented-out
TW_DATA_ATTRIBUTE_ARBITRARY_VALUEline (along with the TODO in tailwind.ungram) indicates this is a partial implementation. The current approach treats data-attribute arbitrary values as regular arbitrary values, which appears intentional for this initial implementation.crates/biome_tailwind_parser/src/syntax/value.rs (2)
2-2: LGTM! Import correctly added.The import enables value parsing to delegate to the data-attribute parser when encountering a data token.
17-19: LGTM! Data-attribute parsing path integrated correctly.The check for
T![data]appropriately delegates toparse_data_attributebefore falling back to named value parsing.crates/biome_tailwind_parser/src/syntax/variant.rs (1)
86-88: LGTM! Variant parsing correctly routes data attributes.The check for
T![data]appropriately delegates to the dedicated data-attribute parser.crates/biome_tailwind_parser/src/lexer/mod.rs (3)
48-48: LGTM! Dash handling correctly routes to data-attribute detection.The change enables special handling for "data-" sequences after a dash, which is essential for the lexer to recognise data-attribute variants.
133-137: LGTM! Keyword emission correctly handles "data".The lexer now emits
DATA_KWwhen it encounters a 4-byte base matching "data", enabling the parser to recognise data-attribute syntax.
160-176: LGTM! Clever implementation with good documentation.The
consume_after_dashmethod elegantly handles the "data-" detection after a dash. The comments clearly explain the behaviour: advancing past "data" and leaving the following dash to be emitted separately. Well done!xtask/codegen/tailwind.ungram (4)
103-107: LGTM! Grammar correctly extends variant union.The addition of
TwDataAttributetoAnyTwVariantproperly integrates data-attribute variants into the grammar.
133-137: LGTM! Grammar correctly extends value union.Including
TwDataAttributeinAnyTwValueallows data attributes to be used as values in functional candidates (e.g.,group-data-active).
168-181: LGTM! Grammar correctly defines data-attribute structure and prevents recursion.The definitions are well-structured:
TwDataAttributecorrectly requires the sequence'data' '-' valueAnyTwDataAttributeValueappropriately excludesTwDataAttributeitself, preventing recursive data-attribute nesting (e.g.,data-data-...)This matches the Tailwind specification and prevents parsing issues.
182-188: TODO noted for future refinement.The commented TODO suggests a future enhancement to parse data-attribute arbitrary values with key=value syntax (e.g.,
[state=open]). The current implementation treats these as regular arbitrary values, which appears intentional for this initial implementation.
| 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); | ||
|
|
||
| Present(m.complete(p, TW_DATA_ATTRIBUTE)) | ||
| } |
There was a problem hiding this comment.
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 parses AnyTwValue (including TwDataAttribute). However, the grammar defines AnyTwDataAttributeValue as:
AnyTwDataAttributeValue =
TwNamedValue |
TwArbitraryValue |
TwBogusValue
This creates infinite recursion for inputs like data-data-active:
- Parser sees
DATA_KW, callsparse_data_attribute - Bumps
data, expects-, callsparse_value parse_valueseesDATA_KWagain, callsparse_data_attribute- → Infinite recursion
The lexer will emit DATA_KW for "data" following a dash (via consume_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_value and parse_named_value crate-visible or move this helper into value.rs.
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In crates/biome_tailwind_parser/src/syntax/variant.rs around lines 142 to 153,
the current parse_data_attribute calls parse_value which includes
TwDataAttribute and leads to infinite recursion for inputs like
"data-data-active"; replace that call with a new function that implements the
grammar AnyTwDataAttributeValue = TwNamedValue | TwArbitraryValue | TwBogusValue
(e.g., parse_any_tw_data_attribute_value) that tries parse_named_value, then
parse_arbitrary_value, then produces a bogus value on failure; make
parse_named_value and parse_arbitrary_value crate-visible (pub(crate)) or move
the helper into value.rs so parse_data_attribute can call only this
non-recursive helper and avoid re-entering parse_data_attribute via parse_value.
…tax (biomejs#8514) <!-- IMPORTANT!! If you generated this PR with the help of any AI assistance, please disclose it in the PR. https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#ai-assistance-notice --> <!-- Thanks for submitting a Pull Request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your PR. Once created, your PR will be automatically labeled according to changed files. Learn more about contributing: https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md --> ## Summary <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve?--> Tailwind allows you to modify styles based on the presence of data attributes and the values assigned to them: https://tailwindcss.com/docs/hover-focus-and-other-states#data-attributes This partially implements dedicated parsing of these as their own syntax nodes. Though the reason I made this PR is to fix the parsing of samples like `group-data-[collapsible=icon]:hidden`, as shadcn commonly uses this pattern. <!-- Link any relevant issues if necessary or include a transcript of any Discord discussion. --> <!-- If you create a user-facing change, please write a changeset: https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#writing-a-changeset (your changeset is often a good starting point for this summary as well) --> ## Test Plan <!-- What demonstrates that your implementation is correct? --> snapshots ## Docs <!-- If you're submitting a new rule or action (or an option for them), the documentation is part of the code. Make sure rules and actions have example usages, and that all options are documented. --> <!-- For other features, please submit a documentation PR to the `next` branch of our website: https://github.com/biomejs/website/. Link the PR here once it's ready. -->
…tax (biomejs#8514) <!-- IMPORTANT!! If you generated this PR with the help of any AI assistance, please disclose it in the PR. https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#ai-assistance-notice --> <!-- Thanks for submitting a Pull Request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your PR. Once created, your PR will be automatically labeled according to changed files. Learn more about contributing: https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md --> ## Summary <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve?--> Tailwind allows you to modify styles based on the presence of data attributes and the values assigned to them: https://tailwindcss.com/docs/hover-focus-and-other-states#data-attributes This partially implements dedicated parsing of these as their own syntax nodes. Though the reason I made this PR is to fix the parsing of samples like `group-data-[collapsible=icon]:hidden`, as shadcn commonly uses this pattern. <!-- Link any relevant issues if necessary or include a transcript of any Discord discussion. --> <!-- If you create a user-facing change, please write a changeset: https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#writing-a-changeset (your changeset is often a good starting point for this summary as well) --> ## Test Plan <!-- What demonstrates that your implementation is correct? --> snapshots ## Docs <!-- If you're submitting a new rule or action (or an option for them), the documentation is part of the code. Make sure rules and actions have example usages, and that all options are documented. --> <!-- For other features, please submit a documentation PR to the `next` branch of our website: https://github.com/biomejs/website/. Link the PR here once it's ready. -->

Summary
Tailwind allows you to modify styles based on the presence of data attributes and the values assigned to them: https://tailwindcss.com/docs/hover-focus-and-other-states#data-attributes This partially implements dedicated parsing of these as their own syntax nodes. Though the reason I made this PR is to fix the parsing of samples like
group-data-[collapsible=icon]:hidden, as shadcn commonly uses this pattern.Test Plan
snapshots
Docs