Skip to content

Commit ec94c29

Browse files
committed
Guard against recursive theme key lookup
1 parent bd1fc8c commit ec94c29

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

packages/tailwindcss-language-service/src/util/rewriting/var-fallbacks.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,25 @@ import { resolveVariableValue } from './lookup'
33
import { replaceCssVars } from './replacements'
44

55
export function replaceCssVarsWithFallbacks(state: State, str: string): string {
6+
let seen = new Set<string>()
7+
68
return replaceCssVars(str, {
79
replace({ name, fallback }) {
810
// Replace with the value from the design system first. The design system
911
// take precedences over other sources as that emulates the behavior of a
1012
// browser where the fallback is only used if the variable is defined.
1113
if (state.designSystem && name.startsWith('--')) {
14+
// TODO: This isn't quite right as we might skip expanding a variable
15+
// that should be expanded
16+
if (seen.has(name)) return null
1217
let value = resolveVariableValue(state.designSystem, name)
13-
if (value !== null) return value
18+
if (value !== null) {
19+
if (value.includes('var(')) {
20+
seen.add(name)
21+
}
22+
23+
return value
24+
}
1425
}
1526

1627
if (fallback) {

0 commit comments

Comments
 (0)