Simplify code
This commit is contained in:
parent
381d336eb1
commit
b86387e532
2 changed files with 8 additions and 7 deletions
|
|
@ -79,19 +79,20 @@ export function walk(
|
|||
node: AstNode,
|
||||
utils: {
|
||||
parent: AstNode | null
|
||||
ancestors: AstNode[]
|
||||
path: AstNode[]
|
||||
replaceWith(newNode: AstNode | AstNode[]): void
|
||||
},
|
||||
) => void | WalkAction,
|
||||
parent: AstNode | null = null,
|
||||
ancestors: AstNode[] = [],
|
||||
parentPath: AstNode[] = [],
|
||||
) {
|
||||
for (let i = 0; i < ast.length; i++) {
|
||||
let node = ast[i]
|
||||
let path = [node, ...parentPath]
|
||||
let status =
|
||||
visit(node, {
|
||||
parent,
|
||||
ancestors,
|
||||
path,
|
||||
replaceWith(newNode) {
|
||||
ast.splice(i, 1, ...(Array.isArray(newNode) ? newNode : [newNode]))
|
||||
// We want to visit the newly replaced node(s), which start at the
|
||||
|
|
@ -108,7 +109,7 @@ export function walk(
|
|||
if (status === WalkAction.Skip) continue
|
||||
|
||||
if (node.kind === 'rule') {
|
||||
walk(node.nodes, visit, node, [node, ...ancestors])
|
||||
walk(node.nodes, visit, node, path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -208,7 +208,7 @@ export function createVariants(theme: Theme): Variants {
|
|||
|
||||
let groups: string[] = []
|
||||
|
||||
walk([ruleNode], (node, { ancestors }) => {
|
||||
walk([ruleNode], (node, { path }) => {
|
||||
if (node.kind !== 'rule') return WalkAction.Continue
|
||||
|
||||
// Skip past at-rules, and continue traversing the children of the at-rule
|
||||
|
|
@ -217,10 +217,10 @@ export function createVariants(theme: Theme): Variants {
|
|||
// 1. Walk the tree until we find `@slot`
|
||||
if (node.nodes.length !== 0) return WalkAction.Continue
|
||||
|
||||
let selectors = [`:not(${node.selector.replaceAll('&', '*')})`]
|
||||
let selectors = []
|
||||
|
||||
// 2. Collect the selectors of the parents
|
||||
for (let ancestor of ancestors) {
|
||||
for (let ancestor of path) {
|
||||
if (ancestor.kind !== 'rule') continue
|
||||
|
||||
// Skip past at-rules, and continue traversing the children of the at-rule
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue