From 24f9150091fa758d898249288ed04077f27089cd Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 19 Sep 2024 08:57:33 -0600 Subject: [PATCH] d2ir: fix importing scopes --- d2compiler/compile.go | 3 + d2compiler/compile_test.go | 34 ++- d2ir/compile.go | 2 + d2ir/import.go | 11 +- d2ir/import_test.go | 17 ++ e2etests-cli/main_test.go | 24 ++ .../TestCLI_E2E/pptx-theme-overrides.exp.pptx | Bin 35191 -> 35190 bytes .../sequence-spread-layer/index.exp.svg | 95 +++++++ .../sequence-spread-layer/seq.exp.svg | 109 ++++++++ .../TestCompile/nested-scope-1.exp.json | 193 ++++++++++++++ .../TestCompile/nested-scope-2.exp.json | 216 ++++++++++++++++ .../TestCompile/nested-scope.exp.json | 193 ++++++++++++++ .../TestCompile/vars-in-imports.exp.json | 51 +--- .../TestCompile/imports/nested-scope.exp.json | 244 ++++++++++++++++++ 14 files changed, 1149 insertions(+), 43 deletions(-) create mode 100644 e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/index.exp.svg create mode 100644 e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/seq.exp.svg create mode 100644 testdata/d2compiler/TestCompile/nested-scope-1.exp.json create mode 100644 testdata/d2compiler/TestCompile/nested-scope-2.exp.json create mode 100644 testdata/d2compiler/TestCompile/nested-scope.exp.json create mode 100644 testdata/d2ir/TestCompile/imports/nested-scope.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 43be72f03d..b623d14a6b 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 fe842e2d96..d2ed43f19a 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 8fb31aad95..1e61d1d0fd 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 ef80d358cd..c415cf1385 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 d67f5950d5..10de29e2d2 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 973434261b..01dff0e6de 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 92f7a703a5c342d7411a28a577a6d7f00a0c1ae9..73d707ceaf2fb033078c5da76a3410cec92731f0 100644 GIT binary patch delta 472 zcmV;}0Vn?Vk^=UU0xFc5(6eG1F>#7-6!YVD>HR6S9t5{ux5j6Kbo`cL+> z*?oHyFL4{_jpNLG^LfTjw%12z$up#Eg5S}u<&=O|K^s5r=-2&i^MR6#(ramhhaEjZ zrq{#8Rz;ygg8LLABs7pO2qEO?tj|Kl9X%jM!B|!Ya5A?cf7NvTW zBe0(HOXdKjmMGaQZDO_3S6Z#AHa;a=Bw8`B;J{;MUE48QS%l>Bn+>JH)@En$6yZ&L zDXuz>*;II%rgqvCyyv`Q-|s$uDQh>z&sV2_4yARgl|X|Q25Ie&1bWMArULot=PyvW zLY7>GR04@14PMCte=PACP*FU>X$nba!d{v*WR*-r6Z~+WAcIFa2V?{fNg`-689b1i zo-}0MEepnUZ>1kw6T@2zqaofS&;X0Br-4VQ3t)BX-de1$u9lfS;53h*SXx OlTL{v248pp0000i58;Ra delta 464 zcmV;>0Wbdck^=XV0*}gz9586?gQ27zJZl9l*)lh6w)Xf9zvOPGW9D8d;R; zNshpJ&aapQlv<)>v$ToTO5bR;s@nLRY>{Ziz=8vhnRRW)Xk`(S%kMUn3R|0n|tyTgJS{S6Y-xKI9tCNh`@;>L4 zK$BxO;`}yC{*@`u{}9_ruRi{*7O zB@xDuPV=Rg)z*K=@GAfS|Nl@+2ME4aVP~MT0e12d1-@2cXP}e#h*SXylTC>u24Hvq G0000~iRL{3 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 0000000000..29a8a55da6 --- /dev/null +++ b/e2etests-cli/testdata/TestCLI_E2E/sequence-spread-layer/index.exp.svg @@ -0,0 +1,95 @@ +k + + + 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 0000000000..f8f8b973d1 --- /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 0000000000..711c990209 --- /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 0000000000..523843136a --- /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 0000000000..cfc5f33219 --- /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 fad97a8406..05c63f5e36 100644 --- a/testdata/d2compiler/TestCompile/vars-in-imports.exp.json +++ b/testdata/d2compiler/TestCompile/vars-in-imports.exp.json @@ -345,20 +345,20 @@ "zIndex": 0 }, { - "id": "vm", - "id_val": "vm", + "id": "env", + "id_val": "env", "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile/template.d2,2:2:37-2:4:39", + "range": "d2/testdata/d2compiler/TestCompile/template.d2,0:0:0-0:3:3", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/template.d2,2:2:37-2:4:39", + "range": "d2/testdata/d2compiler/TestCompile/template.d2,0:0:0-0:3:3", "value": [ { - "string": "vm", - "raw_string": "vm" + "string": "env", + "raw_string": "env" } ] } @@ -371,30 +371,7 @@ ], "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" + "value": "Qa Environment" }, "labelDimensions": { "width": 0, @@ -413,20 +390,20 @@ "zIndex": 0 }, { - "id": "env", - "id_val": "env", + "id": "vm", + "id_val": "vm", "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile/template.d2,0:0:0-0:3:3", + "range": "d2/testdata/d2compiler/TestCompile/template.d2,2:2:37-2:4:39", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile/template.d2,0:0:0-0:3:3", + "range": "d2/testdata/d2compiler/TestCompile/template.d2,2:2:37-2:4:39", "value": [ { - "string": "env", - "raw_string": "env" + "string": "vm", + "raw_string": "vm" } ] } @@ -439,7 +416,7 @@ ], "attributes": { "label": { - "value": "Qa Environment" + "value": "My Virtual machine!" }, "labelDimensions": { "width": 0, 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 0000000000..8ed85fd1f3 --- /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 +}