Skip to content

Commit

Permalink
fix(biome_css_parser): fix css parser cases (#4374)
Browse files Browse the repository at this point in the history
Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
eryue0220 and ematipico authored Oct 24, 2024
1 parent dc0b3ee commit 92879ae
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 14 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

#### Bug fixes

- Fix CSS parser case error, `@-moz-document url-prefix(https://example.com)` and `@-moz-document domain(example.com)` are now valid. Contributed by @eryue0220
- Fix [#4258](https://github.com/biomejs/biome/issues/4258), where fixed css parse error with @-moz-document url-prefix(). Contributed by @eryue0220

### CLI
Expand Down Expand Up @@ -89,7 +90,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
) {}
}
```

Contributed by @fireairforce

- Fix [#3836](https://github.com/biomejs/biome/issues/3836), css parser allow multiple semicolons after a declaration, the following example will now parsed correctly:
Expand Down Expand Up @@ -375,7 +376,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
- Fix [#3364](https://github.com/biomejs/biome/issues/3364) where the `useSelfClosingElements` rule forces the `script` tag to be self-closing. Previously, this rule applies to all elements and cannot be disabled for native HTML elements.

Now, this rule accepts a `ignoreHtmlElements` option, which when set to `true`, ignores native HTML elements and allows them to be non-self-closing.

Contributed by @abidjappie

- Fix a case where raw values inside `url()` functions weren't properly trimmed.
Expand Down
4 changes: 2 additions & 2 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.

2 changes: 1 addition & 1 deletion 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.

6 changes: 5 additions & 1 deletion crates/biome_css_parser/src/syntax/at_rule/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ pub(crate) fn is_at_document_custom_matcher(p: &mut CssParser) -> bool {
p.at_ts(DOCUMENT_CUSTOM_MATCHER_SET) && p.nth_at(1, T!['('])
}

const URL_PREFIX_SET: TokenSet<CssSyntaxKind> = token_set!(T![url_prefix]);
// According to MDN, `url-prefix()`, `domain()` and `media-document()` functions
// can be optionally enclosed by single or double quotes.
// @see https://developer.mozilla.org/en-US/docs/Web/CSS/@document
const URL_PREFIX_SET: TokenSet<CssSyntaxKind> =
token_set!(T![url_prefix], T![domain], T![media_document]);

pub(crate) fn is_at_url_prefix(p: &mut CssParser) -> bool {
p.at_ts(URL_PREFIX_SET) && p.nth_at(1, T!['('])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,21 @@
background-color: green;
}
}

@-moz-document url-prefix(https://example.com) {
body {
background-color: green;
}
}

@-moz-document url(http://www.exmaple.org/), url-prefix(https://www.example.com/test), domain(example.com) {
body {
background-color: green;
}
}

@-moz-document url(http://www.exmaple.org/), url-prefix(https: //www.example.com/test), domain(example.com), media-document(video) {
body {
background-color: green;
}
}

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/biome_css_syntax/src/generated/nodes.rs

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

2 changes: 1 addition & 1 deletion crates/biome_css_syntax/src/generated/nodes_mut.rs

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

2 changes: 1 addition & 1 deletion xtask/codegen/css.ungram
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ AnyCssDocumentMatcher =
CssDocumentCustomMatcher =
name: ('url-prefix' | 'domain' | 'media-document' | 'regexp')
'('
value: CssString?
value: AnyCssUrlValue?
')'

// https://github.com/css-modules/postcss-modules-values
Expand Down

0 comments on commit 92879ae

Please sign in to comment.