php8.2: added readonly classes support (#26)
This commit is contained in:
parent
3dd40d3b5a
commit
7f6cd25376
101
internal/php8/parser_php8_2_test.go
Normal file
101
internal/php8/parser_php8_2_test.go
Normal file
@ -0,0 +1,101 @@
|
||||
package php8_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/VKCOM/php-parser/internal/tester"
|
||||
)
|
||||
|
||||
func TestClassReadonlyModifier(t *testing.T) {
|
||||
suite := tester.NewParserDumpTestSuite(t)
|
||||
suite.UsePHP8()
|
||||
suite.Code = `<?php
|
||||
readonly class Foo {
|
||||
public string $a;
|
||||
}
|
||||
|
||||
final readonly class Boo {
|
||||
public string $a;
|
||||
}
|
||||
`
|
||||
|
||||
suite.Expected = `&ast.Root{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtClass{
|
||||
Modifiers: []ast.Vertex{
|
||||
&ast.Identifier{
|
||||
Val: []byte("readonly"),
|
||||
},
|
||||
},
|
||||
Name: &ast.Identifier{
|
||||
Val: []byte("Foo"),
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtPropertyList{
|
||||
Modifiers: []ast.Vertex{
|
||||
&ast.Identifier{
|
||||
Val: []byte("public"),
|
||||
},
|
||||
},
|
||||
Type: &ast.Name{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NamePart{
|
||||
Val: []byte("string"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Props: []ast.Vertex{
|
||||
&ast.StmtProperty{
|
||||
Var: &ast.ExprVariable{
|
||||
Name: &ast.Identifier{
|
||||
Val: []byte("$a"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
&ast.StmtClass{
|
||||
Modifiers: []ast.Vertex{
|
||||
&ast.Identifier{
|
||||
Val: []byte("final"),
|
||||
},
|
||||
&ast.Identifier{
|
||||
Val: []byte("readonly"),
|
||||
},
|
||||
},
|
||||
Name: &ast.Identifier{
|
||||
Val: []byte("Boo"),
|
||||
},
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtPropertyList{
|
||||
Modifiers: []ast.Vertex{
|
||||
&ast.Identifier{
|
||||
Val: []byte("public"),
|
||||
},
|
||||
},
|
||||
Type: &ast.Name{
|
||||
Parts: []ast.Vertex{
|
||||
&ast.NamePart{
|
||||
Val: []byte("string"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Props: []ast.Vertex{
|
||||
&ast.StmtProperty{
|
||||
Var: &ast.ExprVariable{
|
||||
Name: &ast.Identifier{
|
||||
Val: []byte("$a"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},`
|
||||
|
||||
suite.Run()
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -869,6 +869,7 @@ class_modifiers:
|
||||
class_modifier:
|
||||
T_ABSTRACT { $$ = yylex.(*Parser).builder.NewIdentifier($1) }
|
||||
| T_FINAL { $$ = yylex.(*Parser).builder.NewIdentifier($1) }
|
||||
| T_READONLY { $$ = yylex.(*Parser).builder.NewIdentifier($1) }
|
||||
;
|
||||
|
||||
class_declaration_statement:
|
||||
|
Loading…
Reference in New Issue
Block a user