Skip to content

Commit ddf6d08

Browse files
committed
bug #1988 Fix random errors are throw when empty props (WebMamba)
This PR was merged into the 2.x branch. Discussion ---------- Fix random errors are throw when empty props | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | Fix #1971 | License | MIT We don't throw an exeption when the props tags is empty now. Commits ------- 5e2fb81 Fix random errors are throw when empty props
2 parents 58e21bb + 5e2fb81 commit ddf6d08

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

src/TwigComponent/src/Twig/PropsNode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ public function compile(Compiler $compiler): void
3535
->write('$propsNames = [];')
3636
;
3737

38+
if (!$this->getAttribute('names')) {
39+
return;
40+
}
41+
3842
foreach ($this->getAttribute('names') as $name) {
3943
$compiler
4044
->write('if (isset($context[\'__props\'][\''.$name.'\'])) {')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<twig:EmptyProps/>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% props %}
2+
3+
<p>I have an empty props tag</p>

src/TwigComponent/tests/Integration/ComponentExtensionTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,13 @@ public function testComponentWithConflictBetweenPropsFromTemplateAndClass(): voi
366366
self::getContainer()->get(Environment::class)->render('component_with_conflict_between_props_from_template_and_class.html.twig');
367367
}
368368

369+
public function testComponentWithEmptyProps(): void
370+
{
371+
$output = self::getContainer()->get(Environment::class)->render('anonymous_component_with_empty_props.html.twig');
372+
373+
$this->assertStringContainsString('I have an empty props tag', $output);
374+
}
375+
369376
public function testAnonymousComponentWithPropsOverwriteParentsProps(): void
370377
{
371378
$output = self::getContainer()->get(Environment::class)->render('anonymous_component_with_props_overwrite_parents_props.html.twig');

0 commit comments

Comments
 (0)