From 1acc3d685a36b3d0c538d9ab17eccd656b835e59 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 26 Jun 2023 11:57:18 -0700 Subject: [PATCH] new implementation --- d2compiler/compile.go | 14 - d2compiler/compile_test.go | 82 +++++ d2graph/d2graph.go | 8 - d2ir/compile.go | 9 + d2ir/d2ir.go | 25 ++ .../TestCompile2/nulls/basic/edge.exp.json | 40 --- .../nulls/implicit/delete-children.exp.json | 31 -- .../implicit/no-delete-connection.exp.json | 110 +++---- .../nulls/multiboard/scenario.exp.json | 226 +++++++++++++ .../nulls/reappear/attribute-reset.exp.json | 184 +++++++++++ .../nulls/reappear/children-reset.exp.json | 309 ++++++++++++++++++ .../nulls/reappear/edge-reset.exp.json | 224 +++++++++++++ .../TestCompile2/nulls/reappear/edge.exp.json | 42 +-- .../nulls/reappear/reset.exp.json | 184 +++++++++++ .../nulls/reappear/shape.exp.json | 42 +-- 15 files changed, 1290 insertions(+), 240 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.exp.json create mode 100644 testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.exp.json create mode 100644 testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.exp.json create mode 100644 testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.exp.json create mode 100644 testdata/d2compiler/TestCompile2/nulls/reappear/reset.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index d75ceb2f9..fdb24e551 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -78,7 +78,6 @@ func (c *compiler) compileBoard(g *d2graph.Graph, ir *d2ir.Map) *d2graph.Graph { ir = ir.Copy(nil).(*d2ir.Map) // c.preprocessSeqDiagrams(ir) c.compileMap(g.Root, ir) - c.nullify(g) if len(c.err.Errors) == 0 { c.validateKeys(g.Root, ir) } @@ -834,19 +833,6 @@ func (c *compiler) compileArrowheads(edge *d2graph.Edge, f *d2ir.Field) { } } -func (c *compiler) nullify(g *d2graph.Graph) { - for _, obj := range g.Objects { - if len(obj.References) > 0 && obj.References[len(obj.References)-1].Nulled() { - g.DeleteObject(obj) - } - } - for _, e := range g.Edges { - if len(e.References) > 0 && e.References[len(e.References)-1].Nulled() { - g.DeleteEdge(e) - } - } -} - // TODO add more, e.g. C, bash var ShortToFullLanguageAliases = map[string]string{ "md": "markdown", diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 34e9f3f20..db89c2319 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -2956,6 +2956,16 @@ a -> b assert.Equal(t, 0, len(g.Edges)) }, }, + // { + // name: "attribute", + // run: func(t *testing.T) { + // g := assertCompile(t, ` + // a.style.opacity: 0.2 + // a.style.opacity: null + // `, "") + // assert.Equal(t, "0.2", g.Objects[0].Attributes.Style.Opacity.Value) + // }, + // }, } for _, tc := range tca { @@ -3001,6 +3011,41 @@ a -> b assert.Equal(t, 1, len(g.Edges)) }, }, + { + name: "attribute-reset", + run: func(t *testing.T) { + g := assertCompile(t, ` +a.style.opacity: 0.2 +a: null +a +`, "") + assert.Equal(t, 1, len(g.Objects)) + assert.Equal(t, (*d2graph.Scalar)(nil), g.Objects[0].Attributes.Style.Opacity) + }, + }, + { + name: "edge-reset", + run: func(t *testing.T) { + g := assertCompile(t, ` +a -> b +a: null +a +`, "") + assert.Equal(t, 2, len(g.Objects)) + assert.Equal(t, 0, len(g.Edges)) + }, + }, + { + name: "children-reset", + run: func(t *testing.T) { + g := assertCompile(t, ` +a.b.c +a.b: null +a.b +`, "") + assert.Equal(t, 2, len(g.Objects)) + }, + }, } for _, tc := range tca { @@ -3071,6 +3116,43 @@ a.b: null }) } }) + + t.Run("multiboard", func(t *testing.T) { + t.Parallel() + + tca := []struct { + name string + skip bool + run func(t *testing.T) + }{ + { + name: "scenario", + run: func(t *testing.T) { + g := assertCompile(t, ` +x + +scenarios: { + a: { + x: null + } +} +`, "") + assert.Equal(t, 0, len(g.Scenarios[0].Objects)) + }, + }, + } + + for _, tc := range tca { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if tc.skip { + t.SkipNow() + } + tc.run(t) + }) + } + }) } func assertCompile(t *testing.T, text string, expErr string) *d2graph.Graph { diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index e140542f1..9feb43fda 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -224,10 +224,6 @@ type Reference struct { ScopeAST *d2ast.Map `json:"-"` } -func (r *Reference) Nulled() bool { - return r.MapKey != nil && len(r.MapKey.Edges) == 0 && r.MapKey.Value.Null != nil -} - func (r Reference) MapKeyEdgeDest() bool { return r.Key == r.MapKey.Edges[r.MapKeyEdgeIndex].Dst } @@ -1155,10 +1151,6 @@ type EdgeReference struct { ScopeAST *d2ast.Map `json:"-"` } -func (er *EdgeReference) Nulled() bool { - return er.MapKey != nil && er.MapKey.Value.Null != nil -} - func (e *Edge) GetAstEdge() *d2ast.Edge { return e.References[0].Edge } diff --git a/d2ir/compile.go b/d2ir/compile.go index 20a03b103..f5d92d043 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -150,6 +150,10 @@ func (c *compiler) compileKey(refctx *RefContext) { } func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) { + if refctx.Key != nil && len(refctx.Key.Edges) == 0 && refctx.Key.Value.Null != nil { + dst.DeleteField(kp.IDA()...) + return + } f, err := dst.EnsureField(kp, refctx) if err != nil { c.err.Errors = append(c.err.Errors, err.(d2ast.Error)) @@ -353,6 +357,11 @@ func (c *compiler) compileEdges(refctx *RefContext) { eida := NewEdgeIDs(refctx.Key) for i, eid := range eida { + if refctx.Key != nil && refctx.Key.Value.Null != nil { + refctx.ScopeMap.DeleteEdge(eid) + continue + } + refctx = refctx.Copy() refctx.Edge = refctx.Key.Edges[i] diff --git a/d2ir/d2ir.go b/d2ir/d2ir.go index 7234256f7..bb5ef5f8d 100644 --- a/d2ir/d2ir.go +++ b/d2ir/d2ir.go @@ -738,6 +738,20 @@ func (m *Map) ensureField(i int, kp *d2ast.KeyPath, refctx *RefContext) (*Field, return f.Map().ensureField(i+1, kp, refctx) } +func (m *Map) DeleteEdge(eid *EdgeID) *Edge { + if eid == nil { + return nil + } + + for i, e := range m.Edges { + if e.ID.Match(eid) { + m.Edges = append(m.Edges[:i], m.Edges[i+1:]...) + return e + } + } + return nil +} + func (m *Map) DeleteField(ida ...string) *Field { if len(ida) == 0 { return nil @@ -751,6 +765,17 @@ func (m *Map) DeleteField(ida ...string) *Field { continue } if len(rest) == 0 { + for _, fr := range f.References { + for i, e := range m.Edges { + for _, er := range e.References { + if er.Context == fr.Context { + m.DeleteEdge(e.ID) + i-- + break + } + } + } + } m.Fields = append(m.Fields[:i], m.Fields[i+1:]...) return f } diff --git a/testdata/d2compiler/TestCompile2/nulls/basic/edge.exp.json b/testdata/d2compiler/TestCompile2/nulls/basic/edge.exp.json index 9f83b57fc..66e103bb6 100644 --- a/testdata/d2compiler/TestCompile2/nulls/basic/edge.exp.json +++ b/testdata/d2compiler/TestCompile2/nulls/basic/edge.exp.json @@ -156,26 +156,6 @@ }, "key_path_index": 0, "map_key_edge_index": 0 - }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/edge.d2,2:1:9-2:2:10", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/edge.d2,2:1:9-2:2:10", - "value": [ - { - "string": "a", - "raw_string": "a" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": 0 } ], "attributes": { @@ -221,26 +201,6 @@ }, "key_path_index": 0, "map_key_edge_index": 0 - }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/edge.d2,2:6:14-2:7:15", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/edge.d2,2:6:14-2:7:15", - "value": [ - { - "string": "b", - "raw_string": "b" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": 0 } ], "attributes": { diff --git a/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.exp.json b/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.exp.json index 758fbbabb..7d93bdeea 100644 --- a/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.exp.json +++ b/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.exp.json @@ -232,37 +232,6 @@ }, "key_path_index": 0, "map_key_edge_index": -1 - }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:0:22-5:3:25", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:0:22-5:1:23", - "value": [ - { - "string": "a", - "raw_string": "a" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/delete-children.d2,5:2:24-5:3:25", - "value": [ - { - "string": "b", - "raw_string": "b" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 } ], "attributes": { diff --git a/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.exp.json b/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.exp.json index b7d4840b6..c0b0e4fc1 100644 --- a/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.exp.json +++ b/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.exp.json @@ -136,71 +136,6 @@ } ], "objects": [ - { - "id": "y", - "id_val": "y", - "references": [ - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,1:0:1-1:1:2", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,1:0:1-1:1:2", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 - }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:5:14-2:6:15", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:5:14-2:6:15", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": 0 - } - ], - "attributes": { - "label": { - "value": "" - }, - "labelDimensions": { - "width": 0, - "height": 0 - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": null - }, - "zIndex": 0 - }, { "id": "x", "id_val": "x", @@ -245,6 +180,51 @@ "constraint": null }, "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:5:14-2:6:15", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/implicit/no-delete-connection.d2,2:5:14-2:6:15", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 } ] }, diff --git a/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.exp.json b/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.exp.json new file mode 100644 index 000000000..9a3a10c59 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.exp.json @@ -0,0 +1,226 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,0:0:0-8:0:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,1:0:1-1:1:2", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,1:0:1-1:1:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,1:0:1-1:1:2", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,3:0:4-7:1:41", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,3:0:4-3:9:13", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,3:0:4-3:9:13", + "value": [ + { + "string": "scenarios", + "raw_string": "scenarios" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,3:11:15-7:1:41", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,4:2:19-6:3:39", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,4:2:19-4:3:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,4:2:19-4:3:20", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,4:5:22-6:3:39", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,5:4:28-5:11:35", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,5:4:28-5:5:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,5:4:28-5:5:29", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "null": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,5:7:31-5:11:35" + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,1:0:1-1:1:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/multiboard/scenario.d2,1:0:1-1:1:2", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "scenarios": [ + { + "name": "a", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": null + }, + "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": null + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.exp.json b/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.exp.json new file mode 100644 index 000000000..92f2e464a --- /dev/null +++ b/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.exp.json @@ -0,0 +1,184 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,0:0:0-4:0:32", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,1:0:1-1:20:21", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,1:0:1-1:15:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,1:0:1-1:1:2", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,1:2:3-1:7:8", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,1:8:9-1:15:16", + "value": [ + { + "string": "opacity", + "raw_string": "opacity" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,1:17:18-1:20:21", + "raw": "0.2", + "value": "1/5" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,2:0:22-2:7:29", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,2:0:22-2:1:23", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,2:0:22-2:1:23", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "null": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,2:3:25-2:7:29" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,3:0:30-3:1:31", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,3:0:30-3:1:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,3:0:30-3:1:31", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "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/TestCompile2/nulls/reappear/attribute-reset.d2,3:0:30-3:1:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/attribute-reset.d2,3:0:30-3:1:31", + "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 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.exp.json b/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.exp.json new file mode 100644 index 000000000..3e297fcec --- /dev/null +++ b/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.exp.json @@ -0,0 +1,309 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,0:0:0-4:0:21", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,1:0:1-1:5:6", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,1:0:1-1:5:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,1:0:1-1:1:2", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,1:2:3-1:3:4", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,1:4:5-1:5:6", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,2:0:7-2:9:16", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,2:0:7-2:3:10", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,2:0:7-2:1:8", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,2:2:9-2:3:10", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "null": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,2:5:12-2:9:16" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:0:17-3:3:20", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:0:17-3:3:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:0:17-3:1:18", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:2:19-3:3:20", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "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/TestCompile2/nulls/reappear/children-reset.d2,1:0:1-1:5:6", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,1:0:1-1:1:2", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,1:2:3-1:3:4", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,1:4:5-1:5:6", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:0:17-3:3:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:0:17-3:1:18", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:2:19-3:3:20", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "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 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:0:17-3:3:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:0:17-3:1:18", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/children-reset.d2,3:2:19-3:3:20", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 1, + "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/TestCompile2/nulls/reappear/edge-reset.exp.json b/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.exp.json new file mode 100644 index 000000000..d6e3860e1 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.exp.json @@ -0,0 +1,224 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,0:0:0-4:0:18", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,1:0:1-1:6:7", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,1:0:1-1:6:7", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,1:0:1-1:1:2", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,1:0:1-1:1:2", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,1:5:6-1:6:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,1:5:6-1:6:7", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,2:0:8-2:7:15", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,2:0:8-2:1:9", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,2:0:8-2:1:9", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "null": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,2:3:11-2:7:15" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,3:0:16-3:1:17", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,3:0:16-3:1:17", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,3:0:16-3:1:17", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "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": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,1:5:6-1:6:7", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,1:5:6-1:6:7", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,3:0:16-3:1:17", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge-reset.d2,3:0:16-3:1:17", + "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 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/nulls/reappear/edge.exp.json b/testdata/d2compiler/TestCompile2/nulls/reappear/edge.exp.json index 726082f0e..f22a53468 100644 --- a/testdata/d2compiler/TestCompile2/nulls/reappear/edge.exp.json +++ b/testdata/d2compiler/TestCompile2/nulls/reappear/edge.exp.json @@ -179,7 +179,7 @@ }, "edges": [ { - "index": 1, + "index": 0, "isCurve": false, "src_arrow": false, "dst_arrow": true, @@ -234,26 +234,6 @@ "key_path_index": 0, "map_key_edge_index": 0 }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:1:9-2:2:10", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:1:9-2:2:10", - "value": [ - { - "string": "a", - "raw_string": "a" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": 0 - }, { "key": { "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:0:26-3:1:27", @@ -319,26 +299,6 @@ "key_path_index": 0, "map_key_edge_index": 0 }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:6:14-2:7:15", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,2:6:14-2:7:15", - "value": [ - { - "string": "b", - "raw_string": "b" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": 0 - }, { "key": { "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/edge.d2,3:5:31-3:6:32", diff --git a/testdata/d2compiler/TestCompile2/nulls/reappear/reset.exp.json b/testdata/d2compiler/TestCompile2/nulls/reappear/reset.exp.json new file mode 100644 index 000000000..cc7592209 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/nulls/reappear/reset.exp.json @@ -0,0 +1,184 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,0:0:0-4:0:32", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,1:0:1-1:20:21", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,1:0:1-1:15:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,1:0:1-1:1:2", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,1:2:3-1:7:8", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,1:8:9-1:15:16", + "value": [ + { + "string": "opacity", + "raw_string": "opacity" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,1:17:18-1:20:21", + "raw": "0.2", + "value": "1/5" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,2:0:22-2:7:29", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,2:0:22-2:1:23", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,2:0:22-2:1:23", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "null": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,2:3:25-2:7:29" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,3:0:30-3:1:31", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,3:0:30-3:1:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,3:0:30-3:1:31", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "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/TestCompile2/nulls/reappear/reset.d2,3:0:30-3:1:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/reset.d2,3:0:30-3:1:31", + "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 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/nulls/reappear/shape.exp.json b/testdata/d2compiler/TestCompile2/nulls/reappear/shape.exp.json index e8a97f770..744b757f3 100644 --- a/testdata/d2compiler/TestCompile2/nulls/reappear/shape.exp.json +++ b/testdata/d2compiler/TestCompile2/nulls/reappear/shape.exp.json @@ -109,46 +109,6 @@ "id": "a", "id_val": "a", "references": [ - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/shape.d2,1:0:1-1:1:2", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/shape.d2,1:0:1-1:1:2", - "value": [ - { - "string": "a", - "raw_string": "a" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 - }, - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/shape.d2,2:0:3-2:1:4", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/shape.d2,2:0:3-2:1:4", - "value": [ - { - "string": "a", - "raw_string": "a" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 - }, { "key": { "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/shape.d2,3:0:11-3:1:12", @@ -172,7 +132,7 @@ ], "attributes": { "label": { - "value": "" + "value": "a" }, "labelDimensions": { "width": 0,