|
1 | 1 | import { test } from 'vitest'
|
2 | 2 | import { findClassListsInHtmlRange } from './find'
|
3 |
| -import { js, html, createDocument } from './test-utils' |
| 3 | +import { js, html, pug, createDocument } from './test-utils' |
4 | 4 |
|
5 | 5 | test('class regex works in astro', async ({ expect }) => {
|
6 | 6 | let file = createDocument({
|
@@ -682,3 +682,112 @@ test('classFunctions should only match in JS-like contexts', async ({ expect })
|
682 | 682 | },
|
683 | 683 | ])
|
684 | 684 | })
|
| 685 | + |
| 686 | +test('classAttributes find class lists inside variables in JS(X)/TS(X)', async ({ expect }) => { |
| 687 | + let file = createDocument({ |
| 688 | + name: 'file.html', |
| 689 | + lang: 'javascript', |
| 690 | + settings: { |
| 691 | + tailwindCSS: { |
| 692 | + classAttributes: ['className'], |
| 693 | + }, |
| 694 | + }, |
| 695 | + content: js` |
| 696 | + let className = { |
| 697 | + a: "relative flex", |
| 698 | + nested: { |
| 699 | + b: "relative flex", |
| 700 | + }, |
| 701 | + inFn: fn({ |
| 702 | + c: "relative flex", |
| 703 | + }) |
| 704 | + } |
| 705 | +
|
| 706 | + let other = { |
| 707 | + a: "relative flex", |
| 708 | + } |
| 709 | + `, |
| 710 | + }) |
| 711 | + |
| 712 | + let classLists = await findClassListsInHtmlRange(file.state, file.doc, 'js') |
| 713 | + |
| 714 | + expect(classLists).toEqual([ |
| 715 | + { |
| 716 | + classList: 'relative flex', |
| 717 | + range: { |
| 718 | + start: { line: 1, character: 6 }, |
| 719 | + end: { line: 1, character: 19 }, |
| 720 | + }, |
| 721 | + }, |
| 722 | + { |
| 723 | + classList: 'relative flex', |
| 724 | + range: { |
| 725 | + start: { line: 3, character: 8 }, |
| 726 | + end: { line: 3, character: 21 }, |
| 727 | + }, |
| 728 | + }, |
| 729 | + { |
| 730 | + classList: 'relative flex', |
| 731 | + range: { |
| 732 | + start: { line: 6, character: 8 }, |
| 733 | + end: { line: 6, character: 21 }, |
| 734 | + }, |
| 735 | + }, |
| 736 | + ]) |
| 737 | +}) |
| 738 | + |
| 739 | +test('classAttributes find class lists inside pug', async ({ expect }) => { |
| 740 | + let file = createDocument({ |
| 741 | + name: 'file.pug', |
| 742 | + lang: 'pug', |
| 743 | + settings: { |
| 744 | + tailwindCSS: { |
| 745 | + classAttributes: ['className'], |
| 746 | + }, |
| 747 | + }, |
| 748 | + content: pug` |
| 749 | + div(classNAme="relative flex") |
| 750 | + `, |
| 751 | + }) |
| 752 | + |
| 753 | + let classLists = await findClassListsInHtmlRange(file.state, file.doc, 'js') |
| 754 | + |
| 755 | + expect(classLists).toEqual([ |
| 756 | + { |
| 757 | + classList: 'relative flex', |
| 758 | + range: { |
| 759 | + start: { line: 0, character: 15 }, |
| 760 | + end: { line: 0, character: 28 }, |
| 761 | + }, |
| 762 | + }, |
| 763 | + ]) |
| 764 | +}) |
| 765 | + |
| 766 | +test('classAttributes find class lists inside Vue bindings', async ({ expect }) => { |
| 767 | + let file = createDocument({ |
| 768 | + name: 'file.pug', |
| 769 | + lang: 'vue', |
| 770 | + settings: { |
| 771 | + tailwindCSS: { |
| 772 | + classAttributes: ['class'], |
| 773 | + }, |
| 774 | + }, |
| 775 | + content: html` |
| 776 | + <template> |
| 777 | + <div :class="{'relative flex': true}"></div> |
| 778 | + </template> |
| 779 | + `, |
| 780 | + }) |
| 781 | + |
| 782 | + let classLists = await findClassListsInHtmlRange(file.state, file.doc, 'js') |
| 783 | + |
| 784 | + expect(classLists).toEqual([ |
| 785 | + { |
| 786 | + classList: 'relative flex', |
| 787 | + range: { |
| 788 | + start: { line: 1, character: 17 }, |
| 789 | + end: { line: 1, character: 30 }, |
| 790 | + }, |
| 791 | + }, |
| 792 | + ]) |
| 793 | +}) |
0 commit comments