Skip to content

Adding a comment with a comma in a selector name of addUtilities fails with unclosed comment #7420

Closed

Description

@just-be-dev

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.

if (node.type === 'rule') {
for (let selector of node.selectors) {
let classCandidates = getClasses(selector)

Activity

  1. thecrypticace commented on Feb 11, 2022

    @thecrypticace
    Contributor

    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.

  2. adamwathan commented on Mar 1, 2022

    @adamwathan
    Contributor

    Hey! I think for now let's just track this over in that postcss-js issue — 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-js directly which we'd then benefit from for free.

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