cleanup
This commit is contained in:
parent
090d10e9ca
commit
741a9aa306
6 changed files with 53 additions and 40 deletions
|
|
@ -282,19 +282,6 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
|
|||
if len(f.Map().Edges) > 0 {
|
||||
c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge")
|
||||
}
|
||||
// for _, varField := range f.Map().Fields {
|
||||
// if varField.Map() != nil {
|
||||
// c.errorf(varField.LastRef().AST(), "vars must be simple")
|
||||
// }
|
||||
// for _, cf := range classesField.Map().Fields {
|
||||
// if _, ok := d2graph.ReservedKeywords[cf.Name]; !ok {
|
||||
// c.errorf(cf.LastRef().AST(), "%s is an invalid class field, must be reserved keyword", cf.Name)
|
||||
// }
|
||||
// if cf.Name == "class" {
|
||||
// c.errorf(cf.LastRef().AST(), `"class" cannot appear within "classes"`)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
return
|
||||
} else if isReserved {
|
||||
|
|
|
|||
|
|
@ -3470,7 +3470,31 @@ vars: {
|
|||
x: hey
|
||||
}
|
||||
hi: ${z}
|
||||
`, "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z")
|
||||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable "z"`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "edge",
|
||||
run: func(t *testing.T) {
|
||||
assertCompile(t, `
|
||||
vars: {
|
||||
x -> a
|
||||
}
|
||||
hi
|
||||
`, "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2:3:3: vars cannot contain an edge")
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "map",
|
||||
run: func(t *testing.T) {
|
||||
assertCompile(t, `
|
||||
vars: {
|
||||
colors: {
|
||||
button: red
|
||||
}
|
||||
}
|
||||
hi: ${colors}
|
||||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable "colors"`)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,9 +153,12 @@ func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d
|
|||
resolved = r
|
||||
}
|
||||
if resolved == nil {
|
||||
c.errorf(mk, "could not resolve variable %s", strings.Join(substitution.IDA(), "."))
|
||||
c.errorf(mk, `could not resolve variable "%s"`, strings.Join(substitution.IDA(), "."))
|
||||
} else {
|
||||
// TODO maps
|
||||
if resolved.Composite != nil {
|
||||
c.errorf(mk, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), "."))
|
||||
return nil
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
return nil
|
||||
|
|
@ -211,9 +214,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
|
|||
}
|
||||
for _, n := range ast.Nodes {
|
||||
switch {
|
||||
case n.Substitution != nil:
|
||||
println("\033[1;31m--- DEBUG:", "=======================", "\033[m")
|
||||
c.errorf(n.Substitution, "only values can use substitutions")
|
||||
case n.MapKey != nil:
|
||||
c.compileKey(&RefContext{
|
||||
Key: n.MapKey,
|
||||
|
|
@ -350,15 +350,6 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
|
|||
c.overlayClasses(f.Map())
|
||||
}
|
||||
}
|
||||
// } else if refctx.Key.Value.Substitution != nil {
|
||||
// vars := ParentBoard(f).Map().GetField("vars")
|
||||
// resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution)
|
||||
// if resolved != nil {
|
||||
// f.Primary_ = &Scalar{
|
||||
// parent: f,
|
||||
// Value: resolved,
|
||||
// }
|
||||
// }
|
||||
} else if refctx.Key.Value.ScalarBox().Unbox() != nil {
|
||||
// If the link is a board, we need to transform it into an absolute path.
|
||||
if f.Name == "link" {
|
||||
|
|
@ -368,8 +359,6 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext)
|
|||
parent: f,
|
||||
Value: refctx.Key.Value.ScalarBox().Unbox(),
|
||||
}
|
||||
|
||||
// InterpolationBox within any of these values can be substitutions too
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -538,15 +527,6 @@ func (c *compiler) compileEdges(refctx *RefContext) {
|
|||
}
|
||||
}
|
||||
c.compileMap(e.Map_, refctx.Key.Value.Map, refctx.ScopeAST)
|
||||
// } else if refctx.Key.Value.Substitution != nil {
|
||||
// vars := ParentBoard(e).Map().GetField("vars")
|
||||
// resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution)
|
||||
// if resolved != nil {
|
||||
// e.Primary_ = &Scalar{
|
||||
// parent: e,
|
||||
// Value: resolved,
|
||||
// }
|
||||
// }
|
||||
} else if refctx.Key.Value.ScalarBox().Unbox() != nil {
|
||||
e.Primary_ = &Scalar{
|
||||
parent: e,
|
||||
|
|
|
|||
11
testdata/d2compiler/TestCompile2/vars/errors/edge.exp.json
generated
vendored
Normal file
11
testdata/d2compiler/TestCompile2/vars/errors/edge.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"graph": null,
|
||||
"err": {
|
||||
"errs": [
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2,2:2:11-2:8:17",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2:3:3: vars cannot contain an edge"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
11
testdata/d2compiler/TestCompile2/vars/errors/map.exp.json
generated
vendored
Normal file
11
testdata/d2compiler/TestCompile2/vars/errors/map.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"graph": null,
|
||||
"err": {
|
||||
"errs": [
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2,6:0:43-6:13:56",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable \"colors\""
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
2
testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json
generated
vendored
2
testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json
generated
vendored
|
|
@ -4,7 +4,7 @@
|
|||
"errs": [
|
||||
{
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2,4:0:20-4:8:28",
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z"
|
||||
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable \"z\""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue