Description
What version of Tailwind CSS are you using?
For example: v3.0.21
What build tool (or framework if it abstracts the build tool) are you using?
For example: postcss 8.4.6
What version of Node.js are you using?
For example: v16.13.0
What browser are you using?
For example: N/A
What operating system are you using?
For example: Windows
Reproduction URL
https://play.tailwindcss.com/aiUpPZ53Dc?file=config
Describe your issue
When using addUtilities in a plugin a comment can be added before the the selector of a utility to provide a docs in vscode on hover of a class. We're using this as a way to document our design system tokens. If there's a comma inside the comment though, it breaks the parser. You can see the error clearly in the repo link, it also crashes the sandbox.
addUtilities({
'/* this, is, a, test */ .test': {
'color': 'blue'
}
})I've spent some time chasing this down. If you put a console.log after line 103 (referenced below) you'll see that the selector is /* this when trying to build styles with the above. node.selector shows the correct, full selector but node.selectors looks like it's literally just splitting on the commas. It looks like node is derived from parseStyles which uses parseObjectStyles to do the parsing. That's a fairly bare postcss setup... I'm not actually sure if it's a straight postcss problem though.
tailwindcss/src/lib/setupContextUtils.js
Lines 102 to 104 in 9f119e5
| if (node.type === 'rule') { | |
| for (let selector of node.selectors) { | |
| let classCandidates = getClasses(selector) |
Activity
thecrypticace commentedon Feb 11, 2022
This looks to be a problem with
postcss-js— I've opened an issue there about the problem and hopefully will have some kind of solution soon and will update this once we do.adamwathan commentedon Mar 1, 2022
Hey! I think for now let's just track this over in that
postcss-jsissue — we don't currently do any fancy stuff to augment the behavior there and I don't think we really want to open that can of worms right now 😕If there's enough demand for this in the future or someone can put together a PR that solves it and is really simple and not something we'd be worried about maintaining long term then I think we can revisit it, but in the mean time I think just have to treat this as an accepted limitation and maybe support can be added in
postcss-jsdirectly which we'd then benefit from for free.