refactoring: create "ExprBrackets" node
This commit is contained in:
@@ -1108,6 +1108,19 @@ func (v *Dumper) ExprBooleanNot(n *ast.ExprBooleanNot) {
|
||||
v.print(v.indent, "},\n")
|
||||
}
|
||||
|
||||
func (v *Dumper) ExprBrackets(n *ast.ExprBrackets) {
|
||||
v.print(0, "&ast.ExprBrackets{\n")
|
||||
v.indent++
|
||||
|
||||
v.dumpPosition(n.Position)
|
||||
v.dumpToken("OpenParenthesisTkn", n.OpenParenthesisTkn)
|
||||
v.dumpVertex("Expr", n.Expr)
|
||||
v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn)
|
||||
|
||||
v.indent--
|
||||
v.print(v.indent, "},\n")
|
||||
}
|
||||
|
||||
func (v *Dumper) ExprClassConstFetch(n *ast.ExprClassConstFetch) {
|
||||
v.print(0, "&ast.ExprClassConstFetch{\n")
|
||||
v.indent++
|
||||
|
||||
@@ -1134,6 +1134,12 @@ func (f *formatter) ExprBooleanNot(n *ast.ExprBooleanNot) {
|
||||
n.Expr.Accept(f)
|
||||
}
|
||||
|
||||
func (f *formatter) ExprBrackets(n *ast.ExprBrackets) {
|
||||
n.OpenParenthesisTkn = f.newToken('(', []byte("("))
|
||||
n.Expr.Accept(f)
|
||||
n.CloseParenthesisTkn = f.newToken(')', []byte(")"))
|
||||
}
|
||||
|
||||
func (f *formatter) ExprClassConstFetch(n *ast.ExprClassConstFetch) {
|
||||
n.Class.Accept(f)
|
||||
n.DoubleColonTkn = f.newToken(token.T_PAAMAYIM_NEKUDOTAYIM, []byte("::"))
|
||||
|
||||
@@ -3571,6 +3571,31 @@ func TestFormatter_ExprBooleanNot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatter_ExprBrackets(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
n := &ast.ExprBrackets{
|
||||
Expr: &ast.ExprVariable{
|
||||
VarName: &ast.Identifier{
|
||||
Value: []byte("$foo"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
f := visitor.NewFormatter().WithState(visitor.FormatterStatePHP).WithIndent(1)
|
||||
n.Accept(f)
|
||||
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n.Accept(p)
|
||||
|
||||
expected := `($foo)`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatter_ExprClassConstFetch(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
|
||||
@@ -270,6 +270,10 @@ func (v *Null) ExprBooleanNot(_ *ast.ExprBooleanNot) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) ExprBrackets(_ *ast.ExprBrackets) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
func (v *Null) ExprClassConstFetch(_ *ast.ExprClassConstFetch) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@@ -668,6 +668,12 @@ func (p *printer) ExprBooleanNot(n *ast.ExprBooleanNot) {
|
||||
p.printNode(n.Expr)
|
||||
}
|
||||
|
||||
func (p *printer) ExprBrackets(n *ast.ExprBrackets) {
|
||||
p.printToken(n.OpenParenthesisTkn, nil)
|
||||
p.printNode(n.Expr)
|
||||
p.printToken(n.CloseParenthesisTkn, nil)
|
||||
}
|
||||
|
||||
func (p *printer) ExprClassConstFetch(n *ast.ExprClassConstFetch) {
|
||||
p.printNode(n.Class)
|
||||
p.printToken(n.DoubleColonTkn, []byte("::"))
|
||||
|
||||
@@ -1696,6 +1696,25 @@ func TestPrinterPrintExprBooleanNot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintExprBracket(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
p := visitor.NewPrinter(o).WithState(visitor.PrinterStatePHP)
|
||||
n := &ast.ExprBooleanNot{
|
||||
Expr: &ast.ExprVariable{
|
||||
VarName: &ast.Identifier{Value: []byte("$var")},
|
||||
},
|
||||
}
|
||||
n.Accept(p)
|
||||
|
||||
expected := `!$var`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrinterPrintExprClassConstFetch(t *testing.T) {
|
||||
o := bytes.NewBufferString("")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user