From 4536d310a8cb902c50ffd5be9beed7e767d91174 Mon Sep 17 00:00:00 2001 From: John Koster Date: Mon, 27 Jan 2025 18:48:49 -0600 Subject: [PATCH] Improves compatibility with Volt The Volt precompiler can aggressively remove blocks. This is problematic for Dagger since it inlines nested components. This change utilizes raw component blocks to hide PHP contents from other pre-compilers. --- src/Compiler/TemplateCompiler.php | 3 ++- src/Runtime/ViewManifest.php | 5 +++++ tests/Compiler/AttributeForwardingTest.php | 2 -- tests/Compiler/DynamicComponentsTest.php | 2 -- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Compiler/TemplateCompiler.php b/src/Compiler/TemplateCompiler.php index ed49706..da8bd08 100644 --- a/src/Compiler/TemplateCompiler.php +++ b/src/Compiler/TemplateCompiler.php @@ -564,7 +564,8 @@ protected function compileNodes(array $nodes): string $compiledComponentTemplate = Str::swap($swapVars, $compiledComponentTemplate); $compiledComponentTemplate = $this->compileExceptions($compiledComponentTemplate); - $compiled .= $compiledComponentTemplate; + $compiled .= $this->storeComponentBlock($compiledComponentTemplate); + $this->stopCompilingComponent(); } diff --git a/src/Runtime/ViewManifest.php b/src/Runtime/ViewManifest.php index 1635b88..330fc2a 100644 --- a/src/Runtime/ViewManifest.php +++ b/src/Runtime/ViewManifest.php @@ -3,6 +3,7 @@ namespace Stillat\Dagger\Runtime; use Illuminate\Contracts\View\View; +use Illuminate\Support\Str; class ViewManifest { @@ -121,6 +122,10 @@ public function getRootStoragePaths(): array public function getStoragePath(string $rootView): string { + $rootView = Str::swap([ + ':' => '_', + ], $rootView); + return $this->cachePath."_compiler_manifest_{$rootView}.json"; } diff --git a/tests/Compiler/AttributeForwardingTest.php b/tests/Compiler/AttributeForwardingTest.php index 009f5ae..ac61499 100644 --- a/tests/Compiler/AttributeForwardingTest.php +++ b/tests/Compiler/AttributeForwardingTest.php @@ -64,14 +64,12 @@ - The First Button The Second Button The Third Button - No Title Component B Button Two diff --git a/tests/Compiler/DynamicComponentsTest.php b/tests/Compiler/DynamicComponentsTest.php index b811a6a..cf877ce 100644 --- a/tests/Compiler/DynamicComponentsTest.php +++ b/tests/Compiler/DynamicComponentsTest.php @@ -139,14 +139,12 @@ - The First Button The Second Button The Third Button - No Title Component B Button Two