Skip to content

Commit 77685c5

Browse files
committed
Fix issue with joinFirstPair
1 parent 2094663 commit 77685c5

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/CodeGenerator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,13 @@ public function joinFirstPair(array | Closure | Generator | string $data) : Gene
477477

478478
if ($line instanceof Group && $first !== null) {
479479
$prefix = $first instanceof Group ? '' : (string) $first;
480-
yield Group::indent($this->prefixFirst($prefix, $line->lines), $line->indention);
480+
$lines = self::resolveIterable($line->lines);
481+
482+
if ($lines === []) {
483+
yield $prefix;
484+
} else {
485+
yield Group::indent($this->prefixFirst($prefix, $lines), $line->indention);
486+
}
481487

482488
continue;
483489
}

tests/CodeGeneratorTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,9 +786,8 @@ public function testJoinFirstPairWithEmptySecondGroup() : void
786786

787787
$result = $this->generator->joinFirstPair($data);
788788

789-
// Note: When the second element is an empty group, 'first' gets lost
790-
// This might be unexpected behavior
791789
$expected = <<<'PHP'
790+
first
792791
third
793792
PHP;
794793

0 commit comments

Comments
 (0)