Skip to content

Commit 6c2dbf7

Browse files
authored
Fix theme helper handling when specifying default value (#747)
* Fix `theme` helper handling when specifying default value * Tidy
1 parent db61c88 commit 6c2dbf7

File tree

1 file changed

+22
-1
lines changed
  • packages/tailwindcss-language-service/src/util

1 file changed

+22
-1
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,22 @@ export function findHelperFunctionsInDocument(
348348
)
349349
}
350350

351+
function getFirstCommaIndex(str: string): number | null {
352+
let quoteChar: string | undefined
353+
for (let i = 0; i < str.length; i++) {
354+
let char = str[i]
355+
if (char === ',' && !quoteChar) {
356+
return i
357+
}
358+
if (!quoteChar && (char === '"' || char === "'")) {
359+
quoteChar = char
360+
} else if (char === quoteChar) {
361+
quoteChar = undefined
362+
}
363+
}
364+
return null
365+
}
366+
351367
export function findHelperFunctionsInRange(
352368
doc: TextDocument,
353369
range?: Range
@@ -360,7 +376,12 @@ export function findHelperFunctionsInRange(
360376

361377
return matches.map((match) => {
362378
let quotesBefore = ''
363-
let path = match.groups.path.replace(/['"]+$/, '').replace(/^['"]+/, (m) => {
379+
let path = match.groups.path
380+
let commaIndex = getFirstCommaIndex(path)
381+
if (commaIndex !== null) {
382+
path = path.slice(0, commaIndex).trimEnd()
383+
}
384+
path = path.replace(/['"]+$/, '').replace(/^['"]+/, (m) => {
364385
quotesBefore = m
365386
return ''
366387
})

0 commit comments

Comments
 (0)