From 1a7d5b3c31986900af23723397d4bebc44c1c723 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 26 Aug 2024 13:43:56 -0600 Subject: [PATCH] d2ir: enable linking beyond board root --- ci/release/changelogs/next.md | 2 + d2compiler/compile_test.go | 76 +- d2ir/compile.go | 18 +- .../TestCompile/import-link-layer-1.exp.json | 493 ++++++++++ .../TestCompile/import-link-layer-2.exp.json | 302 ++++++ .../TestCompile/import-link-layer-3.exp.json | 712 ++++++++++++++ .../TestCompile/import-link-layer-4.exp.json | 882 ++++++++++++++++++ .../import-link-sibling-layer.exp.json | 493 ++++++++++ .../link-board-underscore-not-found.exp.json | 4 +- 9 files changed, 2974 insertions(+), 8 deletions(-) create mode 100644 testdata/d2compiler/TestCompile/import-link-layer-1.exp.json create mode 100644 testdata/d2compiler/TestCompile/import-link-layer-2.exp.json create mode 100644 testdata/d2compiler/TestCompile/import-link-layer-3.exp.json create mode 100644 testdata/d2compiler/TestCompile/import-link-layer-4.exp.json create mode 100644 testdata/d2compiler/TestCompile/import-link-sibling-layer.exp.json diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index db34c4ad59..48cefd4f12 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -1,6 +1,8 @@ #### Features ๐Ÿš€ - Vars: Variable definitions can now refer to other variables in the current scope [#2052](https://github.com/terrastruct/d2/pull/2052) +- Composition: Imported boards can use underscores to reference boards beyond its own + scope (e.g. to a sibling board at the scope its imported to) [#2075](https://github.com/terrastruct/d2/pull/2075) #### Improvements ๐Ÿงน diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 037cb4ea75..abcc127805 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -2394,7 +2394,7 @@ layers: { } } }`, - expErr: `d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:9: invalid underscore usage`, + expErr: `d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:9: linked board not found`, }, { name: "border-radius-negative", @@ -3114,6 +3114,80 @@ layers: { "y/n.d2": "p", }, }, + { + name: "import-link-layer-1", + text: `k + +layers: { + x: {...@y} + z: { hi } +}`, + files: map[string]string{ + "y.d2": `a.link: _.layers.z +`, + }, + assertions: func(t *testing.T, g *d2graph.Graph) { + tassert.Equal(t, "root.layers.z", g.Layers[0].Objects[0].Link.Value) + }, + }, + { + name: "import-link-layer-2", + text: `...@y + +layers: { + z: { hi } +}`, + files: map[string]string{ + "y.d2": `a.link: layers.z +`, + }, + assertions: func(t *testing.T, g *d2graph.Graph) { + tassert.Equal(t, "root.layers.z", g.Objects[0].Link.Value) + }, + }, + { + name: "import-link-layer-3", + text: `k + +layers: { + x: {...@y} + z: { hi } +}`, + files: map[string]string{ + "y.d2": `a +layers: { + lol: { + asdf.link: _._.layers.z + } +} +`, + }, + assertions: func(t *testing.T, g *d2graph.Graph) { + tassert.Equal(t, "root.layers.z", g.Layers[0].Layers[0].Objects[0].Link.Value) + }, + }, + { + name: "import-link-layer-4", + text: `k + +layers: { + x: @y + z: { hi } +}`, + files: map[string]string{ + "y.d2": `a +layers: { + lol: { + asdf.link: _.layers.z + } + z: { fjf } +} +`, + }, + assertions: func(t *testing.T, g *d2graph.Graph) { + tassert.Equal(t, "root.layers.x.layers.z", g.Layers[0].Layers[0].Objects[0].Link.Value) + }, + }, { name: "sql-table-header-newline", text: `x: { diff --git a/d2ir/compile.go b/d2ir/compile.go index 9da3a7a4ea..9beb843c32 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -920,7 +920,16 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) { continue } - extendedIDA := append(importIDA, linkIDA[1:]...) + for _, id := range linkIDA[1:] { + if id == "_" { + linkIDA = append([]string{linkIDA[0]}, linkIDA[2:]...) + importIDA = importIDA[:len(importIDA)-2] + } else { + break + } + } + + extendedIDA := append(importIDA[:len(importIDA)], linkIDA[1:]...) kp := d2ast.MakeKeyPath(extendedIDA) s := d2format.Format(kp) f.Primary_.Value = d2ast.MakeValueBox(d2ast.FlatUnquotedString(s)).ScalarBox().Unbox() @@ -984,10 +993,9 @@ func (c *compiler) compileLink(f *Field, refctx *RefContext) { // Resolve underscores for len(linkIDA) > 0 && linkIDA[0] == "_" { if len(scopeIDA) < 2 { - // IR compiler only validates bad underscore usage - // The compiler will validate if the target board actually exists - c.errorf(refctx.Key.Key, "invalid underscore usage") - return + // Leave the underscore. It will fail in compiler as a standalone board, + // but if imported, will get further resolved in extendLinks + break } // pop 2 off path per one underscore scopeIDA = scopeIDA[:len(scopeIDA)-2] diff --git a/testdata/d2compiler/TestCompile/import-link-layer-1.exp.json b/testdata/d2compiler/TestCompile/import-link-layer-1.exp.json new file mode 100644 index 0000000000..193b606ee4 --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-link-layer-1.exp.json @@ -0,0 +1,493 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,0:0:0-5:1:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,2:0:3-5:1:39", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,2:0:3-2:6:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,2:0:3-2:6:9", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,2:8:11-5:1:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,3:2:15-3:12:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,3:2:15-3:3:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,3:2:15-3:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,3:5:18-3:12:25", + "nodes": [ + { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,3:6:19-3:11:24", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,3:10:23-3:11:24", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:2:28-4:11:37", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:2:28-4:3:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:2:28-4:3:29", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:5:31-4:11:37", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:7:33-4:10:36", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:7:33-4:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:7:33-4:9:35", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "x", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "link" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "root.layers.z" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:2:2-0:6:6", + "value": [ + { + "string": "link", + "raw_string": "link" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "link": { + "value": "root.layers.z" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + { + "name": "z", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:7:33-4:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-1.d2,4:7:33-4:9:35", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/import-link-layer-2.exp.json b/testdata/d2compiler/TestCompile/import-link-layer-2.exp.json new file mode 100644 index 0000000000..ea5a732109 --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-link-layer-2.exp.json @@ -0,0 +1,302 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,0:0:0-4:1:30", + "nodes": [ + { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,0:0:0-0:5:5", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,0:4:4-0:5:5", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,2:0:7-4:1:30", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,2:0:7-2:6:13", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,2:0:7-2:6:13", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,2:8:15-4:1:30", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:2:19-3:11:28", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:2:19-3:3:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:2:19-3:3:20", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:5:22-3:11:28", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:7:24-3:10:27", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:7:24-3:9:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:7:24-3:9:26", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:2:2-0:6:6", + "value": [ + { + "string": "link", + "raw_string": "link" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "link": { + "value": "root.layers.z" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "z", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:7:24-3:9:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-2.d2,3:7:24-3:9:26", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/import-link-layer-3.exp.json b/testdata/d2compiler/TestCompile/import-link-layer-3.exp.json new file mode 100644 index 0000000000..54f6603f1e --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-link-layer-3.exp.json @@ -0,0 +1,712 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,0:0:0-5:1:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,2:0:3-5:1:39", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,2:0:3-2:6:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,2:0:3-2:6:9", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,2:8:11-5:1:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,3:2:15-3:12:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,3:2:15-3:3:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,3:2:15-3:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,3:5:18-3:12:25", + "nodes": [ + { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,3:6:19-3:11:24", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,3:10:23-3:11:24", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:2:28-4:11:37", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:2:28-4:3:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:2:28-4:3:29", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:5:31-4:11:37", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:7:33-4:10:36", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:7:33-4:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:7:33-4:9:35", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "x", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "lol" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "asdf" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "link" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "root.layers.z" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "lol", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "asdf" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "link" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "root.layers.z" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "asdf", + "id_val": "asdf", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,3:4:25-3:13:34", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,3:4:25-3:8:29", + "value": [ + { + "string": "asdf", + "raw_string": "asdf" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,3:9:30-3:13:34", + "value": [ + { + "string": "link", + "raw_string": "link" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "asdf" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "link": { + "value": "root.layers.z" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + { + "name": "z", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:7:33-4:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-3.d2,4:7:33-4:9:35", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/import-link-layer-4.exp.json b/testdata/d2compiler/TestCompile/import-link-layer-4.exp.json new file mode 100644 index 0000000000..8192eec657 --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-link-layer-4.exp.json @@ -0,0 +1,882 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,0:0:0-5:1:34", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,2:0:3-5:1:34", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,2:0:3-2:6:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,2:0:3-2:6:9", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,2:8:11-5:1:34", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,3:2:15-3:7:20", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,3:2:15-3:3:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,3:2:15-3:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",1:0:0-1:0:0", + "nodes": [ + { + "import": { + "range": ",1:0:0-1:0:0", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,3:6:19-3:7:20", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + ] + }, + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,3:5:18-3:7:20", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,3:6:19-3:7:20", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:2:23-4:11:32", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:2:23-4:3:24", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:2:23-4:3:24", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:5:26-4:11:32", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:7:28-4:10:31", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:7:28-4:9:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:7:28-4:9:30", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "x", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "lol" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "asdf" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "link" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "root.layers.x.layers.z" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "fjf" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "lol", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "asdf" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "link" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "root.layers.x.layers.z" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "asdf", + "id_val": "asdf", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,3:4:25-3:13:34", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,3:4:25-3:8:29", + "value": [ + { + "string": "asdf", + "raw_string": "asdf" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,3:9:30-3:13:34", + "value": [ + { + "string": "link", + "raw_string": "link" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "asdf" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "link": { + "value": "root.layers.x.layers.z" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + { + "name": "z", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "fjf" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "fjf", + "id_val": "fjf", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,5:6:57-5:9:60", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,5:6:57-5:9:60", + "value": [ + { + "string": "fjf", + "raw_string": "fjf" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "fjf" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + { + "name": "z", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:7:28-4:9:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-layer-4.d2,4:7:28-4:9:30", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/import-link-sibling-layer.exp.json b/testdata/d2compiler/TestCompile/import-link-sibling-layer.exp.json new file mode 100644 index 0000000000..83dcb24947 --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-link-sibling-layer.exp.json @@ -0,0 +1,493 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,0:0:0-5:1:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,2:0:3-5:1:39", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,2:0:3-2:6:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,2:0:3-2:6:9", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,2:8:11-5:1:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,3:2:15-3:12:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,3:2:15-3:3:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,3:2:15-3:3:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,3:5:18-3:12:25", + "nodes": [ + { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,3:6:19-3:11:24", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,3:10:23-3:11:24", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:2:28-4:11:37", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:2:28-4:3:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:2:28-4:3:29", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:5:31-4:11:37", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:7:33-4:10:36", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:7:33-4:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:7:33-4:9:35", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "x", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "link" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "root.layers.x.layers.z" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/y.d2,0:2:2-0:6:6", + "value": [ + { + "string": "link", + "raw_string": "link" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "link": { + "value": "root.layers.x.layers.z" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + { + "name": "z", + "isFolderOnly": false, + "ast": { + "range": ",0:0:0-1:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:7:33-4:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-link-sibling-layer.d2,4:7:33-4:9:35", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/link-board-underscore-not-found.exp.json b/testdata/d2compiler/TestCompile/link-board-underscore-not-found.exp.json index 378536db9e..2cd9f97dfa 100644 --- a/testdata/d2compiler/TestCompile/link-board-underscore-not-found.exp.json +++ b/testdata/d2compiler/TestCompile/link-board-underscore-not-found.exp.json @@ -3,8 +3,8 @@ "err": { "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2,6:8:59-6:18:69", - "errmsg": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:9: invalid underscore usage" + "range": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2,6:8:59-6:25:76", + "errmsg": "d2/testdata/d2compiler/TestCompile/link-board-underscore-not-found.d2:7:9: linked board not found" } ] }