Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit 0524b2e

Browse files
authored
Merge pull request #68 from alan-agius4/preudo-class
fix: handle pseudo-class in middle of selector
2 parents 99d5070 + cf38bdf commit 0524b2e

File tree

4 files changed

+71
-5
lines changed

4 files changed

+71
-5
lines changed

src/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ export default class Critters {
460460
// Strip pseudo-elements and pseudo-classes, since we only care that their associated elements exist.
461461
// This means any selector for a pseudo-element or having a pseudo-class will be inlined if the rest of the selector matches.
462462
if (sel !== ':root') {
463-
sel = sel.replace(/(?:>\s*)?::?[a-z-]+\s*(\{|$)/gi, '$1').trim();
463+
sel = sel.replace(/(?<!\\)::?[a-z-]+(?![a-z-(])/gi, '').replace(/::?not\(\s*\)/g, '').trim();
464464
}
465465
if (!sel) return false;
466466

test/__snapshots__/index.test.js.snap

+35-2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ ul.navbar a {
120120
text-decoration: none;
121121
}
122122
123+
ul.navbar:not(.hidden) li:hover a {
124+
color: black;
125+
}
126+
127+
ul.navbar:not(:hover) li:hover a {
128+
color: black;
129+
}
130+
131+
ul.navbar li:hover a {
132+
color: red;
133+
}
134+
123135
a:link {
124136
color: blue;
125137
}
@@ -132,10 +144,14 @@ footer {
132144
margin-top: 1em;
133145
padding-top: 1em;
134146
border-top: thin dotted;
147+
}
148+
149+
.clazz\\\\:colon {
150+
color: green;
135151
}</style>
136152
</head>
137153
<body>
138-
<ul class=\\"navbar\\">
154+
<ul class=\\"navbar clazz:colon\\">
139155
<li>
140156
<a href=\\"index.html\\">Home page</a>
141157
</li>
@@ -336,12 +352,22 @@ exports[`webpack compilation 1`] = `
336352
ul.navbar a {
337353
text-decoration: none;
338354
}
355+
ul.navbar:not(.hidden) li:hover a {
356+
color: black;
357+
}
358+
ul.navbar:not(:hover) li:hover a {
359+
color: black;
360+
}
361+
ul.navbar li:hover a {
362+
color: red;
363+
}
339364
a:link {
340365
color: blue;
341366
}
342367
a:visited {
343368
color: purple;
344369
}
370+
345371
footer {
346372
margin-top: 1em;
347373
padding-top: 1em;
@@ -350,10 +376,17 @@ exports[`webpack compilation 1`] = `
350376
.extra-style {
351377
font-size: 200%;
352378
}
379+
.hidden {
380+
visibility: hidden;
381+
}
382+
383+
.clazz\\\\:colon {
384+
color: green;
385+
}
353386
</style>
354387
</head>
355388
<body>
356-
<ul class=\\"navbar\\">
389+
<ul class=\\"navbar clazz:colon\\">
357390
<li>
358391
<a href=\\"index.html\\">Home page</a>
359392
</li>

test/__snapshots__/standalone.test.js.snap

+17-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,18 @@ ul.navbar a {
5656
text-decoration: none;
5757
}
5858
59+
ul.navbar:not(.hidden) li:hover a {
60+
color: black;
61+
}
62+
63+
ul.navbar:not(:hover) li:hover a {
64+
color: black;
65+
}
66+
67+
ul.navbar li:hover a {
68+
color: red;
69+
}
70+
5971
a:link {
6072
color: blue;
6173
}
@@ -68,10 +80,14 @@ footer {
6880
margin-top: 1em;
6981
padding-top: 1em;
7082
border-top: thin dotted;
83+
}
84+
85+
.clazz\\\\:colon {
86+
color: green;
7187
}</style>
7288
</head>
7389
<body>
74-
<ul class=\\"navbar\\">
90+
<ul class=\\"navbar clazz:colon\\">
7591
<li>
7692
<a href=\\"index.html\\">Home page</a>
7793
</li>

test/fixtures/basic/index.html

+18-1
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,22 @@
3030
ul.navbar a {
3131
text-decoration: none;
3232
}
33+
ul.navbar:not(.hidden) li:hover a {
34+
color: black;
35+
}
36+
ul.navbar:not(:hover) li:hover a {
37+
color: black;
38+
}
39+
ul.navbar li:hover a {
40+
color: red;
41+
}
3342
a:link {
3443
color: blue;
3544
}
3645
a:visited {
3746
color: purple;
3847
}
48+
3949
footer {
4050
margin-top: 1em;
4151
padding-top: 1em;
@@ -44,10 +54,17 @@
4454
.extra-style {
4555
font-size: 200%;
4656
}
57+
.hidden {
58+
visibility: hidden;
59+
}
60+
61+
.clazz\:colon {
62+
color: green;
63+
}
4764
</style>
4865
</head>
4966
<body>
50-
<ul class="navbar">
67+
<ul class="navbar clazz:colon">
5168
<li>
5269
<a href="index.html">Home page</a>
5370
</li>

0 commit comments

Comments
 (0)