Skip to content

Commit ccfa9e3

Browse files
committed
wip
1 parent 9e682d7 commit ccfa9e3

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

packages/view/src/Elements/ElementFactory.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,6 @@ private function makeElement(Token $token, ?Element $parent): ?Element
8888
$viewComponentClass->setToken($token);
8989
}
9090

91-
if ($viewComponentClass === AnonymousViewComponent::class) {
92-
$attributes = implode(' ', $attributes);
93-
throw new \Exception($token->tag . ' ' . $attributes . ' not resolved');
94-
}
95-
9691
if (! ($viewComponentClass instanceof ViewComponent)) {
9792
$viewComponentClass = $this->container->get($viewComponentClass);
9893
}

packages/view/src/ViewComponentDiscovery.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,17 @@ public function discoverPath(DiscoveryLocation $location, string $path): void
4747

4848
$contents = str(file_get_contents($path))->ltrim();
4949

50-
preg_match('/(?<header>(.|\n)*?)<x-component name="(?<name>[\w\-]+)">/', $contents->toString(), $matches);
51-
52-
$view = $contents
53-
->replaceRegex('/(?<header>(.|\n)*?)<x-component name="(?<name>[\w\-]+)">/', '')
54-
->replaceRegex('/<\/x-component>$/', '')
55-
->toString();
50+
preg_match(
51+
pattern: '/(?<header>(.|\n)*?)<x-component name="(?<name>[\w\-]+)">(?<view>(.|\n)*?)<\/x-component>/',
52+
subject: $contents->toString(),
53+
matches: $matches,
54+
);
5655

5756
if ($fileName->startsWith('x-') && ! isset($matches['name'])) {
5857
$this->discoveryItems->add($location, [
5958
$fileName->toString(),
6059
new AnonymousViewComponent(
61-
contents: $view,
60+
contents: $matches['view'] ?? $contents->toString(),
6261
file: $path,
6362
),
6463
]);
@@ -73,7 +72,7 @@ public function discoverPath(DiscoveryLocation $location, string $path): void
7372
$this->discoveryItems->add($location, [
7473
$matches['name'],
7574
new AnonymousViewComponent(
76-
contents: $matches['header'] . $view,
75+
contents: $matches['header'] . $matches['view'],
7776
file: $path,
7877
),
7978
]);

0 commit comments

Comments
 (0)