Skip to content

Commit 962d4ea

Browse files
author
Javier Ugarte
committed
Fix class name matching in javascript right after opening square brackets
1 parent 3d3f866 commit 962d4ea

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,3 +1081,30 @@ test('class functions work inside astro code fences', async ({ expect }) => {
10811081
},
10821082
])
10831083
})
1084+
1085+
test('classFunctions are detected inside of arrays in javascript just after opening bracket', async ({ expect }) => {
1086+
let file = createDocument({
1087+
name: 'file.js',
1088+
lang: 'javascript',
1089+
settings: {
1090+
tailwindCSS: {
1091+
classFunctions: ['cn'],
1092+
},
1093+
},
1094+
content: js`
1095+
const list = [cn('relative')]
1096+
`,
1097+
})
1098+
1099+
let classLists = await findClassListsInHtmlRange(file.state, file.doc, 'js')
1100+
1101+
expect(classLists).toEqual([
1102+
{
1103+
classList: 'relative',
1104+
range: {
1105+
start: { line: 0, character: 18 },
1106+
end: { line: 0, character: 26 },
1107+
},
1108+
},
1109+
])
1110+
})

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export function matchClassFunctions(text: string, fnNames: string[]): RegExpMatc
179179
// - It needs to be in an expression position — so it must be preceded by
180180
// whitespace, parens, curlies, commas, whitespace, etc…
181181
// - It must look like a fn call or a tagged template literal
182-
let FN_NAMES = /(?<=^|[:=,;\s{()])([\p{ID_Start}$_][\p{ID_Continue}$_.]*)[(`]/dgiu
182+
let FN_NAMES = /(?<=^|[:=,;\s{()\[])([\p{ID_Start}$_][\p{ID_Continue}$_.]*)[(`]/dgiu
183183
let foundFns = findAll(FN_NAMES, text)
184184

185185
// 3. Match against the function names in the document

0 commit comments

Comments
 (0)