From c9793b9a87be4eb782f904fffedf14648edc4223 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 10 Jul 2023 19:24:21 -0700 Subject: [PATCH 01/40] label works --- d2ast/d2ast.go | 6 + d2compiler/compile.go | 23 +++ d2compiler/compile_test.go | 73 ++++++++ d2ir/compile.go | 81 +++++++++ d2parser/parse.go | 3 + .../TestCompile2/vars/basic/label.exp.json | 168 ++++++++++++++++++ .../TestCompile2/vars/errors/missing.exp.json | 11 ++ 7 files changed, 365 insertions(+) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/label.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json diff --git a/d2ast/d2ast.go b/d2ast/d2ast.go index a5be3fa98a..d49b1b268b 100644 --- a/d2ast/d2ast.go +++ b/d2ast/d2ast.go @@ -423,6 +423,7 @@ func (s *BlockString) value() {} func (a *Array) value() {} func (m *Map) value() {} func (i *Import) value() {} +func (i *Substitution) value() {} func (n *Null) scalar() {} func (b *Boolean) scalar() {} @@ -901,6 +902,7 @@ type ValueBox struct { Array *Array `json:"array,omitempty"` Map *Map `json:"map,omitempty"` Import *Import `json:"import,omitempty"` + Substitution *Substitution `json:"substitution,omitempty"` } func (vb ValueBox) Unbox() Value { @@ -925,6 +927,8 @@ func (vb ValueBox) Unbox() Value { return vb.Map case vb.Import != nil: return vb.Import + case vb.Substitution != nil: + return vb.Substitution default: return nil } @@ -953,6 +957,8 @@ func MakeValueBox(v Value) ValueBox { vb.Map = v case *Import: vb.Import = v + case *Substitution: + vb.Substitution = v } return vb } diff --git a/d2compiler/compile.go b/d2compiler/compile.go index fdb24e5513..4c11ac5ddf 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -1,6 +1,7 @@ package d2compiler import ( + "encoding/json" "encoding/xml" "fmt" "io" @@ -64,6 +65,8 @@ func compileIR(ast *d2ast.Map, m *d2ir.Map) (*d2graph.Graph, error) { g := d2graph.NewGraph() g.AST = ast c.compileBoard(g, m) + b, _ := json.MarshalIndent(m, "", " ") + println("\033[1;31m--- DEBUG:", string(b), "\033[m") if len(c.err.Errors) > 0 { return nil, c.err } @@ -277,6 +280,26 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { } } return + } else if f.Name == "vars" { + if f.Map() != nil { + if len(f.Map().Edges) > 0 { + c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") + } + // for _, varField := range f.Map().Fields { + // if varField.Map() != nil { + // c.errorf(varField.LastRef().AST(), "vars must be simple") + // } + // for _, cf := range classesField.Map().Fields { + // if _, ok := d2graph.ReservedKeywords[cf.Name]; !ok { + // c.errorf(cf.LastRef().AST(), "%s is an invalid class field, must be reserved keyword", cf.Name) + // } + // if cf.Name == "class" { + // c.errorf(cf.LastRef().AST(), `"class" cannot appear within "classes"`) + // } + // } + // } + } + return } else if isReserved { c.compileReserved(&obj.Attributes, f) return diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index f0dbaa1bbd..08fef43fd3 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -2744,6 +2744,7 @@ func TestCompile2(t *testing.T) { t.Run("boards", testBoards) t.Run("seqdiagrams", testSeqDiagrams) t.Run("nulls", testNulls) + t.Run("vars", testVars) } func testBoards(t *testing.T) { @@ -3168,6 +3169,78 @@ scenarios: { }) } +func testVars(t *testing.T) { + t.Parallel() + + t.Run("basic", func(t *testing.T) { + t.Parallel() + + tca := []struct { + name string + skip bool + run func(t *testing.T) + }{ + { + name: "label", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} +hi: ${x} +`, "") + assert.Equal(t, 1, len(g.Objects)) + assert.Equal(t, "im a var", g.Objects[0].Label.Value) + }, + }, + } + + for _, tc := range tca { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if tc.skip { + t.SkipNow() + } + tc.run(t) + }) + } + }) + + t.Run("errors", func(t *testing.T) { + t.Parallel() + + tca := []struct { + name string + skip bool + run func(t *testing.T) + }{ + { + name: "missing", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: hey +} +hi: ${z} +`, "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z") + }, + }, + } + + for _, tc := range tca { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if tc.skip { + t.SkipNow() + } + tc.run(t) + }) + } + }) +} + func assertCompile(t *testing.T, text string, expErr string) *d2graph.Graph { d2Path := fmt.Sprintf("d2/testdata/d2compiler/%v.d2", t.Name()) g, err := d2compiler.Compile(d2Path, strings.NewReader(text), nil) diff --git a/d2ir/compile.go b/d2ir/compile.go index f5d92d043d..27c11233bc 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -53,6 +53,8 @@ func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, error) { c.compileMap(m, ast, ast) c.compileClasses(m) + c.compileVars(m) + c.compileSubstitutions(m) if !c.err.Empty() { return nil, c.err } @@ -96,6 +98,81 @@ func (c *compiler) compileClasses(m *Map) { } } +func (c *compiler) compileSubstitutions(m *Map) { + vars := m.GetField("vars") + for _, f := range m.Fields { + // No substitutions within vars itself + if f.Name == "vars" { + continue + } + for _, ref := range f.References { + if ref.Context.Key != nil && ref.Context.Key.Value.Substitution != nil { + var resolved *Field + m := vars + for _, p := range ref.Context.Key.Value.Substitution.Path { + r := m.Map().GetField(p.Unbox().ScalarString()) + if r == nil { + resolved = nil + break + } + m = r + resolved = r + } + if resolved == nil { + c.errorf(ref.Context.Key, "could not resolve variable %s", strings.Join(ref.Context.Key.Value.Substitution.IDA(), ".")) + } else { + // TODO do i need this + // ref.Context.Key.Value = d2ast.MakeValueBox(resolved.Primary().Value) + + // TODO maps + f.Primary_ = &Scalar{ + parent: f, + Value: resolved.Primary().Value, + } + } + ref.Context.Key.Value.Substitution = nil + } + } + } +} + +func (c *compiler) compileVars(m *Map) { + vars := m.GetField("vars") + if vars == nil || vars.Map() == nil { + return + } + + layersField := m.GetField("layers") + if layersField == nil { + return + } + layers := layersField.Map() + if layers == nil { + return + } + + for _, lf := range layers.Fields { + if lf.Map() == nil || lf.Primary() != nil { + c.errorf(lf.References[0].Context.Key, "invalid layer") + continue + } + l := lf.Map() + lVars := l.GetField("vars") + + if lVars == nil { + lVars = vars.Copy(l).(*Field) + l.Fields = append(l.Fields, lVars) + } else { + base := vars.Copy(l).(*Field) + OverlayMap(base.Map(), lVars.Map()) + l.DeleteField("vars") + l.Fields = append(l.Fields, base) + } + + c.compileVars(l) + } +} + func (c *compiler) overlay(base *Map, f *Field) { if f.Map() == nil || f.Primary() != nil { c.errorf(f.References[0].Context.Key, "invalid %s", NodeBoardKind(f)) @@ -244,6 +321,10 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) c.compileClasses(f.Map()) } } + } else if refctx.Key.Value.Substitution != nil { + // b, _ := json.MarshalIndent(refctx.Key.Value.Substitution.IDA(), "", " ") + // println("\033[1;31m--- DEBUG:", string(b), "\033[m") + // println("\033[1;31m--- DEBUG:", "=======what===============", "\033[m") } else if refctx.Key.Value.ScalarBox().Unbox() != nil { // If the link is a board, we need to transform it into an absolute path. if f.Name == "link" { diff --git a/d2parser/parse.go b/d2parser/parse.go index fa64531a31..490505e4d2 100644 --- a/d2parser/parse.go +++ b/d2parser/parse.go @@ -1596,6 +1596,9 @@ func (p *parser) parseValue() d2ast.ValueBox { case '@': box.Import = p.parseImport(false) return box + case '$': + box.Substitution = p.parseSubstitution(false) + return box } p.replay(r) diff --git a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json new file mode 100644 index 0000000000..0270f685c5 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json @@ -0,0 +1,168 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,0:0:0-5:0:34", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.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/label.d2,4:0:25-4:8:33", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:0:25-4:2:27", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + }, + "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/label.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.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": "im a var" + }, + "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/TestCompile2/vars/errors/missing.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json new file mode 100644 index 0000000000..64d4957842 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2,4:0:20-4:8:28", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z" + } + ] + } +} From 05802edb07e19c4e23e61123df52c4b3eb4adafb Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 10 Jul 2023 21:18:18 -0700 Subject: [PATCH 02/40] edge label working --- d2compiler/compile.go | 3 - d2compiler/compile_test.go | 63 ++++ d2ir/compile.go | 105 ++++--- .../vars/basic/edge_label.exp.json | 285 ++++++++++++++++++ .../TestCompile2/vars/basic/label.exp.json | 20 +- .../TestCompile2/vars/override/label.exp.json | 239 +++++++++++++++ 6 files changed, 667 insertions(+), 48 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/override/label.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 4c11ac5ddf..9c27c14590 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -1,7 +1,6 @@ package d2compiler import ( - "encoding/json" "encoding/xml" "fmt" "io" @@ -65,8 +64,6 @@ func compileIR(ast *d2ast.Map, m *d2ir.Map) (*d2graph.Graph, error) { g := d2graph.NewGraph() g.AST = ast c.compileBoard(g, m) - b, _ := json.MarshalIndent(m, "", " ") - println("\033[1;31m--- DEBUG:", string(b), "\033[m") if len(c.err.Errors) > 0 { return nil, c.err } diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 08fef43fd3..bbd0b4e16c 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3193,6 +3193,69 @@ hi: ${x} assert.Equal(t, "im a var", g.Objects[0].Label.Value) }, }, + { + // TODO: text before/after substitutions + name: "combined", + skip: true, + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} +hi: 1 ${x} 2 +`, "") + assert.Equal(t, "1 im a var 2", g.Objects[0].Label.Value) + }, + }, + { + name: "edge label", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} +a -> b: ${x} +`, "") + assert.Equal(t, 1, len(g.Edges)) + assert.Equal(t, "im a var", g.Edges[0].Label.Value) + }, + }, + } + + for _, tc := range tca { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if tc.skip { + t.SkipNow() + } + tc.run(t) + }) + } + }) + + t.Run("override", func(t *testing.T) { + t.Parallel() + + tca := []struct { + name string + skip bool + run func(t *testing.T) + }{ + { + name: "label", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} +hi: ${x} +hi: not a var +`, "") + assert.Equal(t, 1, len(g.Objects)) + assert.Equal(t, "not a var", g.Objects[0].Label.Value) + }, + }, } for _, tc := range tca { diff --git a/d2ir/compile.go b/d2ir/compile.go index 27c11233bc..a19bda5678 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -52,16 +52,15 @@ func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, error) { defer c.popImportStack() c.compileMap(m, ast, ast) - c.compileClasses(m) - c.compileVars(m) - c.compileSubstitutions(m) + c.overlayClasses(m) + c.overlayVars(m) if !c.err.Empty() { return nil, c.err } return m, nil } -func (c *compiler) compileClasses(m *Map) { +func (c *compiler) overlayClasses(m *Map) { classes := m.GetField("classes") if classes == nil || classes.Map() == nil { return @@ -94,49 +93,49 @@ func (c *compiler) compileClasses(m *Map) { l.Fields = append(l.Fields, base) } - c.compileClasses(l) + c.overlayClasses(l) } } -func (c *compiler) compileSubstitutions(m *Map) { - vars := m.GetField("vars") - for _, f := range m.Fields { - // No substitutions within vars itself - if f.Name == "vars" { - continue +func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d2ast.Substitution) d2ast.Scalar { + var resolved *Field + for _, p := range substitution.Path { + if vars == nil { + resolved = nil + break } - for _, ref := range f.References { - if ref.Context.Key != nil && ref.Context.Key.Value.Substitution != nil { - var resolved *Field - m := vars - for _, p := range ref.Context.Key.Value.Substitution.Path { - r := m.Map().GetField(p.Unbox().ScalarString()) - if r == nil { - resolved = nil - break - } - m = r - resolved = r - } - if resolved == nil { - c.errorf(ref.Context.Key, "could not resolve variable %s", strings.Join(ref.Context.Key.Value.Substitution.IDA(), ".")) - } else { - // TODO do i need this - // ref.Context.Key.Value = d2ast.MakeValueBox(resolved.Primary().Value) + r := vars.GetField(p.Unbox().ScalarString()) + if r == nil { + resolved = nil + break + } + vars = r.Map() + resolved = r + } + if resolved == nil { + c.errorf(mk, "could not resolve variable %s", strings.Join(substitution.IDA(), ".")) + } else { + // TODO maps + return resolved.Primary().Value + } + return nil +} - // TODO maps - f.Primary_ = &Scalar{ - parent: f, - Value: resolved.Primary().Value, - } - } - ref.Context.Key.Value.Substitution = nil - } +func (c *compiler) compileVars(m *Map, ast *d2ast.Map) { + for _, n := range ast.Nodes { + if n.MapKey != nil && n.MapKey.Key != nil && len(n.MapKey.Key.Path) == 1 && strings.EqualFold(n.MapKey.Key.Path[0].Unbox().ScalarString(), "vars") { + c.compileKey(&RefContext{ + Key: n.MapKey, + Scope: ast, + ScopeMap: m, + ScopeAST: ast, + }) + break } } } -func (c *compiler) compileVars(m *Map) { +func (c *compiler) overlayVars(m *Map) { vars := m.GetField("vars") if vars == nil || vars.Map() == nil { return @@ -169,7 +168,7 @@ func (c *compiler) compileVars(m *Map) { l.Fields = append(l.Fields, base) } - c.compileVars(l) + c.overlayVars(l) } } @@ -184,6 +183,10 @@ func (c *compiler) overlay(base *Map, f *Field) { } func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { + // When compiling a new board, compile vars before all else, as it might be referenced + if NodeBoardKind(dst) != "" { + c.compileVars(dst, ast) + } for _, n := range ast.Nodes { switch { case n.MapKey != nil: @@ -279,7 +282,7 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) c.compileMap(f.Map(), refctx.Key.Value.Map, scopeAST) switch NodeBoardKind(f) { case BoardScenario, BoardStep: - c.compileClasses(f.Map()) + c.overlayClasses(f.Map()) } } else if refctx.Key.Value.Import != nil { n, ok := c._import(refctx.Key.Value.Import) @@ -318,13 +321,18 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) c.updateLinks(f.Map()) switch NodeBoardKind(f) { case BoardScenario, BoardStep: - c.compileClasses(f.Map()) + c.overlayClasses(f.Map()) } } } else if refctx.Key.Value.Substitution != nil { - // b, _ := json.MarshalIndent(refctx.Key.Value.Substitution.IDA(), "", " ") - // println("\033[1;31m--- DEBUG:", string(b), "\033[m") - // println("\033[1;31m--- DEBUG:", "=======what===============", "\033[m") + vars := ParentBoard(f).Map().GetField("vars") + resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution) + if resolved != nil { + f.Primary_ = &Scalar{ + parent: f, + Value: resolved, + } + } } else if refctx.Key.Value.ScalarBox().Unbox() != nil { // If the link is a board, we need to transform it into an absolute path. if f.Name == "link" { @@ -502,6 +510,15 @@ func (c *compiler) compileEdges(refctx *RefContext) { } } c.compileMap(e.Map_, refctx.Key.Value.Map, refctx.ScopeAST) + } else if refctx.Key.Value.Substitution != nil { + vars := ParentBoard(e).Map().GetField("vars") + resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution) + if resolved != nil { + e.Primary_ = &Scalar{ + parent: e, + Value: resolved, + } + } } else if refctx.Key.Value.ScalarBox().Unbox() != nil { e.Primary_ = &Scalar{ parent: e, diff --git a/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json new file mode 100644 index 0000000000..55c12d65df --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json @@ -0,0 +1,285 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,0:0:0-5:0:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.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/edge_label.d2,4:0:25-4:12:37", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:0:25-4:6:31", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:0:25-4:1:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:0:25-4:1:26", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:5:30-4:6:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:5:30-4:6:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:8:33-4:12:37", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:10:35-4:11:36", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "im a var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:0:25-4:1:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:0:25-4:1:26", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:5:30-4:6:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:5:30-4:6:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "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/TestCompile2/vars/basic/label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json index 0270f685c5..41f1864aed 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json @@ -87,7 +87,25 @@ ] }, "primary": {}, - "value": {} + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:4:29-4:8:33", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:6:31-4:7:32", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } } } ] diff --git a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json new file mode 100644 index 0000000000..585e192ee3 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json @@ -0,0 +1,239 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,0:0:0-6:0:48", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.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/override/label.d2,4:0:25-4:8:33", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:0:25-4:2:27", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:4:29-4:8:33", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:6:31-4:7:32", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,5:0:34-5:13:47", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,5:0:34-5:2:36", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,5:0:34-5:2:36", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,5:4:38-5:13:47", + "value": [ + { + "string": "not a var", + "raw_string": "not a var" + } + ] + } + } + } + } + ] + }, + "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/override/label.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:0:25-4:2:27", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,5:0:34-5:2:36", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,5:0:34-5:2:36", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "not a var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} From fd70b5ef4627cc36572fae3ce07a5c1027a73bb2 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 10 Jul 2023 21:32:30 -0700 Subject: [PATCH 03/40] layers work --- d2compiler/compile_test.go | 40 ++ d2ir/compile.go | 44 +-- .../TestCompile2/vars/boards/layer.exp.json | 372 ++++++++++++++++++ 3 files changed, 425 insertions(+), 31 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index bbd0b4e16c..eb33cf1a47 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3270,6 +3270,46 @@ hi: not a var } }) + t.Run("boards", func(t *testing.T) { + t.Parallel() + + tca := []struct { + name string + skip bool + run func(t *testing.T) + }{ + { + name: "layer", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} + +layers: { + l: { + hi: ${x} + } +} +`, "") + assert.Equal(t, 1, len(g.Layers[0].Objects)) + assert.Equal(t, "im a var", g.Layers[0].Objects[0].Label.Value) + }, + }, + } + + for _, tc := range tca { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if tc.skip { + t.SkipNow() + } + tc.run(t) + }) + } + }) + t.Run("errors", func(t *testing.T) { t.Parallel() diff --git a/d2ir/compile.go b/d2ir/compile.go index a19bda5678..bf5d91d8b2 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -53,7 +53,6 @@ func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, error) { c.compileMap(m, ast, ast) c.overlayClasses(m) - c.overlayVars(m) if !c.err.Empty() { return nil, c.err } @@ -135,40 +134,22 @@ func (c *compiler) compileVars(m *Map, ast *d2ast.Map) { } } -func (c *compiler) overlayVars(m *Map) { - vars := m.GetField("vars") - if vars == nil || vars.Map() == nil { +func (c *compiler) overlayVars(base, overlay *Map) { + vars := overlay.GetField("vars") + if vars == nil { return } - layersField := m.GetField("layers") - if layersField == nil { - return - } - layers := layersField.Map() - if layers == nil { - return - } - - for _, lf := range layers.Fields { - if lf.Map() == nil || lf.Primary() != nil { - c.errorf(lf.References[0].Context.Key, "invalid layer") - continue - } - l := lf.Map() - lVars := l.GetField("vars") + lVars := base.GetField("vars") - if lVars == nil { - lVars = vars.Copy(l).(*Field) - l.Fields = append(l.Fields, lVars) - } else { - base := vars.Copy(l).(*Field) - OverlayMap(base.Map(), lVars.Map()) - l.DeleteField("vars") - l.Fields = append(l.Fields, base) - } - - c.overlayVars(l) + if lVars == nil { + lVars = vars.Copy(base).(*Field) + base.Fields = append(base.Fields, lVars) + } else { + overlayed := vars.Copy(base).(*Field) + OverlayMap(overlayed.Map(), lVars.Map()) + base.DeleteField("vars") + base.Fields = append(base.Fields, overlayed) } } @@ -275,6 +256,7 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) } } case BoardLayer: + c.overlayVars(f.Map(), ParentBoard(f).Map()) default: // If new board type, use that as the new scope AST, otherwise, carry on scopeAST = refctx.ScopeAST diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json new file mode 100644 index 0000000000..a336caf0b8 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json @@ -0,0 +1,372 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,0:0:0-10:0:62", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.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/boards/layer.d2,5:0:26-9:1:61", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,5:0:26-5:6:32", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,5:0:26-5:6:32", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,5:8:34-9:1:61", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,6:2:38-8:3:59", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,6:2:38-6:3:39", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,6:2:38-6:3:39", + "value": [ + { + "string": "l", + "raw_string": "l" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,6:5:41-8:3:59", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:4:47-7:12:55", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:4:47-7:6:49", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:4:47-7:6:49", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:12:55", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:10:53-7:11:54", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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, + "layers": [ + { + "name": "l", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im a var", + "raw_string": "im a var" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hi" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im a var", + "raw_string": "im a var" + } + ] + } + }, + "value": {} + } + } + ] + }, + "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/boards/layer.d2,7:4:47-7:6:49", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:4:47-7:6:49", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im a var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} From 7269ee170630968027d5d6e041e940cb05aa40ca Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 10 Jul 2023 21:54:34 -0700 Subject: [PATCH 04/40] add overlay tests --- d2compiler/compile_test.go | 53 + .../TestCompile2/vars/boards/overlay.exp.json | 1069 +++++++++++++++++ .../vars/boards/scenario.exp.json | 372 ++++++ 3 files changed, 1494 insertions(+) create mode 100644 testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index eb33cf1a47..8c28c3a2a9 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3296,6 +3296,59 @@ layers: { assert.Equal(t, "im a var", g.Layers[0].Objects[0].Label.Value) }, }, + { + name: "scenario", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} + +scenarios: { + l: { + hi: ${x} + } +} +`, "") + assert.Equal(t, 1, len(g.Scenarios[0].Objects)) + assert.Equal(t, "im a var", g.Scenarios[0].Objects[0].Label.Value) + }, + }, + { + name: "overlay", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im x var +} + +scenarios: { + l: { + vars: { + y: im y var + } + x: ${x} + y: ${y} + } +} +layers: { + l2: { + vars: { + y: im y var + } + x: ${x} + y: ${y} + } +} +`, "") + assert.Equal(t, 2, len(g.Scenarios[0].Objects)) + assert.Equal(t, "im x var", g.Scenarios[0].Objects[0].Label.Value) + assert.Equal(t, "im y var", g.Scenarios[0].Objects[1].Label.Value) + assert.Equal(t, 2, len(g.Layers[0].Objects)) + assert.Equal(t, "im x var", g.Layers[0].Objects[0].Label.Value) + assert.Equal(t, "im y var", g.Layers[0].Objects[1].Label.Value) + }, + }, } for _, tc := range tca { diff --git a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json new file mode 100644 index 0000000000..a256b8aabd --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json @@ -0,0 +1,1069 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,0:0:0-23:0:196", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im x var", + "raw_string": "im x var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,5:0:26-13:1:111", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,5:0:26-5:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,5:0:26-5:9:35", + "value": [ + { + "string": "scenarios", + "raw_string": "scenarios" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,5:11:37-13:1:111", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,6:2:41-12:3:109", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,6:2:41-6:3:42", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,6:2:41-6:3:42", + "value": [ + { + "string": "l", + "raw_string": "l" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,6:5:44-12:3:109", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,7:4:50-9:5:81", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,7:4:50-7:8:54", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,7:4:50-7:8:54", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,7:10:56-9:5:81", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:6:64-8:17:75", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:6:64-8:7:65", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:6:64-8:7:65", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", + "value": [ + { + "string": "im y var", + "raw_string": "im y var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:4:86-10:11:93", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:4:86-10:5:87", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:4:86-10:5:87", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:11:93", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:9:91-10:10:92", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:4:98-11:11:105", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:4:98-11:5:99", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:4:98-11:5:99", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:11:105", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:9:103-11:10:104", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,14:0:112-22:1:195", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,14:0:112-14:6:118", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,14:0:112-14:6:118", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,14:8:120-22:1:195", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,15:2:124-21:3:193", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,15:2:124-15:4:126", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,15:2:124-15:4:126", + "value": [ + { + "string": "l2", + "raw_string": "l2" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,15:6:128-21:3:193", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,16:4:134-18:5:165", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,16:4:134-16:8:138", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,16:4:134-16:8:138", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,16:10:140-18:5:165", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:6:148-17:17:159", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:6:148-17:7:149", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:6:148-17:7:149", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", + "value": [ + { + "string": "im y var", + "raw_string": "im y var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:4:170-19:11:177", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:4:170-19:5:171", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:4:170-19:5:171", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:11:177", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:9:175-19:10:176", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:4:182-20:11:189", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:4:182-20:5:183", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:4:182-20:5:183", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:11:189", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:9:187-20:10:188", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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, + "layers": [ + { + "name": "l2", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im x var", + "raw_string": "im x var" + } + ] + } + }, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "y" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", + "value": [ + { + "string": "im y var", + "raw_string": "im y var" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im x var", + "raw_string": "im x var" + } + ] + } + }, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "y" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", + "value": [ + { + "string": "im y var", + "raw_string": "im y var" + } + ] + } + }, + "value": {} + } + } + ] + }, + "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": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:4:170-19:5:171", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:4:170-19:5:171", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im x var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:4:182-20:5:183", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:4:182-20:5:183", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im y var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ], + "scenarios": [ + { + "name": "l", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im x var", + "raw_string": "im x var" + } + ] + } + }, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "y" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", + "value": [ + { + "string": "im y var", + "raw_string": "im y var" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im x var", + "raw_string": "im x var" + } + ] + } + }, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "y" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", + "value": [ + { + "string": "im y var", + "raw_string": "im y var" + } + ] + } + }, + "value": {} + } + } + ] + }, + "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": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:4:86-10:5:87", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:4:86-10:5:87", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im x var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:4:98-11:5:99", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:4:98-11:5:99", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im y var" + }, + "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/TestCompile2/vars/boards/scenario.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json new file mode 100644 index 0000000000..a4b99e65d8 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json @@ -0,0 +1,372 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,0:0:0-10:0:65", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.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/boards/scenario.d2,5:0:26-9:1:64", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,5:0:26-5:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,5:0:26-5:9:35", + "value": [ + { + "string": "scenarios", + "raw_string": "scenarios" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,5:11:37-9:1:64", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,6:2:41-8:3:62", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,6:2:41-6:3:42", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,6:2:41-6:3:42", + "value": [ + { + "string": "l", + "raw_string": "l" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,6:5:44-8:3:62", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:12:58", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:6:52", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:6:52", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:12:58", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:10:56-7:11:57", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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, + "scenarios": [ + { + "name": "l", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im a var", + "raw_string": "im a var" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hi" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im a var", + "raw_string": "im a var" + } + ] + } + }, + "value": {} + } + } + ] + }, + "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/boards/scenario.d2,7:4:50-7:6:52", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:4:50-7:6:52", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im a var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} From acdbfddf239fb52dacb51e5fd8d618d80ab97310 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 10 Jul 2023 21:55:49 -0700 Subject: [PATCH 05/40] add replace tests --- d2compiler/compile_test.go | 31 + .../TestCompile2/vars/boards/replace.exp.json | 769 ++++++++++++++++++ 2 files changed, 800 insertions(+) create mode 100644 testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 8c28c3a2a9..83ba27c336 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3349,6 +3349,37 @@ layers: { assert.Equal(t, "im y var", g.Layers[0].Objects[1].Label.Value) }, }, + { + name: "replace", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im x var +} + +scenarios: { + l: { + vars: { + x: im replaced x var + } + x: ${x} + } +} +layers: { + l2: { + vars: { + x: im replaced x var + } + x: ${x} + } +} +`, "") + assert.Equal(t, 1, len(g.Scenarios[0].Objects)) + assert.Equal(t, "im replaced x var", g.Scenarios[0].Objects[0].Label.Value) + assert.Equal(t, 1, len(g.Layers[0].Objects)) + assert.Equal(t, "im replaced x var", g.Layers[0].Objects[0].Label.Value) + }, + }, } for _, tc := range tca { diff --git a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json new file mode 100644 index 0000000000..a5a4d56e96 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json @@ -0,0 +1,769 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,0:0:0-21:0:190", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im x var", + "raw_string": "im x var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,5:0:26-12:1:108", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,5:0:26-5:9:35", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,5:0:26-5:9:35", + "value": [ + { + "string": "scenarios", + "raw_string": "scenarios" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,5:11:37-12:1:108", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,6:2:41-11:3:106", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,6:2:41-6:3:42", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,6:2:41-6:3:42", + "value": [ + { + "string": "l", + "raw_string": "l" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,6:5:44-11:3:106", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,7:4:50-9:5:90", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,7:4:50-7:8:54", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,7:4:50-7:8:54", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,7:10:56-9:5:90", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:6:64-8:26:84", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:6:64-8:7:65", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:6:64-8:7:65", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", + "value": [ + { + "string": "im replaced x var", + "raw_string": "im replaced x var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:4:95-10:11:102", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:4:95-10:5:96", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:4:95-10:5:96", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:11:102", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:9:100-10:10:101", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,13:0:109-20:1:189", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,13:0:109-13:6:115", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,13:0:109-13:6:115", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,13:8:117-20:1:189", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,14:2:121-19:3:187", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,14:2:121-14:4:123", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,14:2:121-14:4:123", + "value": [ + { + "string": "l2", + "raw_string": "l2" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,14:6:125-19:3:187", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,15:4:131-17:5:171", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,15:4:131-15:8:135", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,15:4:131-15:8:135", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,15:10:137-17:5:171", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:6:145-16:26:165", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:6:145-16:7:146", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:6:145-16:7:146", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:9:148-16:26:165", + "value": [ + { + "string": "im replaced x var", + "raw_string": "im replaced x var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:11:183", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:5:177", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:5:177", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:7:179-18:11:183", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:9:181-18:10:182", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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, + "layers": [ + { + "name": "l2", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:9:148-16:26:165", + "value": [ + { + "string": "im replaced x var", + "raw_string": "im replaced x var" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:9:148-16:26:165", + "value": [ + { + "string": "im replaced x var", + "raw_string": "im replaced x var" + } + ] + } + }, + "value": {} + } + } + ] + }, + "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": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:5:177", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:5:177", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im replaced x var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ], + "scenarios": [ + { + "name": "l", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", + "value": [ + { + "string": "im replaced x var", + "raw_string": "im replaced x var" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", + "value": [ + { + "string": "im replaced x var", + "raw_string": "im replaced x var" + } + ] + } + }, + "value": {} + } + } + ] + }, + "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": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:4:95-10:5:96", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:4:95-10:5:96", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im replaced x var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} From 0347dff7a4ca79e6cb45611fdaf3b4d3632df326 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 10 Jul 2023 22:02:58 -0700 Subject: [PATCH 06/40] more tests --- d2compiler/compile_test.go | 48 +++ .../TestCompile2/vars/basic/nested.exp.json | 310 ++++++++++++++++++ .../TestCompile2/vars/basic/number.exp.json | 282 ++++++++++++++++ .../TestCompile2/vars/basic/style.exp.json | 230 +++++++++++++ 4 files changed, 870 insertions(+) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/number.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/style.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 83ba27c336..f6518d0fa2 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3193,6 +3193,54 @@ hi: ${x} assert.Equal(t, "im a var", g.Objects[0].Label.Value) }, }, + { + name: "style", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + primary-color: red +} +hi: { + style.fill: ${primary-color} +} +`, "") + assert.Equal(t, 1, len(g.Objects)) + assert.Equal(t, "red", g.Objects[0].Style.Fill.Value) + }, + }, + { + name: "number", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + columns: 2 +} +hi: { + grid-columns: ${columns} + x +} +`, "") + assert.Equal(t, "2", g.Objects[0].GridColumns.Value) + }, + }, + { + name: "nested", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + colors: { + primary: { + button: red + } + } +} +hi: { + style.fill: ${colors.primary.button} +} +`, "") + assert.Equal(t, "red", g.Objects[0].Style.Fill.Value) + }, + }, { // TODO: text before/after substitutions name: "combined", diff --git a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json new file mode 100644 index 0000000000..b0bc434b44 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json @@ -0,0 +1,310 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,0:0:0-11:0:112", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,1:0:1-7:1:64", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,1:6:7-7:1:64", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,2:1:10-6:3:62", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,2:1:10-2:7:16", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,2:1:10-2:7:16", + "value": [ + { + "string": "colors", + "raw_string": "colors" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,2:9:18-6:3:62", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,3:4:24-5:5:58", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,3:4:24-3:11:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,3:4:24-3:11:31", + "value": [ + { + "string": "primary", + "raw_string": "primary" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,3:13:33-5:5:58", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:6:41-4:17:52", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:6:41-4:12:47", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:6:41-4:12:47", + "value": [ + { + "string": "button", + "raw_string": "button" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:14:49-4:17:52", + "value": [ + { + "string": "red", + "raw_string": "red" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,8:0:65-10:1:111", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,8:0:65-8:2:67", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,8:0:65-8:2:67", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,8:4:69-10:1:111", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:2:73-9:38:109", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:2:73-9:12:83", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:2:73-9:7:78", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:8:79-9:12:83", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:38:109", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:16:87-9:22:93", + "value": [ + { + "string": "colors", + "raw_string": "colors" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:23:94-9:30:101", + "value": [ + { + "string": "primary", + "raw_string": "primary" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:31:102-9:37:108", + "value": [ + { + "string": "button", + "raw_string": "button" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/nested.d2,8:0:65-8:2:67", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,8:0:65-8:2:67", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "red" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json new file mode 100644 index 0000000000..b9898d3207 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json @@ -0,0 +1,282 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,0:0:0-8:0:60", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,1:0:1-3:1:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,1:6:7-3:1:22", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:1:10-2:11:20", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:1:10-2:8:17", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:1:10-2:8:17", + "value": [ + { + "string": "columns", + "raw_string": "columns" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:10:19-2:11:20", + "raw": "2", + "value": "2" + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,4:0:23-7:1:59", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,4:0:23-4:2:25", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,4:0:23-4:2:25", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,4:4:27-7:1:59", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:1:30-5:25:54", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:1:30-5:13:42", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:1:30-5:13:42", + "value": [ + { + "string": "grid-columns", + "raw_string": "grid-columns" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:25:54", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:17:46-5:24:53", + "value": [ + { + "string": "columns", + "raw_string": "columns" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,6:1:56-6:2:57", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,6:1:56-6:2:57", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,6:1:56-6:2:57", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "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/number.d2,4:0:23-4:2:25", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,4:0:23-4:2:25", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null, + "gridColumns": { + "value": "2" + } + }, + "zIndex": 0 + }, + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,6:1:56-6:2:57", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,6:1:56-6:2:57", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "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/TestCompile2/vars/basic/style.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json new file mode 100644 index 0000000000..6925d574c3 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json @@ -0,0 +1,230 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,0:0:0-7:0:71", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,1:0:1-3:1:31", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,1:6:7-3:1:31", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:2:11-2:20:29", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:2:11-2:15:24", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:2:11-2:15:24", + "value": [ + { + "string": "primary-color", + "raw_string": "primary-color" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:17:26-2:20:29", + "value": [ + { + "string": "red", + "raw_string": "red" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,4:0:32-6:1:70", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,4:0:32-4:2:34", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,4:0:32-4:2:34", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,4:4:36-6:1:70", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:2:40-5:30:68", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:2:40-5:12:50", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:2:40-5:7:45", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:8:46-5:12:50", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:30:68", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:16:54-5:29:67", + "value": [ + { + "string": "primary-color", + "raw_string": "primary-color" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/style.d2,4:0:32-4:2:34", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,4:0:32-4:2:34", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "red" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} From 08cc907f07fe81fee5e974042553ffc62e261276 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Mon, 10 Jul 2023 22:22:04 -0700 Subject: [PATCH 07/40] more test --- d2compiler/compile_test.go | 11 + d2ir/compile.go | 5 +- d2ir/import_test.go | 11 + .../d2ir/TestCompile/imports/vars/1.exp.json | 392 ++++++++++++++++++ 4 files changed, 417 insertions(+), 2 deletions(-) create mode 100644 testdata/d2ir/TestCompile/imports/vars/1.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index f6518d0fa2..7638e9d22d 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3458,6 +3458,17 @@ vars: { x: hey } hi: ${z} +`, "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z") + }, + }, + { + name: "key", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: hey +} +${x} `, "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z") }, }, diff --git a/d2ir/compile.go b/d2ir/compile.go index bf5d91d8b2..bc5450f1e0 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -170,6 +170,9 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { } for _, n := range ast.Nodes { switch { + case n.Substitution != nil: + println("\033[1;31m--- DEBUG:", "=======================", "\033[m") + c.errorf(n.Substitution, "only values can use substitutions") case n.MapKey != nil: c.compileKey(&RefContext{ Key: n.MapKey, @@ -196,8 +199,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { } } } - case n.Substitution != nil: - panic("TODO") } } } diff --git a/d2ir/import_test.go b/d2ir/import_test.go index 38b3a3a2cd..c04cb6a25d 100644 --- a/d2ir/import_test.go +++ b/d2ir/import_test.go @@ -138,6 +138,17 @@ label: meow`, assertQuery(t, m, 0, 0, nil, "q.jon") }, }, + { + name: "vars/1", + run: func(t testing.TB) { + m, err := compileFS(t, "index.d2", map[string]string{ + "index.d2": "vars: { ...@x }; q: ${meow}", + "x.d2": "meow: var replaced", + }) + assert.Success(t, err) + assertQuery(t, m, 0, 0, "var replaced", "q") + }, + }, } runa(t, tca) diff --git a/testdata/d2ir/TestCompile/imports/vars/1.exp.json b/testdata/d2ir/TestCompile/imports/vars/1.exp.json new file mode 100644 index 0000000000..de94a458d1 --- /dev/null +++ b/testdata/d2ir/TestCompile/imports/vars/1.exp.json @@ -0,0 +1,392 @@ +{ + "fields": [ + { + "name": "vars", + "composite": { + "fields": [ + { + "name": "meow", + "primary": { + "value": { + "range": "x.d2,0:6:6-0:18:18", + "value": [ + { + "string": "var replaced", + "raw_string": "var replaced" + } + ] + } + }, + "references": [ + { + "string": { + "range": "x.d2,0:0:0-0:4:4", + "value": [ + { + "string": "meow", + "raw_string": "meow" + } + ] + }, + "key_path": { + "range": "x.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "x.d2,0:0:0-0:4:4", + "value": [ + { + "string": "meow", + "raw_string": "meow" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "x.d2,0:0:0-0:18:18", + "key": { + "range": "x.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "x.d2,0:0:0-0:4:4", + "value": [ + { + "string": "meow", + "raw_string": "meow" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "x.d2,0:6:6-0:18:18", + "value": [ + { + "string": "var replaced", + "raw_string": "var replaced" + } + ] + } + } + } + } + }, + { + "string": { + "range": "x.d2,0:0:0-0:4:4", + "value": [ + { + "string": "meow", + "raw_string": "meow" + } + ] + }, + "key_path": { + "range": "x.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "x.d2,0:0:0-0:4:4", + "value": [ + { + "string": "meow", + "raw_string": "meow" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "x.d2,0:0:0-0:18:18", + "key": { + "range": "x.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "x.d2,0:0:0-0:4:4", + "value": [ + { + "string": "meow", + "raw_string": "meow" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "x.d2,0:6:6-0:18:18", + "value": [ + { + "string": "var replaced", + "raw_string": "var replaced" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + }, + "key_path": { + "range": "index.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:0:0-0:15:15", + "key": { + "range": "index.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "index.d2,0:6:6-0:15:15", + "nodes": [ + { + "import": { + "range": "index.d2,0:8:8-0:14:14", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:12:12-0:13:13", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + }, + { + "string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + }, + "key_path": { + "range": "index.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:0:0-0:15:15", + "key": { + "range": "index.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "index.d2,0:6:6-0:15:15", + "nodes": [ + { + "import": { + "range": "index.d2,0:8:8-0:14:14", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:12:12-0:13:13", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + } + ] + }, + { + "name": "q", + "primary": { + "value": { + "range": "x.d2,0:6:6-0:18:18", + "value": [ + { + "string": "var replaced", + "raw_string": "var replaced" + } + ] + } + }, + "references": [ + { + "string": { + "range": "index.d2,0:17:17-0:18:18", + "value": [ + { + "string": "q", + "raw_string": "q" + } + ] + }, + "key_path": { + "range": "index.d2,0:17:17-0:18:18", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:17:17-0:18:18", + "value": [ + { + "string": "q", + "raw_string": "q" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:17:17-0:27:27", + "key": { + "range": "index.d2,0:17:17-0:18:18", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:17:17-0:18:18", + "value": [ + { + "string": "q", + "raw_string": "q" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "substitution": { + "range": "index.d2,0:20:20-0:27:27", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:22:22-0:26:26", + "value": [ + { + "string": "meow", + "raw_string": "meow" + } + ] + } + } + ] + } + } + } + } + } + ] + } + ], + "edges": null +} From e7e256656457bad08b4e6ccef9f14ffd8f165289 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 11:19:50 -0700 Subject: [PATCH 08/40] 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 7638e9d22d..096cc1cacb 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 bc5450f1e0..b97362077a 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 0000000000..f03a3b5cac --- /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 +} From 090d10e9cae3a7cd83f72453de9dabf09679aeac Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 13:32:07 -0700 Subject: [PATCH 09/40] handle interpolation --- d2ast/d2ast.go | 22 ++ d2compiler/compile_test.go | 45 ++- d2ir/compile.go | 82 +++- .../TestCompile/array-classes.exp.json | 15 +- .../TestCompile/basic_icon.exp.json | 3 +- .../TestCompile/basic_sequence.exp.json | 3 +- .../TestCompile/basic_shape.exp.json | 3 +- .../TestCompile/class-shape-class.exp.json | 9 +- .../TestCompile/class_paren.exp.json | 9 +- .../TestCompile/class_style.exp.json | 6 +- .../d2compiler/TestCompile/classes.exp.json | 33 +- .../dimensions_on_containers.exp.json | 24 +- .../dimensions_on_nonimage.exp.json | 3 +- .../edge_arrowhead_fields.exp.json | 6 +- .../edge_arrowhead_primary.exp.json | 3 +- .../TestCompile/edge_chain.exp.json | 3 +- .../TestCompile/edge_chain_map.exp.json | 3 +- .../TestCompile/edge_column_index.exp.json | 18 +- .../TestCompile/edge_flat_arrowhead.exp.json | 3 +- .../edge_flat_label_arrowhead.exp.json | 3 +- .../TestCompile/edge_index.exp.json | 6 +- .../TestCompile/edge_index_map.exp.json | 3 +- .../TestCompile/edge_index_nested.exp.json | 6 +- .../edge_index_nested_cross_scope.exp.json | 6 +- .../d2compiler/TestCompile/edge_map.exp.json | 3 +- .../TestCompile/edge_map_arrowhead.exp.json | 3 +- .../TestCompile/edge_mixed_arrowhead.exp.json | 6 +- .../edge_non_shape_arrowhead.exp.json | 3 +- .../edge_semiflat_arrowhead.exp.json | 3 +- .../TestCompile/fill-pattern.exp.json | 3 +- .../icon-near-composite-together.exp.json | 3 +- .../TestCompile/image_style.exp.json | 9 +- .../label-near-composite-separate.exp.json | 6 +- .../label-near-composite-together.exp.json | 3 +- .../TestCompile/label-near-parent.exp.json | 3 +- .../TestCompile/link-board-mixed.exp.json | 18 +- .../TestCompile/missing-class.exp.json | 3 +- .../TestCompile/near_constant.exp.json | 3 +- .../TestCompile/nested-array-classes.exp.json | 3 +- .../TestCompile/nested_sql.exp.json | 9 +- .../d2compiler/TestCompile/path_link.exp.json | 3 +- .../TestCompile/reordered-classes.exp.json | 9 +- .../reserved_icon_near_style.exp.json | 12 +- .../TestCompile/root_direction.exp.json | 3 +- .../TestCompile/root_sequence.exp.json | 3 +- .../TestCompile/sequence-timestamp.exp.json | 3 +- .../TestCompile/sequence_container.exp.json | 3 +- .../TestCompile/sequence_container_2.exp.json | 3 +- .../sequence_grouped_note.exp.json | 3 +- .../TestCompile/sequence_scoping.exp.json | 3 +- .../TestCompile/set_direction.exp.json | 3 +- .../single_dimension_on_circle.exp.json | 3 +- .../TestCompile/sql-constraints.exp.json | 6 +- .../TestCompile/sql-regression.exp.json | 6 +- .../d2compiler/TestCompile/sql_paren.exp.json | 9 +- .../table_connection_attr.exp.json | 6 +- .../TestCompile/table_style.exp.json | 6 +- .../TestCompile/table_style_map.exp.json | 9 +- .../TestCompile/text-transform.exp.json | 12 +- .../underscore_edge_existing.exp.json | 6 +- .../underscore_edge_index.exp.json | 6 +- .../underscore_parent_preference_1.exp.json | 6 +- .../underscore_parent_preference_2.exp.json | 6 +- .../d2compiler/TestCompile/url_link.exp.json | 3 +- ..._and_not_url_tooltip_concurrently.exp.json | 6 +- .../url_link_non_url_tooltip_ok.exp.json | 6 +- .../TestCompile/url_tooltip.exp.json | 3 +- .../TestCompile/wrong_column_index.exp.json | 33 +- .../TestCompile2/boards/isFolderOnly.exp.json | 9 +- .../TestCompile2/vars/basic/combined.exp.json | 31 +- .../vars/basic/double-quoted.exp.json | 176 +++++++++ .../vars/basic/edge_label.exp.json | 20 +- .../TestCompile2/vars/basic/label.exp.json | 20 +- .../TestCompile2/vars/basic/nested.exp.json | 42 +- .../TestCompile2/vars/basic/number.exp.json | 20 +- .../vars/basic/single-quoted.exp.json | 173 +++++++++ .../TestCompile2/vars/basic/style.exp.json | 20 +- .../TestCompile2/vars/boards/layer.exp.json | 26 +- .../TestCompile2/vars/boards/overlay.exp.json | 101 ++--- .../TestCompile2/vars/boards/replace.exp.json | 366 +----------------- .../vars/boards/scenario.exp.json | 26 +- .../TestCompile2/vars/override/label.exp.json | 23 +- 82 files changed, 692 insertions(+), 939 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/double-quoted.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/single-quoted.exp.json diff --git a/d2ast/d2ast.go b/d2ast/d2ast.go index d49b1b268b..25d325cf51 100644 --- a/d2ast/d2ast.go +++ b/d2ast/d2ast.go @@ -503,6 +503,17 @@ type UnquotedString struct { Value []InterpolationBox `json:"value"` } +func (s *UnquotedString) Coalesce() { + var b strings.Builder + for _, box := range s.Value { + if box.String == nil { + break + } + b.WriteString(*box.String) + } + s.SetString(b.String()) +} + func FlatUnquotedString(s string) *UnquotedString { return &UnquotedString{ Value: []InterpolationBox{{String: &s}}, @@ -514,6 +525,17 @@ type DoubleQuotedString struct { Value []InterpolationBox `json:"value"` } +func (s *DoubleQuotedString) Coalesce() { + var b strings.Builder + for _, box := range s.Value { + if box.String == nil { + break + } + b.WriteString(*box.String) + } + s.SetString(b.String()) +} + func FlatDoubleQuotedString(s string) *DoubleQuotedString { return &DoubleQuotedString{ Value: []InterpolationBox{{String: &s}}, diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 096cc1cacb..22373fac5e 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3253,6 +3253,30 @@ hi: 1 ${x} 2 assert.Equal(t, "1 im a var 2", g.Objects[0].Label.Value) }, }, + { + name: "double-quoted", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} +hi: "1 ${x} 2" +`, "") + assert.Equal(t, "1 im a var 2", g.Objects[0].Label.Value) + }, + }, + { + name: "single-quoted", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} +hi: '1 ${x} 2' +`, "") + assert.Equal(t, "1 ${x} 2", g.Objects[0].Label.Value) + }, + }, { name: "edge label", run: func(t *testing.T) { @@ -3411,19 +3435,9 @@ scenarios: { x: ${x} } } -layers: { - l2: { - vars: { - x: im replaced x var - } - x: ${x} - } -} `, "") assert.Equal(t, 1, len(g.Scenarios[0].Objects)) assert.Equal(t, "im replaced x var", g.Scenarios[0].Objects[0].Label.Value) - assert.Equal(t, 1, len(g.Layers[0].Objects)) - assert.Equal(t, "im replaced x var", g.Layers[0].Objects[0].Label.Value) }, }, } @@ -3456,17 +3470,6 @@ vars: { x: hey } hi: ${z} -`, "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z") - }, - }, - { - name: "key", - run: func(t *testing.T) { - assertCompile(t, ` -vars: { - x: hey -} -${x} `, "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z") }, }, diff --git a/d2ir/compile.go b/d2ir/compile.go index b97362077a..8e69091de5 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -7,6 +7,7 @@ import ( "oss.terrastruct.com/d2/d2ast" "oss.terrastruct.com/d2/d2format" "oss.terrastruct.com/d2/d2parser" + "oss.terrastruct.com/util-go/go2" ) type compiler struct { @@ -96,7 +97,47 @@ func (c *compiler) overlayClasses(m *Map) { } } -func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d2ast.Substitution) d2ast.Scalar { +func (c *compiler) resolveSubstitutions(refctx *RefContext) { + varsMap := &Map{} + boardScope := refctx.ScopeMap + if NodeBoardKind(refctx.ScopeMap) == "" { + boardScope = ParentBoard(refctx.ScopeMap).Map() + } + vars := boardScope.GetField("vars") + if vars != nil { + varsMap = vars.Map() + } + + switch { + case refctx.Key.Value.Substitution != nil: + resolvedField := c.resolveSubstitution(varsMap, refctx.Key, refctx.Key.Value.Substitution) + if resolvedField != nil { + refctx.Key.Value = d2ast.MakeValueBox(resolvedField.Primary().Value) + } + case refctx.Key.Value.UnquotedString != nil: + for i, box := range refctx.Key.Value.UnquotedString.Value { + if box.Substitution != nil { + resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) + if resolvedField != nil { + refctx.Key.Value.UnquotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + } + } + } + refctx.Key.Value.UnquotedString.Coalesce() + case refctx.Key.Value.DoubleQuotedString != nil: + for i, box := range refctx.Key.Value.DoubleQuotedString.Value { + if box.Substitution != nil { + resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) + if resolvedField != nil { + refctx.Key.Value.DoubleQuotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + } + } + } + refctx.Key.Value.DoubleQuotedString.Coalesce() + } +} + +func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d2ast.Substitution) *Field { var resolved *Field for _, p := range substitution.Path { if vars == nil { @@ -115,7 +156,7 @@ func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d c.errorf(mk, "could not resolve variable %s", strings.Join(substitution.IDA(), ".")) } else { // TODO maps - return resolved.Primary().Value + return resolved } return nil } @@ -205,6 +246,7 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { func (c *compiler) compileKey(refctx *RefContext) { // resolve substitutions here + c.resolveSubstitutions(refctx) if len(refctx.Key.Edges) == 0 { c.compileField(refctx.ScopeMap, refctx.Key.Key, refctx) } else { @@ -308,15 +350,15 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) c.overlayClasses(f.Map()) } } - } else if refctx.Key.Value.Substitution != nil { - vars := ParentBoard(f).Map().GetField("vars") - resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution) - if resolved != nil { - f.Primary_ = &Scalar{ - parent: f, - Value: resolved, - } - } + // } else if refctx.Key.Value.Substitution != nil { + // vars := ParentBoard(f).Map().GetField("vars") + // resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution) + // if resolved != nil { + // f.Primary_ = &Scalar{ + // parent: f, + // Value: resolved, + // } + // } } else if refctx.Key.Value.ScalarBox().Unbox() != nil { // If the link is a board, we need to transform it into an absolute path. if f.Name == "link" { @@ -496,15 +538,15 @@ func (c *compiler) compileEdges(refctx *RefContext) { } } c.compileMap(e.Map_, refctx.Key.Value.Map, refctx.ScopeAST) - } else if refctx.Key.Value.Substitution != nil { - vars := ParentBoard(e).Map().GetField("vars") - resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution) - if resolved != nil { - e.Primary_ = &Scalar{ - parent: e, - Value: resolved, - } - } + // } else if refctx.Key.Value.Substitution != nil { + // vars := ParentBoard(e).Map().GetField("vars") + // resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution) + // if resolved != nil { + // e.Primary_ = &Scalar{ + // parent: e, + // Value: resolved, + // } + // } } else if refctx.Key.Value.ScalarBox().Unbox() != nil { e.Primary_ = &Scalar{ parent: e, diff --git a/testdata/d2compiler/TestCompile/array-classes.exp.json b/testdata/d2compiler/TestCompile/array-classes.exp.json index 55f49e18a6..dc757ba5e2 100644 --- a/testdata/d2compiler/TestCompile/array-classes.exp.json +++ b/testdata/d2compiler/TestCompile/array-classes.exp.json @@ -76,7 +76,11 @@ "value": { "double_quoted_string": { "range": "d2/testdata/d2compiler/TestCompile/array-classes.d2,2:11:39-2:13:41", - "value": null + "value": [ + { + "string": "" + } + ] } } } @@ -106,8 +110,7 @@ "range": "d2/testdata/d2compiler/TestCompile/array-classes.d2,3:11:53-3:17:59", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -150,8 +153,7 @@ "range": "d2/testdata/d2compiler/TestCompile/array-classes.d2,4:16:76-4:22:82", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -212,8 +214,7 @@ "range": "d2/testdata/d2compiler/TestCompile/array-classes.d2,7:11:108-7:17:114", "value": [ { - "string": "then", - "raw_string": "then" + "string": "then" } ] } diff --git a/testdata/d2compiler/TestCompile/basic_icon.exp.json b/testdata/d2compiler/TestCompile/basic_icon.exp.json index c4e7552f61..eab1c4dec5 100644 --- a/testdata/d2compiler/TestCompile/basic_icon.exp.json +++ b/testdata/d2compiler/TestCompile/basic_icon.exp.json @@ -59,8 +59,7 @@ "range": "d2/testdata/d2compiler/TestCompile/basic_icon.d2,1:8:18-1:64:74", "value": [ { - "string": "https://icons.terrastruct.com/essentials/004-picture.svg", - "raw_string": "https://icons.terrastruct.com/essentials/004-picture.svg" + "string": "https://icons.terrastruct.com/essentials/004-picture.svg" } ] } diff --git a/testdata/d2compiler/TestCompile/basic_sequence.exp.json b/testdata/d2compiler/TestCompile/basic_sequence.exp.json index f5e4620d60..16840f3df4 100644 --- a/testdata/d2compiler/TestCompile/basic_sequence.exp.json +++ b/testdata/d2compiler/TestCompile/basic_sequence.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/basic_sequence.d2,1:9:14-1:25:30", "value": [ { - "string": "sequence_diagram", - "raw_string": "sequence_diagram" + "string": "sequence_diagram" } ] } diff --git a/testdata/d2compiler/TestCompile/basic_shape.exp.json b/testdata/d2compiler/TestCompile/basic_shape.exp.json index ff306f1c47..d15fdb3905 100644 --- a/testdata/d2compiler/TestCompile/basic_shape.exp.json +++ b/testdata/d2compiler/TestCompile/basic_shape.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/basic_shape.d2,2:9:15-2:15:21", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2compiler/TestCompile/class-shape-class.exp.json b/testdata/d2compiler/TestCompile/class-shape-class.exp.json index 049d4ed34d..0e3f13227f 100644 --- a/testdata/d2compiler/TestCompile/class-shape-class.exp.json +++ b/testdata/d2compiler/TestCompile/class-shape-class.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2compiler/TestCompile/class-shape-class.d2,2:11:38-2:16:43", "value": [ { - "string": "class", - "raw_string": "class" + "string": "class" } ] } @@ -145,8 +144,7 @@ "range": "d2/testdata/d2compiler/TestCompile/class-shape-class.d2,7:9:70-7:19:80", "value": [ { - "string": "classClass", - "raw_string": "classClass" + "string": "classClass" } ] } @@ -178,8 +176,7 @@ "range": "d2/testdata/d2compiler/TestCompile/class-shape-class.d2,8:12:93-8:15:96", "value": [ { - "string": "int", - "raw_string": "int" + "string": "int" } ] } diff --git a/testdata/d2compiler/TestCompile/class_paren.exp.json b/testdata/d2compiler/TestCompile/class_paren.exp.json index c6b641edc5..c6965fce8d 100644 --- a/testdata/d2compiler/TestCompile/class_paren.exp.json +++ b/testdata/d2compiler/TestCompile/class_paren.exp.json @@ -64,8 +64,7 @@ "range": "d2/testdata/d2compiler/TestCompile/class_paren.d2,1:9:28-1:14:33", "value": [ { - "string": "class", - "raw_string": "class" + "string": "class" } ] } @@ -120,8 +119,7 @@ "range": "d2/testdata/d2compiler/TestCompile/class_paren.d2,4:13:60-4:19:66", "value": [ { - "string": "string", - "raw_string": "string" + "string": "string" } ] } @@ -153,8 +151,7 @@ "range": "d2/testdata/d2compiler/TestCompile/class_paren.d2,5:8:75-5:12:79", "value": [ { - "string": "bool", - "raw_string": "bool" + "string": "bool" } ] } diff --git a/testdata/d2compiler/TestCompile/class_style.exp.json b/testdata/d2compiler/TestCompile/class_style.exp.json index f139da4f22..469bf1f8a7 100644 --- a/testdata/d2compiler/TestCompile/class_style.exp.json +++ b/testdata/d2compiler/TestCompile/class_style.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/class_style.d2,1:9:28-1:16:35", "value": [ { - "string": "class", - "raw_string": "class" + "string": "class" } ] } @@ -87,8 +86,7 @@ "range": "d2/testdata/d2compiler/TestCompile/class_style.d2,2:14:50-2:22:58", "value": [ { - "string": "string", - "raw_string": "string" + "string": "string" } ] } diff --git a/testdata/d2compiler/TestCompile/classes.exp.json b/testdata/d2compiler/TestCompile/classes.exp.json index ac50b12bdb..35438dba33 100644 --- a/testdata/d2compiler/TestCompile/classes.exp.json +++ b/testdata/d2compiler/TestCompile/classes.exp.json @@ -76,7 +76,11 @@ "value": { "double_quoted_string": { "range": "d2/testdata/d2compiler/TestCompile/classes.d2,2:11:39-2:13:41", - "value": null + "value": [ + { + "string": "" + } + ] } } } @@ -106,8 +110,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,3:11:53-3:17:59", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -150,8 +153,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,4:16:76-4:22:82", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -212,8 +214,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,7:11:108-7:17:114", "value": [ { - "string": "then", - "raw_string": "then" + "string": "then" } ] } @@ -319,8 +320,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,11:17:164-11:28:175", "value": [ { - "string": "dragon_ball", - "raw_string": "dragon_ball" + "string": "dragon_ball" } ] } @@ -391,8 +391,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,12:20:198-12:31:209", "value": [ { - "string": "dragon_ball", - "raw_string": "dragon_ball" + "string": "dragon_ball" } ] } @@ -435,8 +434,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,12:45:223-12:48:226", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -497,8 +495,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,13:16:245-13:20:249", "value": [ { - "string": "**", - "raw_string": "**" + "string": "**" } ] } @@ -530,8 +527,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,13:29:258-13:40:269", "value": [ { - "string": "dragon_ball", - "raw_string": "dragon_ball" + "string": "dragon_ball" } ] } @@ -615,8 +611,7 @@ "range": "d2/testdata/d2compiler/TestCompile/classes.d2,15:26:299-15:30:303", "value": [ { - "string": "path", - "raw_string": "path" + "string": "path" } ] } diff --git a/testdata/d2compiler/TestCompile/dimensions_on_containers.exp.json b/testdata/d2compiler/TestCompile/dimensions_on_containers.exp.json index 6072848cd1..7be798b03c 100644 --- a/testdata/d2compiler/TestCompile/dimensions_on_containers.exp.json +++ b/testdata/d2compiler/TestCompile/dimensions_on_containers.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,3:9:45-3:15:51", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -164,8 +163,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,7:10:89-7:17:96", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } @@ -289,8 +287,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,13:9:163-13:16:170", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } @@ -404,8 +401,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,18:10:221-18:16:227", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -500,8 +496,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,23:9:277-23:13:281", "value": [ { - "string": "oval", - "raw_string": "oval" + "string": "oval" } ] } @@ -615,8 +610,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,28:10:333-28:17:340", "value": [ { - "string": "hexagon", - "raw_string": "hexagon" + "string": "hexagon" } ] } @@ -740,8 +734,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,34:9:407-34:16:414", "value": [ { - "string": "hexagon", - "raw_string": "hexagon" + "string": "hexagon" } ] } @@ -855,8 +848,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_containers.d2,39:10:463-39:14:467", "value": [ { - "string": "oval", - "raw_string": "oval" + "string": "oval" } ] } diff --git a/testdata/d2compiler/TestCompile/dimensions_on_nonimage.exp.json b/testdata/d2compiler/TestCompile/dimensions_on_nonimage.exp.json index 2aad6eb2df..a182d32e93 100644 --- a/testdata/d2compiler/TestCompile/dimensions_on_nonimage.exp.json +++ b/testdata/d2compiler/TestCompile/dimensions_on_nonimage.exp.json @@ -59,8 +59,7 @@ "range": "d2/testdata/d2compiler/TestCompile/dimensions_on_nonimage.d2,1:9:19-1:16:26", "value": [ { - "string": "hexagon", - "raw_string": "hexagon" + "string": "hexagon" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_arrowhead_fields.exp.json b/testdata/d2compiler/TestCompile/edge_arrowhead_fields.exp.json index 573bd41bb9..0dc322a3f6 100644 --- a/testdata/d2compiler/TestCompile/edge_arrowhead_fields.exp.json +++ b/testdata/d2compiler/TestCompile/edge_arrowhead_fields.exp.json @@ -111,8 +111,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_fields.d2,2:11:80-2:18:87", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } @@ -149,8 +148,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_fields.d2,4:20:112-4:24:116", "value": [ { - "string": "QOTD", - "raw_string": "QOTD" + "string": "QOTD" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_arrowhead_primary.exp.json b/testdata/d2compiler/TestCompile/edge_arrowhead_primary.exp.json index 43dbe69346..b9ffad1a64 100644 --- a/testdata/d2compiler/TestCompile/edge_arrowhead_primary.exp.json +++ b/testdata/d2compiler/TestCompile/edge_arrowhead_primary.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_arrowhead_primary.d2,1:20:30-1:56:66", "value": [ { - "string": "Reisner's Rule of Conceptual Inertia", - "raw_string": "Reisner's Rule of Conceptual Inertia" + "string": "Reisner's Rule of Conceptual Inertia" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_chain.exp.json b/testdata/d2compiler/TestCompile/edge_chain.exp.json index fc3cb532e2..683290ef1d 100644 --- a/testdata/d2compiler/TestCompile/edge_chain.exp.json +++ b/testdata/d2compiler/TestCompile/edge_chain.exp.json @@ -90,8 +90,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_chain.d2,1:13:14-1:55:56", "value": [ { - "string": "The kids will love our inflatable slides", - "raw_string": "The kids will love our inflatable slides" + "string": "The kids will love our inflatable slides" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_chain_map.exp.json b/testdata/d2compiler/TestCompile/edge_chain_map.exp.json index 7b58cb7bd4..f6b01e3b1a 100644 --- a/testdata/d2compiler/TestCompile/edge_chain_map.exp.json +++ b/testdata/d2compiler/TestCompile/edge_chain_map.exp.json @@ -114,8 +114,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_chain_map.d2,2:9:25-2:88:104", "value": [ { - "string": "Space: the final frontier. These are the voyages of the starship Enterprise.", - "raw_string": "Space: the final frontier. These are the voyages of the starship Enterprise." + "string": "Space: the final frontier. These are the voyages of the starship Enterprise." } ] } diff --git a/testdata/d2compiler/TestCompile/edge_column_index.exp.json b/testdata/d2compiler/TestCompile/edge_column_index.exp.json index a1f43e9869..c0b4d7be46 100644 --- a/testdata/d2compiler/TestCompile/edge_column_index.exp.json +++ b/testdata/d2compiler/TestCompile/edge_column_index.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,1:8:15-1:17:24", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -87,8 +86,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,2:5:30-2:8:33", "value": [ { - "string": "int", - "raw_string": "int" + "string": "int" } ] } @@ -120,8 +118,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,3:9:43-3:12:46", "value": [ { - "string": "int", - "raw_string": "int" + "string": "int" } ] } @@ -182,8 +179,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,7:8:65-7:17:74", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -215,8 +211,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,8:5:80-8:8:83", "value": [ { - "string": "int", - "raw_string": "int" + "string": "int" } ] } @@ -248,8 +243,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_column_index.d2,9:7:91-9:13:97", "value": [ { - "string": "string", - "raw_string": "string" + "string": "string" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_flat_arrowhead.exp.json b/testdata/d2compiler/TestCompile/edge_flat_arrowhead.exp.json index 50be77f894..5d842efabb 100644 --- a/testdata/d2compiler/TestCompile/edge_flat_arrowhead.exp.json +++ b/testdata/d2compiler/TestCompile/edge_flat_arrowhead.exp.json @@ -131,8 +131,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_flat_arrowhead.d2,1:36:43-1:43:50", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_flat_label_arrowhead.exp.json b/testdata/d2compiler/TestCompile/edge_flat_label_arrowhead.exp.json index bccfb91296..052c0ff539 100644 --- a/testdata/d2compiler/TestCompile/edge_flat_label_arrowhead.exp.json +++ b/testdata/d2compiler/TestCompile/edge_flat_label_arrowhead.exp.json @@ -94,8 +94,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_flat_label_arrowhead.d2,2:26:48-2:28:50", "value": [ { - "string": "yo", - "raw_string": "yo" + "string": "yo" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_index.exp.json b/testdata/d2compiler/TestCompile/edge_index.exp.json index dec38ad77b..95a7d7d14d 100644 --- a/testdata/d2compiler/TestCompile/edge_index.exp.json +++ b/testdata/d2compiler/TestCompile/edge_index.exp.json @@ -53,8 +53,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_index.d2,1:8:9-1:11:12", "value": [ { - "string": "one", - "raw_string": "one" + "string": "one" } ] } @@ -114,8 +113,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_index.d2,2:13:26-2:16:29", "value": [ { - "string": "two", - "raw_string": "two" + "string": "two" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_index_map.exp.json b/testdata/d2compiler/TestCompile/edge_index_map.exp.json index 14c91274ea..d97ce029d3 100644 --- a/testdata/d2compiler/TestCompile/edge_index_map.exp.json +++ b/testdata/d2compiler/TestCompile/edge_index_map.exp.json @@ -128,8 +128,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_index_map.d2,3:9:32-3:88:111", "value": [ { - "string": "Space: the final frontier. These are the voyages of the starship Enterprise.", - "raw_string": "Space: the final frontier. These are the voyages of the starship Enterprise." + "string": "Space: the final frontier. These are the voyages of the starship Enterprise." } ] } diff --git a/testdata/d2compiler/TestCompile/edge_index_nested.exp.json b/testdata/d2compiler/TestCompile/edge_index_nested.exp.json index 6ebba4d349..340db81076 100644 --- a/testdata/d2compiler/TestCompile/edge_index_nested.exp.json +++ b/testdata/d2compiler/TestCompile/edge_index_nested.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_index_nested.d2,2:9:15-2:12:18", "value": [ { - "string": "one", - "raw_string": "one" + "string": "one" } ] } @@ -138,8 +137,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_index_nested.d2,3:14:33-3:17:36", "value": [ { - "string": "two", - "raw_string": "two" + "string": "two" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_index_nested_cross_scope.exp.json b/testdata/d2compiler/TestCompile/edge_index_nested_cross_scope.exp.json index 0841677419..a2d139a606 100644 --- a/testdata/d2compiler/TestCompile/edge_index_nested_cross_scope.exp.json +++ b/testdata/d2compiler/TestCompile/edge_index_nested_cross_scope.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_index_nested_cross_scope.d2,2:9:15-2:12:18", "value": [ { - "string": "one", - "raw_string": "one" + "string": "one" } ] } @@ -159,8 +158,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_index_nested_cross_scope.d2,4:15:36-4:18:39", "value": [ { - "string": "two", - "raw_string": "two" + "string": "two" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_map.exp.json b/testdata/d2compiler/TestCompile/edge_map.exp.json index 4e4652c77f..4c010a354e 100644 --- a/testdata/d2compiler/TestCompile/edge_map.exp.json +++ b/testdata/d2compiler/TestCompile/edge_map.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_map.d2,2:9:20-2:88:99", "value": [ { - "string": "Space: the final frontier. These are the voyages of the starship Enterprise.", - "raw_string": "Space: the final frontier. These are the voyages of the starship Enterprise." + "string": "Space: the final frontier. These are the voyages of the starship Enterprise." } ] } diff --git a/testdata/d2compiler/TestCompile/edge_map_arrowhead.exp.json b/testdata/d2compiler/TestCompile/edge_map_arrowhead.exp.json index 9874c0c277..3e1995badf 100644 --- a/testdata/d2compiler/TestCompile/edge_map_arrowhead.exp.json +++ b/testdata/d2compiler/TestCompile/edge_map_arrowhead.exp.json @@ -101,8 +101,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_map_arrowhead.d2,2:11:43-2:18:50", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_mixed_arrowhead.exp.json b/testdata/d2compiler/TestCompile/edge_mixed_arrowhead.exp.json index c00936b2d9..6178022550 100644 --- a/testdata/d2compiler/TestCompile/edge_mixed_arrowhead.exp.json +++ b/testdata/d2compiler/TestCompile/edge_mixed_arrowhead.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_mixed_arrowhead.d2,1:26:36-1:33:43", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } @@ -194,8 +193,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_mixed_arrowhead.d2,4:9:87-4:16:94", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_non_shape_arrowhead.exp.json b/testdata/d2compiler/TestCompile/edge_non_shape_arrowhead.exp.json index 6f5721e7c8..08e3122d84 100644 --- a/testdata/d2compiler/TestCompile/edge_non_shape_arrowhead.exp.json +++ b/testdata/d2compiler/TestCompile/edge_non_shape_arrowhead.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_non_shape_arrowhead.d2,0:34:34-0:42:42", "value": [ { - "string": "triangle", - "raw_string": "triangle" + "string": "triangle" } ] } diff --git a/testdata/d2compiler/TestCompile/edge_semiflat_arrowhead.exp.json b/testdata/d2compiler/TestCompile/edge_semiflat_arrowhead.exp.json index 18c537b795..51c1ca72ff 100644 --- a/testdata/d2compiler/TestCompile/edge_semiflat_arrowhead.exp.json +++ b/testdata/d2compiler/TestCompile/edge_semiflat_arrowhead.exp.json @@ -144,8 +144,7 @@ "range": "d2/testdata/d2compiler/TestCompile/edge_semiflat_arrowhead.d2,2:9:48-2:16:55", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2compiler/TestCompile/fill-pattern.exp.json b/testdata/d2compiler/TestCompile/fill-pattern.exp.json index fcdeecfc73..24e740e1e2 100644 --- a/testdata/d2compiler/TestCompile/fill-pattern.exp.json +++ b/testdata/d2compiler/TestCompile/fill-pattern.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2compiler/TestCompile/fill-pattern.d2,2:18:33-2:22:37", "value": [ { - "string": "dots", - "raw_string": "dots" + "string": "dots" } ] } diff --git a/testdata/d2compiler/TestCompile/icon-near-composite-together.exp.json b/testdata/d2compiler/TestCompile/icon-near-composite-together.exp.json index 1d0b6974e5..632db45696 100644 --- a/testdata/d2compiler/TestCompile/icon-near-composite-together.exp.json +++ b/testdata/d2compiler/TestCompile/icon-near-composite-together.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2compiler/TestCompile/icon-near-composite-together.d2,2:8:41-2:24:57", "value": [ { - "string": "outside-top-left", - "raw_string": "outside-top-left" + "string": "outside-top-left" } ] } diff --git a/testdata/d2compiler/TestCompile/image_style.exp.json b/testdata/d2compiler/TestCompile/image_style.exp.json index 0f22863e93..183ccb9802 100644 --- a/testdata/d2compiler/TestCompile/image_style.exp.json +++ b/testdata/d2compiler/TestCompile/image_style.exp.json @@ -59,8 +59,7 @@ "range": "d2/testdata/d2compiler/TestCompile/image_style.d2,1:8:18-1:64:74", "value": [ { - "string": "https://icons.terrastruct.com/essentials/004-picture.svg", - "raw_string": "https://icons.terrastruct.com/essentials/004-picture.svg" + "string": "https://icons.terrastruct.com/essentials/004-picture.svg" } ] } @@ -92,8 +91,7 @@ "range": "d2/testdata/d2compiler/TestCompile/image_style.d2,2:9:84-2:14:89", "value": [ { - "string": "image", - "raw_string": "image" + "string": "image" } ] } @@ -136,8 +134,7 @@ "range": "d2/testdata/d2compiler/TestCompile/image_style.d2,3:16:106-3:25:115", "value": [ { - "string": "#0D32B2", - "raw_string": "#0D32B2" + "string": "#0D32B2" } ] } diff --git a/testdata/d2compiler/TestCompile/label-near-composite-separate.exp.json b/testdata/d2compiler/TestCompile/label-near-composite-separate.exp.json index b73200e7af..22ecfc551f 100644 --- a/testdata/d2compiler/TestCompile/label-near-composite-separate.exp.json +++ b/testdata/d2compiler/TestCompile/label-near-composite-separate.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/label-near-composite-separate.d2,1:8:15-1:13:20", "value": [ { - "string": "sushi", - "raw_string": "sushi" + "string": "sushi" } ] } @@ -98,8 +97,7 @@ "range": "d2/testdata/d2compiler/TestCompile/label-near-composite-separate.d2,2:13:34-2:29:50", "value": [ { - "string": "outside-top-left", - "raw_string": "outside-top-left" + "string": "outside-top-left" } ] } diff --git a/testdata/d2compiler/TestCompile/label-near-composite-together.exp.json b/testdata/d2compiler/TestCompile/label-near-composite-together.exp.json index ee68c9863b..bedc9a9a87 100644 --- a/testdata/d2compiler/TestCompile/label-near-composite-together.exp.json +++ b/testdata/d2compiler/TestCompile/label-near-composite-together.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2compiler/TestCompile/label-near-composite-together.d2,2:8:32-2:24:48", "value": [ { - "string": "outside-top-left", - "raw_string": "outside-top-left" + "string": "outside-top-left" } ] } diff --git a/testdata/d2compiler/TestCompile/label-near-parent.exp.json b/testdata/d2compiler/TestCompile/label-near-parent.exp.json index 192949f560..261465cf67 100644 --- a/testdata/d2compiler/TestCompile/label-near-parent.exp.json +++ b/testdata/d2compiler/TestCompile/label-near-parent.exp.json @@ -75,8 +75,7 @@ "range": "d2/testdata/d2compiler/TestCompile/label-near-parent.d2,1:13:26-1:29:42", "value": [ { - "string": "outside-top-left", - "raw_string": "outside-top-left" + "string": "outside-top-left" } ] } diff --git a/testdata/d2compiler/TestCompile/link-board-mixed.exp.json b/testdata/d2compiler/TestCompile/link-board-mixed.exp.json index 974fc5fbc4..e0120bcc58 100644 --- a/testdata/d2compiler/TestCompile/link-board-mixed.exp.json +++ b/testdata/d2compiler/TestCompile/link-board-mixed.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,0:10:10-0:30:30", "value": [ { - "string": "How does the cat go?", - "raw_string": "How does the cat go?" + "string": "How does the cat go?" } ] } @@ -177,8 +176,7 @@ "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,5:26:103-5:30:107", "value": [ { - "string": "goes", - "raw_string": "goes" + "string": "goes" } ] } @@ -290,8 +288,7 @@ "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,11:25:164-11:30:169", "value": [ { - "string": "green", - "raw_string": "green" + "string": "green" } ] } @@ -511,8 +508,7 @@ "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,5:26:103-5:30:107", "value": [ { - "string": "goes", - "raw_string": "goes" + "string": "goes" } ] } @@ -701,8 +697,7 @@ "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,0:10:10-0:30:30", "value": [ { - "string": "How does the cat go?", - "raw_string": "How does the cat go?" + "string": "How does the cat go?" } ] } @@ -788,8 +783,7 @@ "range": "d2/testdata/d2compiler/TestCompile/link-board-mixed.d2,11:25:164-11:30:169", "value": [ { - "string": "green", - "raw_string": "green" + "string": "green" } ] } diff --git a/testdata/d2compiler/TestCompile/missing-class.exp.json b/testdata/d2compiler/TestCompile/missing-class.exp.json index 1aa7a96730..25f2adca7e 100644 --- a/testdata/d2compiler/TestCompile/missing-class.exp.json +++ b/testdata/d2compiler/TestCompile/missing-class.exp.json @@ -41,8 +41,7 @@ "range": "d2/testdata/d2compiler/TestCompile/missing-class.d2,0:9:9-0:11:11", "value": [ { - "string": "yo", - "raw_string": "yo" + "string": "yo" } ] } diff --git a/testdata/d2compiler/TestCompile/near_constant.exp.json b/testdata/d2compiler/TestCompile/near_constant.exp.json index 6139e09c55..d6f5751d12 100644 --- a/testdata/d2compiler/TestCompile/near_constant.exp.json +++ b/testdata/d2compiler/TestCompile/near_constant.exp.json @@ -41,8 +41,7 @@ "range": "d2/testdata/d2compiler/TestCompile/near_constant.d2,0:8:8-0:18:18", "value": [ { - "string": "top-center", - "raw_string": "top-center" + "string": "top-center" } ] } diff --git a/testdata/d2compiler/TestCompile/nested-array-classes.exp.json b/testdata/d2compiler/TestCompile/nested-array-classes.exp.json index a897f16781..0ba0aac3f7 100644 --- a/testdata/d2compiler/TestCompile/nested-array-classes.exp.json +++ b/testdata/d2compiler/TestCompile/nested-array-classes.exp.json @@ -158,8 +158,7 @@ "range": "d2/testdata/d2compiler/TestCompile/nested-array-classes.d2,5:26:101-5:31:106", "value": [ { - "string": "arrow", - "raw_string": "arrow" + "string": "arrow" } ] } diff --git a/testdata/d2compiler/TestCompile/nested_sql.exp.json b/testdata/d2compiler/TestCompile/nested_sql.exp.json index 1781b2ac63..6c15ddb77a 100644 --- a/testdata/d2compiler/TestCompile/nested_sql.exp.json +++ b/testdata/d2compiler/TestCompile/nested_sql.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2compiler/TestCompile/nested_sql.d2,2:11:31-2:20:40", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -111,8 +110,7 @@ "range": "d2/testdata/d2compiler/TestCompile/nested_sql.d2,4:15:57-4:21:63", "value": [ { - "string": "string", - "raw_string": "string" + "string": "string" } ] } @@ -144,8 +142,7 @@ "range": "d2/testdata/d2compiler/TestCompile/nested_sql.d2,5:10:74-5:14:78", "value": [ { - "string": "bool", - "raw_string": "bool" + "string": "bool" } ] } diff --git a/testdata/d2compiler/TestCompile/path_link.exp.json b/testdata/d2compiler/TestCompile/path_link.exp.json index af370962eb..c2daa00394 100644 --- a/testdata/d2compiler/TestCompile/path_link.exp.json +++ b/testdata/d2compiler/TestCompile/path_link.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/path_link.d2,1:8:13-1:39:44", "value": [ { - "string": "Overview.Untitled board 7.zzzzz", - "raw_string": "Overview.Untitled board 7.zzzzz" + "string": "Overview.Untitled board 7.zzzzz" } ] } diff --git a/testdata/d2compiler/TestCompile/reordered-classes.exp.json b/testdata/d2compiler/TestCompile/reordered-classes.exp.json index 07280d1c25..0e9844908c 100644 --- a/testdata/d2compiler/TestCompile/reordered-classes.exp.json +++ b/testdata/d2compiler/TestCompile/reordered-classes.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2compiler/TestCompile/reordered-classes.d2,2:11:29-2:17:35", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -132,8 +131,7 @@ "range": "d2/testdata/d2compiler/TestCompile/reordered-classes.d2,5:9:51-5:10:52", "value": [ { - "string": "x", - "raw_string": "x" + "string": "x" } ] } @@ -187,8 +185,7 @@ "range": "d2/testdata/d2compiler/TestCompile/reordered-classes.d2,6:17:70-6:24:77", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2compiler/TestCompile/reserved_icon_near_style.exp.json b/testdata/d2compiler/TestCompile/reserved_icon_near_style.exp.json index d037b9da4f..e2cc05144d 100644 --- a/testdata/d2compiler/TestCompile/reserved_icon_near_style.exp.json +++ b/testdata/d2compiler/TestCompile/reserved_icon_near_style.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/reserved_icon_near_style.d2,1:8:13-1:14:19", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -138,8 +137,7 @@ "range": "d2/testdata/d2compiler/TestCompile/reserved_icon_near_style.d2,3:16:57-3:19:60", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -182,8 +180,7 @@ "range": "d2/testdata/d2compiler/TestCompile/reserved_icon_near_style.d2,4:13:74-4:18:79", "value": [ { - "string": "green", - "raw_string": "green" + "string": "green" } ] } @@ -231,8 +228,7 @@ "range": "d2/testdata/d2compiler/TestCompile/reserved_icon_near_style.d2,6:8:90-6:9:91", "value": [ { - "string": "y", - "raw_string": "y" + "string": "y" } ] } diff --git a/testdata/d2compiler/TestCompile/root_direction.exp.json b/testdata/d2compiler/TestCompile/root_direction.exp.json index 98ba30edae..8fdf89c77d 100644 --- a/testdata/d2compiler/TestCompile/root_direction.exp.json +++ b/testdata/d2compiler/TestCompile/root_direction.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/root_direction.d2,0:11:11-0:16:16", "value": [ { - "string": "right", - "raw_string": "right" + "string": "right" } ] } diff --git a/testdata/d2compiler/TestCompile/root_sequence.exp.json b/testdata/d2compiler/TestCompile/root_sequence.exp.json index 353ce9a61f..510f8fe476 100644 --- a/testdata/d2compiler/TestCompile/root_sequence.exp.json +++ b/testdata/d2compiler/TestCompile/root_sequence.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/root_sequence.d2,0:7:7-0:23:23", "value": [ { - "string": "sequence_diagram", - "raw_string": "sequence_diagram" + "string": "sequence_diagram" } ] } diff --git a/testdata/d2compiler/TestCompile/sequence-timestamp.exp.json b/testdata/d2compiler/TestCompile/sequence-timestamp.exp.json index 4c90eaac07..8248fadb1f 100644 --- a/testdata/d2compiler/TestCompile/sequence-timestamp.exp.json +++ b/testdata/d2compiler/TestCompile/sequence-timestamp.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sequence-timestamp.d2,0:7:7-0:23:23", "value": [ { - "string": "sequence_diagram", - "raw_string": "sequence_diagram" + "string": "sequence_diagram" } ] } diff --git a/testdata/d2compiler/TestCompile/sequence_container.exp.json b/testdata/d2compiler/TestCompile/sequence_container.exp.json index 5dd16ad44b..170abd9c8b 100644 --- a/testdata/d2compiler/TestCompile/sequence_container.exp.json +++ b/testdata/d2compiler/TestCompile/sequence_container.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sequence_container.d2,0:7:7-0:23:23", "value": [ { - "string": "sequence_diagram", - "raw_string": "sequence_diagram" + "string": "sequence_diagram" } ] } diff --git a/testdata/d2compiler/TestCompile/sequence_container_2.exp.json b/testdata/d2compiler/TestCompile/sequence_container_2.exp.json index 503423b6c4..dc7b3eb126 100644 --- a/testdata/d2compiler/TestCompile/sequence_container_2.exp.json +++ b/testdata/d2compiler/TestCompile/sequence_container_2.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sequence_container_2.d2,0:7:7-0:23:23", "value": [ { - "string": "sequence_diagram", - "raw_string": "sequence_diagram" + "string": "sequence_diagram" } ] } diff --git a/testdata/d2compiler/TestCompile/sequence_grouped_note.exp.json b/testdata/d2compiler/TestCompile/sequence_grouped_note.exp.json index 1958d8227a..459a76786a 100644 --- a/testdata/d2compiler/TestCompile/sequence_grouped_note.exp.json +++ b/testdata/d2compiler/TestCompile/sequence_grouped_note.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sequence_grouped_note.d2,0:7:7-0:23:23", "value": [ { - "string": "sequence_diagram", - "raw_string": "sequence_diagram" + "string": "sequence_diagram" } ] } diff --git a/testdata/d2compiler/TestCompile/sequence_scoping.exp.json b/testdata/d2compiler/TestCompile/sequence_scoping.exp.json index 0870aa4c16..a46a3fa316 100644 --- a/testdata/d2compiler/TestCompile/sequence_scoping.exp.json +++ b/testdata/d2compiler/TestCompile/sequence_scoping.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sequence_scoping.d2,1:9:14-1:25:30", "value": [ { - "string": "sequence_diagram", - "raw_string": "sequence_diagram" + "string": "sequence_diagram" } ] } diff --git a/testdata/d2compiler/TestCompile/set_direction.exp.json b/testdata/d2compiler/TestCompile/set_direction.exp.json index b59d6d0da6..92d4166c17 100644 --- a/testdata/d2compiler/TestCompile/set_direction.exp.json +++ b/testdata/d2compiler/TestCompile/set_direction.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/set_direction.d2,1:13:18-1:17:22", "value": [ { - "string": "left", - "raw_string": "left" + "string": "left" } ] } diff --git a/testdata/d2compiler/TestCompile/single_dimension_on_circle.exp.json b/testdata/d2compiler/TestCompile/single_dimension_on_circle.exp.json index 3cf517caae..afba4f2c60 100644 --- a/testdata/d2compiler/TestCompile/single_dimension_on_circle.exp.json +++ b/testdata/d2compiler/TestCompile/single_dimension_on_circle.exp.json @@ -59,8 +59,7 @@ "range": "d2/testdata/d2compiler/TestCompile/single_dimension_on_circle.d2,1:8:18-1:14:24", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2compiler/TestCompile/sql-constraints.exp.json b/testdata/d2compiler/TestCompile/sql-constraints.exp.json index db24296fa4..a74178a5e6 100644 --- a/testdata/d2compiler/TestCompile/sql-constraints.exp.json +++ b/testdata/d2compiler/TestCompile/sql-constraints.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sql-constraints.d2,1:9:14-1:18:23", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -121,8 +120,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sql-constraints.d2,2:22:46-2:33:57", "value": [ { - "string": "primary_key", - "raw_string": "primary_key" + "string": "primary_key" } ] } diff --git a/testdata/d2compiler/TestCompile/sql-regression.exp.json b/testdata/d2compiler/TestCompile/sql-regression.exp.json index 64b5d46e59..47cfcf60ce 100644 --- a/testdata/d2compiler/TestCompile/sql-regression.exp.json +++ b/testdata/d2compiler/TestCompile/sql-regression.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sql-regression.d2,2:10:26-2:22:38", "value": [ { - "string": "lemonchiffon", - "raw_string": "lemonchiffon" + "string": "lemonchiffon" } ] } @@ -140,8 +139,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sql-regression.d2,5:11:61-5:20:70", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } diff --git a/testdata/d2compiler/TestCompile/sql_paren.exp.json b/testdata/d2compiler/TestCompile/sql_paren.exp.json index 8064ff8ed5..4bc3e381e7 100644 --- a/testdata/d2compiler/TestCompile/sql_paren.exp.json +++ b/testdata/d2compiler/TestCompile/sql_paren.exp.json @@ -64,8 +64,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sql_paren.d2,1:9:28-1:18:37", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -97,8 +96,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sql_paren.d2,3:13:52-3:19:58", "value": [ { - "string": "string", - "raw_string": "string" + "string": "string" } ] } @@ -130,8 +128,7 @@ "range": "d2/testdata/d2compiler/TestCompile/sql_paren.d2,4:8:67-4:12:71", "value": [ { - "string": "bool", - "raw_string": "bool" + "string": "bool" } ] } diff --git a/testdata/d2compiler/TestCompile/table_connection_attr.exp.json b/testdata/d2compiler/TestCompile/table_connection_attr.exp.json index 9012bd9270..8d0548dea9 100644 --- a/testdata/d2compiler/TestCompile/table_connection_attr.exp.json +++ b/testdata/d2compiler/TestCompile/table_connection_attr.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,1:9:14-1:18:23", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -139,8 +138,7 @@ "range": "d2/testdata/d2compiler/TestCompile/table_connection_attr.d2,5:9:44-5:18:53", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } diff --git a/testdata/d2compiler/TestCompile/table_style.exp.json b/testdata/d2compiler/TestCompile/table_style.exp.json index b68772eff4..782284d047 100644 --- a/testdata/d2compiler/TestCompile/table_style.exp.json +++ b/testdata/d2compiler/TestCompile/table_style.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/table_style.d2,1:9:28-1:18:37", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -87,8 +86,7 @@ "range": "d2/testdata/d2compiler/TestCompile/table_style.d2,2:13:51-2:19:57", "value": [ { - "string": "string", - "raw_string": "string" + "string": "string" } ] } diff --git a/testdata/d2compiler/TestCompile/table_style_map.exp.json b/testdata/d2compiler/TestCompile/table_style_map.exp.json index bd065d54f0..a2e8f3ff58 100644 --- a/testdata/d2compiler/TestCompile/table_style_map.exp.json +++ b/testdata/d2compiler/TestCompile/table_style_map.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/table_style_map.d2,1:9:28-1:18:37", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -87,8 +86,7 @@ "range": "d2/testdata/d2compiler/TestCompile/table_style_map.d2,2:13:51-2:19:57", "value": [ { - "string": "string", - "raw_string": "string" + "string": "string" } ] } @@ -173,8 +171,7 @@ "range": "d2/testdata/d2compiler/TestCompile/table_style_map.d2,5:16:102-5:20:106", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } diff --git a/testdata/d2compiler/TestCompile/text-transform.exp.json b/testdata/d2compiler/TestCompile/text-transform.exp.json index 6d32e0f758..e8e1fd4a1f 100644 --- a/testdata/d2compiler/TestCompile/text-transform.exp.json +++ b/testdata/d2compiler/TestCompile/text-transform.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/text-transform.d2,0:11:11-0:16:16", "value": [ { - "string": "right", - "raw_string": "right" + "string": "right" } ] } @@ -144,8 +143,7 @@ "range": "d2/testdata/d2compiler/TestCompile/text-transform.d2,3:20:61-3:30:71", "value": [ { - "string": "capitalize", - "raw_string": "capitalize" + "string": "capitalize" } ] } @@ -209,8 +207,7 @@ "range": "d2/testdata/d2compiler/TestCompile/text-transform.d2,6:24:102-6:33:111", "value": [ { - "string": "uppercase", - "raw_string": "uppercase" + "string": "uppercase" } ] } @@ -264,8 +261,7 @@ "range": "d2/testdata/d2compiler/TestCompile/text-transform.d2,7:24:136-7:33:145", "value": [ { - "string": "lowercase", - "raw_string": "lowercase" + "string": "lowercase" } ] } diff --git a/testdata/d2compiler/TestCompile/underscore_edge_existing.exp.json b/testdata/d2compiler/TestCompile/underscore_edge_existing.exp.json index 7b44d6ac87..6d2eaca679 100644 --- a/testdata/d2compiler/TestCompile/underscore_edge_existing.exp.json +++ b/testdata/d2compiler/TestCompile/underscore_edge_existing.exp.json @@ -53,8 +53,7 @@ "range": "d2/testdata/d2compiler/TestCompile/underscore_edge_existing.d2,1:8:9-1:77:78", "value": [ { - "string": "Can you imagine how life could be improved if we could do away with", - "raw_string": "Can you imagine how life could be improved if we could do away with" + "string": "Can you imagine how life could be improved if we could do away with" } ] } @@ -155,8 +154,7 @@ "range": "d2/testdata/d2compiler/TestCompile/underscore_edge_existing.d2,3:13:97-3:80:164", "value": [ { - "string": "Well, it's garish, ugly, and derelicts have used it for a toilet.", - "raw_string": "Well, it's garish, ugly, and derelicts have used it for a toilet." + "string": "Well, it's garish, ugly, and derelicts have used it for a toilet." } ] } diff --git a/testdata/d2compiler/TestCompile/underscore_edge_index.exp.json b/testdata/d2compiler/TestCompile/underscore_edge_index.exp.json index 25aa724942..b888432383 100644 --- a/testdata/d2compiler/TestCompile/underscore_edge_index.exp.json +++ b/testdata/d2compiler/TestCompile/underscore_edge_index.exp.json @@ -53,8 +53,7 @@ "range": "d2/testdata/d2compiler/TestCompile/underscore_edge_index.d2,1:8:9-1:77:78", "value": [ { - "string": "Can you imagine how life could be improved if we could do away with", - "raw_string": "Can you imagine how life could be improved if we could do away with" + "string": "Can you imagine how life could be improved if we could do away with" } ] } @@ -160,8 +159,7 @@ "range": "d2/testdata/d2compiler/TestCompile/underscore_edge_index.d2,3:18:102-3:85:169", "value": [ { - "string": "Well, it's garish, ugly, and derelicts have used it for a toilet.", - "raw_string": "Well, it's garish, ugly, and derelicts have used it for a toilet." + "string": "Well, it's garish, ugly, and derelicts have used it for a toilet." } ] } diff --git a/testdata/d2compiler/TestCompile/underscore_parent_preference_1.exp.json b/testdata/d2compiler/TestCompile/underscore_parent_preference_1.exp.json index 8e1ecb3f23..ea91c31147 100644 --- a/testdata/d2compiler/TestCompile/underscore_parent_preference_1.exp.json +++ b/testdata/d2compiler/TestCompile/underscore_parent_preference_1.exp.json @@ -65,8 +65,7 @@ "range": "d2/testdata/d2compiler/TestCompile/underscore_parent_preference_1.d2,2:6:12-2:84:90", "value": [ { - "string": "All we are given is possibilities -- to make ourselves one thing or another.", - "raw_string": "All we are given is possibilities -- to make ourselves one thing or another." + "string": "All we are given is possibilities -- to make ourselves one thing or another." } ] } @@ -103,8 +102,7 @@ "range": "d2/testdata/d2compiler/TestCompile/underscore_parent_preference_1.d2,4:3:96-4:80:173", "value": [ { - "string": "But it's real. And if it's real it can be affected ... we may not be able", - "raw_string": "But it's real. And if it's real it can be affected ... we may not be able" + "string": "But it's real. And if it's real it can be affected ... we may not be able" } ] } diff --git a/testdata/d2compiler/TestCompile/underscore_parent_preference_2.exp.json b/testdata/d2compiler/TestCompile/underscore_parent_preference_2.exp.json index e8850d2a20..b241f3064a 100644 --- a/testdata/d2compiler/TestCompile/underscore_parent_preference_2.exp.json +++ b/testdata/d2compiler/TestCompile/underscore_parent_preference_2.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2compiler/TestCompile/underscore_parent_preference_2.d2,1:3:4-1:80:81", "value": [ { - "string": "But it's real. And if it's real it can be affected ... we may not be able", - "raw_string": "But it's real. And if it's real it can be affected ... we may not be able" + "string": "But it's real. And if it's real it can be affected ... we may not be able" } ] } @@ -98,8 +97,7 @@ "range": "d2/testdata/d2compiler/TestCompile/underscore_parent_preference_2.d2,3:6:93-3:84:171", "value": [ { - "string": "All we are given is possibilities -- to make ourselves one thing or another.", - "raw_string": "All we are given is possibilities -- to make ourselves one thing or another." + "string": "All we are given is possibilities -- to make ourselves one thing or another." } ] } diff --git a/testdata/d2compiler/TestCompile/url_link.exp.json b/testdata/d2compiler/TestCompile/url_link.exp.json index 0ee2c03782..ec370207a8 100644 --- a/testdata/d2compiler/TestCompile/url_link.exp.json +++ b/testdata/d2compiler/TestCompile/url_link.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/url_link.d2,1:8:13-1:26:31", "value": [ { - "string": "https://google.com", - "raw_string": "https://google.com" + "string": "https://google.com" } ] } diff --git a/testdata/d2compiler/TestCompile/url_link_and_not_url_tooltip_concurrently.exp.json b/testdata/d2compiler/TestCompile/url_link_and_not_url_tooltip_concurrently.exp.json index 4fc6b9851c..c581bc47f1 100644 --- a/testdata/d2compiler/TestCompile/url_link_and_not_url_tooltip_concurrently.exp.json +++ b/testdata/d2compiler/TestCompile/url_link_and_not_url_tooltip_concurrently.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/url_link_and_not_url_tooltip_concurrently.d2,0:10:10-0:28:28", "value": [ { - "string": "https://google.com", - "raw_string": "https://google.com" + "string": "https://google.com" } ] } @@ -87,8 +86,7 @@ "range": "d2/testdata/d2compiler/TestCompile/url_link_and_not_url_tooltip_concurrently.d2,0:39:39-0:50:50", "value": [ { - "string": "hello world", - "raw_string": "hello world" + "string": "hello world" } ] } diff --git a/testdata/d2compiler/TestCompile/url_link_non_url_tooltip_ok.exp.json b/testdata/d2compiler/TestCompile/url_link_non_url_tooltip_ok.exp.json index 55017b2a10..201fb038a8 100644 --- a/testdata/d2compiler/TestCompile/url_link_non_url_tooltip_ok.exp.json +++ b/testdata/d2compiler/TestCompile/url_link_non_url_tooltip_ok.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/url_link_non_url_tooltip_ok.d2,0:10:10-0:32:32", "value": [ { - "string": "https://not-google.com", - "raw_string": "https://not-google.com" + "string": "https://not-google.com" } ] } @@ -87,8 +86,7 @@ "range": "d2/testdata/d2compiler/TestCompile/url_link_non_url_tooltip_ok.d2,0:43:43-0:92:92", "value": [ { - "string": "note: url.ParseRequestURI might see this as a URL", - "raw_string": "note: url.ParseRequestURI might see this as a URL" + "string": "note: url.ParseRequestURI might see this as a URL" } ] } diff --git a/testdata/d2compiler/TestCompile/url_tooltip.exp.json b/testdata/d2compiler/TestCompile/url_tooltip.exp.json index 5191349eda..302556ce6d 100644 --- a/testdata/d2compiler/TestCompile/url_tooltip.exp.json +++ b/testdata/d2compiler/TestCompile/url_tooltip.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/url_tooltip.d2,0:13:13-0:31:31", "value": [ { - "string": "https://google.com", - "raw_string": "https://google.com" + "string": "https://google.com" } ] } diff --git a/testdata/d2compiler/TestCompile/wrong_column_index.exp.json b/testdata/d2compiler/TestCompile/wrong_column_index.exp.json index 555ed3efc1..17739cdd21 100644 --- a/testdata/d2compiler/TestCompile/wrong_column_index.exp.json +++ b/testdata/d2compiler/TestCompile/wrong_column_index.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,1:9:24-1:18:33", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -121,8 +120,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,2:23:57-2:34:68", "value": [ { - "string": "primary_key", - "raw_string": "primary_key" + "string": "primary_key" } ] } @@ -159,8 +157,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,3:15:85-3:18:88", "value": [ { - "string": "int", - "raw_string": "int" + "string": "int" } ] } @@ -192,8 +189,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,4:13:102-4:19:108", "value": [ { - "string": "string", - "raw_string": "string" + "string": "string" } ] } @@ -225,8 +221,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,5:7:116-5:10:119", "value": [ { - "string": "int", - "raw_string": "int" + "string": "int" } ] } @@ -292,8 +287,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,6:27:147-6:38:158", "value": [ { - "string": "foreign_key", - "raw_string": "foreign_key" + "string": "foreign_key" } ] } @@ -364,8 +358,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,7:30:190-7:41:201", "value": [ { - "string": "foreign_key", - "raw_string": "foreign_key" + "string": "foreign_key" } ] } @@ -431,8 +424,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,11:9:243-11:18:252", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -464,8 +456,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,12:6:259-12:9:262", "value": [ { - "string": "int", - "raw_string": "int" + "string": "int" } ] } @@ -531,8 +522,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,13:31:294-13:42:305", "value": [ { - "string": "foreign_key", - "raw_string": "foreign_key" + "string": "foreign_key" } ] } @@ -603,8 +593,7 @@ "range": "d2/testdata/d2compiler/TestCompile/wrong_column_index.d2,14:30:337-14:41:348", "value": [ { - "string": "foreign_key", - "raw_string": "foreign_key" + "string": "foreign_key" } ] } diff --git a/testdata/d2compiler/TestCompile2/boards/isFolderOnly.exp.json b/testdata/d2compiler/TestCompile2/boards/isFolderOnly.exp.json index 75999c067f..31148f4472 100644 --- a/testdata/d2compiler/TestCompile2/boards/isFolderOnly.exp.json +++ b/testdata/d2compiler/TestCompile2/boards/isFolderOnly.exp.json @@ -253,8 +253,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/boards/isFolderOnly.d2,12:13:130-12:26:143", "value": [ { - "string": "one two three", - "raw_string": "one two three" + "string": "one two three" } ] } @@ -608,8 +607,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/boards/isFolderOnly.d2,12:13:130-12:26:143", "value": [ { - "string": "one two three", - "raw_string": "one two three" + "string": "one two three" } ] } @@ -882,8 +880,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/boards/isFolderOnly.d2,12:13:130-12:26:143", "value": [ { - "string": "one two three", - "raw_string": "one two three" + "string": "one two three" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json index f03a3b5cac..091481ef50 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json @@ -54,8 +54,7 @@ "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" + "string": "im a var" } ] } @@ -92,31 +91,7 @@ "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" + "string": "1 im a var 2" } ] } @@ -177,7 +152,7 @@ ], "attributes": { "label": { - "value": "1 " + "value": "1 im a var 2" }, "labelDimensions": { "width": 0, diff --git a/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.exp.json new file mode 100644 index 0000000000..1be8d8d91e --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.exp.json @@ -0,0 +1,176 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,0:0:0-5:0:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im a var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,4:0:25-4:14:39", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,4:0:25-4:2:27", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.d2,4:4:29-4:14:39", + "value": [ + { + "string": "1 im a var 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/double-quoted.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.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 im a var 2" + }, + "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/TestCompile2/vars/basic/edge_label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json index 55c12d65df..9f1b92d8d8 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } @@ -111,20 +110,11 @@ ], "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:8:33-4:12:37", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:5:14-2:13:22", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:10:35-4:11:36", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json index 41f1864aed..3d376033f1 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } @@ -88,20 +87,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:4:29-4:8:33", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:5:14-2:13:22", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:6:31-4:7:32", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json index b0bc434b44..37a8d38196 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json @@ -102,8 +102,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:14:49-4:17:52", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -181,42 +180,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:38:109", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:14:49-4:17:52", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:16:87-9:22:93", - "value": [ - { - "string": "colors", - "raw_string": "colors" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:23:94-9:30:101", - "value": [ - { - "string": "primary", - "raw_string": "primary" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:31:102-9:37:108", - "value": [ - { - "string": "button", - "raw_string": "button" - } - ] - } + "string": "red" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json index b9898d3207..a7a5fb0e59 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json @@ -108,22 +108,10 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:25:54", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:17:46-5:24:53", - "value": [ - { - "string": "columns", - "raw_string": "columns" - } - ] - } - } - ] + "number": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:10:19-2:11:20", + "raw": "2", + "value": "2" } } } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.exp.json new file mode 100644 index 0000000000..f2717ee096 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.exp.json @@ -0,0 +1,173 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,0:0:0-5:0:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,2:5:14-2:13:22", + "value": [ + { + "string": "im a var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,4:0:25-4:14:39", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,4:0:25-4:2:27", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "single_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.d2,4:4:29-4:14:39", + "raw": "", + "value": "1 ${x} 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/single-quoted.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.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 ${x} 2" + }, + "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/TestCompile2/vars/basic/style.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json index 6925d574c3..43318c7222 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:17:26-2:20:29", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -123,20 +122,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:30:68", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:17:26-2:20:29", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:16:54-5:29:67", - "value": [ - { - "string": "primary-color", - "raw_string": "primary-color" - } - ] - } + "string": "red" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json index a336caf0b8..7bde70cfec 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } @@ -136,20 +135,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:12:55", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:10:53-7:11:54", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } + "string": "im a var" } ] } @@ -246,8 +236,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } @@ -283,8 +272,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json index a256b8aabd..01550e52ad 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "string": "im x var" } ] } @@ -164,8 +163,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "string": "im y var" } ] } @@ -198,20 +196,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:11:93", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:9:91-10:10:92", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } + "string": "im x var" } ] } @@ -239,20 +228,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:11:105", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:9:103-11:10:104", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } + "string": "im y var" } ] } @@ -366,8 +346,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "string": "im y var" } ] } @@ -400,20 +379,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:11:177", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:9:175-19:10:176", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } + "string": "im x var" } ] } @@ -441,20 +411,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:11:189", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:9:187-20:10:188", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } + "string": "im y var" } ] } @@ -551,8 +512,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "string": "im x var" } ] } @@ -583,8 +543,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "string": "im y var" } ] } @@ -620,8 +579,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "string": "im x var" } ] } @@ -652,8 +610,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "string": "im y var" } ] } @@ -834,8 +791,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "string": "im x var" } ] } @@ -866,8 +822,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "string": "im y var" } ] } @@ -903,8 +858,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "string": "im x var" } ] } @@ -935,8 +889,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "string": "im y var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json index a5a4d56e96..ad2348046f 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json @@ -3,7 +3,7 @@ "name": "", "isFolderOnly": false, "ast": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,0:0:0-21:0:190", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,0:0:0-13:0:109", "nodes": [ { "map_key": { @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "string": "im x var" } ] } @@ -164,8 +163,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", "value": [ { - "string": "im replaced x var", - "raw_string": "im replaced x var" + "string": "im replaced x var" } ] } @@ -198,181 +196,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:11:102", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:9:100-10:10:101", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } - } - } - } - ] - } - } - } - } - ] - } - } - } - }, - { - "map_key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,13:0:109-20:1:189", - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,13:0:109-13:6:115", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,13:0:109-13:6:115", - "value": [ - { - "string": "layers", - "raw_string": "layers" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "map": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,13:8:117-20:1:189", - "nodes": [ - { - "map_key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,14:2:121-19:3:187", - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,14:2:121-14:4:123", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,14:2:121-14:4:123", - "value": [ - { - "string": "l2", - "raw_string": "l2" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "map": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,14:6:125-19:3:187", - "nodes": [ - { - "map_key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,15:4:131-17:5:171", - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,15:4:131-15:8:135", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,15:4:131-15:8:135", - "value": [ - { - "string": "vars", - "raw_string": "vars" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "map": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,15:10:137-17:5:171", - "nodes": [ - { - "map_key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:6:145-16:26:165", - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:6:145-16:7:146", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:6:145-16:7:146", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:9:148-16:26:165", - "value": [ - { - "string": "im replaced x var", - "raw_string": "im replaced x var" - } - ] - } - } - } - } - ] - } - } - } - }, - { - "map_key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:11:183", - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:5:177", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:5:177", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:7:179-18:11:183", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:9:181-18:10:182", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } + "string": "im replaced x var" } ] } @@ -416,180 +244,6 @@ }, "edges": null, "objects": null, - "layers": [ - { - "name": "l2", - "isFolderOnly": false, - "ast": { - "range": ",1:0:0-2:0:0", - "nodes": [ - { - "map_key": { - "range": ",0:0:0-0:0:0", - "key": { - "range": ",0:0:0-0:0:0", - "path": [ - { - "unquoted_string": { - "range": ",0:0:0-0:0:0", - "value": [ - { - "string": "vars" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "map": { - "range": ",1:0:0-2:0:0", - "nodes": [ - { - "map_key": { - "range": ",0:0:0-0:0:0", - "key": { - "range": ",0:0:0-0:0:0", - "path": [ - { - "unquoted_string": { - "range": ",0:0:0-0:0:0", - "value": [ - { - "string": "x" - } - ] - } - } - ] - }, - "primary": { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:9:148-16:26:165", - "value": [ - { - "string": "im replaced x var", - "raw_string": "im replaced x var" - } - ] - } - }, - "value": {} - } - } - ] - } - } - } - }, - { - "map_key": { - "range": ",0:0:0-0:0:0", - "key": { - "range": ",0:0:0-0:0:0", - "path": [ - { - "unquoted_string": { - "range": ",0:0:0-0:0:0", - "value": [ - { - "string": "x" - } - ] - } - } - ] - }, - "primary": { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,16:9:148-16:26:165", - "value": [ - { - "string": "im replaced x var", - "raw_string": "im replaced x var" - } - ] - } - }, - "value": {} - } - } - ] - }, - "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": "x", - "id_val": "x", - "references": [ - { - "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:5:177", - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,18:4:176-18:5:177", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - }, - "key_path_index": 0, - "map_key_edge_index": -1 - } - ], - "attributes": { - "label": { - "value": "im replaced x var" - }, - "labelDimensions": { - "width": 0, - "height": 0 - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": null - }, - "zIndex": 0 - } - ] - } - ], "scenarios": [ { "name": "l", @@ -643,8 +297,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", "value": [ { - "string": "im replaced x var", - "raw_string": "im replaced x var" + "string": "im replaced x var" } ] } @@ -680,8 +333,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", "value": [ { - "string": "im replaced x var", - "raw_string": "im replaced x var" + "string": "im replaced x var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json index a4b99e65d8..8c02a62f5b 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } @@ -136,20 +135,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:12:58", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:10:56-7:11:57", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } + "string": "im a var" } ] } @@ -246,8 +236,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } @@ -283,8 +272,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json index 585e192ee3..10ff44f21b 100644 --- a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } @@ -88,20 +87,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:4:29-4:8:33", - "spread": false, - "path": [ + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:5:14-2:13:22", + "value": [ { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:6:31-4:7:32", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } + "string": "im a var" } ] } @@ -133,8 +123,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,5:4:38-5:13:47", "value": [ { - "string": "not a var", - "raw_string": "not a var" + "string": "not a var" } ] } From 741a9aa306ad0c65423a276c5a438ca5afd7d353 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 13:40:44 -0700 Subject: [PATCH 10/40] cleanup --- d2compiler/compile.go | 13 -------- d2compiler/compile_test.go | 26 +++++++++++++++- d2ir/compile.go | 30 ++++--------------- .../TestCompile2/vars/errors/edge.exp.json | 11 +++++++ .../TestCompile2/vars/errors/map.exp.json | 11 +++++++ .../TestCompile2/vars/errors/missing.exp.json | 2 +- 6 files changed, 53 insertions(+), 40 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/edge.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/map.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 9c27c14590..c1800e5715 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -282,19 +282,6 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { if len(f.Map().Edges) > 0 { c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") } - // for _, varField := range f.Map().Fields { - // if varField.Map() != nil { - // c.errorf(varField.LastRef().AST(), "vars must be simple") - // } - // for _, cf := range classesField.Map().Fields { - // if _, ok := d2graph.ReservedKeywords[cf.Name]; !ok { - // c.errorf(cf.LastRef().AST(), "%s is an invalid class field, must be reserved keyword", cf.Name) - // } - // if cf.Name == "class" { - // c.errorf(cf.LastRef().AST(), `"class" cannot appear within "classes"`) - // } - // } - // } } return } else if isReserved { diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 22373fac5e..1912a92584 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3470,7 +3470,31 @@ vars: { x: hey } hi: ${z} -`, "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z") +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable "z"`) + }, + }, + { + name: "edge", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x -> a +} +hi +`, "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2:3:3: vars cannot contain an edge") + }, + }, + { + name: "map", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + colors: { + button: red + } +} +hi: ${colors} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable "colors"`) }, }, } diff --git a/d2ir/compile.go b/d2ir/compile.go index 8e69091de5..4a7ef23c0b 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -153,9 +153,12 @@ func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d resolved = r } if resolved == nil { - c.errorf(mk, "could not resolve variable %s", strings.Join(substitution.IDA(), ".")) + c.errorf(mk, `could not resolve variable "%s"`, strings.Join(substitution.IDA(), ".")) } else { - // TODO maps + if resolved.Composite != nil { + c.errorf(mk, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), ".")) + return nil + } return resolved } return nil @@ -211,9 +214,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { } for _, n := range ast.Nodes { switch { - case n.Substitution != nil: - println("\033[1;31m--- DEBUG:", "=======================", "\033[m") - c.errorf(n.Substitution, "only values can use substitutions") case n.MapKey != nil: c.compileKey(&RefContext{ Key: n.MapKey, @@ -350,15 +350,6 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) c.overlayClasses(f.Map()) } } - // } else if refctx.Key.Value.Substitution != nil { - // vars := ParentBoard(f).Map().GetField("vars") - // resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution) - // if resolved != nil { - // f.Primary_ = &Scalar{ - // parent: f, - // Value: resolved, - // } - // } } else if refctx.Key.Value.ScalarBox().Unbox() != nil { // If the link is a board, we need to transform it into an absolute path. if f.Name == "link" { @@ -368,8 +359,6 @@ 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 } } @@ -538,15 +527,6 @@ func (c *compiler) compileEdges(refctx *RefContext) { } } c.compileMap(e.Map_, refctx.Key.Value.Map, refctx.ScopeAST) - // } else if refctx.Key.Value.Substitution != nil { - // vars := ParentBoard(e).Map().GetField("vars") - // resolved := c.resolveSubstitution(vars.Map(), refctx.Key, refctx.Key.Value.Substitution) - // if resolved != nil { - // e.Primary_ = &Scalar{ - // parent: e, - // Value: resolved, - // } - // } } else if refctx.Key.Value.ScalarBox().Unbox() != nil { e.Primary_ = &Scalar{ parent: e, diff --git a/testdata/d2compiler/TestCompile2/vars/errors/edge.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/edge.exp.json new file mode 100644 index 0000000000..b83fda7d8c --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/edge.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2,2:2:11-2:8:17", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2:3:3: vars cannot contain an edge" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/errors/map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/map.exp.json new file mode 100644 index 0000000000..0d8156660f --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/map.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2,6:0:43-6:13:56", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable \"colors\"" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json index 64d4957842..bf2e45fed9 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json @@ -4,7 +4,7 @@ "errs": [ { "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2,4:0:20-4:8:28", - "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable z" + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable \"z\"" } ] } From b193b9be8a8d26dcafbba5bf3deecf4c2070097f Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 13:44:00 -0700 Subject: [PATCH 11/40] cleanup --- d2ast/d2ast.go | 6 ------ d2ir/compile.go | 6 ------ d2parser/parse.go | 3 --- .../TestCompile2/vars/basic/edge_label.exp.json | 2 +- .../TestCompile2/vars/basic/label.exp.json | 2 +- .../TestCompile2/vars/basic/nested.exp.json | 2 +- .../TestCompile2/vars/basic/number.exp.json | 11 +++++++---- .../TestCompile2/vars/basic/style.exp.json | 2 +- .../TestCompile2/vars/boards/layer.exp.json | 4 ++-- .../TestCompile2/vars/boards/overlay.exp.json | 16 ++++++++-------- .../TestCompile2/vars/boards/replace.exp.json | 4 ++-- .../TestCompile2/vars/boards/scenario.exp.json | 4 ++-- .../TestCompile2/vars/override/label.exp.json | 2 +- 13 files changed, 26 insertions(+), 38 deletions(-) diff --git a/d2ast/d2ast.go b/d2ast/d2ast.go index 25d325cf51..6313dbe0dc 100644 --- a/d2ast/d2ast.go +++ b/d2ast/d2ast.go @@ -423,7 +423,6 @@ func (s *BlockString) value() {} func (a *Array) value() {} func (m *Map) value() {} func (i *Import) value() {} -func (i *Substitution) value() {} func (n *Null) scalar() {} func (b *Boolean) scalar() {} @@ -924,7 +923,6 @@ type ValueBox struct { Array *Array `json:"array,omitempty"` Map *Map `json:"map,omitempty"` Import *Import `json:"import,omitempty"` - Substitution *Substitution `json:"substitution,omitempty"` } func (vb ValueBox) Unbox() Value { @@ -949,8 +947,6 @@ func (vb ValueBox) Unbox() Value { return vb.Map case vb.Import != nil: return vb.Import - case vb.Substitution != nil: - return vb.Substitution default: return nil } @@ -979,8 +975,6 @@ func MakeValueBox(v Value) ValueBox { vb.Map = v case *Import: vb.Import = v - case *Substitution: - vb.Substitution = v } return vb } diff --git a/d2ir/compile.go b/d2ir/compile.go index 4a7ef23c0b..9b880b767a 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -109,11 +109,6 @@ func (c *compiler) resolveSubstitutions(refctx *RefContext) { } switch { - case refctx.Key.Value.Substitution != nil: - resolvedField := c.resolveSubstitution(varsMap, refctx.Key, refctx.Key.Value.Substitution) - if resolvedField != nil { - refctx.Key.Value = d2ast.MakeValueBox(resolvedField.Primary().Value) - } case refctx.Key.Value.UnquotedString != nil: for i, box := range refctx.Key.Value.UnquotedString.Value { if box.Substitution != nil { @@ -245,7 +240,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { } func (c *compiler) compileKey(refctx *RefContext) { - // resolve substitutions here c.resolveSubstitutions(refctx) if len(refctx.Key.Edges) == 0 { c.compileField(refctx.ScopeMap, refctx.Key.Key, refctx) diff --git a/d2parser/parse.go b/d2parser/parse.go index 490505e4d2..fa64531a31 100644 --- a/d2parser/parse.go +++ b/d2parser/parse.go @@ -1596,9 +1596,6 @@ func (p *parser) parseValue() d2ast.ValueBox { case '@': box.Import = p.parseImport(false) return box - case '$': - box.Substitution = p.parseSubstitution(false) - return box } p.replay(r) diff --git a/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json index 9f1b92d8d8..f58e674290 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json @@ -111,7 +111,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:8:33-4:9:34", "value": [ { "string": "im a var" diff --git a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json index 3d376033f1..2e0d918a0a 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json @@ -88,7 +88,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:4:29-4:5:30", "value": [ { "string": "im a var" diff --git a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json index 37a8d38196..6fd7ef7619 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json @@ -181,7 +181,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:14:49-4:17:52", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:15:86", "value": [ { "string": "red" diff --git a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json index a7a5fb0e59..37d67c845d 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json @@ -108,10 +108,13 @@ }, "primary": {}, "value": { - "number": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:10:19-2:11:20", - "raw": "2", - "value": "2" + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:16:45", + "value": [ + { + "string": "2" + } + ] } } } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json index 43318c7222..47d41ae5d3 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json @@ -123,7 +123,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:17:26-2:20:29", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:15:53", "value": [ { "string": "red" diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json index 7bde70cfec..a489426334 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json @@ -136,7 +136,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", "value": [ { "string": "im a var" @@ -269,7 +269,7 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", "value": [ { "string": "im a var" diff --git a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json index 01550e52ad..24b73c55d9 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json @@ -197,7 +197,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90", "value": [ { "string": "im x var" @@ -229,7 +229,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102", "value": [ { "string": "im y var" @@ -380,7 +380,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174", "value": [ { "string": "im x var" @@ -412,7 +412,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186", "value": [ { "string": "im y var" @@ -576,7 +576,7 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174", "value": [ { "string": "im x var" @@ -607,7 +607,7 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186", "value": [ { "string": "im y var" @@ -855,7 +855,7 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90", "value": [ { "string": "im x var" @@ -886,7 +886,7 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102", "value": [ { "string": "im y var" diff --git a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json index ad2348046f..75089a991a 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json @@ -197,7 +197,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99", "value": [ { "string": "im replaced x var" @@ -330,7 +330,7 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99", "value": [ { "string": "im replaced x var" diff --git a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json index 8c02a62f5b..dbf4881e38 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json @@ -136,7 +136,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55", "value": [ { "string": "im a var" @@ -269,7 +269,7 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55", "value": [ { "string": "im a var" diff --git a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json index 10ff44f21b..72267b6260 100644 --- a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json @@ -88,7 +88,7 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:4:29-4:5:30", "value": [ { "string": "im a var" From 22bd50a7ef2370b5f53cfc56357b1d3eb9cfe721 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 13:45:58 -0700 Subject: [PATCH 12/40] tests --- .../TestCLI_E2E/internal_linked_pdf.exp.pdf | Bin 79993 -> 80096 bytes .../d2ir/TestCompile/classes/basic.exp.json | 15 +- .../TestCompile/classes/inherited.exp.json | 240 ++++++------------ .../TestCompile/classes/layer-modify.exp.json | 48 ++-- .../d2ir/TestCompile/classes/merge.exp.json | 30 +-- .../d2ir/TestCompile/classes/nested.exp.json | 45 ++-- .../d2ir/TestCompile/fields/label.exp.json | 6 +- .../d2ir/TestCompile/fields/nested.exp.json | 9 +- .../TestCompile/imports/nested/map.exp.json | 12 +- .../imports/nested/scalar.exp.json | 3 +- .../d2ir/TestCompile/imports/spread.exp.json | 6 +- .../d2ir/TestCompile/imports/value.exp.json | 12 +- .../d2ir/TestCompile/imports/vars/1.exp.json | 31 +-- .../TestCreate/make_scope_multiline.exp.json | 3 +- .../make_scope_multiline_spacing_1.exp.json | 3 +- .../make_scope_multiline_spacing_2.exp.json | 3 +- .../TestDelete/arrowhead_label.exp.json | 3 +- testdata/d2oracle/TestDelete/chaos_1.exp.json | 9 +- .../children_edge_conflicts.exp.json | 3 +- .../children_edges_flat_conflicts.exp.json | 6 +- .../children_flat_conflicts.exp.json | 3 +- .../children_multiple_conflicts.exp.json | 3 +- ...ldren_nested_referenced_conflicts.exp.json | 6 +- .../children_referenced_conflicts.exp.json | 3 +- .../TestDelete/container_near.exp.json | 6 +- .../delete_container_of_near.exp.json | 6 +- .../d2oracle/TestDelete/delete_icon.exp.json | 3 +- .../TestDelete/edge_decrement.exp.json | 12 +- .../d2oracle/TestDelete/multi_near.exp.json | 6 +- .../only_delete_edge_reserved.exp.json | 3 +- .../only_delete_obj_reserved.exp.json | 3 +- .../d2oracle/TestDelete/save_map.exp.json | 3 +- .../TestDelete/save_map_with_primary.exp.json | 3 +- .../TestDelete/shape_sql_table.exp.json | 6 +- .../d2oracle/TestDelete/table_refs.exp.json | 3 +- .../TestMove/append_multiple_styles.exp.json | 3 +- .../container_conflicts_generated.exp.json | 18 +- .../d2oracle/TestMove/container_near.exp.json | 3 +- testdata/d2oracle/TestMove/duplicate.exp.json | 3 +- .../d2oracle/TestMove/flat_merge.exp.json | 3 +- testdata/d2oracle/TestMove/flat_near.exp.json | 3 +- .../flat_reparent_with_map_value.exp.json | 3 +- ...lat_reparent_with_mixed_map_value.exp.json | 3 +- .../flat_reparent_with_value.exp.json | 3 +- .../d2oracle/TestMove/flat_style.exp.json | 3 +- testdata/d2oracle/TestMove/gnarly_1.exp.json | 6 +- .../include_descendants_near.exp.json | 3 +- ...ude_descendants_nested_reserved_2.exp.json | 3 +- ...ude_descendants_nested_reserved_3.exp.json | 3 +- .../TestMove/include_descendants_sql.exp.json | 6 +- .../into_container_with_flat_keys.exp.json | 6 +- .../d2oracle/TestMove/map_transplant.exp.json | 3 +- .../d2oracle/TestMove/map_with_label.exp.json | 3 +- .../d2oracle/TestMove/merge_reserved.exp.json | 6 +- testdata/d2oracle/TestMove/near.exp.json | 3 +- .../TestMove/nested_reserved_2.exp.json | 3 +- .../TestMove/nested_reserved_3.exp.json | 3 +- .../d2oracle/TestMove/parentheses.exp.json | 6 +- .../d2oracle/TestMove/slice_style.exp.json | 3 +- .../TestMove/underscore_merge.exp.json | 6 +- .../TestReconnectEdge/indexed_ref.exp.json | 3 +- .../preserve_old_obj.exp.json | 3 +- .../TestReconnectEdge/second_index.exp.json | 6 +- .../d2oracle/TestRename/container.exp.json | 9 +- testdata/d2oracle/TestRename/edges.exp.json | 3 +- testdata/d2oracle/TestRename/near.exp.json | 3 +- .../d2oracle/TestSet/classes-style.exp.json | 9 +- .../TestSet/dupe-classes-style.exp.json | 9 +- testdata/d2oracle/TestSet/edge.exp.json | 3 +- testdata/d2oracle/TestSet/edge_chain.exp.json | 6 +- .../TestSet/edge_chain_nested_set.exp.json | 3 +- .../edge_flat_merge_arrowhead.exp.json | 3 +- .../d2oracle/TestSet/edge_index_case.exp.json | 3 +- .../TestSet/edge_index_nested.exp.json | 3 +- .../TestSet/edge_merge_arrowhead.exp.json | 3 +- .../TestSet/edge_nested_label_set.exp.json | 3 +- .../TestSet/edge_replace_arrowhead.exp.json | 3 +- .../edge_replace_arrowhead_indexed.exp.json | 3 +- .../TestSet/edge_set_arrowhead.exp.json | 3 +- testdata/d2oracle/TestSet/icon.exp.json | 3 +- .../d2oracle/TestSet/inline_style.exp.json | 3 +- testdata/d2oracle/TestSet/label.exp.json | 3 +- .../d2oracle/TestSet/label_replace.exp.json | 3 +- .../d2oracle/TestSet/map_key_missing.exp.json | 3 +- .../d2oracle/TestSet/nested_alex.exp.json | 9 +- .../TestSet/replace_arrowhead.exp.json | 3 +- .../TestSet/replace_arrowhead_map.exp.json | 3 +- .../TestSet/replace_fill_pattern.exp.json | 3 +- .../d2oracle/TestSet/replace_link.exp.json | 3 +- .../d2oracle/TestSet/replace_shape.exp.json | 3 +- .../TestSet/replace_style_edgecase.exp.json | 3 +- .../d2oracle/TestSet/replace_tooltip.exp.json | 3 +- .../TestSet/scenarios-arrowhead.exp.json | 9 +- .../scenarios-label-primary-missing.exp.json | 6 +- ...scenarios-nested-usable-ref-style.exp.json | 3 +- .../scenarios-usable-ref-style.exp.json | 3 +- .../TestSet/set_fill_pattern.exp.json | 3 +- .../d2oracle/TestSet/set_tooltip.exp.json | 3 +- testdata/d2oracle/TestSet/shape.exp.json | 3 +- .../unapplied-classes-style-2.exp.json | 6 +- .../TestSet/unapplied-classes-style.exp.json | 6 +- 101 files changed, 288 insertions(+), 544 deletions(-) diff --git a/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf index 87b6e616ebd993c5764f71d54757f39e0f941759..c3f44895dd54e116e5a1400d3a6fee089be81b9d 100644 GIT binary patch delta 5771 zcmZu#c{r49-?ofhW9(!bWQ&-^EV7djk;ctAG(hJuDk_Y4FHd_L7e-&o zm)G^~i^3tR4{~NNIBjDR$+9}tWFd*h(nh`%7upIw4?XR$WhR4R&c%Qf~DN-R96n(KegY0 zF&`_cewc8kvNyZ#=IhQw3msD%;`KBK@ZZ(jnK7!wp#z&xdr)G!OeQOe71vfe16zqW z-q=!fEeE2^fM8CeCnaS(Fqs2CbpRO2@!z!|IZYs5N_PzLX$9uGF(_+_gjkmJ_1QG`#U{N#qa&j^QBM$?#|O(|uf6iuXudL*Lj!HE%2mdYFTGDe9u zk6|_BnH!Rco^`Oq??Nxw<)JX>bw)XTdshdqdr$-l4aZidLoJwqoCkaw1KI?gbKfYGfiW0*Sd86dp+3ELuK{qto;B1m1l2Q6N#qxLLuMcDl zLSwg%?fYz2zIRv`bl%6|Zo|X*g8r42S|4X6s?9pds1u)jP%sY#B1Db(ed13wnNhji zX9s}`%TVsxhcDKEzgR)Dz*OOY*o->+6<)5$fprCn=c-h23d1igyuoJTfy0*$l<6pb zYD2@h!{*jQp(aY!o)#yjrBPqE{tBZ$+AZ{%3@}S=R>dD%^scIDmuc{4dGGDU$rxB= z#B`puhEnj_!)YxWKT&#Lpx&8&d)7GNfI^3Qv$QWq zGLOs3e~_f34Iw05R|Evl=LxE8{G?piG!vGUQ5CWjx-P_LmpxQZnk9aoqOH|l4CZc2 zT5q((XwtVHvl0%cQjkPeLbNoW!|`gUIRkC%9Tmh8Rjtw$mPRP#mMCOzkBC{HXh8NP zM^e(arUn2Y+`byQG;Zq6JF38RUTkE3o+6{AM}P3!Es>^2tFJu9Rz15~DTv&JZq?%g z73Rq+!TJr`-y^m+*$Fe6V=*)YR>FnI?Z2dDFUFf#wGK-_3QpMB3Gg)f){P4;?NqJw zt;wx^{hZtauxH%n>^)@EZ!+c=-E| zH`Q&aAHU?x@+M-gYs@AvG`2V5aVM}ht;ng>+9}PWf6a}{eD<-(&!kwW* zH$ZktDVT>>3mWbg&dU@p47rsMrWIl7_1@CTuK1=?$As0&_vevDw6op|Ud;i{n`svT z+p~AWc-W)Wn5RA?xu9y$>T`Ng;JP0{b&a1abSDcN%p2kUhdF1O&_lz+rlzK`re@~m zqhn);6Peq2Ttj@t*r7Ns72VT03J}hYJD8^_%|S*jNX=O{nM1&{pAzr)wCc<9&iSf? z9j7|dArc(1GQMV2H6A@~^mB;VcgY1{B|N=N&cNO5atcbSaxwGkUZ1q+KF?`=>r$W7 zaatw%Kgjm--(0gYb~1iAaRi?FlP8lypkghwu91-O3iHuh!t=pUD?R_svpr?(9h)y` zMoDZ}$P70BVDKO_)U(WQiMWa=IB5VKb$a#0-NuBu(Wbc z*Wrr1Q@8nLqAmlhy{hSXR5q~%3+73?Og4I+mkC0Sc7<+KiP@gbD>AN@Q=pmhkcFZG z(34X+F!Xkew7Ri4Aoudjnabc)+hJHaIc6@ec$sQtsLBClvYxhj>Xu|~56w=8%sbiH z^*(#ag+_`scT`+`4E#NgM%LG6T2nfKl3Mi~S8#|;4zJxAve8C?(=@>&*;w&<+(fWV zcXVy;w$^OjC{9>)_5L&%)zYh;2Y)j+Q+`KS9AXQhf(P(LUd#B^qjGppZIL?>$`|>Zbl-0@D#7OBK z9#L-+*#z8JFj(RCM`}?80mor+@BO(HwQlagWWWMox2 zlFsr)!RgLXK#8w;2$c3j9U_Wu7GU~8fDR3SaBB6AzNN6)ne$G4a`U})i!GZ25*
mit3PXLj5Qlah|N1JW$#+IbfA zjm;-&+`gRy=x4J?mnN1=^fyosMnZno?fbFs51>=FwGh(K$zX13OwTz8T z9kUlm2hVFnO)*idaSq;j?XXo@{y=3YJ`kHT_c0{i?Tbh#g8C+s+9ZE~7s zxM;|~bYC4aQ0``I~m~WF(x25Zot*({blkJ<;TytCj#C&J#qcXrA)iYm;N#KmZ>;Bj+|K5 z48R*tg%%-DN2Lc*)sr4u;=PcgP*2FR=ze}yqf9@PFcVGAq%cOpIu;6+^xc(OoM-p# z>AyN(ovO}X9qzMJamf}BIc=MK7olZ5??Itz^=XJV&_vdAGo*_s`vbHjq9|oQnt#jD z8B#l!oHx{!|GMhH+2XGsBJ}A|i}`DS#pLi6?pr<>j&mH1!Rpo_>R}~}B48yr2e@wp z*|hOciO7uin`+^mKO}YFClxxjvu9@Z4i7x}KRHqCk>4pB;jRW0AS(DRXWN|Z%nX+9 z3gS2YmzENchK;SV@3zAwbB5?MlxAV%mE|k?6dZr71YXwC;AB{)v>G*H)R?Q)ptO@_ z-r^LD!KoLj%i|ad3R)}nvC3&C0aWmD`IRxJ7BbZcQ!tOO?Pwx}BnVe+Mxzp*naxI= zCH@T1$C3veN2-Jb@*#u|R`jj!`H0ydH7Eqxac-l$?cSBoZ{oMNZ3GCs`7^y`F#Sj> z4K<~Mz;1XzBMG`#AEMics z`IF|);=_{_^ZE;lAY4!b6hiGLFy#9juL+%xay+mL-zmEI{Gt>T;L-7gsM zJ%wrT-y6QRSt_H`3epNu#@ZlUjm~?vS1i_YAl&rTCxXtx3!5cI)eB-3&RVBF;@fOO^XpipSZ_bT8P)$Wh;94`Y4v5qvW;_Hkn)3YT2A4 zqlY4H`>T-LJ5(31_B@jV0WObhyNPcxGH>{Oskfo=Z<0wJ_P z2)Vbride+*77R0$G{sfj)lR1j_zkOH_X-e7hZlE+_Md%ojuTYQSK%Ib=kHTd2>R7l zD!6;@=kN{&s&WPU4qWt_mGF}aUw*81+K#XofC@AoqxE!9*QCu-+2kF~zvu%!QNpNR z+_isLxeygcBJJcg2!P2#G@-Pz&qg=Muh{4aHD(jZN|n|=tJ?J!%m^0@bE~2cpyYFc z^E?a*Qe$?d3+Ac4cDIEH3LargiEc9!PL4n*|0GBQPXDo%$7``UNazeVwNt^(xF z^J)AW`Y8xkWnpaWH*`-vImt9r1z%lMBqAw!4Jl(*cxL@e+pLczDXi;=y+F>YKA@6x zx0ymUR{WgjN@;`l>V1`kgfH8wCnNgpEgBJ1J~@^#+8$UiyJV1NV-z>;cqrJCHZr{KM1f`zq(q#fsLLTe1w zOtk}rgXEi;O>u@+bwHCguk>m<-05Uc8a1oe(RTS=M)lFjp+A9+MqN_6)E95_u``h- zUx4+LVk)Vd+b~<+NM78su$ZYoCRfxv?QkddfVZ@__}!yWFk?u3=Fi>Fi@?2m`zJf3 zXz=kund7UTR)#p&vG}ountGS#NhM7-n~J(WwcBr6PX__c<^VU>#h51}-C+ngRk;#} zvCwYdGgejq+$6rZ=-9EhHc5Wa$<*xYHv?R^hgN6tgZBrs1=izukrqml^cs44-D5i$ z15@KykeFPP!t06bvpAPP>*G6grx~@l2gZY9o)=M`t<;W%$zQ&|DRkR+Kb-U#ekWI# z2~91j6-U9v>wz6=qO8@?>8JjS;ZZQZ_}q1{_LjI(=a)cn1s1#2r=@Ny}o#N}E*`E|g9jn_T9*$9J#$%3OvfNBp%!9jDf~U+m}hIl91YetDbAoT0*Q5RFk3g}Dbg zc7)`0-x$C+S8e>&`Ls_(P+^vGOS7PyMb-Xng?_O~pi%tl=)!`TFfEjP6f>!PnjQK3SzTy6%i!&F@FU`x6DfhCAGyw-fAiev7y) zM5r^nh08wD$nfUP0ErWn(2bmE^Ja7;zxCSJ*B>Qv9$6tu2E$pv{Hb`E^`)fr*2iI` z$BVtjla}!tA9mlJyRXXedUbT$fhMdif$lAt9N}6fuNu|09!)1`O$*1GQTp{)p zfQjko-Q>f%Ar;zY}U5e={AYmvpOhMir4Y#$kgJJJtF$y*q6bfet$D!nr zwg@}SU8IdX4vIjgaG)sd#V~L<94Rl4Kua;oU3Ig&WaDKImArHj0Ye~R|2vnGjiOBA zL_=Y}K2TRE z(Fp9n)civX77qWD7@+`%|LGP|L0;j{y=W8?{bwO$572)K#3&#!l$aDrETuN1JO;%m LCZ=V0nel%Bm0?-8 delta 5632 zcmZWtcU)83(xrsnf>fzNnn+6^kc1lPO0!(56bV(T2-4vY1qoe^bO8kgq*ozSg#ao7 zVhO#70wTQ^DKFgb-uK<-%^%76?K3lL&6+v0&(72uXm1r%sRcTR)X-q`^S|Zn;Kdk3 z`Rt0JyC@92bUSxi)|Fc{O+&oyrHh(&wO<~S!E?MP2m&y~10-DrafGd|A|gYLD{byl zb)D?P!n1#Pkv^EPiztG#ANlnvV8G#8MC17=@>ZST}wA-ejT&fZRcNkhK!!MHQRYGP@u`S7@7F??DkfRBc-fs~YB@EWNsYbHRr zkVRzZ#+Rtt;^IqJ>M2FeyG?!eOFjr@A#k%AjImcl^2ZUSEWA09tBgqTKLkXvXK;CM z#9nfY@{jU|(wQ+`HbbdyEB0Gf9Uj_P*HyW8RprbT4lFMgnR>#h)(FTXdzGtq(99GZ zWD;xS3^HXzTZ1vxryRk_9~1b0Yq#3O$x(ot;cL1@7S0Z37B zkCVO9gToAJiV#t-D6YLD_ZES;N`tRiPqX9BnCWEX**!$8w1ihw`nw+eOpzLoW_5@` zYAh@Y3xqyyR+dmDM(^a#<{WP;w27eENFy)0YLY__*rsAaq9BZHxwE%`u%8WN#?fpyg%SlZKdFhOb&0OIarUe>Vl|GG zSNuFQFWSdFg38-TWXwdPW#Fu7Mwf)A@{dL(HRS0+-Yr^2aGml2kCQo}ZSHyx1W;Qr>+aJu<)f z%{@1r-cK$bM|wy5W2Gd_RqcisNs?cl7qRhjVtJpU02OYCcE^SoQ+ym;V(P4XwMd?e zbX=x&vUj<8$@42xhhx)7J6l`hDY!Z8mecrgVYN8 zGVTqFbPb*01a?z_PH=z=CqQFlpo<~)<8_4LX#Rfr)vYQ5fzaBz92QeoSGTm}HJ9ux zZIN%?k|DNzwC*~r8B9sWo0jE>ynu&dJ88~yhP>L4E)cm({?6|o4k4r{n2VTl?58CM$As>^ zQy`2HoC*eL`31_LBhiZ&9&>U9_rJEa3%h54h_%lOpCL^vb(+Q87t&m;S2u!m>HH&X z*uy;T71XAg9Wme1Bl(;p$vS0Yuzhc(R>>pa7#VV~D?N`sv_ZeG^5DG&!bFiQx~XV& zA={EBan{X}AAEw@*&bwy4#P_4i0&Gh3yLda9B#)d|A_DlO?jV!uvxnAHtlm`10EQ;?BHRqI{Q5$Su@=)@ zL9B8%U@fLXaT&3sW20Fg1RpI*WId#yq*1bJR+4)v8eLi#8+*QpY1K_WvnEs11|h)Qrx5|DsW7h}m#6W} zWNDU{`ZYQO3>EPAEU;~EEN@k?k<1fSs;V3b(R+C%uPa*I`WiFkYnpkJS^MmASYsmQ zx~`Xn`f2nm^g8r*bhO?`M<=xClJRylQI%=*#E{HL-neqww(UGr4=NCqm6j3?si;(H zGngw4KU|2Oc4nZ0tqN1YFdJExXnhby-5AYm09f1$jA0kHunP4>1@;-|CfKV1A@(~& zQsYMb23-2FVp{w{Mccl~e$9{Fz7emcDzqo_A>{-;5!V}PLum`fZ4n2cGPb8D1oixE z%*=RdqW!$pRD#yNemdGAkEpO;gJ3nqH>>hWUz$kVZ zCF%8>6t0!WeJX8uEPlg$&S#6s!{bgkS)J|EJg~dv^*|LEh&v{Ck;lXxlY?7Q*=s2k!2bVU# zkRwJOt^2^;J6_C_A_g5zweqi7VC4CRGgc^xGzU#X+Gn-IZ@?Z(h^l*Jy&L)RQ>7<< zD~65k?pr5+c=_?jhSQZceV71iX7|W?UM=ag1vxm(9KZY5h>3^bZ-sPzx>vKd3{;-XXv% zAGdGbJ)*ED*JKv)JTi$l=)6vEG*w)PSec%$jbuulRVt#sb+4^o=U}sEG2YZP0jAkz z*Si0`!7dKEHCUz;FZMBf)vNV#!+A*85qSzJzkNhy&5pZ^%ciG!CVs&>aZ`p+;}c;C z9CybHx7i>2+0zqWxtz2>#uai4_?|tCXp3JT=!w9-=L#RaZ}q}vzYr8s%ylFvS2 z`mcpSW8yS2Hk5^!JQI?RW+o4L3_juPNv4l-I2@#P)!V)EkprWLG#D$siK;;o=?B~D z$phHVPUG4AiU}y{*BOeg6*8-TAoO!igQ^P2h_K9fm4DI=#q2cAOjzWTi0bQsA46)# z^+L*HCa9|vSp2jTy6=z+UMtEtghLBlVmtpKzFf$we;|7zuN!?}kpH)K1%f88^q89? z^YqY^w(26GN#ze&&d_1P>07-d)5Q5U>2?9~PVw@72ZN>K6b+}^w$%JjhA}_?&M_`U zaEx(BQ=`nl(3tR%!^(1g-nk8Aq~;5!g@l|Gp5Qf_ly7oBKtIo@N;wY~T(j~7H_W6y zC%r3pQ5T{td)c2IWZdb0HBfeP@M4;EAc9kj)BZIC`ud5MMKqYsggLt7w5p#_c=H6{ zOY1TlEEkx*GFK6rOZap+KEL`aoM3}(rM)RhPlWKzeFdQ%rq((U+l0Qlkf4`>gXbRj z<)Rn6>SNYC2469p*z~^zy@G%@{>O%c8|NFktNep)>MRHYPMmY1x(;34o#y}5aFZaG z)7w3R@dk6?_J9J1omPa=Q_aYHFz!4&N0A}&^{a337E|Be%sfOQgwqzPz+l`S*($<6 z{X9USF9N>n_Sp3lMKrcsFzr=0PvOIc+aiMtUj=cfg0Foy9sg@IrpF%1Nh=gsUZ~C< z^hakK6UvsW5d9uTr$|qn8aM$v%BQCQj^k{=g?>56gNvtz;z#VC)nF}ks9aRcI15%; z6p@TrUL6i()GNHh6vM|O&qA>Yv$Yk&rP2>;XqmH&f$dWTIR!(qBZn*zsu14=mt{61)O@6WrWgWC^{@xALVw{7UZ&_A~Rh|HU_)A*aKUooa!wWrK-{wyMB6;?j|P{3|Bx*pk#}}N@l+KF|YQ( zOlqJMj7!1(MdDF9YznL9K6N^=7oThDdGwWTUvs3V#{(d-Hp*tcq4+7*X*fMh)S<2D}Q3SNX@P~VFeW&GSivf)1AUeW#* z@J_`d_2P3~7x@MIU!xNe7Q_%sY=Bjz=cmc~DvzUuk2H#QIqd=GPikJ4xJEH0a1!G@ zBvlJ?Px(cS=A+bX^?(CT*$DJ;L|ZmA$s172Rt4L?KrD{$FtiLUk2je{NR(fz_x877 zIVll2j8-aQ@i<|>-55plxSw5p!K0b|E&2j>~76L ze$|?Mb-eo3TS&+gw$Y`VC;dqUqkr0mm87StQUYNrwX+XJd}j~Tg`Ebf)d48jXL9fB zB7tds=H$2|M2F>#x-|ES1B4you8;3*&@N>rgRLctb8@A8FnvW$y|!Mfbh?D}sYf3| z%NB)Z)++LwVmQM@v@R=X{8>BfDOXXX7W~scIM~_1pwio|$WAzT&{nx^`dpuxpnAai zL3I3}b@>(x_(J)Ppq?DGLeYn=m-6+JavAEpSVkGg2=efNQ>Q?)QAut!} z*5{%Jtr{)!lu`FbR?0a!1>|MU%@4{OAY}aC|0pWAZL+p&z{m4=++v-vu&{T#af5+* zm5qPDr)p=?b#7OgU?HIgF~3*5Pu@C;OPWHyTn{>U>zb9Bu*pFWFt1Nm-;f>OUYl1B zx&#$j*OxGNmdRKjTVY{IjMnWeG~vqXb;*|dLwHMC)szpebh?I3ptyAZW$VP$%8IJn zRODK++OvVpCz9@k3xgFr+$oR3E(fe#Nqqa6k6T4d#{bPKefI69hJfD9EyNcyv&qN5 zii-;h-dg2x+5CKo0hefTDwfpz&f+1TSudrUQ#KH>6T z;&$Y)RiAS0tM~iLum6R2bP; zyX9;~0xSJF3b#}Jb@jHnhY3Pq*NyBVu)w11ALP`pO^llPmd7n$6eo6<_8Z~L!_4+> zd$z|{gZg*(LWJMFWnA5Hls35;Z<&BDWj5QQE2ORxv`^*U-C1*{<4x?9H_A@Q3XCdy z6ISihbo*ZF4KJ_orT+MU#eIX9eU;s6)fz{WpVM4wwp6WC5A>#m?I9p6?-VTv1Aw*6 zs7>Kk26fscUmkG@FArbUPL@)=su5r_8hFp#S%`Y4rBqKYI;K(^@Zg}K<^_x(_@^Fc(iFfNFUAAja()QYh2yvEh5Z2;s zY7Dh5)7!QuAN`H&+qJgWKPyRF_*9loaPp|GX@olk1lVoAZqD-f4rJH8z@Lif4#>WX zW{xT<(G+;IC*!5-;^$Yh7^=l5#~@r?NuDi zldSA=(>5na<8b#$VXm^3fp4zSy5iMzvfOP-KBV{aY4XQ4NCJZ%NVcK-5MSo2U4uLR z3dd__Lh-A!i)f;%}WJ1Dp~D!@@LN-i)M$`J#_U?2*xv`{5VXK`g15(a}Ip(rUv zd1D_Z9S47B$XOi~1*n1|^uPDgXp|{axDXKN$p_*MVf^y~fkeVlX%)(p7yt(S?H&}S z3@3B?AA6_*OhM^iYf3QGzt@nzV?h-VsDH&fVfd#n@c*Qsa0Cqbdq6l+>0iJ~ii-aN zRzfJkfA>{FLKS{rQzobP&o$sAPh|z<|FQW88M3y&11l;bk-rm!BjAYNvr|UG5x?6Z fP%!1+l}4Zx5R~w=WF)0Nqas3qQCwWtRFCmLH&`6r diff --git a/testdata/d2ir/TestCompile/classes/basic.exp.json b/testdata/d2ir/TestCompile/classes/basic.exp.json index eed20a6c8d..b53c728174 100644 --- a/testdata/d2ir/TestCompile/classes/basic.exp.json +++ b/testdata/d2ir/TestCompile/classes/basic.exp.json @@ -75,8 +75,7 @@ "range": "TestCompile/classes/basic.d2,3:16:40-3:22:46", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -156,8 +155,7 @@ "range": "TestCompile/classes/basic.d2,3:16:40-3:22:46", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -245,8 +243,7 @@ "range": "TestCompile/classes/basic.d2,3:16:40-3:22:46", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -347,8 +344,7 @@ "range": "TestCompile/classes/basic.d2,3:16:40-3:22:46", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -478,8 +474,7 @@ "range": "TestCompile/classes/basic.d2,3:16:40-3:22:46", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } diff --git a/testdata/d2ir/TestCompile/classes/inherited.exp.json b/testdata/d2ir/TestCompile/classes/inherited.exp.json index f88697361e..48f9fe1448 100644 --- a/testdata/d2ir/TestCompile/classes/inherited.exp.json +++ b/testdata/d2ir/TestCompile/classes/inherited.exp.json @@ -19,8 +19,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -100,8 +99,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -189,8 +187,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -291,8 +288,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -422,8 +418,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -470,8 +465,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -551,8 +545,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -640,8 +633,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -742,8 +734,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -873,8 +864,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -921,8 +911,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1002,8 +991,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1091,8 +1079,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1193,8 +1180,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1224,8 +1210,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -1305,8 +1290,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -1394,8 +1378,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -1496,8 +1479,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -1627,8 +1609,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1757,8 +1738,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -1973,8 +1953,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -2045,8 +2024,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -2126,8 +2104,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -2215,8 +2192,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -2317,8 +2293,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -2348,8 +2323,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -2429,8 +2403,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -2518,8 +2491,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -2620,8 +2592,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -2751,8 +2722,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -2881,8 +2851,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -3123,8 +3092,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -3204,8 +3172,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -3293,8 +3260,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -3395,8 +3361,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -3426,8 +3391,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -3507,8 +3471,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -3590,8 +3553,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -3679,8 +3641,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -3762,8 +3723,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -3864,8 +3824,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -3965,8 +3924,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -4096,8 +4054,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -4226,8 +4183,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -4356,8 +4312,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -4679,8 +4634,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -4751,8 +4705,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -4832,8 +4785,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -4921,8 +4873,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -5023,8 +4974,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -5054,8 +5004,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -5135,8 +5084,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -5218,8 +5166,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -5307,8 +5254,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -5390,8 +5336,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -5492,8 +5437,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -5593,8 +5537,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -5724,8 +5667,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -5854,8 +5796,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -5984,8 +5925,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -6302,8 +6242,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -6383,8 +6322,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -6472,8 +6410,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -6574,8 +6511,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -6605,8 +6541,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -6686,8 +6621,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -6769,8 +6703,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -6858,8 +6791,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -6941,8 +6873,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -7043,8 +6974,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -7144,8 +7074,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -7275,8 +7204,7 @@ "range": "TestCompile/classes/inherited.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -7405,8 +7333,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -7535,8 +7462,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -8087,8 +8013,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -8293,8 +8218,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -8667,8 +8591,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -8873,8 +8796,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -9276,8 +9198,7 @@ "range": "TestCompile/classes/inherited.d2,11:24:161-11:27:164", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -9482,8 +9403,7 @@ "range": "TestCompile/classes/inherited.d2,22:24:308-22:28:312", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } diff --git a/testdata/d2ir/TestCompile/classes/layer-modify.exp.json b/testdata/d2ir/TestCompile/classes/layer-modify.exp.json index 087bc4de2d..07e31f3f8e 100644 --- a/testdata/d2ir/TestCompile/classes/layer-modify.exp.json +++ b/testdata/d2ir/TestCompile/classes/layer-modify.exp.json @@ -19,8 +19,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -100,8 +99,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -189,8 +187,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -291,8 +288,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -422,8 +418,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -470,8 +465,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -551,8 +545,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -569,8 +562,7 @@ "range": "TestCompile/classes/layer-modify.d2,7:30:96-7:33:99", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -694,8 +686,7 @@ "range": "TestCompile/classes/layer-modify.d2,7:30:96-7:33:99", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -783,8 +774,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -910,8 +900,7 @@ "range": "TestCompile/classes/layer-modify.d2,7:30:96-7:33:99", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -1012,8 +1001,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -1144,8 +1132,7 @@ "range": "TestCompile/classes/layer-modify.d2,7:30:96-7:33:99", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -1270,8 +1257,7 @@ "range": "TestCompile/classes/layer-modify.d2,2:16:36-2:22:42", "value": [ { - "string": "yellow", - "raw_string": "yellow" + "string": "yellow" } ] } @@ -1404,8 +1390,7 @@ "range": "TestCompile/classes/layer-modify.d2,7:30:96-7:33:99", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -1557,8 +1542,7 @@ "range": "TestCompile/classes/layer-modify.d2,7:30:96-7:33:99", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } diff --git a/testdata/d2ir/TestCompile/classes/merge.exp.json b/testdata/d2ir/TestCompile/classes/merge.exp.json index 1ad04233f4..fc776823c8 100644 --- a/testdata/d2ir/TestCompile/classes/merge.exp.json +++ b/testdata/d2ir/TestCompile/classes/merge.exp.json @@ -19,8 +19,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -100,8 +99,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -189,8 +187,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -360,8 +357,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -520,8 +516,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -597,8 +592,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -678,8 +672,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -767,8 +760,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -995,8 +987,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1241,8 +1232,7 @@ "range": "TestCompile/classes/merge.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } diff --git a/testdata/d2ir/TestCompile/classes/nested.exp.json b/testdata/d2ir/TestCompile/classes/nested.exp.json index 9fec0c6472..40fcad16d1 100644 --- a/testdata/d2ir/TestCompile/classes/nested.exp.json +++ b/testdata/d2ir/TestCompile/classes/nested.exp.json @@ -19,8 +19,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -100,8 +99,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -189,8 +187,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -291,8 +288,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -422,8 +418,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -534,8 +529,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -615,8 +609,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -704,8 +697,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -806,8 +798,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -937,8 +928,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1178,8 +1168,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1259,8 +1248,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1348,8 +1336,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1450,8 +1437,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } @@ -1581,8 +1567,7 @@ "range": "TestCompile/classes/nested.d2,2:16:38-2:22:44", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } diff --git a/testdata/d2ir/TestCompile/fields/label.exp.json b/testdata/d2ir/TestCompile/fields/label.exp.json index 278d708572..be26669b0c 100644 --- a/testdata/d2ir/TestCompile/fields/label.exp.json +++ b/testdata/d2ir/TestCompile/fields/label.exp.json @@ -7,8 +7,7 @@ "range": "TestCompile/fields/label.d2,0:3:3-0:6:6", "value": [ { - "string": "yes", - "raw_string": "yes" + "string": "yes" } ] } @@ -66,8 +65,7 @@ "range": "TestCompile/fields/label.d2,0:3:3-0:6:6", "value": [ { - "string": "yes", - "raw_string": "yes" + "string": "yes" } ] } diff --git a/testdata/d2ir/TestCompile/fields/nested.exp.json b/testdata/d2ir/TestCompile/fields/nested.exp.json index 042d9865ff..48b7c3ec1f 100644 --- a/testdata/d2ir/TestCompile/fields/nested.exp.json +++ b/testdata/d2ir/TestCompile/fields/nested.exp.json @@ -11,8 +11,7 @@ "range": "TestCompile/fields/nested.d2,0:5:5-0:8:8", "value": [ { - "string": "yes", - "raw_string": "yes" + "string": "yes" } ] } @@ -92,8 +91,7 @@ "range": "TestCompile/fields/nested.d2,0:5:5-0:8:8", "value": [ { - "string": "yes", - "raw_string": "yes" + "string": "yes" } ] } @@ -181,8 +179,7 @@ "range": "TestCompile/fields/nested.d2,0:5:5-0:8:8", "value": [ { - "string": "yes", - "raw_string": "yes" + "string": "yes" } ] } diff --git a/testdata/d2ir/TestCompile/imports/nested/map.exp.json b/testdata/d2ir/TestCompile/imports/nested/map.exp.json index b1dedaa355..e6f547dbdb 100644 --- a/testdata/d2ir/TestCompile/imports/nested/map.exp.json +++ b/testdata/d2ir/TestCompile/imports/nested/map.exp.json @@ -11,8 +11,7 @@ "range": "x.d2,1:8:13-1:14:19", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -70,8 +69,7 @@ "range": "x.d2,1:8:13-1:14:19", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -88,8 +86,7 @@ "range": "x.d2,2:8:28-2:12:32", "value": [ { - "string": "meow", - "raw_string": "meow" + "string": "meow" } ] } @@ -147,8 +144,7 @@ "range": "x.d2,2:8:28-2:12:32", "value": [ { - "string": "meow", - "raw_string": "meow" + "string": "meow" } ] } diff --git a/testdata/d2ir/TestCompile/imports/nested/scalar.exp.json b/testdata/d2ir/TestCompile/imports/nested/scalar.exp.json index ed273c2c07..750095b9a2 100644 --- a/testdata/d2ir/TestCompile/imports/nested/scalar.exp.json +++ b/testdata/d2ir/TestCompile/imports/nested/scalar.exp.json @@ -7,8 +7,7 @@ "range": "x.d2,0:3:3-0:7:7", "value": [ { - "string": "meow", - "raw_string": "meow" + "string": "meow" } ] } diff --git a/testdata/d2ir/TestCompile/imports/spread.exp.json b/testdata/d2ir/TestCompile/imports/spread.exp.json index cc2a0a3e57..b43e59e20a 100644 --- a/testdata/d2ir/TestCompile/imports/spread.exp.json +++ b/testdata/d2ir/TestCompile/imports/spread.exp.json @@ -7,8 +7,7 @@ "range": "x.d2,0:3:3-0:7:7", "value": [ { - "string": "wowa", - "raw_string": "wowa" + "string": "wowa" } ] } @@ -66,8 +65,7 @@ "range": "x.d2,0:3:3-0:7:7", "value": [ { - "string": "wowa", - "raw_string": "wowa" + "string": "wowa" } ] } diff --git a/testdata/d2ir/TestCompile/imports/value.exp.json b/testdata/d2ir/TestCompile/imports/value.exp.json index 8e5c0f0215..7828f5ba2d 100644 --- a/testdata/d2ir/TestCompile/imports/value.exp.json +++ b/testdata/d2ir/TestCompile/imports/value.exp.json @@ -11,8 +11,7 @@ "range": "x.d2,0:7:7-0:13:13", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -70,8 +69,7 @@ "range": "x.d2,0:7:7-0:13:13", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } @@ -88,8 +86,7 @@ "range": "x.d2,1:7:21-1:11:25", "value": [ { - "string": "meow", - "raw_string": "meow" + "string": "meow" } ] } @@ -147,8 +144,7 @@ "range": "x.d2,1:7:21-1:11:25", "value": [ { - "string": "meow", - "raw_string": "meow" + "string": "meow" } ] } diff --git a/testdata/d2ir/TestCompile/imports/vars/1.exp.json b/testdata/d2ir/TestCompile/imports/vars/1.exp.json index de94a458d1..7da5d84d7d 100644 --- a/testdata/d2ir/TestCompile/imports/vars/1.exp.json +++ b/testdata/d2ir/TestCompile/imports/vars/1.exp.json @@ -11,8 +11,7 @@ "range": "x.d2,0:6:6-0:18:18", "value": [ { - "string": "var replaced", - "raw_string": "var replaced" + "string": "var replaced" } ] } @@ -70,8 +69,7 @@ "range": "x.d2,0:6:6-0:18:18", "value": [ { - "string": "var replaced", - "raw_string": "var replaced" + "string": "var replaced" } ] } @@ -131,8 +129,7 @@ "range": "x.d2,0:6:6-0:18:18", "value": [ { - "string": "var replaced", - "raw_string": "var replaced" + "string": "var replaced" } ] } @@ -306,11 +303,10 @@ "name": "q", "primary": { "value": { - "range": "x.d2,0:6:6-0:18:18", + "range": "index.d2,0:20:20-0:21:21", "value": [ { - "string": "var replaced", - "raw_string": "var replaced" + "string": "var replaced" } ] } @@ -364,20 +360,11 @@ }, "primary": {}, "value": { - "substitution": { - "range": "index.d2,0:20:20-0:27:27", - "spread": false, - "path": [ + "unquoted_string": { + "range": "index.d2,0:20:20-0:21:21", + "value": [ { - "unquoted_string": { - "range": "index.d2,0:22:22-0:26:26", - "value": [ - { - "string": "meow", - "raw_string": "meow" - } - ] - } + "string": "var replaced" } ] } diff --git a/testdata/d2oracle/TestCreate/make_scope_multiline.exp.json b/testdata/d2oracle/TestCreate/make_scope_multiline.exp.json index 3b2eb0b981..379eb30af0 100644 --- a/testdata/d2oracle/TestCreate/make_scope_multiline.exp.json +++ b/testdata/d2oracle/TestCreate/make_scope_multiline.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestCreate/make_scope_multiline.d2,1:9:17-1:15:23", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_1.exp.json b/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_1.exp.json index c5e68d3cb9..021d825c51 100644 --- a/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_1.exp.json +++ b/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_1.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_1.d2,2:9:24-2:15:30", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_2.exp.json b/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_2.exp.json index b5616c2209..4457a46e74 100644 --- a/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_2.exp.json +++ b/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_2.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestCreate/make_scope_multiline_spacing_2.d2,3:9:25-3:15:31", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestDelete/arrowhead_label.exp.json b/testdata/d2oracle/TestDelete/arrowhead_label.exp.json index 0ca9c574fe..408321427d 100644 --- a/testdata/d2oracle/TestDelete/arrowhead_label.exp.json +++ b/testdata/d2oracle/TestDelete/arrowhead_label.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2oracle/TestDelete/arrowhead_label.d2,1:26:36-1:33:43", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2oracle/TestDelete/chaos_1.exp.json b/testdata/d2oracle/TestDelete/chaos_1.exp.json index dc0352817d..7cdb43a602 100644 --- a/testdata/d2oracle/TestDelete/chaos_1.exp.json +++ b/testdata/d2oracle/TestDelete/chaos_1.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,0:12:12-0:20:20", "value": [ { - "string": "cylinder", - "raw_string": "cylinder" + "string": "cylinder" } ] } @@ -150,8 +149,7 @@ "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,1:36:58-1:51:73", "value": [ { - "string": "cf-one-required", - "raw_string": "cf-one-required" + "string": "cf-one-required" } ] } @@ -188,8 +186,7 @@ "range": "d2/testdata/d2oracle/TestDelete/chaos_1.d2,2:4:79-2:5:80", "value": [ { - "string": "z", - "raw_string": "z" + "string": "z" } ] } diff --git a/testdata/d2oracle/TestDelete/children_edge_conflicts.exp.json b/testdata/d2oracle/TestDelete/children_edge_conflicts.exp.json index 7759732a26..f995a64cc7 100644 --- a/testdata/d2oracle/TestDelete/children_edge_conflicts.exp.json +++ b/testdata/d2oracle/TestDelete/children_edge_conflicts.exp.json @@ -99,8 +99,7 @@ "range": "d2/testdata/d2oracle/TestDelete/children_edge_conflicts.d2,4:5:18-4:9:22", "value": [ { - "string": "hi", - "raw_string": "hi" + "string": "hi" } ] } diff --git a/testdata/d2oracle/TestDelete/children_edges_flat_conflicts.exp.json b/testdata/d2oracle/TestDelete/children_edges_flat_conflicts.exp.json index a11ffdd2c2..ee7d331d5b 100644 --- a/testdata/d2oracle/TestDelete/children_edges_flat_conflicts.exp.json +++ b/testdata/d2oracle/TestDelete/children_edges_flat_conflicts.exp.json @@ -159,8 +159,7 @@ "range": "d2/testdata/d2oracle/TestDelete/children_edges_flat_conflicts.d2,4:5:26-4:9:30", "value": [ { - "string": "hi", - "raw_string": "hi" + "string": "hi" } ] } @@ -192,8 +191,7 @@ "range": "d2/testdata/d2oracle/TestDelete/children_edges_flat_conflicts.d2,5:5:36-5:9:40", "value": [ { - "string": "ey", - "raw_string": "ey" + "string": "ey" } ] } diff --git a/testdata/d2oracle/TestDelete/children_flat_conflicts.exp.json b/testdata/d2oracle/TestDelete/children_flat_conflicts.exp.json index fe212f64a6..4b7ffd6ad6 100644 --- a/testdata/d2oracle/TestDelete/children_flat_conflicts.exp.json +++ b/testdata/d2oracle/TestDelete/children_flat_conflicts.exp.json @@ -76,8 +76,7 @@ "range": "d2/testdata/d2oracle/TestDelete/children_flat_conflicts.d2,3:5:12-3:9:16", "value": [ { - "string": "hi", - "raw_string": "hi" + "string": "hi" } ] } diff --git a/testdata/d2oracle/TestDelete/children_multiple_conflicts.exp.json b/testdata/d2oracle/TestDelete/children_multiple_conflicts.exp.json index c1cf6e9226..e6a9fe9763 100644 --- a/testdata/d2oracle/TestDelete/children_multiple_conflicts.exp.json +++ b/testdata/d2oracle/TestDelete/children_multiple_conflicts.exp.json @@ -168,8 +168,7 @@ "range": "d2/testdata/d2oracle/TestDelete/children_multiple_conflicts.d2,7:5:30-7:9:34", "value": [ { - "string": "hi", - "raw_string": "hi" + "string": "hi" } ] } diff --git a/testdata/d2oracle/TestDelete/children_nested_referenced_conflicts.exp.json b/testdata/d2oracle/TestDelete/children_nested_referenced_conflicts.exp.json index 489e99551e..b4bef52535 100644 --- a/testdata/d2oracle/TestDelete/children_nested_referenced_conflicts.exp.json +++ b/testdata/d2oracle/TestDelete/children_nested_referenced_conflicts.exp.json @@ -87,8 +87,7 @@ "range": "d2/testdata/d2oracle/TestDelete/children_nested_referenced_conflicts.d2,4:5:15-4:9:19", "value": [ { - "string": "hi", - "raw_string": "hi" + "string": "hi" } ] } @@ -131,8 +130,7 @@ "range": "d2/testdata/d2oracle/TestDelete/children_nested_referenced_conflicts.d2,5:7:27-5:12:32", "value": [ { - "string": "hey", - "raw_string": "hey" + "string": "hey" } ] } diff --git a/testdata/d2oracle/TestDelete/children_referenced_conflicts.exp.json b/testdata/d2oracle/TestDelete/children_referenced_conflicts.exp.json index 25088c4786..e61acceb2e 100644 --- a/testdata/d2oracle/TestDelete/children_referenced_conflicts.exp.json +++ b/testdata/d2oracle/TestDelete/children_referenced_conflicts.exp.json @@ -76,8 +76,7 @@ "range": "d2/testdata/d2oracle/TestDelete/children_referenced_conflicts.d2,4:5:13-4:9:17", "value": [ { - "string": "hi", - "raw_string": "hi" + "string": "hi" } ] } diff --git a/testdata/d2oracle/TestDelete/container_near.exp.json b/testdata/d2oracle/TestDelete/container_near.exp.json index 5044d5f4b9..f9a7d69e9f 100644 --- a/testdata/d2oracle/TestDelete/container_near.exp.json +++ b/testdata/d2oracle/TestDelete/container_near.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestDelete/container_near.d2,1:8:13-1:9:14", "value": [ { - "string": "z", - "raw_string": "z" + "string": "z" } ] } @@ -139,8 +138,7 @@ "range": "d2/testdata/d2oracle/TestDelete/container_near.d2,5:8:32-5:9:33", "value": [ { - "string": "z", - "raw_string": "z" + "string": "z" } ] } diff --git a/testdata/d2oracle/TestDelete/delete_container_of_near.exp.json b/testdata/d2oracle/TestDelete/delete_container_of_near.exp.json index 4c52363d83..5555f957ea 100644 --- a/testdata/d2oracle/TestDelete/delete_container_of_near.exp.json +++ b/testdata/d2oracle/TestDelete/delete_container_of_near.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2oracle/TestDelete/delete_container_of_near.d2,0:11:11-0:15:15", "value": [ { - "string": "down", - "raw_string": "down" + "string": "down" } ] } @@ -452,8 +451,7 @@ "range": "d2/testdata/d2oracle/TestDelete/delete_container_of_near.d2,9:19:236-9:37:254", "value": [ { - "string": "collision detected", - "raw_string": "collision detected" + "string": "collision detected" } ] } diff --git a/testdata/d2oracle/TestDelete/delete_icon.exp.json b/testdata/d2oracle/TestDelete/delete_icon.exp.json index 09b4bbab93..2c04083ce3 100644 --- a/testdata/d2oracle/TestDelete/delete_icon.exp.json +++ b/testdata/d2oracle/TestDelete/delete_icon.exp.json @@ -65,8 +65,7 @@ "range": "d2/testdata/d2oracle/TestDelete/delete_icon.d2,1:8:15-1:26:33", "value": [ { - "string": "https://google.com", - "raw_string": "https://google.com" + "string": "https://google.com" } ] } diff --git a/testdata/d2oracle/TestDelete/edge_decrement.exp.json b/testdata/d2oracle/TestDelete/edge_decrement.exp.json index 13a576bb8f..d9910b9db2 100644 --- a/testdata/d2oracle/TestDelete/edge_decrement.exp.json +++ b/testdata/d2oracle/TestDelete/edge_decrement.exp.json @@ -242,8 +242,7 @@ "range": "d2/testdata/d2oracle/TestDelete/edge_decrement.d2,5:13:42-5:17:46", "value": [ { - "string": "zero", - "raw_string": "zero" + "string": "zero" } ] } @@ -303,8 +302,7 @@ "range": "d2/testdata/d2oracle/TestDelete/edge_decrement.d2,6:13:60-6:16:63", "value": [ { - "string": "one", - "raw_string": "one" + "string": "one" } ] } @@ -364,8 +362,7 @@ "range": "d2/testdata/d2oracle/TestDelete/edge_decrement.d2,8:13:78-8:18:83", "value": [ { - "string": "three", - "raw_string": "three" + "string": "three" } ] } @@ -425,8 +422,7 @@ "range": "d2/testdata/d2oracle/TestDelete/edge_decrement.d2,9:13:97-9:17:101", "value": [ { - "string": "four", - "raw_string": "four" + "string": "four" } ] } diff --git a/testdata/d2oracle/TestDelete/multi_near.exp.json b/testdata/d2oracle/TestDelete/multi_near.exp.json index f6c3e68b19..78ba7c9a8d 100644 --- a/testdata/d2oracle/TestDelete/multi_near.exp.json +++ b/testdata/d2oracle/TestDelete/multi_near.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestDelete/multi_near.d2,2:8:24-2:11:27", "value": [ { - "string": "API", - "raw_string": "API" + "string": "API" } ] } @@ -139,8 +138,7 @@ "range": "d2/testdata/d2oracle/TestDelete/multi_near.d2,5:8:44-5:12:48", "value": [ { - "string": "Blah", - "raw_string": "Blah" + "string": "Blah" } ] } diff --git a/testdata/d2oracle/TestDelete/only_delete_edge_reserved.exp.json b/testdata/d2oracle/TestDelete/only_delete_edge_reserved.exp.json index b93c9f0c63..224894d557 100644 --- a/testdata/d2oracle/TestDelete/only_delete_edge_reserved.exp.json +++ b/testdata/d2oracle/TestDelete/only_delete_edge_reserved.exp.json @@ -65,8 +65,7 @@ "range": "d2/testdata/d2oracle/TestDelete/only_delete_edge_reserved.d2,0:18:18-0:27:27", "value": [ { - "string": "#000e3d", - "raw_string": "#000e3d" + "string": "#000e3d" } ] } diff --git a/testdata/d2oracle/TestDelete/only_delete_obj_reserved.exp.json b/testdata/d2oracle/TestDelete/only_delete_obj_reserved.exp.json index 35f4eac8bd..6a06bf2ad0 100644 --- a/testdata/d2oracle/TestDelete/only_delete_obj_reserved.exp.json +++ b/testdata/d2oracle/TestDelete/only_delete_obj_reserved.exp.json @@ -134,8 +134,7 @@ "range": "d2/testdata/d2oracle/TestDelete/only_delete_obj_reserved.d2,2:23:27-2:32:36", "value": [ { - "string": "#2b50c2", - "raw_string": "#2b50c2" + "string": "#2b50c2" } ] } diff --git a/testdata/d2oracle/TestDelete/save_map.exp.json b/testdata/d2oracle/TestDelete/save_map.exp.json index f9a437bd2b..6050b7deca 100644 --- a/testdata/d2oracle/TestDelete/save_map.exp.json +++ b/testdata/d2oracle/TestDelete/save_map.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestDelete/save_map.d2,1:9:14-1:15:20", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestDelete/save_map_with_primary.exp.json b/testdata/d2oracle/TestDelete/save_map_with_primary.exp.json index 9135e99996..7a09a0b955 100644 --- a/testdata/d2oracle/TestDelete/save_map_with_primary.exp.json +++ b/testdata/d2oracle/TestDelete/save_map_with_primary.exp.json @@ -64,8 +64,7 @@ "range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,1:9:20-1:15:26", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestDelete/shape_sql_table.exp.json b/testdata/d2oracle/TestDelete/shape_sql_table.exp.json index 279fee006f..48896ea4c4 100644 --- a/testdata/d2oracle/TestDelete/shape_sql_table.exp.json +++ b/testdata/d2oracle/TestDelete/shape_sql_table.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2oracle/TestDelete/shape_sql_table.d2,2:11:31-2:20:40", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -145,8 +144,7 @@ "range": "d2/testdata/d2oracle/TestDelete/shape_sql_table.d2,3:25:66-3:36:77", "value": [ { - "string": "primary_key", - "raw_string": "primary_key" + "string": "primary_key" } ] } diff --git a/testdata/d2oracle/TestDelete/table_refs.exp.json b/testdata/d2oracle/TestDelete/table_refs.exp.json index 8dddf30b20..903675edef 100644 --- a/testdata/d2oracle/TestDelete/table_refs.exp.json +++ b/testdata/d2oracle/TestDelete/table_refs.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestDelete/table_refs.d2,1:9:14-1:18:23", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } diff --git a/testdata/d2oracle/TestMove/append_multiple_styles.exp.json b/testdata/d2oracle/TestMove/append_multiple_styles.exp.json index f35e81c9de..84fb3f5cc5 100644 --- a/testdata/d2oracle/TestMove/append_multiple_styles.exp.json +++ b/testdata/d2oracle/TestMove/append_multiple_styles.exp.json @@ -189,8 +189,7 @@ "range": "d2/testdata/d2oracle/TestMove/append_multiple_styles.d2,8:12:86-8:17:91", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } diff --git a/testdata/d2oracle/TestMove/container_conflicts_generated.exp.json b/testdata/d2oracle/TestMove/container_conflicts_generated.exp.json index 2bb20536aa..53bcaad10b 100644 --- a/testdata/d2oracle/TestMove/container_conflicts_generated.exp.json +++ b/testdata/d2oracle/TestMove/container_conflicts_generated.exp.json @@ -28,7 +28,11 @@ "value": { "double_quoted_string": { "range": "d2/testdata/d2oracle/TestMove/container_conflicts_generated.d2,0:10:10-0:12:12", - "value": null + "value": [ + { + "string": "" + } + ] } } } @@ -56,7 +60,11 @@ "value": { "double_quoted_string": { "range": "d2/testdata/d2oracle/TestMove/container_conflicts_generated.d2,2:8:22-2:10:24", - "value": null + "value": [ + { + "string": "" + } + ] } } } @@ -108,7 +116,11 @@ "value": { "double_quoted_string": { "range": "d2/testdata/d2oracle/TestMove/container_conflicts_generated.d2,4:12:49-4:14:51", - "value": null + "value": [ + { + "string": "" + } + ] } } } diff --git a/testdata/d2oracle/TestMove/container_near.exp.json b/testdata/d2oracle/TestMove/container_near.exp.json index 95d0a59828..a48adc76c7 100644 --- a/testdata/d2oracle/TestMove/container_near.exp.json +++ b/testdata/d2oracle/TestMove/container_near.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2oracle/TestMove/container_near.d2,2:10:22-2:15:27", "value": [ { - "string": "x.a.z", - "raw_string": "x.a.z" + "string": "x.a.z" } ] } diff --git a/testdata/d2oracle/TestMove/duplicate.exp.json b/testdata/d2oracle/TestMove/duplicate.exp.json index 3222684280..099aaf3571 100644 --- a/testdata/d2oracle/TestMove/duplicate.exp.json +++ b/testdata/d2oracle/TestMove/duplicate.exp.json @@ -100,8 +100,7 @@ "range": "d2/testdata/d2oracle/TestMove/duplicate.d2,4:9:19-4:17:27", "value": [ { - "string": "cylinder", - "raw_string": "cylinder" + "string": "cylinder" } ] } diff --git a/testdata/d2oracle/TestMove/flat_merge.exp.json b/testdata/d2oracle/TestMove/flat_merge.exp.json index 735394e904..21adc51151 100644 --- a/testdata/d2oracle/TestMove/flat_merge.exp.json +++ b/testdata/d2oracle/TestMove/flat_merge.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestMove/flat_merge.d2,2:5:12-2:9:16", "value": [ { - "string": "meow", - "raw_string": "meow" + "string": "meow" } ] } diff --git a/testdata/d2oracle/TestMove/flat_near.exp.json b/testdata/d2oracle/TestMove/flat_near.exp.json index 88af9eb39c..bcefc6a775 100644 --- a/testdata/d2oracle/TestMove/flat_near.exp.json +++ b/testdata/d2oracle/TestMove/flat_near.exp.json @@ -41,8 +41,7 @@ "range": "d2/testdata/d2oracle/TestMove/flat_near.d2,0:8:8-0:11:11", "value": [ { - "string": "a.y", - "raw_string": "a.y" + "string": "a.y" } ] } diff --git a/testdata/d2oracle/TestMove/flat_reparent_with_map_value.exp.json b/testdata/d2oracle/TestMove/flat_reparent_with_map_value.exp.json index 28401eb184..0521ffd8b1 100644 --- a/testdata/d2oracle/TestMove/flat_reparent_with_map_value.exp.json +++ b/testdata/d2oracle/TestMove/flat_reparent_with_map_value.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestMove/flat_reparent_with_map_value.d2,2:9:16-2:16:23", "value": [ { - "string": "hexagon", - "raw_string": "hexagon" + "string": "hexagon" } ] } diff --git a/testdata/d2oracle/TestMove/flat_reparent_with_mixed_map_value.exp.json b/testdata/d2oracle/TestMove/flat_reparent_with_mixed_map_value.exp.json index 5ca987152c..12ba9058da 100644 --- a/testdata/d2oracle/TestMove/flat_reparent_with_mixed_map_value.exp.json +++ b/testdata/d2oracle/TestMove/flat_reparent_with_mixed_map_value.exp.json @@ -118,8 +118,7 @@ "range": "d2/testdata/d2oracle/TestMove/flat_reparent_with_mixed_map_value.d2,6:9:62-6:16:69", "value": [ { - "string": "hexagon", - "raw_string": "hexagon" + "string": "hexagon" } ] } diff --git a/testdata/d2oracle/TestMove/flat_reparent_with_value.exp.json b/testdata/d2oracle/TestMove/flat_reparent_with_value.exp.json index 9360697188..369217c57e 100644 --- a/testdata/d2oracle/TestMove/flat_reparent_with_value.exp.json +++ b/testdata/d2oracle/TestMove/flat_reparent_with_value.exp.json @@ -53,8 +53,7 @@ "range": "d2/testdata/d2oracle/TestMove/flat_reparent_with_value.d2,1:3:5-1:7:9", "value": [ { - "string": "yo", - "raw_string": "yo" + "string": "yo" } ] } diff --git a/testdata/d2oracle/TestMove/flat_style.exp.json b/testdata/d2oracle/TestMove/flat_style.exp.json index ac3ee73268..0fc9d191c7 100644 --- a/testdata/d2oracle/TestMove/flat_style.exp.json +++ b/testdata/d2oracle/TestMove/flat_style.exp.json @@ -127,8 +127,7 @@ "range": "d2/testdata/d2oracle/TestMove/flat_style.d2,2:16:44-2:21:49", "value": [ { - "string": "black", - "raw_string": "black" + "string": "black" } ] } diff --git a/testdata/d2oracle/TestMove/gnarly_1.exp.json b/testdata/d2oracle/TestMove/gnarly_1.exp.json index d4fdf0016d..20eecde9f9 100644 --- a/testdata/d2oracle/TestMove/gnarly_1.exp.json +++ b/testdata/d2oracle/TestMove/gnarly_1.exp.json @@ -144,8 +144,7 @@ "range": "d2/testdata/d2oracle/TestMove/gnarly_1.d2,2:5:25-2:9:29", "value": [ { - "string": "meow", - "raw_string": "meow" + "string": "meow" } ] } @@ -182,8 +181,7 @@ "range": "d2/testdata/d2oracle/TestMove/gnarly_1.d2,4:3:35-4:8:40", "value": [ { - "string": "eyy", - "raw_string": "eyy" + "string": "eyy" } ] } diff --git a/testdata/d2oracle/TestMove/include_descendants_near.exp.json b/testdata/d2oracle/TestMove/include_descendants_near.exp.json index fe66e976fb..d98ded6e2b 100644 --- a/testdata/d2oracle/TestMove/include_descendants_near.exp.json +++ b/testdata/d2oracle/TestMove/include_descendants_near.exp.json @@ -104,8 +104,7 @@ "range": "d2/testdata/d2oracle/TestMove/include_descendants_near.d2,3:8:21-3:13:26", "value": [ { - "string": "z.x.y", - "raw_string": "z.x.y" + "string": "z.x.y" } ] } diff --git a/testdata/d2oracle/TestMove/include_descendants_nested_reserved_2.exp.json b/testdata/d2oracle/TestMove/include_descendants_nested_reserved_2.exp.json index 16780889ec..561c3dc9c0 100644 --- a/testdata/d2oracle/TestMove/include_descendants_nested_reserved_2.exp.json +++ b/testdata/d2oracle/TestMove/include_descendants_nested_reserved_2.exp.json @@ -75,8 +75,7 @@ "range": "d2/testdata/d2oracle/TestMove/include_descendants_nested_reserved_2.d2,1:9:13-1:15:19", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestMove/include_descendants_nested_reserved_3.exp.json b/testdata/d2oracle/TestMove/include_descendants_nested_reserved_3.exp.json index 3548537769..553161a8f4 100644 --- a/testdata/d2oracle/TestMove/include_descendants_nested_reserved_3.exp.json +++ b/testdata/d2oracle/TestMove/include_descendants_nested_reserved_3.exp.json @@ -75,8 +75,7 @@ "range": "d2/testdata/d2oracle/TestMove/include_descendants_nested_reserved_3.d2,1:11:13-1:17:19", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestMove/include_descendants_sql.exp.json b/testdata/d2oracle/TestMove/include_descendants_sql.exp.json index 990495062e..61a5f3bc92 100644 --- a/testdata/d2oracle/TestMove/include_descendants_sql.exp.json +++ b/testdata/d2oracle/TestMove/include_descendants_sql.exp.json @@ -78,8 +78,7 @@ "range": "d2/testdata/d2oracle/TestMove/include_descendants_sql.d2,2:11:23-2:20:32", "value": [ { - "string": "sql_table", - "raw_string": "sql_table" + "string": "sql_table" } ] } @@ -111,8 +110,7 @@ "range": "d2/testdata/d2oracle/TestMove/include_descendants_sql.d2,3:7:40-3:8:41", "value": [ { - "string": "b", - "raw_string": "b" + "string": "b" } ] } diff --git a/testdata/d2oracle/TestMove/into_container_with_flat_keys.exp.json b/testdata/d2oracle/TestMove/into_container_with_flat_keys.exp.json index 409433d81b..0c07d26081 100644 --- a/testdata/d2oracle/TestMove/into_container_with_flat_keys.exp.json +++ b/testdata/d2oracle/TestMove/into_container_with_flat_keys.exp.json @@ -129,8 +129,7 @@ "range": "d2/testdata/d2oracle/TestMove/into_container_with_flat_keys.d2,3:16:51-3:25:60", "value": [ { - "string": "#FFFFFF", - "raw_string": "#FFFFFF" + "string": "#FFFFFF" } ] } @@ -173,8 +172,7 @@ "range": "d2/testdata/d2oracle/TestMove/into_container_with_flat_keys.d2,4:18:79-4:27:88", "value": [ { - "string": "#FFFFFF", - "raw_string": "#FFFFFF" + "string": "#FFFFFF" } ] } diff --git a/testdata/d2oracle/TestMove/map_transplant.exp.json b/testdata/d2oracle/TestMove/map_transplant.exp.json index e5eb385326..d9bdd3d731 100644 --- a/testdata/d2oracle/TestMove/map_transplant.exp.json +++ b/testdata/d2oracle/TestMove/map_transplant.exp.json @@ -182,8 +182,7 @@ "range": "d2/testdata/d2oracle/TestMove/map_transplant.d2,10:11:68-10:15:72", "value": [ { - "string": "yo", - "raw_string": "yo" + "string": "yo" } ] } diff --git a/testdata/d2oracle/TestMove/map_with_label.exp.json b/testdata/d2oracle/TestMove/map_with_label.exp.json index fd11c89598..5c5b35676a 100644 --- a/testdata/d2oracle/TestMove/map_with_label.exp.json +++ b/testdata/d2oracle/TestMove/map_with_label.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestMove/map_with_label.d2,3:5:13-3:9:17", "value": [ { - "string": "yo", - "raw_string": "yo" + "string": "yo" } ] } diff --git a/testdata/d2oracle/TestMove/merge_reserved.exp.json b/testdata/d2oracle/TestMove/merge_reserved.exp.json index 26d98f1c75..037f7fab45 100644 --- a/testdata/d2oracle/TestMove/merge_reserved.exp.json +++ b/testdata/d2oracle/TestMove/merge_reserved.exp.json @@ -99,8 +99,7 @@ "range": "d2/testdata/d2oracle/TestMove/merge_reserved.d2,2:11:22-2:15:26", "value": [ { - "string": "yo", - "raw_string": "yo" + "string": "yo" } ] } @@ -143,8 +142,7 @@ "range": "d2/testdata/d2oracle/TestMove/merge_reserved.d2,3:11:38-3:15:42", "value": [ { - "string": "hi", - "raw_string": "hi" + "string": "hi" } ] } diff --git a/testdata/d2oracle/TestMove/near.exp.json b/testdata/d2oracle/TestMove/near.exp.json index bb04cafce0..6d222608ef 100644 --- a/testdata/d2oracle/TestMove/near.exp.json +++ b/testdata/d2oracle/TestMove/near.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestMove/near.d2,1:8:13-1:11:16", "value": [ { - "string": "a.y", - "raw_string": "a.y" + "string": "a.y" } ] } diff --git a/testdata/d2oracle/TestMove/nested_reserved_2.exp.json b/testdata/d2oracle/TestMove/nested_reserved_2.exp.json index 178643bd1b..df689ac771 100644 --- a/testdata/d2oracle/TestMove/nested_reserved_2.exp.json +++ b/testdata/d2oracle/TestMove/nested_reserved_2.exp.json @@ -75,8 +75,7 @@ "range": "d2/testdata/d2oracle/TestMove/nested_reserved_2.d2,1:9:13-1:15:19", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestMove/nested_reserved_3.exp.json b/testdata/d2oracle/TestMove/nested_reserved_3.exp.json index 6e727d7995..f5e278e7ed 100644 --- a/testdata/d2oracle/TestMove/nested_reserved_3.exp.json +++ b/testdata/d2oracle/TestMove/nested_reserved_3.exp.json @@ -134,8 +134,7 @@ "range": "d2/testdata/d2oracle/TestMove/nested_reserved_3.d2,3:13:31-3:19:37", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestMove/parentheses.exp.json b/testdata/d2oracle/TestMove/parentheses.exp.json index 8550114dbc..a1359a9faf 100644 --- a/testdata/d2oracle/TestMove/parentheses.exp.json +++ b/testdata/d2oracle/TestMove/parentheses.exp.json @@ -85,7 +85,11 @@ "value": { "double_quoted_string": { "range": "d2/testdata/d2oracle/TestMove/parentheses.d2,1:3:16-1:5:18", - "value": null + "value": [ + { + "string": "" + } + ] } } } diff --git a/testdata/d2oracle/TestMove/slice_style.exp.json b/testdata/d2oracle/TestMove/slice_style.exp.json index ab093f083e..0e5d76161f 100644 --- a/testdata/d2oracle/TestMove/slice_style.exp.json +++ b/testdata/d2oracle/TestMove/slice_style.exp.json @@ -110,8 +110,7 @@ "range": "d2/testdata/d2oracle/TestMove/slice_style.d2,3:8:14-3:63:69", "value": [ { - "string": "https://icons.terrastruct.com/essentials/142-target.svg", - "raw_string": "https://icons.terrastruct.com/essentials/142-target.svg" + "string": "https://icons.terrastruct.com/essentials/142-target.svg" } ] } diff --git a/testdata/d2oracle/TestMove/underscore_merge.exp.json b/testdata/d2oracle/TestMove/underscore_merge.exp.json index 914e4dc1b4..3094f38ca7 100644 --- a/testdata/d2oracle/TestMove/underscore_merge.exp.json +++ b/testdata/d2oracle/TestMove/underscore_merge.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestMove/underscore_merge.d2,3:5:13-3:9:17", "value": [ { - "string": "yo", - "raw_string": "yo" + "string": "yo" } ] } @@ -110,8 +109,7 @@ "range": "d2/testdata/d2oracle/TestMove/underscore_merge.d2,4:5:23-4:11:29", "value": [ { - "string": "what", - "raw_string": "what" + "string": "what" } ] } diff --git a/testdata/d2oracle/TestReconnectEdge/indexed_ref.exp.json b/testdata/d2oracle/TestReconnectEdge/indexed_ref.exp.json index 02ecdaa4f9..cef57ffe10 100644 --- a/testdata/d2oracle/TestReconnectEdge/indexed_ref.exp.json +++ b/testdata/d2oracle/TestReconnectEdge/indexed_ref.exp.json @@ -177,8 +177,7 @@ "range": "d2/testdata/d2oracle/TestReconnectEdge/indexed_ref.d2,3:26:37-3:29:40", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } diff --git a/testdata/d2oracle/TestReconnectEdge/preserve_old_obj.exp.json b/testdata/d2oracle/TestReconnectEdge/preserve_old_obj.exp.json index aef3931510..743197677f 100644 --- a/testdata/d2oracle/TestReconnectEdge/preserve_old_obj.exp.json +++ b/testdata/d2oracle/TestReconnectEdge/preserve_old_obj.exp.json @@ -154,8 +154,7 @@ "range": "d2/testdata/d2oracle/TestReconnectEdge/preserve_old_obj.d2,2:26:35-2:29:38", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } diff --git a/testdata/d2oracle/TestReconnectEdge/second_index.exp.json b/testdata/d2oracle/TestReconnectEdge/second_index.exp.json index 5f52b761f7..0d0d769c37 100644 --- a/testdata/d2oracle/TestReconnectEdge/second_index.exp.json +++ b/testdata/d2oracle/TestReconnectEdge/second_index.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2oracle/TestReconnectEdge/second_index.d2,1:16:26-1:20:30", "value": [ { - "string": "blue", - "raw_string": "blue" + "string": "blue" } ] } @@ -184,8 +183,7 @@ "range": "d2/testdata/d2oracle/TestReconnectEdge/second_index.d2,4:16:59-4:19:62", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } diff --git a/testdata/d2oracle/TestRename/container.exp.json b/testdata/d2oracle/TestRename/container.exp.json index 1d4593223c..b467fb1be9 100644 --- a/testdata/d2oracle/TestRename/container.exp.json +++ b/testdata/d2oracle/TestRename/container.exp.json @@ -437,8 +437,7 @@ "range": "d2/testdata/d2oracle/TestRename/container.d2,3:5:108-3:10:113", "value": [ { - "string": "label", - "raw_string": "label" + "string": "label" } ] } @@ -617,8 +616,7 @@ "range": "d2/testdata/d2oracle/TestRename/container.d2,10:30:181-10:45:196", "value": [ { - "string": "furbling, v.:", - "raw_string": "furbling, v.:" + "string": "furbling, v.:" } ] } @@ -722,8 +720,7 @@ "range": "d2/testdata/d2oracle/TestRename/container.d2,11:22:219-11:37:234", "value": [ { - "string": "furbling, v.:", - "raw_string": "furbling, v.:" + "string": "furbling, v.:" } ] } diff --git a/testdata/d2oracle/TestRename/edges.exp.json b/testdata/d2oracle/TestRename/edges.exp.json index 6e5ab06501..21f1251995 100644 --- a/testdata/d2oracle/TestRename/edges.exp.json +++ b/testdata/d2oracle/TestRename/edges.exp.json @@ -382,8 +382,7 @@ "range": "d2/testdata/d2oracle/TestRename/edges.d2,3:7:66-3:12:71", "value": [ { - "string": "label", - "raw_string": "label" + "string": "label" } ] } diff --git a/testdata/d2oracle/TestRename/near.exp.json b/testdata/d2oracle/TestRename/near.exp.json index 7c7ddf5637..e1cf9bfb65 100644 --- a/testdata/d2oracle/TestRename/near.exp.json +++ b/testdata/d2oracle/TestRename/near.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestRename/near.d2,1:8:13-1:9:14", "value": [ { - "string": "z", - "raw_string": "z" + "string": "z" } ] } diff --git a/testdata/d2oracle/TestSet/classes-style.exp.json b/testdata/d2oracle/TestSet/classes-style.exp.json index a99073d1f6..a7a808ade0 100644 --- a/testdata/d2oracle/TestSet/classes-style.exp.json +++ b/testdata/d2oracle/TestSet/classes-style.exp.json @@ -89,8 +89,7 @@ "range": "d2/testdata/d2oracle/TestSet/classes-style.d2,2:16:34-2:19:37", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -143,8 +142,7 @@ "range": "d2/testdata/d2oracle/TestSet/classes-style.d2,5:9:53-5:10:54", "value": [ { - "string": "a", - "raw_string": "a" + "string": "a" } ] } @@ -198,8 +196,7 @@ "range": "d2/testdata/d2oracle/TestSet/classes-style.d2,6:14:69-6:19:74", "value": [ { - "string": "green", - "raw_string": "green" + "string": "green" } ] } diff --git a/testdata/d2oracle/TestSet/dupe-classes-style.exp.json b/testdata/d2oracle/TestSet/dupe-classes-style.exp.json index 9c74249a85..ec26cc69ef 100644 --- a/testdata/d2oracle/TestSet/dupe-classes-style.exp.json +++ b/testdata/d2oracle/TestSet/dupe-classes-style.exp.json @@ -89,8 +89,7 @@ "range": "d2/testdata/d2oracle/TestSet/dupe-classes-style.d2,2:16:34-2:19:37", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -143,8 +142,7 @@ "range": "d2/testdata/d2oracle/TestSet/dupe-classes-style.d2,5:9:53-5:10:54", "value": [ { - "string": "a", - "raw_string": "a" + "string": "a" } ] } @@ -198,8 +196,7 @@ "range": "d2/testdata/d2oracle/TestSet/dupe-classes-style.d2,6:14:69-6:19:74", "value": [ { - "string": "green", - "raw_string": "green" + "string": "green" } ] } diff --git a/testdata/d2oracle/TestSet/edge.exp.json b/testdata/d2oracle/TestSet/edge.exp.json index f9568af910..1da9d1df91 100644 --- a/testdata/d2oracle/TestSet/edge.exp.json +++ b/testdata/d2oracle/TestSet/edge.exp.json @@ -53,8 +53,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge.d2,0:8:8-0:11:11", "value": [ { - "string": "two", - "raw_string": "two" + "string": "two" } ] } diff --git a/testdata/d2oracle/TestSet/edge_chain.exp.json b/testdata/d2oracle/TestSet/edge_chain.exp.json index e36df946df..88c2c9847d 100644 --- a/testdata/d2oracle/TestSet/edge_chain.exp.json +++ b/testdata/d2oracle/TestSet/edge_chain.exp.json @@ -114,8 +114,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_chain.d2,1:15:23-1:19:27", "value": [ { - "string": "wsup", - "raw_string": "wsup" + "string": "wsup" } ] } @@ -175,8 +174,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_chain.d2,2:15:43-2:62:90", "value": [ { - "string": "QOTD:\n \"It's been Monday all week today.\"", - "raw_string": "QOTD:\\n \\\"It's been Monday all week today.\\\"" + "string": "QOTD:\n \"It's been Monday all week today.\"" } ] } diff --git a/testdata/d2oracle/TestSet/edge_chain_nested_set.exp.json b/testdata/d2oracle/TestSet/edge_chain_nested_set.exp.json index 3bd0f42a89..f39d6e68e8 100644 --- a/testdata/d2oracle/TestSet/edge_chain_nested_set.exp.json +++ b/testdata/d2oracle/TestSet/edge_chain_nested_set.exp.json @@ -114,8 +114,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_chain_nested_set.d2,1:15:23-1:19:27", "value": [ { - "string": "wsup", - "raw_string": "wsup" + "string": "wsup" } ] } diff --git a/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.exp.json b/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.exp.json index fe82080509..d6b04d13db 100644 --- a/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.exp.json +++ b/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.exp.json @@ -168,8 +168,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_flat_merge_arrowhead.d2,1:36:48-1:42:54", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestSet/edge_index_case.exp.json b/testdata/d2oracle/TestSet/edge_index_case.exp.json index d1eb8f9c33..8ae066c108 100644 --- a/testdata/d2oracle/TestSet/edge_index_case.exp.json +++ b/testdata/d2oracle/TestSet/edge_index_case.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_index_case.d2,1:22:32-1:25:35", "value": [ { - "string": "two", - "raw_string": "two" + "string": "two" } ] } diff --git a/testdata/d2oracle/TestSet/edge_index_nested.exp.json b/testdata/d2oracle/TestSet/edge_index_nested.exp.json index 1abf22a573..a18a8da4d9 100644 --- a/testdata/d2oracle/TestSet/edge_index_nested.exp.json +++ b/testdata/d2oracle/TestSet/edge_index_nested.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_index_nested.d2,1:10:18-1:14:22", "value": [ { - "string": "QOTD", - "raw_string": "QOTD" + "string": "QOTD" } ] } diff --git a/testdata/d2oracle/TestSet/edge_merge_arrowhead.exp.json b/testdata/d2oracle/TestSet/edge_merge_arrowhead.exp.json index e647ebf853..f7ffe88217 100644 --- a/testdata/d2oracle/TestSet/edge_merge_arrowhead.exp.json +++ b/testdata/d2oracle/TestSet/edge_merge_arrowhead.exp.json @@ -130,8 +130,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_merge_arrowhead.d2,3:11:56-3:18:63", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2oracle/TestSet/edge_nested_label_set.exp.json b/testdata/d2oracle/TestSet/edge_nested_label_set.exp.json index 64f975592c..53237d909c 100644 --- a/testdata/d2oracle/TestSet/edge_nested_label_set.exp.json +++ b/testdata/d2oracle/TestSet/edge_nested_label_set.exp.json @@ -77,8 +77,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_nested_label_set.d2,1:10:18-1:12:20", "value": [ { - "string": "yo", - "raw_string": "yo" + "string": "yo" } ] } diff --git a/testdata/d2oracle/TestSet/edge_replace_arrowhead.exp.json b/testdata/d2oracle/TestSet/edge_replace_arrowhead.exp.json index 88538296c8..c9064aac63 100644 --- a/testdata/d2oracle/TestSet/edge_replace_arrowhead.exp.json +++ b/testdata/d2oracle/TestSet/edge_replace_arrowhead.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead.d2,0:33:33-0:40:40", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.exp.json b/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.exp.json index 7b3b4168a1..a852056d4c 100644 --- a/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.exp.json +++ b/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.exp.json @@ -131,8 +131,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_replace_arrowhead_indexed.d2,1:36:43-1:43:50", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2oracle/TestSet/edge_set_arrowhead.exp.json b/testdata/d2oracle/TestSet/edge_set_arrowhead.exp.json index 4a34779689..f34c30d72c 100644 --- a/testdata/d2oracle/TestSet/edge_set_arrowhead.exp.json +++ b/testdata/d2oracle/TestSet/edge_set_arrowhead.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2oracle/TestSet/edge_set_arrowhead.d2,0:33:33-0:40:40", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2oracle/TestSet/icon.exp.json b/testdata/d2oracle/TestSet/icon.exp.json index ab79c0a72b..08156af78f 100644 --- a/testdata/d2oracle/TestSet/icon.exp.json +++ b/testdata/d2oracle/TestSet/icon.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestSet/icon.d2,0:13:13-0:66:66", "value": [ { - "string": "https://icons.terrastruct.com/essentials/087-menu.svg", - "raw_string": "https://icons.terrastruct.com/essentials/087-menu.svg" + "string": "https://icons.terrastruct.com/essentials/087-menu.svg" } ] } diff --git a/testdata/d2oracle/TestSet/inline_style.exp.json b/testdata/d2oracle/TestSet/inline_style.exp.json index 032b0654ec..f66fd2cda5 100644 --- a/testdata/d2oracle/TestSet/inline_style.exp.json +++ b/testdata/d2oracle/TestSet/inline_style.exp.json @@ -105,8 +105,7 @@ "range": "d2/testdata/d2oracle/TestSet/inline_style.d2,2:14:45-2:17:48", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } diff --git a/testdata/d2oracle/TestSet/label.exp.json b/testdata/d2oracle/TestSet/label.exp.json index b091d0d7e3..601a69cfe7 100644 --- a/testdata/d2oracle/TestSet/label.exp.json +++ b/testdata/d2oracle/TestSet/label.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2oracle/TestSet/label.d2,0:8:8-0:87:87", "value": [ { - "string": "Always try to do things in chronological order; it's less confusing that way.", - "raw_string": "Always try to do things in chronological order; it's less confusing that way." + "string": "Always try to do things in chronological order; it's less confusing that way." } ] } diff --git a/testdata/d2oracle/TestSet/label_replace.exp.json b/testdata/d2oracle/TestSet/label_replace.exp.json index 976aa222fe..57815ab6f2 100644 --- a/testdata/d2oracle/TestSet/label_replace.exp.json +++ b/testdata/d2oracle/TestSet/label_replace.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2oracle/TestSet/label_replace.d2,0:8:8-0:87:87", "value": [ { - "string": "Always try to do things in chronological order; it's less confusing that way.", - "raw_string": "Always try to do things in chronological order; it's less confusing that way." + "string": "Always try to do things in chronological order; it's less confusing that way." } ] } diff --git a/testdata/d2oracle/TestSet/map_key_missing.exp.json b/testdata/d2oracle/TestSet/map_key_missing.exp.json index e26a744904..3fa4221188 100644 --- a/testdata/d2oracle/TestSet/map_key_missing.exp.json +++ b/testdata/d2oracle/TestSet/map_key_missing.exp.json @@ -76,8 +76,7 @@ "range": "d2/testdata/d2oracle/TestSet/map_key_missing.d2,0:11:11-0:82:82", "value": [ { - "string": "Never offend people with style when you can offend them with substance.", - "raw_string": "Never offend people with style when you can offend them with substance." + "string": "Never offend people with style when you can offend them with substance." } ] } diff --git a/testdata/d2oracle/TestSet/nested_alex.exp.json b/testdata/d2oracle/TestSet/nested_alex.exp.json index 97bb445e09..46c65b1e3f 100644 --- a/testdata/d2oracle/TestSet/nested_alex.exp.json +++ b/testdata/d2oracle/TestSet/nested_alex.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestSet/nested_alex.d2,1:9:17-1:11:19", "value": [ { - "string": "do", - "raw_string": "do" + "string": "do" } ] } @@ -110,8 +109,7 @@ "range": "d2/testdata/d2oracle/TestSet/nested_alex.d2,2:16:36-2:20:40", "value": [ { - "string": "asdf", - "raw_string": "asdf" + "string": "asdf" } ] } @@ -143,8 +141,7 @@ "range": "d2/testdata/d2oracle/TestSet/nested_alex.d2,3:8:49-3:158:199", "value": [ { - "string": "How much of their influence on you is a result of your influence on them?\nA conference is a gathering of important people who singly can do nothing", - "raw_string": "How much of their influence on you is a result of your influence on them?\\nA conference is a gathering of important people who singly can do nothing" + "string": "How much of their influence on you is a result of your influence on them?\nA conference is a gathering of important people who singly can do nothing" } ] } diff --git a/testdata/d2oracle/TestSet/replace_arrowhead.exp.json b/testdata/d2oracle/TestSet/replace_arrowhead.exp.json index 9870e4e344..ae74ac3baf 100644 --- a/testdata/d2oracle/TestSet/replace_arrowhead.exp.json +++ b/testdata/d2oracle/TestSet/replace_arrowhead.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead.d2,1:26:36-1:32:42", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestSet/replace_arrowhead_map.exp.json b/testdata/d2oracle/TestSet/replace_arrowhead_map.exp.json index 2c26e580a4..5b4e8547a0 100644 --- a/testdata/d2oracle/TestSet/replace_arrowhead_map.exp.json +++ b/testdata/d2oracle/TestSet/replace_arrowhead_map.exp.json @@ -101,8 +101,7 @@ "range": "d2/testdata/d2oracle/TestSet/replace_arrowhead_map.d2,2:11:43-2:17:49", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestSet/replace_fill_pattern.exp.json b/testdata/d2oracle/TestSet/replace_fill_pattern.exp.json index e85fb417b3..ed61d736f7 100644 --- a/testdata/d2oracle/TestSet/replace_fill_pattern.exp.json +++ b/testdata/d2oracle/TestSet/replace_fill_pattern.exp.json @@ -65,8 +65,7 @@ "range": "d2/testdata/d2oracle/TestSet/replace_fill_pattern.d2,1:22:32-1:27:37", "value": [ { - "string": "grain", - "raw_string": "grain" + "string": "grain" } ] } diff --git a/testdata/d2oracle/TestSet/replace_link.exp.json b/testdata/d2oracle/TestSet/replace_link.exp.json index e6ac316254..b8e5e01e09 100644 --- a/testdata/d2oracle/TestSet/replace_link.exp.json +++ b/testdata/d2oracle/TestSet/replace_link.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestSet/replace_link.d2,1:8:18-1:25:35", "value": [ { - "string": "https://apple.com", - "raw_string": "https://apple.com" + "string": "https://apple.com" } ] } diff --git a/testdata/d2oracle/TestSet/replace_shape.exp.json b/testdata/d2oracle/TestSet/replace_shape.exp.json index 9fa391b045..7d3024894f 100644 --- a/testdata/d2oracle/TestSet/replace_shape.exp.json +++ b/testdata/d2oracle/TestSet/replace_shape.exp.json @@ -41,8 +41,7 @@ "range": "d2/testdata/d2oracle/TestSet/replace_shape.d2,0:14:14-0:20:20", "value": [ { - "string": "circle", - "raw_string": "circle" + "string": "circle" } ] } diff --git a/testdata/d2oracle/TestSet/replace_style_edgecase.exp.json b/testdata/d2oracle/TestSet/replace_style_edgecase.exp.json index 197c9461bf..66bbecebf5 100644 --- a/testdata/d2oracle/TestSet/replace_style_edgecase.exp.json +++ b/testdata/d2oracle/TestSet/replace_style_edgecase.exp.json @@ -52,8 +52,7 @@ "range": "d2/testdata/d2oracle/TestSet/replace_style_edgecase.d2,0:19:19-0:25:25", "value": [ { - "string": "orange", - "raw_string": "orange" + "string": "orange" } ] } diff --git a/testdata/d2oracle/TestSet/replace_tooltip.exp.json b/testdata/d2oracle/TestSet/replace_tooltip.exp.json index c1490dc89a..18a8a85a6c 100644 --- a/testdata/d2oracle/TestSet/replace_tooltip.exp.json +++ b/testdata/d2oracle/TestSet/replace_tooltip.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestSet/replace_tooltip.d2,1:11:21-1:12:22", "value": [ { - "string": "y", - "raw_string": "y" + "string": "y" } ] } diff --git a/testdata/d2oracle/TestSet/scenarios-arrowhead.exp.json b/testdata/d2oracle/TestSet/scenarios-arrowhead.exp.json index 168961d593..e25834dfd6 100644 --- a/testdata/d2oracle/TestSet/scenarios-arrowhead.exp.json +++ b/testdata/d2oracle/TestSet/scenarios-arrowhead.exp.json @@ -88,8 +88,7 @@ "range": "d2/testdata/d2oracle/TestSet/scenarios-arrowhead.d2,1:26:36-1:34:44", "value": [ { - "string": "triangle", - "raw_string": "triangle" + "string": "triangle" } ] } @@ -283,8 +282,7 @@ "range": "d2/testdata/d2oracle/TestSet/scenarios-arrowhead.d2,8:30:124-8:37:131", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } @@ -869,8 +867,7 @@ "range": "d2/testdata/d2oracle/TestSet/scenarios-arrowhead.d2,8:30:124-8:37:131", "value": [ { - "string": "diamond", - "raw_string": "diamond" + "string": "diamond" } ] } diff --git a/testdata/d2oracle/TestSet/scenarios-label-primary-missing.exp.json b/testdata/d2oracle/TestSet/scenarios-label-primary-missing.exp.json index 9dd6fd8f11..e6e289764f 100644 --- a/testdata/d2oracle/TestSet/scenarios-label-primary-missing.exp.json +++ b/testdata/d2oracle/TestSet/scenarios-label-primary-missing.exp.json @@ -170,8 +170,7 @@ "range": "d2/testdata/d2oracle/TestSet/scenarios-label-primary-missing.d2,7:7:62-7:8:63", "value": [ { - "string": "b", - "raw_string": "b" + "string": "b" } ] } @@ -295,8 +294,7 @@ "range": "d2/testdata/d2oracle/TestSet/scenarios-label-primary-missing.d2,7:7:62-7:8:63", "value": [ { - "string": "b", - "raw_string": "b" + "string": "b" } ] } diff --git a/testdata/d2oracle/TestSet/scenarios-nested-usable-ref-style.exp.json b/testdata/d2oracle/TestSet/scenarios-nested-usable-ref-style.exp.json index 10d0c34abe..b7d308ac22 100644 --- a/testdata/d2oracle/TestSet/scenarios-nested-usable-ref-style.exp.json +++ b/testdata/d2oracle/TestSet/scenarios-nested-usable-ref-style.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestSet/scenarios-nested-usable-ref-style.d2,1:5:10-1:10:15", "value": [ { - "string": "outer", - "raw_string": "outer" + "string": "outer" } ] } diff --git a/testdata/d2oracle/TestSet/scenarios-usable-ref-style.exp.json b/testdata/d2oracle/TestSet/scenarios-usable-ref-style.exp.json index 446504d3bf..d51f5db66d 100644 --- a/testdata/d2oracle/TestSet/scenarios-usable-ref-style.exp.json +++ b/testdata/d2oracle/TestSet/scenarios-usable-ref-style.exp.json @@ -30,8 +30,7 @@ "range": "d2/testdata/d2oracle/TestSet/scenarios-usable-ref-style.d2,0:3:3-0:8:8", "value": [ { - "string": "outer", - "raw_string": "outer" + "string": "outer" } ] } diff --git a/testdata/d2oracle/TestSet/set_fill_pattern.exp.json b/testdata/d2oracle/TestSet/set_fill_pattern.exp.json index 476a81bc15..5552199b88 100644 --- a/testdata/d2oracle/TestSet/set_fill_pattern.exp.json +++ b/testdata/d2oracle/TestSet/set_fill_pattern.exp.json @@ -65,8 +65,7 @@ "range": "d2/testdata/d2oracle/TestSet/set_fill_pattern.d2,0:29:29-0:34:34", "value": [ { - "string": "grain", - "raw_string": "grain" + "string": "grain" } ] } diff --git a/testdata/d2oracle/TestSet/set_tooltip.exp.json b/testdata/d2oracle/TestSet/set_tooltip.exp.json index a832f994d0..e08e95d17c 100644 --- a/testdata/d2oracle/TestSet/set_tooltip.exp.json +++ b/testdata/d2oracle/TestSet/set_tooltip.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestSet/set_tooltip.d2,0:18:18-0:19:19", "value": [ { - "string": "y", - "raw_string": "y" + "string": "y" } ] } diff --git a/testdata/d2oracle/TestSet/shape.exp.json b/testdata/d2oracle/TestSet/shape.exp.json index bd4bedb40e..fc4a574696 100644 --- a/testdata/d2oracle/TestSet/shape.exp.json +++ b/testdata/d2oracle/TestSet/shape.exp.json @@ -54,8 +54,7 @@ "range": "d2/testdata/d2oracle/TestSet/shape.d2,0:16:16-0:22:22", "value": [ { - "string": "square", - "raw_string": "square" + "string": "square" } ] } diff --git a/testdata/d2oracle/TestSet/unapplied-classes-style-2.exp.json b/testdata/d2oracle/TestSet/unapplied-classes-style-2.exp.json index fce9058ea2..ef7596fba1 100644 --- a/testdata/d2oracle/TestSet/unapplied-classes-style-2.exp.json +++ b/testdata/d2oracle/TestSet/unapplied-classes-style-2.exp.json @@ -89,8 +89,7 @@ "range": "d2/testdata/d2oracle/TestSet/unapplied-classes-style-2.d2,2:16:34-2:19:37", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -167,8 +166,7 @@ "range": "d2/testdata/d2oracle/TestSet/unapplied-classes-style-2.d2,5:16:60-5:21:65", "value": [ { - "string": "green", - "raw_string": "green" + "string": "green" } ] } diff --git a/testdata/d2oracle/TestSet/unapplied-classes-style.exp.json b/testdata/d2oracle/TestSet/unapplied-classes-style.exp.json index b7ac7a166c..971db84a9e 100644 --- a/testdata/d2oracle/TestSet/unapplied-classes-style.exp.json +++ b/testdata/d2oracle/TestSet/unapplied-classes-style.exp.json @@ -89,8 +89,7 @@ "range": "d2/testdata/d2oracle/TestSet/unapplied-classes-style.d2,2:16:34-2:19:37", "value": [ { - "string": "red", - "raw_string": "red" + "string": "red" } ] } @@ -154,8 +153,7 @@ "range": "d2/testdata/d2oracle/TestSet/unapplied-classes-style.d2,5:14:58-5:19:63", "value": [ { - "string": "green", - "raw_string": "green" + "string": "green" } ] } From 78e9e4565e93ceb8aa75398fe4a70fec3f76c535 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 13:52:29 -0700 Subject: [PATCH 13/40] only coalesce if subbed --- d2ir/compile.go | 11 +- .../TestCLI_E2E/internal_linked_pdf.exp.pdf | Bin 80096 -> 80096 bytes .../TestCompile/array-classes.exp.json | 15 +- .../TestCompile/basic_icon.exp.json | 3 +- .../TestCompile/basic_sequence.exp.json | 3 +- .../TestCompile/basic_shape.exp.json | 3 +- .../TestCompile/class-shape-class.exp.json | 9 +- .../TestCompile/class_paren.exp.json | 9 +- .../TestCompile/class_style.exp.json | 6 +- .../d2compiler/TestCompile/classes.exp.json | 33 ++- .../dimensions_on_containers.exp.json | 24 +- .../dimensions_on_nonimage.exp.json | 3 +- .../edge_arrowhead_fields.exp.json | 6 +- .../edge_arrowhead_primary.exp.json | 3 +- .../TestCompile/edge_chain.exp.json | 3 +- .../TestCompile/edge_chain_map.exp.json | 3 +- .../TestCompile/edge_column_index.exp.json | 18 +- .../TestCompile/edge_flat_arrowhead.exp.json | 3 +- .../edge_flat_label_arrowhead.exp.json | 3 +- .../TestCompile/edge_index.exp.json | 6 +- .../TestCompile/edge_index_map.exp.json | 3 +- .../TestCompile/edge_index_nested.exp.json | 6 +- .../edge_index_nested_cross_scope.exp.json | 6 +- .../d2compiler/TestCompile/edge_map.exp.json | 3 +- .../TestCompile/edge_map_arrowhead.exp.json | 3 +- .../TestCompile/edge_mixed_arrowhead.exp.json | 6 +- .../edge_non_shape_arrowhead.exp.json | 3 +- .../edge_semiflat_arrowhead.exp.json | 3 +- .../TestCompile/fill-pattern.exp.json | 3 +- .../icon-near-composite-together.exp.json | 3 +- .../TestCompile/image_style.exp.json | 9 +- .../label-near-composite-separate.exp.json | 6 +- .../label-near-composite-together.exp.json | 3 +- .../TestCompile/label-near-parent.exp.json | 3 +- .../TestCompile/link-board-mixed.exp.json | 18 +- .../TestCompile/missing-class.exp.json | 3 +- .../TestCompile/near_constant.exp.json | 3 +- .../TestCompile/nested-array-classes.exp.json | 3 +- .../TestCompile/nested_sql.exp.json | 9 +- .../d2compiler/TestCompile/path_link.exp.json | 3 +- .../TestCompile/reordered-classes.exp.json | 9 +- .../reserved_icon_near_style.exp.json | 12 +- .../TestCompile/root_direction.exp.json | 3 +- .../TestCompile/root_sequence.exp.json | 3 +- .../TestCompile/sequence-timestamp.exp.json | 3 +- .../TestCompile/sequence_container.exp.json | 3 +- .../TestCompile/sequence_container_2.exp.json | 3 +- .../sequence_grouped_note.exp.json | 3 +- .../TestCompile/sequence_scoping.exp.json | 3 +- .../TestCompile/set_direction.exp.json | 3 +- .../single_dimension_on_circle.exp.json | 3 +- .../TestCompile/sql-constraints.exp.json | 6 +- .../TestCompile/sql-regression.exp.json | 6 +- .../d2compiler/TestCompile/sql_paren.exp.json | 9 +- .../table_connection_attr.exp.json | 6 +- .../TestCompile/table_style.exp.json | 6 +- .../TestCompile/table_style_map.exp.json | 9 +- .../TestCompile/text-transform.exp.json | 12 +- .../underscore_edge_existing.exp.json | 6 +- .../underscore_edge_index.exp.json | 6 +- .../underscore_parent_preference_1.exp.json | 6 +- .../underscore_parent_preference_2.exp.json | 6 +- .../d2compiler/TestCompile/url_link.exp.json | 3 +- ..._and_not_url_tooltip_concurrently.exp.json | 6 +- .../url_link_non_url_tooltip_ok.exp.json | 6 +- .../TestCompile/url_tooltip.exp.json | 3 +- .../TestCompile/wrong_column_index.exp.json | 33 ++- .../TestCompile2/boards/isFolderOnly.exp.json | 9 +- .../TestCompile2/vars/basic/combined.exp.json | 3 +- .../vars/basic/double-quoted.exp.json | 3 +- .../vars/basic/edge_label.exp.json | 3 +- .../TestCompile2/vars/basic/label.exp.json | 3 +- .../TestCompile2/vars/basic/nested.exp.json | 3 +- .../vars/basic/single-quoted.exp.json | 3 +- .../TestCompile2/vars/basic/style.exp.json | 3 +- .../TestCompile2/vars/boards/layer.exp.json | 6 +- .../TestCompile2/vars/boards/overlay.exp.json | 21 +- .../TestCompile2/vars/boards/replace.exp.json | 9 +- .../vars/boards/scenario.exp.json | 6 +- .../TestCompile2/vars/override/label.exp.json | 6 +- .../d2ir/TestCompile/classes/basic.exp.json | 15 +- .../TestCompile/classes/inherited.exp.json | 240 ++++++++++++------ .../TestCompile/classes/layer-modify.exp.json | 48 ++-- .../d2ir/TestCompile/classes/merge.exp.json | 30 ++- .../d2ir/TestCompile/classes/nested.exp.json | 45 ++-- .../d2ir/TestCompile/fields/label.exp.json | 6 +- .../d2ir/TestCompile/fields/nested.exp.json | 9 +- .../TestCompile/imports/nested/map.exp.json | 12 +- .../imports/nested/scalar.exp.json | 3 +- .../d2ir/TestCompile/imports/spread.exp.json | 6 +- .../d2ir/TestCompile/imports/value.exp.json | 12 +- .../d2ir/TestCompile/imports/vars/1.exp.json | 9 +- .../TestCreate/make_scope_multiline.exp.json | 3 +- .../make_scope_multiline_spacing_1.exp.json | 3 +- .../make_scope_multiline_spacing_2.exp.json | 3 +- .../TestDelete/arrowhead_label.exp.json | 3 +- testdata/d2oracle/TestDelete/chaos_1.exp.json | 9 +- .../children_edge_conflicts.exp.json | 3 +- .../children_edges_flat_conflicts.exp.json | 6 +- .../children_flat_conflicts.exp.json | 3 +- .../children_multiple_conflicts.exp.json | 3 +- ...ldren_nested_referenced_conflicts.exp.json | 6 +- .../children_referenced_conflicts.exp.json | 3 +- .../TestDelete/container_near.exp.json | 6 +- .../delete_container_of_near.exp.json | 6 +- .../d2oracle/TestDelete/delete_icon.exp.json | 3 +- .../TestDelete/edge_decrement.exp.json | 12 +- .../d2oracle/TestDelete/multi_near.exp.json | 6 +- .../only_delete_edge_reserved.exp.json | 3 +- .../only_delete_obj_reserved.exp.json | 3 +- .../d2oracle/TestDelete/save_map.exp.json | 3 +- .../TestDelete/save_map_with_primary.exp.json | 3 +- .../TestDelete/shape_sql_table.exp.json | 6 +- .../d2oracle/TestDelete/table_refs.exp.json | 3 +- .../TestMove/append_multiple_styles.exp.json | 3 +- .../container_conflicts_generated.exp.json | 18 +- .../d2oracle/TestMove/container_near.exp.json | 3 +- testdata/d2oracle/TestMove/duplicate.exp.json | 3 +- .../d2oracle/TestMove/flat_merge.exp.json | 3 +- testdata/d2oracle/TestMove/flat_near.exp.json | 3 +- .../flat_reparent_with_map_value.exp.json | 3 +- ...lat_reparent_with_mixed_map_value.exp.json | 3 +- .../flat_reparent_with_value.exp.json | 3 +- .../d2oracle/TestMove/flat_style.exp.json | 3 +- testdata/d2oracle/TestMove/gnarly_1.exp.json | 6 +- .../include_descendants_near.exp.json | 3 +- ...ude_descendants_nested_reserved_2.exp.json | 3 +- ...ude_descendants_nested_reserved_3.exp.json | 3 +- .../TestMove/include_descendants_sql.exp.json | 6 +- .../into_container_with_flat_keys.exp.json | 6 +- .../d2oracle/TestMove/map_transplant.exp.json | 3 +- .../d2oracle/TestMove/map_with_label.exp.json | 3 +- .../d2oracle/TestMove/merge_reserved.exp.json | 6 +- testdata/d2oracle/TestMove/near.exp.json | 3 +- .../TestMove/nested_reserved_2.exp.json | 3 +- .../TestMove/nested_reserved_3.exp.json | 3 +- .../d2oracle/TestMove/parentheses.exp.json | 6 +- .../d2oracle/TestMove/slice_style.exp.json | 3 +- .../TestMove/underscore_merge.exp.json | 6 +- .../TestReconnectEdge/indexed_ref.exp.json | 3 +- .../preserve_old_obj.exp.json | 3 +- .../TestReconnectEdge/second_index.exp.json | 6 +- .../d2oracle/TestRename/container.exp.json | 9 +- testdata/d2oracle/TestRename/edges.exp.json | 3 +- testdata/d2oracle/TestRename/near.exp.json | 3 +- .../d2oracle/TestSet/classes-style.exp.json | 9 +- .../TestSet/dupe-classes-style.exp.json | 9 +- testdata/d2oracle/TestSet/edge.exp.json | 3 +- testdata/d2oracle/TestSet/edge_chain.exp.json | 6 +- .../TestSet/edge_chain_nested_set.exp.json | 3 +- .../edge_flat_merge_arrowhead.exp.json | 3 +- .../d2oracle/TestSet/edge_index_case.exp.json | 3 +- .../TestSet/edge_index_nested.exp.json | 3 +- .../TestSet/edge_merge_arrowhead.exp.json | 3 +- .../TestSet/edge_nested_label_set.exp.json | 3 +- .../TestSet/edge_replace_arrowhead.exp.json | 3 +- .../edge_replace_arrowhead_indexed.exp.json | 3 +- .../TestSet/edge_set_arrowhead.exp.json | 3 +- testdata/d2oracle/TestSet/icon.exp.json | 3 +- .../d2oracle/TestSet/inline_style.exp.json | 3 +- testdata/d2oracle/TestSet/label.exp.json | 3 +- .../d2oracle/TestSet/label_replace.exp.json | 3 +- .../d2oracle/TestSet/map_key_missing.exp.json | 3 +- .../d2oracle/TestSet/nested_alex.exp.json | 9 +- .../TestSet/replace_arrowhead.exp.json | 3 +- .../TestSet/replace_arrowhead_map.exp.json | 3 +- .../TestSet/replace_fill_pattern.exp.json | 3 +- .../d2oracle/TestSet/replace_link.exp.json | 3 +- .../d2oracle/TestSet/replace_shape.exp.json | 3 +- .../TestSet/replace_style_edgecase.exp.json | 3 +- .../d2oracle/TestSet/replace_tooltip.exp.json | 3 +- .../TestSet/scenarios-arrowhead.exp.json | 9 +- .../scenarios-label-primary-missing.exp.json | 6 +- ...scenarios-nested-usable-ref-style.exp.json | 3 +- .../scenarios-usable-ref-style.exp.json | 3 +- .../TestSet/set_fill_pattern.exp.json | 3 +- .../d2oracle/TestSet/set_tooltip.exp.json | 3 +- testdata/d2oracle/TestSet/shape.exp.json | 3 +- .../unapplied-classes-style-2.exp.json | 6 +- .../TestSet/unapplied-classes-style.exp.json | 6 +- 180 files changed, 869 insertions(+), 459 deletions(-) diff --git a/d2ir/compile.go b/d2ir/compile.go index 9b880b767a..90c21d060f 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -108,6 +108,7 @@ func (c *compiler) resolveSubstitutions(refctx *RefContext) { varsMap = vars.Map() } + subbed := false switch { case refctx.Key.Value.UnquotedString != nil: for i, box := range refctx.Key.Value.UnquotedString.Value { @@ -115,20 +116,26 @@ func (c *compiler) resolveSubstitutions(refctx *RefContext) { resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) if resolvedField != nil { refctx.Key.Value.UnquotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + subbed = true } } } - refctx.Key.Value.UnquotedString.Coalesce() + if subbed { + refctx.Key.Value.UnquotedString.Coalesce() + } case refctx.Key.Value.DoubleQuotedString != nil: for i, box := range refctx.Key.Value.DoubleQuotedString.Value { if box.Substitution != nil { resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) if resolvedField != nil { refctx.Key.Value.DoubleQuotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + subbed = true } } } - refctx.Key.Value.DoubleQuotedString.Coalesce() + if subbed { + refctx.Key.Value.DoubleQuotedString.Coalesce() + } } } diff --git a/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf index c3f44895dd54e116e5a1400d3a6fee089be81b9d..7f3e137b3e86af39639573844a36ae259461e050 100644 GIT binary patch delta 50 zcmaFxk>$ZhmWC~iPfZm}4NNUHx%7SWQ(O{DQWZ2@tc(ndj19~U4GoP!a@$$W7;iHH E0LMZPN&o-= delta 50 zcmaFxk>$ZhmWC~iPfZm}OpMGlx%7SWQ(O{DQWZ2@tc(ndj19~U4GoP!a@$$W7;iHH E0LI7 Date: Tue, 11 Jul 2023 14:01:35 -0700 Subject: [PATCH 14/40] cleanup --- d2compiler/compile_test.go | 13 +++++++++++++ d2ir/compile.go | 10 +++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 1912a92584..e9a59d6cca 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3473,6 +3473,19 @@ hi: ${z} `, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable "z"`) }, }, + { + name: "nested-missing", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: { + y: hey + } +} +hi: ${x.z} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.d2:7:1: could not resolve variable "x.z"`) + }, + }, { name: "edge", run: func(t *testing.T) { diff --git a/d2ir/compile.go b/d2ir/compile.go index 90c21d060f..3fa8f3edb5 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -98,11 +98,12 @@ func (c *compiler) overlayClasses(m *Map) { } func (c *compiler) resolveSubstitutions(refctx *RefContext) { - varsMap := &Map{} boardScope := refctx.ScopeMap if NodeBoardKind(refctx.ScopeMap) == "" { boardScope = ParentBoard(refctx.ScopeMap).Map() } + + varsMap := &Map{} vars := boardScope.GetField("vars") if vars != nil { varsMap = vars.Map() @@ -154,13 +155,12 @@ func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d vars = r.Map() resolved = r } + if resolved == nil { c.errorf(mk, `could not resolve variable "%s"`, strings.Join(substitution.IDA(), ".")) + } else if resolved.Composite != nil { + c.errorf(mk, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), ".")) } else { - if resolved.Composite != nil { - c.errorf(mk, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), ".")) - return nil - } return resolved } return nil From 85cf491d74cba05c9d06830ebe26eba22f540e77 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 14:56:09 -0700 Subject: [PATCH 15/40] quotes --- d2compiler/compile_test.go | 35 ++ d2graph/d2graph.go | 1 + d2ir/compile.go | 9 +- .../vars/basic/edge_label.exp.json | 5 +- .../TestCompile2/vars/basic/label.exp.json | 5 +- .../TestCompile2/vars/basic/nested.exp.json | 5 +- .../TestCompile2/vars/basic/number.exp.json | 11 +- .../vars/basic/quoted-var-quoted-sub.exp.json | 177 ++++++++++ .../vars/basic/quoted-var.exp.json | 330 ++++++++++++++++++ .../TestCompile2/vars/basic/style.exp.json | 5 +- .../TestCompile2/vars/boards/layer.exp.json | 10 +- .../TestCompile2/vars/boards/overlay.exp.json | 40 ++- .../TestCompile2/vars/boards/replace.exp.json | 10 +- .../vars/boards/scenario.exp.json | 10 +- .../vars/errors/nested-missing.exp.json | 11 + .../TestCompile2/vars/override/label.exp.json | 5 +- 16 files changed, 622 insertions(+), 47 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/nested-missing.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index e9a59d6cca..d642833355 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3290,6 +3290,41 @@ a -> b: ${x} assert.Equal(t, "im a var", g.Edges[0].Label.Value) }, }, + { + name: "quoted-var", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + primaryColors: { + button: { + active: "#4baae5" + } + } +} + +button: { + style: { + border-radius: 5 + fill: ${primaryColors.button.active} + } +} +`, "") + assert.Equal(t, `#4baae5`, g.Objects[0].Style.Fill.Value) + }, + }, + { + name: "quoted-var-quoted-sub", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: "hi" +} + +y: "hey ${x}" +`, "") + assert.Equal(t, `hey "hi"`, g.Objects[0].Label.Value) + }, + }, } for _, tc := range tca { diff --git a/d2graph/d2graph.go b/d2graph/d2graph.go index 26413dcb3e..f7aa7ec2b3 100644 --- a/d2graph/d2graph.go +++ b/d2graph/d2graph.go @@ -1651,6 +1651,7 @@ var SimpleReservedKeywords = map[string]struct{}{ "vertical-gap": {}, "horizontal-gap": {}, "class": {}, + "vars": {}, } // ReservedKeywordHolders are reserved keywords that are meaningless on its own and must hold composites diff --git a/d2ir/compile.go b/d2ir/compile.go index 3fa8f3edb5..bcfabb3464 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -116,8 +116,13 @@ func (c *compiler) resolveSubstitutions(refctx *RefContext) { if box.Substitution != nil { resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) if resolvedField != nil { - refctx.Key.Value.UnquotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) - subbed = true + // If lone and unquoted, replace with value of sub + if len(refctx.Key.Value.UnquotedString.Value) == 1 { + refctx.Key.Value = d2ast.MakeValueBox(resolvedField.Primary().Value) + } else { + refctx.Key.Value.UnquotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + subbed = true + } } } } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json index f7d87362c1..77d0d380fb 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json @@ -112,10 +112,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:8:33-4:9:34", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var" + "string": "im a var", + "raw_string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json index 5a0acd806d..723fae3221 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json @@ -89,10 +89,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:4:29-4:5:30", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var" + "string": "im a var", + "raw_string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json index d32d26e50c..7593600784 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json @@ -182,10 +182,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:15:86", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:14:49-4:17:52", "value": [ { - "string": "red" + "string": "red", + "raw_string": "red" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json index 37d67c845d..a7a5fb0e59 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json @@ -108,13 +108,10 @@ }, "primary": {}, "value": { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:16:45", - "value": [ - { - "string": "2" - } - ] + "number": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:10:19-2:11:20", + "raw": "2", + "value": "2" } } } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.exp.json new file mode 100644 index 0000000000..1004100aab --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.exp.json @@ -0,0 +1,177 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,0:0:0-6:0:36", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,1:0:1-3:1:20", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,1:6:7-3:1:20", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,2:2:11-2:9:18", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,2:5:14-2:9:18", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,5:0:22-5:13:35", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,5:0:22-5:1:23", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,5:0:22-5:1:23", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,5:3:25-5:13:35", + "value": [ + { + "string": "hey \"hi\"" + } + ] + } + } + } + } + ] + }, + "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": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,5:0:22-5:1:23", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,5:0:22-5:1:23", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hey \"hi\"" + }, + "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/TestCompile2/vars/basic/quoted-var.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json new file mode 100644 index 0000000000..4b4d56a324 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json @@ -0,0 +1,330 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,0:0:0-15:0:168", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,1:0:1-7:1:77", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,1:6:7-7:1:77", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,2:2:11-6:3:75", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,2:2:11-2:15:24", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,2:2:11-2:15:24", + "value": [ + { + "string": "primaryColors", + "raw_string": "primaryColors" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,2:17:26-6:3:75", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,3:4:32-5:5:71", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,3:4:32-3:10:38", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,3:4:32-3:10:38", + "value": [ + { + "string": "button", + "raw_string": "button" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,3:12:40-5:5:71", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,4:6:48-4:23:65", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,4:6:48-4:12:54", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,4:6:48-4:12:54", + "value": [ + { + "string": "active", + "raw_string": "active" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,4:14:56-4:23:65", + "value": [ + { + "string": "#4baae5", + "raw_string": "#4baae5" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,9:0:79-14:1:167", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,9:0:79-9:6:85", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,9:0:79-9:6:85", + "value": [ + { + "string": "button", + "raw_string": "button" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,9:8:87-14:1:167", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,10:2:91-13:3:165", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,10:2:91-10:7:96", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,10:2:91-10:7:96", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,10:9:98-13:3:165", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,11:4:104-11:20:120", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,11:4:104-11:17:117", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,11:4:104-11:17:117", + "value": [ + { + "string": "border-radius", + "raw_string": "border-radius" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,11:19:119-11:20:120", + "raw": "5", + "value": "5" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:4:125-12:40:161", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:4:125-12:8:129", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:4:125-12:8:129", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,4:14:56-4:23:65", + "value": [ + { + "string": "#4baae5", + "raw_string": "#4baae5" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": "button", + "id_val": "button", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,9:0:79-9:6:85", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,9:0:79-9:6:85", + "value": [ + { + "string": "button", + "raw_string": "button" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "button" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "#4baae5" + }, + "borderRadius": { + "value": "5" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json index 11ae2fe4d6..c5a5ae699e 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json @@ -124,10 +124,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:15:53", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:17:26-2:20:29", "value": [ { - "string": "red" + "string": "red", + "raw_string": "red" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json index 7f3f693b18..6ca33821b2 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json @@ -137,10 +137,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var" + "string": "im a var", + "raw_string": "im a var" } ] } @@ -271,10 +272,11 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var" + "string": "im a var", + "raw_string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json index 23431936c4..06ce2bc1cb 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json @@ -199,10 +199,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var" + "string": "im x var", + "raw_string": "im x var" } ] } @@ -231,10 +232,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", "value": [ { - "string": "im y var" + "string": "im y var", + "raw_string": "im y var" } ] } @@ -383,10 +385,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var" + "string": "im x var", + "raw_string": "im x var" } ] } @@ -415,10 +418,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", "value": [ { - "string": "im y var" + "string": "im y var", + "raw_string": "im y var" } ] } @@ -581,10 +585,11 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var" + "string": "im x var", + "raw_string": "im x var" } ] } @@ -612,10 +617,11 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", "value": [ { - "string": "im y var" + "string": "im y var", + "raw_string": "im y var" } ] } @@ -862,10 +868,11 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", "value": [ { - "string": "im x var" + "string": "im x var", + "raw_string": "im x var" } ] } @@ -893,10 +900,11 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", "value": [ { - "string": "im y var" + "string": "im y var", + "raw_string": "im y var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json index fc75006dd6..0637551ac5 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json @@ -199,10 +199,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", "value": [ { - "string": "im replaced x var" + "string": "im replaced x var", + "raw_string": "im replaced x var" } ] } @@ -333,10 +334,11 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", "value": [ { - "string": "im replaced x var" + "string": "im replaced x var", + "raw_string": "im replaced x var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json index 571e94ad86..aed67f5838 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json @@ -137,10 +137,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var" + "string": "im a var", + "raw_string": "im a var" } ] } @@ -271,10 +272,11 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var" + "string": "im a var", + "raw_string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.exp.json new file mode 100644 index 0000000000..96bef919ae --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.d2,6:0:33-6:10:43", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.d2:7:1: could not resolve variable \"x.z\"" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json index 9040dfa59a..f1a1cb4be7 100644 --- a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json @@ -89,10 +89,11 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:4:29-4:5:30", + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:5:14-2:13:22", "value": [ { - "string": "im a var" + "string": "im a var", + "raw_string": "im a var" } ] } From 4a9327e102f284125bc3abf57ff1bf0369069551 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 15:05:16 -0700 Subject: [PATCH 16/40] non-root err check --- d2compiler/compile.go | 3 +++ d2compiler/compile_test.go | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index c1800e5715..c1bed291b2 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -283,6 +283,9 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") } } + if d2ir.NodeBoardKind(d2ir.ParentMap(f)) == "" { + c.errorf(f.LastRef().AST(), "vars must be defined at the root of a board") + } return } else if isReserved { c.compileReserved(&obj.Attributes, f) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index d642833355..878199312a 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3545,6 +3545,18 @@ hi: ${colors} `, `d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable "colors"`) }, }, + { + name: "non-root", + run: func(t *testing.T) { + assertCompile(t, ` +x: { + vars: { + x: hey + } +} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/non-root.d2:3:3: vars must be defined at the root of a board`) + }, + }, } for _, tc := range tca { From 92d87b553f43748419c7c4c823b66727171c119a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 17:19:34 -0700 Subject: [PATCH 17/40] new implementation --- d2compiler/compile.go | 3 - d2compiler/compile_test.go | 33 +- d2ir/compile.go | 78 ++--- .../TestCLI_E2E/internal_linked_pdf.exp.pdf | Bin 80096 -> 80096 bytes lib/urlenc/testdata/TestChanges.exp.txt | 2 +- .../vars/basic/edge-label.exp.json | 292 ++++++++++++++++ .../vars/basic/edge_label.exp.json | 23 +- .../TestCompile2/vars/basic/label.exp.json | 23 +- .../TestCompile2/vars/basic/nested.exp.json | 43 ++- .../TestCompile2/vars/basic/number.exp.json | 27 +- .../vars/basic/quoted-var.exp.json | 45 ++- .../vars/basic/shape-label.exp.json | 193 ++++++++++ .../TestCompile2/vars/basic/style.exp.json | 21 +- .../TestCompile2/vars/boards/layer.exp.json | 21 +- .../TestCompile2/vars/boards/overlay.exp.json | 84 ++++- .../TestCompile2/vars/boards/replace.exp.json | 21 +- .../vars/boards/scenario.exp.json | 21 +- .../TestCompile2/vars/errors/map.exp.json | 2 +- .../TestCompile2/vars/errors/missing.exp.json | 2 +- .../vars/errors/nested-missing.exp.json | 2 +- .../TestCompile2/vars/override/label.exp.json | 21 +- .../TestCompile2/vars/override/map.exp.json | 329 ++++++++++++++++++ .../d2ir/TestCompile/imports/vars/1.exp.json | 161 ++------- 23 files changed, 1195 insertions(+), 252 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/override/map.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index c1bed291b2..c1800e5715 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -283,9 +283,6 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") } } - if d2ir.NodeBoardKind(d2ir.ParentMap(f)) == "" { - c.errorf(f.LastRef().AST(), "vars must be defined at the root of a board") - } return } else if isReserved { c.compileReserved(&obj.Attributes, f) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 878199312a..b401bb4f56 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3181,7 +3181,7 @@ func testVars(t *testing.T) { run func(t *testing.T) }{ { - name: "label", + name: "shape-label", run: func(t *testing.T) { g := assertCompile(t, ` vars: { @@ -3278,7 +3278,7 @@ hi: '1 ${x} 2' }, }, { - name: "edge label", + name: "edge-label", run: func(t *testing.T) { g := assertCompile(t, ` vars: { @@ -3361,6 +3361,23 @@ hi: not a var assert.Equal(t, "not a var", g.Objects[0].Label.Value) }, }, + { + name: "map", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im root var +} +a: { + vars: { + x: im nested var + } + hi: ${x} +} +`, "") + assert.Equal(t, "im nested var", g.Objects[1].Label.Value) + }, + }, } for _, tc := range tca { @@ -3545,18 +3562,6 @@ hi: ${colors} `, `d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable "colors"`) }, }, - { - name: "non-root", - run: func(t *testing.T) { - assertCompile(t, ` -x: { - vars: { - x: hey - } -} -`, `d2/testdata/d2compiler/TestCompile2/vars/errors/non-root.d2:3:3: vars must be defined at the root of a board`) - }, - }, } for _, tc := range tca { diff --git a/d2ir/compile.go b/d2ir/compile.go index bcfabb3464..c8fae9c026 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -53,6 +53,7 @@ func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, error) { defer c.popImportStack() c.compileMap(m, ast, ast) + c.compileSubstitutions(m, nil) c.overlayClasses(m) if !c.err.Empty() { return nil, c.err @@ -97,55 +98,63 @@ func (c *compiler) overlayClasses(m *Map) { } } -func (c *compiler) resolveSubstitutions(refctx *RefContext) { - boardScope := refctx.ScopeMap - if NodeBoardKind(refctx.ScopeMap) == "" { - boardScope = ParentBoard(refctx.ScopeMap).Map() +func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { + for _, f := range m.Fields { + if f.Name == "vars" && f.Map() != nil { + varsStack = append([]*Map{f.Map()}, varsStack...) + } + if f.Primary() != nil { + c.resolveSubstitutions(varsStack, f.LastRef().AST(), f.Primary()) + } + if f.Map() != nil { + c.compileSubstitutions(f.Map(), varsStack) + } } - - varsMap := &Map{} - vars := boardScope.GetField("vars") - if vars != nil { - varsMap = vars.Map() + for _, e := range m.Edges { + if e.Primary() != nil { + c.resolveSubstitutions(varsStack, e.LastRef().AST(), e.Primary()) + } } +} +func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scalar *Scalar) { subbed := false - switch { - case refctx.Key.Value.UnquotedString != nil: - for i, box := range refctx.Key.Value.UnquotedString.Value { + switch s := scalar.Value.(type) { + case *d2ast.UnquotedString: + for i, box := range s.Value { if box.Substitution != nil { - resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) + resolvedField := c.resolveSubstitution(varsStack[0], node, box.Substitution) if resolvedField != nil { // If lone and unquoted, replace with value of sub - if len(refctx.Key.Value.UnquotedString.Value) == 1 { - refctx.Key.Value = d2ast.MakeValueBox(resolvedField.Primary().Value) + if len(s.Value) == 1 { + scalar.Value = resolvedField.Primary().Value } else { - refctx.Key.Value.UnquotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) subbed = true } } } } if subbed { - refctx.Key.Value.UnquotedString.Coalesce() + s.Coalesce() } - case refctx.Key.Value.DoubleQuotedString != nil: - for i, box := range refctx.Key.Value.DoubleQuotedString.Value { + case *d2ast.DoubleQuotedString: + for i, box := range s.Value { if box.Substitution != nil { - resolvedField := c.resolveSubstitution(varsMap, refctx.Key, box.Substitution) + resolvedField := c.resolveSubstitution(varsStack[0], node, box.Substitution) if resolvedField != nil { - refctx.Key.Value.DoubleQuotedString.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) subbed = true } } } if subbed { - refctx.Key.Value.DoubleQuotedString.Coalesce() + s.Coalesce() } } } -func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d2ast.Substitution) *Field { +func (c *compiler) resolveSubstitution(vars *Map, node d2ast.Node, substitution *d2ast.Substitution) *Field { var resolved *Field for _, p := range substitution.Path { if vars == nil { @@ -162,29 +171,15 @@ func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d } if resolved == nil { - c.errorf(mk, `could not resolve variable "%s"`, strings.Join(substitution.IDA(), ".")) + c.errorf(node, `could not resolve variable "%s"`, strings.Join(substitution.IDA(), ".")) } else if resolved.Composite != nil { - c.errorf(mk, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), ".")) + c.errorf(node, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), ".")) } else { return resolved } return nil } -func (c *compiler) compileVars(m *Map, ast *d2ast.Map) { - for _, n := range ast.Nodes { - if n.MapKey != nil && n.MapKey.Key != nil && len(n.MapKey.Key.Path) == 1 && strings.EqualFold(n.MapKey.Key.Path[0].Unbox().ScalarString(), "vars") { - c.compileKey(&RefContext{ - Key: n.MapKey, - Scope: ast, - ScopeMap: m, - ScopeAST: ast, - }) - break - } - } -} - func (c *compiler) overlayVars(base, overlay *Map) { vars := overlay.GetField("vars") if vars == nil { @@ -215,10 +210,6 @@ func (c *compiler) overlay(base *Map, f *Field) { } func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { - // When compiling a new board, compile vars before all else, as it might be referenced - if NodeBoardKind(dst) != "" { - c.compileVars(dst, ast) - } for _, n := range ast.Nodes { switch { case n.MapKey != nil: @@ -252,7 +243,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { } func (c *compiler) compileKey(refctx *RefContext) { - c.resolveSubstitutions(refctx) if len(refctx.Key.Edges) == 0 { c.compileField(refctx.ScopeMap, refctx.Key.Key, refctx) } else { diff --git a/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf index 7f3e137b3e86af39639573844a36ae259461e050..763c539b9822b93b1cc157155275f42bdc34ae08 100644 GIT binary patch delta 66 zcmaFxk>$ZhmWC~iYfPr!HDNTEzRHBra5}Fk<8?)ILkk0QO)h=k{1lhOl2io^7b_zJ TBVz+|LqkKb+;&zo#@kE)9}g6F delta 66 zcmaFxk>$ZhmWC~iYfPr!Ghx)9zRHBrXgaSc<8?)2Qv*{=O)h=k{1lhOl2io^7b_zJ TBVz+|LqkKb+;&zo#@kE)9{3b? diff --git a/lib/urlenc/testdata/TestChanges.exp.txt b/lib/urlenc/testdata/TestChanges.exp.txt index c8aeb9aed3..0ab14ee949 100644 --- a/lib/urlenc/testdata/TestChanges.exp.txt +++ b/lib/urlenc/testdata/TestChanges.exp.txt @@ -1 +1 @@ -vFdtb9s4Ev6uXzFwWvQuiN5sN0mFwx1yadMUaLHe2rv9UmBBiyOZrUSqJGUn3ea_L4aSbFl2usUusPkQkzPkzMNnXkhZUSIpoBR3qBMYjeB3DwDvqoJJRkwm8K3kHgDAyQmcni72NpyeOo0Pb-QnTC0wbs5gs1K-VX6mikJtzkDJpWKaC5m3a6-VXKM2zjqUitcFdppaG6WFzM8qlovGf6tabJBZ4MjrqhBpXzNHvUYOnFkGhcrzxtE378GboaoKBC5Mqtao7xMYDUXwURrUa5HiyGO8JeGKN6dzVDiiA0qZBEYnaczG2WTkPXje7lzQmkhg9NNO2LO8zzL4_4UhjiNLDu0fWdRi9lJKRyFRR9sY5ppVqy-FB5CqskRpPQBbGFYJ76G3PmjXJfCaBj-__ShvkKOmyoO51cwquHbl0NBB6ZqAKFlOUaPkT2BlbWWSMKyrQjEebMRnUSIXLFA6D2lW0SwkHEqa0K7qchnGYXwRtj5_e6tyFZh1HsbjKKru_KE8qGS-D7s9VJeeJyeUImjD2qAGWofSwuqea5crZ7AWRixFIew9ZKKwSGnmfetbbMhJYPF27l_N3sC_lkjkc6w0pkTHv4_QRkHYD8swSv_x4cCJZzeCWhFklDSLdnKjHWwOTQD3uaWZCSxqzYzVdWqJgdCoVLAijOKJ35r0Y-JrGKmHnkeCfCz-YrZSEmGDy8cXdxzdLhYzuJJcK8G9DS4T-IDLH0bNvtYaww-4fDqO5k1uPx1H19SHw6uq2pO-VCUT0hw_lPemIsxJz_OzzrUxF8H668Y5FCZ0W8Jf0bXuD0JjgcaErKoK9IWz4sdj_3yaL_2q1iR9PoniC7_8JONJUfjsf084Eia_yJ88O4TSkpEcISHlchqQKBPUiB0ialcNO6Epmba-g2B8i-lKqkLlAk34PB6HrLHb6F0ZHLKwwaXLw23UdjloUqVdY-8a90c5d6LRke6WZRyzmLrbSpUImsnPtPeWJu_dxOtZ7pre9kqYP9qmDuAsVlpkFt7Pro-s3nO-Q9m7CROYDsQEP4qiV5OXBP97CFqQzknb8G-3Y-fu5NGmf7z--6b-EtydgSNkDbR_n5zHvLXElEyumLVMwjiBd93Ey8VXuqvTzwm87oZe034cFQnM3aS5dzxLzfi-EpQfbggzgQPXPU8DzdbZQN7zNzxG569tCYN6aKtzIK00cuHei93pxwnMdsI2of_84ku59F0x-5XMg6xglmau0KmGz6fnsft3Gb9obzKHvqsGl39NWX63KreE9QNTYpmydIUJvGtHR1oQj7-cZxHD4i6qlA7SQtU8o-smkGjDShPZ1i9UrkzIMZrGz6OpH3G-9KeT7NxfXr5AP8NoOo0macouud955e15vAxtukrghn56h-gewAlYXeOOR3rhNtuYrTXSRjf48a1EnpB54oiji_qHdzqolAqt8w6Ey7DGmHckN_6p1GghEJpDEDvw2140DlLdvDz6WbVXYPQoPNRuE2c0GuqOVEb_Ttg2on6L2qkOoSVwzSQXnFlsUmTXSsfbF-tjLeuwIOiP5Dvr-t22fQ-X31zcXN68ouUP9GnDdHG_FJon8IqG_xea3o-1ZXkCv1jm7teKUbjn9NO-n2sprECTwPVu4j14aNMEgiBAmx7w63RdWt92L1Gvn23bAO0J27j0Zc7WjsLme9F4fwQAAP__ \ No newline at end of file +vFdtb9s4Ev6uXzFwWvQuiN5sN0mFwx1yadMUaLHe2rv9UmBBiyOZrUSqJGUn3ea_L4aSbFl2usUusPkQkzPkzMNnXkhZUSIpoRR3qBMYjeB3DwDvqoJJRmwm8K3kHgDAyQmcni72NpyeOo0Pb-QnTC0wbs5gs1K-VX6mikJtzkDJpWKaC5m3a6-VXKM2zjqUitcFdppaG6WFzM8qlovGf6tabJBZ4MjrqhBpXzNHvUYOnFkGhcrzxtE378GboaoKBC5Mqtao7xMYDUXwURrUa5HiyGO8JeGKN6dzVDiyA0qbBEYnaczG2WTkPXje7lzQmkhg9NNO2LO8zzL4_4UhjiNLDu0fWdRi9lJKSSFRR9sY5ppVqy-FB5CqskRpPQBbGFYJ76G3PmjXJfCaBj-__ShvkKOm6oO51cwquHYl0dBBKZuAKFlOUaMCSGBlbWWSMKyrQjEebMRnUSIXLFA6D2lW0SwkHEqa0K7qchnGYXwRtj5_e6tyFZh1HsbjKKru_KE8qGS-D7s9VJeeJyeUImjD2qAGWofSwuqea5crZ7AWRixFIew9ZKKwSGnmfetbbMhJYPF27l_N3sC_lkjkc6w0pkTHv4_QRkHYD8swSv_x4cCJZzeC2hFklDSLdnKjHWwOTQD3uaWZCSxqzYzVdWqJgdCoVLAijOKJ35r0Y-JrGKmHnkeCfCz-YrZSEmGDy8cXdxzdLhYzuJJcK8G9DS4T-IDLH0bNvtYaww-4fDqO5k1uPx1H19SLw6uq2pO-VCUT0hw_lPemIsxJz_OzzrUxF8H668Y5FCZ0W8Jf0bXvD0JjgcaErKoK9IWz4sdj_3yaL_2q1iR9PoniC7_8JONJUfjsf084Eia_yJ88O4TSkpEcISHlchqQKBPUjB0ialcNO6Epmba-g2B8i-lKqkLlAk34PB6HrLHb6F0ZHLKwwaXLw23UdjloUqVdY-8a90c5d6LRke6WZRyzmLrbSpUImsnPtPeWJu_dxOtZ7pre9kqYP9qmDuAsVlpkFt7Pro-s3nO-Q9m7DROYDsQEP4qiV5OXBP97CFqQzknb8G-3Y-fu5NGmf7z--6b-EtydgSNkDbR_n5zHvLXElEyumLVMwjiBd93Ey8VXuqvTzwm87oZe034cFQnM3aS5dzxLzfi-EpQfbggzgQPXPU8DzdbZQN7zNzxG569tCYN6aKtzIK00cuHejN3pxwnMdsI2of_84ku59F0x-5XMg6xglmau0KmGz6fnsft3Gb9obzKHvqsGl39NWX63KreE9QNTYpmydIUJvGtHR1oQj7-cZxHD4i6qlA7SQtU8o-smkGjDShPZ1i9UrkzIMZrGz6OpH3G-9KeT7NxfXr5AP8NoOo0macouud955e15vAxtukrghn56h-gewQlYXeOOR3rlNtuYrTXSRjf48a1EnpB54oiji_qHdzqolAqt8w6Ey7DGmHckN_6p1GghEJpDEDvw2140DlLdvDz6WbVXYPQoPNRuE2c0GuqOVEb_Ttg2on6L2qkOoSVwzSQXnFlsUmTXSsfbF-tjLeuwIOiP5Dvr-t22fQ-X31zcXN68ouUP9GnDdHG_FJon8IqG_xea3o-1ZXkCv1jm7teKUbjn9NO-n2sprECTwPVu4j14aNMEgiBAmx7w63RdWt92L1Gvn23bAO0J27j0Zc7WjsLmm9F4fwQAAP__ \ No newline at end of file diff --git a/testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json new file mode 100644 index 0000000000..87391a5711 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json @@ -0,0 +1,292 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,0:0:0-5:0:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.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/edge-label.d2,4:0:25-4:12:37", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:0:25-4:6:31", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:0:25-4:1:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:0:25-4:1:26", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:5:30-4:6:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:5:30-4:6:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:8:33-4:9:34", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:8:33-4:12:37", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:10:35-4:11:36", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "im a var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:0:25-4:1:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:0:25-4:1:26", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:5:30-4:6:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:5:30-4:6:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "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/TestCompile2/vars/basic/edge_label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json index 77d0d380fb..b5d58ba790 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json @@ -112,11 +112,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:8:33-4:9:34", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:8:33-4:12:37", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge_label.d2,4:10:35-4:11:36", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } } ] } @@ -161,7 +176,7 @@ ], "attributes": { "label": { - "value": "im a var" + "value": "" }, "labelDimensions": { "width": 0, diff --git a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json index 723fae3221..7c20031a34 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json @@ -89,11 +89,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:4:29-4:5:30", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:4:29-4:8:33", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:6:31-4:7:32", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } } ] } @@ -154,7 +169,7 @@ ], "attributes": { "label": { - "value": "im a var" + "value": "" }, "labelDimensions": { "width": 0, diff --git a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json index 7593600784..2b5c53b82a 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json @@ -182,11 +182,48 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,4:14:49-4:17:52", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:15:86", "value": [ { - "string": "red", - "raw_string": "red" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:38:109", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:16:87-9:22:93", + "value": [ + { + "string": "colors", + "raw_string": "colors" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:23:94-9:30:101", + "value": [ + { + "string": "primary", + "raw_string": "primary" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:31:102-9:37:108", + "value": [ + { + "string": "button", + "raw_string": "button" + } + ] + } + } + ] + } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json index a7a5fb0e59..a27ca9ad5e 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json @@ -108,10 +108,29 @@ }, "primary": {}, "value": { - "number": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,2:10:19-2:11:20", - "raw": "2", - "value": "2" + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:16:45", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:25:54", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:17:46-5:24:53", + "value": [ + { + "string": "columns", + "raw_string": "columns" + } + ] + } + } + ] + } + } + ] } } } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json index 4b4d56a324..ec15253727 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json @@ -223,12 +223,49 @@ }, "primary": {}, "value": { - "double_quoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,4:14:56-4:23:65", + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:10:131-12:11:132", "value": [ { - "string": "#4baae5", - "raw_string": "#4baae5" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:10:131-12:40:161", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:12:133-12:25:146", + "value": [ + { + "string": "primaryColors", + "raw_string": "primaryColors" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:26:147-12:32:153", + "value": [ + { + "string": "button", + "raw_string": "button" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:33:154-12:39:160", + "value": [ + { + "string": "active", + "raw_string": "active" + } + ] + } + } + ] + } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json new file mode 100644 index 0000000000..faf48d6517 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json @@ -0,0 +1,193 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,0:0:0-5:0:34", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.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/shape-label.d2,4:0:25-4:8:33", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,4:0:25-4:2:27", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,4:4:29-4:5:30", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,4:4:29-4:8:33", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,4:6:31-4:7:32", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "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/shape-label.d2,4:0:25-4:2:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.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": "im a var" + }, + "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/TestCompile2/vars/basic/style.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json index c5a5ae699e..9cd133ce42 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json @@ -124,11 +124,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,2:17:26-2:20:29", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:15:53", "value": [ { - "string": "red", - "raw_string": "red" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:30:68", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:16:54-5:29:67", + "value": [ + { + "string": "primary-color", + "raw_string": "primary-color" + } + ] + } + } + ] + } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json index 6ca33821b2..2f2a237c82 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json @@ -137,11 +137,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:12:55", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:10:53-7:11:54", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json index 06ce2bc1cb..b2557d9b0e 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json @@ -199,11 +199,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:11:93", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:9:91-10:10:92", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } } ] } @@ -232,11 +247,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:11:105", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:9:103-11:10:104", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } } ] } @@ -385,11 +415,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:11:177", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:9:175-19:10:176", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } } ] } @@ -418,11 +463,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:11:189", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:9:187-20:10:188", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json index 0637551ac5..86ad2c0cbf 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json @@ -199,11 +199,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99", "value": [ { - "string": "im replaced x var", - "raw_string": "im replaced x var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:11:102", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:9:100-10:10:101", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json index aed67f5838..1da21aa143 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json @@ -137,11 +137,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:12:58", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:10:56-7:11:57", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/errors/map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/map.exp.json index 0d8156660f..ca00beed9f 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/map.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/map.exp.json @@ -3,7 +3,7 @@ "err": { "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2,6:0:43-6:13:56", + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2,6:0:43-6:2:45", "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable \"colors\"" } ] diff --git a/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json index bf2e45fed9..c877996889 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json @@ -3,7 +3,7 @@ "err": { "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2,4:0:20-4:8:28", + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2,4:0:20-4:2:22", "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable \"z\"" } ] diff --git a/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.exp.json index 96bef919ae..e105b1ef05 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.exp.json @@ -3,7 +3,7 @@ "err": { "errs": [ { - "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.d2,6:0:33-6:10:43", + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.d2,6:0:33-6:2:35", "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.d2:7:1: could not resolve variable \"x.z\"" } ] diff --git a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json index f1a1cb4be7..7101e2e4fc 100644 --- a/testdata/d2compiler/TestCompile2/vars/override/label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json @@ -89,11 +89,26 @@ "primary": {}, "value": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:4:29-4:5:30", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:4:29-4:8:33", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:6:31-4:7:32", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/override/map.exp.json b/testdata/d2compiler/TestCompile2/vars/override/map.exp.json new file mode 100644 index 0000000000..11208a29bb --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/map.exp.json @@ -0,0 +1,329 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,0:0:0-10:0:81", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,1:0:1-3:1:27", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,1:6:7-3:1:27", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,2:2:11-2:16:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,2:5:14-2:16:25", + "value": [ + { + "string": "im root var", + "raw_string": "im root var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,4:0:28-9:1:80", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,4:0:28-4:1:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,4:0:28-4:1:29", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,4:3:31-9:1:80", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,5:2:35-7:3:67", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,5:2:35-5:6:39", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,5:2:35-5:6:39", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,5:8:41-7:3:67", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,6:4:47-6:20:63", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,6:4:47-6:5:48", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,6:4:47-6:5:48", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,6:7:50-6:20:63", + "value": [ + { + "string": "im nested var", + "raw_string": "im nested var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:2:70-8:10:78", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:2:70-8:4:72", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:2:70-8:4:72", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:6:74-8:7:75", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:6:74-8:10:78", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:8:76-8:9:77", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/TestCompile2/vars/override/map.d2,4:0:28-4:1:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,4:0:28-4:1:29", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "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 + }, + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:2:70-8:4:72", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:2:70-8:4:72", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im nested var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2ir/TestCompile/imports/vars/1.exp.json b/testdata/d2ir/TestCompile/imports/vars/1.exp.json index bd5c4b97eb..9d278fd743 100644 --- a/testdata/d2ir/TestCompile/imports/vars/1.exp.json +++ b/testdata/d2ir/TestCompile/imports/vars/1.exp.json @@ -18,67 +18,6 @@ } }, "references": [ - { - "string": { - "range": "x.d2,0:0:0-0:4:4", - "value": [ - { - "string": "meow", - "raw_string": "meow" - } - ] - }, - "key_path": { - "range": "x.d2,0:0:0-0:4:4", - "path": [ - { - "unquoted_string": { - "range": "x.d2,0:0:0-0:4:4", - "value": [ - { - "string": "meow", - "raw_string": "meow" - } - ] - } - } - ] - }, - "context": { - "edge": null, - "key": { - "range": "x.d2,0:0:0-0:18:18", - "key": { - "range": "x.d2,0:0:0-0:4:4", - "path": [ - { - "unquoted_string": { - "range": "x.d2,0:0:0-0:4:4", - "value": [ - { - "string": "meow", - "raw_string": "meow" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "unquoted_string": { - "range": "x.d2,0:6:6-0:18:18", - "value": [ - { - "string": "var replaced", - "raw_string": "var replaced" - } - ] - } - } - } - } - }, { "string": { "range": "x.d2,0:0:0-0:4:4", @@ -146,83 +85,6 @@ "edges": null }, "references": [ - { - "string": { - "range": "index.d2,0:0:0-0:4:4", - "value": [ - { - "string": "vars", - "raw_string": "vars" - } - ] - }, - "key_path": { - "range": "index.d2,0:0:0-0:4:4", - "path": [ - { - "unquoted_string": { - "range": "index.d2,0:0:0-0:4:4", - "value": [ - { - "string": "vars", - "raw_string": "vars" - } - ] - } - } - ] - }, - "context": { - "edge": null, - "key": { - "range": "index.d2,0:0:0-0:15:15", - "key": { - "range": "index.d2,0:0:0-0:4:4", - "path": [ - { - "unquoted_string": { - "range": "index.d2,0:0:0-0:4:4", - "value": [ - { - "string": "vars", - "raw_string": "vars" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "map": { - "range": "index.d2,0:6:6-0:15:15", - "nodes": [ - { - "import": { - "range": "index.d2,0:8:8-0:14:14", - "spread": true, - "pre": "", - "path": [ - { - "unquoted_string": { - "range": "index.d2,0:12:12-0:13:13", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } - } - ] - } - } - } - } - }, { "string": { "range": "index.d2,0:0:0-0:4:4", @@ -306,10 +168,11 @@ "name": "q", "primary": { "value": { - "range": "index.d2,0:20:20-0:21:21", + "range": "x.d2,0:6:6-0:18:18", "value": [ { - "string": "var replaced" + "string": "var replaced", + "raw_string": "var replaced" } ] } @@ -367,7 +230,23 @@ "range": "index.d2,0:20:20-0:21:21", "value": [ { - "string": "var replaced" + "substitution": { + "range": "index.d2,0:20:20-0:27:27", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:22:22-0:26:26", + "value": [ + { + "string": "meow", + "raw_string": "meow" + } + ] + } + } + ] + } } ] } From af69e6f62646aea709a3a9e200a1960d5d36c77d Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 17:33:01 -0700 Subject: [PATCH 18/40] edge cases --- d2compiler/compile_test.go | 45 +++ d2ir/compile.go | 46 ++- .../TestCompile2/vars/basic/edge-map.exp.json | 350 ++++++++++++++++++ .../vars/basic/parent-scope.exp.json | 329 ++++++++++++++++ .../vars/errors/out-of-scope.exp.json | 11 + 5 files changed, 769 insertions(+), 12 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/out-of-scope.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index b401bb4f56..fdaf33951c 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3290,6 +3290,21 @@ a -> b: ${x} assert.Equal(t, "im a var", g.Edges[0].Label.Value) }, }, + { + name: "edge-map", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im a var +} +a -> b: { + target-arrowhead.label: ${x} +} +`, "") + assert.Equal(t, 1, len(g.Edges)) + assert.Equal(t, "im a var", g.Edges[0].DstArrowhead.Label.Value) + }, + }, { name: "quoted-var", run: func(t *testing.T) { @@ -3325,6 +3340,23 @@ y: "hey ${x}" assert.Equal(t, `hey "hi"`, g.Objects[0].Label.Value) }, }, + { + name: "parent-scope", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: im root var +} +a: { + vars: { + b: im nested var + } + hi: ${x} +} +`, "") + assert.Equal(t, "im root var", g.Objects[1].Label.Value) + }, + }, } for _, tc := range tca { @@ -3538,6 +3570,19 @@ hi: ${x.z} `, `d2/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.d2:7:1: could not resolve variable "x.z"`) }, }, + { + name: "out-of-scope", + run: func(t *testing.T) { + assertCompile(t, ` +a: { + vars: { + x: hey + } +} +hi: ${x} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/out-of-scope.d2:7:1: could not resolve variable "x"`) + }, + }, { name: "edge", run: func(t *testing.T) { diff --git a/d2ir/compile.go b/d2ir/compile.go index c8fae9c026..7495ea2c4c 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -114,17 +114,31 @@ func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { if e.Primary() != nil { c.resolveSubstitutions(varsStack, e.LastRef().AST(), e.Primary()) } + if e.Map() != nil { + c.compileSubstitutions(e.Map(), varsStack) + } } } func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scalar *Scalar) { - subbed := false + var subbed bool + var resolvedField *Field + switch s := scalar.Value.(type) { case *d2ast.UnquotedString: for i, box := range s.Value { if box.Substitution != nil { - resolvedField := c.resolveSubstitution(varsStack[0], node, box.Substitution) + for _, vars := range varsStack { + resolvedField = c.resolveSubstitution(vars, box.Substitution) + if resolvedField != nil { + break + } + } if resolvedField != nil { + if resolvedField.Composite != nil { + c.errorf(node, `cannot reference map variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + return + } // If lone and unquoted, replace with value of sub if len(s.Value) == 1 { scalar.Value = resolvedField.Primary().Value @@ -132,6 +146,9 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) subbed = true } + } else { + c.errorf(node, `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + return } } } @@ -141,10 +158,22 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala case *d2ast.DoubleQuotedString: for i, box := range s.Value { if box.Substitution != nil { - resolvedField := c.resolveSubstitution(varsStack[0], node, box.Substitution) + for _, vars := range varsStack { + resolvedField = c.resolveSubstitution(vars, box.Substitution) + if resolvedField != nil { + break + } + } if resolvedField != nil { + if resolvedField.Composite != nil { + c.errorf(node, `cannot reference map variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + return + } s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) subbed = true + } else { + c.errorf(node, `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + return } } } @@ -154,7 +183,7 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala } } -func (c *compiler) resolveSubstitution(vars *Map, node d2ast.Node, substitution *d2ast.Substitution) *Field { +func (c *compiler) resolveSubstitution(vars *Map, substitution *d2ast.Substitution) *Field { var resolved *Field for _, p := range substitution.Path { if vars == nil { @@ -170,14 +199,7 @@ func (c *compiler) resolveSubstitution(vars *Map, node d2ast.Node, substitution resolved = r } - if resolved == nil { - c.errorf(node, `could not resolve variable "%s"`, strings.Join(substitution.IDA(), ".")) - } else if resolved.Composite != nil { - c.errorf(node, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), ".")) - } else { - return resolved - } - return nil + return resolved } func (c *compiler) overlayVars(base, overlay *Map) { diff --git a/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json new file mode 100644 index 0000000000..cb64534ff0 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json @@ -0,0 +1,350 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,0:0:0-7:0:68", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,1:0:1-3:1:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,1:6:7-3:1:24", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,2:2:11-2:13:22", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.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/edge-map.d2,4:0:25-6:1:67", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:0:25-4:6:31", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:0:25-4:1:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:0:25-4:1:26", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:5:30-4:6:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:5:30-4:6:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:8:33-6:1:67", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:2:37-5:30:65", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:2:37-5:24:59", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:2:37-5:18:53", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:19:54-5:24:59", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:26:61-5:27:62", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:26:61-5:30:65", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:28:63-5:29:64", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "im a var" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:0:25-4:1:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:0:25-4:1:26", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:5:30-4:6:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,4:5:30-4:6:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "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/TestCompile2/vars/basic/parent-scope.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json new file mode 100644 index 0000000000..b9d8924d51 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json @@ -0,0 +1,329 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,0:0:0-10:0:81", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,1:0:1-3:1:27", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,1:6:7-3:1:27", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,2:2:11-2:16:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,2:5:14-2:16:25", + "value": [ + { + "string": "im root var", + "raw_string": "im root var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,4:0:28-9:1:80", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,4:0:28-4:1:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,4:0:28-4:1:29", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,4:3:31-9:1:80", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,5:2:35-7:3:67", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,5:2:35-5:6:39", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,5:2:35-5:6:39", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,5:8:41-7:3:67", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,6:4:47-6:20:63", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,6:4:47-6:5:48", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,6:4:47-6:5:48", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,6:7:50-6:20:63", + "value": [ + { + "string": "im nested var", + "raw_string": "im nested var" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:2:70-8:10:78", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:2:70-8:4:72", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:2:70-8:4:72", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:6:74-8:7:75", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:6:74-8:10:78", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:8:76-8:9:77", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/TestCompile2/vars/basic/parent-scope.d2,4:0:28-4:1:29", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,4:0:28-4:1:29", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "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 + }, + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:2:70-8:4:72", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:2:70-8:4:72", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "im root var" + }, + "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/TestCompile2/vars/errors/out-of-scope.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/out-of-scope.exp.json new file mode 100644 index 0000000000..c9251b81e7 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/out-of-scope.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/out-of-scope.d2,6:0:33-6:2:35", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/out-of-scope.d2:7:1: could not resolve variable \"x\"" + } + ] + } +} From 5d4d9c5c17c4a3d457fec48a22febafbd162fee6 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 17:37:39 -0700 Subject: [PATCH 19/40] import tests --- d2ir/import_test.go | 22 + .../d2ir/TestCompile/imports/vars/2.exp.json | 401 ++++++++++++++++++ .../d2ir/TestCompile/imports/vars/3.exp.json | 401 ++++++++++++++++++ 3 files changed, 824 insertions(+) create mode 100644 testdata/d2ir/TestCompile/imports/vars/2.exp.json create mode 100644 testdata/d2ir/TestCompile/imports/vars/3.exp.json diff --git a/d2ir/import_test.go b/d2ir/import_test.go index c04cb6a25d..0b9497abee 100644 --- a/d2ir/import_test.go +++ b/d2ir/import_test.go @@ -149,6 +149,28 @@ label: meow`, assertQuery(t, m, 0, 0, "var replaced", "q") }, }, + { + name: "vars/2", + run: func(t testing.TB) { + m, err := compileFS(t, "index.d2", map[string]string{ + "index.d2": "vars: { x: 1 }; ...@a", + "a.d2": "vars: { x: 2 }; hi: ${x}", + }) + assert.Success(t, err) + assertQuery(t, m, 0, 0, 2, "hi") + }, + }, + { + name: "vars/3", + run: func(t testing.TB) { + m, err := compileFS(t, "index.d2", map[string]string{ + "index.d2": "...@a; vars: { x: 1 }; hi: ${x}", + "a.d2": "vars: { x: 2 }", + }) + assert.Success(t, err) + assertQuery(t, m, 0, 0, 1, "hi") + }, + }, } runa(t, tca) diff --git a/testdata/d2ir/TestCompile/imports/vars/2.exp.json b/testdata/d2ir/TestCompile/imports/vars/2.exp.json new file mode 100644 index 0000000000..3107e5c6e7 --- /dev/null +++ b/testdata/d2ir/TestCompile/imports/vars/2.exp.json @@ -0,0 +1,401 @@ +{ + "fields": [ + { + "name": "vars", + "composite": { + "fields": [ + { + "name": "x", + "primary": { + "value": { + "range": "a.d2,0:11:11-0:12:12", + "raw": "2", + "value": "2" + } + }, + "references": [ + { + "string": { + "range": "index.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "index.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:8:8-0:13:13", + "key": { + "range": "index.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "index.d2,0:11:11-0:12:12", + "raw": "1", + "value": "1" + } + } + } + } + }, + { + "string": { + "range": "a.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "a.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "a.d2,0:8:8-0:13:13", + "key": { + "range": "a.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "a.d2,0:11:11-0:12:12", + "raw": "2", + "value": "2" + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + }, + "key_path": { + "range": "index.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:0:0-0:14:14", + "key": { + "range": "index.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "index.d2,0:6:6-0:14:14", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:8:8-0:13:13", + "key": { + "range": "index.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "index.d2,0:11:11-0:12:12", + "raw": "1", + "value": "1" + } + } + } + } + ] + } + } + } + } + }, + { + "string": { + "range": "a.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + }, + "key_path": { + "range": "a.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "a.d2,0:0:0-0:14:14", + "key": { + "range": "a.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "a.d2,0:6:6-0:14:14", + "nodes": [ + { + "map_key": { + "range": "a.d2,0:8:8-0:13:13", + "key": { + "range": "a.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "a.d2,0:11:11-0:12:12", + "raw": "2", + "value": "2" + } + } + } + } + ] + } + } + } + } + } + ] + }, + { + "name": "hi", + "primary": { + "value": { + "range": "a.d2,0:11:11-0:12:12", + "raw": "2", + "value": "2" + } + }, + "references": [ + { + "string": { + "range": "a.d2,0:16:16-0:18:18", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + }, + "key_path": { + "range": "a.d2,0:16:16-0:18:18", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:16:16-0:18:18", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "a.d2,0:16:16-0:24:24", + "key": { + "range": "a.d2,0:16:16-0:18:18", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:16:16-0:18:18", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "a.d2,0:20:20-0:21:21", + "value": [ + { + "substitution": { + "range": "a.d2,0:20:20-0:24:24", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:22:22-0:23:23", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + } + ] + } + ], + "edges": null +} diff --git a/testdata/d2ir/TestCompile/imports/vars/3.exp.json b/testdata/d2ir/TestCompile/imports/vars/3.exp.json new file mode 100644 index 0000000000..e2ddd2094c --- /dev/null +++ b/testdata/d2ir/TestCompile/imports/vars/3.exp.json @@ -0,0 +1,401 @@ +{ + "fields": [ + { + "name": "vars", + "composite": { + "fields": [ + { + "name": "x", + "primary": { + "value": { + "range": "index.d2,0:18:18-0:19:19", + "raw": "1", + "value": "1" + } + }, + "references": [ + { + "string": { + "range": "a.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "a.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "a.d2,0:8:8-0:13:13", + "key": { + "range": "a.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "a.d2,0:11:11-0:12:12", + "raw": "2", + "value": "2" + } + } + } + } + }, + { + "string": { + "range": "index.d2,0:15:15-0:16:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + }, + "key_path": { + "range": "index.d2,0:15:15-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:15:15-0:16:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:15:15-0:20:20", + "key": { + "range": "index.d2,0:15:15-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:15:15-0:16:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "index.d2,0:18:18-0:19:19", + "raw": "1", + "value": "1" + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "a.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + }, + "key_path": { + "range": "a.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "a.d2,0:0:0-0:14:14", + "key": { + "range": "a.d2,0:0:0-0:4:4", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:0:0-0:4:4", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "a.d2,0:6:6-0:14:14", + "nodes": [ + { + "map_key": { + "range": "a.d2,0:8:8-0:13:13", + "key": { + "range": "a.d2,0:8:8-0:9:9", + "path": [ + { + "unquoted_string": { + "range": "a.d2,0:8:8-0:9:9", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "a.d2,0:11:11-0:12:12", + "raw": "2", + "value": "2" + } + } + } + } + ] + } + } + } + } + }, + { + "string": { + "range": "index.d2,0:7:7-0:11:11", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + }, + "key_path": { + "range": "index.d2,0:7:7-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:7:7-0:11:11", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:7:7-0:21:21", + "key": { + "range": "index.d2,0:7:7-0:11:11", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:7:7-0:11:11", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "index.d2,0:13:13-0:21:21", + "nodes": [ + { + "map_key": { + "range": "index.d2,0:15:15-0:20:20", + "key": { + "range": "index.d2,0:15:15-0:16:16", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:15:15-0:16:16", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "index.d2,0:18:18-0:19:19", + "raw": "1", + "value": "1" + } + } + } + } + ] + } + } + } + } + } + ] + }, + { + "name": "hi", + "primary": { + "value": { + "range": "index.d2,0:18:18-0:19:19", + "raw": "1", + "value": "1" + } + }, + "references": [ + { + "string": { + "range": "index.d2,0:23:23-0:25:25", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + }, + "key_path": { + "range": "index.d2,0:23:23-0:25:25", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:23:23-0:25:25", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "index.d2,0:23:23-0:31:31", + "key": { + "range": "index.d2,0:23:23-0:25:25", + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:23:23-0:25:25", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "index.d2,0:27:27-0:28:28", + "value": [ + { + "substitution": { + "range": "index.d2,0:27:27-0:31:31", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "index.d2,0:29:29-0:30:30", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + } + ] + } + ], + "edges": null +} From 67a06b65579374c6e4409500394ba747afa61885 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 18:05:03 -0700 Subject: [PATCH 20/40] var-in-var --- d2compiler/compile_test.go | 18 + d2ir/compile.go | 2 +- .../vars/override/var-in-var.exp.json | 360 ++++++++++++++++++ 3 files changed, 379 insertions(+), 1 deletion(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index fdaf33951c..bc485af313 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3410,6 +3410,24 @@ a: { assert.Equal(t, "im nested var", g.Objects[1].Label.Value) }, }, + { + name: "var-in-var", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + surname: Smith +} +a: { + vars: { + trade1: Black${surname} + trade2: Metal${surname} + } + hi: ${trade1} +} +`, "") + assert.Equal(t, "BlackSmith", g.Objects[1].Label.Value) + }, + }, } for _, tc := range tca { diff --git a/d2ir/compile.go b/d2ir/compile.go index 7495ea2c4c..3dbe65e0c1 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -154,6 +154,7 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala } if subbed { s.Coalesce() + scalar.Value = d2ast.RawString(s.ScalarString(), false) } case *d2ast.DoubleQuotedString: for i, box := range s.Value { @@ -198,7 +199,6 @@ func (c *compiler) resolveSubstitution(vars *Map, substitution *d2ast.Substituti vars = r.Map() resolved = r } - return resolved } diff --git a/testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json b/testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json new file mode 100644 index 0000000000..6f41e1fad8 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json @@ -0,0 +1,360 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,0:0:0-11:0:116", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,1:0:1-3:1:26", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,1:6:7-3:1:26", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,2:1:10-2:15:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,2:1:10-2:8:17", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,2:1:10-2:8:17", + "value": [ + { + "string": "surname", + "raw_string": "surname" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,2:10:19-2:15:24", + "value": [ + { + "string": "Smith", + "raw_string": "Smith" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,4:0:27-10:1:115", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,4:0:27-4:1:28", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,4:0:27-4:1:28", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,4:3:30-10:1:115", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,5:2:34-8:3:97", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,5:2:34-5:6:38", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,5:2:34-5:6:38", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,5:8:40-8:3:97", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,6:2:44-6:25:67", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,6:2:44-6:8:50", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,6:2:44-6:8:50", + "value": [ + { + "string": "trade1", + "raw_string": "trade1" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,6:10:52-6:16:58", + "value": [ + { + "string": "BlackSmith" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,7:2:70-7:25:93", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,7:2:70-7:8:76", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,7:2:70-7:8:76", + "value": [ + { + "string": "trade2", + "raw_string": "trade2" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,7:10:78-7:16:84", + "value": [ + { + "string": "MetalSmith" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:2:100-9:15:113", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:2:100-9:4:102", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:2:100-9:4:102", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:6:104-9:7:105", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:6:104-9:15:113", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:8:106-9:14:112", + "value": [ + { + "string": "trade1", + "raw_string": "trade1" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/TestCompile2/vars/override/var-in-var.d2,4:0:27-4:1:28", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,4:0:27-4:1:28", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "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 + }, + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:2:100-9:4:102", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:2:100-9:4:102", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "BlackSmith" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} From 7091c580ef6c5034b5bee49f086975816935127a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 19:16:10 -0700 Subject: [PATCH 21/40] changelog --- ci/release/changelogs/next.md | 1 + 1 file changed, 1 insertion(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 69969d43e4..5a915f6c5e 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -1,5 +1,6 @@ #### Features 🚀 +- Variables and substitutions are implemented. See [docs](https://d2lang.com/tour/vars). [#1473](https://github.com/terrastruct/d2/pull/1473) - Configure timeout value with D2_TIMEOUT env var [#1392](https://github.com/terrastruct/d2/pull/1392) - Scale renders and disable fit to screen with `--scale` flag [#1413](https://github.com/terrastruct/d2/pull/1413) - `null` keyword can be used to un-declare. See [docs](https://d2lang.com/tour/TODO) [#1446](https://github.com/terrastruct/d2/pull/1446) From 63dbaf093587413580bf45ed259e7f1268cb1a1c Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Tue, 11 Jul 2023 23:26:06 -0700 Subject: [PATCH 22/40] pr changes --- d2compiler/compile_test.go | 28 ++ d2ir/compile.go | 83 ++--- .../vars/errors/recursive-var.exp.json | 11 + .../vars/override/recursive-var.exp.json | 328 ++++++++++++++++++ 4 files changed, 410 insertions(+), 40 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/recursive-var.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index bc485af313..54c2feba43 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3428,6 +3428,23 @@ a: { assert.Equal(t, "BlackSmith", g.Objects[1].Label.Value) }, }, + { + name: "recursive-var", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: a +} +hi: { + vars: { + x: ${x}-b + } + yo: ${x} +} +`, "") + assert.Equal(t, "a-b", g.Objects[1].Label.Value) + }, + }, } for _, tc := range tca { @@ -3601,6 +3618,17 @@ hi: ${x} `, `d2/testdata/d2compiler/TestCompile2/vars/errors/out-of-scope.d2:7:1: could not resolve variable "x"`) }, }, + { + name: "recursive-var", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: ${x} +} +hi: ${x} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/recursive-var.d2:3:3: could not resolve variable "x"`) + }, + }, { name: "edge", run: func(t *testing.T) { diff --git a/d2ir/compile.go b/d2ir/compile.go index 3dbe65e0c1..49d2ab43ba 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -107,7 +107,13 @@ func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { c.resolveSubstitutions(varsStack, f.LastRef().AST(), f.Primary()) } if f.Map() != nil { - c.compileSubstitutions(f.Map(), varsStack) + // this map could be the "vars" + // and if it is, then its already been compiled, so the varsStack can be truncated + if f.Name == "vars" { + c.compileSubstitutions(f.Map(), varsStack[1:]) + } else { + c.compileSubstitutions(f.Map(), varsStack) + } } } for _, e := range m.Edges { @@ -134,27 +140,25 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala break } } - if resolvedField != nil { - if resolvedField.Composite != nil { - c.errorf(node, `cannot reference map variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) - return - } - // If lone and unquoted, replace with value of sub - if len(s.Value) == 1 { - scalar.Value = resolvedField.Primary().Value - } else { - s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) - subbed = true - } - } else { + if resolvedField == nil { c.errorf(node, `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) return } + if resolvedField.Composite != nil { + c.errorf(node, `cannot reference map variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + return + } + // If lone and unquoted, replace with value of sub + if len(s.Value) == 1 { + scalar.Value = resolvedField.Primary().Value + } else { + s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + subbed = true + } } } if subbed { s.Coalesce() - scalar.Value = d2ast.RawString(s.ScalarString(), false) } case *d2ast.DoubleQuotedString: for i, box := range s.Value { @@ -165,17 +169,16 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala break } } - if resolvedField != nil { - if resolvedField.Composite != nil { - c.errorf(node, `cannot reference map variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) - return - } - s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) - subbed = true - } else { + if resolvedField == nil { c.errorf(node, `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) return } + if resolvedField.Composite != nil { + c.errorf(node, `cannot reference map variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + return + } + s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + subbed = true } } if subbed { @@ -185,21 +188,21 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala } func (c *compiler) resolveSubstitution(vars *Map, substitution *d2ast.Substitution) *Field { - var resolved *Field - for _, p := range substitution.Path { - if vars == nil { - resolved = nil - break + if vars == nil { + return nil + } + + for i, p := range substitution.Path { + f := vars.GetField(p.Unbox().ScalarString()) + if f == nil { + return nil } - r := vars.GetField(p.Unbox().ScalarString()) - if r == nil { - resolved = nil - break + if i == len(substitution.Path)-1 { + return f } - vars = r.Map() - resolved = r + vars = f.Map() } - return resolved + return nil } func (c *compiler) overlayVars(base, overlay *Map) { @@ -208,14 +211,14 @@ func (c *compiler) overlayVars(base, overlay *Map) { return } - lVars := base.GetField("vars") + baseVars := base.GetField("vars") - if lVars == nil { - lVars = vars.Copy(base).(*Field) - base.Fields = append(base.Fields, lVars) + if baseVars == nil { + baseVars = vars.Copy(base).(*Field) + base.Fields = append(base.Fields, baseVars) } else { overlayed := vars.Copy(base).(*Field) - OverlayMap(overlayed.Map(), lVars.Map()) + OverlayMap(overlayed.Map(), baseVars.Map()) base.DeleteField("vars") base.Fields = append(base.Fields, overlayed) } diff --git a/testdata/d2compiler/TestCompile2/vars/errors/recursive-var.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/recursive-var.exp.json new file mode 100644 index 0000000000..d00db4c643 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/recursive-var.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/recursive-var.d2,2:2:11-2:3:12", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/recursive-var.d2:3:3: could not resolve variable \"x\"" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json b/testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json new file mode 100644 index 0000000000..19277bee22 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json @@ -0,0 +1,328 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,0:0:0-10:0:65", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,1:0:1-3:1:17", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,1:6:7-3:1:17", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,2:2:11-2:6:15", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,2:5:14-2:6:15", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,4:0:18-9:1:64", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,4:0:18-4:2:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,4:0:18-4:2:20", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,4:4:22-9:1:64", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,5:2:26-7:3:51", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,5:2:26-5:6:30", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,5:2:26-5:6:30", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,5:8:32-7:3:51", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,6:4:38-6:13:47", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,6:4:38-6:5:39", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,6:4:38-6:5:39", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,6:7:41-6:13:47", + "value": [ + { + "string": "a-b" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:2:54-8:10:62", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:2:54-8:4:56", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:2:54-8:4:56", + "value": [ + { + "string": "yo", + "raw_string": "yo" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:6:58-8:7:59", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:6:58-8:10:62", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:8:60-8:9:61", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/override/recursive-var.d2,4:0:18-4:2:20", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,4:0:18-4:2:20", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "yo", + "id_val": "yo", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:2:54-8:4:56", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:2:54-8:4:56", + "value": [ + { + "string": "yo", + "raw_string": "yo" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "a-b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} From d06e395e8d10a200fdbad92076a005930ec9dc79 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 12 Jul 2023 10:27:32 -0700 Subject: [PATCH 23/40] overlayVars refactor --- d2ir/compile.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/d2ir/compile.go b/d2ir/compile.go index 49d2ab43ba..f908d9b389 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -210,18 +210,15 @@ func (c *compiler) overlayVars(base, overlay *Map) { if vars == nil { return } + vars = vars.Copy(base).(*Field) baseVars := base.GetField("vars") - - if baseVars == nil { - baseVars = vars.Copy(base).(*Field) - base.Fields = append(base.Fields, baseVars) - } else { - overlayed := vars.Copy(base).(*Field) - OverlayMap(overlayed.Map(), baseVars.Map()) + if baseVars != nil { + OverlayMap(vars.Map(), baseVars.Map()) base.DeleteField("vars") - base.Fields = append(base.Fields, overlayed) } + + base.Fields = append(base.Fields, vars) } func (c *compiler) overlay(base *Map, f *Field) { From 85bfad19a6cb1455a242e4d08bddbad73ba5a01c Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 12 Jul 2023 11:55:58 -0700 Subject: [PATCH 24/40] compile composites --- d2compiler/compile.go | 6 + d2compiler/compile_test.go | 85 ++- d2ir/compile.go | 50 +- .../TestCompile2/vars/basic/map.exp.json | 531 ++++++++++++++++++ .../vars/basic/primary-and-composite.exp.json | 323 +++++++++++ .../TestCompile2/vars/errors/bad-var.exp.json | 11 + .../vars/errors/multi-part-map.exp.json | 11 + .../vars/errors/quoted-map.exp.json | 11 + 8 files changed, 997 insertions(+), 31 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/map.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/quoted-map.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index c1800e5715..29927ca57a 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -281,6 +281,12 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { if f.Map() != nil { if len(f.Map().Edges) > 0 { c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") + } else { + for _, f := range f.Map().Fields { + if f.Primary() == nil && f.Composite == nil { + c.errorf(f.LastRef().AST(), "invalid var with no value") + } + } } } return diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 54c2feba43..75871506d4 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3357,6 +3357,41 @@ a: { assert.Equal(t, "im root var", g.Objects[1].Label.Value) }, }, + { + name: "map", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + cool-style: { + fill: red + } + arrows: { + target-arrowhead.label: yay + } +} +hi.style: ${cool-style} +a -> b: ${arrows} +`, "") + assert.Equal(t, "red", g.Objects[0].Style.Fill.Value) + assert.Equal(t, "yay", g.Edges[0].DstArrowhead.Label.Value) + }, + }, + { + name: "primary-and-composite", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: all { + a: b + } +} +z: ${x} +`, "") + assert.Equal(t, "z", g.Objects[1].ID) + assert.Equal(t, "all", g.Objects[1].Label.Value) + assert.Equal(t, 1, len(g.Objects[1].Children)) + }, + }, } for _, tc := range tca { @@ -3592,6 +3627,43 @@ hi: ${z} `, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable "z"`) }, }, + { + name: "bad-var", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x +} +hi: ${x} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:3:3: invalid var with no value`) + }, + }, + { + name: "multi-part-map", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: { + a: b + } +} +hi: 1 ${x} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute map variable "x" as part of a string`) + }, + }, + { + name: "quoted-map", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: { + a: b + } +} +hi: "${x}" +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/quoted-map.d2:7:1: cannot substitute map variable "x" in quotes`) + }, + }, { name: "nested-missing", run: func(t *testing.T) { @@ -3640,19 +3712,6 @@ hi `, "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2:3:3: vars cannot contain an edge") }, }, - { - name: "map", - run: func(t *testing.T) { - assertCompile(t, ` -vars: { - colors: { - button: red - } -} -hi: ${colors} -`, `d2/testdata/d2compiler/TestCompile2/vars/errors/map.d2:7:1: cannot reference map variable "colors"`) - }, - }, } for _, tc := range tca { diff --git a/d2ir/compile.go b/d2ir/compile.go index f908d9b389..2c93b6ef4b 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -104,11 +104,10 @@ func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { varsStack = append([]*Map{f.Map()}, varsStack...) } if f.Primary() != nil { - c.resolveSubstitutions(varsStack, f.LastRef().AST(), f.Primary()) + c.resolveSubstitutions(varsStack, f) } if f.Map() != nil { - // this map could be the "vars" - // and if it is, then its already been compiled, so the varsStack can be truncated + // don't resolve substitutions in vars with the current scope of vars if f.Name == "vars" { c.compileSubstitutions(f.Map(), varsStack[1:]) } else { @@ -118,7 +117,7 @@ func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { } for _, e := range m.Edges { if e.Primary() != nil { - c.resolveSubstitutions(varsStack, e.LastRef().AST(), e.Primary()) + c.resolveSubstitutions(varsStack, e) } if e.Map() != nil { c.compileSubstitutions(e.Map(), varsStack) @@ -126,11 +125,11 @@ func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { } } -func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scalar *Scalar) { +func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { var subbed bool var resolvedField *Field - switch s := scalar.Value.(type) { + switch s := node.Primary().Value.(type) { case *d2ast.UnquotedString: for i, box := range s.Value { if box.Substitution != nil { @@ -141,19 +140,34 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala } } if resolvedField == nil { - c.errorf(node, `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + c.errorf(node.LastRef().AST(), `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) return } - if resolvedField.Composite != nil { - c.errorf(node, `cannot reference map variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) - return - } - // If lone and unquoted, replace with value of sub - if len(s.Value) == 1 { - scalar.Value = resolvedField.Primary().Value + if resolvedField.Primary() == nil { + if len(s.Value) > 1 { + c.errorf(node.LastRef().AST(), `cannot substitute map variable "%s" as part of a string`, strings.Join(box.Substitution.IDA(), ".")) + return + } } else { - s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) - subbed = true + // If lone and unquoted, replace with value of sub + if len(s.Value) == 1 { + node.Primary().Value = resolvedField.Primary().Value + } else { + s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + subbed = true + } + } + if resolvedField.Composite != nil { + switch n := node.(type) { + case *Field: + n.Composite = resolvedField.Composite + case *Edge: + if resolvedField.Composite.Map() == nil { + c.errorf(node.LastRef().AST(), `cannot substitute array variable "%s" to an edge`, strings.Join(box.Substitution.IDA(), ".")) + return + } + n.Map_ = resolvedField.Composite.Map() + } } } } @@ -170,11 +184,11 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node d2ast.Node, scala } } if resolvedField == nil { - c.errorf(node, `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + c.errorf(node.LastRef().AST(), `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) return } if resolvedField.Composite != nil { - c.errorf(node, `cannot reference map variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + c.errorf(node.LastRef().AST(), `cannot substitute map variable "%s" in quotes`, strings.Join(box.Substitution.IDA(), ".")) return } s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) diff --git a/testdata/d2compiler/TestCompile2/vars/basic/map.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/map.exp.json new file mode 100644 index 0000000000..e04804d697 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/map.exp.json @@ -0,0 +1,531 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,0:0:0-11:0:133", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,1:0:1-8:1:90", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,1:6:7-8:1:90", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,2:2:11-4:3:40", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,2:2:11-2:12:21", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,2:2:11-2:12:21", + "value": [ + { + "string": "cool-style", + "raw_string": "cool-style" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,2:14:23-4:3:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,3:2:27-3:11:36", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,3:2:27-3:6:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,3:2:27-3:6:31", + "value": [ + { + "string": "fill", + "raw_string": "fill" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,3:8:33-3:11:36", + "value": [ + { + "string": "red", + "raw_string": "red" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,5:2:43-7:3:88", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,5:2:43-5:8:49", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,5:2:43-5:8:49", + "value": [ + { + "string": "arrows", + "raw_string": "arrows" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,5:10:51-7:3:88", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,6:4:57-6:31:84", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,6:4:57-6:26:79", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,6:4:57-6:20:73", + "value": [ + { + "string": "target-arrowhead", + "raw_string": "target-arrowhead" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,6:21:74-6:26:79", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,6:28:81-6:31:84", + "value": [ + { + "string": "yay", + "raw_string": "yay" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:0:91-9:23:114", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:0:91-9:8:99", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:0:91-9:2:93", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:3:94-9:8:99", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:10:101-9:11:102", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:10:101-9:23:114", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:12:103-9:22:113", + "value": [ + { + "string": "cool-style", + "raw_string": "cool-style" + } + ] + } + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:0:115-10:17:132", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:0:115-10:6:121", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:0:115-10:1:116", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:0:115-10:1:116", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:5:120-10:6:121", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:5:120-10:6:121", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:8:123-10:9:124", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:8:123-10:17:132", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:10:125-10:16:131", + "value": [ + { + "string": "arrows", + "raw_string": "arrows" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "dstArrowhead": { + "label": { + "value": "yay" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:0:91-9:8:99", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:0:91-9:2:93", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,9:3:94-9:8:99", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "red" + } + }, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:0:115-10:1:116", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:0:115-10:1:116", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:5:120-10:6:121", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/map.d2,10:5:120-10:6:121", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "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/TestCompile2/vars/basic/primary-and-composite.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json new file mode 100644 index 0000000000..f7ddb1d5cc --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json @@ -0,0 +1,323 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,0:0:0-7:0:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,1:0:1-5:1:31", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,1:6:7-5:1:31", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,2:1:10-4:3:29", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,2:1:10-2:2:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,2:1:10-2:2:11", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,2:4:13-2:7:16", + "value": [ + { + "string": "all", + "raw_string": "all" + } + ] + } + }, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,2:8:17-4:3:29", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,3:2:21-3:6:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,3:2:21-3:3:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,3:2:21-3:3:22", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,3:5:24-3:6:25", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:0:32-6:7:39", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:0:32-6:1:33", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:0:32-6:1:33", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:3:35-6:4:36", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:3:35-6:7:39", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:5:37-6:6:38", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "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/TestCompile2/vars/basic/primary-and-composite.d2,3:2:21-3:3:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,3:2:21-3:3:22", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "z", + "id_val": "z", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:0:32-6:1:33", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:0:32-6:1:33", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "all" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "vars", + "id_val": "vars", + "attributes": { + "label": { + "value": "vars" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "x", + "id_val": "x", + "attributes": { + "label": { + "value": "x" + }, + "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/TestCompile2/vars/errors/bad-var.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json new file mode 100644 index 0000000000..c079e0f3c7 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2,2:2:11-2:3:12", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:3:3: invalid var with no value" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json new file mode 100644 index 0000000000..70c263dfa6 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2,6:0:31-6:2:33", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute map variable \"x\" as part of a string" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/errors/quoted-map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/quoted-map.exp.json new file mode 100644 index 0000000000..f5610c5dec --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/quoted-map.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/quoted-map.d2,6:0:31-6:2:33", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/quoted-map.d2:7:1: cannot substitute map variable \"x\" in quotes" + } + ] + } +} From 4b7b636657a73808bee00006d150e55b54a94b74 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 12 Jul 2023 14:53:28 -0700 Subject: [PATCH 25/40] spread --- d2compiler/compile_test.go | 50 ++ d2ir/compile.go | 37 +- .../TestCompile2/vars/basic/spread.exp.json | 469 +++++++++++++++++ .../TestCompile2/vars/basic/variadic.exp.json | 492 ++++++++++++++++++ .../vars/errors/spread-non-map.exp.json | 11 + 5 files changed, 1058 insertions(+), 1 deletion(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/spread.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/variadic.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 75871506d4..36e502a687 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3392,6 +3392,25 @@ z: ${x} assert.Equal(t, 1, len(g.Objects[1].Children)) }, }, + { + name: "spread", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: all { + a: b + b: c + } +} +z: { + ...${x} + c +} +`, "") + assert.Equal(t, "z", g.Objects[1].ID) + assert.Equal(t, 3, len(g.Objects[1].Children)) + }, + }, } for _, tc := range tca { @@ -3712,6 +3731,37 @@ hi `, "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2:3:3: vars cannot contain an edge") }, }, + { + name: "spread-non-map", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: all +} +z: { + ...${x} + c +} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-map into map`) + }, + }, + { + name: "spread-non-solo", + // NOTE: this doesn't get parsed correctly and so the error message isn't exactly right, but the important thing is that it errors + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: { + a: b + } +} +z: { + d: ...${x} + c +} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute map variable "x" as part of a string`) + }, + }, } for _, tc := range tca { diff --git a/d2ir/compile.go b/d2ir/compile.go index 2c93b6ef4b..db1e8ec5cd 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -143,14 +143,33 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { c.errorf(node.LastRef().AST(), `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) return } + if box.Substitution.Spread { + if resolvedField.Composite == nil { + c.errorf(box.Substitution, "cannot spread non-map into map") + continue + } + // TODO arrays + if resolvedField.Map() != nil { + OverlayMap(ParentMap(node), resolvedField.Map()) + } + // Remove the placeholder field + f := node.(*Field) + m := f.parent.(*Map) + for i, f2 := range m.Fields { + if f == f2 { + m.Fields = append(m.Fields[:i], m.Fields[i+1:]...) + break + } + } + } if resolvedField.Primary() == nil { if len(s.Value) > 1 { c.errorf(node.LastRef().AST(), `cannot substitute map variable "%s" as part of a string`, strings.Join(box.Substitution.IDA(), ".")) return } } else { - // If lone and unquoted, replace with value of sub if len(s.Value) == 1 { + // If lone and unquoted, replace with value of sub node.Primary().Value = resolvedField.Primary().Value } else { s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) @@ -255,6 +274,21 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { ScopeMap: dst, ScopeAST: scopeAST, }) + case n.Substitution != nil: + if !n.Substitution.Spread { + c.errorf(n.Import, "invalid non-spread substitution in map") + continue + } + // placeholder field to be resolved at the end + f := &Field{ + parent: dst, + Primary_: &Scalar{ + Value: &d2ast.UnquotedString{ + Value: []d2ast.InterpolationBox{{Substitution: n.Substitution}}, + }, + }, + } + dst.Fields = append(dst.Fields, f) case n.Import != nil: impn, ok := c._import(n.Import) if !ok { @@ -619,6 +653,7 @@ func (c *compiler) compileArray(dst *Array, a *d2ast.Array, scopeAST *d2ast.Map) irv = n } case *d2ast.Substitution: + // TODO // panic("TODO") } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/spread.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/spread.exp.json new file mode 100644 index 0000000000..9dbadf0d4d --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/spread.exp.json @@ -0,0 +1,469 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,0:0:0-11:0:62", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,1:0:1-6:1:40", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,1:6:7-6:1:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,2:1:10-5:3:38", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,2:1:10-2:2:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,2:1:10-2:2:11", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,2:4:13-2:7:16", + "value": [ + { + "string": "all", + "raw_string": "all" + } + ] + } + }, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,2:8:17-5:3:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,3:2:21-3:6:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,3:2:21-3:3:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,3:2:21-3:3:22", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,3:5:24-3:6:25", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:8:34", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:5:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:5:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:7:33-4:8:34", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-10:1:61", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-7:1:42", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-7:1:42", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:3:44-10:1:61", + "nodes": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,8:2:48-8:9:55", + "spread": true, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,8:7:53-8:8:54", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "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/TestCompile2/vars/basic/spread.d2,3:2:21-3:3:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,3:2:21-3:3:22", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "z", + "id_val": "z", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-7:1:42", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-7:1:42", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "vars", + "id_val": "vars", + "attributes": { + "label": { + "value": "vars" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "x", + "id_val": "x", + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:5:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:5:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "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/TestCompile2/vars/basic/variadic.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/variadic.exp.json new file mode 100644 index 0000000000..424de2d0ff --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/variadic.exp.json @@ -0,0 +1,492 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,0:0:0-11:0:62", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,1:0:1-6:1:40", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,1:6:7-6:1:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,2:1:10-5:3:38", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,2:1:10-2:2:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,2:1:10-2:2:11", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,2:4:13-2:7:16", + "value": [ + { + "string": "all", + "raw_string": "all" + } + ] + } + }, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,2:8:17-5:3:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,3:2:21-3:6:25", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,3:2:21-3:3:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,3:2:21-3:3:22", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,3:5:24-3:6:25", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,4:4:30-4:8:34", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,4:4:30-4:5:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,4:4:30-4:5:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,4:7:33-4:8:34", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,7:0:41-10:1:61", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,7:0:41-7:1:42", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,7:0:41-7:1:42", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,7:3:44-10:1:61", + "nodes": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,8:2:48-8:9:55", + "spread": true, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,8:7:53-8:8:54", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,9:2:58-9:3:59", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,9:2:58-9:3:59", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,9:2:58-9:3:59", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "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": "z", + "id_val": "z", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,7:0:41-7:1:42", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,7:0:41-7:1:42", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "\"\"", + "id_val": "", + "attributes": { + "label": { + "value": "all" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,3:2:21-3:3:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,3:2:21-3:3:22", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "b" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "vars", + "id_val": "vars", + "attributes": { + "label": { + "value": "vars" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "x", + "id_val": "x", + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "b", + "id_val": "b", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,4:4:30-4:5:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,4:4:30-4:5:31", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "c", + "id_val": "c", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,9:2:58-9:3:59", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/variadic.d2,9:2:58-9:3:59", + "value": [ + { + "string": "c", + "raw_string": "c" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "c" + }, + "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/TestCompile2/vars/errors/spread-non-map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json new file mode 100644 index 0000000000..02e2b3eb62 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2,5:2:26-5:9:33", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-map into map" + } + ] + } +} From 98f79e2ba5e20e8d13acda4d2dc9b58b677c23cc Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 12 Jul 2023 22:20:55 -0700 Subject: [PATCH 26/40] arrays --- d2compiler/compile_test.go | 88 ++++- d2ir/compile.go | 63 ++- d2parser/parse.go | 3 +- .../TestCompile2/vars/basic/array.exp.json | 347 +++++++++++++++++ .../vars/basic/multi-part-array.exp.json | 221 +++++++++++ .../vars/basic/spread-array.exp.json | 359 ++++++++++++++++++ .../vars/basic/sub-array.exp.json | 237 ++++++++++++ .../vars/errors/missing-array.exp.json | 11 + .../vars/errors/spread-non-array.exp.json | 11 + .../vars/errors/spread-non-map.exp.json | 2 +- .../vars/errors/spread-non-solo.exp.json | 11 + 11 files changed, 1335 insertions(+), 18 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/array.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/spread-array.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/missing-array.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/spread-non-array.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 36e502a687..ac43dcc6df 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3411,6 +3411,64 @@ z: { assert.Equal(t, 3, len(g.Objects[1].Children)) }, }, + { + name: "array", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + base-constraints: [UNQ; NOT NULL] +} +a: { + shape: sql_table + b: int {constraint: ${base-constraints}} +} +`, "") + assert.Equal(t, "a", g.Objects[0].ID) + assert.Equal(t, 2, len(g.Objects[0].SQLTable.Columns[0].Constraint)) + }, + }, + { + name: "spread-array", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + base-constraints: [UNQ; NOT NULL] +} +a: { + shape: sql_table + b: int {constraint: [PK; ...${base-constraints}]} +} +`, "") + assert.Equal(t, "a", g.Objects[0].ID) + assert.Equal(t, 3, len(g.Objects[0].SQLTable.Columns[0].Constraint)) + }, + }, + { + name: "sub-array", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: all +} +z.class: [a; ${x}] +`, "") + assert.Equal(t, "z", g.Objects[0].ID) + assert.Equal(t, "all", g.Objects[0].Attributes.Classes[1]) + }, + }, + { + name: "multi-part-array", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: all +} +z.class: [a; ${x}together] +`, "") + assert.Equal(t, "z", g.Objects[0].ID) + assert.Equal(t, "alltogether", g.Objects[0].Attributes.Classes[1]) + }, + }, } for _, tc := range tca { @@ -3742,7 +3800,35 @@ z: { ...${x} c } -`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-map into map`) +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-composite into composite`) + }, + }, + { + name: "missing-array", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: b +} +z: { + class: [...${a}] +} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing-array.d2:6:3: could not resolve variable "a"`) + }, + }, + { + name: "spread-non-array", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + x: { + a: b + } +} +z: { + class: [...${x}] +} +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-array.d2:8:11: cannot spread non-array into array`) }, }, { diff --git a/d2ir/compile.go b/d2ir/compile.go index db1e8ec5cd..f4f0e7d4c7 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -106,6 +106,13 @@ func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { if f.Primary() != nil { c.resolveSubstitutions(varsStack, f) } + if arr, ok := f.Composite.(*Array); ok { + for _, val := range arr.Values { + if scalar, ok := val.(*Scalar); ok { + c.resolveSubstitutions(varsStack, scalar) + } + } + } if f.Map() != nil { // don't resolve substitutions in vars with the current scope of vars if f.Name == "vars" { @@ -145,20 +152,34 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { } if box.Substitution.Spread { if resolvedField.Composite == nil { - c.errorf(box.Substitution, "cannot spread non-map into map") + c.errorf(box.Substitution, "cannot spread non-composite into composite") continue } - // TODO arrays - if resolvedField.Map() != nil { - OverlayMap(ParentMap(node), resolvedField.Map()) - } - // Remove the placeholder field - f := node.(*Field) - m := f.parent.(*Map) - for i, f2 := range m.Fields { - if f == f2 { - m.Fields = append(m.Fields[:i], m.Fields[i+1:]...) - break + switch n := node.(type) { + case *Scalar: // Array value + resolvedArr, ok := resolvedField.Composite.(*Array) + if !ok { + c.errorf(box.Substitution, "cannot spread non-array into array") + continue + } + arr := n.parent.(*Array) + for i, s := range arr.Values { + if s == n { + arr.Values = append(append(arr.Values[:i], resolvedArr.Values...), arr.Values[i+1:]...) + break + } + } + case *Field: + if resolvedField.Map() != nil { + OverlayMap(ParentMap(n), resolvedField.Map()) + } + // Remove the placeholder field + m := n.parent.(*Map) + for i, f2 := range m.Fields { + if n == f2 { + m.Fields = append(m.Fields[:i], m.Fields[i+1:]...) + break + } } } } @@ -167,6 +188,12 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { c.errorf(node.LastRef().AST(), `cannot substitute map variable "%s" as part of a string`, strings.Join(box.Substitution.IDA(), ".")) return } + switch n := node.(type) { + case *Field: + n.Primary_ = nil + case *Edge: + n.Primary_ = nil + } } else { if len(s.Value) == 1 { // If lone and unquoted, replace with value of sub @@ -276,7 +303,9 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { }) case n.Substitution != nil: if !n.Substitution.Spread { - c.errorf(n.Import, "invalid non-spread substitution in map") + // TODO parser parses ${x} as a field with name "$" and map of child x + // So this is never reached. But that parser behavior could change + c.errorf(n.Substitution, "invalid non-spread substitution in map") continue } // placeholder field to be resolved at the end @@ -653,8 +682,12 @@ func (c *compiler) compileArray(dst *Array, a *d2ast.Array, scopeAST *d2ast.Map) irv = n } case *d2ast.Substitution: - // TODO - // panic("TODO") + irv = &Scalar{ + parent: dst, + Value: &d2ast.UnquotedString{ + Value: []d2ast.InterpolationBox{{Substitution: an.Substitution}}, + }, + } } dst.Values = append(dst.Values, irv) diff --git a/d2parser/parse.go b/d2parser/parse.go index fa64531a31..bb460da82a 100644 --- a/d2parser/parse.go +++ b/d2parser/parse.go @@ -1560,7 +1560,8 @@ func (p *parser) parseArrayNode(r rune) d2ast.ArrayNodeBox { p.replay(r) vbox := p.parseValue() - if vbox.UnquotedString != nil && vbox.UnquotedString.ScalarString() == "" { + if vbox.UnquotedString != nil && vbox.UnquotedString.ScalarString() == "" && + !(len(vbox.UnquotedString.Value) > 0 && vbox.UnquotedString.Value[0].Substitution != nil) { p.errorf(p.pos, p.pos.Advance(r, p.utf16), "unquoted strings cannot start on %q", r) } box.Null = vbox.Null diff --git a/testdata/d2compiler/TestCompile2/vars/basic/array.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/array.exp.json new file mode 100644 index 0000000000..73c5d4b33f --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/array.exp.json @@ -0,0 +1,347 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,0:0:0-8:0:114", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,1:0:1-3:1:45", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,1:6:7-3:1:45", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,2:1:10-2:34:43", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,2:1:10-2:17:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,2:1:10-2:17:26", + "value": [ + { + "string": "base-constraints", + "raw_string": "base-constraints" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "array": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,2:19:28-2:33:42", + "nodes": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,2:20:29-2:23:32", + "value": [ + { + "string": "UNQ", + "raw_string": "UNQ" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,2:25:34-2:33:42", + "value": [ + { + "string": "NOT NULL", + "raw_string": "NOT NULL" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,4:0:46-7:1:113", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,4:0:46-4:1:47", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,4:0:46-4:1:47", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,4:3:49-7:1:113", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,5:2:53-5:18:69", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,5:2:53-5:7:58", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,5:2:53-5:7:58", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,5:9:60-5:18:69", + "value": [ + { + "string": "sql_table", + "raw_string": "sql_table" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:1:71-6:41:111", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:1:71-6:2:72", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:1:71-6:2:72", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:4:74-6:7:77", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + }, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:8:78-6:41:111", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:9:79-6:40:110", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:9:79-6:19:89", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:9:79-6:19:89", + "value": [ + { + "string": "constraint", + "raw_string": "constraint" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:21:91-6:22:92", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:21:91-6:40:110", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,6:23:93-6:39:109", + "value": [ + { + "string": "base-constraints", + "raw_string": "base-constraints" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/TestCompile2/vars/basic/array.d2,4:0:46-4:1:47", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/array.d2,4:0:46-4:1:47", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "sql_table": { + "columns": [ + { + "name": { + "label": "b", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "type": { + "label": "int", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "constraint": [ + "UNQ", + "NOT NULL" + ], + "reference": "" + } + ] + }, + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "sql_table" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.exp.json new file mode 100644 index 0000000000..f6b14f8640 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.exp.json @@ -0,0 +1,221 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,0:0:0-5:0:46", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,1:0:1-3:1:18", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,1:6:7-3:1:18", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,2:1:10-2:7:16", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,2:1:10-2:2:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,2:1:10-2:2:11", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,2:4:13-2:7:16", + "value": [ + { + "string": "all", + "raw_string": "all" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:0:19-4:26:45", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:0:19-4:7:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:0:19-4:1:20", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:2:21-4:7:26", + "value": [ + { + "string": "class", + "raw_string": "class" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "array": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:9:28-4:25:44", + "nodes": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:10:29-4:11:30", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:13:32-4:25:44", + "value": [ + { + "string": "alltogether" + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": "z", + "id_val": "z", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:0:19-4:7:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:0:19-4:1:20", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/multi-part-array.d2,4:2:21-4:7:26", + "value": [ + { + "string": "class", + "raw_string": "class" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null, + "classes": [ + "a", + "alltogether" + ] + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/vars/basic/spread-array.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/spread-array.exp.json new file mode 100644 index 0000000000..f83c5490d2 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/spread-array.exp.json @@ -0,0 +1,359 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,0:0:0-8:0:123", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,1:0:1-3:1:45", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,1:6:7-3:1:45", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,2:1:10-2:34:43", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,2:1:10-2:17:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,2:1:10-2:17:26", + "value": [ + { + "string": "base-constraints", + "raw_string": "base-constraints" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "array": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,2:19:28-2:33:42", + "nodes": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,2:20:29-2:23:32", + "value": [ + { + "string": "UNQ", + "raw_string": "UNQ" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,2:25:34-2:33:42", + "value": [ + { + "string": "NOT NULL", + "raw_string": "NOT NULL" + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,4:0:46-7:1:122", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,4:0:46-4:1:47", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,4:0:46-4:1:47", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,4:3:49-7:1:122", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,5:2:53-5:18:69", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,5:2:53-5:7:58", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,5:2:53-5:7:58", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,5:9:60-5:18:69", + "value": [ + { + "string": "sql_table", + "raw_string": "sql_table" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:1:71-6:50:120", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:1:71-6:2:72", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:1:71-6:2:72", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:4:74-6:7:77", + "value": [ + { + "string": "int", + "raw_string": "int" + } + ] + } + }, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:8:78-6:50:120", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:9:79-6:49:119", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:9:79-6:19:89", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:9:79-6:19:89", + "value": [ + { + "string": "constraint", + "raw_string": "constraint" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "array": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:21:91-6:48:118", + "nodes": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:22:92-6:24:94", + "value": [ + { + "string": "PK", + "raw_string": "PK" + } + ] + } + }, + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:26:96-6:48:118", + "spread": true, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,6:31:101-6:47:117", + "value": [ + { + "string": "base-constraints", + "raw_string": "base-constraints" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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/TestCompile2/vars/basic/spread-array.d2,4:0:46-4:1:47", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-array.d2,4:0:46-4:1:47", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "sql_table": { + "columns": [ + { + "name": { + "label": "b", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "type": { + "label": "int", + "fontSize": 0, + "fontFamily": "", + "language": "", + "color": "", + "italic": false, + "bold": false, + "underline": false, + "labelWidth": 0, + "labelHeight": 0 + }, + "constraint": [ + "PK", + "UNQ", + "NOT NULL" + ], + "reference": "" + } + ] + }, + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "sql_table" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json new file mode 100644 index 0000000000..0c182f3441 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json @@ -0,0 +1,237 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,0:0:0-5:0:38", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,1:0:1-3:1:18", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,1:6:7-3:1:18", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,2:1:10-2:7:16", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,2:1:10-2:2:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,2:1:10-2:2:11", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,2:4:13-2:7:16", + "value": [ + { + "string": "all", + "raw_string": "all" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:0:19-4:18:37", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:0:19-4:7:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:0:19-4:1:20", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:2:21-4:7:26", + "value": [ + { + "string": "class", + "raw_string": "class" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "array": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:9:28-4:18:37", + "nodes": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:10:29-4:11:30", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:13:32-4:14:33", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:13:32-4:17:36", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:15:34-4:16:35", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": "z", + "id_val": "z", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:0:19-4:7:26", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:0:19-4:1:20", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:2:21-4:7:26", + "value": [ + { + "string": "class", + "raw_string": "class" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "z" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null, + "classes": [ + "a", + "all" + ] + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/vars/errors/missing-array.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/missing-array.exp.json new file mode 100644 index 0000000000..a0790a2f07 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/missing-array.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing-array.d2,5:2:24-5:7:29", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/missing-array.d2:6:3: could not resolve variable \"a\"" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/errors/spread-non-array.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-array.exp.json new file mode 100644 index 0000000000..2ffbdf15cb --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-array.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-array.d2,7:10:45-7:17:52", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-array.d2:8:11: cannot spread non-array into array" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json index 02e2b3eb62..b713c683f3 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json @@ -4,7 +4,7 @@ "errs": [ { "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2,5:2:26-5:9:33", - "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-map into map" + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-composite into composite" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json new file mode 100644 index 0000000000..296f35954a --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2,7:1:36-7:2:37", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute map variable \"x\" as part of a string" + } + ] + } +} From 301bc8ddfbd789549af58e16add68a80d9ce84cb Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Wed, 12 Jul 2023 23:01:11 -0700 Subject: [PATCH 27/40] add precedent test --- d2compiler/compile_test.go | 25 + .../TestCompile2/vars/boards/layer-2.exp.json | 631 ++++++++++++++++++ 2 files changed, 656 insertions(+) create mode 100644 testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index ac43dcc6df..457b442a7c 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3597,6 +3597,31 @@ layers: { assert.Equal(t, "im a var", g.Layers[0].Objects[0].Label.Value) }, }, + { + name: "layer-2", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: root var x + y: root var y +} + +layers: { + l: { + vars: { + x: layer var x + } + hi: ${x} + hello: ${y} + } +} +`, "") + assert.Equal(t, "hi", g.Layers[0].Objects[0].ID) + assert.Equal(t, "layer var x", g.Layers[0].Objects[0].Label.Value) + assert.Equal(t, "hello", g.Layers[0].Objects[1].ID) + assert.Equal(t, "root var y", g.Layers[0].Objects[1].Label.Value) + }, + }, { name: "scenario", run: func(t *testing.T) { diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json new file mode 100644 index 0000000000..1edf3e182c --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json @@ -0,0 +1,631 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,0:0:0-15:0:135", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,1:0:1-4:1:42", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,1:6:7-4:1:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,2:2:11-2:15:24", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,2:2:11-2:3:12", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,2:2:11-2:3:12", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,2:5:14-2:15:24", + "value": [ + { + "string": "root var x", + "raw_string": "root var x" + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,3:2:27-3:15:40", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,3:2:27-3:3:28", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,3:2:27-3:3:28", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,3:5:30-3:15:40", + "value": [ + { + "string": "root var y", + "raw_string": "root var y" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,6:0:44-14:1:134", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,6:0:44-6:6:50", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,6:0:44-6:6:50", + "value": [ + { + "string": "layers", + "raw_string": "layers" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,6:8:52-14:1:134", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,7:2:56-13:3:132", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,7:2:56-7:3:57", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,7:2:56-7:3:57", + "value": [ + { + "string": "l", + "raw_string": "l" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,7:5:59-13:3:132", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,8:4:65-10:5:99", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,8:4:65-8:8:69", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,8:4:65-8:8:69", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,8:10:71-10:5:99", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,9:6:79-9:20:93", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,9:6:79-9:7:80", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,9:6:79-9:7:80", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,9:9:82-9:20:93", + "value": [ + { + "string": "layer var x", + "raw_string": "layer var x" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:4:104-11:12:112", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:4:104-11:6:106", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:4:104-11:6:106", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:8:108-11:9:109", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:8:108-11:12:112", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:10:110-11:11:111", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:4:117-12:15:128", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:4:117-12:9:122", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:4:117-12:9:122", + "value": [ + { + "string": "hello", + "raw_string": "hello" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:11:124-12:12:125", + "value": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:11:124-12:15:128", + "spread": false, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:13:126-12:14:127", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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, + "layers": [ + { + "name": "l", + "isFolderOnly": false, + "ast": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": ",1:0:0-2:0:0", + "nodes": [ + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,9:9:82-9:20:93", + "value": [ + { + "string": "layer var x", + "raw_string": "layer var x" + } + ] + } + }, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "y" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,3:5:30-3:15:40", + "value": [ + { + "string": "root var y", + "raw_string": "root var y" + } + ] + } + }, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hi" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,9:9:82-9:20:93", + "value": [ + { + "string": "layer var x", + "raw_string": "layer var x" + } + ] + } + }, + "value": {} + } + }, + { + "map_key": { + "range": ",0:0:0-0:0:0", + "key": { + "range": ",0:0:0-0:0:0", + "path": [ + { + "unquoted_string": { + "range": ",0:0:0-0:0:0", + "value": [ + { + "string": "hello" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,3:5:30-3:15:40", + "value": [ + { + "string": "root var y", + "raw_string": "root var y" + } + ] + } + }, + "value": {} + } + } + ] + }, + "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/boards/layer-2.d2,11:4:104-11:6:106", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:4:104-11:6:106", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "layer var x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "hello", + "id_val": "hello", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:4:117-12:9:122", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:4:117-12:9:122", + "value": [ + { + "string": "hello", + "raw_string": "hello" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "root var y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + } + ] + }, + "err": null +} From ef11d47fc8208259ffee227edb63903fe337fa3a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 08:35:16 -0700 Subject: [PATCH 28/40] null --- d2compiler/compile_test.go | 16 ++++++++++++++++ d2ir/compile.go | 14 ++++++++++++-- .../TestCompile2/vars/boards/null.exp.json | 11 +++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/boards/null.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 457b442a7c..15ed529621 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3696,6 +3696,22 @@ scenarios: { assert.Equal(t, "im replaced x var", g.Scenarios[0].Objects[0].Label.Value) }, }, + { + name: "null", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + surname: Smith +} +a: { + vars: { + surname: null + } + hi: John ${surname} +} +`, `d2/testdata/d2compiler/TestCompile2/vars/boards/null.d2:9:3: could not resolve variable "surname"`) + }, + }, } for _, tc := range tca { diff --git a/d2ir/compile.go b/d2ir/compile.go index f4f0e7d4c7..f4fc7775bc 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -143,6 +143,11 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { for _, vars := range varsStack { resolvedField = c.resolveSubstitution(vars, box.Substitution) if resolvedField != nil { + if resolvedField.Primary() != nil { + if _, ok := resolvedField.Primary().Value.(*d2ast.Null); ok { + resolvedField = nil + } + } break } } @@ -257,6 +262,7 @@ func (c *compiler) resolveSubstitution(vars *Map, substitution *d2ast.Substituti if f == nil { return nil } + if i == len(substitution.Path)-1 { return f } @@ -351,8 +357,12 @@ func (c *compiler) compileKey(refctx *RefContext) { func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) { if refctx.Key != nil && len(refctx.Key.Edges) == 0 && refctx.Key.Value.Null != nil { - dst.DeleteField(kp.IDA()...) - return + // For vars, if we delete the field, it may just resolve to an outer scope var of the same name + // Instead we keep it around, so that resolveSubstitutions can find it + if ParentField(dst) == nil || ParentField(dst).Name != "vars" { + dst.DeleteField(kp.IDA()...) + return + } } f, err := dst.EnsureField(kp, refctx) if err != nil { diff --git a/testdata/d2compiler/TestCompile2/vars/boards/null.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/null.exp.json new file mode 100644 index 0000000000..b96afe0dd3 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/null.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/null.d2,8:2:64-8:4:66", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/boards/null.d2:9:3: could not resolve variable \"surname\"" + } + ] + } +} From 06ed41ecaedeaf220e7da83287b8ded48d8552bd Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 08:36:28 -0700 Subject: [PATCH 29/40] remove dead code --- d2ir/compile.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/d2ir/compile.go b/d2ir/compile.go index f4fc7775bc..fb9ca598eb 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -308,12 +308,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { ScopeAST: scopeAST, }) case n.Substitution != nil: - if !n.Substitution.Spread { - // TODO parser parses ${x} as a field with name "$" and map of child x - // So this is never reached. But that parser behavior could change - c.errorf(n.Substitution, "invalid non-spread substitution in map") - continue - } // placeholder field to be resolved at the end f := &Field{ parent: dst, From ffdb5121f49e16e4f82f63cb034452881a77a91d Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 08:37:22 -0700 Subject: [PATCH 30/40] err msg --- d2compiler/compile_test.go | 2 +- d2ir/compile.go | 2 +- .../d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 15ed529621..33336b247c 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3841,7 +3841,7 @@ z: { ...${x} c } -`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-composite into composite`) +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-composite`) }, }, { diff --git a/d2ir/compile.go b/d2ir/compile.go index fb9ca598eb..2f28ce9b6f 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -157,7 +157,7 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { } if box.Substitution.Spread { if resolvedField.Composite == nil { - c.errorf(box.Substitution, "cannot spread non-composite into composite") + c.errorf(box.Substitution, "cannot spread non-composite") continue } switch n := node.(type) { diff --git a/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json index b713c683f3..85b10a3cea 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.exp.json @@ -4,7 +4,7 @@ "errs": [ { "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2,5:2:26-5:9:33", - "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-composite into composite" + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-map.d2:6:3: cannot spread non-composite" } ] } From 780345beeb3e3ad89e70b2f940a5a4f04b684b8a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 10:11:08 -0700 Subject: [PATCH 31/40] fix double quote primary --- d2compiler/compile_test.go | 15 ++ d2ir/compile.go | 5 +- .../vars/basic/double-quote-primary.exp.json | 216 ++++++++++++++++++ 3 files changed, 233 insertions(+), 3 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 33336b247c..fdf1cc82f5 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3469,6 +3469,21 @@ z.class: [a; ${x}together] assert.Equal(t, "alltogether", g.Objects[0].Attributes.Classes[1]) }, }, + { + name: "double-quote-primary", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + x: always { + a: b + } +} +z: "${x} be my maybe" +`, "") + assert.Equal(t, "z", g.Objects[0].ID) + assert.Equal(t, "always be my maybe", g.Objects[0].Label.Value) + }, + }, } for _, tc := range tca { diff --git a/d2ir/compile.go b/d2ir/compile.go index 2f28ce9b6f..0cdbe5c45a 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -112,8 +112,7 @@ func (c *compiler) compileSubstitutions(m *Map, varsStack []*Map) { c.resolveSubstitutions(varsStack, scalar) } } - } - if f.Map() != nil { + } else if f.Map() != nil { // don't resolve substitutions in vars with the current scope of vars if f.Name == "vars" { c.compileSubstitutions(f.Map(), varsStack[1:]) @@ -238,7 +237,7 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { c.errorf(node.LastRef().AST(), `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) return } - if resolvedField.Composite != nil { + if resolvedField.Primary() == nil && resolvedField.Composite != nil { c.errorf(node.LastRef().AST(), `cannot substitute map variable "%s" in quotes`, strings.Join(box.Substitution.IDA(), ".")) return } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.exp.json new file mode 100644 index 0000000000..d23e462599 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.exp.json @@ -0,0 +1,216 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,0:0:0-7:0:59", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,1:0:1-5:1:36", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,1:6:7-5:1:36", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,2:1:10-4:3:34", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,2:1:10-2:2:11", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,2:1:10-2:2:11", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,2:4:13-2:10:19", + "value": [ + { + "string": "always", + "raw_string": "always" + } + ] + } + }, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,2:11:20-4:3:34", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,3:4:26-3:8:30", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,3:4:26-3:5:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,3:4:26-3:5:27", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,3:7:29-3:8:30", + "value": [ + { + "string": "b", + "raw_string": "b" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,6:0:37-6:21:58", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,6:0:37-6:1:38", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,6:0:37-6:1:38", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "double_quoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,6:3:40-6:21:58", + "value": [ + { + "string": "always be my maybe" + } + ] + } + } + } + } + ] + }, + "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": "z", + "id_val": "z", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,6:0:37-6:1:38", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/double-quote-primary.d2,6:0:37-6:1:38", + "value": [ + { + "string": "z", + "raw_string": "z" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "always be my maybe" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} From eba41af47d101964b31c90f52465cf45ad8a0439 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 10:13:26 -0700 Subject: [PATCH 32/40] use scalarstring --- d2compiler/compile_test.go | 2 +- d2ir/compile.go | 11 +-- .../vars/basic/edge-label.exp.json | 18 +--- .../TestCompile2/vars/basic/edge-map.exp.json | 18 +--- .../TestCompile2/vars/basic/nested.exp.json | 40 +------- .../TestCompile2/vars/basic/number.exp.json | 18 +--- .../vars/basic/parent-scope.exp.json | 18 +--- .../vars/basic/primary-and-composite.exp.json | 18 +--- .../vars/basic/quoted-var-quoted-sub.exp.json | 4 +- .../vars/basic/quoted-var.exp.json | 40 +------- .../vars/basic/shape-label.exp.json | 18 +--- .../TestCompile2/vars/basic/style.exp.json | 18 +--- .../vars/basic/sub-array.exp.json | 18 +--- .../TestCompile2/vars/boards/layer-2.exp.json | 46 ++-------- .../TestCompile2/vars/boards/layer.exp.json | 23 +---- .../TestCompile2/vars/boards/overlay.exp.json | 92 +++---------------- .../TestCompile2/vars/boards/replace.exp.json | 23 +---- .../vars/boards/scenario.exp.json | 23 +---- .../TestCompile2/vars/override/map.exp.json | 18 +--- .../vars/override/recursive-var.exp.json | 18 +--- .../vars/override/var-in-var.exp.json | 18 +--- 21 files changed, 46 insertions(+), 456 deletions(-) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index fdf1cc82f5..b99b1a8c93 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3337,7 +3337,7 @@ vars: { y: "hey ${x}" `, "") - assert.Equal(t, `hey "hi"`, g.Objects[0].Label.Value) + assert.Equal(t, `hey hi`, g.Objects[0].Label.Value) }, }, { diff --git a/d2ir/compile.go b/d2ir/compile.go index 0cdbe5c45a..1aaa321509 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -199,13 +199,8 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { n.Primary_ = nil } } else { - if len(s.Value) == 1 { - // If lone and unquoted, replace with value of sub - node.Primary().Value = resolvedField.Primary().Value - } else { - s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) - subbed = true - } + s.Value[i].String = go2.Pointer(resolvedField.Primary().Value.ScalarString()) + subbed = true } if resolvedField.Composite != nil { switch n := node.(type) { @@ -241,7 +236,7 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { c.errorf(node.LastRef().AST(), `cannot substitute map variable "%s" in quotes`, strings.Join(box.Substitution.IDA(), ".")) return } - s.Value[i].String = go2.Pointer(resolvedField.Primary().String()) + s.Value[i].String = go2.Pointer(resolvedField.Primary().Value.ScalarString()) subbed = true } } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json index 87391a5711..4a85c46033 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json @@ -115,23 +115,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:8:33-4:9:34", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:8:33-4:12:37", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-label.d2,4:10:35-4:11:36", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json index cb64534ff0..92d823330f 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json @@ -150,23 +150,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:26:61-5:27:62", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:26:61-5:30:65", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/edge-map.d2,5:28:63-5:29:64", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json index 2b5c53b82a..d32d26e50c 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json @@ -185,45 +185,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:15:86", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:38:109", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:16:87-9:22:93", - "value": [ - { - "string": "colors", - "raw_string": "colors" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:23:94-9:30:101", - "value": [ - { - "string": "primary", - "raw_string": "primary" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:31:102-9:37:108", - "value": [ - { - "string": "button", - "raw_string": "button" - } - ] - } - } - ] - } + "string": "red" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json index a27ca9ad5e..37d67c845d 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json @@ -112,23 +112,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:16:45", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:25:54", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:17:46-5:24:53", - "value": [ - { - "string": "columns", - "raw_string": "columns" - } - ] - } - } - ] - } + "string": "2" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json index b9d8924d51..5a3d26c1e0 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json @@ -178,23 +178,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:6:74-8:7:75", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:6:74-8:10:78", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.d2,8:8:76-8:9:77", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im root var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json index f7ddb1d5cc..bceafd1911 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json @@ -131,23 +131,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:3:35-6:4:36", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:3:35-6:7:39", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.d2,6:5:37-6:6:38", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "all" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.exp.json index 1004100aab..0ab13c79f3 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.exp.json @@ -92,7 +92,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var-quoted-sub.d2,5:3:25-5:13:35", "value": [ { - "string": "hey \"hi\"" + "string": "hey hi" } ] } @@ -153,7 +153,7 @@ ], "attributes": { "label": { - "value": "hey \"hi\"" + "value": "hey hi" }, "labelDimensions": { "width": 0, diff --git a/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json index ec15253727..24ca57ef51 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json @@ -227,45 +227,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:10:131-12:11:132", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:10:131-12:40:161", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:12:133-12:25:146", - "value": [ - { - "string": "primaryColors", - "raw_string": "primaryColors" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:26:147-12:32:153", - "value": [ - { - "string": "button", - "raw_string": "button" - } - ] - } - }, - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:33:154-12:39:160", - "value": [ - { - "string": "active", - "raw_string": "active" - } - ] - } - } - ] - } + "string": "#4baae5" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json index faf48d6517..29d85cf4e2 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json @@ -92,23 +92,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,4:4:29-4:5:30", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,4:4:29-4:8:33", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/shape-label.d2,4:6:31-4:7:32", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json index 9cd133ce42..11ae2fe4d6 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json @@ -127,23 +127,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:15:53", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:30:68", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:16:54-5:29:67", - "value": [ - { - "string": "primary-color", - "raw_string": "primary-color" - } - ] - } - } - ] - } + "string": "red" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json index 0c182f3441..0ad0ba9f37 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json @@ -118,23 +118,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:13:32-4:14:33", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:13:32-4:17:36", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/sub-array.d2,4:15:34-4:16:35", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "all" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json index 1edf3e182c..bd02109b50 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json @@ -235,23 +235,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:8:108-11:9:109", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:8:108-11:12:112", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:10:110-11:11:111", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "layer var x" } ] } @@ -283,23 +267,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:11:124-12:12:125", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:11:124-12:15:128", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:13:126-12:14:127", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - } + "string": "root var y" } ] } @@ -462,11 +430,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,9:9:82-9:20:93", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:8:108-11:9:109", "value": [ { - "string": "layer var x", - "raw_string": "layer var x" + "string": "layer var x" } ] } @@ -494,11 +461,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,3:5:30-3:15:40", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,12:11:124-12:12:125", "value": [ { - "string": "root var y", - "raw_string": "root var y" + "string": "root var y" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json index 2f2a237c82..7f3f693b18 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json @@ -140,23 +140,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:12:55", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:10:53-7:11:54", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im a var" } ] } @@ -287,11 +271,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json index b2557d9b0e..23431936c4 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json @@ -202,23 +202,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:11:93", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:9:91-10:10:92", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im x var" } ] } @@ -250,23 +234,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:11:105", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:9:103-11:10:104", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - } + "string": "im y var" } ] } @@ -418,23 +386,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:11:177", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:9:175-19:10:176", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im x var" } ] } @@ -466,23 +418,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:11:189", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:9:187-20:10:188", - "value": [ - { - "string": "y", - "raw_string": "y" - } - ] - } - } - ] - } + "string": "im y var" } ] } @@ -645,11 +581,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "string": "im x var" } ] } @@ -677,11 +612,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,17:9:151-17:17:159", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "string": "im y var" } ] } @@ -928,11 +862,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90", "value": [ { - "string": "im x var", - "raw_string": "im x var" + "string": "im x var" } ] } @@ -960,11 +893,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,8:9:67-8:17:75", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102", "value": [ { - "string": "im y var", - "raw_string": "im y var" + "string": "im y var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json index 86ad2c0cbf..fc75006dd6 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json @@ -202,23 +202,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:11:102", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:9:100-10:10:101", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im replaced x var" } ] } @@ -349,11 +333,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,8:9:67-8:26:84", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99", "value": [ { - "string": "im replaced x var", - "raw_string": "im replaced x var" + "string": "im replaced x var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json index 1da21aa143..571e94ad86 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json @@ -140,23 +140,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:12:58", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:10:56-7:11:57", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im a var" } ] } @@ -287,11 +271,10 @@ }, "primary": { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,2:5:14-2:13:22", + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55", "value": [ { - "string": "im a var", - "raw_string": "im a var" + "string": "im a var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/override/map.exp.json b/testdata/d2compiler/TestCompile2/vars/override/map.exp.json index 11208a29bb..cd51692583 100644 --- a/testdata/d2compiler/TestCompile2/vars/override/map.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/override/map.exp.json @@ -178,23 +178,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:6:74-8:7:75", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:6:74-8:10:78", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/map.d2,8:8:76-8:9:77", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "im nested var" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json b/testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json index 19277bee22..25f7bf6a0e 100644 --- a/testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json @@ -177,23 +177,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:6:58-8:7:59", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:6:58-8:10:62", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/recursive-var.d2,8:8:60-8:9:61", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "a-b" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json b/testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json index 6f41e1fad8..f6beaba86d 100644 --- a/testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json @@ -209,23 +209,7 @@ "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:6:104-9:7:105", "value": [ { - "substitution": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:6:104-9:15:113", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/override/var-in-var.d2,9:8:106-9:14:112", - "value": [ - { - "string": "trade1", - "raw_string": "trade1" - } - ] - } - } - ] - } + "string": "BlackSmith" } ] } From a54907e28a2f3c08ab890afcdf5eb52ae023095d Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 10:16:41 -0700 Subject: [PATCH 33/40] remove overlayVars --- d2ir/compile.go | 17 ------ .../TestCompile2/vars/boards/layer-2.exp.json | 32 ---------- .../TestCompile2/vars/boards/layer.exp.json | 60 ------------------- .../TestCompile2/vars/boards/overlay.exp.json | 32 ---------- 4 files changed, 141 deletions(-) diff --git a/d2ir/compile.go b/d2ir/compile.go index 1aaa321509..3efd94dd86 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -265,22 +265,6 @@ func (c *compiler) resolveSubstitution(vars *Map, substitution *d2ast.Substituti return nil } -func (c *compiler) overlayVars(base, overlay *Map) { - vars := overlay.GetField("vars") - if vars == nil { - return - } - vars = vars.Copy(base).(*Field) - - baseVars := base.GetField("vars") - if baseVars != nil { - OverlayMap(vars.Map(), baseVars.Map()) - base.DeleteField("vars") - } - - base.Fields = append(base.Fields, vars) -} - func (c *compiler) overlay(base *Map, f *Field) { if f.Map() == nil || f.Primary() != nil { c.errorf(f.References[0].Context.Key, "invalid %s", NodeBoardKind(f)) @@ -393,7 +377,6 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) } } case BoardLayer: - c.overlayVars(f.Map(), ParentBoard(f).Map()) default: // If new board type, use that as the new scope AST, otherwise, carry on scopeAST = refctx.ScopeAST diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json index bd02109b50..891273336b 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json @@ -372,38 +372,6 @@ }, "value": {} } - }, - { - "map_key": { - "range": ",0:0:0-0:0:0", - "key": { - "range": ",0:0:0-0:0:0", - "path": [ - { - "unquoted_string": { - "range": ",0:0:0-0:0:0", - "value": [ - { - "string": "y" - } - ] - } - } - ] - }, - "primary": { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,3:5:30-3:15:40", - "value": [ - { - "string": "root var y", - "raw_string": "root var y" - } - ] - } - }, - "value": {} - } } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json index 7f3f693b18..80e36aa1ed 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json @@ -191,66 +191,6 @@ "ast": { "range": ",1:0:0-2:0:0", "nodes": [ - { - "map_key": { - "range": ",0:0:0-0:0:0", - "key": { - "range": ",0:0:0-0:0:0", - "path": [ - { - "unquoted_string": { - "range": ",0:0:0-0:0:0", - "value": [ - { - "string": "vars" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "map": { - "range": ",1:0:0-2:0:0", - "nodes": [ - { - "map_key": { - "range": ",0:0:0-0:0:0", - "key": { - "range": ",0:0:0-0:0:0", - "path": [ - { - "unquoted_string": { - "range": ",0:0:0-0:0:0", - "value": [ - { - "string": "x" - } - ] - } - } - ] - }, - "primary": { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,2:5:14-2:13:22", - "value": [ - { - "string": "im a var", - "raw_string": "im a var" - } - ] - } - }, - "value": {} - } - } - ] - } - } - } - }, { "map_key": { "range": ",0:0:0-0:0:0", diff --git a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json index 23431936c4..5f46293b97 100644 --- a/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json @@ -492,38 +492,6 @@ "map": { "range": ",1:0:0-2:0:0", "nodes": [ - { - "map_key": { - "range": ",0:0:0-0:0:0", - "key": { - "range": ",0:0:0-0:0:0", - "path": [ - { - "unquoted_string": { - "range": ",0:0:0-0:0:0", - "value": [ - { - "string": "x" - } - ] - } - } - ] - }, - "primary": { - "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,2:5:14-2:13:22", - "value": [ - { - "string": "im x var", - "raw_string": "im x var" - } - ] - } - }, - "value": {} - } - }, { "map_key": { "range": ",0:0:0-0:0:0", From fb0c0d20edef91b518db8ff20eb55d5999d67a62 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 10:22:37 -0700 Subject: [PATCH 34/40] nested null --- d2compiler/compile_test.go | 52 +++++++++++++------ d2ir/compile.go | 2 +- d2ir/d2ir.go | 15 ++++++ .../vars/override/nested-null.exp.json | 11 ++++ .../TestCompile2/vars/override/null.exp.json | 11 ++++ 5 files changed, 74 insertions(+), 17 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/override/nested-null.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/override/null.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index b99b1a8c93..767cc9ac04 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3572,6 +3572,42 @@ hi: { assert.Equal(t, "a-b", g.Objects[1].Label.Value) }, }, + { + name: "null", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + surname: Smith +} +a: { + vars: { + surname: null + } + hi: John ${surname} +} +`, `d2/testdata/d2compiler/TestCompile2/vars/override/null.d2:9:3: could not resolve variable "surname"`) + }, + }, + { + name: "nested-null", + run: func(t *testing.T) { + assertCompile(t, ` +vars: { + surnames: { + john: smith + } +} +a: { + vars: { + surnames: { + john: null + } + } + hi: John ${surname} +} +`, `d2/testdata/d2compiler/TestCompile2/vars/override/nested-null.d2:13:3: could not resolve variable "surname"`) + }, + }, } for _, tc := range tca { @@ -3711,22 +3747,6 @@ scenarios: { assert.Equal(t, "im replaced x var", g.Scenarios[0].Objects[0].Label.Value) }, }, - { - name: "null", - run: func(t *testing.T) { - assertCompile(t, ` -vars: { - surname: Smith -} -a: { - vars: { - surname: null - } - hi: John ${surname} -} -`, `d2/testdata/d2compiler/TestCompile2/vars/boards/null.d2:9:3: could not resolve variable "surname"`) - }, - }, } for _, tc := range tca { diff --git a/d2ir/compile.go b/d2ir/compile.go index 3efd94dd86..ef88d95a9f 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -331,7 +331,7 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) if refctx.Key != nil && len(refctx.Key.Edges) == 0 && refctx.Key.Value.Null != nil { // For vars, if we delete the field, it may just resolve to an outer scope var of the same name // Instead we keep it around, so that resolveSubstitutions can find it - if ParentField(dst) == nil || ParentField(dst).Name != "vars" { + if !IsVar(dst) { dst.DeleteField(kp.IDA()...) return } diff --git a/d2ir/d2ir.go b/d2ir/d2ir.go index 65ed636b55..1160021f42 100644 --- a/d2ir/d2ir.go +++ b/d2ir/d2ir.go @@ -1026,6 +1026,21 @@ func ParentField(n Node) *Field { } } +func IsVar(n Node) bool { + for { + if n == nil { + return false + } + if NodeBoardKind(n) != "" { + return false + } + if f, ok := n.(*Field); ok && f.Name == "vars" { + return true + } + n = n.Parent() + } +} + func ParentBoard(n Node) Node { for { n = n.Parent() diff --git a/testdata/d2compiler/TestCompile2/vars/override/nested-null.exp.json b/testdata/d2compiler/TestCompile2/vars/override/nested-null.exp.json new file mode 100644 index 0000000000..e73ae9f615 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/nested-null.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/nested-null.d2,12:2:102-12:4:104", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/override/nested-null.d2:13:3: could not resolve variable \"surname\"" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile2/vars/override/null.exp.json b/testdata/d2compiler/TestCompile2/vars/override/null.exp.json new file mode 100644 index 0000000000..84df5d0e50 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/null.exp.json @@ -0,0 +1,11 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/null.d2,8:2:64-8:4:66", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/override/null.d2:9:3: could not resolve variable \"surname\"" + } + ] + } +} From 4847714c3c88507dbcba38ba9e805a486c2dd709 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 12:24:48 -0700 Subject: [PATCH 35/40] fix compiler creating vars --- d2compiler/compile.go | 4 +- d2compiler/compile_test.go | 21 +- .../vars/basic/primary-and-composite.exp.json | 46 --- .../TestCompile2/vars/basic/removed.exp.json | 212 ++++++++++++++ .../vars/basic/spread-nested.exp.json | 267 ++++++++++++++++++ .../TestCompile2/vars/basic/spread.exp.json | 86 ++---- 6 files changed, 520 insertions(+), 116 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/removed.exp.json create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/spread-nested.exp.json diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 29927ca57a..e2c8b71bbd 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -342,7 +342,7 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { Scope: fr.Context.Scope, ScopeAST: fr.Context.ScopeAST, } - if fr.Context.ScopeMap != nil { + if fr.Context.ScopeMap != nil && !d2ir.IsVar(fr.Context.ScopeMap) { scopeObjIDA := d2graphIDA(d2ir.BoardIDA(fr.Context.ScopeMap)) r.ScopeObj = obj.Graph.Root.EnsureChild(scopeObjIDA) } @@ -738,7 +738,7 @@ func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) { Scope: er.Context.Scope, ScopeAST: er.Context.ScopeAST, } - if er.Context.ScopeMap != nil { + if er.Context.ScopeMap != nil && !d2ir.IsVar(er.Context.ScopeMap) { scopeObjIDA := d2graphIDA(d2ir.BoardIDA(er.Context.ScopeMap)) r.ScopeObj = edge.Src.Graph.Root.EnsureChild(scopeObjIDA) } diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 767cc9ac04..d716228cf4 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3407,8 +3407,9 @@ z: { c } `, "") - assert.Equal(t, "z", g.Objects[1].ID) - assert.Equal(t, 3, len(g.Objects[1].Children)) + assert.Equal(t, "z", g.Objects[2].ID) + assert.Equal(t, 4, len(g.Objects)) + assert.Equal(t, 3, len(g.Objects[2].Children)) }, }, { @@ -3484,6 +3485,22 @@ z: "${x} be my maybe" assert.Equal(t, "always be my maybe", g.Objects[0].Label.Value) }, }, + { + name: "spread-nested", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + disclaimer: { + I am not a lawyer + } +} +custom-disclaimer: DRAFT DISCLAIMER { + ...${disclaimer} +} +`, "") + assert.Equal(t, 2, len(g.Objects)) + }, + }, } for _, tc := range tca { diff --git a/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json index bceafd1911..87592f6fcf 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json @@ -254,52 +254,6 @@ "constraint": null }, "zIndex": 0 - }, - { - "id": "vars", - "id_val": "vars", - "attributes": { - "label": { - "value": "vars" - }, - "labelDimensions": { - "width": 0, - "height": 0 - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": null - }, - "zIndex": 0 - }, - { - "id": "x", - "id_val": "x", - "attributes": { - "label": { - "value": "x" - }, - "labelDimensions": { - "width": 0, - "height": 0 - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": null - }, - "zIndex": 0 } ] }, diff --git a/testdata/d2compiler/TestCompile2/vars/basic/removed.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/removed.exp.json new file mode 100644 index 0000000000..afa9d9a11e --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/removed.exp.json @@ -0,0 +1,212 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,0:0:0-8:0:121", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,1:0:1-7:1:120", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,1:6:7-7:1:120", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,2:2:11-2:35:44", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,2:2:11-2:18:27", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,2:2:11-2:18:27", + "value": [ + { + "string": "base-constraints", + "raw_string": "base-constraints" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "array": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,2:20:29-2:34:43", + "nodes": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,2:21:30-2:29:38", + "value": [ + { + "string": "NOT NULL", + "raw_string": "NOT NULL" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,2:31:40-2:34:43", + "value": [ + { + "string": "UNQ", + "raw_string": "UNQ" + } + ] + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,3:2:47-6:3:118", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,3:2:47-3:12:57", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,3:2:47-3:12:57", + "value": [ + { + "string": "disclaimer", + "raw_string": "disclaimer" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,3:14:59-3:24:69", + "value": [ + { + "string": "DISCLAIMER", + "raw_string": "DISCLAIMER" + } + ] + } + }, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,3:25:70-6:3:118", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,4:4:76-4:21:93", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,4:4:76-4:21:93", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,4:4:76-4:21:93", + "value": [ + { + "string": "I am not a lawyer", + "raw_string": "I am not a lawyer" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,5:4:98-5:20:114", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,5:4:98-5:8:102", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,5:4:98-5:8:102", + "value": [ + { + "string": "near", + "raw_string": "near" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/removed.d2,5:10:104-5:20:114", + "value": [ + { + "string": "top-center", + "raw_string": "top-center" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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 +} diff --git a/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.exp.json new file mode 100644 index 0000000000..c8e6699c94 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.exp.json @@ -0,0 +1,267 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,0:0:0-9:0:112", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,1:0:1-5:1:52", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,1:6:7-5:1:52", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,2:2:11-4:3:50", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,2:2:11-2:12:21", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,2:2:11-2:12:21", + "value": [ + { + "string": "disclaimer", + "raw_string": "disclaimer" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,2:14:23-4:3:50", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,3:4:29-3:21:46", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,3:4:29-3:21:46", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,3:4:29-3:21:46", + "value": [ + { + "string": "I am not a lawyer", + "raw_string": "I am not a lawyer" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,6:0:53-8:1:111", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,6:0:53-6:17:70", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,6:0:53-6:17:70", + "value": [ + { + "string": "custom-disclaimer", + "raw_string": "custom-disclaimer" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,6:19:72-6:35:88", + "value": [ + { + "string": "DRAFT DISCLAIMER", + "raw_string": "DRAFT DISCLAIMER" + } + ] + } + }, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,6:36:89-8:1:111", + "nodes": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,7:2:93-7:18:109", + "spread": true, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,7:7:98-7:17:108", + "value": [ + { + "string": "disclaimer", + "raw_string": "disclaimer" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": "I am not a lawyer", + "id_val": "I am not a lawyer", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,3:4:29-3:21:46", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,3:4:29-3:21:46", + "value": [ + { + "string": "I am not a lawyer", + "raw_string": "I am not a lawyer" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "I am not a lawyer" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "custom-disclaimer", + "id_val": "custom-disclaimer", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,6:0:53-6:17:70", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-nested.d2,6:0:53-6:17:70", + "value": [ + { + "string": "custom-disclaimer", + "raw_string": "custom-disclaimer" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "DRAFT DISCLAIMER" + }, + "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/TestCompile2/vars/basic/spread.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/spread.exp.json index 9dbadf0d4d..8789c60c70 100644 --- a/testdata/d2compiler/TestCompile2/vars/basic/spread.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/basic/spread.exp.json @@ -283,20 +283,20 @@ "zIndex": 0 }, { - "id": "z", - "id_val": "z", + "id": "b", + "id_val": "b", "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-7:1:42", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:5:31", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-7:1:42", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:5:31", "value": [ { - "string": "z", - "raw_string": "z" + "string": "b", + "raw_string": "b" } ] } @@ -309,7 +309,7 @@ ], "attributes": { "label": { - "value": "z" + "value": "c" }, "labelDimensions": { "width": 0, @@ -328,20 +328,20 @@ "zIndex": 0 }, { - "id": "c", - "id_val": "c", + "id": "z", + "id_val": "z", "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-7:1:42", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,7:0:41-7:1:42", "value": [ { - "string": "c", - "raw_string": "c" + "string": "z", + "raw_string": "z" } ] } @@ -354,53 +354,7 @@ ], "attributes": { "label": { - "value": "c" - }, - "labelDimensions": { - "width": 0, - "height": 0 - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": null - }, - "zIndex": 0 - }, - { - "id": "vars", - "id_val": "vars", - "attributes": { - "label": { - "value": "vars" - }, - "labelDimensions": { - "width": 0, - "height": 0 - }, - "style": {}, - "near_key": null, - "shape": { - "value": "rectangle" - }, - "direction": { - "value": "" - }, - "constraint": null - }, - "zIndex": 0 - }, - { - "id": "x", - "id_val": "x", - "attributes": { - "label": { - "value": "x" + "value": "z" }, "labelDimensions": { "width": 0, @@ -419,20 +373,20 @@ "zIndex": 0 }, { - "id": "b", - "id_val": "b", + "id": "c", + "id_val": "c", "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:5:31", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,4:4:30-4:5:31", + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread.d2,9:2:58-9:3:59", "value": [ { - "string": "b", - "raw_string": "b" + "string": "c", + "raw_string": "c" } ] } From 29af92310bc95873a218d6acbd173d90ed4d4587 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 14:11:14 -0700 Subject: [PATCH 36/40] fix no-primary-composite --- d2compiler/compile.go | 6 ------ d2compiler/compile_test.go | 15 ++------------- d2ir/compile.go | 6 +++++- .../TestCompile2/vars/errors/bad-var.exp.json | 4 ++++ .../vars/errors/multi-part-map.exp.json | 2 +- .../vars/errors/spread-non-solo.exp.json | 2 +- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index e2c8b71bbd..3c0946bfad 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -281,12 +281,6 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { if f.Map() != nil { if len(f.Map().Edges) > 0 { c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") - } else { - for _, f := range f.Map().Fields { - if f.Primary() == nil && f.Composite == nil { - c.errorf(f.LastRef().AST(), "invalid var with no value") - } - } } } return diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index d716228cf4..b3f189be29 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3797,17 +3797,6 @@ hi: ${z} `, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable "z"`) }, }, - { - name: "bad-var", - run: func(t *testing.T) { - assertCompile(t, ` -vars: { - x -} -hi: ${x} -`, `d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:3:3: invalid var with no value`) - }, - }, { name: "multi-part-map", run: func(t *testing.T) { @@ -3818,7 +3807,7 @@ vars: { } } hi: 1 ${x} -`, `d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute map variable "x" as part of a string`) +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute composite variable "x" as part of a string`) }, }, { @@ -3938,7 +3927,7 @@ z: { d: ...${x} c } -`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute map variable "x" as part of a string`) +`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute composite variable "x" as part of a string`) }, }, } diff --git a/d2ir/compile.go b/d2ir/compile.go index ef88d95a9f..ffa5a96aee 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -188,8 +188,12 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { } } if resolvedField.Primary() == nil { + if resolvedField.Composite == nil { + c.errorf(node.LastRef().AST(), `cannot substitute variable without value: "%s"`, strings.Join(box.Substitution.IDA(), ".")) + return + } if len(s.Value) > 1 { - c.errorf(node.LastRef().AST(), `cannot substitute map variable "%s" as part of a string`, strings.Join(box.Substitution.IDA(), ".")) + c.errorf(node.LastRef().AST(), `cannot substitute composite variable "%s" as part of a string`, strings.Join(box.Substitution.IDA(), ".")) return } switch n := node.(type) { diff --git a/testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json index c079e0f3c7..c740711a72 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json @@ -5,6 +5,10 @@ { "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2,2:2:11-2:3:12", "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:3:3: invalid var with no value" + }, + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2,4:4:23-4:5:24", + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:5:5: invalid var with no value" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json index 70c263dfa6..055c954df2 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json @@ -4,7 +4,7 @@ "errs": [ { "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2,6:0:31-6:2:33", - "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute map variable \"x\" as part of a string" + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute composite variable \"x\" as part of a string" } ] } diff --git a/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json index 296f35954a..3d31fd966e 100644 --- a/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json +++ b/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json @@ -4,7 +4,7 @@ "errs": [ { "range": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2,7:1:36-7:2:37", - "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute map variable \"x\" as part of a string" + "errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute composite variable \"x\" as part of a string" } ] } From f12f9ca69de2546597ff5b066b63b00ff362de16 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 14:34:33 -0700 Subject: [PATCH 37/40] move edge check --- d2compiler/compile.go | 10 +++++----- d2ir/compile.go | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 3c0946bfad..0b7469f9fd 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -278,11 +278,11 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { } return } else if f.Name == "vars" { - if f.Map() != nil { - if len(f.Map().Edges) > 0 { - c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") - } - } + // if f.Map() != nil { + // if len(f.Map().Edges) > 0 { + // c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") + // } + // } return } else if isReserved { c.compileReserved(&obj.Attributes, f) diff --git a/d2ir/compile.go b/d2ir/compile.go index ffa5a96aee..724294e52b 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -523,6 +523,10 @@ func (c *compiler) compileLink(refctx *RefContext) { } func (c *compiler) compileEdges(refctx *RefContext) { + if IsVar(refctx.ScopeMap) { + c.errorf(refctx.Key, "vars cannot contain an edge") + return + } if refctx.Key.Key != nil { f, err := refctx.ScopeMap.EnsureField(refctx.Key.Key, refctx) if err != nil { From e95f61985e78be7d7e3b32b2dc93e4b48391ddbd Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 14:41:06 -0700 Subject: [PATCH 38/40] fix import test --- d2ir/import_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/d2ir/import_test.go b/d2ir/import_test.go index 0b9497abee..76012a33a0 100644 --- a/d2ir/import_test.go +++ b/d2ir/import_test.go @@ -157,7 +157,7 @@ label: meow`, "a.d2": "vars: { x: 2 }; hi: ${x}", }) assert.Success(t, err) - assertQuery(t, m, 0, 0, 2, "hi") + assertQuery(t, m, 0, 0, "2", "hi") }, }, { @@ -168,7 +168,7 @@ label: meow`, "a.d2": "vars: { x: 2 }", }) assert.Success(t, err) - assertQuery(t, m, 0, 0, 1, "hi") + assertQuery(t, m, 0, 0, "1", "hi") }, }, } From d275a4503364e1e9e780c1ab1a18176df4b81c16 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 14:47:32 -0700 Subject: [PATCH 39/40] allow edges in vars --- d2compiler/compile_test.go | 29 +- d2ir/compile.go | 4 - .../vars/basic/spread-edge.exp.json | 356 ++++++++++++++++++ .../d2ir/TestCompile/imports/vars/1.exp.json | 23 +- .../d2ir/TestCompile/imports/vars/2.exp.json | 27 +- .../d2ir/TestCompile/imports/vars/3.exp.json | 27 +- 6 files changed, 391 insertions(+), 75 deletions(-) create mode 100644 testdata/d2compiler/TestCompile2/vars/basic/spread-edge.exp.json diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index b3f189be29..aee82e1456 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -3501,6 +3501,23 @@ custom-disclaimer: DRAFT DISCLAIMER { assert.Equal(t, 2, len(g.Objects)) }, }, + { + name: "spread-edge", + run: func(t *testing.T) { + g := assertCompile(t, ` +vars: { + connections: { + x -> a + } +} +hi: { + ...${connections} +} +`, "") + assert.Equal(t, 3, len(g.Objects)) + assert.Equal(t, 1, len(g.Edges)) + }, + }, } for _, tc := range tca { @@ -3860,17 +3877,7 @@ hi: ${x} `, `d2/testdata/d2compiler/TestCompile2/vars/errors/recursive-var.d2:3:3: could not resolve variable "x"`) }, }, - { - name: "edge", - run: func(t *testing.T) { - assertCompile(t, ` -vars: { - x -> a -} -hi -`, "d2/testdata/d2compiler/TestCompile2/vars/errors/edge.d2:3:3: vars cannot contain an edge") - }, - }, + { name: "spread-non-map", run: func(t *testing.T) { diff --git a/d2ir/compile.go b/d2ir/compile.go index 724294e52b..ffa5a96aee 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -523,10 +523,6 @@ func (c *compiler) compileLink(refctx *RefContext) { } func (c *compiler) compileEdges(refctx *RefContext) { - if IsVar(refctx.ScopeMap) { - c.errorf(refctx.Key, "vars cannot contain an edge") - return - } if refctx.Key.Key != nil { f, err := refctx.ScopeMap.EnsureField(refctx.Key.Key, refctx) if err != nil { diff --git a/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.exp.json new file mode 100644 index 0000000000..7a1960c964 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.exp.json @@ -0,0 +1,356 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,0:0:0-9:0:71", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,1:0:1-5:1:42", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,1:0:1-1:4:5", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,1:0:1-1:4:5", + "value": [ + { + "string": "vars", + "raw_string": "vars" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,1:6:7-5:1:42", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,2:2:11-4:3:40", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,2:2:11-2:13:22", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,2:2:11-2:13:22", + "value": [ + { + "string": "connections", + "raw_string": "connections" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,2:15:24-4:3:40", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:4:30-3:10:36", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:4:30-3:10:36", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:4:30-3:5:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:4:30-3:5:31", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:9:35-3:10:36", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:9:35-3:10:36", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,6:0:43-8:1:70", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,6:0:43-6:2:45", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,6:0:43-6:2:45", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,6:4:47-8:1:70", + "nodes": [ + { + "substitution": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,7:2:51-7:19:68", + "spread": true, + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,7:7:56-7:18:67", + "value": [ + { + "string": "connections", + "raw_string": "connections" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": [ + { + "index": 0, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:4:30-3:5:31", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:4:30-3:5:31", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "x" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:9:35-3:10:36", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,3:9:35-3:10:36", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "a" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "hi", + "id_val": "hi", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,6:0:43-6:2:45", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/spread-edge.d2,6:0:43-6:2:45", + "value": [ + { + "string": "hi", + "raw_string": "hi" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "hi" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2ir/TestCompile/imports/vars/1.exp.json b/testdata/d2ir/TestCompile/imports/vars/1.exp.json index 9d278fd743..cf6fe40f1d 100644 --- a/testdata/d2ir/TestCompile/imports/vars/1.exp.json +++ b/testdata/d2ir/TestCompile/imports/vars/1.exp.json @@ -168,11 +168,10 @@ "name": "q", "primary": { "value": { - "range": "x.d2,0:6:6-0:18:18", + "range": "index.d2,0:20:20-0:21:21", "value": [ { - "string": "var replaced", - "raw_string": "var replaced" + "string": "var replaced" } ] } @@ -230,23 +229,7 @@ "range": "index.d2,0:20:20-0:21:21", "value": [ { - "substitution": { - "range": "index.d2,0:20:20-0:27:27", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "index.d2,0:22:22-0:26:26", - "value": [ - { - "string": "meow", - "raw_string": "meow" - } - ] - } - } - ] - } + "string": "var replaced" } ] } diff --git a/testdata/d2ir/TestCompile/imports/vars/2.exp.json b/testdata/d2ir/TestCompile/imports/vars/2.exp.json index 3107e5c6e7..6a962c22b7 100644 --- a/testdata/d2ir/TestCompile/imports/vars/2.exp.json +++ b/testdata/d2ir/TestCompile/imports/vars/2.exp.json @@ -312,9 +312,12 @@ "name": "hi", "primary": { "value": { - "range": "a.d2,0:11:11-0:12:12", - "raw": "2", - "value": "2" + "range": "a.d2,0:20:20-0:21:21", + "value": [ + { + "string": "2" + } + ] } }, "references": [ @@ -370,23 +373,7 @@ "range": "a.d2,0:20:20-0:21:21", "value": [ { - "substitution": { - "range": "a.d2,0:20:20-0:24:24", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "a.d2,0:22:22-0:23:23", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "2" } ] } diff --git a/testdata/d2ir/TestCompile/imports/vars/3.exp.json b/testdata/d2ir/TestCompile/imports/vars/3.exp.json index e2ddd2094c..5c2b89aad4 100644 --- a/testdata/d2ir/TestCompile/imports/vars/3.exp.json +++ b/testdata/d2ir/TestCompile/imports/vars/3.exp.json @@ -312,9 +312,12 @@ "name": "hi", "primary": { "value": { - "range": "index.d2,0:18:18-0:19:19", - "raw": "1", - "value": "1" + "range": "index.d2,0:27:27-0:28:28", + "value": [ + { + "string": "1" + } + ] } }, "references": [ @@ -370,23 +373,7 @@ "range": "index.d2,0:27:27-0:28:28", "value": [ { - "substitution": { - "range": "index.d2,0:27:27-0:31:31", - "spread": false, - "path": [ - { - "unquoted_string": { - "range": "index.d2,0:29:29-0:30:30", - "value": [ - { - "string": "x", - "raw_string": "x" - } - ] - } - } - ] - } + "string": "1" } ] } From da0d24555d5db78057928b7baa32a291ae3f74ec Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Thu, 13 Jul 2023 15:13:24 -0700 Subject: [PATCH 40/40] rm commented code --- d2compiler/compile.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 0b7469f9fd..600179d40f 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -278,11 +278,6 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { } return } else if f.Name == "vars" { - // if f.Map() != nil { - // if len(f.Map().Edges) > 0 { - // c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge") - // } - // } return } else if isReserved { c.compileReserved(&obj.Attributes, f)