walkImplementation() — tailwindcss Function Reference
Architecture documentation for the walkImplementation() function in walk.ts from the tailwindcss codebase.
Entity Profile
Dependency Diagram
graph TD 96f1cc7c_88a9_c4be_b08f_696483b5d4aa["walkImplementation()"] de024372_c459_7fda_5f4a_06bad3d1cb60["walk.ts"] 96f1cc7c_88a9_c4be_b08f_696483b5d4aa -->|defined in| de024372_c459_7fda_5f4a_06bad3d1cb60 bb379d5c_9fdc_b83c_4c2a_dc331ebe547a["walk()"] bb379d5c_9fdc_b83c_4c2a_dc331ebe547a -->|calls| 96f1cc7c_88a9_c4be_b08f_696483b5d4aa style 96f1cc7c_88a9_c4be_b08f_696483b5d4aa fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
packages/tailwindcss/src/walk.ts lines 60–196
function walkImplementation<T extends { nodes?: T[] }>(
ast: T[],
enter: (node: T, ctx: VisitContext<T>) => EnterResult<T> | void = () => WalkAction.Continue,
exit: (node: T, ctx: VisitContext<T>) => ExitResult<T> | void = () => WalkAction.Continue,
) {
type StackFrame = [nodes: T[], offset: number, parent: Parent<T> | null]
let stack: Stack<StackFrame> | null = { value: [ast, 0, null], prev: null }
let ctx: VisitContext<T> = {
parent: null,
depth: 0,
path() {
let path: T[] = []
let frames: Stack<StackFrame> | null = stack
while (frames) {
let parent = frames.value[2]
if (parent) path.push(parent)
frames = frames.prev
}
path.reverse()
return path
},
}
while (stack !== null) {
let frame = stack.value
let nodes = frame[0]
let offset = frame[1]
let parent = frame[2]
// Done with this level
if (offset >= nodes.length) {
stack = stack.prev
ctx.depth -= 1
continue
}
ctx.parent = parent
// Enter phase (offsets are positive)
if (offset >= 0) {
let node = nodes[offset]
let result = enter(node, ctx) ?? WalkAction.Continue
switch (result.kind) {
case WalkKind.Continue: {
if (node.nodes && node.nodes.length > 0) {
ctx.depth += 1
stack = {
value: [node.nodes, 0, node as Parent<T>],
prev: stack,
}
}
frame[1] = ~offset // Prepare for exit phase, same offset
continue
}
case WalkKind.Stop:
return // Stop immediately
case WalkKind.Skip: {
frame[1] = ~offset // Prepare for exit phase, same offset
continue
}
case WalkKind.Replace: {
nodes.splice(offset, 1, ...result.nodes)
continue // Re-process at same offset
}
case WalkKind.ReplaceStop: {
nodes.splice(offset, 1, ...result.nodes)
return // Stop immediately
}
case WalkKind.ReplaceSkip: {
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does walkImplementation() do?
walkImplementation() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/walk.ts.
Where is walkImplementation() defined?
walkImplementation() is defined in packages/tailwindcss/src/walk.ts at line 60.
What calls walkImplementation()?
walkImplementation() is called by 1 function(s): walk.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free