This commit is contained in:
Alexander Wang 2023-03-01 14:53:58 -08:00
parent 9fd773bbb7
commit 3a9745974c
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
13 changed files with 712 additions and 145 deletions

View file

@ -56,7 +56,7 @@ func compileIR(ast *d2ast.Map, m *d2ir.Map) (*d2graph.Graph, error) {
if len(c.err.Errors) > 0 { if len(c.err.Errors) > 0 {
return nil, c.err return nil, c.err
} }
c.compileBoardLink(g) c.validateBoardLinks(g)
if len(c.err.Errors) > 0 { if len(c.err.Errors) > 0 {
return nil, c.err return nil, c.err
} }
@ -722,7 +722,7 @@ func (c *compiler) validateNear(g *d2graph.Graph) {
} }
} }
func (c *compiler) compileBoardLink(g *d2graph.Graph) { func (c *compiler) validateBoardLinks(g *d2graph.Graph) {
for _, obj := range g.Objects { for _, obj := range g.Objects {
if obj.Attributes.Link == nil { if obj.Attributes.Link == nil {
continue continue
@ -734,65 +734,55 @@ func (c *compiler) compileBoardLink(g *d2graph.Graph) {
continue continue
} }
switch linkKey.Path[0].Unbox().ScalarString() { if linkKey.Path[0].Unbox().ScalarString() != "root" {
// Starting a link with one of the following means it is targeting a board
case "layers", "scenarios", "steps", "_":
default:
continue continue
} }
obj.LinkedBoard = c.findBoard(g, linkKey.IDA()) root := g
for root.Parent != nil {
if obj.LinkedBoard == nil { root = root.Parent
c.errorf(obj.Attributes.Link.MapKey, "link key %#v to board not found", obj.Attributes.Link.Value) }
if !hasBoard(root, linkKey.IDA()) {
c.errorf(obj.Attributes.Link.MapKey, "link key to board not found")
continue continue
} }
} }
for _, b := range append(append(g.Layers, g.Scenarios...), g.Steps...) { for _, b := range append(append(g.Layers, g.Scenarios...), g.Steps...) {
c.compileBoardLink(b) c.validateBoardLinks(b)
} }
} }
func (c *compiler) findBoard(g *d2graph.Graph, ida []string) *d2graph.Graph { func hasBoard(root *d2graph.Graph, ida []string) bool {
var currType string for i := 0; i < len(ida); i += 2 {
for _, p := range ida { id := ida[i]
if g == nil { if id == "root" {
return nil
}
if p == "_" {
g = g.Parent
continue continue
} }
switch p { if i == len(ida)-1 {
case "layers", "scenarios", "steps": return root.Name == id
currType = p
continue
} }
var boards []*d2graph.Graph nextID := ida[i+1]
switch currType { if id == "layers" {
case "layers": for _, b := range root.Layers {
boards = g.Layers if b.Name == nextID {
case "scenarios": return hasBoard(b, ida[i:])
boards = g.Scenarios
case "steps":
boards = g.Steps
default:
return nil
}
currType = ""
var board *d2graph.Graph
for i, b := range boards {
if b.Name == p {
board = boards[i]
break
} }
} }
} else if id == "scenarios" {
g = board for _, b := range root.Scenarios {
if b.Name == nextID {
return hasBoard(b, ida[i:])
} }
}
return g } else if id == "steps" {
for _, b := range root.Steps {
if b.Name == nextID {
return hasBoard(b, ida[i:])
}
}
}
}
return false
} }
func init() { func init() {

View file

@ -2036,7 +2036,7 @@ layers: {
} }
}`, }`,
assertions: func(t *testing.T, g *d2graph.Graph) { assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, ".layers.x", g.Objects[0].LinkedBoard.AbsID()) tassert.Equal(t, "root.layers.x", g.Objects[0].Attributes.Link.Value)
}, },
}, },
{ {
@ -2056,7 +2056,7 @@ scenarios: {
} }
}`, }`,
assertions: func(t *testing.T, g *d2graph.Graph) { assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, ".layers.cat", g.Objects[0].LinkedBoard.AbsID()) tassert.Equal(t, "root.layers.cat", g.Objects[0].Attributes.Link.Value)
}, },
}, },
{ {
@ -2089,7 +2089,21 @@ layers: {
} }
}`, }`,
assertions: func(t *testing.T, g *d2graph.Graph) { assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, ".layers.x.layers.x", g.Objects[0].LinkedBoard.AbsID()) tassert.Equal(t, "root.layers.x.layers.x", g.Objects[0].Attributes.Link.Value)
},
},
{
name: "link-board-key-nested",
text: `x: {
y.link: layers.x
}
layers: {
x: {
yo
}
}`,
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "root.layers.x", g.Objects[1].Attributes.Link.Value)
}, },
}, },
{ {
@ -2107,9 +2121,9 @@ layers: {
} }
}`, }`,
assertions: func(t *testing.T, g *d2graph.Graph) { assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.NotNil(t, g.Layers[0].Layers[0].Objects[0].LinkedBoard) tassert.NotNil(t, g.Layers[0].Layers[0].Objects[0].Attributes.Link.Value)
tassert.Equal(t, ".layers.x", g.Layers[0].Layers[0].Objects[0].LinkedBoard.AbsID()) tassert.Equal(t, "root.layers.x", g.Layers[0].Layers[0].Objects[0].Attributes.Link.Value)
tassert.Equal(t, ".layers.x", g.Layers[0].Layers[0].Objects[1].LinkedBoard.AbsID()) tassert.Equal(t, "root.layers.x", g.Layers[0].Layers[0].Objects[1].Attributes.Link.Value)
}, },
}, },
{ {
@ -2125,7 +2139,7 @@ layers: {
} }
} }
}`, }`,
expErr: `d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:17: link key "_._._" to board not found`, expErr: `d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:5: board referenced by link not found`,
}, },
} }

