@@ -40,6 +40,7 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
4040 $ value = null ;
4141 $ noKey = false ;
4242 $ alterNext = false ;
43+ $ isNthOfType = false ;
4344
4445 // check for elements that alter the behavior of the next element
4546 if ($ tag == '> ' ) {
@@ -64,13 +65,14 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
6465 $ tag = '* ' ;
6566 $ value = \substr ($ match [0 ], 1 );
6667
67- if (preg_match ("/^nth-child\(\d+\)$/ " , \trim ($ value , ', ' ))) {
68- preg_match_all ("/^nth-child\((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
69- $ key = (int ) $ matches [0 ][1 ];
70- } else if (preg_match ("/^nth-last-child\(\d+\)$/ " , \trim ($ value , ', ' ))) {
71- preg_match_all ("/^nth-last-child\((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
72- $ key = - (int ) $ matches [0 ][1 ];
68+ if (preg_match ("/^( nth-child|nth-of-type) \(\d+\)$/ " , \trim ($ value , ', ' ))) {
69+ preg_match_all ("/^( nth-child|nth-of-type) \((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
70+ $ key = (int ) $ matches [0 ][2 ];
71+ } else if (preg_match ("/^( nth-last-child|nth-last-of-type) \(\d+\)$/ " , \trim ($ value , ', ' ))) {
72+ preg_match_all ("/^( nth-last-child|nth-last-of-type) \((\d+)\)$/ " , \trim ($ value , ', ' ), $ matches , PREG_SET_ORDER );
73+ $ key = - (int ) $ matches [0 ][2 ];
7374 }
75+ $ isNthOfType = preg_match ("/^nth(-last)?-of-type\(\d+\)$/ " , \trim ($ value , ', ' ));
7476 }
7577
7678 // and final attribute selector
@@ -113,7 +115,8 @@ public function parseSelectorString(string $selector): ParsedSelectorCollectionD
113115 $ key ,
114116 $ value ,
115117 $ noKey ,
116- $ alterNext
118+ $ alterNext ,
119+ $ isNthOfType
117120 );
118121 if (isset ($ match [7 ]) && \is_string ($ match [7 ]) && \trim ($ match [7 ]) == ', ' ) {
119122 $ selectors [] = ParsedSelectorDTO::makeFromRules ($ rules );
0 commit comments