lukeed / clsx

A tiny (239B) utility for constructing `className` strings conditionally.
MIT License
8.08k stars 141 forks source link

Tailwind regex flags unreachable paths #77

Closed will-stone closed 11 months ago

will-stone commented 1 year ago

Hi Luke 👋

Please excuse my lack of regex knowledge. The Tailwind set-up instruction currently flags items in nested ternaries as conflicting, even though the logic paths are unique. Here's an example where a different size prop results in different class strings resulting in different sized text:

image

I'm guessing this is something that any amount of regex-fu isn't going to solve as it's runtime logic.

We chose to use nested ternaries because the string concat is much faster than array/object notation. It also means conditionals stop being checked as soon as the first passing condition is reached.

Would love to hear your thoughts 😄

Thanks,

Will.

writeens commented 1 year ago

@will-stone I encountered the same issue. I found this regex here

"tailwindCSS.experimental.classRegex": [
  ["clsx\\(([^)]*)\\)", "(?:'|\"|`)([^\"'`]*)(?:'|\"|`)"]
]

Its only slightly different but it gets rid of the css conflict.

Hope this helps

will-stone commented 11 months ago

Thanks @writeens Mine seems to be working fine without any regex now, but good to know I can use this if I have any issues 👍