@@ -26,6 +26,7 @@ export const SelectorType = {
26
26
AdjacentSiblingCombinator : 16 ,
27
27
GeneralSiblingCombinator : 17 ,
28
28
Root : 18 , // E:root, :root
29
+ NthChild : 19
29
30
} ;
30
31
31
32
/**
@@ -36,6 +37,7 @@ export const SelectorType = {
36
37
const SelectorCategoryRegex = {
37
38
Type : / ^ [ A - Z a - z ] + / ,
38
39
Attribute : / ^ ( \# | \. ) ? [ A - Z a - z ] + \[ .+ ?\] $ / ,
40
+ NthChild : / ^ ( \# | \. ) ? ( [ A - Z a - z ] + ) ? \: n t h - c h i l d \( ( [ 0 - 9 ] + | n [ 0 - 9 ] + \+ [ 0 - 9 ] | o d d | e v e n ) \) /
39
41
} ;
40
42
41
43
/**
@@ -60,6 +62,8 @@ const SelectorTypeRegex = {
60
62
AttributeSuffix : / ^ ( \# | \. ) ? [ A - Z a - z ] + \[ [ A - Z a - z ] + \$ \= \" [ A - Z a - z ] + \" \] $ / , // E[attr$=value]
61
63
AttributeContains : / ^ ( \# | \. ) ? [ A - Z a - z ] + \[ [ A - Z a - z ] + \* \= \" [ A - Z a - z ] + \" \] $ / , // E[attr*=value]
62
64
Root : / ^ ( \# | \. ) ? [ a - z A - Z ] * : r o o t / , // E:root, :root
65
+ // todo add nth-child selectors like in attribute, odd, even, #n+# etc)
66
+
63
67
} ;
64
68
65
69
/**
@@ -82,6 +86,10 @@ export default function getType(selector) {
82
86
return SelectorType . Root ;
83
87
}
84
88
89
+ if ( SelectorCategoryRegex . NthChild . test ( selector ) ) {
90
+ return SelectorType . NthChild ;
91
+ }
92
+
85
93
if ( SelectorCategoryRegex . Attribute . test ( selector ) ) {
86
94
return SelectorTypeRegex . AttributePrefix . test ( selector ) ? SelectorType . AttributePrefix :
87
95
SelectorTypeRegex . AttributeSuffix . test ( selector ) ? SelectorType . AttributeSuffix :
0 commit comments