Skip to content

Remove backslash line continuations from the CSS output - #114

Merged
ai merged 1 commit into
postcss:mainfrom
wahidrizka:fix-backslash-line-continuation
Oct 7, 2026
Merged

ai merged 1 commit into
postcss:mainfrom
wahidrizka:fix-backslash-line-continuation

Conversation

@wahidrizka

Copy link
Copy Markdown
Contributor

The README lists "Backslash before new line" among the 3 ways to continue a line for any type of node. The parser keeps the backslash in selectors, at-rule params and declaration values, so the CSS output still has it:

@media screen and \
       (min-width: 600px) {

A backslash before a new line is not a valid escape in CSS, and browsers reject it. In Chrome 153 the media query above becomes not all, an @supports rule written the same way is dropped, and so is a margin value continued with a backslash. With only the backslash removed, all three apply.

Now the parser removes the backslash from the value and from raws[prop].raw, and keeps it in raws[prop].sss, like it does for inline comments, so stringify() still returns the original SugarSS. The new backslash case fails on main; it covers at-rule params, a selector and a declaration value. All 66 tests pass.

Related to #91: with this, a multi-line @apply px-10 \ works with Tailwind CSS 4.3.3, while with sugarss 5.0.1 Tailwind reads the backslash as a class name. When the classes start on the next line (@apply \), params still starts with a new line, which Tailwind reads as an empty class. Fixing that needs the new line in raws.afterName and a SugarSS-only raw to keep the round trip, so I left it out; I can add it if you want.

I made backslash.json with JSON.stringify(jsonify(root), null, 2), because test/update-cases.js now writes [object Object]: jsonify() from postcss-parser-tests 8.9.0 returns an object.

A backslash before a new line continues the line in SugarSS, but the
parser kept it in selectors, at-rule params and values. CSS has no such
escape, so browsers dropped those rules and declarations. Keep the
backslash only in the SugarSS raw, so stringify still gives the input.
@ai
ai merged commit fa7925d into postcss:main Oct 7, 2026
3 checks passed
@ai

ai commented Oct 7, 2026

Copy link
Copy Markdown
Member

Thanks. Released in 5.0.2.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants