diff --git a/src/Tags/BladeHost.php b/src/Tags/BladeHost.php
index 476a6e1..d3f08e4 100644
--- a/src/Tags/BladeHost.php
+++ b/src/Tags/BladeHost.php
@@ -2,6 +2,7 @@
namespace Stillat\AntlersComponents\Tags;
+use Illuminate\View\AnonymousComponent;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Compilers\ComponentTagCompiler;
use Illuminate\View\ComponentAttributeBag;
@@ -27,18 +28,31 @@ public function component(): string
$componentTagCompiler = $this->makeComponentTagCompiler();
$componentName = $this->params->get('component');
$className = $componentTagCompiler->componentClass($componentName);
+
$attributes = new ComponentAttributeBag($this->params->except('component')->all());
$constructorParameters = [];
$scopeData = $this->context->all();
$scopeData = array_merge($scopeData, $this->params->except('component')->all());
+ $isAnonymous = false;
+ $anonymousViewName = $className;
+
+ if (! class_exists($className)) {
+ $isAnonymous = true;
+ $className = AnonymousComponent::class;
+ }
+
if ($constructor = (new ReflectionClass($className))->getConstructor()) {
$constructorParameters = collect($constructor->getParameters())->map->getName()->all();
$attributes = $attributes->except($constructorParameters);
$constructorParameters = collect($scopeData)->only($constructorParameters)->all();
}
+ if ($isAnonymous) {
+ $constructorParameters = array_merge($constructorParameters, ['view' => $anonymousViewName, 'data' => []]);
+ }
+
$__env = $this->context['__env'] ?? view();
$component = $className::resolve($constructorParameters + ((array) $attributes->getIterator()));
diff --git a/tests/BladeComponentsTest.php b/tests/BladeComponentsTest.php
index dbae208..e8c4e80 100644
--- a/tests/BladeComponentsTest.php
+++ b/tests/BladeComponentsTest.php
@@ -62,6 +62,25 @@ public function testBladeComponentsWithSlots()
Footer
+EXP;
+
+ $this->assertSame($expected, $this->renderString($template));
+ }
+
+ public function testRenderingAnonymousComponents()
+ {
+ $template = <<<'EOT'
+