From d7f68ba6342aacad7247ecb755c1235e18be86b3 Mon Sep 17 00:00:00 2001 From: nickpoulos Date: Sat, 12 Jun 2021 01:44:27 +0000 Subject: [PATCH] Fix styling --- src/SvelteDirectServiceProvider.php | 2 ++ tests/SvelteDirectTest.php | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/SvelteDirectServiceProvider.php b/src/SvelteDirectServiceProvider.php index 4e856aa..d93e6ba 100644 --- a/src/SvelteDirectServiceProvider.php +++ b/src/SvelteDirectServiceProvider.php @@ -76,6 +76,7 @@ public function loadBladePreCompiler() : void public function precompiler(string $viewTemplateCode) { $tagsToLoad = $this->findSvelteComponentTagsInBlade($viewTemplateCode); + return $viewTemplateCode . $this->appendPushDirective($tagsToLoad); } @@ -93,6 +94,7 @@ public function findSvelteComponentTagsInBlade(string $view) : array $tagPattern = implode('|', array_keys($this->manifest)); $pattern = "/(?<=<)\s*(?:{$tagPattern})(?=\s|>|\/)+/"; preg_match_all($pattern, $view, $matches); + return array_intersect(array_keys($this->manifest), array_unique($matches[0])); } diff --git a/tests/SvelteDirectTest.php b/tests/SvelteDirectTest.php index 852e816..b117b51 100644 --- a/tests/SvelteDirectTest.php +++ b/tests/SvelteDirectTest.php @@ -33,7 +33,7 @@ class SvelteDirectTest extends TestCase */ protected array $testManifest = [ 'test-tag' => '/js/TestTag.js', - 'nick-poulos' => '/js/NickPoulos.js' + 'nick-poulos' => '/js/NickPoulos.js', ]; /** @@ -203,23 +203,23 @@ public function bladeTemplateCodeDataProvider() : array return [ "Regular Style Tags" => [ $expectedResultWhenFound, - $regularStyleTags + $regularStyleTags, ], "Single Closing Style Tags" => [ $expectedResultWhenFound, - $singleClosingStyleTags + $singleClosingStyleTags, ], "Nested Regular Style Tags" => [ $expectedResultWhenFound, - $nestedRegularStyleTags + $nestedRegularStyleTags, ], "Nested Single Closing Style Tags" => [ $expectedResultWhenFound, - $nestedSingleClosingStyleTags + $nestedSingleClosingStyleTags, ], "Broken Tag That Is Close" => [ $expectedResultWhenNotFound, - $brokenTagsWithCloseName + $brokenTagsWithCloseName, ], ]; } @@ -232,7 +232,7 @@ protected function buildTestManifestCode(array $testManifest) : string { $result = " '" . $jsFile . "'," . PHP_EOL; });