Skip to content

[css-values-4] Serialization of Negate and Invert nodes seems incorrect #10943

@cdoublev

Description

@cdoublev

Per spec, 1 - sibling-index() should serialize with 1 - (-1 * sibling-index()).

  1. If root is a Negate node, let s be a string initially containing "(-1 * ".

    [...]

  2. [...]

  3. If root is a Sum node, let s be a string initially containing "(".

    [...]

    For each child of root beyond the first:

    1. If child is a Negate node, append " - " to s, then serialize the Negate’s child and append the result to s.

It should presumably serialize as is. An equivalent problem exists for 2 / sibling-index().

I think steps 4 and 5 (Negate and Invert) can be removed: steps 6 and 7 could simply serialize the child of Negate and Invert, and wrap each serialization of their child in () when it is Sum or Product node (to handle cases like 1 - (1 * sibling-index()).

Alternatively, they could wrap their own serialization only when the parent node is a Sum or Product node, which requires to pass the parent node recursively, and to remove the following from serialize a math function, which seems a little awkward:

[...] If a result of this serialization starts with a "(" (open parenthesis) and ends with a ")" (close parenthesis), remove those characters from the result. [...]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions