diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index da5e686ba..f077c5abe 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1714,6 +1714,25 @@ steps: { assert.Equal(t, 1, len(g.Layers[0].Steps)) }, }, + { + name: "import-nested-var", + + text: `...@models.environment +`, + files: map[string]string{ + "models.d2": ` +vars: { + c: { + k + } +} + +environment: { + ...${c} +} +`, + }, + }, { name: "import-connections", diff --git a/testdata/d2compiler/TestCompile/import-nested-var.exp.json b/testdata/d2compiler/TestCompile/import-nested-var.exp.json new file mode 100644 index 000000000..243379fb6 --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-nested-var.exp.json @@ -0,0 +1,191 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-3:0:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-2:1:41", + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:11:11", + "value": [ + { + "string": "development", + "raw_string": "development" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:13:13-2:1:41", + "nodes": [ + { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,1:2:17-1:24:39", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,1:6:21-1:12:27", + "value": [ + { + "string": "models", + "raw_string": "models" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,1:13:28-1:24:39", + "value": [ + { + "string": "environment", + "raw_string": "environment" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "development", + "id_val": "development", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:11:11", + "value": [ + { + "string": "development", + "raw_string": "development" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "development" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/models.d2,8:2:56-8:3:57", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/models.d2,8:2:56-8:3:57", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +}