Skip to content
This repository was archived by the owner on Apr 6, 2021. It is now read-only.
This repository was archived by the owner on Apr 6, 2021. It is now read-only.

Some string in codebase causing candidatePermutations to stack overflow #172

Closed
@calebmer

Description

@calebmer

What version of @tailwindcss/jit are you using?

v0.1.13

What version of Node.js are you using?

v14.15.0

What browser are you using?

n/a

What operating system are you using?

macOS

Reproduction repository

n/a

I have the following line of code in my codebase: [^${char}\\s][^${char}]*[^${char}\\s] (it’s used to build a regular expression). When I remove it from my codebase, @tailwindcss/jit works fine. When I add it back Tailwind CSS fails to build with:

RangeError: Maximum call stack size exceeded
    at candidatePermutations.next (<anonymous>)
    at candidatePermutations.next (<anonymous>)
    at candidatePermutations.next (<anonymous>)
    at candidatePermutations.next (<anonymous>)
    at candidatePermutations.next (<anonymous>)
    at candidatePermutations.next (<anonymous>)
    at candidatePermutations.next (<anonymous>)

I reproduced this issue by taking the implementation of candidatePermutations() in my node_modules folder and running it standalone:

function* candidatePermutations(candidate, lastIndex = Infinity) {
  if (lastIndex < 0) {
    return
  }

  let dashIdx

  if (candidate.endsWith(']', lastIndex + 1)) {
    dashIdx = candidate.lastIndexOf('[') - 1
  } else {
    dashIdx = candidate.lastIndexOf('-', lastIndex)
  }

  if (dashIdx < 0) {
    return
  }

  let prefix = candidate.slice(0, dashIdx)
  let modifier = candidate.slice(dashIdx + 1)

  yield [prefix, modifier]

  yield* candidatePermutations(candidate, dashIdx - 1)
}

for (const result of candidatePermutations('[^${char}\\\\s][^${char}]*[^${char}\\\\s]')) {
  console.log(result);
}

(Babel playground)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions