mirror of
https://github.com/nikic/PHP-Parser.git
synced 2025-01-17 07:08:14 +01:00
Support empty list insertion for attributes
This commit is contained in:
parent
9dca6f1d37
commit
a2608f0b74
@ -920,7 +920,7 @@ abstract class PrettyPrinterAbstract {
|
||||
$result .= $this->p($delayedAddNode, true);
|
||||
$first = false;
|
||||
}
|
||||
$result .= $extraRight;
|
||||
$result .= $extraRight === "\n" ? $this->nl : $extraRight;
|
||||
}
|
||||
|
||||
return $result;
|
||||
@ -1448,6 +1448,16 @@ abstract class PrettyPrinterAbstract {
|
||||
'Stmt_ClassMethod->params' => ['(', '', ''],
|
||||
'Stmt_Interface->extends' => [null, ' extends ', ''],
|
||||
'Stmt_Function->params' => ['(', '', ''],
|
||||
'Stmt_Interface->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_Class->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_ClassConst->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_ClassMethod->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_Function->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_Property->attrGroups' => [null, '', "\n"],
|
||||
'Stmt_Trait->attrGroups' => [null, '', "\n"],
|
||||
'Expr_ArrowFunction->attrGroups' => [null, '', ' '],
|
||||
'Expr_Closure->attrGroups' => [null, '', ' '],
|
||||
'Expr_PrintableNewAnonClass->attrGroups' => [\T_NEW, ' ', ''],
|
||||
|
||||
/* These cannot be empty to start with:
|
||||
* Expr_Isset->vars
|
||||
|
@ -102,7 +102,6 @@ function() {};
|
||||
fn()
|
||||
=> 42;
|
||||
-----
|
||||
// TODO: Currently we lose formatting for this case.
|
||||
$attrGroup = new Node\AttributeGroup([
|
||||
new Node\Attribute(new Node\Name('A'), []),
|
||||
]);
|
||||
@ -119,39 +118,32 @@ $stmts[6]->expr->attrGroups[] = $attrGroup;
|
||||
-----
|
||||
<?php
|
||||
#[A]
|
||||
class X
|
||||
{
|
||||
class X {
|
||||
#[A]
|
||||
public function m()
|
||||
{
|
||||
}
|
||||
public function m() {}
|
||||
|
||||
#[A]
|
||||
public $prop;
|
||||
public
|
||||
$prop;
|
||||
|
||||
#[A]
|
||||
const X = 42;
|
||||
const
|
||||
X = 42;
|
||||
}
|
||||
|
||||
#[A]
|
||||
trait X
|
||||
{
|
||||
}
|
||||
trait X {}
|
||||
|
||||
#[A]
|
||||
interface X
|
||||
{
|
||||
}
|
||||
interface X {}
|
||||
|
||||
#[A]
|
||||
function f()
|
||||
{
|
||||
}
|
||||
function f() {}
|
||||
|
||||
new #[A] class
|
||||
{
|
||||
};
|
||||
#[A] function () {
|
||||
};
|
||||
#[A] fn() => 42;
|
||||
new #[A] class {};
|
||||
#[A] function() {};
|
||||
#[A] fn()
|
||||
=> 42;
|
||||
-----
|
||||
<?php
|
||||
|
||||
@ -176,4 +168,4 @@ class X {};
|
||||
B,
|
||||
C,
|
||||
]
|
||||
class X {};
|
||||
class X {};
|
||||
|
@ -107,4 +107,4 @@ Foo
|
||||
|
||||
new class
|
||||
($a, $b)
|
||||
extends Foo {};
|
||||
extends Foo {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user