Home / Function/ parseString() — tailwindcss Function Reference

parseString() — tailwindcss Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  1079aed1_4f38_ebc0_2e2d_4c9d9cfb4c94["parseString()"]
  54851997_7544_bab2_96ab_548e5f5df205["css-parser.ts"]
  1079aed1_4f38_ebc0_2e2d_4c9d9cfb4c94 -->|defined in| 54851997_7544_bab2_96ab_548e5f5df205
  b8a15b09_3dfb_7181_b1f8_368422e178e4["parse()"]
  b8a15b09_3dfb_7181_b1f8_368422e178e4 -->|calls| 1079aed1_4f38_ebc0_2e2d_4c9d9cfb4c94
  style 1079aed1_4f38_ebc0_2e2d_4c9d9cfb4c94 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/tailwindcss/src/css-parser.ts lines 642–717

function parseString(
  input: string,
  startIdx: number,
  quoteChar: number,
  source: Source | null = null,
): number {
  let peekChar: number

  // We need to ensure that the closing quote is the same as the opening
  // quote.
  //
  // E.g.:
  //
  // ```css
  // .foo {
  //   content: "This is a string with a 'quote' in it";
  //                                     ^     ^         -> These are not the end of the string.
  // }
  // ```
  for (let i = startIdx + 1; i < input.length; i++) {
    peekChar = input.charCodeAt(i)

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

    // End of the string.
    else if (peekChar === quoteChar) {
      return i
    }

    // End of the line without ending the string but with a `;` at the end.
    //
    // E.g.:
    //
    // ```css
    // .foo {
    //   content: "This is a string with a;
    //                                    ^ Missing "
    // }
    // ```
    else if (
      peekChar === SEMICOLON &&
      (input.charCodeAt(i + 1) === LINE_BREAK ||
        (input.charCodeAt(i + 1) === CARRIAGE_RETURN && input.charCodeAt(i + 2) === LINE_BREAK))
    ) {
      throw new CssSyntaxError(
        `Unterminated string: ${input.slice(startIdx, i + 1) + String.fromCharCode(quoteChar)}`,
        source ? [source, startIdx, i + 1] : null,
      )
    }

    // End of the line without ending the string.
    //
    // E.g.:
    //
    // ```css
    // .foo {
    //   content: "This is a string with a
    //                                    ^ Missing "
    // }
    // ```
    else if (
      peekChar === LINE_BREAK ||
      (peekChar === CARRIAGE_RETURN && input.charCodeAt(i + 1) === LINE_BREAK)
    ) {
      throw new CssSyntaxError(
        `Unterminated string: ${input.slice(startIdx, i) + String.fromCharCode(quoteChar)}`,
        source ? [source, startIdx, i + 1] : null,
      )
    }
  }

  return startIdx
}

Domain

Subdomains

Called By

Frequently Asked Questions

What does parseString() do?
parseString() is a function in the tailwindcss codebase, defined in packages/tailwindcss/src/css-parser.ts.
Where is parseString() defined?
parseString() is defined in packages/tailwindcss/src/css-parser.ts at line 642.
What calls parseString()?
parseString() is called by 1 function(s): parse.

Analyze Your Own Codebase

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

Try Supermodel Free