Merge pull request #1550 from alixander/no-ast-modify

dont modify ast when modifying links in the IR
This commit is contained in:
Alexander Wang 2023-08-13 10:22:21 -07:00 committed by GitHub
commit c670987516
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 26 deletions

View file

@ -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)
}
}
}
@ -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 {
@ -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) {

View file

@ -62,10 +62,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:10:15-1:18:23",
"value": [
{
"string": "root.layers.x"
"string": "layers.x",
"raw_string": "layers.x"
}
]
}

View file

@ -71,10 +71,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:15:46-1:25:56",
"value": [
{
"string": "root.layers.cat"
"string": "layers.cat",
"raw_string": "layers.cat"
}
]
}

View file

@ -38,10 +38,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:8:8-0:25:25",
"value": [
{
"string": "root.layers.x.layers.x"
"string": "layers.x.layers.x",
"raw_string": "layers.x.layers.x"
}
]
}

View file

@ -38,10 +38,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:8:8-0:16:16",
"value": [
{
"string": "root.layers.x"
"string": "layers.x",
"raw_string": "layers.x"
}
]
}

View file

@ -180,10 +180,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:20:69-6:32:81",
"value": [
{
"string": "root.layers.x"
"string": "_._.layers.x",
"raw_string": "_._.layers.x"
}
]
}
@ -223,10 +224,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:18:100-7:19:101",
"value": [
{
"string": "root.layers.x"
"string": "_",
"raw_string": "_"
}
]
}

View file

@ -88,10 +88,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "index.d2,0:8:8-0:16:16",
"value": [
{
"string": "root.layers.x"
"string": "layers.x",
"raw_string": "layers.x"
}
]
}
@ -176,10 +177,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "index.d2,0:8:8-0:16:16",
"value": [
{
"string": "root.layers.x"
"string": "layers.x",
"raw_string": "layers.x"
}
]
}
@ -285,10 +287,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "x.d2,0:8:8-0:16:16",
"value": [
{
"string": "root.layers.y"
"string": "layers.y",
"raw_string": "layers.y"
}
]
}
@ -373,10 +376,11 @@
"primary": {},
"value": {
"unquoted_string": {
"range": ",0:0:0-0:0:0",
"range": "x.d2,0:8:8-0:16:16",
"value": [
{
"string": "root.layers.y"
"string": "layers.y",
"raw_string": "layers.y"
}
]
}