non-root err check
This commit is contained in:
parent
85cf491d74
commit
4a9327e102
2 changed files with 15 additions and 0 deletions
|
|
@ -283,6 +283,9 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
|
||||||
c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge")
|
c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if d2ir.NodeBoardKind(d2ir.ParentMap(f)) == "" {
|
||||||
|
c.errorf(f.LastRef().AST(), "vars must be defined at the root of a board")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
} else if isReserved {
|
} else if isReserved {
|
||||||
c.compileReserved(&obj.Attributes, f)
|
c.compileReserved(&obj.Attributes, f)
|
||||||
|
|
|
||||||
|
|
@ -3545,6 +3545,18 @@ hi: ${colors}
|
||||||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable "colors"`)
|
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable "colors"`)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "non-root",
|
||||||
|
run: func(t *testing.T) {
|
||||||
|
assertCompile(t, `
|
||||||
|
x: {
|
||||||
|
vars: {
|
||||||
|
x: hey
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/non-root.d2:3:3: vars must be defined at the root of a board`)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tca {
|
for _, tc := range tca {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue