tailwindlabs / prettier-plugin-tailwindcss

A Prettier plugin for Tailwind CSS that automatically sorts classes based on our recommended class order.
MIT License
5.66k stars 135 forks source link

Only re-apply string escaping when necessary #295

Closed thecrypticace closed 5 months ago

thecrypticace commented 5 months ago

In #286 we fixed a situation in which escapes were being stripped from strings. This is because StringLiteral nodes in an expression have both escaped and unescaped values.

However, it seems that some StringLiteral nodes do not do this even though they are otherwise identical. Any StringLiteral that is the direct value of a JSX attribute does not perform any escaping.

For example, given these two JSX nodes, you will get the following as the AST:

// The first one
;<div class={"before:content-['\\\\2248']"} />

// The second one
;<div class="before:content-['\\\\2248']" />

image

So we have to detect whether or not escaping was applied originally before doing that ourselves.

tl;dr software is hard 😅

Fixes #294