Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/some-walls-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed [#7913](https://github.com/biomejs/biome/issues/7913): The CSS parser, with `tailwindDirectives` enabled, will now correctly handle `@slot`.
9 changes: 9 additions & 0 deletions crates/biome_css_factory/src/generated/node_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions crates/biome_css_factory/src/generated/syntax_factory.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/css/any/at_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl FormatRule<AnyCssAtRule> for FormatAnyCssAtRule {
AnyCssAtRule::TwCustomVariantAtRule(node) => node.format().fmt(f),
AnyCssAtRule::TwPluginAtRule(node) => node.format().fmt(f),
AnyCssAtRule::TwReferenceAtRule(node) => node.format().fmt(f),
AnyCssAtRule::TwSlotAtRule(node) => node.format().fmt(f),
AnyCssAtRule::TwSourceAtRule(node) => node.format().fmt(f),
AnyCssAtRule::TwThemeAtRule(node) => node.format().fmt(f),
AnyCssAtRule::TwUtilityAtRule(node) => node.format().fmt(f),
Expand Down
34 changes: 34 additions & 0 deletions crates/biome_css_formatter/src/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5750,6 +5750,40 @@ impl IntoFormat<CssFormatContext> for biome_css_syntax::TwReferenceAtRule {
)
}
}
impl FormatRule<biome_css_syntax::TwSlotAtRule>
for crate::tailwind::statements::slot_at_rule::FormatTwSlotAtRule
{
type Context = CssFormatContext;
#[inline(always)]
fn fmt(&self, node: &biome_css_syntax::TwSlotAtRule, f: &mut CssFormatter) -> FormatResult<()> {
FormatNodeRule::<biome_css_syntax::TwSlotAtRule>::fmt(self, node, f)
}
}
impl AsFormat<CssFormatContext> for biome_css_syntax::TwSlotAtRule {
type Format<'a> = FormatRefWithRule<
'a,
biome_css_syntax::TwSlotAtRule,
crate::tailwind::statements::slot_at_rule::FormatTwSlotAtRule,
>;
fn format(&self) -> Self::Format<'_> {
FormatRefWithRule::new(
self,
crate::tailwind::statements::slot_at_rule::FormatTwSlotAtRule::default(),
)
}
}
impl IntoFormat<CssFormatContext> for biome_css_syntax::TwSlotAtRule {
type Format = FormatOwnedWithRule<
biome_css_syntax::TwSlotAtRule,
crate::tailwind::statements::slot_at_rule::FormatTwSlotAtRule,
>;
fn into_format(self) -> Self::Format {
FormatOwnedWithRule::new(
self,
crate::tailwind::statements::slot_at_rule::FormatTwSlotAtRule::default(),
)
}
}
Comment on lines +5753 to +5786
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

🧩 Analysis chain

Solid wiring for @slot — formatter glue matches the house style.

Impls for FormatRule, AsFormat, and IntoFormat mirror neighbouring Tailwind at‑rules. Ordering alongside TwReference/TwSource also looks tidy. Nice one.

Run a quick cross‑check to ensure the rule type exists and the module is exported:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Formatter rule type present?
rg -nS "FormatTwSlotAtRule" crates -C2

# Syntax node present?
rg -nS "\bTwSlotAtRule\b" crates -C3

# Module wired in tailwind statements?
rg -nS "mod\s+slot_at_rule|pub\(crate\)\s+mod\s+slot_at_rule" crates/biome_css_formatter/src/tailwind/statements -C1

Length of output: 23745


Verification passed—all three checks confirmed.

FormatTwSlotAtRule is properly defined, TwSlotAtRule syntax node exists throughout the crate, and the module is correctly exported at crates/biome_css_formatter/src/tailwind/statements/mod.rs. The generated.rs impls wire up cleanly alongside sibling Tailwind at-rules.

One remaining item per coding guidelines: add inline rustdoc to crates/biome_css_formatter/src/tailwind/statements/slot_at_rule.rs to document what FormatTwSlotAtRule does.

🤖 Prompt for AI Agents
crates/biome_css_formatter/src/generated.rs lines 5753-5786: add an inline
rustdoc comment in
crates/biome_css_formatter/src/tailwind/statements/slot_at_rule.rs for the
FormatTwSlotAtRule type explaining its purpose and behavior; specifically, place
a /// doc comment immediately above the FormatTwSlotAtRule definition that
concisely states that it formats TwSlotAtRule Tailwind at-rules into the crate's
CSS output, notes any important formatting behaviors or context types used
(CssFormatContext), and optionally gives a short usage example or reference to
the generated impls; keep the comment brief and idiomatic Rust doc style.

