Home / Function/ injectVar() — tailwindcss Function Reference

injectVar() — tailwindcss Function Reference

Architecture documentation for the injectVar() function in migrate-automatic-var-injection.ts from the tailwindcss codebase.

Entity Profile

Dependency Diagram

graph TD
  0f7313a5_adb3_4061_aabb_d87ca01352a1["injectVar()"]
  0064e910_a1e5_1dd9_95f1_ac33aef2f9b1["migrate-automatic-var-injection.ts"]
  0f7313a5_adb3_4061_aabb_d87ca01352a1 -->|defined in| 0064e910_a1e5_1dd9_95f1_ac33aef2f9b1
  d9972d7e_4ead_d84f_3f97_3cc5f06273b9["migrateAutomaticVarInjection()"]
  d9972d7e_4ead_d84f_3f97_3cc5f06273b9 -->|calls| 0f7313a5_adb3_4061_aabb_d87ca01352a1
  8d5f9b9b_87e8_82f7_232d_21a34c01e2f4["injectVarIntoVariant()"]
  8d5f9b9b_87e8_82f7_232d_21a34c01e2f4 -->|calls| 0f7313a5_adb3_4061_aabb_d87ca01352a1
  49a8c506_c50e_ed4b_5a0e_0393edae2b6f["parse()"]
  0f7313a5_adb3_4061_aabb_d87ca01352a1 -->|calls| 49a8c506_c50e_ed4b_5a0e_0393edae2b6f
  style 0f7313a5_adb3_4061_aabb_d87ca01352a1 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/@tailwindcss-upgrade/src/codemods/template/migrate-automatic-var-injection.ts lines 76–101

function injectVar(value: string): { value: string; didChange: boolean } {
  let didChange = false
  if (value.startsWith('--')) {
    // E.g.:
    //
    // - `--my-color` → `var(--my-color)`             Convert variable
    // - `--my-color,red` → `var(--my-color,red)`     Convert variable with fallback
    // - `--theme(color.red)` → `--theme(color.red)`  Do not convert functions
    //
    if (
      // No `(` definitely means there is no function
      !value.includes('(') ||
      // There could be a function call in the fallback value, but it cannot be
      // top-level, so we can safely check the first part
      ValueParser.parse(value)[0]?.kind !== 'function'
    ) {
      value = `var(${value})`
      didChange = true
    }
  } else if (value.startsWith(' --')) {
    value = value.slice(1)
    didChange = true
  }

  return { value, didChange }
}

Subdomains

Calls

Frequently Asked Questions

What does injectVar() do?
injectVar() is a function in the tailwindcss codebase, defined in packages/@tailwindcss-upgrade/src/codemods/template/migrate-automatic-var-injection.ts.
Where is injectVar() defined?
injectVar() is defined in packages/@tailwindcss-upgrade/src/codemods/template/migrate-automatic-var-injection.ts at line 76.
What does injectVar() call?
injectVar() calls 1 function(s): parse.
What calls injectVar()?
injectVar() is called by 2 function(s): injectVarIntoVariant, migrateAutomaticVarInjection.

Analyze Your Own Codebase

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

Try Supermodel Free