|
1 | 1 | import { test } from 'vitest'
|
2 |
| -import { findClassListsInHtmlRange } from './find' |
| 2 | +import { findClassListsInHtmlRange, findClassNameAtPosition } from './find' |
3 | 3 | import { js, html, pug, createDocument } from './test-utils'
|
4 | 4 |
|
5 | 5 | test('class regex works in astro', async ({ expect }) => {
|
@@ -791,3 +791,87 @@ test('classAttributes find class lists inside Vue bindings', async ({ expect })
|
791 | 791 | },
|
792 | 792 | ])
|
793 | 793 | })
|
| 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 | +}) |
0 commit comments