diff --git a/d2compiler/compile.go b/d2compiler/compile.go
index 43be72f03..b623d14a6 100644
--- a/d2compiler/compile.go
+++ b/d2compiler/compile.go
@@ -351,6 +351,7 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
}
}
+ parent := obj
obj = obj.EnsureChild(d2graphIDA([]string{f.Name}))
if f.Primary() != nil {
c.compileLabel(&obj.Attributes, f)
@@ -376,6 +377,7 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
MapKeyEdgeIndex: fr.Context_.EdgeIndex(),
Scope: fr.Context_.Scope,
ScopeAST: fr.Context_.ScopeAST,
+ ScopeObj: parent,
}
if fr.Context_.ScopeMap != nil && !d2ir.IsVar(fr.Context_.ScopeMap) {
scopeObjIDA := d2graphIDA(d2ir.BoardIDA(fr.Context_.ScopeMap))
@@ -777,6 +779,7 @@ func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) {
MapKeyEdgeIndex: er.Context_.EdgeIndex(),
Scope: er.Context_.Scope,
ScopeAST: er.Context_.ScopeAST,
+ ScopeObj: obj,
}
if er.Context_.ScopeMap != nil && !d2ir.IsVar(er.Context_.ScopeMap) {
scopeObjIDA := d2graphIDA(d2ir.BoardIDA(er.Context_.ScopeMap))
diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go
index fe842e2d9..d2ed43f19 100644
--- a/d2compiler/compile_test.go
+++ b/d2compiler/compile_test.go
@@ -1523,6 +1523,36 @@ x -> y: {
}
},
},
+ {
+ name: "nested-scope-1",
+
+ text: `...@second
+`,
+ files: map[string]string{
+ "second.d2": `second: {
+ ...@third
+}`,
+ "third.d2": `third: {
+ elem
+}`,
+ },
+ assertions: func(t *testing.T, g *d2graph.Graph) {
+ assert.Equal(t, 3, len(g.Objects))
+ },
+ },
+ {
+ name: "nested-scope-2",
+
+ text: `...@second
+a.style.fill: null
+`,
+ files: map[string]string{
+ "second.d2": `a.style.fill: red`,
+ },
+ assertions: func(t *testing.T, g *d2graph.Graph) {
+ assert.Equal(t, 1, len(g.Objects))
+ },
+ },
{
name: "url_tooltip",
text: `x: {tooltip: https://google.com}`,
@@ -2998,8 +3028,8 @@ qa: {
assertions: func(t *testing.T, g *d2graph.Graph) {
tassert.Equal(t, "dev.env", g.Objects[1].AbsID())
tassert.Equal(t, "Dev Environment", g.Objects[1].Label.Value)
- tassert.Equal(t, "qa.env", g.Objects[4].AbsID())
- tassert.Equal(t, "Qa Environment", g.Objects[4].Label.Value)
+ tassert.Equal(t, "qa.env", g.Objects[2].AbsID())
+ tassert.Equal(t, "Qa Environment", g.Objects[2].Label.Value)
},
},
{
diff --git a/d2ir/compile.go b/d2ir/compile.go
index 8fb31aad9..1e61d1d0f 100644
--- a/d2ir/compile.go
+++ b/d2ir/compile.go
@@ -541,6 +541,7 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
}
dst.Fields = append(dst.Fields, f)
case n.Import != nil:
+ // Spread import
impn, ok := c._import(n.Import)
if !ok {
continue
@@ -867,6 +868,7 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) {
c.overlayClasses(f.Map())
}
} else if refctx.Key.Value.Import != nil {
+ // Non-spread import
n, ok := c._import(refctx.Key.Value.Import)
if !ok {
return
diff --git a/d2ir/import.go b/d2ir/import.go
index ef80d358c..c415cf138 100644
--- a/d2ir/import.go
+++ b/d2ir/import.go
@@ -61,18 +61,15 @@ func (c *compiler) _import(imp *d2ast.Import) (Node, bool) {
if !ok {
return nil, false
}
+ nilScopeMap(ir)
if len(imp.IDA()) > 0 {
f := ir.GetField(imp.IDA()...)
if f == nil {
c.errorf(imp, "import key %q doesn't exist inside import", imp.IDA())
return nil, false
}
- if f.Map() != nil {
- nilScopeMap(f.Map())
- }
return f, true
}
- nilScopeMap(ir)
return ir, true
}
@@ -135,9 +132,15 @@ func nilScopeMap(n Node) {
for _, r := range n.References {
r.Context_.ScopeMap = nil
}
+ if n.Map() != nil {
+ nilScopeMap(n.Map())
+ }
case *Field:
for _, r := range n.References {
r.Context_.ScopeMap = nil
}
+ if n.Map() != nil {
+ nilScopeMap(n.Map())
+ }
}
}
diff --git a/d2ir/import_test.go b/d2ir/import_test.go
index d67f5950d..10de29e2d 100644
--- a/d2ir/import_test.go
+++ b/d2ir/import_test.go
@@ -211,6 +211,23 @@ label: meow`,
assert.Success(t, err)
},
},
+ {
+ name: "nested-scope",
+ run: func(t testing.TB) {
+ m, err := compileFS(t, "index.d2", map[string]string{
+ "index.d2": `...@second
+`,
+ "second.d2": `elem: {
+ ...@third
+}`,
+ "third.d2": `third: {
+ elem
+}`,
+ })
+ assert.Success(t, err)
+ assertQuery(t, m, 3, 0, nil, "")
+ },
+ },
}
runa(t, tca)
diff --git a/e2etests-cli/main_test.go b/e2etests-cli/main_test.go
index 973434261..01dff0e6d 100644
--- a/e2etests-cli/main_test.go
+++ b/e2etests-cli/main_test.go
@@ -109,6 +109,30 @@ if i'm right: {
a <- b: fix
}
+if i'm wrong: {
+ a <- b: nah, intended
+}`)
+ err := runTestMain(t, ctx, dir, env, "index.d2")
+ assert.Success(t, err)
+
+ assert.TestdataDir(t, filepath.Join(dir, "index"))
+ },
+ },
+ {
+ name: "sequence-spread-layer",
+ run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
+ writeFile(t, dir, "index.d2", `k; layers: { seq: {...@seq.d2} }`)
+ writeFile(t, dir, "seq.d2", `shape: sequence_diagram
+a: me
+b: github.com/terrastruct/d2
+
+a -> b: issue about a bug
+a."some note about the bug"
+
+if i'm right: {
+ a <- b: fix
+}
+
if i'm wrong: {
a <- b: nah, intended
}`)
diff --git a/e2etests-cli/testdata/TestCLI_E2E/pptx-theme-overrides.exp.pptx b/e2etests-cli/testdata/TestCLI_E2E/pptx-theme-overrides.exp.pptx
index 92f7a703a..73d707cea 100644
Binary files a/e2etests-cli/testdata/TestCLI_E2E/pptx-theme-overrides.exp.pptx and b/e2etests-cli/testdata/TestCLI_E2E/pptx-theme-overrides.exp.pptx differ
diff --git a/e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/index.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/index.exp.svg
new file mode 100644
index 000000000..29a8a55da
--- /dev/null
+++ b/e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/index.exp.svg
@@ -0,0 +1,95 @@
+
diff --git a/e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/seq.exp.svg b/e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/seq.exp.svg
new file mode 100644
index 000000000..f8f8b973d
--- /dev/null
+++ b/e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/seq.exp.svg
@@ -0,0 +1,109 @@
+megithub.com/terrastruct/d2if i'm rightif i'm wrong fixnah, intended issue about a bugsome note about the bug
+
+
+
+
+
+
+
+
+
+
diff --git a/testdata/d2compiler/TestCompile/nested-scope-1.exp.json b/testdata/d2compiler/TestCompile/nested-scope-1.exp.json
new file mode 100644
index 000000000..711c99020
--- /dev/null
+++ b/testdata/d2compiler/TestCompile/nested-scope-1.exp.json
@@ -0,0 +1,193 @@
+{
+ "graph": {
+ "name": "",
+ "isFolderOnly": false,
+ "ast": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-1.d2,0:0:0-1:0:11",
+ "nodes": [
+ {
+ "import": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-1.d2,0:0:0-0:10:10",
+ "spread": true,
+ "pre": "",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-1.d2,0:4:4-0:10:10",
+ "value": [
+ {
+ "string": "second",
+ "raw_string": "second"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "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": [
+ {
+ "id": "second",
+ "id_val": "second",
+ "references": [
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/second.d2,0:0:0-0:6:6",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/second.d2,0:0:0-0:6:6",
+ "value": [
+ {
+ "string": "second",
+ "raw_string": "second"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ }
+ ],
+ "attributes": {
+ "label": {
+ "value": "second"
+ },
+ "labelDimensions": {
+ "width": 0,
+ "height": 0
+ },
+ "style": {},
+ "near_key": null,
+ "shape": {
+ "value": "rectangle"
+ },
+ "direction": {
+ "value": ""
+ },
+ "constraint": null
+ },
+ "zIndex": 0
+ },
+ {
+ "id": "third",
+ "id_val": "third",
+ "references": [
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/third.d2,0:0:0-0:5:5",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/third.d2,0:0:0-0:5:5",
+ "value": [
+ {
+ "string": "third",
+ "raw_string": "third"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ }
+ ],
+ "attributes": {
+ "label": {
+ "value": "third"
+ },
+ "labelDimensions": {
+ "width": 0,
+ "height": 0
+ },
+ "style": {},
+ "near_key": null,
+ "shape": {
+ "value": "rectangle"
+ },
+ "direction": {
+ "value": ""
+ },
+ "constraint": null
+ },
+ "zIndex": 0
+ },
+ {
+ "id": "elem",
+ "id_val": "elem",
+ "references": [
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/third.d2,1:2:11-1:6:15",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/third.d2,1:2:11-1:6:15",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ }
+ ],
+ "attributes": {
+ "label": {
+ "value": "elem"
+ },
+ "labelDimensions": {
+ "width": 0,
+ "height": 0
+ },
+ "style": {},
+ "near_key": null,
+ "shape": {
+ "value": "rectangle"
+ },
+ "direction": {
+ "value": ""
+ },
+ "constraint": null
+ },
+ "zIndex": 0
+ }
+ ]
+ },
+ "err": null
+}
diff --git a/testdata/d2compiler/TestCompile/nested-scope-2.exp.json b/testdata/d2compiler/TestCompile/nested-scope-2.exp.json
new file mode 100644
index 000000000..523843136
--- /dev/null
+++ b/testdata/d2compiler/TestCompile/nested-scope-2.exp.json
@@ -0,0 +1,216 @@
+{
+ "graph": {
+ "name": "",
+ "isFolderOnly": false,
+ "ast": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,0:0:0-2:0:30",
+ "nodes": [
+ {
+ "import": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,0:0:0-0:10:10",
+ "spread": true,
+ "pre": "",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,0:4:4-0:10:10",
+ "value": [
+ {
+ "string": "second",
+ "raw_string": "second"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ },
+ {
+ "map_key": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:0:11-1:18:29",
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:0:11-1:12:23",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:0:11-1:1:12",
+ "value": [
+ {
+ "string": "a",
+ "raw_string": "a"
+ }
+ ]
+ }
+ },
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:2:13-1:7:18",
+ "value": [
+ {
+ "string": "style",
+ "raw_string": "style"
+ }
+ ]
+ }
+ },
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:8:19-1:12:23",
+ "value": [
+ {
+ "string": "fill",
+ "raw_string": "fill"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "primary": {},
+ "value": {
+ "null": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:14:25-1:18:29"
+ }
+ }
+ }
+ }
+ ]
+ },
+ "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": [
+ {
+ "id": "a",
+ "id_val": "a",
+ "references": [
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/second.d2,0:0:0-0:12:12",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/second.d2,0:0:0-0:1:1",
+ "value": [
+ {
+ "string": "a",
+ "raw_string": "a"
+ }
+ ]
+ }
+ },
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/second.d2,0:2:2-0:7:7",
+ "value": [
+ {
+ "string": "style",
+ "raw_string": "style"
+ }
+ ]
+ }
+ },
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/second.d2,0:8:8-0:12:12",
+ "value": [
+ {
+ "string": "fill",
+ "raw_string": "fill"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ },
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:0:11-1:12:23",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:0:11-1:1:12",
+ "value": [
+ {
+ "string": "a",
+ "raw_string": "a"
+ }
+ ]
+ }
+ },
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:2:13-1:7:18",
+ "value": [
+ {
+ "string": "style",
+ "raw_string": "style"
+ }
+ ]
+ }
+ },
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope-2.d2,1:8:19-1:12:23",
+ "value": [
+ {
+ "string": "fill",
+ "raw_string": "fill"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ }
+ ],
+ "attributes": {
+ "label": {
+ "value": "a"
+ },
+ "labelDimensions": {
+ "width": 0,
+ "height": 0
+ },
+ "style": {},
+ "near_key": null,
+ "shape": {
+ "value": "rectangle"
+ },
+ "direction": {
+ "value": ""
+ },
+ "constraint": null
+ },
+ "zIndex": 0
+ }
+ ]
+ },
+ "err": null
+}
diff --git a/testdata/d2compiler/TestCompile/nested-scope.exp.json b/testdata/d2compiler/TestCompile/nested-scope.exp.json
new file mode 100644
index 000000000..cfc5f3321
--- /dev/null
+++ b/testdata/d2compiler/TestCompile/nested-scope.exp.json
@@ -0,0 +1,193 @@
+{
+ "graph": {
+ "name": "",
+ "isFolderOnly": false,
+ "ast": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope.d2,0:0:0-1:0:11",
+ "nodes": [
+ {
+ "import": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope.d2,0:0:0-0:10:10",
+ "spread": true,
+ "pre": "",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/nested-scope.d2,0:4:4-0:10:10",
+ "value": [
+ {
+ "string": "second",
+ "raw_string": "second"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "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": [
+ {
+ "id": "second",
+ "id_val": "second",
+ "references": [
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/second.d2,0:0:0-0:6:6",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/second.d2,0:0:0-0:6:6",
+ "value": [
+ {
+ "string": "second",
+ "raw_string": "second"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ }
+ ],
+ "attributes": {
+ "label": {
+ "value": "second"
+ },
+ "labelDimensions": {
+ "width": 0,
+ "height": 0
+ },
+ "style": {},
+ "near_key": null,
+ "shape": {
+ "value": "rectangle"
+ },
+ "direction": {
+ "value": ""
+ },
+ "constraint": null
+ },
+ "zIndex": 0
+ },
+ {
+ "id": "third",
+ "id_val": "third",
+ "references": [
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/third.d2,0:0:0-0:5:5",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/third.d2,0:0:0-0:5:5",
+ "value": [
+ {
+ "string": "third",
+ "raw_string": "third"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ }
+ ],
+ "attributes": {
+ "label": {
+ "value": "third"
+ },
+ "labelDimensions": {
+ "width": 0,
+ "height": 0
+ },
+ "style": {},
+ "near_key": null,
+ "shape": {
+ "value": "rectangle"
+ },
+ "direction": {
+ "value": ""
+ },
+ "constraint": null
+ },
+ "zIndex": 0
+ },
+ {
+ "id": "elem",
+ "id_val": "elem",
+ "references": [
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/third.d2,1:2:11-1:6:15",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/third.d2,1:2:11-1:6:15",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ }
+ ],
+ "attributes": {
+ "label": {
+ "value": "elem"
+ },
+ "labelDimensions": {
+ "width": 0,
+ "height": 0
+ },
+ "style": {},
+ "near_key": null,
+ "shape": {
+ "value": "rectangle"
+ },
+ "direction": {
+ "value": ""
+ },
+ "constraint": null
+ },
+ "zIndex": 0
+ }
+ ]
+ },
+ "err": null
+}
diff --git a/testdata/d2compiler/TestCompile/vars-in-imports.exp.json b/testdata/d2compiler/TestCompile/vars-in-imports.exp.json
index fad97a840..05c63f5e3 100644
--- a/testdata/d2compiler/TestCompile/vars-in-imports.exp.json
+++ b/testdata/d2compiler/TestCompile/vars-in-imports.exp.json
@@ -344,74 +344,6 @@
},
"zIndex": 0
},
- {
- "id": "vm",
- "id_val": "vm",
- "references": [
- {
- "key": {
- "range": "d2/testdata/d2compiler/TestCompile/template.d2,2:2:37-2:4:39",
- "path": [
- {
- "unquoted_string": {
- "range": "d2/testdata/d2compiler/TestCompile/template.d2,2:2:37-2:4:39",
- "value": [
- {
- "string": "vm",
- "raw_string": "vm"
- }
- ]
- }
- }
- ]
- },
- "key_path_index": 0,
- "map_key_edge_index": -1
- }
- ],
- "attributes": {
- "label": {
- "value": "My Virtual machine!"
- },
- "labelDimensions": {
- "width": 0,
- "height": 0
- },
- "style": {},
- "near_key": null,
- "shape": {
- "value": "rectangle"
- },
- "direction": {
- "value": ""
- },
- "constraint": null
- },
- "zIndex": 0
- },
- {
- "id": "env",
- "id_val": "env",
- "attributes": {
- "label": {
- "value": "env"
- },
- "labelDimensions": {
- "width": 0,
- "height": 0
- },
- "style": {},
- "near_key": null,
- "shape": {
- "value": "rectangle"
- },
- "direction": {
- "value": ""
- },
- "constraint": null
- },
- "zIndex": 0
- },
{
"id": "env",
"id_val": "env",
@@ -502,6 +434,51 @@
},
"zIndex": 0
},
+ {
+ "id": "vm",
+ "id_val": "vm",
+ "references": [
+ {
+ "key": {
+ "range": "d2/testdata/d2compiler/TestCompile/template.d2,2:2:37-2:4:39",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "d2/testdata/d2compiler/TestCompile/template.d2,2:2:37-2:4:39",
+ "value": [
+ {
+ "string": "vm",
+ "raw_string": "vm"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "key_path_index": 0,
+ "map_key_edge_index": -1
+ }
+ ],
+ "attributes": {
+ "label": {
+ "value": "My Virtual machine!"
+ },
+ "labelDimensions": {
+ "width": 0,
+ "height": 0
+ },
+ "style": {},
+ "near_key": null,
+ "shape": {
+ "value": "rectangle"
+ },
+ "direction": {
+ "value": ""
+ },
+ "constraint": null
+ },
+ "zIndex": 0
+ },
{
"id": "qa",
"id_val": "qa",
diff --git a/testdata/d2ir/TestCompile/imports/nested-scope.exp.json b/testdata/d2ir/TestCompile/imports/nested-scope.exp.json
new file mode 100644
index 000000000..8ed85fd1f
--- /dev/null
+++ b/testdata/d2ir/TestCompile/imports/nested-scope.exp.json
@@ -0,0 +1,244 @@
+{
+ "fields": [
+ {
+ "name": "elem",
+ "composite": {
+ "fields": [
+ {
+ "name": "third",
+ "composite": {
+ "fields": [
+ {
+ "name": "elem",
+ "references": [
+ {
+ "string": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ },
+ "key_path": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "edge": null,
+ "key": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "key": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "primary": {},
+ "value": {}
+ }
+ },
+ "due_to_glob": false,
+ "due_to_lazy_glob": false
+ }
+ ]
+ }
+ ],
+ "edges": null
+ },
+ "references": [
+ {
+ "string": {
+ "range": "third.d2,0:0:0-0:5:5",
+ "value": [
+ {
+ "string": "third",
+ "raw_string": "third"
+ }
+ ]
+ },
+ "key_path": {
+ "range": "third.d2,0:0:0-0:5:5",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "third.d2,0:0:0-0:5:5",
+ "value": [
+ {
+ "string": "third",
+ "raw_string": "third"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "edge": null,
+ "key": {
+ "range": "third.d2,0:0:0-2:1:17",
+ "key": {
+ "range": "third.d2,0:0:0-0:5:5",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "third.d2,0:0:0-0:5:5",
+ "value": [
+ {
+ "string": "third",
+ "raw_string": "third"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "primary": {},
+ "value": {
+ "map": {
+ "range": "third.d2,0:7:7-2:1:17",
+ "nodes": [
+ {
+ "map_key": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "key": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "third.d2,1:2:11-1:6:15",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "primary": {},
+ "value": {}
+ }
+ }
+ ]
+ }
+ }
+ }
+ },
+ "due_to_glob": false,
+ "due_to_lazy_glob": false
+ }
+ ]
+ }
+ ],
+ "edges": null
+ },
+ "references": [
+ {
+ "string": {
+ "range": "second.d2,0:0:0-0:4:4",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ },
+ "key_path": {
+ "range": "second.d2,0:0:0-0:4:4",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "second.d2,0:0:0-0:4:4",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "context": {
+ "edge": null,
+ "key": {
+ "range": "second.d2,0:0:0-2:1:21",
+ "key": {
+ "range": "second.d2,0:0:0-0:4:4",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "second.d2,0:0:0-0:4:4",
+ "value": [
+ {
+ "string": "elem",
+ "raw_string": "elem"
+ }
+ ]
+ }
+ }
+ ]
+ },
+ "primary": {},
+ "value": {
+ "map": {
+ "range": "second.d2,0:6:6-2:1:21",
+ "nodes": [
+ {
+ "import": {
+ "range": "second.d2,1:2:10-1:11:19",
+ "spread": true,
+ "pre": "",
+ "path": [
+ {
+ "unquoted_string": {
+ "range": "second.d2,1:6:14-1:11:19",
+ "value": [
+ {
+ "string": "third",
+ "raw_string": "third"
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ }
+ }
+ },
+ "due_to_glob": false,
+ "due_to_lazy_glob": false
+ }
+ ]
+ }
+ ],
+ "edges": null
+}