@@ -2,7 +2,6 @@ import { walk, WalkAction } from '../../../../tailwindcss/src/ast'
22import { type Candidate , type Variant } from '../../../../tailwindcss/src/candidate'
33import type { Config } from '../../../../tailwindcss/src/compat/plugin-api'
44import type { DesignSystem } from '../../../../tailwindcss/src/design-system'
5- import * as ValueParser from '../../../../tailwindcss/src/value-parser'
65import { printCandidate } from '../candidates'
76
87export function automaticVarInjection (
@@ -74,32 +73,16 @@ export function automaticVarInjection(
7473}
7574
7675function injectVar ( value : string ) : { value : string ; didChange : boolean } {
77- let ast = ValueParser . parse ( value )
78-
7976 let didChange = false
80- for ( let [ idx , node ] of ast . entries ( ) ) {
81- // Convert `--my-color` to `var(--my-color)`
82- // Except if:
83- // - It's a function like `--spacing(…)`
84- // - It's preceeded by a space, e.g.: `bg-[_--my-color]` -> `bg-[--my-color]`
85- if (
86- node . kind === 'word' &&
87- node . value . startsWith ( '--' ) &&
88- ! ( ast [ idx - 1 ] ?. kind === 'separator' && ast [ idx - 1 ] ?. value === ' ' )
89- ) {
90- node . value = `var(${ node . value } )`
91- didChange = true
92- }
93-
94- // Remove the space "hack" before a variable. E.g.: `bg-[_--my-color]` ->
95- // `bg-[--my-color]`
96- else if ( node . kind === 'separator' && node . value === ' ' ) {
97- ast . splice ( idx , 1 )
98- didChange = true
99- }
77+ if ( value . startsWith ( '--' ) && ! value . includes ( '(' ) ) {
78+ value = `var(${ value } )`
79+ didChange = true
80+ } else if ( value . startsWith ( ' --' ) ) {
81+ value = value . slice ( 1 )
82+ didChange = true
10083 }
10184
102- return { value : ValueParser . toCss ( ast ) , didChange }
85+ return { value, didChange }
10386}
10487
10588function injectVarIntoVariant ( designSystem : DesignSystem , variant : Variant ) : boolean {
0 commit comments