Skip to content

Commit ff2cab5

Browse files
scqcodyfinegan
authored andcommitted
TL-47105: Fix parsing of calc split over multiple lines
1 parent 58f73db commit ff2cab5

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
@@ -71,10 +71,10 @@ public static function parse(ParserState $oParserState, $bIgnoreCase = false)
7171
} else {
7272
if (in_array($oParserState->peek(), $aOperators)) {
7373
if (($oParserState->comes('-') || $oParserState->comes('+'))) {
74+
$sNextChar = $oParserState->peek(1, 1);
7475
if (
7576
$oParserState->peek(1, -1) != ' '
76-
|| !($oParserState->comes('- ')
77-
|| $oParserState->comes('+ '))
77+
|| !($sNextChar === ' ' || $sNextChar === "\n" || $sNextChar === "\r")
7878
) {
7979
throw new UnexpectedTokenException(
8080
" {$oParserState->peek()} ",

tests/ParserTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,4 +1265,16 @@ public function escapedSpecialCaseTokens()
12651265
self::assertTrue(is_a($urlRule->getValue(), '\Sabberworm\CSS\Value\URL'));
12661266
self::assertTrue(is_a($calcRule->getValue(), '\Sabberworm\CSS\Value\CalcFunction'));
12671267
}
1268+
1269+
/**
1270+
* @test
1271+
*/
1272+
public function multilineCalc()
1273+
{
1274+
$oDoc = self::parsedStructureForFile('multiline-calc');
1275+
$sExpected = <<<EXPECTED
1276+
.btn {--foo: calc(var(--bar) + ( var(--baz) + var(--qux) ) * 2);}
1277+
EXPECTED;
1278+
self::assertSame($sExpected, $oDoc->render());
1279+
}
12681280
}

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)