This commit is contained in:
Alexander Wang 2023-03-20 11:50:50 -07:00
parent e102fd98c3
commit 8a69f36972
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE

View file

@ -643,7 +643,9 @@ func renameConflictsToParent(g *d2graph.Graph, key *d2ast.KeyPath) (*d2graph.Gra
return g, nil return g, nil
} }
// Keep a list of newly generated IDs, so that generateUniqueKey considers them for conflict
var newIDs []string var newIDs []string
// If we already renamed the key from another reference, no need to touch
dedupedRenames := map[string]struct{}{} dedupedRenames := map[string]struct{}{}
for _, ref := range obj.References { for _, ref := range obj.References {
var absKeys []*d2ast.KeyPath var absKeys []*d2ast.KeyPath
@ -694,6 +696,7 @@ func renameConflictsToParent(g *d2graph.Graph, key *d2ast.KeyPath) (*d2graph.Gra
if _, ok := dedupedRenames[absKeyStr]; ok { if _, ok := dedupedRenames[absKeyStr]; ok {
continue continue
} }
// Stale reference
dedupedRenames[absKeyStr] = struct{}{} dedupedRenames[absKeyStr] = struct{}{}
// Do not consider the parent for conflicts, assume the parent will be deleted // Do not consider the parent for conflicts, assume the parent will be deleted
if ida[len(ida)-1] == ida[len(ida)-2] { if ida[len(ida)-1] == ida[len(ida)-2] {