Skip to content

Commit 05e9d7e

Browse files
committed
Keep namespace statements at file beginning
1 parent 086536a commit 05e9d7e

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/JsPhpize/Traits/Compilation.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ protected function parseOutput($compiler, $output)
8888

8989
$dependencies = $jsPhpize->compileDependencies();
9090
if ($dependencies !== '') {
91-
$output = $compiler->getFormatter()->handleCode($dependencies) . $output;
91+
$dependencies = $compiler->getFormatter()->handleCode($dependencies);
92+
$output = preg_match('/^(<\?(?:php)?\s+namespace\s\S.*)(((?:;|\n|\?>)[\s\S]*)?)$/U', $output, $matches)
93+
? $matches[1] . $dependencies . $matches[2]
94+
: $dependencies . $output;
9295
}
9396

9497
$jsPhpize->flushDependencies();

0 commit comments

Comments
 (0)