diff --git a/d2compiler/compile.go b/d2compiler/compile.go index d9eb109fe..4c39c7084 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -210,8 +210,8 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { c.compileReserved(&obj.Attributes, f) return } else if f.Name == "style" { - if f.Map() == nil { - c.errorf(f.LastRef().AST(), `"style" expected to be set to a map, or contain an additional keyword like "style.opacity: 0.4"`) + if f.Map() == nil || len(f.Map().Fields) == 0 { + c.errorf(f.LastRef().AST(), `"style" expected to be set to a map of key-values, or contain an additional keyword like "style.opacity: 0.4"`) return } c.compileStyle(&obj.Attributes, f.Map()) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 188fd5225..657d09575 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1700,7 +1700,13 @@ x.a.b`, name: "tail-style", text: `myobj.style: 3`, - expErr: `d2/testdata/d2compiler/TestCompile/tail-style.d2:1:7: "style" expected to be set to a map, or contain an additional keyword like "style.opacity: 0.4"`, + expErr: `d2/testdata/d2compiler/TestCompile/tail-style.d2:1:7: "style" expected to be set to a map of key-values, or contain an additional keyword like "style.opacity: 0.4"`, + }, + { + name: "tail-style-map", + + text: `myobj.style: {}`, + expErr: `d2/testdata/d2compiler/TestCompile/tail-style-map.d2:1:7: "style" expected to be set to a map of key-values, or contain an additional keyword like "style.opacity: 0.4"`, }, { name: "bad-style-nesting", diff --git a/testdata/d2compiler/TestCompile/tail-style-map.exp.json b/testdata/d2compiler/TestCompile/tail-style-map.exp.json new file mode 100644 index 000000000..96995af66 --- /dev/null +++ b/testdata/d2compiler/TestCompile/tail-style-map.exp.json @@ -0,0 +1,12 @@ +{ + "graph": null, + "err": { + "ioerr": null, + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/tail-style-map.d2,0:6:6-0:11:11", + "errmsg": "d2/testdata/d2compiler/TestCompile/tail-style-map.d2:1:7: \"style\" expected to be set to a map of key-values, or contain an additional keyword like \"style.opacity: 0.4\"" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile/tail-style.exp.json b/testdata/d2compiler/TestCompile/tail-style.exp.json index de962fbdf..3788c9e9f 100644 --- a/testdata/d2compiler/TestCompile/tail-style.exp.json +++ b/testdata/d2compiler/TestCompile/tail-style.exp.json @@ -5,7 +5,7 @@ "errs": [ { "range": "d2/testdata/d2compiler/TestCompile/tail-style.d2,0:6:6-0:11:11", - "errmsg": "d2/testdata/d2compiler/TestCompile/tail-style.d2:1:7: \"style\" expected to be set to a map, or contain an additional keyword like \"style.opacity: 0.4\"" + "errmsg": "d2/testdata/d2compiler/TestCompile/tail-style.d2:1:7: \"style\" expected to be set to a map of key-values, or contain an additional keyword like \"style.opacity: 0.4\"" } ] }