Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/Property/Selector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Sabberworm\CSS\Parsing\ParserState;
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
use Sabberworm\CSS\Property\Selector\Combinator;
use Sabberworm\CSS\Property\Selector\Component;
use Sabberworm\CSS\Property\Selector\CompoundSelector;
use Sabberworm\CSS\Property\Selector\SpecificityCalculator;
use Sabberworm\CSS\Renderable;
Expand Down Expand Up @@ -76,11 +77,11 @@ final public function __construct(string $selector)
/**
* @param list<Comment> $comments
*
* @throws UnexpectedTokenException
* @return list<Component>
*
* @internal
* @throws UnexpectedTokenException
*/
public static function parse(ParserState $parserState, array &$comments = []): self
private static function parseComponents(ParserState $parserState, array &$comments = []): array
{
// Whitespace is a descendent combinator, not allowed around a compound selector.
// (It is allowed within, e.g. as part of a string or within a function like `:not()`.)
Expand Down Expand Up @@ -109,6 +110,20 @@ public static function parse(ParserState $parserState, array &$comments = []): s
}
}

return $selectorParts;
}

/**
* @param list<Comment> $comments
*
* @throws UnexpectedTokenException
*
* @internal
*/
public static function parse(ParserState $parserState, array &$comments = []): self
{
$selectorParts = self::parseComponents($parserState, $comments);

// Check that the selector has been fully parsed:
if (!\in_array($parserState->peek(), ['{', '}', ',', ''], true)) {
throw new UnexpectedTokenException(
Expand Down