Skip to content

Commit

Permalink
dont modify ast when modifying links
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Aug 13, 2023
1 parent 9997be1 commit 5afc712
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 26 deletions.
12 changes: 6 additions & 6 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,14 +580,14 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) {
}
}
} else if refctx.Key.Value.ScalarBox().Unbox() != nil {
// If the link is a board, we need to transform it into an absolute path.
if f.Name == "link" {
c.compileLink(refctx)
}
f.Primary_ = &Scalar{
parent: f,
Value: refctx.Key.Value.ScalarBox().Unbox(),
}
// If the link is a board, we need to transform it into an absolute path.
if f.Name == "link" {
c.compileLink(f, refctx)
}
}
}

Expand Down Expand Up @@ -624,7 +624,7 @@ func (c *compiler) updateLinks(m *Map) {
}
}

func (c *compiler) compileLink(refctx *RefContext) {
func (c *compiler) compileLink(f *Field, refctx *RefContext) {
val := refctx.Key.Value.ScalarBox().Unbox().ScalarString()
link, err := d2parser.ParseKey(val)
if err != nil {
Expand Down Expand Up @@ -683,7 +683,7 @@ func (c *compiler) compileLink(refctx *RefContext) {
// Create the absolute path by appending scope path with value specified
scopeIDA = append(scopeIDA, linkIDA...)
kp := d2ast.MakeKeyPath(scopeIDA)
refctx.Key.Value = d2ast.MakeValueBox(d2ast.FlatUnquotedString(d2format.Format(kp)))
f.Primary_.Value = d2ast.FlatUnquotedString(d2format.Format(kp))
}

func (c *compiler) compileEdges(refctx *RefContext) {
Expand Down

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

5 changes: 3 additions & 2 deletions testdata/d2compiler/TestCompile/link-board-mixed.exp.json

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

5 changes: 3 additions & 2 deletions testdata/d2compiler/TestCompile/link-board-nested.exp.json

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

5 changes: 3 additions & 2 deletions testdata/d2compiler/TestCompile/link-board-ok.exp.json

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

10 changes: 6 additions & 4 deletions testdata/d2compiler/TestCompile/link-board-underscore.exp.json

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

20 changes: 12 additions & 8 deletions testdata/d2ir/TestCompile/imports/boards.exp.json

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

0 comments on commit 5afc712

Please sign in to comment.