Skip to content

Commit

Permalink
fix arrowhead label detection
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Mar 12, 2023
1 parent 8f20799 commit f03a5d4
Show file tree
Hide file tree
Showing 10 changed files with 303 additions and 21 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
#### Bugfixes ⛑️

- Fixes `d2` erroring on malformed user paths (`fdopendir` error). [util-go#10](https://github.com/terrastruct/util-go/pull/10)
- Arrowhead labels being set without maps wasn't being picked up. [#1015](https://github.com/terrastruct/d2/pull/1015)
32 changes: 16 additions & 16 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,7 @@ func (c *compiler) compileEdgeField(edge *d2graph.Edge, f *d2ir.Field) {
}

if f.Name == "source-arrowhead" || f.Name == "target-arrowhead" {
if f.Map() != nil {
c.compileArrowheads(edge, f)
}
c.compileArrowheads(edge, f)
}
}

Expand All @@ -508,21 +506,23 @@ func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) {
c.compileLabel(attrs, f)
}

for _, f2 := range f.Map().Fields {
keyword := strings.ToLower(f2.Name)
_, isReserved := d2graph.SimpleReservedKeywords[keyword]
if isReserved {
c.compileReserved(attrs, f2)
continue
} else if f2.Name == "style" {
if f2.Map() == nil {
if f.Map() != nil {
for _, f2 := range f.Map().Fields {
keyword := strings.ToLower(f2.Name)
_, isReserved := d2graph.SimpleReservedKeywords[keyword]
if isReserved {
c.compileReserved(attrs, f2)
continue
} else if f2.Name == "style" {
if f2.Map() == nil {
continue
}
c.compileStyle(attrs, f2.Map())
continue
} else {
c.errorf(f2.LastRef().AST(), `source-arrowhead/target-arrowhead map keys must be reserved keywords`)
continue
}
c.compileStyle(attrs, f2.Map())
continue
} else {
c.errorf(f2.LastRef().AST(), `source-arrowhead/target-arrowhead map keys must be reserved keywords`)
continue
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -971,6 +971,17 @@ x -> y: {
}
},
},
{
name: "edge_arrowhead_primary",

text: `x -> y: {
source-arrowhead: Reisner's Rule of Conceptual Inertia
}
`,
assertions: func(t *testing.T, g *d2graph.Graph) {
assert.String(t, "Reisner's Rule of Conceptual Inertia", g.Edges[0].SrcArrowhead.Label.Value)
},
},
{
name: "edge_arrowhead_fields",

Expand Down
Binary file modified e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf
Binary file not shown.

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

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

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

Loading

0 comments on commit f03a5d4

Please sign in to comment.