Skip to content

Commit ad1d759

Browse files
nkzawarauchg
authored andcommitted
support pseudo-classes and pseudo-elements (#48)
1 parent 37a16a2 commit ad1d759

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

lib/style-transform.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@
211211
var inGlobal = false
212212
var inSubSelector = false
213213
var inQuotes = false
214+
var inPseudo = false
214215
var quoteChar = null
215216

216217
for (var k = 0; k < selector.length; k++) {
@@ -254,6 +255,14 @@
254255
piece += chr
255256
continue
256257
}
258+
} else if (inPseudo) {
259+
if (' ' === chr) {
260+
inPseudo = false
261+
_line += piece + ' '
262+
piece = ''
263+
} else {
264+
piece += chr
265+
}
257266
} else {
258267
// potential beginning of :global()
259268
if (chr === ':'
@@ -272,6 +281,11 @@
272281
_line += piece + suffix + ' '
273282
piece = ''
274283
}
284+
} else if (chr === ':') {
285+
// pseudo-class or preudo-element
286+
_line += piece + suffix
287+
piece = chr
288+
inPseudo = true
275289
} else {
276290
piece += chr
277291
}
@@ -282,7 +296,10 @@
282296

283297
// flush remainder
284298
if (piece.length) {
285-
_line += piece + suffix
299+
_line += piece
300+
if (!inPseudo) {
301+
_line += suffix
302+
}
286303
}
287304

288305
if (isLast) {

test/fixtures/transform.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ p, h1 {
4040
animation-delay: 100ms;
4141
}
4242

43+
p:hover {
44+
color: red;
45+
}
46+
47+
p::before {
48+
color: red;
49+
}
50+
51+
:hover {
52+
color: red;
53+
}
54+
55+
::before {
56+
color: red;
57+
}
58+
59+
:hover p {
60+
color: red;
61+
}
62+
4363
@keyframes hahaha {
4464
from { top: 0 }
4565
to { top: 100 }

test/fixtures/transform.out.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)