View file

@ -107,8 +107,6 @@ type Object struct {
LabelHeight *int `json:"labelHeight,omitempty"` LabelHeight *int `json:"labelHeight,omitempty"`
IconPosition *string `json:"iconPosition,omitempty"` IconPosition *string `json:"iconPosition,omitempty"`
LinkedBoard *Graph `json:"-"`
Class *d2target.Class `json:"class,omitempty"` Class *d2target.Class `json:"class,omitempty"`
SQLTable *d2target.SQLTable `json:"sql_table,omitempty"` SQLTable *d2target.SQLTable `json:"sql_table,omitempty"`

View file

@ -1,6 +1,8 @@
package d2ir package d2ir
import ( import (
"strings"
"oss.terrastruct.com/d2/d2ast" "oss.terrastruct.com/d2/d2ast"
"oss.terrastruct.com/d2/d2parser" "oss.terrastruct.com/d2/d2parser"
) )
@ -127,6 +129,34 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
} }
c.compileMap(f.Map(), refctx.Key.Value.Map) c.compileMap(f.Map(), refctx.Key.Value.Map)
} else if refctx.Key.Value.ScalarBox().Unbox() != nil { } else if refctx.Key.Value.ScalarBox().Unbox() != nil {
// If these are boards, we transform into absolute paths
if f.Name == "link" {
link, err := d2parser.ParseKey(refctx.Key.Value.ScalarBox().Unbox().ScalarString())
if err == nil {
scopeID, _ := d2parser.ParseKey(refctx.ScopeMap.AbsID())
scopeIDA := scopeID.IDA()
for i := len(scopeIDA) - 1; i > 0; i-- {
if scopeIDA[i-1] == "layers" || scopeIDA[i-1] == "scenarios" || scopeIDA[i-1] == "steps" || scopeIDA[i-1] == "root" {
scopeIDA = scopeIDA[:i+1]
break
}
}
linkIDA := link.IDA()
if len(linkIDA) > 0 {
for len(linkIDA) > 0 && linkIDA[0] == "_" {
if len(scopeIDA) <= 2 {
c.errorf(refctx.Key.Key, "board referenced by link not found")
return
}
// pop 2 off path per one underscore
scopeIDA = scopeIDA[:len(scopeIDA)-2]
linkIDA = linkIDA[1:]
}
scopeIDA = append(scopeIDA, linkIDA...)
refctx.Key.Value = d2ast.MakeValueBox(d2ast.RawString(strings.Join(scopeIDA, "."), true))
}
}
}
f.Primary_ = &Scalar{ f.Primary_ = &Scalar{
parent: f, parent: f,
Value: refctx.Key.Value.ScalarBox().Unbox(), Value: refctx.Key.Value.ScalarBox().Unbox(),

View file

@ -158,7 +158,7 @@ type Map struct {
func (m *Map) initRoot() { func (m *Map) initRoot() {
m.parent = &Field{ m.parent = &Field{
Name: "", Name: "root",
References: []*FieldReference{{ References: []*FieldReference{{
Context: &RefContext{ Context: &RefContext{
ScopeMap: m, ScopeMap: m,
@ -221,6 +221,17 @@ func (m *Map) Root() bool {
return f.Root() return f.Root()
} }
func (m *Map) AbsID() string {
f, ok := m.parent.(*Field)
if !ok {
return ""
}
if f.parent == nil {
return f.Name
}
return f.parent.(*Map).AbsID() + "." + f.Name
}
func (f *Field) Root() bool { func (f *Field) Root() bool {
return f.parent == nil return f.parent == nil
} }

View file

@ -0,0 +1,540 @@
{
"graph": {
"name": "",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-7:1:54",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-2:1:25",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:3:3-2:0:24",
"nodes": [
{
"map_key": {
"range": ",0:0:0-0:0:0",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:3:8",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:4:9-1:8:13",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.x.layers.x"
}
]
}
}
}
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-7:1:54",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-3:6:32",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:8:34-7:0:53",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:1:37-6:3:52",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:1:37-4:2:38",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:1:37-4:2:38",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:4:40-6:2:51",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:46-5:6:48",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:46-5:6:48",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:46-5:6:48",
"value": [
{
"string": "yo",
"raw_string": "yo"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "x",
"id_val": "x",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "x"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
{
"id": "y",
"id_val": "y",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:3:8",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:4:9-1:8:13",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "y"
},
"style": {},
"link": {
"value": "root.x.layers.x"
},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
],
"layers": [
{
"name": "x",
"isFolderOnly": false,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-7:1:54",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-2:1:25",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,0:3:3-2:0:24",
"nodes": [
{
"map_key": {
"range": ",0:0:0-0:0:0",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:8:13",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:2:7-1:3:8",
"value": [
{
"string": "y",
"raw_string": "y"
}
]
}
},
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,1:4:9-1:8:13",
"value": [
{
"string": "link",
"raw_string": "link"
}
]
}
}
]
},
"primary": {},
"value": {
"double_quoted_string": {
"range": ",0:0:0-0:0:0",
"value": [
{
"string": "root.x.layers.x"
}
]
}
}
}
}
]
}
}
}
},
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-7:1:54",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-3:6:32",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:0:26-3:6:32",
"value": [
{
"string": "layers",
"raw_string": "layers"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,3:8:34-7:0:53",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:1:37-6:3:52",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:1:37-4:2:38",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:1:37-4:2:38",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
}
}
]
},
"primary": {},
"value": {
"map": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,4:4:40-6:2:51",
"nodes": [
{
"map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:46-5:6:48",
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:46-5:6:48",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:46-5:6:48",
"value": [
{
"string": "yo",
"raw_string": "yo"
}
]
}
}
]
},
"primary": {},
"value": {}
}
}
]
}
}
}
}
]
}
}
}
}
]
},
"root": {
"id": "",
"id_val": "",
"label_dimensions": {
"width": 0,
"height": 0
},
"attributes": {
"label": {
"value": ""
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
},
"edges": null,
"objects": [
{
"id": "yo",
"id_val": "yo",
"label_dimensions": {
"width": 0,
"height": 0
},
"references": [
{
"key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:46-5:6:48",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-key-nested.d2,5:4:46-5:6:48",
"value": [
{
"string": "yo",
"raw_string": "yo"
}
]
}
}
]
},
"key_path_index": 0,
"map_key_edge_index": -1
}
],
"attributes": {
"label": {
"value": "yo"
},
"style": {},
"near_key": null,
"shape": {
"value": "rectangle"
},
"direction": {
"value": ""
},
"constraint": {
"value": ""
}
},
"zIndex": 0
}
]
}
]
},
"err": null
}

