Skip to content

Call the builder with every node when the output is escaped #2174

Closed

Description

@firefoxic

Since 8.5.29 the builder is called once for the whole output when the stringifier escapes anything, instead of once per node.

let { parse } = require('postcss')
let stringify = require('postcss/lib/stringify')

let root = parse('a{}b{color:red}</style>c{}')

stringify(root, (chunk, node, type) => {
  console.log(JSON.stringify([chunk, node && node.type, type]))
})

On 8.5.28:

["a{", "rule", "start"]
["}", "rule", "end"]
["b{", "rule", "start"]
["color:red", "decl", undefined]
["}", "rule", "end"]
["\\3c /style>c{", "rule", "start"]
["}", "rule", "end"]

On 8.5.29 and 8.5.30:

["a{}b{color:red}\\3c /style>c{}", "root", undefined]

and on 8.5.30 the last argument is "start":

["a{}b{color:red}\\3c /style>c{}", "root", "start"]

docs/syntax.md says the builder is called with every node's string and node instance, and that start and end mark where a node's part opens and closes. A stylesheet without <style, </style or <!-- is unaffected, so the loss only reaches the files where the escaping happens to fire.

We hit this in stylelint-stylistic: max-empty-lines reads each node's raws out of the pieces the builder is given, to know where a neighboring rule's fixes land, and behind such an escape it read none of them.

Is this intended? If not, could the escaped text be cut back into the pieces it was built from and handed over one by one? Escaping only replaces < with the three characters longer \3c , so every piece survives around its own nodes.

Activity

  1. ai commented on Oct 18, 2026

    @ai
    Member

    Can you send PR with this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions