Skip to content

Commit

Permalink
allow edges in vars
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Jul 13, 2023
1 parent e95f619 commit d275a45
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 75 deletions.
29 changes: 18 additions & 11 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3501,6 +3501,23 @@ custom-disclaimer: DRAFT DISCLAIMER {
assert.Equal(t, 2, len(g.Objects))
},
},
{
name: "spread-edge",
run: func(t *testing.T) {
g := assertCompile(t, `
vars: {
connections: {
x -> a
}
}
hi: {
...${connections}
}
`, "")
assert.Equal(t, 3, len(g.Objects))
assert.Equal(t, 1, len(g.Edges))
},
},
}

for _, tc := range tca {
Expand Down Expand Up @@ -3860,17 +3877,7 @@ hi: ${x}
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/recursive-var.d2:3:3: could not resolve variable "x"`)
},
},
{
name: "edge",
run: func(t *testing.T) {
assertCompile(t, `
vars: {
x -> a
}
hi
`, "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2:3:3: vars cannot contain an edge")
},
},

{
name: "spread-non-map",
run: func(t *testing.T) {
Expand Down
4 changes: 0 additions & 4 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,10 +523,6 @@ func (c *compiler) compileLink(refctx *RefContext) {
}

func (c *compiler) compileEdges(refctx *RefContext) {
if IsVar(refctx.ScopeMap) {
c.errorf(refctx.Key, "vars cannot contain an edge")
return
}
if refctx.Key.Key != nil {
f, err := refctx.ScopeMap.EnsureField(refctx.Key.Key, refctx)
if err != nil {
Expand Down
Loading

0 comments on commit d275a45

Please sign in to comment.