Skip to content

Commit

Permalink
[9.x] Short attribute syntax for Self Closing Blade Components (#44413)
Browse files Browse the repository at this point in the history
* Short attribute syntax for Self Closing Blade Components

* Fix test
  • Loading branch information
PerryvanderMeer authored Oct 3, 2022
1 parent 031b7d1 commit fa0b45c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/View/Compilers/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ protected function compileSelfClosingTags(string $value)
\{\{\s*\\\$attributes(?:[^}]+?)?\s*\}\}
)
|
(?:
(\:\\\$)(\w+)
)
|
(?:
[\w\-:.@]+
(
Expand Down
12 changes: 12 additions & 0 deletions tests/View/Blade/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,18 @@ public function testColonDataShortSyntax()
<?php \$component->withAttributes([]); ?> @endComponentClass##END-COMPONENT-CLASS##", trim($result));
}

public function testSelfClosingComponentWithColonDataShortSyntax()
{
$result = $this->compiler(['profile' => TestProfileComponent::class])->compileTags('<x-profile :$userId/>');

$this->assertSame("##BEGIN-COMPONENT-CLASS##@component('Illuminate\Tests\View\Blade\TestProfileComponent', 'profile', ['userId' => \$userId])
<?php if (isset(\$attributes) && \$constructor = (new ReflectionClass(Illuminate\Tests\View\Blade\TestProfileComponent::class))->getConstructor()): ?>
<?php \$attributes = \$attributes->except(collect(\$constructor->getParameters())->map->getName()->all()); ?>
<?php endif; ?>
<?php \$component->withAttributes([]); ?>\n".
'@endComponentClass##END-COMPONENT-CLASS##', trim($result));
}

public function testEscapedColonAttribute()
{
$result = $this->compiler(['profile' => TestProfileComponent::class])->compileTags('<x-profile :user-id="1" ::title="user.name"></x-profile>');
Expand Down

0 comments on commit fa0b45c

Please sign in to comment.