impl FormatRule<biome_css_syntax::TwSourceAtRule>
for crate::tailwind::statements::source_at_rule::FormatTwSourceAtRule
{
Expand Down
1 change: 1 addition & 0 deletions crates/biome_css_formatter/src/tailwind/statements/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub(crate) mod config_at_rule;
pub(crate) mod custom_variant_at_rule;
pub(crate) mod plugin_at_rule;
pub(crate) mod reference_at_rule;
pub(crate) mod slot_at_rule;
pub(crate) mod source_at_rule;
pub(crate) mod theme_at_rule;
pub(crate) mod utility_at_rule;
Expand Down
16 changes: 16 additions & 0 deletions crates/biome_css_formatter/src/tailwind/statements/slot_at_rule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use crate::prelude::*;
use biome_css_syntax::{TwSlotAtRule, TwSlotAtRuleFields};
use biome_formatter::write;

#[derive(Debug, Clone, Default)]
pub(crate) struct FormatTwSlotAtRule;
impl FormatNodeRule<TwSlotAtRule> for FormatTwSlotAtRule {
fn fmt_fields(&self, node: &TwSlotAtRule, f: &mut CssFormatter) -> FormatResult<()> {
let TwSlotAtRuleFields {
slot_token,
semicolon_token,
} = node.as_fields();

write!(f, [slot_token.format(), semicolon_token.format()])
}
}
1 change: 1 addition & 0 deletions crates/biome_css_parser/src/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ impl<'src> CssLexer<'src> {
b"reference" => REFERENCE_KW,
b"config" => CONFIG_KW,
b"plugin" => PLUGIN_KW,
b"slot" => SLOT_KW,
_ => IDENT,
}
}
Expand Down
9 changes: 7 additions & 2 deletions crates/biome_css_parser/src/syntax/at_rule/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ use crate::syntax::at_rule::starting_style::parse_starting_style_at_rule;
use crate::syntax::at_rule::supports::parse_supports_at_rule;
use crate::syntax::at_rule::tailwind::{
parse_apply_at_rule, parse_config_at_rule, parse_custom_variant_at_rule, parse_plugin_at_rule,
parse_reference_at_rule, parse_source_at_rule, parse_theme_at_rule, parse_utility_at_rule,
parse_variant_at_rule,
parse_reference_at_rule, parse_slot_at_rule, parse_source_at_rule, parse_theme_at_rule,
parse_utility_at_rule, parse_variant_at_rule,
};
use crate::syntax::at_rule::unknown::{is_at_unknown_at_rule, parse_unknown_at_rule};
use crate::syntax::at_rule::value::parse_value_at_rule;
Expand Down Expand Up @@ -162,6 +162,11 @@ pub(crate) fn parse_any_at_rule(p: &mut CssParser) -> ParsedSyntax {
tailwind_disabled(p, m.range(p))
})
.or_else(|| parse_unknown_at_rule(p)),
T![slot] => CssSyntaxFeatures::Tailwind
.parse_exclusive_syntax(p, parse_slot_at_rule, |p, m| {
tailwind_disabled(p, m.range(p))
})
.or_else(|| parse_unknown_at_rule(p)),
_ if is_at_unknown_at_rule(p) => parse_unknown_at_rule(p),
_ => Absent,
}
Expand Down
13 changes: 13 additions & 0 deletions crates/biome_css_parser/src/syntax/at_rule/tailwind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,16 @@ pub(crate) fn parse_reference_at_rule(p: &mut CssParser) -> ParsedSyntax {

Present(m.complete(p, TW_REFERENCE_AT_RULE))
}

// @slot;
pub(crate) fn parse_slot_at_rule(p: &mut CssParser) -> ParsedSyntax {
if !p.at(T![slot]) {
return Absent;
}

let m = p.start();
p.bump(T![slot]);
p.expect(T![;]);

Present(m.complete(p, TW_SLOT_AT_RULE))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@slot;
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
---
source: crates/biome_css_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```css
@slot;

```


## AST

```
CssRoot {
bom_token: missing (optional),
rules: CssRuleList [
CssAtRule {
at_token: [email protected] "@" [] [],
rule: CssBogusAtRule {
items: [
[email protected] "slot" [] [],
[email protected] ";" [] [],
],
},
},
],
eof_token: [email protected] "" [Newline("\n")] [],
}
```

## CST

```
0: [email protected]
0: (empty)
1: [email protected]
0: [email protected]
0: [email protected] "@" [] []
1: [email protected]
0: [email protected] "slot" [] []
1: [email protected] ";" [] []
2: [email protected] "" [Newline("\n")] []

```

## Diagnostics

```
slot.css:1:2 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Tailwind-specific syntax is disabled.

> 1 │ @slot;
│ ^^^^^
2 │

i Enable `tailwindDirectives` in the css parser options, or remove this if you are not using Tailwind CSS.

```
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,8 @@ CssRoot {
items: CssDeclarationOrRuleList [
CssAtRule {
at_token: [email protected] "@" [Newline("\n"), Whitespace("\t\t")] [],
rule: CssUnknownValueAtRule {
name: CssIdentifier {
value_token: [email protected] "slot" [] [],
},
components: CssUnknownAtRuleComponentList {
items: [],
},
rule: TwSlotAtRule {
slot_token: [email protected] "slot" [] [],
semicolon_token: [email protected] ";" [] [],
},
},
Expand Down Expand Up @@ -181,11 +176,9 @@ CssRoot {
1: [email protected]
0: [email protected]
0: [email protected] "@" [Newline("\n"), Whitespace("\t\t")] []
1: [email protected]
0: [email protected]
0: [email protected] "slot" [] []
1: [email protected]
2: [email protected] ";" [] []
1: [email protected]
0: [email protected] "slot" [] []
1: [email protected] ";" [] []
2: [email protected] "}" [Newline("\n"), Whitespace("\t")] []
2: [email protected] "}" [Newline("\n")] []
2: [email protected] "" [Newline("\n")] []
Expand Down
Loading
Loading