Skip to content

Commit 8502a50

Browse files
committed
[BUGFIX] Parse calc split over multiple lines
1 parent c29c15a commit 8502a50

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

src/Value/CalcFunction.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public static function parse(ParserState $parserState, bool $ignoreCase = false)
5959
} else {
6060
if (\in_array($parserState->peek(), $operators, true)) {
6161
if (($parserState->comes('-') || $parserState->comes('+'))) {
62+
$nextChar = $parserState->peek(1, 1);
6263
if (
6364
$parserState->peek(1, -1) !== ' '
64-
|| !($parserState->comes('- ')
65-
|| $parserState->comes('+ '))
65+
|| !($nextChar === ' ' || $nextChar === "\n" || $nextChar === "\r")
6666
) {
6767
throw new UnexpectedTokenException(
6868
" {$parserState->peek()} ",

tests/ParserTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,4 +1237,14 @@ public function escapedSpecialCaseTokens(): void
12371237
self::assertInstanceOf(URL::class, $urlRule->getValue());
12381238
self::assertInstanceOf(CalcFunction::class, $calcRule->getValue());
12391239
}
1240+
1241+
/**
1242+
* @test
1243+
*/
1244+
public function multilineCalc()
1245+
{
1246+
$document = self::parsedStructureForFile('multiline-calc');
1247+
$expected = '.btn {--foo: calc(var(--bar) + ( var(--baz) + var(--qux) ) * 2);}';
1248+
self::assertSame($expected, $document->render());
1249+
}
12401250
}

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)