From cc1e647dfc8ddcf3ac2af251e283c4626d834845 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 14 Mar 2025 21:17:41 -0600 Subject: [PATCH] fix var panic --- d2ir/compile.go | 4 ++ .../TestCompile/import-var-chain.exp.json | 57 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 testdata/d2compiler/TestCompile/import-var-chain.exp.json diff --git a/d2ir/compile.go b/d2ir/compile.go index 9473b7e37..a239862a8 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -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") diff --git a/testdata/d2compiler/TestCompile/import-var-chain.exp.json b/testdata/d2compiler/TestCompile/import-var-chain.exp.json new file mode 100644 index 000000000..8868dcdb7 --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-var-chain.exp.json @@ -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 +}