|
1 | | -import { styleRule, walkDepth } from './ast' |
| 1 | +import { styleRule } from './ast' |
2 | 2 | import { applyVariant } from './compile' |
3 | 3 | import type { DesignSystem } from './design-system' |
4 | 4 | import { compare } from './utils/compare' |
5 | 5 | import { DefaultMap } from './utils/default-map' |
| 6 | +import { walk } from './walk' |
6 | 7 | export { canonicalizeCandidates, type CanonicalizeOptions } from './canonicalize-candidates' |
7 | 8 |
|
8 | 9 | interface ClassMetadata { |
@@ -180,42 +181,47 @@ export function getVariants(design: DesignSystem) { |
180 | 181 |
|
181 | 182 | // Produce v3-style selector strings in the face of nested rules |
182 | 183 | // 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 |
186 | 188 |
|
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) |
191 | 191 |
|
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' |
194 | 196 |
|
195 | | - return 0 |
196 | | - }) |
| 197 | + if (aIsAtRule && !bIsAtRule) return -1 |
| 198 | + if (!aIsAtRule && bIsAtRule) return 1 |
197 | 199 |
|
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 | + }) |
203 | 202 |
|
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 | + } |
207 | 208 |
|
208 | | - return [] |
209 | | - }) |
| 209 | + if (node.kind === 'at-rule') { |
| 210 | + return [`${node.name} ${node.params}`] |
| 211 | + } |
210 | 212 |
|
211 | | - // Build a v3-style nested selector |
212 | | - let selector = '' |
| 213 | + return [] |
| 214 | + }) |
213 | 215 |
|
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 | + } |
217 | 222 |
|
218 | | - selectors.push(selector) |
| 223 | + selectors.push(selector) |
| 224 | + }, |
219 | 225 | }) |
220 | 226 |
|
221 | 227 | return selectors |
|
0 commit comments