Home / Function/ parse() — tailwindcss Function Reference

parse() — tailwindcss Function Reference

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

Function typescript Oxide Extractor calls 1 called by 6

Entity Profile

Dependency Diagram

graph TD
  117bca28_0677_ab3f_6eec_6019671b392d["parse()"]
  73875259_ec95_9835_94d8_655298d1f0e9["attribute-selector-parser.ts"]
  117bca28_0677_ab3f_6eec_6019671b392d -->|defined in| 73875259_ec95_9835_94d8_655298d1f0e9
  7f0ac26e_d200_2f14_4236_46ff9eed21ef["createConverterCache()"]
  7f0ac26e_d200_2f14_4236_46ff9eed21ef -->|calls| 117bca28_0677_ab3f_6eec_6019671b392d
  a4ba0e6f_8062_6435_8f6d_7ec692b4801d["substituteFunctionsInValue()"]
  a4ba0e6f_8062_6435_8f6d_7ec692b4801d -->|calls| 117bca28_0677_ab3f_6eec_6019671b392d
  e065de15_2d14_7687_5e7d_5513c20a5e8c["allVariablesAreUsed()"]
  e065de15_2d14_7687_5e7d_5513c20a5e8c -->|calls| 117bca28_0677_ab3f_6eec_6019671b392d
  4af25bcc_7295_c96c_9ddc_5c19bf644f5e["modernizeArbitraryValuesVariant()"]
  4af25bcc_7295_c96c_9ddc_5c19bf644f5e -->|calls| 117bca28_0677_ab3f_6eec_6019671b392d
  7b28cf23_d052_57d9_b076_5abe2b724a3f["resolveVariablesInValue()"]
  7b28cf23_d052_57d9_b076_5abe2b724a3f -->|calls| 117bca28_0677_ab3f_6eec_6019671b392d
  975d8b8a_4b03_4408_cd48_2cea8a20646c["createVariantSignatureCache()"]
  975d8b8a_4b03_4408_cd48_2cea8a20646c -->|calls| 117bca28_0677_ab3f_6eec_6019671b392d
  39f79f5e_df1c_1b0a_f2e4_f8898e21c1f3["isAsciiWhitespace()"]
  117bca28_0677_ab3f_6eec_6019671b392d -->|calls| 39f79f5e_df1c_1b0a_f2e4_f8898e21c1f3
  style 117bca28_0677_ab3f_6eec_6019671b392d fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/attribute-selector-parser.ts lines 35–216

export function parse(input: string): AttributeSelector | null {
  // Must start with `[` and end with `]`
  if (input[0] !== '[' || input[input.length - 1] !== ']') {
    return null
  }

  let i = 1
  let start = i
  let end = input.length - 1

  // Skip whitespace, e.g.: [   data-foo]
  //                         ^^^
  while (isAsciiWhitespace(input.charCodeAt(i))) i++

  // Attribute name, e.g.: [data-foo]
  //                        ^^^^^^^^
  {
    start = i
    for (; i < end; i++) {
      let currentChar = input.charCodeAt(i)
      // Skip escaped character
      if (currentChar === BACKSLASH) {
        i++
        continue
      }
      if (currentChar >= UPPER_A && currentChar <= UPPER_Z) continue
      if (currentChar >= LOWER_A && currentChar <= LOWER_Z) continue
      if (currentChar >= ZERO && currentChar <= NINE) continue
      if (currentChar === DASH || currentChar === UNDERSCORE) continue
      break
    }

    // Must have at least one character in the attribute name
    if (start === i) {
      return null
    }
  }
  let attribute = input.slice(start, i)

  // Skip whitespace, e.g.: [data-foo   =value]
  //                                 ^^^
  while (isAsciiWhitespace(input.charCodeAt(i))) i++

  // At the end, e.g.: `[data-foo]`
  if (i === end) {
    return {
      attribute,
      operator: null,
      quote: null,
      value: null,
      sensitivity: null,
    }
  }

  // Operator, e.g.: [data-foo*=value]
  //                          ^^
  let operator = null
  let currentChar = input.charCodeAt(i)
  if (currentChar === EQUALS) {
    operator = '='
    i++
  } else if (
    (currentChar === TILDE ||
      currentChar === PIPE ||
      currentChar === CARET ||
      currentChar === DOLLAR ||
      currentChar === ASTERISK) &&
    input.charCodeAt(i + 1) === EQUALS
  ) {
    operator = input[i] + '='
    i += 2
  } else {
    return null // Invalid operator
  }

  // Skip whitespace, e.g.: [data-foo*=   value]
  //                                   ^^^
  while (isAsciiWhitespace(input.charCodeAt(i))) i++

  // At the end, that means that we have an operator but no valid, which is
  // invalid, e.g.: `[data-foo*=]`

Domain

Subdomains

Frequently Asked Questions

What does parse() do?
parse() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/attribute-selector-parser.ts.
Where is parse() defined?
parse() is defined in packages/tailwindcss/src/attribute-selector-parser.ts at line 35.
What does parse() call?
parse() calls 1 function(s): isAsciiWhitespace.
What calls parse()?
parse() is called by 6 function(s): allVariablesAreUsed, createConverterCache, createVariantSignatureCache, modernizeArbitraryValuesVariant, resolveVariablesInValue, substituteFunctionsInValue.

Analyze Your Own Codebase

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

Try Supermodel Free