From fdb73c14b2d0a657a96cb74090e35230813784ed Mon Sep 17 00:00:00 2001 From: Bernard Xie Date: Mon, 19 Jun 2023 17:39:05 -0700 Subject: [PATCH] rename + refactor --- d2ast/d2ast.go | 4 ++-- d2format/format.go | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/d2ast/d2ast.go b/d2ast/d2ast.go index 43348804d..c0b5eedf7 100644 --- a/d2ast/d2ast.go +++ b/d2ast/d2ast.go @@ -760,8 +760,8 @@ func (mb MapNodeBox) Unbox() MapNode { } } -func (mb MapNodeBox) IsSpecialBoard() bool { - if mb.MapKey == nil || mb.MapKey.Key == nil { +func (mb MapNodeBox) IsBoardNode() bool { + if mb.MapKey == nil || mb.MapKey.Key == nil || len(mb.MapKey.Key.Path) == 0 { return false } switch mb.MapKey.Key.Path[0].Unbox().ScalarString() { diff --git a/d2format/format.go b/d2format/format.go index 82fd9daac..102b085d7 100644 --- a/d2format/format.go +++ b/d2format/format.go @@ -260,7 +260,7 @@ func (p *printer) _map(m *d2ast.Map) { stepNodes := []d2ast.MapNodeBox{} for i := 0; i < len(m.Nodes); i++ { node := m.Nodes[i] - if node.MapKey != nil && node.MapKey.Key != nil { + if node.IsBoardNode() { key := node.MapKey.Key switch key.Path[0].Unbox().ScalarString() { case "layers": @@ -269,8 +269,6 @@ func (p *printer) _map(m *d2ast.Map) { scenarioNodes = append(scenarioNodes, node) case "steps": stepNodes = append(stepNodes, node) - default: - nodes = append(nodes, node) } } else { nodes = append(nodes, node) @@ -309,7 +307,7 @@ func (p *printer) _map(m *d2ast.Map) { p.sb.WriteString("; ") } - if m.IsFileMap() && nb.IsSpecialBoard() { + if m.IsFileMap() && nb.IsBoardNode() { currString := p.sb.String() // if the the character before the special board is not a newline, we add one if currString[len(currString)-2:] != "\n\n" {