diff --git a/packages/tailwindcss/src/ast.ts b/packages/tailwindcss/src/ast.ts index fb7d5b78c..4074ff1be 100644 --- a/packages/tailwindcss/src/ast.ts +++ b/packages/tailwindcss/src/ast.ts @@ -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) } } } diff --git a/packages/tailwindcss/src/variants.ts b/packages/tailwindcss/src/variants.ts index 4af361a26..47e9ae16b 100644 --- a/packages/tailwindcss/src/variants.ts +++ b/packages/tailwindcss/src/variants.ts @@ -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