@@ -76,7 +76,7 @@ public function getKeywords(): array
7676 return [
7777 'slot ' => static function (string $ name ): array {
7878 return [
79- 'begin ' => '<?php if ( ' .static ::class.'::slot( ' .var_export ($ name , true ).', get_defined_vars())) { ?> ' ,
79+ 'begin ' => '<?php if ( \\ ' .static ::class.'::slot( ' .var_export ($ name , true ).', get_defined_vars())) { ?> ' ,
8080 'end ' => '<?php } ?> ' ,
8181 ];
8282 },
@@ -120,7 +120,17 @@ public function handleNodeEvent(NodeEvent $event): void
120120
121121 public function handleOutputEvent (OutputEvent $ event ): void
122122 {
123- $ event ->setOutput ($ this ->parseOutput ($ event ->getOutput ()));
123+ $ event ->prependCode (implode ("\n" , [
124+ '$firstMixin = function (string ...$names) use (&$__pug_mixins) { ' ,
125+ ' foreach ($names as $name) { ' ,
126+ ' if (isset($__pug_mixins[$name])) { ' ,
127+ ' return $name; ' ,
128+ ' } ' ,
129+ ' } ' ,
130+ ' throw new \\InvalidArgumentException("No defined mixin/component in [".implode(", ", $names)."]"); ' ,
131+ '}; ' ,
132+ '$firstComponent = $firstMixin; ' ,
133+ ]));
124134 }
125135
126136 public function attachEvents (): void
@@ -136,27 +146,4 @@ public function detachEvents(): void
136146 $ compiler ->detach (CompilerEvent::NODE , [$ this , 'handleNodeEvent ' ]);
137147 $ compiler ->detach (CompilerEvent::OUTPUT , [$ this , 'handleOutputEvent ' ]);
138148 }
139-
140- private function parseOutput (string $ output ): string
141- {
142- $ mixinFunctionsCode = implode ("\n" , [
143- '' ,
144- '$firstMixin = function (string ...$names) use (&$__pug_mixins) { ' ,
145- ' foreach ($names as $name) { ' ,
146- ' if (isset($__pug_mixins[$name])) { ' ,
147- ' return $name; ' ,
148- ' } ' ,
149- ' } ' ,
150- ' throw new \\InvalidArgumentException("No defined mixin/component in [".implode(", ", $names)."]"); ' ,
151- '}; ' ,
152- '$firstComponent = $firstMixin; ' ,
153- '' ,
154- ]);
155-
156- if (preg_match ('/^(<\?(?:php)?\s+namespace\s\S.*)((\n[\s\S]*)?)$/U ' , $ output , $ matches )) {
157- return $ matches [1 ].$ mixinFunctionsCode .$ matches [2 ];
158- }
159-
160- return "<?php $ mixinFunctionsCode?> $ output " ;
161- }
162149}
0 commit comments