Skip to content

Commit

Permalink
Merge pull request #619 from stof/strict_unary
Browse files Browse the repository at this point in the history
Emit a deprecation warning for the strict parsing of unary operators
  • Loading branch information
stof committed Sep 17, 2022
2 parents f8eb36f + cae0624 commit b8e9415
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Parser/StylesheetParser.php
Expand Up @@ -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 = <<<WARNING
This operation is parsed as:
$left $operator $right
but you may have intended it to mean:
$left ($operator$right)
Add a space after $operator to clarify that it's meant to be a binary operation, or wrap
it in parentheses to make it a unary operation. This will be an error in future
versions of Sass.
More info and automated migrator: https://sass-lang.com/d/strict-unary
WARNING;

$this->logger->warn($message, true, $singleExpression->getSpan());
}
}
}
};

Expand Down

0 comments on commit b8e9415

Please sign in to comment.