Skip to content

Commit

Permalink
[9.x] Fix undefined constant error when use slot name as key of object (
Browse files Browse the repository at this point in the history
#42943)

* modify name if inline name is not empty

* styleci fix

* key of object of dynamic slot name tests added
  • Loading branch information
monurakkaya authored Jun 27, 2022
1 parent 1711a5c commit 3b3a568
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/View/Compilers/ComponentTagCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ public function compileSlots(string $value)
$value = preg_replace_callback($pattern, function ($matches) {
$name = $this->stripQuotes($matches['inlineName'] ?: $matches['name']);

if (Str::contains($name, '-')) {
if (Str::contains($name, '-') && ! empty($matches['inlineName'])) {
$name = Str::camel($name);
}

Expand Down
8 changes: 8 additions & 0 deletions tests/View/Blade/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ public function testDynamicSlotsCanBeCompiled()
$this->assertSame("@slot(\$foo, null, []) \n".' @endslot', trim($result));
}

public function testDynamicSlotsCanBeCompiledWithKeyOfObjects()
{
$result = $this->compiler()->compileSlots('<x-slot :name="$foo->name">
</x-slot>');

$this->assertSame("@slot(\$foo->name, null, []) \n".' @endslot', trim($result));
}

public function testSlotsWithAttributesCanBeCompiled()
{
$result = $this->compiler()->compileSlots('<x-slot name="foo" class="font-bold">
Expand Down

0 comments on commit 3b3a568

Please sign in to comment.