Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(biome_css_parser): fixed css @document parser error #4350

Merged
merged 8 commits into from
Oct 23, 2024
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

### Analyzer

#### Bug fixes

- Fix [#4258](https://github.com/biomejs/biome/issues/4258), where fixed css parse error with @-moz-document url-prefix(). Contributed by @eryue0220

### CLI

### Configuration
Expand Down
42 changes: 31 additions & 11 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.

17 changes: 16 additions & 1 deletion crates/biome_css_parser/src/syntax/at_rule/document.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use crate::lexer::CssLexContext;
use crate::parser::CssParser;
use crate::syntax::at_rule::parse_error::expected_any_document_matcher;
use crate::syntax::block::parse_rule_block;
use crate::syntax::parse_error::expected_string;
use crate::syntax::parse_string;
use crate::syntax::value::url::{is_at_url_function, parse_url_function};
use crate::syntax::value::url::{is_at_url_function, parse_url_function, parse_url_value};
use biome_css_syntax::CssSyntaxKind::*;
use biome_css_syntax::{CssSyntaxKind, T};
use biome_parser::parse_lists::ParseSeparatedList;
Expand Down Expand Up @@ -158,6 +159,12 @@ 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]);

pub(crate) fn is_at_url_prefix(p: &mut CssParser) -> bool {
p.at_ts(URL_PREFIX_SET) && p.nth_at(1, T!['('])
}

/// Parses a custom matcher for the `@document` at-rule in a CSS stylesheet.
/// # Example
/// Basic usage in CSS:
Expand All @@ -177,6 +184,14 @@ pub(crate) fn parse_document_custom_matcher(p: &mut CssParser) -> ParsedSyntax {

let m = p.start();

if is_at_url_prefix(p) {
p.bump_ts(URL_PREFIX_SET);
p.bump_with_context(T!['('], CssLexContext::UrlRawValue);
parse_url_value(p).ok();
p.expect(T![')']);
return Present(m.complete(p, CSS_DOCUMENT_CUSTOM_MATCHER));
}

p.bump_ts(DOCUMENT_CUSTOM_MATCHER_SET);
p.bump(T!['(']);
parse_string(p).or_add_diagnostic(p, expected_string);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,19 @@
}
}
}

@-moz-document url-prefix() {}

@-moz-document url-prefix("https://www.example.com/") {}

@-moz-document url-prefix() {
body {
background-color: green;
}
}

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