Skip to content

Commit fe90c78

Browse files
authored
fix(parse/css): fix parsing tailwind source exclude syntax (#7853)
1 parent bd254c7 commit fe90c78

File tree

15 files changed

+183
-27
lines changed

15 files changed

+183
-27
lines changed

.changeset/soft-rules-feel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed #7848: The css parser with `tailwindDirectives` enabled will now correctly parse tailwind's source exclude syntax: `@source not "foo.css";`

crates/biome_css_factory/src/generated/node_factory.rs

Lines changed: 30 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_css_factory/src/generated/syntax_factory.rs

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_css_formatter/src/tailwind/statements/source_at_rule.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@ impl FormatNodeRule<TwSourceAtRule> for FormatTwSourceAtRule {
77
fn fmt_fields(&self, node: &TwSourceAtRule, f: &mut CssFormatter) -> FormatResult<()> {
88
let TwSourceAtRuleFields {
99
source_token,
10+
not_token,
1011
path,
1112
semicolon_token,
1213
} = node.as_fields();
1314

14-
write!(
15-
f,
16-
[
17-
source_token.format(),
18-
space(),
19-
path.format(),
20-
semicolon_token.format()
21-
]
22-
)
15+
write!(f, [source_token.format(), space()])?;
16+
if let Some(not_token) = not_token {
17+
write!(f, [not_token.format(), space()])?;
18+
}
19+
write!(f, [path.format(), semicolon_token.format()])
2320
}
2421
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"css": {
3+
"parser": {
4+
"tailwindDirectives": true
5+
}
6+
}
7+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@source not "../routes/utils/ds.tsx";
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
source: crates/biome_formatter_test/src/snapshot_builder.rs
3+
info: css/atrule/tailwind/source-not.css
4+
---
5+
# Input
6+
7+
```css
8+
@source not "../routes/utils/ds.tsx";
9+
10+
```
11+
12+
13+
=============================
14+
15+
# Outputs
16+
17+
## Output 1
18+
19+
-----
20+
Indent style: Tab
21+
Indent width: 2
22+
Line ending: LF
23+
Line width: 80
24+
Quote style: Double Quotes
25+
-----
26+
27+
```css
28+
@source not "../routes/utils/ds.tsx";
29+
```
30+
31+
## Output 1
32+
33+
-----
34+
Indent style: Tab
35+
Indent width: 2
36+
Line ending: LF
37+
Line width: 80
38+
Quote style: Double Quotes
39+
-----
40+
41+
```css
42+
@source not "../routes/utils/ds.tsx";
43+
```

crates/biome_css_parser/src/syntax/at_rule/tailwind.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ pub(crate) fn parse_source_at_rule(p: &mut CssParser) -> ParsedSyntax {
215215

216216
let m = p.start();
217217
p.bump(T![source]);
218+
if p.at(T![not]) {
219+
p.bump(T![not]);
220+
}
218221
parse_string(p).or_add_diagnostic(p, expected_string);
219222
p.expect(T![;]);
220223

crates/biome_css_parser/tests/css_test_suite/ok/tailwind/simple.css.snap

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ CssRoot {
224224
at_token: AT@281..284 "@" [Newline("\n"), Newline("\n")] [],
225225
rule: TwSourceAtRule {
226226
source_token: SOURCE_KW@284..291 "source" [] [Whitespace(" ")],
227+
not_token: missing (optional),
227228
path: CssString {
228229
value_token: CSS_STRING_LITERAL@291..303 "\"./base.css\"" [] [],
229230
},
@@ -480,9 +481,10 @@ CssRoot {
480481
0: AT@281..284 "@" [Newline("\n"), Newline("\n")] []
481482
1: TW_SOURCE_AT_RULE@284..304
482483
0: SOURCE_KW@284..291 "source" [] [Whitespace(" ")]
483-
1: CSS_STRING@291..303
484+
1: (empty)
485+
2: CSS_STRING@291..303
484486
0: CSS_STRING_LITERAL@291..303 "\"./base.css\"" [] []
485-
2: SEMICOLON@303..304 ";" [] []
487+
3: SEMICOLON@303..304 ";" [] []
486488
5: CSS_QUALIFIED_RULE@304..380
487489
0: CSS_SELECTOR_LIST@304..315
488490
0: CSS_COMPOUND_SELECTOR@304..315
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@source not "../routes/utils/ds.tsx";

0 commit comments

Comments
 (0)