Skip to content

Conversation

@OverflowCat
Copy link

@OverflowCat OverflowCat commented Jul 3, 2025

It seems that there are no p.Peek(), so I clone the Parser every time it enters a QualifiedRuleset. Lookahead is necessary, since we cannot determine whether it is a declaration or a child rule:

.a {
  div:hover {
    ...
  }
}

.a {
  prop:value
}

Decl is <ident><colon><value>+, but not vice versa. So we need to step until <lbrace>/a combinator (child rule) or <semi>/<rbace> (decl).

Also, the test case

{false, "a{@media{width:70%;} b{width:60%;}}", "a{@media{ERROR(width:70%;})ERROR(b{width:60%;})}"},

should be all valid as Chrome supports empty media queries:

css-test

@tdewolff
Copy link
Owner

tdewolff commented Jul 3, 2025

I highly appreciate the effort to investigate and create a PR. I think this addresses some important bugs with the CSS parser. I wanted to rewrite it from the ground up, but perhaps we can improve it bit-by-bit.

However, the cloning part I don't really like. Other parsers or lexers can peek without cloning, and either can do it at no cost or they use an internal buffer. I think we should use a buffer to store the tokens from the lexer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants