php8.1: added readonly modifier (#6)

This commit is contained in:
Makhnev Petr
2021-07-31 18:00:21 +03:00
committed by GitHub
parent 4d0bfa25aa
commit 8c35b0aef1
18 changed files with 7662 additions and 7053 deletions

View File

@@ -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)

View File

@@ -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(" "))
}

View File

@@ -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)

View 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,
) {}
}
`)
}

View File

@@ -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)