svelte icon indicating copy to clipboard operation
svelte copied to clipboard

Class directive breaks with token "/" for TailwindCSS width classes

Open jerriclynsjohn opened this issue 6 years ago • 12 comments

Describe the bug When using specific classes like "w-1/2", which is standard tailwind class, the svelte compiler throws an error "Expected >svelte(unexpected-token)"

I'm pretty sure it is because the compiler assumes token ">" after the token in question "/".

To Reproduce Write any code with a class directive class:sm:w-1/2={!contact} in a Svelte+Tailwind project.

Expected behavior Compiler should not assume that the closing ">" token to succeed token "/" in a string after the class directive.

jerriclynsjohn avatar Dec 09 '19 09:12 jerriclynsjohn

This bug is not reproducible now and I'm closing the issue.

jerriclynsjohn avatar Apr 07 '20 17:04 jerriclynsjohn

I'm also having this bug.

simonbernard2 avatar Mar 01 '22 15:03 simonbernard2

I'm experiencing this too, in 3.44.2, what version are you on?

image

Also finding that Svelte doesn't recognise border-gray-400 and border-gray-400/50 as distinct attributes:

image

EDIT: Also happening if I remove the shorthand syntax:

image

EDIT: Also happening if the class doesn't clash at all:

image

I should add that I'm using windicss v3.2.1 and vite-plugin-windicss v1.5.4.

EDIT: Upgrading to svelte 3.46.4, windicss 3.5.0 and vite-plugin-windicss v1.8.1 did not fix this issue for me.

benwoodward avatar Mar 02 '22 02:03 benwoodward

Reopening since this still seems to be an issue - can someone provide a REPL showing the issue?

geoffrich avatar Mar 02 '22 16:03 geoffrich

@geoffrich

Reopening since this still seems to be an issue - can someone provide a REPL showing the issue?

Here is example repositoryI created for you with the issue in index.svelte git repo

git-no avatar Mar 15 '22 19:03 git-no

@git-no thanks, I totally forgot to do this.

benwoodward avatar Mar 15 '22 21:03 benwoodward

I have also this issue, Class directive breaks with token "/" for TailwindCSS

git-no avatar Mar 16 '22 10:03 git-no

any update on this?

filpgc avatar Sep 29 '23 11:09 filpgc

I remove my demo repository because it was not used for 1 1/2 years.

To remind, this does not work: class:bg-red-600/10={hasError}

git-no avatar Sep 29 '23 17:09 git-no

Confirmed still broken in Svelte 5. Related: #7170

Rich-Harris avatar Apr 02 '24 01:04 Rich-Harris

See https://github.com/sveltejs/svelte/issues/7170#issuecomment-2041078111 for a proposal

dummdidumm avatar Apr 06 '24 13:04 dummdidumm

Reproduction

<div class:bg-white/5={true}></div> causes an error: Expected token >.

Serator avatar May 16 '24 22:05 Serator