Skip to content

Commit e7d7f37

Browse files
committed
replace walkDepth with walk#exit
1 parent 0120c7a commit e7d7f37

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

packages/tailwindcss/src/intellisense.ts

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { styleRule, walkDepth } from './ast'
1+
import { styleRule } from './ast'
22
import { applyVariant } from './compile'
33
import type { DesignSystem } from './design-system'
44
import { compare } from './utils/compare'
55
import { DefaultMap } from './utils/default-map'
6+
import { walk } from './walk'
67
export { canonicalizeCandidates, type CanonicalizeOptions } from './canonicalize-candidates'
78

89
interface ClassMetadata {
@@ -180,42 +181,47 @@ export function getVariants(design: DesignSystem) {
180181

181182
// Produce v3-style selector strings in the face of nested rules
182183
// this is more visible for things like group-*, not-*, etc…
183-
walkDepth(node.nodes, (node, { path }) => {
184-
if (node.kind !== 'rule' && node.kind !== 'at-rule') return
185-
if (node.nodes.length > 0) return
184+
walk(node.nodes, {
185+
exit(node, ctx) {
186+
if (node.kind !== 'rule' && node.kind !== 'at-rule') return
187+
if (node.nodes.length > 0) return
186188

187-
// Sort at-rules before style rules
188-
path.sort((a, b) => {
189-
let aIsAtRule = a.kind === 'at-rule'
190-
let bIsAtRule = b.kind === 'at-rule'
189+
let path = ctx.path()
190+
path.push(node)
191191

192-
if (aIsAtRule && !bIsAtRule) return -1
193-
if (!aIsAtRule && bIsAtRule) return 1
192+
// Sort at-rules before style rules
193+
path.sort((a, b) => {
194+
let aIsAtRule = a.kind === 'at-rule'
195+
let bIsAtRule = b.kind === 'at-rule'
194196

195-
return 0
196-
})
197+
if (aIsAtRule && !bIsAtRule) return -1
198+
if (!aIsAtRule && bIsAtRule) return 1
197199

198-
// A list of the selectors / at rules encountered to get to this point
199-
let group = path.flatMap((node) => {
200-
if (node.kind === 'rule') {
201-
return node.selector === '&' ? [] : [node.selector]
202-
}
200+
return 0
201+
})
203202

204-
if (node.kind === 'at-rule') {
205-
return [`${node.name} ${node.params}`]
206-
}
203+
// A list of the selectors / at rules encountered to get to this point
204+
let group = path.flatMap((node) => {
205+
if (node.kind === 'rule') {
206+
return node.selector === '&' ? [] : [node.selector]
207+
}
207208

208-
return []
209-
})
209+
if (node.kind === 'at-rule') {
210+
return [`${node.name} ${node.params}`]
211+
}
210212

211-
// Build a v3-style nested selector
212-
let selector = ''
213+
return []
214+
})
213215

214-
for (let i = group.length - 1; i >= 0; i--) {
215-
selector = selector === '' ? group[i] : `${group[i]} { ${selector} }`
216-
}
216+
// Build a v3-style nested selector
217+
let selector = ''
218+
219+
for (let i = group.length - 1; i >= 0; i--) {
220+
selector = selector === '' ? group[i] : `${group[i]} { ${selector} }`
221+
}
217222

218-
selectors.push(selector)
223+
selectors.push(selector)
224+
},
219225
})
220226

221227
return selectors

0 commit comments

Comments
 (0)