Skip to content

Commit

Permalink
Parity with class component compiler changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnathonKoster committed Dec 10, 2023
1 parent 1cd2be3 commit 9bf25bc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Compiler/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public static function compileClassComponentOpening(string $component, string $a
{
return implode("\n", [
'<?php if (isset($component)) { $__componentOriginal'.$hash.' = $component; } ?>',
'<?php if (isset($attributes)) { $__attributesOriginal'.$hash.' = $attributes; } ?>',
'<?php $component = '.$component.'::resolve('.($data ?: '[]').' + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>',
'<?php $component->withName('.$alias.'); ?>',
'<?php if ($component->shouldRender()): ?>',
Expand Down
4 changes: 4 additions & 0 deletions src/Compiler/Concerns/CompilesComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function compileEndComponentClass(): string
$hash = array_pop(Compiler::$componentHashStack);

return $this->compileEndComponent()."\n".implode("\n", [
'<?php endif; ?>',
'<?php if (isset($__attributesOriginal'.$hash.')): ?>',
'<?php $attributes = $__attributesOriginal'.$hash.'; ?>',
'<?php unset($__attributesOriginal'.$hash.'); ?>',
'<?php endif; ?>',
'<?php if (isset($__componentOriginal'.$hash.')): ?>',
'<?php $component = $__componentOriginal'.$hash.'; ?>',
Expand Down
2 changes: 1 addition & 1 deletion tests/Compiler/BladeComponentTagCompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ public function testAttributesTreatedAsPropsAreRemovedFromFinalAttributes()
eval(" ?> $template <?php ");
ob_get_clean();

$this->assertNull($attributes->get('userId'));
$this->assertSame($attributes->get('userId'), 'bar');
$this->assertSame($attributes->get('other'), 'ok');
}

Expand Down
5 changes: 5 additions & 0 deletions tests/Compiler/BladeComponentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function testComponentsAreCompiled()
public function testClassComponentsAreCompiled()
{
$this->assertSame('<?php if (isset($component)) { $__componentOriginald797ca481a3632d6131474d33f4e32d7 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginald797ca481a3632d6131474d33f4e32d7 = $attributes; } ?>
<?php $component = Stillat\BladeParser\Tests\Compiler\ComponentStub::class::resolve(["foo" => "bar"] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? (array) $attributes->getIterator() : [])); ?>
<?php $component->withName(\'test\'); ?>
<?php if ($component->shouldRender()): ?>
Expand All @@ -37,6 +38,10 @@ public function testEndComponentClassesAreCompiled()

$this->assertSame('<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal79aef92e83454121ab6e5f64077e7d8a)): ?>
<?php $attributes = $__attributesOriginal79aef92e83454121ab6e5f64077e7d8a; ?>
<?php unset($__attributesOriginal79aef92e83454121ab6e5f64077e7d8a); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal79aef92e83454121ab6e5f64077e7d8a)): ?>
<?php $component = $__componentOriginal79aef92e83454121ab6e5f64077e7d8a; ?>
<?php unset($__componentOriginal79aef92e83454121ab6e5f64077e7d8a); ?>
Expand Down

0 comments on commit 9bf25bc

Please sign in to comment.