php8.1: added readonly modifier (#6)
This commit is contained in:
@@ -194,7 +194,7 @@ func (v *Dumper) Parameter(n *ast.Parameter) {
|
||||
|
||||
v.dumpPosition(n.Position)
|
||||
v.dumpVertexList("AttrGroups", n.AttrGroups)
|
||||
v.dumpVertex("Visibility", n.Visibility)
|
||||
v.dumpVertexList("Modifiers", n.Modifiers)
|
||||
v.dumpVertex("Type", n.Type)
|
||||
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
|
||||
v.dumpToken("VariadicTkn", n.VariadicTkn)
|
||||
|
||||
@@ -161,8 +161,8 @@ func (f *formatter) Parameter(n *ast.Parameter) {
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
|
||||
}
|
||||
|
||||
if n.Visibility != nil {
|
||||
n.Visibility.Accept(f)
|
||||
for _, modifier := range n.Modifiers {
|
||||
modifier.Accept(f)
|
||||
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ func (p *printer) Nullable(n *ast.Nullable) {
|
||||
|
||||
func (p *printer) Parameter(n *ast.Parameter) {
|
||||
p.printList(n.AttrGroups)
|
||||
p.printNode(n.Visibility)
|
||||
p.printList(n.Modifiers)
|
||||
p.printNode(n.Type)
|
||||
p.printToken(n.AmpersandTkn, nil)
|
||||
p.printToken(n.VariadicTkn, nil)
|
||||
|
||||
25
pkg/visitor/printer/printer_php8_1_test.go
Normal file
25
pkg/visitor/printer/printer_php8_1_test.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package printer_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/VKCOM/php-parser/internal/tester"
|
||||
)
|
||||
|
||||
func TestParseAndPrintReadonlyModifierPHP81(t *testing.T) {
|
||||
tester.NewParserPrintTestSuite(t).UsePHP8().Run(`<?php
|
||||
class Foo {
|
||||
readonly string $a;
|
||||
private readonly string $a;
|
||||
private string $a;
|
||||
private readonly $a = 100;
|
||||
|
||||
public function __construct(
|
||||
readonly string $a,
|
||||
private readonly string $a,
|
||||
private string $a,
|
||||
private readonly $a = 100,
|
||||
) {}
|
||||
}
|
||||
`)
|
||||
}
|
||||
@@ -41,7 +41,10 @@ func (t *Traverser) Parameter(n *ast.Parameter) {
|
||||
nn.Accept(t)
|
||||
}
|
||||
|
||||
t.Traverse(n.Visibility)
|
||||
for _, nn := range n.Modifiers {
|
||||
nn.Accept(t)
|
||||
}
|
||||
|
||||
t.Traverse(n.Type)
|
||||
t.Traverse(n.Var)
|
||||
t.Traverse(n.DefaultValue)
|
||||
|
||||
Reference in New Issue
Block a user