@@ -283,19 +283,33 @@ public function render(OutputFormat $outputFormat): string
283283 private static function parseSelectors (ParserState $ parserState , array &$ comments = []): array
284284 {
285285 $ selectors = [];
286+
287+ while (true ) {
288+ $ selectors [] = self ::parseSelector ($ parserState , $ comments );
289+ if (!$ parserState ->consumeIfComes (', ' )) {
290+ break ;
291+ }
292+ }
293+
294+ return $ selectors ;
295+ }
296+
297+ /**
298+ * @param list<Comment> $comments
299+ *
300+ * @throws UnexpectedTokenException
301+ */
302+ private static function parseSelector (ParserState $ parserState , array &$ comments = []): string
303+ {
286304 $ selectorParts = [];
287305 $ stringWrapperCharacter = null ;
288306 $ functionNestingLevel = 0 ;
289- $ consumedNextCharacter = false ;
290307 static $ stopCharacters = ['{ ' , '} ' , '\'' , '" ' , '( ' , ') ' , ', ' ];
291308
292- do {
293- if (!$ consumedNextCharacter ) {
294- $ selectorParts [] = $ parserState ->consume (1 );
295- }
309+ while (true ) {
310+ $ selectorParts [] = $ parserState ->consume (1 );
296311 $ selectorParts [] = $ parserState ->consumeUntil ($ stopCharacters , false , false , $ comments );
297312 $ nextCharacter = $ parserState ->peek ();
298- $ consumedNextCharacter = false ;
299313 switch ($ nextCharacter ) {
300314 case '\'' :
301315 // The fallthrough is intentional.
@@ -321,22 +335,25 @@ private static function parseSelectors(ParserState $parserState, array &$comment
321335 --$ functionNestingLevel ;
322336 }
323337 break ;
338+ case '{ ' :
339+ // The fallthrough is intentional.
340+ case '} ' :
341+ if (!\is_string ($ stringWrapperCharacter )) {
342+ break 2 ;
343+ }
344+ break ;
324345 case ', ' :
325346 if (!\is_string ($ stringWrapperCharacter ) && $ functionNestingLevel === 0 ) {
326- $ selectors [] = \implode ('' , $ selectorParts );
327- $ selectorParts = [];
328- $ parserState ->consume (1 );
329- $ consumedNextCharacter = true ;
347+ break 2 ;
330348 }
331349 break ;
332350 }
333- } while (! \in_array ( $ nextCharacter , [ ' { ' , ' } ' ], true ) || \is_string ( $ stringWrapperCharacter ));
351+ }
334352
335353 if ($ functionNestingLevel !== 0 ) {
336354 throw new UnexpectedTokenException (') ' , $ nextCharacter );
337355 }
338- $ selectors [] = \implode ('' , $ selectorParts ); // add final or only selector
339356
340- return $ selectors ;
357+ return \implode ( '' , $ selectorParts ) ;
341358 }
342359}
0 commit comments