Skip to content

Commit

Permalink
d2oracle: fix setting with comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Apr 25, 2024
1 parent 3caa110 commit bd7f9e1
Show file tree
Hide file tree
Showing 3 changed files with 284 additions and 3 deletions.
6 changes: 3 additions & 3 deletions d2oracle/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ func _set(g *d2graph.Graph, baseAST *d2ast.Map, key string, tag, value *string)
foundMap = true
scope = ref.MapKey.Value.Map
for _, n := range scope.Nodes {
if n.MapKey.Value.Map == nil {
if n.MapKey == nil || n.MapKey.Value.Map == nil {
continue
}
if n.MapKey.Key == nil || len(n.MapKey.Key.Path) != 1 {
Expand Down Expand Up @@ -1059,7 +1059,7 @@ func bumpChildrenUnderscores(m *d2ast.Map) {
}

func hoistRefChildren(g *d2graph.Graph, key *d2ast.KeyPath, ref d2graph.Reference) {
if ref.MapKey.Value.Map == nil {
if ref.MapKey == nil || ref.MapKey.Value.Map == nil {
return
}

Expand Down Expand Up @@ -1115,7 +1115,7 @@ func renameConflictsToParent(g *d2graph.Graph, key *d2ast.KeyPath) (*d2graph.Gra
var absKeys []*d2ast.KeyPath

if len(ref.Key.Path)-1 == ref.KeyPathIndex {
if ref.MapKey.Value.Map == nil {
if ref.MapKey == nil || ref.MapKey.Value.Map == nil {
continue
}
var mapKeys []*d2ast.KeyPath
Expand Down
16 changes: 16 additions & 0 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2502,6 +2502,22 @@ x -> a.b -> a.b.c
x -> a.b -> a.b.c
(a.b -> a.b.c)[0].style.stroke: green
}
`,
},
{
name: "edge-comment",

text: `x -> y: {
# hi
style.stroke: blue
}
`,
key: `(x -> y)[0].style.stroke`,
value: go2.Pointer(`green`),
exp: `x -> y: {
# hi
style.stroke: green
}
`,
},
}
Expand Down
265 changes: 265 additions & 0 deletions testdata/d2oracle/TestSet/edge-comment.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bd7f9e1

Please sign in to comment.