Skip to content

Commit

Permalink
Merge pull request #2174 from alixander/create-board-api-2
Browse files Browse the repository at this point in the history
better detection of empty boards
  • Loading branch information
alixander authored Oct 23, 2024
2 parents dcd7c15 + dc5c5e2 commit efd401a
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 8 deletions.
7 changes: 4 additions & 3 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,21 @@ func (c *compiler) compileBoardsField(g *d2graph.Graph, ir *d2ir.Map, fieldName
return
}
for _, f := range boards.Map().Fields {
m := f.Map()
if f.Map() == nil {
continue
m = &d2ir.Map{}
}
if g.GetBoard(f.Name) != nil {
c.errorf(f.References[0].AST(), "board name %v already used by another board", f.Name)
continue
}
g2 := d2graph.NewGraph()
g2.Parent = g
g2.AST = f.Map().AST().(*d2ast.Map)
g2.AST = m.AST().(*d2ast.Map)
if g.BaseAST != nil {
g2.BaseAST = findFieldAST(g.BaseAST, f)
}
c.compileBoard(g2, f.Map())
c.compileBoard(g2, m)
g2.Name = f.Name
switch fieldName {
case "layers":
Expand Down
21 changes: 21 additions & 0 deletions d2oracle/edit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,27 @@ layers: {
}
}
}
`,
},
{
name: "add_layer/4",
text: `b
layers: {
c
}
`,
key: `d`,

boardPath: []string{"c"},
expKey: `d`,
exp: `b
layers: {
c: {
d
}
}
`,
},
{
Expand Down
39 changes: 39 additions & 0 deletions testdata/d2compiler/TestCompile2/boards/isFolderOnly.exp.json

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

42 changes: 41 additions & 1 deletion testdata/d2oracle/TestCreate/add_layer/1.exp.json

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

40 changes: 39 additions & 1 deletion testdata/d2oracle/TestCreate/add_layer/2.exp.json

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

42 changes: 41 additions & 1 deletion testdata/d2oracle/TestCreate/add_layer/3.exp.json

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

Loading

0 comments on commit efd401a

Please sign in to comment.