Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions packages/tailwindcss-language-service/src/util/find.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1081,3 +1081,30 @@ test('class functions work inside astro code fences', async ({ expect }) => {
},
])
})

test('classFunctions are detected inside of arrays in javascript just after opening bracket', async ({ expect }) => {
let file = createDocument({
name: 'file.js',
lang: 'javascript',
settings: {
tailwindCSS: {
classFunctions: ['cn'],
},
},
content: js`
const list = [cn('relative')]
`,
})

let classLists = await findClassListsInHtmlRange(file.state, file.doc, 'js')

expect(classLists).toEqual([
{
classList: 'relative',
range: {
start: { line: 0, character: 18 },
end: { line: 0, character: 26 },
},
},
])
})
2 changes: 1 addition & 1 deletion packages/tailwindcss-language-service/src/util/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function matchClassFunctions(text: string, fnNames: string[]): RegExpMatc
// - It needs to be in an expression position — so it must be preceded by
// whitespace, parens, curlies, commas, whitespace, etc…
// - It must look like a fn call or a tagged template literal
let FN_NAMES = /(?<=^|[:=,;\s{()])([\p{ID_Start}$_][\p{ID_Continue}$_.]*)[(`]/dgiu
let FN_NAMES = /(?<=^|[:=,;\s{()\[])([\p{ID_Start}$_][\p{ID_Continue}$_.]*)[(`]/dgiu
let foundFns = findAll(FN_NAMES, text)

// 3. Match against the function names in the document
Expand Down
2 changes: 1 addition & 1 deletion packages/vscode-tailwindcss/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Prerelease

- Nothing yet!
- Match class functions that appear after an opening square bracket ([#1428](https://github.com/tailwindlabs/tailwindcss-intellisense/pull/1428))

## 0.14.25

Expand Down