- From: Tab Atkins Jr. via GitHub <sysbot+gh@w3.org>
- Date: Wed, 25 Sep 2024 15:53:24 +0000
- To: public-css-archive@w3.org
> Would `var(--foo, {"foo.svg", "bar.svg"})` resolve to `"foo.svg", "bar.svg"` or to `{"foo.svg", "bar.svg"}`? If the former, does that mean that `if(cond(...): var(--foo))` resolves to `"foo.svg"` if `cond(...)` is true? If the latter, does that mean that `prop: var(--foo)` is invalid? Per my proposal above, the `var()` would resolve to `{"foo.svg", "bar.svg"}`. Then the `if()` gets the var() subbed in, producing `if(cond(...): {"foo.svg", "bar.svg"})`. But as Anders said, we might be able to (and hopefully can) make var() more subtle, and allow enforcing the {} rules like other locations. (But, as they say, there's no way we can make it *require* {} around commas; it'll still need to allow top-level commas in its fallback for back-compat.) If that's the case, then the behavior instead becomes: * The `var()` would resolve to `"foo.svg", "bar.svg"`. * It then subs into the `if()` to produce `if(cond(...): "foo.svg", "bar.svg")`, which is invalid syntax; the property becomes IACVT. * The solution would be to write the `if()` as `if(cond(...): {var(--foo)})`. You can do this defensively; it works correctly whether the var() substitutes as a value with commas or not. This is similar to the current specced behavior, where you might need to defensively write your function like `if(cond(...): var(--foo);)` to ensure that *if* the var() substitution contains commas, it works properly (but is also fine if it doesn't). * (The var() author could also defensively double-wrap their value in {}; only the outer one gets stripped by the grammar. But then it can't be safely used *directly* in properties. Not a good idea in general. Similarly, you shouldn't defensively write your custom property with a {} wrapper in its value, like `--foo: {"foo.svg", "bar.svg"};`, because it then can't be subbed directly into many locations.) This defensive coding is slightly unfortunate but a required part of how var() (and all other arbitrary-substitution functions) work; they are *intrinsically* passing around raw syntax, not higher-level values. For example, a custom property could be `--foo: cond1(...): val1, cond2(...): val2;`, then used like `if(var(--foo), cond3(...): val3)`. -- GitHub Notification of comment by tabatkins Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9539#issuecomment-2374479826 using your GitHub account -- Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config
Received on Wednesday, 25 September 2024 15:53:25 UTC