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
  c155249e_9c85_fd4e_2707_8f98f0ab5228["printArbitraryValueCache()"]
  0638028e_f2f7_8e77_2f19_1bd2ce4b2d6a["parse()"]
  c155249e_9c85_fd4e_2707_8f98f0ab5228 -->|calls| 0638028e_f2f7_8e77_2f19_1bd2ce4b2d6a
  e9d556bc_f22d_356c_1bd2_27442c34b5c7["walk()"]
  c155249e_9c85_fd4e_2707_8f98f0ab5228 -->|calls| e9d556bc_f22d_356c_1bd2_27442c34b5c7
  e73ecbca_812d_ed91_0c5d_af2f6a61ea6b["recursivelyEscapeUnderscores()"]
  c155249e_9c85_fd4e_2707_8f98f0ab5228 -->|calls| e73ecbca_812d_ed91_0c5d_af2f6a61ea6b
  f66dddcc_be1c_d082_4eb0_ec82ce3bf380["toCss()"]
  c155249e_9c85_fd4e_2707_8f98f0ab5228 -->|calls| f66dddcc_be1c_d082_4eb0_ec82ce3bf380
  style c155249e_9c85_fd4e_2707_8f98f0ab5228 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)
})

Subdomains

Frequently Asked Questions

What does printArbitraryValueCache() do?
printArbitraryValueCache() is a function in the tailwindcss codebase.
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