Browse Source

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

Matthias Ladkau 3 years ago
parent
commit
643790ec49
2 changed files with 17 additions and 0 deletions
  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
+	}
 }