Skip to content

Commit

Permalink
fix(css_parser): fix Parser is no longer progressing #3284
Browse files Browse the repository at this point in the history
  • Loading branch information
denbezrukov committed Jul 14, 2024
1 parent f80f505 commit 5577ea5
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 1 deletion.
4 changes: 3 additions & 1 deletion crates/biome_css_parser/src/syntax/at_rule/media.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ fn parse_any_media_query(p: &mut CssParser) -> ParsedSyntax {
parse_any_media_type_query(p)
} else if is_at_grit_metavariable(p) {
parse_grit_metavariable(p)
} else {
} else if is_at_any_media_condition(p) {
let m = p.start();
parse_any_media_condition(p).ok(); // TODO handle error
Present(m.complete(p, CSS_MEDIA_CONDITION_QUERY))
} else {
Absent
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@media (--umrel-breakpoints$-breakpoint) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
---
source: crates/biome_css_parser/tests/spec_test.rs
expression: snapshot
---
## Input

```css
@media (--umrel-breakpoints$-breakpoint) {}
```


## AST

```
CssRoot {
bom_token: missing (optional),
rules: CssRuleList [
CssAtRule {
at_token: AT@0..1 "@" [] [],
rule: CssMediaAtRule {
media_token: MEDIA_KW@1..7 "media" [] [Whitespace(" ")],
queries: CssMediaQueryList [
CssMediaConditionQuery {
condition: CssMediaFeatureInParens {
l_paren_token: L_PAREN@7..8 "(" [] [],
feature: CssQueryFeatureBoolean {
name: CssIdentifier {
value_token: IDENT@8..27 "--umrel-breakpoints" [] [],
},
},
r_paren_token: missing (required),
},
},
missing separator,
CssMediaTypeQuery {
modifier: missing (optional),
ty: CssMediaType {
value: CssIdentifier {
value_token: IDENT@27..39 "$-breakpoint" [] [],
},
},
},
missing separator,
CssBogusMediaQuery {
items: [
R_PAREN@39..41 ")" [] [Whitespace(" ")],
],
},
],
block: CssRuleBlock {
l_curly_token: L_CURLY@41..42 "{" [] [],
rules: CssRuleList [],
r_curly_token: R_CURLY@42..43 "}" [] [],
},
},
},
],
eof_token: EOF@43..44 "" [Newline("\n")] [],
}
```

## CST

```
0: [email protected]
0: (empty)
1: [email protected]
0: [email protected]
0: [email protected] "@" [] []
1: [email protected]
0: [email protected] "media" [] [Whitespace(" ")]
1: [email protected]
0: [email protected]
0: [email protected]
0: [email protected] "(" [] []
1: [email protected]
0: [email protected]
0: [email protected] "--umrel-breakpoints" [] []
2: (empty)
1: (empty)
2: [email protected]
0: (empty)
1: [email protected]
0: [email protected]
0: [email protected] "$-breakpoint" [] []
3: (empty)
4: [email protected]
0: [email protected] ")" [] [Whitespace(" ")]
2: [email protected]
0: [email protected] "{" [] []
1: CSS_RULE_LIST@42..42
2: R_CURLY@42..43 "}" [] []
2: EOF@43..44 "" [Newline("\n")] []
```
## Diagnostics
```
at_rule_media_error.css:1:28 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `)` but instead found `$-breakpoint`
> 1 │ @media (--umrel-breakpoints$-breakpoint) {}
^^^^^^^^^^^^
2
i Remove $-breakpoint
at_rule_media_error.css:1:40 parse ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× expected `,` but instead found `)`
> 1 │ @media (--umrel-breakpoints$-breakpoint) {}
^
2
i Remove )
```

0 comments on commit 5577ea5

Please sign in to comment.