Closed bzbarsky closed 6 years ago
Oh, and the point is that -2 + -3
would become 2 + 3
when negated.
And I guess really -2 and -3 would both be represented by CSSUnitValue anyway... So this is really abot about negating -(2+3) + -(4+5)
or something.
I have no strong opinion on this - I captured some simple shortcuts in the current algorithms, with the goal of avoiding stacking the same wrapper over and over again when you're just doing some operation piece-meal instead of all at once. (That is, I want val1.add(val2, val3)
to give the same result as val1.add(val2).add(val3)
.)
We can always add more shortcuts, if people think it's reasonable.
Maybe we could also add a note saying that new shortcuts in the future (if that's the plan) may change the tree structure of the output, and your code shouldn't depend on the structure being the same over time?
Depends. If we do add a shortcut like this, then yeah, we should be open to more in the future. My current shortcuts, tho, are limited to three simple principles that won't result in future changes: (1) produce the same result whether you do the op as a single n-ary operation or N binary operations (so v1.add(v2, v3)
gives the same result as v1.add(v2).add(v3)
; (2) when an operation self-reverses (negation and inverse), don't double-stack them; and (3) when operating on just unit values of the same unit, produce another unit value, rather than a math function (so v1.add(v2)
gives the same result as v1.value += v2.value
)
I would prefer to not have the result change over time, so I think I'd prefer to stick with these simple principles for shortcuts and nothing more. But like I said, I'm not wedded to this if people think more shortcuts are indeed worthwhile.
It looks like https://drafts.css-houdini.org/css-typed-om-1/#cssmath-negate will turn
-5
into5
but-2 + -3
into-(-2 + -3)
. That might be OK; we could probably spend our entire lives trying to make negation "nice". But the specific case of a CSSMathSum of CSSMathNegate might be worth considering as a special-case anyway...