浏览代码

fix: Pretty printer fix for loop statements using an in operator

Matthias Ladkau 4 年之前
父节点
当前提交
643790ec49
共有 2 个文件被更改,包括 17 次插入0 次删除
  1. 1 0
      parser/prettyprinter.go
  2. 16 0
      parser/prettyprinter_test.go

+ 1 - 0
parser/prettyprinter.go

@@ -266,6 +266,7 @@ func ppPostProcessing(ast *ASTNode, path []*ASTNode, ppString string) string {
 			// Add initial indent only if we are inside a block statement
 
 			if stringutil.IndexOf(parent.Name, []string{
+				NodeIN,
 				NodeASSIGN,
 				NodePRESET,
 				NodeKVP,

+ 16 - 0
parser/prettyprinter_test.go

@@ -630,4 +630,20 @@ sink SomeSink
 		return
 	}
 
+	input = `
+
+	for [a,b,c] in foo {
+a := 1
+a := 2
+
+}
+`
+	if err := UnitTestPrettyPrinting(input, "",
+		`for [a, b, c] in foo {
+    a := 1
+    a := 2
+}`); err != nil {
+		t.Error(err)
+		return
+	}
 }