Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve data type analysis for arbitrary values #9320

Merged
merged 7 commits into from Sep 14, 2022

Commits on Sep 13, 2022

  1. 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
        │
        └─
    ```
    RobinMalfait committed Sep 13, 2022
    Copy the full SHA
    9d48e04 View commit details
    Browse the repository at this point in the history
  2. Copy the full SHA
    523df1f View commit details
    Browse the repository at this point in the history
  3. 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.
    RobinMalfait committed Sep 13, 2022
    Copy the full SHA
    69f5221 View commit details
    Browse the repository at this point in the history
  4. Copy the full SHA
    5edf7c7 View commit details
    Browse the repository at this point in the history
  5. make split go brrrrrrr

    thecrypticace committed Sep 13, 2022
    Copy the full SHA
    81b27b4 View commit details
    Browse the repository at this point in the history
  6. update changelog

    RobinMalfait committed Sep 13, 2022
    Copy the full SHA
    749d983 View commit details
    Browse the repository at this point in the history
  7. Copy the full SHA
    c1e6e8a View commit details
    Browse the repository at this point in the history