Skip to content

Commit 7b2600b

Browse files
authored
fix(parse/css): allow @plugin to accept options (#7866)
1 parent 0a59995 commit 7b2600b

File tree

24 files changed

+1370
-34
lines changed

24 files changed

+1370
-34
lines changed

.changeset/small-sides-teach.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 [#7860](https://github.com/biomejs/biome/issues/7860): The css parser, with `tailwindDirectives` enabled, will now accept `@plugin` options.

crates/biome_css_factory/src/generated/node_factory.rs

Lines changed: 34 additions & 11 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/plugin_at_rule.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ impl FormatNodeRule<TwPluginAtRule> for FormatTwPluginAtRule {
99
let TwPluginAtRuleFields {
1010
plugin_token,
1111
name,
12+
block,
1213
semicolon_token,
1314
} = node.as_fields();
1415

15-
write!(
16-
f,
17-
[
18-
plugin_token.format(),
19-
space(),
20-
name.format(),
21-
semicolon_token.format()
22-
]
23-
)
16+
write!(f, [plugin_token.format(), space(), name.format()])?;
17+
if let Some(block) = block {
18+
write!(f, [space(), block.format()])?;
19+
if let Some(semicolon_token) = semicolon_token {
20+
write!(f, [format_removed(&semicolon_token)])?;
21+
}
22+
} else {
23+
write!(f, [semicolon_token.format()])?;
24+
}
25+
26+
Ok(())
2427
}
2528
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@plugin "my-plugin" ;
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/tailwind/plugin-no-options.css
4+
---
5+
# Input
6+
7+
```css
8+
@plugin "my-plugin" ;
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+
@plugin "my-plugin";
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+
@plugin "my-plugin";
43+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@plugin "my-plugin" {
2+
debug: false;
3+
threshold:0.5;
4+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
source: crates/biome_formatter_test/src/snapshot_builder.rs
3+
info: css/tailwind/plugin-with-options.css
4+
---
5+
# Input
6+
7+
```css
8+
@plugin "my-plugin" {
9+
debug: false;
10+
threshold:0.5;
11+
}
12+
13+
```
14+
15+
16+
=============================
17+
18+
# Outputs
19+
20+
## Output 1
21+
22+
-----
23+
Indent style: Tab
24+
Indent width: 2
25+
Line ending: LF
26+
Line width: 80
27+
Quote style: Double Quotes
28+
-----
29+
30+
```css
31+
@plugin "my-plugin" {
32+
debug: false;
33+
threshold: 0.5;
34+
}
35+
```
36+
37+
## Output 1
38+
39+
-----
40+
Indent style: Tab
41+
Indent width: 2
42+
Line ending: LF
43+
Line width: 80
44+
Quote style: Double Quotes
45+
-----
46+
47+
```css
48+
@plugin "my-plugin" {
49+
debug: false;
50+
threshold: 0.5;
51+
}
52+
```

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::lexer::CssLexContext;
22
use crate::parser::CssParser;
3-
use crate::syntax::block::{parse_declaration_or_rule_list_block, parse_rule_block};
3+
use crate::syntax::block::{
4+
parse_declaration_block, parse_declaration_or_rule_list_block, parse_rule_block,
5+
};
46
use crate::syntax::parse_error::{expected_identifier, expected_selector, expected_string};
57
use crate::syntax::selector::parse_selector;
68
use crate::syntax::{is_at_identifier, parse_identifier, parse_regular_identifier, parse_string};
@@ -194,6 +196,11 @@ pub(crate) fn parse_config_at_rule(p: &mut CssParser) -> ParsedSyntax {
194196
}
195197

196198
// @plugin "@tailwindcss/typography";
199+
// OR
200+
// @plugin "my-plugin" {
201+
// debug: false;
202+
// threshold: 0.5;
203+
// }
197204
pub(crate) fn parse_plugin_at_rule(p: &mut CssParser) -> ParsedSyntax {
198205
if !p.at(T![plugin]) {
199206
return Absent;
@@ -202,7 +209,10 @@ pub(crate) fn parse_plugin_at_rule(p: &mut CssParser) -> ParsedSyntax {
202209
let m = p.start();
203210
p.bump(T![plugin]);
204211
parse_string(p).or_add_diagnostic(p, expected_string);
205-
p.expect(T![;]);
212+
if !p.eat(T![;]) {
213+
parse_declaration_block(p);
214+
p.eat(T![;]);
215+
}
206216

207217
Present(m.complete(p, TW_PLUGIN_AT_RULE))
208218
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@plugin "my-plugin" {
2+
.some-selector > * {
3+
primary: "blue";
4+
secondary: "green";
5+
}
6+
}
7+
8+
/* Error: `@plugin` can only contain declarations. */

0 commit comments

Comments
 (0)