[refactoring] update ast structure of "Do" node
This commit is contained in:
@@ -2343,7 +2343,7 @@ func TestPrintAltWhile(t *testing.T) {
|
||||
p.Print(&ast.StmtNamespace{
|
||||
Stmts: []ast.Vertex{
|
||||
&ast.StmtWhile{
|
||||
Alt: true,
|
||||
Alt: true,
|
||||
Cond: &ast.ExprVariable{VarName: &ast.Identifier{Value: []byte("a")}},
|
||||
Stmt: &ast.StmtStmtList{
|
||||
Stmts: []ast.Vertex{
|
||||
|
||||
@@ -2361,42 +2361,17 @@ func (p *Printer) printStmtDefault(n ast.Vertex) {
|
||||
p.printFreeFloating(nn, token.End)
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtDo(n ast.Vertex) {
|
||||
nn := n.(*ast.StmtDo)
|
||||
p.printFreeFloating(nn, token.Start)
|
||||
func (p *Printer) printStmtDo(n *ast.StmtDo) {
|
||||
p.printToken(n.DoTkn, "do")
|
||||
p.bufStart = " "
|
||||
|
||||
io.WriteString(p.w, "do")
|
||||
p.Print(n.Stmt)
|
||||
|
||||
if _, ok := nn.Stmt.(*ast.StmtStmtList); !ok {
|
||||
if nn.Stmt.GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, " ")
|
||||
}
|
||||
}
|
||||
|
||||
p.Print(nn.Stmt)
|
||||
|
||||
p.printFreeFloating(nn, token.Stmts)
|
||||
|
||||
io.WriteString(p.w, "while")
|
||||
|
||||
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
|
||||
io.WriteString(p.w, "(")
|
||||
}
|
||||
|
||||
p.Print(nn.Cond)
|
||||
|
||||
if _, ok := nn.Cond.(*ast.ParserBrackets); !ok {
|
||||
io.WriteString(p.w, ")")
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.Cond)
|
||||
|
||||
p.printFreeFloating(nn, token.SemiColon)
|
||||
if nn.GetNode().Tokens.IsEmpty() {
|
||||
io.WriteString(p.w, ";")
|
||||
}
|
||||
|
||||
p.printFreeFloating(nn, token.End)
|
||||
p.printToken(n.WhileTkn, "while")
|
||||
p.printToken(n.OpenParenthesisTkn, "(")
|
||||
p.Print(n.Cond)
|
||||
p.printToken(n.CloseParenthesisTkn, ")")
|
||||
p.printToken(n.SemiColonTkn, ";")
|
||||
}
|
||||
|
||||
func (p *Printer) printStmtEcho(n ast.Vertex) {
|
||||
|
||||
@@ -945,7 +945,8 @@ func TestParseAndPrintPhp5Declare(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintPhp5DoWhile(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
do {
|
||||
;
|
||||
} while ( $a ) ;
|
||||
|
||||
@@ -1061,7 +1061,8 @@ func TestParseAndPrintDeclare(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestParseAndPrintDoWhile(t *testing.T) {
|
||||
src := `<?php
|
||||
// TODO: remove ; after <?php
|
||||
src := `<?php ;
|
||||
do {
|
||||
;
|
||||
} while ( $a ) ;
|
||||
|
||||
@@ -3331,7 +3331,7 @@ func TestPrinterPrintStmtDo_StmtList(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
expected := `do{$a;}while(1);`
|
||||
expected := `do {$a;}while(1);`
|
||||
actual := o.String()
|
||||
|
||||
if expected != actual {
|
||||
|
||||
Reference in New Issue
Block a user