Merge pull request #1332 from alixander/no-empty-map
fix `style` validation
This commit is contained in:
commit
266e8eee8b
4 changed files with 22 additions and 4 deletions
|
|
@ -210,8 +210,8 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
|
||||||
c.compileReserved(&obj.Attributes, f)
|
c.compileReserved(&obj.Attributes, f)
|
||||||
return
|
return
|
||||||
} else if f.Name == "style" {
|
} else if f.Name == "style" {
|
||||||
if f.Map() == nil {
|
if f.Map() == nil || len(f.Map().Fields) == 0 {
|
||||||
c.errorf(f.LastRef().AST(), `"style" expected to be set to a map, or contain an additional keyword like "style.opacity: 0.4"`)
|
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
|
return
|
||||||
}
|
}
|
||||||
c.compileStyle(&obj.Attributes, f.Map())
|
c.compileStyle(&obj.Attributes, f.Map())
|
||||||
|
|
|
||||||
|
|
@ -1700,7 +1700,13 @@ x.a.b`,
|
||||||
name: "tail-style",
|
name: "tail-style",
|
||||||
|
|
||||||
text: `myobj.style: 3`,
|
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",
|
name: "bad-style-nesting",
|
||||||
|
|
|
||||||
12
testdata/d2compiler/TestCompile/tail-style-map.exp.json
generated
vendored
Normal file
12
testdata/d2compiler/TestCompile/tail-style-map.exp.json
generated
vendored
Normal file
|
|
@ -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\""
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
2
testdata/d2compiler/TestCompile/tail-style.exp.json
generated
vendored
2
testdata/d2compiler/TestCompile/tail-style.exp.json
generated
vendored
|
|
@ -5,7 +5,7 @@
|
||||||
"errs": [
|
"errs": [
|
||||||
{
|
{
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/tail-style.d2,0:6:6-0:11:11",
|
"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\""
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue