Skip to content

Commit 8101767

Browse files
committed
Tweak AST returned by the design system
1 parent 8363b4a commit 8101767

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

packages/tailwindcss-language-server/src/util/v4/design-system.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { Jiti } from 'jiti/lib/types'
1010
import { assets } from './assets'
1111
import { plugins } from './plugins'
1212
import { AstNode, cloneAstNode, parse } from '@tailwindcss/language-service/src/css'
13+
import { walk, WalkAction } from '@tailwindcss/language-service/src/util/walk'
1314

1415
const HAS_V4_IMPORT = /@import\s*(?:'tailwindcss'|"tailwindcss")/
1516
const HAS_V4_THEME = /@theme\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

0 commit comments

Comments
 (0)