From 7bdfcfdee98869509752a95d695bf136b1b0c7a3 Mon Sep 17 00:00:00 2001 From: Josh Hanley Date: Mon, 15 Jun 2026 10:31:39 +1000 Subject: [PATCH] Preserve literal static attributes when folding --- src/Parser/Attribute.php | 8 ++++++++ tests/ComparisonTest.php | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Parser/Attribute.php b/src/Parser/Attribute.php index cc9cb98..4c29d67 100644 --- a/src/Parser/Attribute.php +++ b/src/Parser/Attribute.php @@ -40,6 +40,14 @@ public function getStaticValue(): mixed throw new \LogicException("Cannot get static value of dynamic attribute '{$this->name}'."); } + if ($this->valueless) { + return true; + } + + if (! $this->bound()) { + return $this->value; + } + return match ($this->value) { 'true' => true, 'false' => false, diff --git a/tests/ComparisonTest.php b/tests/ComparisonTest.php index eb594de..155bd2a 100644 --- a/tests/ComparisonTest.php +++ b/tests/ComparisonTest.php @@ -58,6 +58,13 @@ ['readonly' => false], )); +test('foldable literal string attributes matching PHP constants', fn () => compare(<<<'BLADE' + + + + BLADE +)); + test('same component in a slot doesnt affect parents attributes', fn () => compare(<<<'BLADE' @@ -115,4 +122,4 @@ BLADE -)); \ No newline at end of file +));