mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-11-30 04:29:15 +01:00
Fix issue #251
This commit is contained in:
parent
c8282e6e76
commit
9829bf69cd
@ -129,14 +129,11 @@ abstract class PrettyPrinterAbstract
|
||||
return "<?php\n\n";
|
||||
}
|
||||
|
||||
$p = $this->prettyPrint($stmts);
|
||||
$p = "<?php\n\n" . $this->prettyPrint($stmts);
|
||||
|
||||
if ($stmts[0] instanceof Stmt\InlineHTML) {
|
||||
$p = preg_replace('/^\?>\n?/', '', $p);
|
||||
} else {
|
||||
$p = "<?php\n\n" . $p;
|
||||
$p = preg_replace('/^<\?php\s+\?>\n?/', '', $p);
|
||||
}
|
||||
|
||||
if ($stmts[count($stmts) - 1] instanceof Stmt\InlineHTML) {
|
||||
$p = preg_replace('/<\?php$/', '', rtrim($p));
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace PhpParser;
|
||||
|
||||
use PhpParser\Comment;
|
||||
use PhpParser\Node\Expr;
|
||||
use PhpParser\Node\Scalar\String_;
|
||||
use PhpParser\Node\Stmt;
|
||||
@ -87,6 +88,14 @@ class PrettyPrinterTest extends CodeTestAbstract
|
||||
$this->assertEquals("function () {\n return 'a\nb';\n}", $prettyPrinter->prettyPrintExpr($expr));
|
||||
}
|
||||
|
||||
public function testCommentBeforeInlineHTML() {
|
||||
$prettyPrinter = new PrettyPrinter\Standard;
|
||||
$comment = new Comment\Doc("/**\n * This is a comment\n */");
|
||||
$stmts = [new Stmt\InlineHTML('Hello World!', ['comments' => [$comment]])];
|
||||
$expected = "<?php\n\n/**\n * This is a comment\n */\n?>\nHello World!";
|
||||
$this->assertSame($expected, $prettyPrinter->prettyPrintFile($stmts));
|
||||
}
|
||||
|
||||
private function parseModeLine($modeLine) {
|
||||
$parts = explode(' ', $modeLine, 2);
|
||||
$version = isset($parts[0]) ? $parts[0] : 'both';
|
||||
|
Loading…
Reference in New Issue
Block a user