@@ -1087,6 +1087,7 @@ it('should parse a utility with an implicit variable as the modifier using the s
1087
1087
let utilities = new Utilities ( )
1088
1088
utilities . functional ( 'bg' , ( ) => [ ] )
1089
1089
1090
+ // Standard case (no underscores)
1090
1091
expect ( run ( 'bg-red-500/(--value)' , { utilities } ) ) . toMatchInlineSnapshot ( `
1091
1092
[
1092
1093
{
@@ -1107,6 +1108,156 @@ it('should parse a utility with an implicit variable as the modifier using the s
1107
1108
},
1108
1109
]
1109
1110
` )
1111
+
1112
+ // Should preserve underscores
1113
+ expect ( run ( 'bg-red-500/(--with_underscore)' , { utilities } ) ) . toMatchInlineSnapshot ( `
1114
+ [
1115
+ {
1116
+ "important": false,
1117
+ "kind": "functional",
1118
+ "modifier": {
1119
+ "kind": "arbitrary",
1120
+ "value": "var(--with_underscore)",
1121
+ },
1122
+ "raw": "bg-red-500/(--with_underscore)",
1123
+ "root": "bg",
1124
+ "value": {
1125
+ "fraction": null,
1126
+ "kind": "named",
1127
+ "value": "red-500",
1128
+ },
1129
+ "variants": [],
1130
+ },
1131
+ ]
1132
+ ` )
1133
+
1134
+ // Should remove underscores in fallback values
1135
+ expect ( run ( 'bg-red-500/(--with_underscore,fallback_value)' , { utilities } ) )
1136
+ . toMatchInlineSnapshot ( `
1137
+ [
1138
+ {
1139
+ "important": false,
1140
+ "kind": "functional",
1141
+ "modifier": {
1142
+ "kind": "arbitrary",
1143
+ "value": "var(--with_underscore,fallback value)",
1144
+ },
1145
+ "raw": "bg-red-500/(--with_underscore,fallback_value)",
1146
+ "root": "bg",
1147
+ "value": {
1148
+ "fraction": null,
1149
+ "kind": "named",
1150
+ "value": "red-500",
1151
+ },
1152
+ "variants": [],
1153
+ },
1154
+ ]
1155
+ ` )
1156
+
1157
+ // Should keep underscores in the CSS variable itself, but remove underscores
1158
+ // in fallback values
1159
+ expect ( run ( 'bg-(--a_b,c_d_var(--e_f,g_h))/(--i_j,k_l_var(--m_n,o_p))' , { utilities } ) )
1160
+ . toMatchInlineSnapshot ( `
1161
+ [
1162
+ {
1163
+ "important": false,
1164
+ "kind": "functional",
1165
+ "modifier": {
1166
+ "kind": "arbitrary",
1167
+ "value": "var(--i_j,k l var(--m_n,o p))",
1168
+ },
1169
+ "raw": "bg-(--a_b,c_d_var(--e_f,g_h))/(--i_j,k_l_var(--m_n,o_p))",
1170
+ "root": "bg",
1171
+ "value": {
1172
+ "dataType": null,
1173
+ "kind": "arbitrary",
1174
+ "value": "var(--a_b,c d var(--e_f,g h))",
1175
+ },
1176
+ "variants": [],
1177
+ },
1178
+ ]
1179
+ ` )
1180
+ } )
1181
+
1182
+ it ( 'should not parse an invalid arbitrary shorthand modifier' , ( ) => {
1183
+ let utilities = new Utilities ( )
1184
+ utilities . functional ( 'bg' , ( ) => [ ] )
1185
+
1186
+ // Completely empty
1187
+ expect ( run ( 'bg-red-500/()' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1188
+
1189
+ // Invalid due to leading spaces
1190
+ expect ( run ( 'bg-red-500/(_--)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1191
+ expect ( run ( 'bg-red-500/(_--x)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1192
+
1193
+ // Invalid due to leading spaces
1194
+ expect ( run ( 'bg-red-500/(_--)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1195
+ expect ( run ( 'bg-red-500/(_--x)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1196
+
1197
+ // Invalid due to top-level `;` or ` }` characters
1198
+ expect ( run ( 'bg-red-500/(--x;--y)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1199
+ expect ( run ( 'bg-red-500/(--x:{foo:bar})' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1200
+
1201
+ // Valid, but ensuring that we didn't make an off-by-one error
1202
+ expect ( run ( 'bg-red-500/(--x)' , { utilities } ) ) . toMatchInlineSnapshot ( `
1203
+ [
1204
+ {
1205
+ "important": false,
1206
+ "kind": "functional",
1207
+ "modifier": {
1208
+ "kind": "arbitrary",
1209
+ "value": "var(--x)",
1210
+ },
1211
+ "raw": "bg-red-500/(--x)",
1212
+ "root": "bg",
1213
+ "value": {
1214
+ "fraction": null,
1215
+ "kind": "named",
1216
+ "value": "red-500",
1217
+ },
1218
+ "variants": [],
1219
+ },
1220
+ ]
1221
+ ` )
1222
+ } )
1223
+
1224
+ it ( 'should not parse an invalid arbitrary shorthand value' , ( ) => {
1225
+ let utilities = new Utilities ( )
1226
+ utilities . functional ( 'bg' , ( ) => [ ] )
1227
+
1228
+ // Completely empty
1229
+ expect ( run ( 'bg-()' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1230
+
1231
+ // Invalid due to leading spaces
1232
+ expect ( run ( 'bg-(_--)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1233
+ expect ( run ( 'bg-(_--x)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1234
+
1235
+ // Invalid due to leading spaces
1236
+ expect ( run ( 'bg-(_--)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1237
+ expect ( run ( 'bg-(_--x)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1238
+
1239
+ // Invalid due to top-level `;` or ` }` characters
1240
+ expect ( run ( 'bg-(--x;--y)' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1241
+ expect ( run ( 'bg-(--x:{foo:bar})' , { utilities } ) ) . toMatchInlineSnapshot ( `[]` )
1242
+
1243
+ // Valid, but ensuring that we didn't make an off-by-one error
1244
+ expect ( run ( 'bg-(--x)' , { utilities } ) ) . toMatchInlineSnapshot ( `
1245
+ [
1246
+ {
1247
+ "important": false,
1248
+ "kind": "functional",
1249
+ "modifier": null,
1250
+ "raw": "bg-(--x)",
1251
+ "root": "bg",
1252
+ "value": {
1253
+ "dataType": null,
1254
+ "kind": "arbitrary",
1255
+ "value": "var(--x)",
1256
+ },
1257
+ "variants": [],
1258
+ },
1259
+ ]
1260
+ ` )
1110
1261
} )
1111
1262
1112
1263
it ( 'should not parse a utility with an implicit invalid variable as the modifier using the shorthand' , ( ) => {
0 commit comments