Skip to content

Commit b4451e4

Browse files
committed
Add tests
1 parent 784f34c commit b4451e4

File tree

2 files changed

+86
-1
lines changed

2 files changed

+86
-1
lines changed

packages/tailwindcss-language-service/src/util/find.test.ts

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test } from 'vitest'
2-
import { findClassListsInHtmlRange } from './find'
2+
import { findClassListsInHtmlRange, findClassNameAtPosition } from './find'
33
import { js, html, pug, createDocument } from './test-utils'
44

55
test('class regex works in astro', async ({ expect }) => {
@@ -791,3 +791,87 @@ test('classAttributes find class lists inside Vue bindings', async ({ expect })
791791
},
792792
])
793793
})
794+
795+
test('Can find class name inside JS/TS functions in <script> tags (HTML)', async ({ expect }) => {
796+
let file = createDocument({
797+
name: 'file.html',
798+
lang: 'html',
799+
settings: {
800+
tailwindCSS: {
801+
classFunctions: ['clsx'],
802+
},
803+
},
804+
content: html`
805+
<script>
806+
let classes = clsx('flex relative')
807+
</script>
808+
`,
809+
})
810+
811+
let className = await findClassNameAtPosition(file.state, file.doc, {
812+
line: 1,
813+
character: 23,
814+
})
815+
816+
expect(className).toEqual({
817+
className: 'flex',
818+
range: {
819+
start: { line: 1, character: 22 },
820+
end: { line: 1, character: 26 },
821+
},
822+
relativeRange: {
823+
start: { line: 0, character: 0 },
824+
end: { line: 0, character: 4 },
825+
},
826+
classList: {
827+
classList: 'flex relative',
828+
important: undefined,
829+
range: {
830+
start: { character: 22, line: 1 },
831+
end: { character: 35, line: 1 },
832+
},
833+
},
834+
})
835+
})
836+
837+
test('Can find class name inside JS/TS functions in <script> tags (Svelte)', async ({ expect }) => {
838+
let file = createDocument({
839+
name: 'file.svelte',
840+
lang: 'svelte',
841+
settings: {
842+
tailwindCSS: {
843+
classFunctions: ['clsx'],
844+
},
845+
},
846+
content: html`
847+
<script>
848+
let classes = clsx('flex relative')
849+
</script>
850+
`,
851+
})
852+
853+
let className = await findClassNameAtPosition(file.state, file.doc, {
854+
line: 1,
855+
character: 23,
856+
})
857+
858+
expect(className).toEqual({
859+
className: 'flex',
860+
range: {
861+
start: { line: 1, character: 22 },
862+
end: { line: 1, character: 26 },
863+
},
864+
relativeRange: {
865+
start: { line: 0, character: 0 },
866+
end: { line: 0, character: 4 },
867+
},
868+
classList: {
869+
classList: 'flex relative',
870+
important: undefined,
871+
range: {
872+
start: { character: 22, line: 1 },
873+
end: { character: 35, line: 1 },
874+
},
875+
},
876+
})
877+
})

packages/tailwindcss-language-service/src/util/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ export function createState(
228228
return {
229229
enabled: true,
230230
features: [],
231+
blocklist: [],
231232
...partial,
232233
editor: {
233234
get connection(): Connection {

0 commit comments

Comments
 (0)