Skip to content

Commit 259169a

Browse files
scqcodyfinegan
authored andcommitted
TL-47105: Fix parsing of calc split over multiple lines
1 parent 1c15bf0 commit 259169a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/Value/CalcFunction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ public static function parse(ParserState $oParserState, $bIgnoreCase = false)
7676
} else {
7777
if (in_array($oParserState->peek(), $aOperators)) {
7878
if (($oParserState->comes('-') || $oParserState->comes('+'))) {
79+
$sNextChar = $oParserState->peek(1, 1);
7980
if (
8081
$oParserState->peek(1, -1) != ' '
81-
|| !($oParserState->comes('- ')
82-
|| $oParserState->comes('+ '))
82+
|| !($sNextChar === ' ' || $sNextChar === "\n" || $sNextChar === "\r")
8383
) {
8484
throw new UnexpectedTokenException(
8585
" {$oParserState->peek()} ",

tests/ParserTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,4 +1321,16 @@ public function testInnerCommentExtracting() {
13211321
$this->assertCount(1, $comments);
13221322
$this->assertEquals("Find Me!", $comments[0]->getComment());
13231323
}
1324+
1325+
/**
1326+
* @test
1327+
*/
1328+
public function multilineCalc()
1329+
{
1330+
$oDoc = self::parsedStructureForFile('multiline-calc');
1331+
$sExpected = <<<EXPECTED
1332+
.btn {--foo: calc(var(--bar) + ( var(--baz) + var(--qux) ) * 2);}
1333+
EXPECTED;
1334+
self::assertSame($sExpected, $oDoc->render());
1335+
}
13241336
}

tests/fixtures/multiline-calc.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.btn {
2+
--foo: calc(
3+
var(--bar) +
4+
(var(--baz) + var(--qux)) * 2
5+
);
6+
}

0 commit comments

Comments
 (0)