From 8dea3b49412371a327dcdf461b601aa1d6ea6cfa Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Fri, 25 Sep 2020 16:07:38 +0200 Subject: [PATCH] Support namespace with debug mode on --- src/Phug/Formatter/Formatter/Util/PhpUnwrapString.php | 10 ++++++++++ tests/Phug/CasesTest.php | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Phug/Formatter/Formatter/Util/PhpUnwrapString.php b/src/Phug/Formatter/Formatter/Util/PhpUnwrapString.php index 169c1cb3..5b0929f5 100644 --- a/src/Phug/Formatter/Formatter/Util/PhpUnwrapString.php +++ b/src/Phug/Formatter/Formatter/Util/PhpUnwrapString.php @@ -18,10 +18,20 @@ public static function withoutOpenTag($code) { $unwrappedCode = new self($code); $unwrappedCode->unwrapStart(); + $unwrappedCode->movePhugCodeAfterNamespace(); return $unwrappedCode; } + public function movePhugCodeAfterNamespace() + { + $this->code = preg_replace( + '/^((?:[ \t]*(?:\\\\Phug\\\\.*\n|\\/\\/.*\n|(?:\?><\?php)?[ \t\n]+)?)*)(namespace (?:.*)\n)/', + '$2$1', + $this->code + ); + } + public function unwrapStart() { $this->code = preg_match('/^<\?php\s/', $this->code) diff --git a/tests/Phug/CasesTest.php b/tests/Phug/CasesTest.php index 91b47397..c5fa5911 100644 --- a/tests/Phug/CasesTest.php +++ b/tests/Phug/CasesTest.php @@ -28,7 +28,7 @@ public function caseProvider() public function testRender($expected, $actual, $message) { $debug = $this->renderer->getOption('debug'); - $this->renderer->setOption('debug', pathinfo($actual)['filename'] !== 'scope'); + $this->renderer->setOption('debug', true); $render = $this->renderer->renderFile($actual); $this->renderer->setOption('debug', $debug);