diff --git a/d2compiler/compile.go b/d2compiler/compile.go index f4630137c..fceec752d 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -250,7 +250,6 @@ func (c *compiler) compileMap(obj *d2graph.Object, m *d2ir.Map) { } func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { - println("\033[1;31m--- DEBUG:", "=======================", "\033[m") keyword := strings.ToLower(f.Name) _, isStyleReserved := d2graph.StyleKeywords[keyword] if isStyleReserved { diff --git a/d2ir/compile.go b/d2ir/compile.go index 20a03b103..7c5ed5fb0 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -156,6 +156,13 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) return } + if f.Primary() != nil { + // null only applies if it's the appearance + if _, ok := f.Primary().Value.(*d2ast.Null); ok { + f.Primary_ = nil + } + } + if refctx.Key.Primary.Unbox() != nil { f.Primary_ = &Scalar{ parent: f, diff --git a/testdata/d2compiler/TestCompile2/nulls/reappear/shape.exp.json b/testdata/d2compiler/TestCompile2/nulls/reappear/shape.exp.json index ebeb96548..cd14b3174 100644 --- a/testdata/d2compiler/TestCompile2/nulls/reappear/shape.exp.json +++ b/testdata/d2compiler/TestCompile2/nulls/reappear/shape.exp.json @@ -104,7 +104,93 @@ "zIndex": 0 }, "edges": null, - "objects": null + "objects": [ + { + "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", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/nulls/reappear/shape.d2,3:0:11-3:1:12", + "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 }