Skip to content

Commit

Permalink
Add space after component closing tag (#32005)
Browse files Browse the repository at this point in the history
  • Loading branch information
driesvints authored Mar 17, 2020
1 parent ec7d5b8 commit 48d1c19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/View/Compilers/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ protected function compileSelfClosingTags(string $value)

$attributes = $this->getAttributesFromAttributeString($matches['attributes']);

return $this->componentString($matches[1], $attributes)."\n@endcomponentClass";
return $this->componentString($matches[1], $attributes)."\n@endcomponentClass ";
}, $value);
}

Expand Down Expand Up @@ -270,7 +270,7 @@ protected function partitionDataAndAttributes($class, array $attributes)
*/
protected function compileClosingTags(string $value)
{
return preg_replace("/<\/\s*x[-\:][\w\-\:\.]*\s*>/", ' @endcomponentClass', $value);
return preg_replace("/<\/\s*x[-\:][\w\-\:\.]*\s*>/", ' @endcomponentClass ', $value);
}

/**
Expand Down
25 changes: 21 additions & 4 deletions tests/View/Blade/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ public function testBasicComponentParsing()

$this->assertSame("<div> @component('Illuminate\Tests\View\Blade\TestAlertComponent', [])
<?php \$component->withAttributes(['type' => 'foo','limit' => '5','@click' => 'foo','required' => true]); ?>
@endcomponentClass @component('Illuminate\Tests\View\Blade\TestAlertComponent', [])
@endcomponentClass @component('Illuminate\Tests\View\Blade\TestAlertComponent', [])
<?php \$component->withAttributes([]); ?>
@endcomponentClass</div>", trim($result));
@endcomponentClass </div>", trim($result));
}

public function testBasicComponentWithEmptyAttributesParsing()
Expand All @@ -42,7 +42,7 @@ public function testBasicComponentWithEmptyAttributesParsing()

$this->assertSame("<div> @component('Illuminate\Tests\View\Blade\TestAlertComponent', [])
<?php \$component->withAttributes(['type' => '','limit' => '','@click' => '','required' => true]); ?>
@endcomponentClass</div>", trim($result));
@endcomponentClass </div>", trim($result));
}

public function testDataCamelCasing()
Expand Down Expand Up @@ -91,7 +91,7 @@ public function testSelfClosingComponentsCanBeCompiled()

$this->assertSame("<div> @component('Illuminate\Tests\View\Blade\TestAlertComponent', [])
<?php \$component->withAttributes([]); ?>
@endcomponentClass</div>", trim($result));
@endcomponentClass </div>", trim($result));
}

public function testClassNamesCanBeGuessed()
Expand Down Expand Up @@ -140,6 +140,23 @@ public function testSelfClosingComponentsCanBeCompiledWithDataAndAttributes()
@endcomponentClass", trim($result));
}

public function testComponentsCanHaveAttachedWord()
{
$result = (new ComponentTagCompiler(['profile' => TestProfileComponent::class]))->compileTags('<x-profile></x-profile>Words');

$this->assertSame("@component('Illuminate\Tests\View\Blade\TestProfileComponent', [])
<?php \$component->withAttributes([]); ?> @endcomponentClass Words", trim($result));
}

public function testSelfClosingComponentsCanHaveAttachedWord()
{
$result = (new ComponentTagCompiler(['alert' => TestAlertComponent::class]))->compileTags('<x-alert/>Words');

$this->assertSame("@component('Illuminate\Tests\View\Blade\TestAlertComponent', [])
<?php \$component->withAttributes([]); ?>
@endcomponentClass Words", trim($result));
}

public function testSelfClosingComponentsCanBeCompiledWithBoundData()
{
$result = (new ComponentTagCompiler(['alert' => TestAlertComponent::class]))->compileTags('<x-alert :title="$title" class="bar" />');
Expand Down

0 comments on commit 48d1c19

Please sign in to comment.