Skip to content

Commit

Permalink
Merge pull request #2000 from alixander/fix-underscore-edge-case
Browse files Browse the repository at this point in the history
d2compiler: fix underscore sibling edge case
  • Loading branch information
alixander authored Jul 13, 2024
2 parents 9f1092c + d608740 commit 4027228
Show file tree
Hide file tree
Showing 3 changed files with 346 additions and 9 deletions.
5 changes: 5 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2933,6 +2933,7 @@ layers: {
layers: {
b: {
d.link: _
s.link: _.layers.k
layers: {
c: {
Expand All @@ -2942,13 +2943,17 @@ layers: {
}
}
}
k: {
k
}
}`,
},
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "root.layers.x", g.Layers[0].Layers[0].Objects[0].Link.Value)
tassert.Equal(t, "root.layers.x.layers.b", g.Layers[0].Layers[0].Layers[0].Objects[0].Link.Value)
tassert.Equal(t, "root.layers.x", g.Layers[0].Layers[0].Layers[0].Objects[1].Link.Value)
tassert.Equal(t, "root.layers.x.layers.b", g.Layers[0].Layers[0].Layers[0].Objects[2].Link.Value)
tassert.Equal(t, "root.layers.x.layers.k", g.Layers[0].Layers[0].Objects[1].Link.Value)
},
},
{
Expand Down
3 changes: 3 additions & 0 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,9 @@ func (c *compiler) updateLinks(m *Map) {
prependIDA := aida[:len(aida)-len(bida)]
if uplevels > 0 {
prependIDA = prependIDA[:len(prependIDA)-uplevels]
} else if uplevels == 0 {
// It's a sibling, so we go up one level to find it
prependIDA = prependIDA[:len(prependIDA)-2]
}
fullIDA := []string{"root"}
// With nested imports, a value may already have been updated with part of the absolute path
Expand Down
Loading

0 comments on commit 4027228

Please sign in to comment.