Home / Function/ parse() — tailwindcss Function Reference

parse() — tailwindcss Function Reference

Architecture documentation for the parse() function in css-parser.ts from the tailwindcss codebase.

Function typescript OxideEngine Extractor calls 5 called by 10

Entity Profile

Dependency Diagram

graph TD
  b8a15b09_3dfb_7181_b1f8_368422e178e4["parse()"]
  54851997_7544_bab2_96ab_548e5f5df205["css-parser.ts"]
  b8a15b09_3dfb_7181_b1f8_368422e178e4 -->|defined in| 54851997_7544_bab2_96ab_548e5f5df205
  fa6eaba6_9ce1_3f40_275c_1ab85a97a856["rewriteUrls()"]
  fa6eaba6_9ce1_3f40_275c_1ab85a97a856 -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  1e8a63fb_d767_393f_749f_708105a54264["expand()"]
  1e8a63fb_d767_393f_749f_708105a54264 -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  9c33d37f_aea4_85fa_1eb9_f13429950630["compile()"]
  9c33d37f_aea4_85fa_1eb9_f13429950630 -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  28a4a0ba_405e_2b1a_b1d1_5f3944486a8f["__unstable__loadDesignSystem()"]
  28a4a0ba_405e_2b1a_b1d1_5f3944486a8f -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  5bda8ff2_4761_4c27_d724_a4e36f403452["analyze()"]
  5bda8ff2_4761_4c27_d724_a4e36f403452 -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  47b4c875_7e44_6ff9_fb06_16ecf9254223["optimizeAst()"]
  47b4c875_7e44_6ff9_fb06_16ecf9254223 -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  5713e78d_1b82_b74a_13d9_da852136ec3c["substituteAtImports()"]
  5713e78d_1b82_b74a_13d9_da852136ec3c -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  2efa0a66_c375_c031_24ad_1f7509bb9b14["buildPluginApi()"]
  2efa0a66_c375_c031_24ad_1f7509bb9b14 -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  e4fb3115_ed56_fc92_888c_5174adbc3ff5["parseVariantValue()"]
  e4fb3115_ed56_fc92_888c_5174adbc3ff5 -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  a0e7559e_bcba_7de4_f51b_c146c7957bfd["replaceNestedClassNameReferences()"]
  a0e7559e_bcba_7de4_f51b_c146c7957bfd -->|calls| b8a15b09_3dfb_7181_b1f8_368422e178e4
  96bdb9bb_93af_2fac_25bd_5a2e67895fa7["comment()"]
  b8a15b09_3dfb_7181_b1f8_368422e178e4 -->|calls| 96bdb9bb_93af_2fac_25bd_5a2e67895fa7
  1079aed1_4f38_ebc0_2e2d_4c9d9cfb4c94["parseString()"]
  b8a15b09_3dfb_7181_b1f8_368422e178e4 -->|calls| 1079aed1_4f38_ebc0_2e2d_4c9d9cfb4c94
  4b8217e6_b6b6_0b8b_fe5c_3374ea515cf9["parseDeclaration()"]
  b8a15b09_3dfb_7181_b1f8_368422e178e4 -->|calls| 4b8217e6_b6b6_0b8b_fe5c_3374ea515cf9
  style b8a15b09_3dfb_7181_b1f8_368422e178e4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/css-parser.ts lines 64–594

export function parse(input: string, opts?: ParseOptions) {
  let source: Source | null = opts?.from ? { file: opts.from, code: input } : null

  // Note: it is important that any transformations of the input string
  // *before* processing do NOT change the length of the string. This
  // would invalidate the mechanism used to track source locations.
  if (input[0] === '\uFEFF') input = ' ' + input.slice(1)

  let ast: AstNode[] = []
  let licenseComments: Comment[] = []

  let stack: (Rule | null)[] = []

  let parent = null as Rule | null
  let node = null as AstNode | null

  let buffer = ''
  let closingBracketStack = ''

  // The start of the first non-whitespace character in the buffer
  let bufferStart = 0

  let peekChar

  for (let i = 0; i < input.length; i++) {
    let currentChar = input.charCodeAt(i)

    // Skip over the CR in CRLF. This allows code below to only check for a line
    // break even if we're looking at a Windows newline. Peeking the input still
    // has to check for CRLF but that happens less often.
    if (currentChar === CARRIAGE_RETURN) {
      peekChar = input.charCodeAt(i + 1)
      if (peekChar === LINE_BREAK) continue
    }

    // Current character is a `\` therefore the next character is escaped,
    // consume it together with the next character and continue.
    //
    // E.g.:
    //
    // ```css
    // .hover\:foo:hover {}
    //       ^
    // ```
    //
    if (currentChar === BACKSLASH) {
      if (buffer === '') bufferStart = i
      buffer += input.slice(i, i + 2)
      i += 1
    }

    // Start of a comment.
    //
    // E.g.:
    //
    // ```css
    // /* Example */
    // ^^^^^^^^^^^^^
    // .foo {
    //  color: red; /* Example */
    //              ^^^^^^^^^^^^^
    // }
    // .bar {
    //  color: /* Example */ red;
    //         ^^^^^^^^^^^^^
    // }
    // ```
    else if (currentChar === SLASH && input.charCodeAt(i + 1) === ASTERISK) {
      let start = i

      for (let j = i + 2; j < input.length; j++) {
        peekChar = input.charCodeAt(j)

        // Current character is a `\` therefore the next character is escaped.
        if (peekChar === BACKSLASH) {
          j += 1
        }

        // End of the comment
        else if (peekChar === ASTERISK && input.charCodeAt(j + 1) === SLASH) {
          i = j + 1

Domain

Subdomains

Frequently Asked Questions

What does parse() do?
parse() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/css-parser.ts.
Where is parse() defined?
parse() is defined in packages/tailwindcss/src/css-parser.ts at line 64.
What does parse() call?
parse() calls 5 function(s): comment, parseAtRule, parseDeclaration, parseString, rule.
What calls parse()?
parse() is called by 10 function(s): __unstable__loadDesignSystem, analyze, buildPluginApi, compile, expand, optimizeAst, parseVariantValue, replaceNestedClassNameReferences, and 2 more.

Analyze Your Own Codebase

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

Try Supermodel Free