Skip to content

Commit

Permalink
Merge pull request #1550 from alixander/no-ast-modify
Browse files Browse the repository at this point in the history
dont modify ast when modifying links in the IR
  • Loading branch information
alixander authored Aug 13, 2023
2 parents 9997be1 + 5afc712 commit c670987
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 c670987

Please sign in to comment.