Skip to content

Commit ea3c5a3

Browse files
committed
Add test for classAttributes matching variable names
This was 100% a bug that this behavior got introduced but at this point it’s shipped and people might rely on it / want the behavior. So I’m explicitly encoding this in a test so it doesn’t break later when the big parsing refactor lands.
1 parent d561b61 commit ea3c5a3

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

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

+53
Original file line numberDiff line numberDiff line change
@@ -682,3 +682,56 @@ test('classFunctions should only match in JS-like contexts', async ({ expect })
682682
},
683683
])
684684
})
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+
})

0 commit comments

Comments
 (0)