tailwindcss/src/lib
Robin Malfait 527031d5f6
Improve data type analyses for arbitrary values (#9320)
* improve split logic by delimiter

The original RegEx did mostly what we want, the idea is that we wanted
to split by a `,` but one that was not within `()`. This is useful when
you define multiple background colors for example:
```html
<div class="bg-[rgb(0,0,0),rgb(255,255,255)]"></div>
```

In this case splitting by the regex would result in the proper result:
```js
let result = [
  'rgb(0,0,0)',
  'rgb(255,255,255)'
]
```

Visually, you can think of it like:
```
    ┌─[./example.html]
    │
∙ 1 │   <div class="bg-[rgb(0,0,0),rgb(255,255,255)]"></div>
    ·                       ──┬── ┬    ─────┬─────
    ·                         │   │         ╰─────── Guarded by parens
    ·                         │   ╰───────────────── We will split here
    ·                         ╰───────────────────── Guarded by parens
    │
    └─
```

We properly split by `,` not inside a `()`. However, this RegEx fails
the moment you have deeply nested RegEx values.

Visually, this is what's happening:
```
    ┌─[./example.html]
    │
∙ 1 │   <div class="bg-[rgba(0,0,0,var(--alpha))]"></div>
    ·                         ┬ ┬ ┬
    ·                         ╰─┴─┴── We accidentally split here
    │
    └─
```
This is because on the right of the `,`, the first paren is an opening
paren `(` instead of a closing one `)`.

I'm not 100% sure how we can improve the RegEx to handle that case as
well, instead I wrote a small `splitBy` function that allows you to
split the string by a character (just like you could do before) but
ignores the ones inside the given exceptions. This keeps track of a
stack to know whether we are within parens or not.

Visually, the fix looks like this:
```
    ┌─[./example.html]
    │
∙ 1 │   <div class="bg-[rgba(0,0,0,var(--alpha)),rgb(255,255,255,var(--alpha))]"></div>
    ·                         ┬ ┬ ┬             ┬       ┬   ┬   ┬
    ·                         │ │ │             │       ╰───┴───┴── Guarded by parens
    ·                         │ │ │             ╰────────────────── We will split here
    ·                         ╰─┴─┴──────────────────────────────── Guarded by parens
    │
    └─
```

* use already existing `splitAtTopLevelOnly` function

* add faster implemetation for `splitAtTopLevelOnly`

However, the faster version can't handle separators with multiple
characters right now. So instead of using buggy code or only using the
"slower" code, we've added a fast path where we use the faster code
wherever we can.

* use `splitAtTopLevelOnly` directly

* make split go brrrrrrr

* update changelog

* remove unncessary array.from call

Co-authored-by: Jordan Pittman <jordan@cryptica.me>
2022-09-14 14:08:56 +02:00
..
cacheInvalidation.js Invalidate context when main css changes (#7626) 2022-02-25 13:12:45 -05:00
collapseAdjacentRules.js Handle duplicate atrules without children (#8122) 2022-04-15 12:24:27 -04:00
collapseDuplicateDeclarations.js Improve collapsing of duplicate declarations (#6856) 2022-01-03 15:41:49 +01:00
defaultExtractor.js Fix usage of special-character prefixes (#8772) 2022-07-04 14:42:27 -04:00
detectNesting.js Improve nesting detection (#6011) 2021-11-10 13:15:32 +01:00
evaluateTailwindFunctions.js Handle theme keys with slashes when using theme() in CSS (#8831) 2022-07-11 10:47:17 -04:00
expandApplyAtRules.js Fix parallel variant ordering clash (#9282) 2022-09-09 13:12:43 -04:00
expandTailwindAtRules.js Fix parallel variant ordering clash (#9282) 2022-09-09 13:12:43 -04:00
generateRules.js Improve data type analyses for arbitrary values (#9320) 2022-09-14 14:08:56 +02:00
getModuleDependencies.js Prettier likes parens a lot now 2020-10-16 15:39:44 -04:00
normalizeTailwindDirectives.js Improve various warnings (#7118) 2022-01-19 15:09:13 -05:00
offsets.js Fix parallel variant ordering clash (#9282) 2022-09-09 13:12:43 -04:00
partitionApplyAtRules.js Fix consecutive builds with at apply producing different CSS (#6999) 2022-01-10 12:36:14 -05:00
regex.js Rewrite default class extractor (#8204) 2022-05-04 16:08:25 -04:00
resolveDefaultsAtRules.js Split ::backdrop into separate defaults group (#8567) 2022-06-09 16:26:18 -04:00
setupContextUtils.js Fix parallel variant ordering clash (#9282) 2022-09-09 13:12:43 -04:00
setupTrackingContext.js Use absolute paths when resolving changed files (#9032) 2022-08-08 10:47:23 -04:00
sharedState.js Invalidate context when main css changes (#7626) 2022-02-25 13:12:45 -05:00
substituteScreenAtRules.js Add tuple syntax to guarantee screens order (#6104) 2021-11-16 18:01:06 +01:00