From b5601736ead0dfc11600d2d24c98abdbfa709294 Mon Sep 17 00:00:00 2001 From: Simon Chester Date: Mon, 1 Dec 2025 16:29:03 +1300 Subject: [PATCH] TL-47105: Fix parsing of calc split over multiple lines --- src/Value/CalcFunction.php | 4 ++-- tests/ParserTest.php | 12 ++++++++++++ tests/fixtures/multiline-calc.css | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/fixtures/multiline-calc.css diff --git a/src/Value/CalcFunction.php b/src/Value/CalcFunction.php index c3ed0a08..11b3024b 100644 --- a/src/Value/CalcFunction.php +++ b/src/Value/CalcFunction.php @@ -76,10 +76,10 @@ public static function parse(ParserState $oParserState, $bIgnoreCase = false) } else { if (in_array($oParserState->peek(), $aOperators)) { if (($oParserState->comes('-') || $oParserState->comes('+'))) { + $sNextChar = $oParserState->peek(1, 1); if ( $oParserState->peek(1, -1) != ' ' - || !($oParserState->comes('- ') - || $oParserState->comes('+ ')) + || !($sNextChar === ' ' || $sNextChar === "\n" || $sNextChar === "\r") ) { throw new UnexpectedTokenException( " {$oParserState->peek()} ", diff --git a/tests/ParserTest.php b/tests/ParserTest.php index a9d5c6cd..a18f3808 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -1321,4 +1321,16 @@ public function testInnerCommentExtracting() { $this->assertCount(1, $comments); $this->assertEquals("Find Me!", $comments[0]->getComment()); } + + /** + * @test + */ + public function multilineCalc() + { + $oDoc = self::parsedStructureForFile('multiline-calc'); + $sExpected = <<render()); + } } diff --git a/tests/fixtures/multiline-calc.css b/tests/fixtures/multiline-calc.css new file mode 100644 index 00000000..069caccf --- /dev/null +++ b/tests/fixtures/multiline-calc.css @@ -0,0 +1,6 @@ +.btn { + --foo: calc( + var(--bar) + + (var(--baz) + var(--qux)) * 2 + ); +}