refactoring: update ast structure of "ArrayItem" node
This commit is contained in:
@@ -1177,6 +1177,7 @@ type ExprArrayItem struct {
|
||||
EllipsisTkn *token.Token
|
||||
Key Vertex
|
||||
DoubleArrowTkn *token.Token
|
||||
AmpersandTkn *token.Token
|
||||
Val Vertex
|
||||
}
|
||||
|
||||
|
||||
@@ -1056,6 +1056,7 @@ func (v *Dumper) ExprArrayItem(n *ast.ExprArrayItem) {
|
||||
v.dumpToken("EllipsisTkn", n.EllipsisTkn)
|
||||
v.dumpVertex("Key", n.Key)
|
||||
v.dumpToken("DoubleArrowTkn", n.DoubleArrowTkn)
|
||||
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
|
||||
v.dumpVertex("Val", n.Val)
|
||||
|
||||
v.indent--
|
||||
|
||||
@@ -641,6 +641,7 @@ func (p *printer) ExprArrayItem(n *ast.ExprArrayItem) {
|
||||
p.printToken(n.EllipsisTkn, nil)
|
||||
p.printNode(n.Key)
|
||||
p.printToken(n.DoubleArrowTkn, p.ifNode(n.Key, []byte("=>")))
|
||||
p.printToken(n.AmpersandTkn, nil)
|
||||
p.printNode(n.Val)
|
||||
}
|
||||
|
||||
|
||||
@@ -1559,9 +1559,31 @@ func TestPrinterPrintExprArrayItem(t *testing.T) {
|
||||
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n := &ast.ExprArrayItem{
|
||||
Val: &ast.ExprReference{Var: &ast.ExprVariable{
|
||||
Val: &ast.ExprVariable{
|
||||
VarName: &ast.Identifier{Value: []byte("$world")},
|
||||
}},
|
||||
},
|
||||
}
|
||||
n.Accept(p)
|
||||
|
||||
expected := `$world`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintExprArrayItem_Reference(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n := &ast.ExprArrayItem{
|
||||
AmpersandTkn: &token.Token{
|
||||
Value: []byte("&"),
|
||||
},
|
||||
Val: &ast.ExprVariable{
|
||||
VarName: &ast.Identifier{Value: []byte("$world")},
|
||||
},
|
||||
}
|
||||
n.Accept(p)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user