Open
Description
https://drafts.csswg.org/css-values-4/#serialize-a-math-function
Step 4 says:
For each child of the root node, serialize the calculation tree. If a result of this serialization starts with a "(" (open parenthesis) and ends with a ")" (close parenthesis), remove those characters from the result. Concatenate all of the results using ", " (comma followed by space), then append the result to s.
There are a couple of issues with this:
- The
clamp()
function has a<rounding-strategy>
as its first child. Passing that to "serialize the calculation tree" isn't valid, but ignoring it would miss it from the serialization. - If
root
is a numeric value and we are serializing it before the computed-value stage, it has no children and should be passed to "serialize the calculation tree" directly. - If
root
is a calc-operator node, serializing its children as a comma-separated list is incorrect. It should also be passed to "serialize the calculation tree" directly.
When implementing this in Ladybird, I replaced step 4 with this behaviour, and it seems to be correct according to the WPT tests I've checked:
- If the root node is a numeric value, or a calc-operator node:
- Call "serialize the calculation tree" on the root node, then any wrapping (), and append that to
s
.
- Call "serialize the calculation tree" on the root node, then any wrapping (), and append that to
- Otherwise:
- If the root node is a Clamp function:
- Serialize its rounding-strategy and append that to
s
, followed by ", ".
- Serialize its rounding-strategy and append that to
- Perform the original step 4 on the children that are calculation nodes.
- If the root node is a Clamp function:
In reality you'd want to combine that with step 3, as the two steps have identical if conditions.