Skip to content

Commit

Permalink
support pseudo-classes and pseudo-elements (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzawa authored and rauchg committed Dec 21, 2016
1 parent 37a16a2 commit ad1d759
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
19 changes: 18 additions & 1 deletion lib/style-transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
var inGlobal = false
var inSubSelector = false
var inQuotes = false
var inPseudo = false
var quoteChar = null

for (var k = 0; k < selector.length; k++) {
Expand Down Expand Up @@ -254,6 +255,14 @@
piece += chr
continue
}
} else if (inPseudo) {
if (' ' === chr) {
inPseudo = false
_line += piece + ' '
piece = ''
} else {
piece += chr
}
} else {
// potential beginning of :global()
if (chr === ':'
Expand All @@ -272,6 +281,11 @@
_line += piece + suffix + ' '
piece = ''
}
} else if (chr === ':') {
// pseudo-class or preudo-element
_line += piece + suffix
piece = chr
inPseudo = true
} else {
piece += chr
}
Expand All @@ -282,7 +296,10 @@

// flush remainder
if (piece.length) {
_line += piece + suffix
_line += piece
if (!inPseudo) {
_line += suffix
}
}

if (isLast) {
Expand Down
20 changes: 20 additions & 0 deletions test/fixtures/transform.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@ p, h1 {
animation-delay: 100ms;
}

p:hover {
color: red;
}

p::before {
color: red;
}

:hover {
color: red;
}

::before {
color: red;
}

:hover p {
color: red;
}

@keyframes hahaha {
from { top: 0 }
to { top: 100 }
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/transform.out.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad1d759

Please sign in to comment.