From bcb27d77e08a2a62f6040c644adc9f621051b6e2 Mon Sep 17 00:00:00 2001 From: Pranjal Agrawal Date: Thu, 23 Mar 2017 01:56:01 +0530 Subject: [PATCH] Fixed bug where buildifier swallowed up some comments at the beginning of list/d ictionary expressions. Fixes #68 on github --- build/lex.go | 3 ++- build/print.go | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/build/lex.go b/build/lex.go index b64f8d604..a7f3f272a 100644 --- a/build/lex.go +++ b/build/lex.go @@ -726,7 +726,8 @@ func (in *input) assignComments() { // whole file, or conditional expression. // Instead assign them to the last argument, element, or rule. switch x.(type) { - case *CallExpr, *ListExpr, *End, *File, *ConditionalExpr: + case *CallExpr, *ListExpr, *End, *File, + *ConditionalExpr, *IfClause, *ForClause: continue } diff --git a/build/print.go b/build/print.go index c4b5fda1f..81e7e4710 100644 --- a/build/print.go +++ b/build/print.go @@ -121,7 +121,16 @@ func (p *printer) file(f *File) { for i, stmt := range f.Stmt { switch stmt := stmt.(type) { case *CommentBlock: - // comments already handled + // This is necessary so that CommentBlock + // doesn't swallow up suffix comments of + // the expression after it. + for _, scom := range stmt.Suffix { + scom.Suffix = false + stmt.After = append(stmt.After, scom) + suffix := stmt.Suffix + stmt.Suffix = suffix[:len(suffix) - 1] + } + case *PythonBlock: for _, com := range stmt.Before {