tailwindcss/crates/oxide/src/extractor
Robin Malfait f369e22172
Fix class extraction followed by ( in Slim (#17278)
This PR fixes an issue where using the class shorthand in Slim
templates, followed by an `(` results in the last class being ignored.

E.g.:

```slim
body.border-t-4.p-8(class="#{body_classes}" data-hotwire-native="#{hotwire_native_app?}" data-controller="update-time-zone")
```

This is because we will eventually extract `p-8` but it's followed by an
invalid boundary character `(`.

To solve this, we make sure to replace the `(` with a space. We already
do a similar thing when the classes are followed by an `[`.

One caveat, we _can_ have `(` in our classes, like `bg-(--my-color)`.
But in my testing this is not something that can be used in the
shorthand version.

E.g.:
```slim
div.bg-(--my-color)
```

Compiles to:
```html
<div --my-color="" class="bg-"></div>
```

So I didn't add any special handling for this. Even when trying to
escape the `(`, `-` and `)` characters, it still doesn't work. E.g.:

```slim
div.bg-\(--my-color\)
```

Compiles to:
```html
<div class="bg-">\(--my-color\)</div>
```

# Test plan

1. Added test for the issue
2. Existing tests pass
3. Verified via the extractor tool:

| Before | After |
| --- | --- |
| <img width="958" alt="image"
src="https://github.com/user-attachments/assets/f72c420e-5429-424f-a01d-12f724062bf2"
/> | <img width="958" alt="image"
src="https://github.com/user-attachments/assets/b0cc8f2f-97a8-4fca-8813-3bb1da8d99a8"
/> |

---

Fixes: #17277
2025-03-19 09:50:30 -04:00
..
pre_processors Fix class extraction followed by ( in Slim (#17278) 2025-03-19 09:50:30 -04:00
arbitrary_property_machine.rs Do not extract candidates containing JS string interpolation pattern ${ (#17142) 2025-03-12 12:09:13 +01:00
arbitrary_value_machine.rs Do not extract candidates containing JS string interpolation pattern ${ (#17142) 2025-03-12 12:09:13 +01:00
arbitrary_variable_machine.rs Do not extract candidates containing JS string interpolation pattern ${ (#17142) 2025-03-12 12:09:13 +01:00
boundary.rs Ensure classes between > and < are properly extracted (#17094) 2025-03-10 11:28:08 +01:00
bracket_stack.rs Improve Oxide candidate extractor [0] (#16306) 2025-03-05 11:55:24 +01:00
candidate_machine.rs Do not extract candidates containing JS string interpolation pattern ${ (#17142) 2025-03-12 12:09:13 +01:00
css_variable_machine.rs Improve internal DX around byte classification [1] (#16864) 2025-03-05 14:00:07 +01:00
machine.rs Improve Oxide candidate extractor [0] (#16306) 2025-03-05 11:55:24 +01:00
mod.rs Ensure candidate extraction works as expected in Clojure/ClojureScript (#17087) 2025-03-13 11:31:27 +01:00
modifier_machine.rs Improve internal DX around byte classification [1] (#16864) 2025-03-05 14:00:07 +01:00
named_utility_machine.rs Refactor: use compile time type state pattern (#17083) 2025-03-10 14:08:39 -04:00
named_variant_machine.rs Fix variants with <digit>.</digit> are extracted correctly (#17153) 2025-03-12 21:04:11 +00:00
string_machine.rs Improve internal DX around byte classification [1] (#16864) 2025-03-05 14:00:07 +01:00
utility_machine.rs Improve boundary classification (#17005) 2025-03-07 00:00:54 +00:00
variant_machine.rs Improve internal DX around byte classification [1] (#16864) 2025-03-05 14:00:07 +01:00