From e7e256656457bad08b4e6ccef9f14ffd8f165289 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 11:19:50 -0700 Subject: [PATCH] save --- d2compiler/compile_test.go | 2 - d2ir/compile.go | 3 + .../TestCompile2/vars/basic/combined.exp.json | 201 ++++++++++++++++++ 3 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 7638e9d22..096cc1cac 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3242,9 +3242,7 @@ hi: { }, }, { - // TODO: text before/after substitutions name: "combined", - skip: true, run: func(t *testing.T) { g := assertCompile(t, ` vars: { diff --git a/d2ir/compile.go b/d2ir/compile.go index bc5450f1e..b97362077 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -204,6 +204,7 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { } func (c *compiler) compileKey(refctx *RefContext) { + // resolve substitutions here if len(refctx.Key.Edges) == 0 { c.compileField(refctx.ScopeMap, refctx.Key.Key, refctx) } else { @@ -325,6 +326,8 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) parent: f, Value: refctx.Key.Value.ScalarBox().Unbox(), } + + // InterpolationBox within any of these values can be substitutions too } } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json new file mode 100644 index 000000000..f03a3b5ca --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json @@ -0,0 +1,201 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,0:0:0-5:0:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im a var", + "raw_string": "im a var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,4:0:25-4:12:37", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,4:0:25-4:2:27", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,4:4:29-4:12:37", + "value": [ + { + "string": "1 ", + "raw_string": "1 " + }, + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,4:6:31-4:10:35", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,4:8:33-4:9:34", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + }, + { + "string": " 2", + "raw_string": "1 2" + } + ] + } + } + } + } + ] + }, + "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": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/combined.d2,4:0:25-4:2:27", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "1 " + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +}