mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 14:20:35 +01:00
Fix formatting of nodes with no children (#1351)
For example, this fixes an issue where an empty module turns into ` \n`. Closes https://github.com/apple/pkl/issues/1348 --------- Co-authored-by: Jen Basch <jbasch94@gmail.com>
This commit is contained in:
@@ -1239,7 +1239,7 @@ internal class Builder(sourceText: String, private val grammarVersion: GrammarVe
|
||||
// skip semicolons
|
||||
val children = children.filter { !it.isSemicolon() }
|
||||
// short circuit
|
||||
if (children.isEmpty()) return listOf(spaceOrLine())
|
||||
if (children.isEmpty()) return emptyList()
|
||||
if (children.size == 1) return listOf(format(children[0]))
|
||||
|
||||
val nodes = mutableListOf<FormatNode>()
|
||||
|
||||
@@ -113,4 +113,11 @@ class FormatterTest {
|
||||
|
||||
walkDir(outputDir)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `whitespace only`() {
|
||||
for (src in listOf(";;;", "\n", "\n\n\n", "\t")) {
|
||||
assertThat(format(src)).isEqualTo("\n")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user