Skip to content

Commit 555f79d

Browse files
committed
Fix annotations being written for nested inherited frames
1 parent 5311d7e commit 555f79d

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

src/XmlFileParser.php

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -172,35 +172,41 @@ private function childHasInterestingData(Frame $child): bool
172172

173173
private function writeFrame(Frame $frame, ?string $linkPrefix, ?string $typeOverride = null): string
174174
{
175+
$shouldWriteGlobal = $frame->getName() && $frame->getRootNode()::class === Frame::class;
175176
$data = '';
176177
$globalChildrenWithParentKey = [];
177-
foreach ($frame->getChildren() as $child) {
178-
if ($this->childHasInterestingData($child)) {
179-
$data .= $this->writeFrame($child, $linkPrefix);
180-
if ($child->getName() && $child->getParentKey()) {
181-
$globalChildrenWithParentKey[$child->getParentKey()] = $child->getName();
182-
}
183-
}
184-
}
185178
$inheritedKeyValues = [];
186-
foreach ($frame->getInherits() as $templateName) {
187-
$template = $this->templateRegistry->get($templateName);
188-
if (!$template) {
189-
continue;
190-
}
191-
foreach ($template->getKeyValues() as $key => $value) {
192-
$inheritedKeyValues[$key] = $value;
179+
if ($shouldWriteGlobal) {
180+
foreach ($frame->getChildren() as $child) {
181+
if ($this->childHasInterestingData($child)) {
182+
$data .= $this->writeFrame($child, $linkPrefix);
183+
if ($child->getName() && $child->getParentKey()) {
184+
$globalChildrenWithParentKey[$child->getParentKey()] = $child->getName();
185+
}
186+
}
193187
}
194-
foreach ($template->getChildren() as $child) {
195-
$clone = $child->withParent($frame);
196-
if (!empty($clone->getName())) { // will create a global
197-
$data .= $this->writeFrame(
198-
$clone,
199-
$linkPrefix,
200-
$this->childHasInterestingData($child) ? $child->getClassName() : $child->getType(), // this must be $child rather than $clone
201-
);
202-
if($clone->getParentKey()) {
203-
$inheritedKeyValues[$clone->getParentKey()] = [$clone->getName()];
188+
foreach ($frame->getInherits() as $templateName) {
189+
$template = $this->templateRegistry->get($templateName);
190+
if (!$template) {
191+
continue;
192+
}
193+
foreach ($template->getKeyValues() as $key => $value) {
194+
$inheritedKeyValues[$key] = $value;
195+
}
196+
foreach ($template->getChildren() as $child) {
197+
$clone = $child->withParent($frame);
198+
if (!empty($clone->getName())) { // will create a global
199+
$data .= $this->writeFrame(
200+
$clone,
201+
$linkPrefix,
202+
// this must be $child rather than $clone
203+
$this->childHasInterestingData($child)
204+
? $child->getClassName()
205+
: $child->getType(),
206+
);
207+
if ($clone->getParentKey()) {
208+
$inheritedKeyValues[$clone->getParentKey()] = [$clone->getName()];
209+
}
204210
}
205211
}
206212
}
@@ -246,7 +252,7 @@ private function writeFrame(Frame $frame, ?string $linkPrefix, ?string $typeOver
246252
}
247253
}
248254
}
249-
if ($frame->getName() && $frame->getRootNode()::class === Frame::class) {
255+
if ($shouldWriteGlobal) {
250256
$data .= $frame->getName() . " = {}\n";
251257
foreach ($globalChildrenWithParentKey as $key => $value) {
252258
$data .= $frame->getName() . '["' . $key . '"] = ' . $value . "\n";

0 commit comments

Comments
 (0)