Merge pull request #2448 from alixander/fix-classes-panic
d2ir: fix classes panic
This commit is contained in:
commit
f22d8a43c7
7 changed files with 52 additions and 6 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
- fixes panic when comment lines appear in arrays [#2378](https://github.com/terrastruct/d2/pull/2378)
|
- fixes panic when comment lines appear in arrays [#2378](https://github.com/terrastruct/d2/pull/2378)
|
||||||
- fixes inconsistencies when objects were double quoted [#2390](https://github.com/terrastruct/d2/pull/2390)
|
- fixes inconsistencies when objects were double quoted [#2390](https://github.com/terrastruct/d2/pull/2390)
|
||||||
- fixes globs not applying to spread substitutions [#2426](https://github.com/terrastruct/d2/issues/2426)
|
- fixes globs not applying to spread substitutions [#2426](https://github.com/terrastruct/d2/issues/2426)
|
||||||
|
- fixes panic when classes were mixed with layers incorrectly [#2448](https://github.com/terrastruct/d2/pull/2448)
|
||||||
- CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370)
|
- CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370)
|
||||||
- d2js: handle unicode characters [#2393](https://github.com/terrastruct/d2/pull/2393)
|
- d2js: handle unicode characters [#2393](https://github.com/terrastruct/d2/pull/2393)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -328,7 +328,7 @@ containers: {
|
||||||
Steps
|
Steps
|
||||||
}
|
}
|
||||||
`,
|
`,
|
||||||
expErr: `d2/testdata/d2compiler/TestCompile/image_children_Steps.d2:4:3: steps is only allowed at a board root`,
|
expErr: `d2/testdata/d2compiler/TestCompile/image_children_Steps.d2:4:3: steps must be declared at a board root scope`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "name-with-dot-underscore",
|
name: "name-with-dot-underscore",
|
||||||
|
|
@ -1714,6 +1714,40 @@ steps: {
|
||||||
assert.Equal(t, 1, len(g.Layers[0].Steps))
|
assert.Equal(t, 1, len(g.Layers[0].Steps))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "import-classes-boards",
|
||||||
|
|
||||||
|
text: `classes: {
|
||||||
|
a: {
|
||||||
|
label: hi
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
layers: {
|
||||||
|
asdf: {
|
||||||
|
qwer: {
|
||||||
|
layers: {
|
||||||
|
ok: {
|
||||||
|
bok
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wert: {
|
||||||
|
classes: @classes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
`,
|
||||||
|
files: map[string]string{
|
||||||
|
"classes.d2": `
|
||||||
|
c: {
|
||||||
|
label: bye
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
expErr: `d2/testdata/d2compiler/TestCompile/import-classes-boards.d2:10:7: layers must be declared at a board root scope`,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "import_url_link",
|
name: "import_url_link",
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ func (c *compiler) overlayClasses(m *Map) {
|
||||||
if lClasses == nil {
|
if lClasses == nil {
|
||||||
lClasses = classes.Copy(l).(*Field)
|
lClasses = classes.Copy(l).(*Field)
|
||||||
l.Fields = append(l.Fields, lClasses)
|
l.Fields = append(l.Fields, lClasses)
|
||||||
} else {
|
} else if lClasses.Map() != nil {
|
||||||
base := classes.Copy(l).(*Field)
|
base := classes.Copy(l).(*Field)
|
||||||
OverlayMap(base.Map(), lClasses.Map())
|
OverlayMap(base.Map(), lClasses.Map())
|
||||||
l.DeleteField("classes")
|
l.DeleteField("classes")
|
||||||
|
|
|
||||||
|
|
@ -593,7 +593,7 @@ classes: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
assert.ErrorString(t, err, `TestCompile/classes/nonroot.d2:2:3: classes is only allowed at a board root`)
|
assert.ErrorString(t, err, `TestCompile/classes/nonroot.d2:2:3: classes must be declared at a board root scope`)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -942,11 +942,11 @@ func (m *Map) ensureField(i int, kp *d2ast.KeyPath, refctx *RefContext, create b
|
||||||
}
|
}
|
||||||
|
|
||||||
if headString == "classes" && head.IsUnquoted() && NodeBoardKind(m) == "" {
|
if headString == "classes" && head.IsUnquoted() && NodeBoardKind(m) == "" {
|
||||||
return d2parser.Errorf(kp.Path[i].Unbox(), "%s is only allowed at a board root", headString)
|
return d2parser.Errorf(kp.Path[i].Unbox(), "%s must be declared at a board root scope", headString)
|
||||||
}
|
}
|
||||||
|
|
||||||
if findBoardKeyword(head) != -1 && head.IsUnquoted() && NodeBoardKind(m) == "" {
|
if findBoardKeyword(head) != -1 && head.IsUnquoted() && NodeBoardKind(m) == "" {
|
||||||
return d2parser.Errorf(kp.Path[i].Unbox(), "%s is only allowed at a board root", headString)
|
return d2parser.Errorf(kp.Path[i].Unbox(), "%s must be declared at a board root scope", headString)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, f := range m.Fields {
|
for _, f := range m.Fields {
|
||||||
|
|
|
||||||
2
testdata/d2compiler/TestCompile/image_children_Steps.exp.json
generated
vendored
2
testdata/d2compiler/TestCompile/image_children_Steps.exp.json
generated
vendored
|
|
@ -4,7 +4,7 @@
|
||||||
"errs": [
|
"errs": [
|
||||||
{
|
{
|
||||||
"range": "d2/testdata/d2compiler/TestCompile/image_children_Steps.d2,3:2:115-3:7:120",
|
"range": "d2/testdata/d2compiler/TestCompile/image_children_Steps.d2,3:2:115-3:7:120",
|
||||||
"errmsg": "d2/testdata/d2compiler/TestCompile/image_children_Steps.d2:4:3: steps is only allowed at a board root"
|
"errmsg": "d2/testdata/d2compiler/TestCompile/image_children_Steps.d2:4:3: steps must be declared at a board root scope"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
testdata/d2compiler/TestCompile/import-classes-boards.exp.json
generated
vendored
Normal file
11
testdata/d2compiler/TestCompile/import-classes-boards.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
{
|
||||||
|
"graph": null,
|
||||||
|
"err": {
|
||||||
|
"errs": [
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/import-classes-boards.d2,9:6:75-9:12:81",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile/import-classes-boards.d2:10:7: layers must be declared at a board root scope"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue