File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed
packages/tailwindcss-language-server/src/util/v4 Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import type { Jiti } from 'jiti/lib/types'
1010import { assets } from './assets'
1111import { plugins } from './plugins'
1212import { AstNode , cloneAstNode , parse } from '@tailwindcss/language-service/src/css'
13+ import { walk , WalkAction } from '@tailwindcss/language-service/src/util/walk'
1314
1415const HAS_V4_IMPORT = / @ i m p o r t \s * (?: ' t a i l w i n d c s s ' | " t a i l w i n d c s s " ) /
1516const HAS_V4_THEME = / @ t h e m e \s * \{ /
@@ -240,7 +241,26 @@ export async function loadDesignSystem(
240241 let str = css [ idx ]
241242
242243 if ( Array . isArray ( str ) ) {
243- cache [ cls ] = str
244+ let ast = str . map ( cloneAstNode )
245+
246+ // Rewrite at-rules with zero nodes to act as if they have no body
247+ //
248+ // At a future time we'll only do this conditionally for earlier
249+ // Tailwind CSS v4 versions. We have to clone the AST *first*
250+ // because if the AST was shared with Tailwind CSS internals
251+ // and we mutated it we could break things.
252+ walk ( ast , ( node ) => {
253+ if ( node . kind !== 'at-rule' ) return WalkAction . Continue
254+ if ( node . nodes === null ) return WalkAction . Continue
255+ if ( node . nodes . length !== 0 ) return WalkAction . Continue
256+
257+ node . nodes = null
258+
259+ return WalkAction . Continue
260+ } )
261+
262+ cache [ cls ] = ast
263+
244264 continue
245265 }
246266
You can’t perform that action at this time.
0 commit comments