Skip to content

Commit 975ca89

Browse files
committed
Tweak regex
1 parent dbf0b74 commit 975ca89

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,42 @@ test('Can find helper functions in CSS', async ({ expect }) => {
10201020
])
10211021
})
10221022

1023+
test('Helper functions can start with --', async ({ expect }) => {
1024+
let file = createDocument({
1025+
name: 'file.css',
1026+
lang: 'css',
1027+
settings: {
1028+
tailwindCSS: {
1029+
classFunctions: ['clsx'],
1030+
},
1031+
},
1032+
content: `
1033+
.a { color: --theme(foo); }
1034+
.a { color: --theme(--theme(foo)); }
1035+
`,
1036+
})
1037+
1038+
let fns = findHelperFunctionsInDocument(file.state, file.doc)
1039+
1040+
expect(fns).toEqual([
1041+
{
1042+
helper: 'theme',
1043+
path: 'foo',
1044+
ranges: { full: range(1, 26, 1, 29), path: range(1, 26, 1, 29) },
1045+
},
1046+
{
1047+
helper: 'theme',
1048+
path: '--theme(foo)',
1049+
ranges: { full: range(2, 26, 2, 38), path: range(2, 26, 2, 38) },
1050+
},
1051+
{
1052+
helper: 'theme',
1053+
path: 'foo',
1054+
ranges: { full: range(2, 34, 2, 37), path: range(2, 34, 2, 37) },
1055+
},
1056+
])
1057+
})
1058+
10231059
test('Can find helper functions in SCSS', async ({ expect }) => {
10241060
let file = createDocument({
10251061
name: 'file.scss',

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ export function findHelperFunctionsInRange(
406406
let text = getTextWithoutComments(doc, 'css', range)
407407

408408
// Find every instance of a helper function
409-
let matches = findAll(/\b(?<![-$%#.])(?<helper>config|theme|--theme|var)\(/g, text)
409+
let matches = findAll(
410+
/(?:\b|(?<=[\s\W]))(?<![-$%#.])(?<helper>config|theme|--theme|var)\(/g,
411+
text,
412+
)
410413

411414
// Eliminate matches that are attached to an `@import`
412415
matches = matches.filter((match) => {

0 commit comments

Comments
 (0)