Skip to content

[css-syntax-3] Allow positioned {}-block in @property/initial-value #11737

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

Open
cdoublev opened this issue Feb 18, 2025 · 3 comments
Open

[css-syntax-3] Allow positioned {}-block in @property/initial-value #11737

cdoublev opened this issue Feb 18, 2025 · 3 comments

Comments

@cdoublev
Copy link
Collaborator

Per spec, a positioned {}-block is allowed for a custom property, but not for @property/initial-value:

  1. [...] Otherwise, if decl’s value contains a top-level simple block with an associated token of <{-token>, and also contains any other non- value, return nothing. (That is, a top-level {}-block is only allowed as the entire value of a non-custom property.)

A possible solution could be to apply this only "if decls name is a supported CSS property".

However, I think the intention of step 9 is to allow reparsing a:hover {} / avoid reparsing --custom: var(1) {}, as a qualified rule. But it indifferently returns "nothing". So it could return an "invalid declaration error" instead. Consume a block's contents would also need to be updated accordingly.

@tabatkins
Copy link
Member

tabatkins commented Feb 18, 2025

Ah, I see, since initial-value isn't a custom property name, the parser will reject the value if it's got a {} block plus other stuff.

I'm not particularly sad about that. Allowing {} with other junk in a custom property is mostly there for back-compat. If you're registering a custom property, it's very likely to be with intent to use it for CSS stuff, where that sort of value would be completley invalid anyway. (You'd need to pair with a syntax: "*"; anyway, meaning that if you weren't using it for CSS values, the only reason to register it would be to turn off inheritance, which is a super minimal use-case at that point. Just put it in some parens or something if you really care, so it's not top-level.)

So, I'm inclined to just leave this as no change: you cannot express certain initial values for a registered custom property, even tho they are technically syntactically valid values for the property to have.

@cdoublev
Copy link
Collaborator Author

So defining it with ? would be a lie? I agree with your opinion on the use case, but I must admit that I am primarily interested in the design of CSS grammar.

I did not mention @function/result because it is not implemented anywhere but it applies as well.

@cdoublev
Copy link
Collaborator Author

cdoublev commented Feb 19, 2025

I also did not mention that positioned {}-block in @property/initial-value are valid in Chrome and Firefox (non-exhaustive) today.

And if the intention is to early exit consuming nested rules in div { a:hover {} a:focus {} /* etc... */ } as a declaration, I presume that "grammar-aware" parser implementations would do it after consuming the declaration name.

(edit) They still need to abort parsing color: {} var(--custom) ... as soon as they see var(, or marker:hover {}, as soon as they see {.

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

No branches or pull requests

2 participants