Merge pull request #2427 from alixander/some-vars

fix import var panic
This commit is contained in:
Alexander Wang 2025-03-14 20:27:12 -07:00 committed by GitHub
commit 4e85eb711c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 80 additions and 0 deletions

View file

@ -32,6 +32,7 @@
- Compiler:
- fixes panic when `sql_shape` shape value had mixed casing [#2349](https://github.com/terrastruct/d2/pull/2349)
- fixes panic when importing from a file with spread substitutions in `vars` [#2427](https://github.com/terrastruct/d2/pull/2427)
- fixes support for `center` in `d2-config` [#2360](https://github.com/terrastruct/d2/pull/2360)
- 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)

View file

@ -3125,6 +3125,24 @@ x*: {
tassert.Equal(t, "x2.ok", g.Objects[3].AbsID())
},
},
{
name: "import-var-chain",
text: `...@dev
`,
files: map[string]string{
"dev.d2": `
vars: {
a: {
b
}
c: {
...${a}
}
}
`,
},
},
{
name: "var_in_markdown",
text: `vars: {

View file

@ -1134,6 +1134,10 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {
nodeBoardKind := NodeBoardKind(m)
importIDA := IDA(importF)
for _, f := range m.Fields {
// A substitute or such
if f.Name == nil {
continue
}
if f.Name.ScalarString() == "link" && f.Name.IsUnquoted() {
if nodeBoardKind != "" {
c.errorf(f.LastRef().AST(), "a board itself cannot be linked; only objects within a board can be linked")

View file

@ -0,0 +1,57 @@
{
"graph": {
"name": "",
"isFolderOnly": true,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/import-var-chain.d2,0:0:0-1:0:8",
"nodes": [
{
"import": {
"range": "d2/testdata/d2compiler/TestCompile/import-var-chain.d2,0:0:0-0:7:7",
"spread": true,
"pre": "",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/import-var-chain.d2,0:4:4-0:7:7",
"value": [
{
"string": "dev",
"raw_string": "dev"
}
]
}
}
]
}
}
]
},
"root": {
"id": "",
"id_val": "",
"attributes": {
"label": {
"value": ""
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
},
"edges": null,
"objects": null
},
"err": null
}