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

[css-values-5] Should <whole-value> functions be parsed before the declaration value range? #10340

Open
cdoublev opened this issue May 16, 2024 · 3 comments

Comments

@cdoublev
Copy link
Collaborator

CSS-wide keyword parsing should kick in first because --custom: initial should result to --custom being declared to its initial (guaranteed-invalid) value rather than the <ident-token> for initial (the result from matching against its value definition).

Arbitrary substitution parsing should then kick in before the value range because --custom: var(1) should be invalid. They should be parsed before <whole-value> because display: var(--empty) first-valid(block) should be valid (at parse time, at least).

Should --custom: first-valid(not, whole) value be valid?

@Loirooriol
Copy link
Contributor

Unregistered custom properties just tokenize, except for a few things like var() and env(). So:

  • If first-valid() is a normal function, it's accepted, as a token.
  • Otherwise I guess it's invalid.

I don't see any reason to treat it specially, since unregistered custom properties accept almost everything?
I don't think it's likely that people will want --foo: first-supported(var(b), var(--b)) to behave as --foo: var(--b) because --foo: var(b) is invalid.
I think it's more likely that people will want to defer the resolution of first-supported, e.g.

:root {
  --color: first-supported(color(brand-new-color-space, ...), cyan);
}
.foo { color: var(--color) }
#bar something { color: var(--color) }

@cdoublev
Copy link
Collaborator Author

cdoublev commented May 21, 2024

Unregistered custom properties just tokenize, except for a few things like var() and env().

I have not considered this option. So --custom: first-valid(not, whole) value is valid but not --custom: first-valid(1) var(--empty, var(invalid)), and a CSS parser should therefore not try matching <whole-value> as a replacement for a custom property value, but only for standard properties?

Even if first-valid(not, whole) value is guaranteed to be invalid in any declaration value, it would probably not be usefull to make it invalid at parse time also for a custom property value. It just seems more consistent though.

@tabatkins
Copy link
Member

Unregistered custom properties do not grammar-check at all besides the basic validity of substitution functions in their value. They shouldn't do anything special for first-valid() either; that's just part of every property's grammar, and thus included in the "no parsing beyond tokenization" aspect.

Remember that one of the reasons we don't grammar-check custom properties is because they can be used to pass around information for non-CSS purposes; we do only the absolute bare minimum of checking (CSS-wide keywords, and other substitution functions) so people can avoid having to think abuot it as much as possible.

That said, I think it's reasonable to clarify this in the spec.

cdoublev added a commit to cdoublev/css that referenced this issue Oct 7, 2024
- a property with a CSS-wide keyword that is not the sole component
  value, eg. "initial identifier" for a hypothetical property defined
  with <ident>+
- a property or descriptor with an arbitrary substitution that is not
  allowed in the context, eg. "size: var(..., attr(...))", which is
  inappropriate (w3c/csswg-drafts#10337)
- a custom property with a <whole-value> value that would be invalid for
  a standard property, eg. "--custom: not first-valid(whole-value)",
  which is inappropriate (w3c/csswg-drafts#10340)
cdoublev added a commit to cdoublev/css that referenced this issue Oct 8, 2024
The previous implementation prevented declaring:

- a property with a CSS-wide keyword that is not the sole component
  value, eg. "initial identifier" for a property defined with <ident>+
- a property or descriptor with an arbitrary substitution that is not
  allowed in the context, eg. "size: var(..., attr(...))"
  (w3c/csswg-drafts#10337)
- a custom property with a <whole-value> that is guaranteed to be
  invalid after substitution, eg. "--custom: not
  first-valid(whole-value)" (w3c/csswg-drafts#10340)
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

3 participants