@@ -170,6 +170,15 @@ private function childHasInterestingData(Frame $child): bool
170170 || !empty ($ child ->getChildren ());
171171 }
172172
173+ private function wrapInGIfNeeded (string $ name ): string
174+ {
175+ if (str_contains ($ name , '$ ' )) {
176+ return '_G[" ' . $ name . '"] ' ;
177+ }
178+
179+ return $ name ;
180+ }
181+
173182 private function writeFrame (Frame $ frame , ?string $ linkPrefix , ?string $ typeOverride = null ): string
174183 {
175184 $ shouldWriteGlobal = $ frame ->getRootNode ()->getName () && $ frame ->getRootNode ()::class === Frame::class;
@@ -234,19 +243,16 @@ private function writeFrame(Frame $frame, ?string $linkPrefix, ?string $typeOver
234243 }
235244 }
236245 if ($ shouldWriteGlobal && $ frame ->getName ()) {
237- $ name = $ frame ->getName ();
238- if (str_contains ($ name , '$ ' )) {
239- $ name = '_G[" ' . $ name . '"] ' ;
240- }
246+ $ name = $ this ->wrapInGIfNeeded ($ frame ->getName ());
241247 $ data .= $ name . " = {} \n" ;
242248 foreach ($ globalChildrenWithParentKey as $ key => $ value ) {
243- $ data .= $ frame -> getName () . '[" ' . $ key . '"] = ' . $ value . "\n" ;
249+ $ data .= $ name . '[" ' . $ key . '"] = ' . $ this -> wrapInGIfNeeded ( $ value) . "\n" ;
244250 }
245251 foreach ($ frame ->getKeyValues () as $ key => $ value ) {
246- $ data .= $ frame -> getName () . '[" ' . $ key . '"] = ' . $ value [0 ] . "\n" ;
252+ $ data .= $ name . '[" ' . $ key . '"] = ' . $ this -> wrapInGIfNeeded ( $ value [0 ]) . "\n" ;
247253 }
248254 foreach ($ inheritedKeyValues as $ key => $ value ) {
249- $ data .= $ frame -> getName () . '[" ' . $ key . '"] = ' . $ value [0 ] . " -- inherited \n" ;
255+ $ data .= $ name . '[" ' . $ key . '"] = ' . $ this -> wrapInGIfNeeded ( $ value [0 ]) . " -- inherited \n" ;
250256 }
251257 }
252258
@@ -277,11 +283,7 @@ private function handleInherits(Frame $frame, array &$inheritedKeyValues, ?strin
277283 : $ child ->getType (),
278284 );
279285 if ($ clone ->getParentKey ()) {
280- $ name = $ clone ->getName ();
281- if (str_contains ($ name , '$ ' )) {
282- $ name = '_G[" ' . $ name . '"] ' ;
283- }
284- $ inheritedKeyValues [$ clone ->getParentKey ()] = [$ name ];
286+ $ inheritedKeyValues [$ clone ->getParentKey ()] = [$ this ->wrapInGIfNeeded ($ clone ->getName ())];
285287 }
286288 }
287289 }
0 commit comments