From ce5da5214f0ee28b465f39604794cbac6b71a77d Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 25 Mar 2025 08:55:30 -0600 Subject: [PATCH 1/4] fix most of it --- d2compiler/compile_test.go | 53 ++ d2ir/compile.go | 21 + .../TestCompile/import-connections.exp.json | 446 ++++++++++++++ .../TestCompile/import-icon-near.exp.json | 20 + .../TestCompile/import-style-1.exp.json | 316 ++++++++++ .../TestCompile/import-style-2.exp.json | 572 ++++++++++++++++++ .../TestCompile/import-style.exp.json | 342 +++++++++++ .../imports/pattern-value.exp.json | 6 + 8 files changed, 1776 insertions(+) create mode 100644 testdata/d2compiler/TestCompile/import-connections.exp.json create mode 100644 testdata/d2compiler/TestCompile/import-style-1.exp.json create mode 100644 testdata/d2compiler/TestCompile/import-style-2.exp.json create mode 100644 testdata/d2compiler/TestCompile/import-style.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index bb939a807..45ef05ed0 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1714,6 +1714,59 @@ steps: { assert.Equal(t, 1, len(g.Layers[0].Steps)) }, }, + { + name: "import-connections", + + text: `b.c -> b.d + +b: @imp +`, + files: map[string]string{ + "imp.d2": ` +c +d +d -> c +`, + }, + assertions: func(t *testing.T, g *d2graph.Graph) { + assert.Equal(t, 2, len(g.Edges)) + }, + }, + { + name: "import-style-1", + + text: `c.style.fill: red + +b: @imp +`, + files: map[string]string{ + "imp.d2": `c`, + }, + assertions: func(t *testing.T, g *d2graph.Graph) { + assert.Equal(t, 2, len(g.Objects)) + assert.Equal(t, "c", g.Objects[1].Label.Value) + assert.Equal(t, "red", g.Objects[1].Style.Fill.Value) + }, + }, + { + name: "import-style-2", + + text: `b.k.c.style.fill: red + +b: @imp +`, + files: map[string]string{ + "imp.d2": ` +k: { + c +} +`, + }, + assertions: func(t *testing.T, g *d2graph.Graph) { + assert.Equal(t, "c", g.Objects[2].Label.Value) + assert.Equal(t, "red", g.Objects[2].Style.Fill.Value) + }, + }, { name: "import-scenario", diff --git a/d2ir/compile.go b/d2ir/compile.go index c7bf15e9d..45672d4bb 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -1098,6 +1098,11 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) { return } n.(Importable).SetImportAST(refctx.Key.Value.Import) + var existingEdges []*Edge + if f.Map() != nil { + existingEdges = f.Map().Edges + } + originalF := f.Copy(refctx.ScopeMap).(*Field) switch n := n.(type) { case *Field: if n.Primary_ != nil { @@ -1134,6 +1139,22 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) { c.overlayClasses(f.Map()) } } + OverlayField(f, originalF) + if existingEdges != nil && f.Map() != nil { + for _, edge := range existingEdges { + exists := false + for _, currentEdge := range f.Map().Edges { + if currentEdge.ID.Match(edge.ID) { + exists = true + break + } + } + if !exists { + f.Map().Edges = append(f.Map().Edges, edge) + } + } + } + } else if refctx.Key.Value.ScalarBox().Unbox() != nil { if c.ignoreLazyGlob(f) { return diff --git a/testdata/d2compiler/TestCompile/import-connections.exp.json b/testdata/d2compiler/TestCompile/import-connections.exp.json new file mode 100644 index 000000000..d86d554ae --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-connections.exp.json @@ -0,0 +1,446 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-3:0:20", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:10:10", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:10:10", + "src": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:3:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:2:2-0:3:3", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:7:7-0:10:10", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:7:7-0:8:8", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:9:9-0:10:10", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:0:12-2:7:19", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:0:12-2:1:13", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:0:12-2:1:13", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:3:15-2:7:19", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:4:16-2:7:19", + "value": [ + { + "string": "imp", + "raw_string": "imp" + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "index": 0, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:3:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:2:2-0:3:3", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:7:7-0:10:10", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:7:7-0:8:8", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:9:9-0:10:10", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:0:12-2:1:13", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:0:12-2:1:13", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,1:0:1-1:1:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,1:0:1-1:1:2", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,3:5:10-3:6:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,3:5:10-3:6:11", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "d", + "id_val": "d", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,2:0:3-2:1:4", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,2:0:3-2:1:4", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,3:0:5-3:1:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,3:0:5-3:1:6", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "d" + }, + "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-icon-near.exp.json b/testdata/d2compiler/TestCompile/import-icon-near.exp.json index ae9301419..5b95fd136 100644 --- a/testdata/d2compiler/TestCompile/import-icon-near.exp.json +++ b/testdata/d2compiler/TestCompile/import-icon-near.exp.json @@ -78,6 +78,26 @@ "id": "y", "id_val": "y", "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-icon-near.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-icon-near.d2,0:0:0-0:1:1", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, { "key": { "range": "d2/testdata/d2compiler/TestCompile/import-icon-near.d2,0:0:0-0:1:1", diff --git a/testdata/d2compiler/TestCompile/import-style-1.exp.json b/testdata/d2compiler/TestCompile/import-style-1.exp.json new file mode 100644 index 000000000..ed113c14f --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-style-1.exp.json @@ -0,0 +1,316 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-3:0:27", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:17:17", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:12:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:2:2-0:7:7", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:8:8-0:12:12", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:14:14-0:17:17", + "value": [ + { + "string": "red", + "raw_string": "red" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:7:26", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:3:22-2:7:26", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:4:23-2:7:26", + "value": [ + { + "string": "imp", + "raw_string": "imp" + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:12:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:2:2-0:7:7", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:8:8-0:12:12", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "red" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,0:0:0-0:1:1", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "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-style-2.exp.json b/testdata/d2compiler/TestCompile/import-style-2.exp.json new file mode 100644 index 000000000..8f4fa248e --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-style-2.exp.json @@ -0,0 +1,572 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-3:0:31", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:21:21", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:2:2-0:3:3", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:4:4-0:5:5", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:6:6-0:11:11", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:12:12-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:18:18-0:21:21", + "value": [ + { + "string": "red", + "raw_string": "red" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:0:23-2:7:30", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:0:23-2:1:24", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:0:23-2:1:24", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:3:26-2:7:30", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:4:27-2:7:30", + "value": [ + { + "string": "imp", + "raw_string": "imp" + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:2:2-0:3:3", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:4:4-0:5:5", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:6:6-0:11:11", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:12:12-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:0:23-2:1:24", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:0:23-2:1:24", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:2:2-0:3:3", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:4:4-0:5:5", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:6:6-0:11:11", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:12:12-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:0:23-2:1:24", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,2:0:23-2:1:24", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,1:0:1-1:1:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,1:0:1-1:1:2", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:2:2-0:3:3", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:4:4-0:5:5", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:6:6-0:11:11", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:12:12-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "red" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,2:2:8-2:3:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,2:2:8-2:3:9", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:2:2-0:3:3", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:4:4-0:5:5", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:6:6-0:11:11", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-2.d2,0:12:12-0:16:16", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 2, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "red" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile/import-style.exp.json b/testdata/d2compiler/TestCompile/import-style.exp.json new file mode 100644 index 000000000..0bea509e5 --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-style.exp.json @@ -0,0 +1,342 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:0:0-3:0:27", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:0:0-0:17:17", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:0:0-0:12:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:2:2-0:7:7", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:8:8-0:12:12", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:14:14-0:17:17", + "value": [ + { + "string": "red", + "raw_string": "red" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,2:0:19-2:7:26", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,2:0:19-2:1:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,2:0:19-2:1:20", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,2:3:22-2:7:26", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,2:4:23-2:7:26", + "value": [ + { + "string": "imp", + "raw_string": "imp" + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:0:0-0:12:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:2:2-0:7:7", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:8:8-0:12:12", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "red" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,1:0:1-1:1:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/imp.d2,1:0:1-1:1:2", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:0:0-0:12:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:0:0-0:1:1", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:2:2-0:7:7", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,0:8:8-0:12:12", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "red" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,2:0:19-2:1:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style.d2,2:0:19-2:1:20", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2ir/TestCompile/imports/pattern-value.exp.json b/testdata/d2ir/TestCompile/imports/pattern-value.exp.json index 8e8653a31..f4753c9c5 100644 --- a/testdata/d2ir/TestCompile/imports/pattern-value.exp.json +++ b/testdata/d2ir/TestCompile/imports/pattern-value.exp.json @@ -10,6 +10,9 @@ } ] }, + "primary": { + "value": null + }, "composite": { "fields": [ { @@ -255,6 +258,9 @@ } ] }, + "primary": { + "value": null + }, "composite": { "fields": [ { From df4f9ca30b1a8762c79547b28eee6dc3da2ff51c Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 25 Mar 2025 09:01:46 -0600 Subject: [PATCH 2/4] fix test --- d2compiler/compile_test.go | 2 +- .../TestCompile/import-connections.exp.json | 144 +++++++++ .../TestCompile/import-style-1.exp.json | 277 ++++++++++++------ .../TestCompile/import-style-2.exp.json | 2 +- 4 files changed, 336 insertions(+), 89 deletions(-) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 45ef05ed0..e373a4cd9 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1735,7 +1735,7 @@ d -> c { name: "import-style-1", - text: `c.style.fill: red + text: `b.c.style.fill: red b: @imp `, diff --git a/testdata/d2compiler/TestCompile/import-connections.exp.json b/testdata/d2compiler/TestCompile/import-connections.exp.json index d86d554ae..6433fd184 100644 --- a/testdata/d2compiler/TestCompile/import-connections.exp.json +++ b/testdata/d2compiler/TestCompile/import-connections.exp.json @@ -207,6 +207,88 @@ "id": "b", "id_val": "b", "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:3:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:2:2-0:3:3", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:7:7-0:10:10", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:7:7-0:8:8", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:9:9-0:10:10", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:0:12-2:1:13", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,2:0:12-2:1:13", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, { "key": { "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:3:3", @@ -353,6 +435,37 @@ }, "key_path_index": 0, "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:3:3", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:2:2-0:3:3", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": 0 } ], "attributes": { @@ -418,6 +531,37 @@ }, "key_path_index": 0, "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:7:7-0:10:10", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:7:7-0:8:8", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-connections.d2,0:9:9-0:10:10", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": 0 } ], "attributes": { diff --git a/testdata/d2compiler/TestCompile/import-style-1.exp.json b/testdata/d2compiler/TestCompile/import-style-1.exp.json index ed113c14f..7a15621be 100644 --- a/testdata/d2compiler/TestCompile/import-style-1.exp.json +++ b/testdata/d2compiler/TestCompile/import-style-1.exp.json @@ -3,17 +3,28 @@ "name": "", "isFolderOnly": false, "ast": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-3:0:27", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-3:0:29", "nodes": [ { "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:17:17", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:19:19", "key": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:12:12", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:14:14", "path": [ { "unquoted_string": { "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:2:2-0:3:3", "value": [ { "string": "c", @@ -24,7 +35,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:2:2-0:7:7", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:4:4-0:9:9", "value": [ { "string": "style", @@ -35,7 +46,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:8:8-0:12:12", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:10:10-0:14:14", "value": [ { "string": "fill", @@ -49,7 +60,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:14:14-0:17:17", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:16:16-0:19:19", "value": [ { "string": "red", @@ -62,13 +73,13 @@ }, { "map_key": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:7:26", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:21-2:7:28", "key": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:21-2:1:22", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:21-2:1:22", "value": [ { "string": "b", @@ -82,13 +93,13 @@ "primary": {}, "value": { "import": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:3:22-2:7:26", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:3:24-2:7:28", "spread": false, "pre": "", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:4:23-2:7:26", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:4:25-2:7:28", "value": [ { "string": "imp", @@ -130,16 +141,27 @@ "edges": null, "objects": [ { - "id": "c", - "id_val": "c", + "id": "b", + "id_val": "b", "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:12:12", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:14:14", "path": [ { "unquoted_string": { "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:2:2-0:3:3", "value": [ { "string": "c", @@ -150,7 +172,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:2:2-0:7:7", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:4:4-0:9:9", "value": [ { "string": "style", @@ -161,7 +183,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:8:8-0:12:12", + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:10:10-0:14:14", "value": [ { "string": "fill", @@ -174,21 +196,110 @@ }, "key_path_index": 0, "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:21-2:1:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:21-2:1:22", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:14:14", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:2:2-0:3:3", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:4:4-0:9:9", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:10:10-0:14:14", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:21-2:1:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:21-2:1:22", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 } ], "attributes": { "label": { - "value": "c" + "value": "b" }, "labelDimensions": { "width": 0, "height": 0 }, - "style": { - "fill": { - "value": "red" - } - }, + "style": {}, "near_key": null, "shape": { "value": "rectangle" @@ -223,6 +334,59 @@ }, "key_path_index": 0, "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:14:14", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:0:0-0:1:1", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:2:2-0:3:3", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:4:4-0:9:9", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,0:10:10-0:14:14", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": -1 } ], "attributes": { @@ -233,72 +397,11 @@ "width": 0, "height": 0 }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" + "style": { + "fill": { + "value": "red" + } }, - "direction": { - "value": "" - }, - "constraint": null - }, - "zIndex": 0 - }, - { - "id": "b", - "id_val": "b", - "references": [ - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", - "value": [ - { - "string": "b", - "raw_string": "b" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 - }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/import-style-1.d2,2:0:19-2:1:20", - "value": [ - { - "string": "b", - "raw_string": "b" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 - } - ], - "attributes": { - "label": { - "value": "b" - }, - "labelDimensions": { - "width": 0, - "height": 0 - }, - "style": {}, "near_key": null, "shape": { "value": "rectangle" diff --git a/testdata/d2compiler/TestCompile/import-style-2.exp.json b/testdata/d2compiler/TestCompile/import-style-2.exp.json index 8f4fa248e..5c61b5d52 100644 --- a/testdata/d2compiler/TestCompile/import-style-2.exp.json +++ b/testdata/d2compiler/TestCompile/import-style-2.exp.json @@ -435,7 +435,7 @@ ], "attributes": { "label": { - "value": "red" + "value": "k" }, "labelDimensions": { "width": 0, From ba46b055166e96fbf20fcef3b92e80a8c524f0e4 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 25 Mar 2025 09:04:09 -0600 Subject: [PATCH 3/4] ta --- .../TestCompile/imports/boards-deep.exp.json | 216 +++++++++++++ .../d2ir/TestCompile/imports/boards.exp.json | 144 +++++++++ .../TestCompile/imports/nested/array.exp.json | 83 +++++ .../TestCompile/imports/nested/map.exp.json | 83 +++++ .../imports/nested/scalar.exp.json | 83 +++++ .../imports/pattern-value.exp.json | 112 ++++++- .../imports/steps-inheritence.exp.json | 288 ++++++++++++++++++ .../d2ir/TestCompile/imports/value.exp.json | 72 +++++ testdata/d2oracle/TestSet/import/6.exp.json | 20 ++ 9 files changed, 1095 insertions(+), 6 deletions(-) diff --git a/testdata/d2ir/TestCompile/imports/boards-deep.exp.json b/testdata/d2ir/TestCompile/imports/boards-deep.exp.json index 892926586..2ea3a94a1 100644 --- a/testdata/d2ir/TestCompile/imports/boards-deep.exp.json +++ b/testdata/d2ir/TestCompile/imports/boards-deep.exp.json @@ -775,6 +775,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "c.d2,0:28:28-0:29:29", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + }, + "key_path": { + "range": "c.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "c.d2,0:28:28-0:29:29", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "c.d2,0:28:28-0:34:34", + "key": { + "range": "c.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "c.d2,0:28:28-0:29:29", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "c.d2,0:31:31-0:34:34", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "c.d2,0:32:32-0:33:33", + "value": [ + { + "string": "d", + "raw_string": "d" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "c.d2,0:28:28-0:29:29", @@ -960,6 +1032,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "b.d2,0:28:28-0:29:29", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + }, + "key_path": { + "range": "b.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "b.d2,0:28:28-0:29:29", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "b.d2,0:28:28-0:34:34", + "key": { + "range": "b.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "b.d2,0:28:28-0:29:29", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "b.d2,0:31:31-0:34:34", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "b.d2,0:32:32-0:33:33", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "b.d2,0:28:28-0:29:29", @@ -1145,6 +1289,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:28:28-0:29:29", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + }, + "key_path": { + "range": "index.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:28:28-0:29:29", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:28:28-0:34:34", + "key": { + "range": "index.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:28:28-0:29:29", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:31:31-0:34:34", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:32:32-0:33:33", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:28:28-0:29:29", diff --git a/testdata/d2ir/TestCompile/imports/boards.exp.json b/testdata/d2ir/TestCompile/imports/boards.exp.json index c2e7e9a19..e2cd8d6b4 100644 --- a/testdata/d2ir/TestCompile/imports/boards.exp.json +++ b/testdata/d2ir/TestCompile/imports/boards.exp.json @@ -540,6 +540,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "x.d2,0:28:28-0:29:29", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + }, + "key_path": { + "range": "x.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "x.d2,0:28:28-0:29:29", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "x.d2,0:28:28-0:34:34", + "key": { + "range": "x.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "x.d2,0:28:28-0:29:29", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "x.d2,0:31:31-0:34:34", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "x.d2,0:32:32-0:33:33", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "x.d2,0:28:28-0:29:29", @@ -725,6 +797,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:28:28-0:29:29", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "index.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:28:28-0:29:29", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:28:28-0:34:34", + "key": { + "range": "index.d2,0:28:28-0:29:29", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:28:28-0:29:29", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:31:31-0:34:34", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:32:32-0:33:33", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:28:28-0:29:29", diff --git a/testdata/d2ir/TestCompile/imports/nested/array.exp.json b/testdata/d2ir/TestCompile/imports/nested/array.exp.json index 7081d05e0..e06ff2377 100644 --- a/testdata/d2ir/TestCompile/imports/nested/array.exp.json +++ b/testdata/d2ir/TestCompile/imports/nested/array.exp.json @@ -26,6 +26,89 @@ ] }, "references": [ + { + "string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:0:0-0:7:7", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:7:7", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:5:5", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "unquoted_string": { + "range": "index.d2,0:6:6-0:7:7", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:0:0-0:1:1", diff --git a/testdata/d2ir/TestCompile/imports/nested/map.exp.json b/testdata/d2ir/TestCompile/imports/nested/map.exp.json index 39559df56..6efbc25c3 100644 --- a/testdata/d2ir/TestCompile/imports/nested/map.exp.json +++ b/testdata/d2ir/TestCompile/imports/nested/map.exp.json @@ -190,6 +190,89 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:0:0-0:7:7", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:7:7", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:5:5", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "unquoted_string": { + "range": "index.d2,0:6:6-0:7:7", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:0:0-0:1:1", diff --git a/testdata/d2ir/TestCompile/imports/nested/scalar.exp.json b/testdata/d2ir/TestCompile/imports/nested/scalar.exp.json index 76558fb51..0d42ee494 100644 --- a/testdata/d2ir/TestCompile/imports/nested/scalar.exp.json +++ b/testdata/d2ir/TestCompile/imports/nested/scalar.exp.json @@ -22,6 +22,89 @@ } }, "references": [ + { + "string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:0:0-0:7:7", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:7:7", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:5:5", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + }, + { + "unquoted_string": { + "range": "index.d2,0:6:6-0:7:7", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:0:0-0:1:1", diff --git a/testdata/d2ir/TestCompile/imports/pattern-value.exp.json b/testdata/d2ir/TestCompile/imports/pattern-value.exp.json index f4753c9c5..a40689479 100644 --- a/testdata/d2ir/TestCompile/imports/pattern-value.exp.json +++ b/testdata/d2ir/TestCompile/imports/pattern-value.exp.json @@ -10,9 +10,6 @@ } ] }, - "primary": { - "value": null - }, "composite": { "fields": [ { @@ -193,6 +190,59 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:0:0-0:11:11", + "value": [ + { + "string": "userWebsite", + "raw_string": "userWebsite" + } + ] + }, + "key_path": { + "range": "index.d2,0:0:0-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:11:11", + "value": [ + { + "string": "userWebsite", + "raw_string": "userWebsite" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:0:0-0:11:11", + "key": { + "range": "index.d2,0:0:0-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:11:11", + "value": [ + { + "string": "userWebsite", + "raw_string": "userWebsite" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:0:0-0:11:11", @@ -258,9 +308,6 @@ } ] }, - "primary": { - "value": null - }, "composite": { "fields": [ { @@ -441,6 +488,59 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,1:0:12-1:10:22", + "value": [ + { + "string": "userMobile", + "raw_string": "userMobile" + } + ] + }, + "key_path": { + "range": "index.d2,1:0:12-1:10:22", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:12-1:10:22", + "value": [ + { + "string": "userMobile", + "raw_string": "userMobile" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,1:0:12-1:10:22", + "key": { + "range": "index.d2,1:0:12-1:10:22", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:12-1:10:22", + "value": [ + { + "string": "userMobile", + "raw_string": "userMobile" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,1:0:12-1:10:22", diff --git a/testdata/d2ir/TestCompile/imports/steps-inheritence.exp.json b/testdata/d2ir/TestCompile/imports/steps-inheritence.exp.json index 12e600fb8..3f542c369 100644 --- a/testdata/d2ir/TestCompile/imports/steps-inheritence.exp.json +++ b/testdata/d2ir/TestCompile/imports/steps-inheritence.exp.json @@ -226,6 +226,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:41:41-0:42:42", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "index.d2,0:41:41-0:42:42", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:41:41-0:42:42", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:41:41-0:46:46", + "key": { + "range": "index.d2,0:41:41-0:42:42", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:41:41-0:42:42", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:44:44-0:46:46", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:45:45-0:46:46", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:41:41-0:42:42", @@ -448,6 +520,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:48:48-0:49:49", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + }, + "key_path": { + "range": "index.d2,0:48:48-0:49:49", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:48:48-0:49:49", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:48:48-0:54:54", + "key": { + "range": "index.d2,0:48:48-0:49:49", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:48:48-0:49:49", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:51:51-0:54:54", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:52:52-0:53:53", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:48:48-0:49:49", @@ -831,6 +975,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:12:12-0:13:13", + "value": [ + { + "string": "1", + "raw_string": "1" + } + ] + }, + "key_path": { + "range": "index.d2,0:12:12-0:13:13", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:12:12-0:13:13", + "value": [ + { + "string": "1", + "raw_string": "1" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:12:12-0:17:17", + "key": { + "range": "index.d2,0:12:12-0:13:13", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:12:12-0:13:13", + "value": [ + { + "string": "1", + "raw_string": "1" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:15:15-0:17:17", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:16:16-0:17:17", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:12:12-0:13:13", @@ -1119,6 +1335,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:19:19-0:20:20", + "value": [ + { + "string": "2", + "raw_string": "2" + } + ] + }, + "key_path": { + "range": "index.d2,0:19:19-0:20:20", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:19:19-0:20:20", + "value": [ + { + "string": "2", + "raw_string": "2" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:19:19-0:25:25", + "key": { + "range": "index.d2,0:19:19-0:20:20", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:19:19-0:20:20", + "value": [ + { + "string": "2", + "raw_string": "2" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:22:22-0:25:25", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:23:23-0:24:24", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:19:19-0:20:20", diff --git a/testdata/d2ir/TestCompile/imports/value.exp.json b/testdata/d2ir/TestCompile/imports/value.exp.json index 64186e6af..fa8af8371 100644 --- a/testdata/d2ir/TestCompile/imports/value.exp.json +++ b/testdata/d2ir/TestCompile/imports/value.exp.json @@ -190,6 +190,78 @@ "edges": null }, "references": [ + { + "string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:0:0-0:8:8", + "key": { + "range": "index.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "import": { + "range": "index.d2,0:3:3-0:8:8", + "spread": false, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:4:4-0:5:5", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + }, + "due_to_glob": false, + "due_to_lazy_glob": false + }, { "string": { "range": "index.d2,0:0:0-0:1:1", diff --git a/testdata/d2oracle/TestSet/import/6.exp.json b/testdata/d2oracle/TestSet/import/6.exp.json index 7c2f2b3e6..9b0e876c3 100644 --- a/testdata/d2oracle/TestSet/import/6.exp.json +++ b/testdata/d2oracle/TestSet/import/6.exp.json @@ -334,6 +334,26 @@ "key_path_index": 0, "map_key_edge_index": -1 }, + { + "key": { + "range": "index.d2,1:0:2-1:1:3", + "path": [ + { + "unquoted_string": { + "range": "index.d2,1:0:2-1:1:3", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, { "key": { "range": "index.d2,2:0:9-2:14:23", From 205ad7752123f6c154376fb770fb9ac5c2ecb0d0 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 25 Mar 2025 09:06:42 -0600 Subject: [PATCH 4/4] next --- ci/release/changelogs/next.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 442b2fe74..f3ee2da8a 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -31,7 +31,9 @@ - Formatter: - fixes substitutions in quotes surrounded by text [#2462](https://github.com/terrastruct/d2/pull/2462) - CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370) -- Composition: spread importing scenarios/steps was not inheriting correctly [#2460](https://github.com/terrastruct/d2/pull/2460) +- Composition: + - spread importing scenarios/steps was not inheriting correctly [#2460](https://github.com/terrastruct/d2/pull/2460) + - imported fields were not merging with current fields/edges [#2464](https://github.com/terrastruct/d2/pull/2464) - Markdown: fixes nested var substitutions not working [#2456](https://github.com/terrastruct/d2/pull/2456) - d2js: handle unicode characters [#2393](https://github.com/terrastruct/d2/pull/2393)