Skip to content

Commit baa8f65

Browse files
authored
Ensure nested [] is allowed (#5304)
This will allow us to write something like: `grid-cols-[[linename],1fr,auto]`
1 parent 5f02fe4 commit baa8f65

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/jit/lib/generateRules.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ function getClassNameFromSelector(selector) {
1717
// ['ring-offset-blue', '100']
1818
// ['ring-offset', 'blue-100']
1919
// ['ring', 'offset-blue-100']
20+
// Example with dynamic classes:
21+
// ['grid-cols', '[[linename],1fr,auto]']
22+
// ['grid', 'cols-[[linename],1fr,auto]']
2023
function* candidatePermutations(candidate, lastIndex = Infinity) {
2124
if (lastIndex < 0) {
2225
return
@@ -25,7 +28,7 @@ function* candidatePermutations(candidate, lastIndex = Infinity) {
2528
let dashIdx
2629

2730
if (lastIndex === Infinity && candidate.endsWith(']')) {
28-
let bracketIdx = candidate.lastIndexOf('[')
31+
let bracketIdx = candidate.indexOf('[')
2932

3033
// If character before `[` isn't a dash or a slash, this isn't a dynamic class
3134
// eg. string[]

tests/jit/arbitrary-values.test.css

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,21 @@
103103
}
104104
}
105105
}
106+
.w-\[\[\]\] {
107+
width: [];
108+
}
109+
.w-\[\[\[\]\]\] {
110+
width: [[]];
111+
}
106112
.w-\[\(\)\] {
107113
width: ();
108114
}
109115
.w-\[\(\(\)\)\] {
110116
width: (());
111117
}
118+
.w-\[\'\]\[\]\'\] {
119+
width: '][]';
120+
}
112121
.w-\[\'\)\(\)\'\] {
113122
width: ')()';
114123
}
@@ -169,6 +178,9 @@
169178
.grid-cols-\[200px\2c repeat\(auto-fill\2c minmax\(15\%\2c 100px\)\)\2c 300px\] {
170179
grid-template-columns: 200px repeat(auto-fill, minmax(15%, 100px)) 300px;
171180
}
181+
.grid-cols-\[\[linename\]\2c 1fr\2c auto\] {
182+
grid-template-columns: [linename] 1fr auto;
183+
}
172184
.grid-rows-\[200px\2c repeat\(auto-fill\2c minmax\(15\%\2c 100px\)\)\2c 300px\] {
173185
grid-template-rows: 200px repeat(auto-fill, minmax(15%, 100px)) 300px;
174186
}

tests/jit/arbitrary-values.test.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@
135135
<div class="w-['][]']"></div><!-- VALID -->
136136
<div class="w-[')()']"></div><!-- VALID -->
137137
<div class="w-['}{}']"></div><!-- VALID -->
138-
<div class="w-[[']']]"></div><!-- VALID -->
139-
<div class="w-[(')')]"></div><!-- VALID -->
140-
<div class="w-[{'}'}]"></div><!-- VALID -->
141138
<div class="w-[{[}]]"></div><!-- INVALID -->
142139
<div class="w-[[{]}]"></div><!-- INVALID -->
143140
<div class="w-[{(})]"></div><!-- INVALID -->

0 commit comments

Comments
 (0)