-
Notifications
You must be signed in to change notification settings - Fork 757
Description
Running the simplify a calculation tree algorithm on a calculation tree containing a sum node which contains an invert node which in turn contains a sum node that can't be simplified down to a single numeric value results in incomplete simplification.
Take for instance the value calc(100 - (sign(1em - 1px) - 50)) which produces the following calculation tree:
SUM:
NUMERIC(100)
NEGATE:
SUM:
SIGN:
SUM:
NUMERIC(1em)
NUMERIC(-1px)
NUMERIC(-50)
Chrome and Firefox both correctly simplify this to calc(150 - sign(1em - 1px)) but the existing algorithm results in no simplification. This is because step 6 only simplifies the Negate node if it's child is a Numeric or Negate node, and step 8 only combines the children of the root Sum node which are Numeric or Sum nodes (not negate).
One way to fix this would be that, when simplifying Negate nodes, we convert a negated sum node into a sum of negated nodes i.e. convert
NEGATE:
SUM:
SIGN:
SUM:
NUMERIC(1em)
NUMERIC(-1px)
NUMERIC(-50)
into
SUM:
NEGATE:
SIGN:
SUM:
NUMERIC(1em)
NUMERIC(-1px)
NUMERIC(50)
Which would then be further simplified by step 9 producing an output in line with Chrome and Firefox.
I am happy to take a stab at a PR for this if the above seems like a reasonable approach.