diff --git a/src/Folder/Foldable.php b/src/Folder/Foldable.php index 533cfbb..2b2dfa8 100644 --- a/src/Folder/Foldable.php +++ b/src/Folder/Foldable.php @@ -102,6 +102,10 @@ protected function setupSlots(): void foreach ($this->node->children as $child) { if ($child instanceof SlotNode) { + if (! $this->hasActualContent($child->children)) { + continue; + } + $placeholder = 'BLAZE_PLACEHOLDER_' . $this->placeholderIndex++ . '_'; $this->slotByPlaceholder[$placeholder] = $child; @@ -121,7 +125,7 @@ protected function setupSlots(): void } // Synthesize a default slot from loose content when there's not an explicit one - if ($looseContent && ! isset($slots['slot'])) { + if ($this->hasActualContent($looseContent) && ! isset($slots['slot'])) { $placeholder = 'BLAZE_PLACEHOLDER_' . $this->placeholderIndex++ . '_'; $defaultSlot = new SlotNode( @@ -146,6 +150,20 @@ protected function setupSlots(): void $this->renderable->children = $slots; } + /** + * Determine whether a list of nodes contains anything besides whitespace-only text. + */ + protected function hasActualContent(array $nodes): bool + { + foreach ($nodes as $node) { + if (! $node instanceof TextNode || trim($node->content) !== '') { + return true; + } + } + + return false; + } + /** * Convert [BLAZE_ATTR:...] markers into conditional PHP for dynamic attributes. */ diff --git a/tests/Folder/FoldableTest.php b/tests/Folder/FoldableTest.php index 7def932..6ff77c7 100644 --- a/tests/Folder/FoldableTest.php +++ b/tests/Folder/FoldableTest.php @@ -402,3 +402,37 @@ expect((new Foldable($node, '', app(BladeRenderer::class), app(BladeService::class)))->fold()) ->toBe('
'); }); + +test('does not synthesize a default slot for whitespace-only loose content', function () { + $node = app(Parser::class)->parse('