php8.1: added intersection types support (#29)
This commit is contained in:
@@ -261,6 +261,17 @@ func (v *Dumper) Union(n *ast.Union) {
|
||||
v.print(v.indent, "},\n")
|
||||
}
|
||||
|
||||
func (v *Dumper) Intersection(n *ast.Intersection) {
|
||||
v.print(0, "&ast.Intersection{\n")
|
||||
v.indent++
|
||||
|
||||
v.dumpPosition(n.Position)
|
||||
v.dumpVertexList("Types", n.Types)
|
||||
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
|
||||
|
||||
v.indent--
|
||||
v.print(v.indent, "},\n")
|
||||
}
|
||||
func (v *Dumper) Attribute(n *ast.Attribute) {
|
||||
v.print(0, "&ast.Attribute{\n")
|
||||
v.indent++
|
||||
|
||||
@@ -237,6 +237,12 @@ func (f *formatter) Union(n *ast.Union) {
|
||||
}
|
||||
}
|
||||
|
||||
func (f *formatter) Intersection(n *ast.Intersection) {
|
||||
if len(n.Types) > 0 {
|
||||
n.SeparatorTkns = f.formatList(n.Types, '&')
|
||||
}
|
||||
}
|
||||
|
||||
func (f *formatter) Attribute(n *ast.Attribute) {
|
||||
n.Name.Accept(f)
|
||||
n.OpenParenthesisTkn = f.newToken('(', []byte("("))
|
||||
|
||||
@@ -50,6 +50,10 @@ func (v *Null) Union(_ *ast.Union) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) Intersection(_ *ast.Intersection) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) Attribute(_ *ast.Attribute) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -180,6 +180,10 @@ func (p *printer) Union(n *ast.Union) {
|
||||
p.printSeparatedList(n.Types, n.SeparatorTkns, []byte("|"))
|
||||
}
|
||||
|
||||
func (p *printer) Intersection(n *ast.Intersection) {
|
||||
p.printSeparatedList(n.Types, n.SeparatorTkns, []byte("&"))
|
||||
}
|
||||
|
||||
func (p *printer) Attribute(n *ast.Attribute) {
|
||||
p.printNode(n.Name)
|
||||
p.printToken(n.OpenParenthesisTkn, p.ifNodeList(n.Args, []byte("(")))
|
||||
|
||||
@@ -104,3 +104,13 @@ $foo = $closure->__invoke(...);
|
||||
// new Foo(...); // not working
|
||||
`)
|
||||
}
|
||||
|
||||
func TestIntersectionTypesSyntaxPHP81(t *testing.T) {
|
||||
tester.NewParserPrintTestSuite(t).UsePHP8().Run(`<?php
|
||||
class Test {
|
||||
public A&B $prop;
|
||||
}
|
||||
|
||||
function test(A&B $a): A&B {}
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -78,6 +78,14 @@ func (t *Traverser) Union(n *ast.Union) {
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Traverser) Intersection(n *ast.Intersection) {
|
||||
n.Accept(t.v)
|
||||
|
||||
for _, nn := range n.Types {
|
||||
nn.Accept(t)
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Traverser) Attribute(n *ast.Attribute) {
|
||||
n.Accept(t.v)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user