From 31f2ca66b8cd09985d6d0a44712c6d401cf3f893 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 5 Jun 2024 15:11:07 -0600 Subject: [PATCH 1/2] test --- d2compiler/compile_test.go | 16 + .../TestCompile/spread-import-link.exp.json | 539 ++++++++++++++++++ 2 files changed, 555 insertions(+) create mode 100644 testdata/d2compiler/TestCompile/spread-import-link.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 9a360bf0c..2350f1aba 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -2902,6 +2902,22 @@ qa: { tassert.Equal(t, "Qa Environment", g.Objects[2].Label.Value) }, }, + { + name: "spread-import-link", + text: `k + +layers: { + x: {...@x} +}`, + files: map[string]string{ + "x.d2": `a.link: layers.b +layers: { + b: { + d + } +}`, + }, + }, } for _, tc := range testCases { diff --git a/testdata/d2compiler/TestCompile/spread-import-link.exp.json b/testdata/d2compiler/TestCompile/spread-import-link.exp.json new file mode 100644 index 000000000..e78eb6e03 --- /dev/null +++ b/testdata/d2compiler/TestCompile/spread-import-link.exp.json @@ -0,0 +1,539 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,0:0:0-4:1:22", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,0:0:0-0:1:1", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,0:0:0-0:1:1", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:0:3-4:1:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:0:3-2:6:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:0:3-2:6:9", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:8:11-4:1:22", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:2:15-3:7:20", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:2:15-3:3:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.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/spread-import-link.d2,3:6:19-3:7:20", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + }, + "import": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:5:18-3:7:20", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:6:19-3:7:20", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/spread-import-link.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.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.b" + } + ] + } + }, + "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": "b" + } + ] + } + } + ] + }, + "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": "d" + } + ] + } + } + ] + }, + "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/x.d2,0:0:0-0:6:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/x.d2,0:0:0-0:1:1", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/x.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.b" + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "layers": [ + { + "name": "b", + "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": "d" + } + ] + } + } + ] + }, + "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": "d", + "id_val": "d", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/x.d2,3:4:38-3:5:39", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/x.d2,3:4:38-3:5:39", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "d" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + } + ] + }, + "err": null +} From d2ec7cd19c90668cebcc2424dc5cd4493aa611b7 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 5 Jun 2024 22:22:47 -0600 Subject: [PATCH 2/2] fix --- ci/release/changelogs/next.md | 1 + d2ir/compile.go | 1 + .../TestCompile/spread-import-link.exp.json | 32 ++++--------------- 3 files changed, 9 insertions(+), 25 deletions(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 9df546a71..56fb4e6b1 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -12,3 +12,4 @@ - Using `shape: circle` for arrowheads no longer removes all arrowheads along path in sketch mode [#1942](https://github.com/terrastruct/d2/pull/1942) - Globs to null connections work [#1965](https://github.com/terrastruct/d2/pull/1965) - Edge globs setting styles inherit correctly in child boards [#1967](https://github.com/terrastruct/d2/pull/1967) +- Board links imported with spread imports work [#1972](https://github.com/terrastruct/d2/pull/1972) diff --git a/d2ir/compile.go b/d2ir/compile.go index 1d7028c2c..b05cda85c 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -512,6 +512,7 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { } OverlayMap(dst, impn.Map()) + c.updateLinks(dst) if impnf, ok := impn.(*Field); ok { if impnf.Primary_ != nil { diff --git a/testdata/d2compiler/TestCompile/spread-import-link.exp.json b/testdata/d2compiler/TestCompile/spread-import-link.exp.json index e78eb6e03..a3fbe8c23 100644 --- a/testdata/d2compiler/TestCompile/spread-import-link.exp.json +++ b/testdata/d2compiler/TestCompile/spread-import-link.exp.json @@ -3,7 +3,7 @@ "name": "", "isFolderOnly": false, "ast": { - "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,0:0:0-4:1:22", + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,0:0:0-4:1:27", "nodes": [ { "map_key": { @@ -30,7 +30,7 @@ }, { "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:0:3-4:1:22", + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:0:3-4:1:27", "key": { "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:0:3-2:6:9", "path": [ @@ -50,11 +50,11 @@ "primary": {}, "value": { "map": { - "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:8:11-4:1:22", + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,2:8:11-4:1:27", "nodes": [ { "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:2:15-3:7:20", + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:2:15-3:12:25", "key": { "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:2:15-3:3:16", "path": [ @@ -74,17 +74,17 @@ "primary": {}, "value": { "map": { - "range": ",1:0:0-1:0:0", + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:5:18-3:12:25", "nodes": [ { "import": { - "range": ",1:0:0-1:0:0", + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:6:19-3:11:24", "spread": true, "pre": "", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:6:19-3:7:20", + "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:10:23-3:11:24", "value": [ { "string": "x", @@ -97,24 +97,6 @@ } } ] - }, - "import": { - "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:5:18-3:7:20", - "spread": false, - "pre": "", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/spread-import-link.d2,3:6:19-3:7:20", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] } } }