php8.1: added first class callable syntax (#18)

This commit is contained in:
Makhnev Petr
2021-07-31 23:50:59 +03:00
committed by GitHub
parent 13ed0df282
commit 50ed139750
9 changed files with 2096 additions and 2037 deletions

View File

@@ -787,6 +787,7 @@ func (p *printer) ExprFunctionCall(n *ast.ExprFunctionCall) {
p.printNode(n.Function)
p.printToken(n.OpenParenthesisTkn, []byte("("))
p.printSeparatedList(n.Args, n.SeparatorTkns, []byte(","))
p.printToken(n.EllipsisTkn, nil)
p.printToken(n.CloseParenthesisTkn, []byte(")"))
}
@@ -828,6 +829,7 @@ func (p *printer) ExprMethodCall(n *ast.ExprMethodCall) {
p.printToken(n.CloseCurlyBracketTkn, nil)
p.printToken(n.OpenParenthesisTkn, []byte("("))
p.printSeparatedList(n.Args, n.SeparatorTkns, []byte(","))
p.printToken(n.EllipsisTkn, nil)
p.printToken(n.CloseParenthesisTkn, []byte(")"))
}
@@ -839,6 +841,7 @@ func (p *printer) ExprNullsafeMethodCall(n *ast.ExprNullsafeMethodCall) {
p.printToken(n.CloseCurlyBracketTkn, nil)
p.printToken(n.OpenParenthesisTkn, []byte("("))
p.printSeparatedList(n.Args, n.SeparatorTkns, []byte(","))
p.printToken(n.EllipsisTkn, nil)
p.printToken(n.CloseParenthesisTkn, []byte(")"))
}
@@ -915,6 +918,7 @@ func (p *printer) ExprStaticCall(n *ast.ExprStaticCall) {
p.printToken(n.CloseCurlyBracketTkn, nil)
p.printToken(n.OpenParenthesisTkn, p.ifNodeList(n.Args, []byte("(")))
p.printSeparatedList(n.Args, n.SeparatorTkns, []byte(","))
p.printToken(n.EllipsisTkn, nil)
p.printToken(n.CloseParenthesisTkn, p.ifNodeList(n.Args, []byte(")")))
}

View File

@@ -84,3 +84,23 @@ class Foo {
}
`)
}
func TestFirstClassCallableSyntaxPHP81(t *testing.T) {
tester.NewParserPrintTestSuite(t).UsePHP8().Run(`<?php
$fn = id(...);
stdClass::doesNotExist(...);
(new stdClass)->doesNotExist(...);
Test::privateMethod(...);
Test::instanceMethod(...);
$fn = (new A)->$name2(...);
false && strlen(...);
$foo?->foo->bar(...);
$foo?->foo($foo->bar(...));
$foo = $closure->__invoke(...);
// #[Attribute(...)] // not working
// class Foo {}
// new Foo(...); // not working
`)
}