Skip to content
Closed
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
19 changes: 18 additions & 1 deletion src/css/css_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1595,8 +1595,12 @@ mod rule_parsers {
b"container" => {
let container_name: Option<ContainerName> =
input.try_parse(css_rules::container::ContainerName::parse).ok();
let unknown_blocks = input.general_enclosed_blocks();
let condition: ContainerCondition =
css_rules::container::ContainerCondition::parse(input)?;
if input.general_enclosed_blocks() != unknown_blocks {
media_query::warn_general_enclosed(input, this.options, &condition);
}
break 'brk AtRulePrelude::Container { name: container_name, condition };
},
b"starting-style" => break 'brk AtRulePrelude::StartingStyle,
Expand Down Expand Up @@ -3293,6 +3297,17 @@ impl<'a> Parser<'a> {
self.input.token_list_parse_failures += 1;
}

/// See `ParserInput::general_enclosed_blocks`.
#[inline]
pub(crate) fn general_enclosed_blocks(&self) -> u64 {
self.input.general_enclosed_blocks
}

#[inline]
pub(crate) fn note_general_enclosed_block(&mut self) {
self.input.general_enclosed_blocks += 1;
}

pub(crate) fn is_exhausted(&mut self) -> bool {
self.expect_exhausted().is_ok()
}
Expand All @@ -3308,7 +3323,6 @@ impl<'a> Parser<'a> {
match tok {
Token::Function(_) | Token::OpenParen | Token::OpenSquare | Token::OpenCurly => {
self.parse_nested_block(|i| i.expect_no_error_token())?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) Stylesheets that built on the base branch now print different @ supports selector(..) and @ import .. supports(..) text, with trailing whitespace and comments kept even under --minify. Removing the early return at src/css/css_parser.rs:3310 makes expect_no_error_token scan to the closing ), so the slice taken at supports.rs:339 and supports.rs:320 now ends at ) instead of right after the first nested block. Fix: trim trailing whitespace/comments from the slice at both slice_from_cloned sites (or stop the slice at the last non-whitespace token) so the Selector and Declaration text matches base for every input that already built.

Why this was flagged

Input @ supports selector(:is(a) ) {} or @ import "a.css" supports(transform: rotate(1deg) ); reaches expect_no_error_token through supports.rs:339 (Selector) and supports.rs:319 (Declaration via css_parser.rs:1194). On base the loop returned Ok right after the first nested block (:is( / rotate(), so slice_from_cloned at supports.rs:340 / supports.rs:320 ended at that block's ) and the trailing or /* c */ was dropped by parse_entirely's expect_exhausted. With the diff at src/css/css_parser.rs:3310 the loop continues until the stop_before ), so the slice now includes the trailing whitespace and any comment, and the printer writes it verbatim (supports.rs:200 write_bytes) in minified output. This runs for every @ supports/@ import supports with a function value in every build; it is a printed-output regression for input that was valid on base. Remedy: trim trailing whitespace/comments at the two slice sites.

Verification: Base src/css/css_parser.rs:3310 returned right after the first nested block, so slice_from_cloned(p) at supports.rs:340 / :320 ended at that block's ); expect_exhausted (css_parser.rs:3630-3649) skipped trailing or /* c */. Now the loop (3309-3311) consumes them, so the slice is :is(a) and to_css writes it raw via write_bytes (supports.rs:162, :200) under minify.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changed. This is the output of #38552, which is the same one-line change and pins selector(:is(a) ) and supports(transform:translate(1px) ) with the space. The description lists it under "@supports", and a test here pins the same text so the two PRs agree. A trim at the two slice_from_cloned sites in supports.rs is possible, but it should be decided in one place for both PRs.

return Ok(());
}
_ => {
if tok.is_parse_error() {
Expand Down Expand Up @@ -3833,6 +3847,8 @@ pub struct ParserInput<'a> {
/// alternative is guaranteed to fail again, so they propagate the error
/// instead of retrying (which is exponential in the nesting depth).
token_list_parse_failures: u64,
/// Count of the blocks that became `<general-enclosed>` conditions.
general_enclosed_blocks: u64,
}

/// See `ParserInput::unclosed_block_at_eof`.
Expand Down Expand Up @@ -3861,6 +3877,7 @@ impl<'a> ParserInput<'a> {
unclosed_block_at_eof: None,
math_fn_parse_failures: 0,
token_list_parse_failures: 0,
general_enclosed_blocks: 0,
}
}
}
Expand Down
Loading
Loading