Skip to content

Commit 6ed014f

Browse files
committed
fix null props not overwrite parent context
1 parent bdd3107 commit 6ed014f

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/TwigComponent/src/Twig/PropsNode.php

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,23 @@ public function compile(Compiler $compiler): void
7373
->raw(";\n")
7474
->outdent()
7575
->write('}')
76-
->write("\n");
76+
->write("\n")
77+
;
78+
79+
// overwrite the context value if a props with a similar name and a default value exist
80+
if ($this->hasNode($name)) {
81+
$compiler
82+
->write('if (isset($context[\'__context\'][\''.$name.'\'])) {')
83+
->raw("\n")
84+
->indent()
85+
->write('$context[\''.$name.'\'] = ')
86+
->subcompile($this->getNode($name))
87+
->raw(";\n")
88+
->outdent()
89+
->write('}')
90+
->raw("\n")
91+
;
92+
}
7793
}
7894

7995
$compiler
@@ -94,20 +110,5 @@ public function compile(Compiler $compiler): void
94110
->write('}')
95111
->raw("\n")
96112
;
97-
98-
// overwrite the context value if a props with a similar name and a default value exist
99-
if ($this->hasNode($name)) {
100-
$compiler
101-
->write('if (isset($context[\'__context\'][\''.$name.'\'])) {')
102-
->raw("\n")
103-
->indent()
104-
->write('$context[\''.$name.'\'] = ')
105-
->subcompile($this->getNode($name))
106-
->raw(";\n")
107-
->outdent()
108-
->write('}')
109-
->raw("\n")
110-
;
111-
}
112113
}
113114
}

0 commit comments

Comments
 (0)