Home / Function/ printArbitraryValueCache() — tailwindcss Function Reference

printArbitraryValueCache() — tailwindcss Function Reference

Architecture documentation for the printArbitraryValueCache() function in candidate.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  fa7106d0_b629_ab06_9635_b04e9e0c20f0["printArbitraryValueCache()"]
  ba6fca27_7720_5839_0f92_bc2abb8db636["candidate.ts"]
  fa7106d0_b629_ab06_9635_b04e9e0c20f0 -->|defined in| ba6fca27_7720_5839_0f92_bc2abb8db636
  49a8c506_c50e_ed4b_5a0e_0393edae2b6f["parse()"]
  fa7106d0_b629_ab06_9635_b04e9e0c20f0 -->|calls| 49a8c506_c50e_ed4b_5a0e_0393edae2b6f
  4982d9ce_98d4_85d9_44af_7cc47b93c482["walk()"]
  fa7106d0_b629_ab06_9635_b04e9e0c20f0 -->|calls| 4982d9ce_98d4_85d9_44af_7cc47b93c482
  6ed70775_e947_c74d_9604_e478b2ca9982["recursivelyEscapeUnderscores()"]
  fa7106d0_b629_ab06_9635_b04e9e0c20f0 -->|calls| 6ed70775_e947_c74d_9604_e478b2ca9982
  d6cf80a6_8130_7069_e60d_09156f156b67["toCss()"]
  fa7106d0_b629_ab06_9635_b04e9e0c20f0 -->|calls| d6cf80a6_8130_7069_e60d_09156f156b67
  style fa7106d0_b629_ab06_9635_b04e9e0c20f0 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/candidate.ts lines 1033–1088

const printArbitraryValueCache = new DefaultMap<string, string>((input) => {
  let ast = ValueParser.parse(input)

  let drop = new Set<ValueParser.ValueAstNode>()

  walk(ast, (node, ctx) => {
    let parentArray = ctx.parent === null ? ast : (ctx.parent.nodes ?? [])

    // Handle operators (e.g.: inside of `calc(…)`)
    if (
      node.kind === 'word' &&
      // Operators
      (node.value === '+' || node.value === '-' || node.value === '*' || node.value === '/')
    ) {
      let idx = parentArray.indexOf(node) ?? -1

      // This should not be possible
      if (idx === -1) return

      let previous = parentArray[idx - 1]
      if (previous?.kind !== 'separator' || previous.value !== ' ') return

      let next = parentArray[idx + 1]
      if (next?.kind !== 'separator' || next.value !== ' ') return

      drop.add(previous)
      drop.add(next)
    }

    // Leading and trailing whitespace
    else if (node.kind === 'separator' && node.value.length > 0 && node.value.trim() === '') {
      if (parentArray[0] === node || parentArray[parentArray.length - 1] === node) {
        drop.add(node)
      }
    }

    // Whitespace around `,` separators can be removed.
    // E.g.: `min(1px , 2px)` -> `min(1px,2px)`
    else if (node.kind === 'separator' && node.value.trim() === ',') {
      node.value = ','
    }
  })

  if (drop.size > 0) {
    walk(ast, (node) => {
      if (drop.has(node)) {
        drop.delete(node)
        return WalkAction.ReplaceSkip([])
      }
    })
  }

  recursivelyEscapeUnderscores(ast)

  return ValueParser.toCss(ast)
})

Domain

Subdomains

Frequently Asked Questions

What does printArbitraryValueCache() do?
printArbitraryValueCache() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/candidate.ts.
Where is printArbitraryValueCache() defined?
printArbitraryValueCache() is defined in packages/tailwindcss/src/candidate.ts at line 1033.
What does printArbitraryValueCache() call?
printArbitraryValueCache() calls 4 function(s): parse, recursivelyEscapeUnderscores, toCss, walk.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free