From cae0624324f4bb834f5164ee3d752787d9c6068c Mon Sep 17 00:00:00 2001 From: Christophe Coevoet Date: Sat, 17 Sep 2022 13:23:43 +0200 Subject: [PATCH] Emit a deprecation warning for the strict parsing of unary operators This emits a deprecation warning for `$a -$b` and `$a +$b`, since these look like they could be unary operations but they're actually parsed as binary operations. Either explicitly write `$a - $b` or `$a (-$b)`. See https://sass-lang.com/d/strict-unary for more details. This deprecation is only implemented for the new parser ported from dart-sass, not for the legacy parser. --- src/Parser/StylesheetParser.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Parser/StylesheetParser.php b/src/Parser/StylesheetParser.php index 2b874514..5b57fcbc 100644 --- a/src/Parser/StylesheetParser.php +++ b/src/Parser/StylesheetParser.php @@ -1928,6 +1928,31 @@ private function expression(?callable $until = null, bool $singleEquals = false, } else { $singleExpression = new BinaryOperationExpression($operator, $left, $right); $allowSlash = false; + + if ($operator === BinaryOperator::PLUS || $operator === BinaryOperator::MINUS) { + if ( + $this->scanner->substring($right->getSpan()->getStart()->getOffset() - 1, $right->getSpan()->getStart()->getOffset()) === $operator + && Character::isWhitespace($this->scanner->getString()[$left->getSpan()->getEnd()->getOffset()]) + ) { + $message = <<logger->warn($message, true, $singleExpression->getSpan()); + } + } } };