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
  f9a17feb_4681_8aa1_f2b8_21e3641747be["printArbitraryValueCache()"]
  669e6a28_c71f_3c5e_9c53_915cede7da78["candidate.ts"]
  f9a17feb_4681_8aa1_f2b8_21e3641747be -->|defined in| 669e6a28_c71f_3c5e_9c53_915cede7da78
  2d6c8361_96d8_df0d_ca51_c62f179fdc73["parse()"]
  f9a17feb_4681_8aa1_f2b8_21e3641747be -->|calls| 2d6c8361_96d8_df0d_ca51_c62f179fdc73
  ed78da58_8727_ad98_120c_61f35cea357a["walk()"]
  f9a17feb_4681_8aa1_f2b8_21e3641747be -->|calls| ed78da58_8727_ad98_120c_61f35cea357a
  90af3061_98c6_bbc0_b56e_ef2a73fdc21a["recursivelyEscapeUnderscores()"]
  f9a17feb_4681_8aa1_f2b8_21e3641747be -->|calls| 90af3061_98c6_bbc0_b56e_ef2a73fdc21a
  e79308d2_473f_b6d6_3b04_e4e55c2708d3["toCss()"]
  f9a17feb_4681_8aa1_f2b8_21e3641747be -->|calls| e79308d2_473f_b6d6_3b04_e4e55c2708d3
  style f9a17feb_4681_8aa1_f2b8_21e3641747be 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