View file

@ -40,7 +40,7 @@
}, },
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:15:46-1:25:56", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:0:31-1:13:44", "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:0:31-1:13:44",
"path": [ "path": [
@ -70,12 +70,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:15:46-1:25:56", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "layers.cat", "string": "root.layers.cat"
"raw_string": "layers.cat"
} }
] ]
} }
@ -404,7 +403,7 @@
}, },
"style": {}, "style": {},
"link": { "link": {
"value": "layers.cat" "value": "root.layers.cat"
}, },
"near_key": null, "near_key": null,
"shape": { "shape": {
@ -462,7 +461,7 @@
}, },
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:15:46-1:25:56", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:0:31-1:13:44", "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:0:31-1:13:44",
"path": [ "path": [
@ -492,12 +491,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:15:46-1:25:56", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "layers.cat", "string": "root.layers.cat"
"raw_string": "layers.cat"
} }
] ]
} }
@ -934,7 +932,7 @@
}, },
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:15:46-1:25:56", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:0:31-1:13:44", "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:0:31-1:13:44",
"path": [ "path": [
@ -964,12 +962,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,1:15:46-1:25:56", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "layers.cat", "string": "root.layers.cat"
"raw_string": "layers.cat"
} }
] ]
} }
@ -1344,7 +1341,7 @@
} }
}, },
"link": { "link": {
"value": "layers.cat" "value": "root.layers.cat"
}, },
"near_key": null, "near_key": null,
"shape": { "shape": {

View file

@ -7,7 +7,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:8:8-0:25:25", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6", "range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6",
"path": [ "path": [
@ -37,12 +37,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:8:8-0:25:25", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "layers.x.layers.x", "string": "root.layers.x.layers.x"
"raw_string": "layers.x.layers.x"
} }
] ]
} }
@ -263,7 +262,7 @@
}, },
"style": {}, "style": {},
"link": { "link": {
"value": "layers.x.layers.x" "value": "root.layers.x.layers.x"
}, },
"near_key": null, "near_key": null,
"shape": { "shape": {
@ -288,7 +287,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:8:8-0:25:25", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6", "range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6",
"path": [ "path": [
@ -318,12 +317,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:8:8-0:25:25", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "layers.x.layers.x", "string": "root.layers.x.layers.x"
"raw_string": "layers.x.layers.x"
} }
] ]
} }
@ -507,7 +505,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:8:8-0:25:25", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6", "range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:0:0-0:6:6",
"path": [ "path": [
@ -537,12 +535,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-nested.d2,0:8:8-0:25:25", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "layers.x.layers.x", "string": "root.layers.x.layers.x"
"raw_string": "layers.x.layers.x"
} }
] ]
} }

