Home / Function/ walkImplementation() — tailwindcss Function Reference

walkImplementation() — tailwindcss Function Reference

Architecture documentation for the walkImplementation() function in walk.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  1ed63abc_1a96_e860_3fc7_956298faeb50["walkImplementation()"]
  1b8f1c54_b1e9_e18d_0719_b7ad92808185["walk.ts"]
  1ed63abc_1a96_e860_3fc7_956298faeb50 -->|defined in| 1b8f1c54_b1e9_e18d_0719_b7ad92808185
  4982d9ce_98d4_85d9_44af_7cc47b93c482["walk()"]
  4982d9ce_98d4_85d9_44af_7cc47b93c482 -->|calls| 1ed63abc_1a96_e860_3fc7_956298faeb50
  style 1ed63abc_1a96_e860_3fc7_956298faeb50 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

Called By

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