diff --git a/CHANGELOG.md b/CHANGELOG.md index f60db312..d75a0e76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index c8cdb6d4..a3921815 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -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; } @@ -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)); diff --git a/tests/Unit/RuleSet/DeclarationBlockTest.php b/tests/Unit/RuleSet/DeclarationBlockTest.php index 9eaab956..91c3b66c 100644 --- a/tests/Unit/RuleSet/DeclarationBlockTest.php +++ b/tests/Unit/RuleSet/DeclarationBlockTest.php @@ -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]'], ];