View file

@ -7,7 +7,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:8:8-0:16:16", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:6:6", "range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:6:6",
"path": [ "path": [
@ -37,12 +37,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:8:8-0:16:16", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "layers.x", "string": "root.layers.x"
"raw_string": "layers.x"
} }
] ]
} }
@ -205,7 +204,7 @@
}, },
"style": {}, "style": {},
"link": { "link": {
"value": "layers.x" "value": "root.layers.x"
}, },
"near_key": null, "near_key": null,
"shape": { "shape": {
@ -230,7 +229,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:8:8-0:16:16", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:6:6", "range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:0:0-0:6:6",
"path": [ "path": [
@ -260,12 +259,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-ok.d2,0:8:8-0:16:16", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "layers.x", "string": "root.layers.x"
"raw_string": "layers.x"
} }
] ]
} }

View file

@ -4,8 +4,8 @@
"ioerr": null, "ioerr": null,
"errs": [ "errs": [
{ {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2,6:16:62-6:21:67", "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2,6:4:50-6:14:60",
"errmsg": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:17: link key \"_._._\" to board not found" "errmsg": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:5: board referenced by link not found"
} }
] ]
} }

View file

@ -149,7 +149,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:16:62-6:28:74", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:4:50-6:14:60", "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:4:50-6:14:60",
"path": [ "path": [
@ -179,12 +179,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:16:62-6:28:74", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "_._.layers.x", "string": "root.layers.x"
"raw_string": "_._.layers.x"
} }
] ]
} }
@ -193,7 +192,7 @@
}, },
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:14:89-7:15:90", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:4:79-7:12:87", "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:4:79-7:12:87",
"path": [ "path": [
@ -223,12 +222,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:14:89-7:15:90", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "_", "string": "root.layers.x"
"raw_string": "_"
} }
] ]
} }
@ -483,7 +481,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:16:62-6:28:74", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:4:50-6:14:60", "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:4:50-6:14:60",
"path": [ "path": [
@ -513,12 +511,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:16:62-6:28:74", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "_._.layers.x", "string": "root.layers.x"
"raw_string": "_._.layers.x"
} }
] ]
} }
@ -527,7 +524,7 @@
}, },
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:14:89-7:15:90", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:4:79-7:12:87", "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:4:79-7:12:87",
"path": [ "path": [
@ -557,12 +554,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:14:89-7:15:90", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "_", "string": "root.layers.x"
"raw_string": "_"
} }
] ]
} }
@ -817,7 +813,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:16:62-6:28:74", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:4:50-6:14:60", "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:4:50-6:14:60",
"path": [ "path": [
@ -847,12 +843,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,6:16:62-6:28:74", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "_._.layers.x", "string": "root.layers.x"
"raw_string": "_._.layers.x"
} }
] ]
} }
@ -861,7 +856,7 @@
}, },
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:14:89-7:15:90", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:4:79-7:12:87", "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:4:79-7:12:87",
"path": [ "path": [
@ -891,12 +886,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/link-board-underscore.d2,7:14:89-7:15:90", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "_", "string": "root.layers.x"
"raw_string": "_"
} }
] ]
} }
@ -998,7 +992,7 @@
}, },
"style": {}, "style": {},
"link": { "link": {
"value": "_._.layers.x" "value": "root.layers.x"
}, },
"near_key": null, "near_key": null,
"shape": { "shape": {
@ -1059,7 +1053,7 @@
}, },
"style": {}, "style": {},
"link": { "link": {
"value": "_" "value": "root.layers.x"
}, },
"near_key": null, "near_key": null,
"shape": { "shape": {

View file

@ -31,7 +31,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/path_link.d2,1:8:13-1:39:44", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/path_link.d2,1:2:7-1:6:11", "range": "d2/testdata/d2compiler/TestCompile/path_link.d2,1:2:7-1:6:11",
"path": [ "path": [
@ -50,12 +50,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/path_link.d2,1:8:13-1:39:44", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "Overview.Untitled board 7.zzzzz", "string": "root.x.Overview.Untitled board 7.zzzzz"
"raw_string": "Overview.Untitled board 7.zzzzz"
} }
] ]
} }
@ -131,7 +130,7 @@
}, },
"style": {}, "style": {},
"link": { "link": {
"value": "Overview.Untitled board 7.zzzzz" "value": "root.x.Overview.Untitled board 7.zzzzz"
}, },
"near_key": null, "near_key": null,
"shape": { "shape": {

View file

@ -31,7 +31,7 @@
"nodes": [ "nodes": [
{ {
"map_key": { "map_key": {
"range": "d2/testdata/d2compiler/TestCompile/url_link.d2,1:8:13-1:26:31", "range": ",0:0:0-0:0:0",
"key": { "key": {
"range": "d2/testdata/d2compiler/TestCompile/url_link.d2,1:2:7-1:6:11", "range": "d2/testdata/d2compiler/TestCompile/url_link.d2,1:2:7-1:6:11",
"path": [ "path": [
@ -50,12 +50,11 @@
}, },
"primary": {}, "primary": {},
"value": { "value": {
"unquoted_string": { "double_quoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/url_link.d2,1:8:13-1:26:31", "range": ",0:0:0-0:0:0",
"value": [ "value": [
{ {
"string": "https://google.com", "string": "root.x.https"
"raw_string": "https://google.com"
} }
] ]
} }
@ -131,7 +130,7 @@
}, },
"style": {}, "style": {},
"link": { "link": {
"value": "https://google.com" "value": "root.x.https"
}, },
"near_key": null, "near_key": null,
"shape": { "shape": {