Commit 5d8b5dc
Match class functions that appear after an opening square bracket (#1428)
**The problem:**
The lookbehind pattern `(?<=^|[:=,;\s{()])` doesn't include `[` in its
character class, so these cases would be missed:
```javascript
const classes = [clsx('btn', 'primary')] // ❌ "clsx" not matched
const arr = [cn('text-red-500')] // ❌ "cn" not matched
```
But these would work:
```javascript
const classes = [ clsx('btn', 'primary')] // ✅ matches (whitespace after [)
const arr = [, cn('text-red-500')] // ✅ matches (comma before cn)
```
**Why this matters:**
Array contexts are common in modern JavaScript/React for combining
classes:
```javascript
const buttonClasses = [clsx(conditionalClasses), baseClasses]
const styles = [cn(variantStyle), defaultStyle]
```
**The Fix:**
The regex should include `[` in the lookbehind character class:
```javascript
/(?<=^|[:=,;\s{()\[])([\p{ID_Start}$_][\p{ID_Continue}$_.]*)[(`]/dgiu
// ^ add \[ here
```
This would ensure we properly detect class utility functions at the
beginning of arrays.
---------
Co-authored-by: Javier Ugarte <javo@cycle.eco>
Co-authored-by: Jordan Pittman <jordan@cryptica.me>1 parent 3d3f866 commit 5d8b5dc
File tree
3 files changed
+29
-2
lines changed- packages
- tailwindcss-language-service/src/util
- vscode-tailwindcss
3 files changed
+29
-2
lines changedLines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1081 | 1081 | | |
1082 | 1082 | | |
1083 | 1083 | | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
182 | | - | |
| 182 | + | |
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments