Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Please also have a look at our

### Added

- Provide line number in exception message for mismatched parentheses in
selector (#1435)
- Add support for CSS container queries (#1400)

### Changed
Expand Down
9 changes: 7 additions & 2 deletions src/RuleSet/DeclarationBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@ private static function parseSelector(ParserState $parserState, array &$comments
case ')':
if (!\is_string($stringWrapperCharacter)) {
if ($functionNestingLevel <= 0) {
throw new UnexpectedTokenException('anything but', ')');
throw new UnexpectedTokenException(
'anything but',
')',
'literal',
$parserState->currentLine()
);
}
--$functionNestingLevel;
}
Expand All @@ -351,7 +356,7 @@ private static function parseSelector(ParserState $parserState, array &$comments
}

if ($functionNestingLevel !== 0) {
throw new UnexpectedTokenException(')', $nextCharacter);
throw new UnexpectedTokenException(')', $nextCharacter, 'literal', $parserState->currentLine());
}

$selector = \trim(\implode('', $selectorParts));
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/RuleSet/DeclarationBlockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ public static function provideInvalidSelectorAndExpectedExceptionMessage(): arra
{
return [
'no selector' => ['', 'Token “selector” (literal) not found. Got “{”. [line no: 1]'],
'lone `(`' => ['(', 'Token “)” (literal) not found. Got “{”.'],
'lone `)`' => [')', 'Token “anything but” (literal) not found. Got “)”.'],
'lone `(`' => ['(', 'Token “)” (literal) not found. Got “{”. [line no: 1]'],
'lone `)`' => [')', 'Token “anything but” (literal) not found. Got “)”. [line no: 1]'],
'lone `,`' => [',', 'Token “selector” (literal) not found. Got “,”. [line no: 1]'],
'unclosed `(`' => [':not(#your-mug', 'Token “)” (literal) not found. Got “{”.'],
'extra `)`' => [':not(#your-mug))', 'Token “anything but” (literal) not found. Got “)”.'],
'unclosed `(`' => [':not(#your-mug', 'Token “)” (literal) not found. Got “{”. [line no: 1]'],
'extra `)`' => [':not(#your-mug))', 'Token “anything but” (literal) not found. Got “)”. [line no: 1]'],
'`,` missing left operand' => [', a', 'Token “selector” (literal) not found. Got “,”. [line no: 1]'],
'`,` missing right operand' => ['a,', 'Token “selector” (literal) not found. Got “{”. [line no: 1]'],
];
Expand Down