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) diff --git a/d2ast/d2ast.go b/d2ast/d2ast.go index a5be3fa98a..6313dbe0dc 100644 --- a/d2ast/d2ast.go +++ b/d2ast/d2ast.go @@ -502,6 +502,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}}, @@ -513,6 +524,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.go b/d2compiler/compile.go index fdb24e5513..600179d40f 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -277,6 +277,8 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) { } } return + } else if f.Name == "vars" { + return } else if isReserved { c.compileReserved(&obj.Attributes, f) return @@ -329,7 +331,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) } @@ -725,7 +727,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 f0dbaa1bbd..aee82e1456 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,789 @@ 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: "shape-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) + }, + }, + { + 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) + }, + }, + { + name: "combined", + 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: "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) { + 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) + }, + }, + { + 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) { + 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) + }, + }, + { + 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) + }, + }, + { + 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)) + }, + }, + { + 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[2].ID) + assert.Equal(t, 4, len(g.Objects)) + assert.Equal(t, 3, len(g.Objects[2].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]) + }, + }, + { + 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) + }, + }, + { + 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)) + }, + }, + { + 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 { + 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) + }, + }, + { + 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) + }, + }, + { + 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) + }, + }, + { + 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) + }, + }, + { + 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 { + tc := tc + t.Run(tc.name, func(t *testing.T) { + t.Parallel() + if tc.skip { + t.SkipNow() + } + tc.run(t) + }) + } + }) + + 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) + }, + }, + { + 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) { + 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) + }, + }, + { + 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} + } +} +`, "") + assert.Equal(t, 1, len(g.Scenarios[0].Objects)) + assert.Equal(t, "im replaced x var", g.Scenarios[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() + + 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"`) + }, + }, + { + 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 composite 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) { + 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: "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: "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: "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-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`) + }, + }, + { + 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 composite variable "x" as part of a string`) + }, + }, + } + + 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/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 f5d92d043d..ffa5a96aee 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 { @@ -52,14 +53,15 @@ func Compile(ast *d2ast.Map, opts *CompileOptions) (*Map, error) { defer c.popImportStack() c.compileMap(m, ast, ast) - c.compileClasses(m) + c.compileSubstitutions(m, nil) + c.overlayClasses(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 @@ -92,10 +94,181 @@ func (c *compiler) compileClasses(m *Map) { l.Fields = append(l.Fields, base) } - c.compileClasses(l) + c.overlayClasses(l) } } +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) + } + if arr, ok := f.Composite.(*Array); ok { + for _, val := range arr.Values { + if scalar, ok := val.(*Scalar); ok { + c.resolveSubstitutions(varsStack, scalar) + } + } + } 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:]) + } else { + c.compileSubstitutions(f.Map(), varsStack) + } + } + } + for _, e := range m.Edges { + if e.Primary() != nil { + c.resolveSubstitutions(varsStack, e) + } + if e.Map() != nil { + c.compileSubstitutions(e.Map(), varsStack) + } + } +} + +func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) { + var subbed bool + var resolvedField *Field + + switch s := node.Primary().Value.(type) { + case *d2ast.UnquotedString: + for i, box := range s.Value { + if box.Substitution != nil { + 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 + } + } + if resolvedField == nil { + 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-composite") + continue + } + 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 + } + } + } + } + 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 composite 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 { + s.Value[i].String = go2.Pointer(resolvedField.Primary().Value.ScalarString()) + 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() + } + } + } + } + if subbed { + s.Coalesce() + } + case *d2ast.DoubleQuotedString: + for i, box := range s.Value { + if box.Substitution != nil { + for _, vars := range varsStack { + resolvedField = c.resolveSubstitution(vars, box.Substitution) + if resolvedField != nil { + break + } + } + if resolvedField == nil { + c.errorf(node.LastRef().AST(), `could not resolve variable "%s"`, strings.Join(box.Substitution.IDA(), ".")) + return + } + 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 + } + s.Value[i].String = go2.Pointer(resolvedField.Primary().Value.ScalarString()) + subbed = true + } + } + if subbed { + s.Coalesce() + } + } +} + +func (c *compiler) resolveSubstitution(vars *Map, substitution *d2ast.Substitution) *Field { + if vars == nil { + return nil + } + + for i, p := range substitution.Path { + f := vars.GetField(p.Unbox().ScalarString()) + if f == nil { + return nil + } + + if i == len(substitution.Path)-1 { + return f + } + vars = f.Map() + } + return nil +} + 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)) @@ -116,6 +289,17 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { ScopeMap: dst, ScopeAST: scopeAST, }) + case n.Substitution != nil: + // 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 { @@ -135,8 +319,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { } } } - case n.Substitution != nil: - panic("TODO") } } } @@ -151,8 +333,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 !IsVar(dst) { + dst.DeleteField(kp.IDA()...) + return + } } f, err := dst.EnsureField(kp, refctx) if err != nil { @@ -202,7 +388,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) @@ -241,7 +427,7 @@ 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.ScalarBox().Unbox() != nil { @@ -481,7 +667,12 @@ func (c *compiler) compileArray(dst *Array, a *d2ast.Array, scopeAST *d2ast.Map) irv = n } case *d2ast.Substitution: - // panic("TODO") + irv = &Scalar{ + parent: dst, + Value: &d2ast.UnquotedString{ + Value: []d2ast.InterpolationBox{{Substitution: an.Substitution}}, + }, + } } dst.Values = append(dst.Values, irv) 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/d2ir/import_test.go b/d2ir/import_test.go index 38b3a3a2cd..76012a33a0 100644 --- a/d2ir/import_test.go +++ b/d2ir/import_test.go @@ -138,6 +138,39 @@ 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") + }, + }, + { + 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/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/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf index 87b6e616eb..763c539b98 100644 Binary files a/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf and b/e2etests-cli/testdata/TestCLI_E2E/internal_linked_pdf.exp.pdf differ 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/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/combined.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json new file mode 100644 index 0000000000..647ad1d52d --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/combined.exp.json @@ -0,0 +1,177 @@ +{ + "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 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/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 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/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 +} 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..dd4764b6b7 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/double-quoted.exp.json @@ -0,0 +1,177 @@ +{ + "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", + "raw_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 new file mode 100644 index 0000000000..4a85c46033 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge-label.exp.json @@ -0,0 +1,276 @@ +{ + "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": [ + { + "string": "im 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": [ + { + "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-map.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json new file mode 100644 index 0000000000..92d823330f --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/edge-map.exp.json @@ -0,0 +1,334 @@ +{ + "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": [ + { + "string": "im 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": [ + { + "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/edge_label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/edge_label.exp.json new file mode 100644 index 0000000000..b5d58ba790 --- /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": "" + }, + "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 new file mode 100644 index 0000000000..7c20031a34 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/label.exp.json @@ -0,0 +1,193 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/label.d2,4:4:29-4:5:30", + "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" + } + ] + } + } + ] + } + } + ] + } + } + } + } + ] + }, + "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": "" + }, + "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/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/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/nested.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json new file mode 100644 index 0000000000..d32d26e50c --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/nested.exp.json @@ -0,0 +1,279 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/nested.d2,9:14:85-9:15:86", + "value": [ + { + "string": "red" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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..37d67c845d --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/number.exp.json @@ -0,0 +1,273 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/number.d2,5:15:44-5:16:45", + "value": [ + { + "string": "2" + } + ] + } + } + } + }, + { + "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/parent-scope.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json new file mode 100644 index 0000000000..5a3d26c1e0 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/parent-scope.exp.json @@ -0,0 +1,313 @@ +{ + "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": [ + { + "string": "im root 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": "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/basic/primary-and-composite.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json new file mode 100644 index 0000000000..87592f6fcf --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/primary-and-composite.exp.json @@ -0,0 +1,261 @@ +{ + "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": [ + { + "string": "all" + } + ] + } + } + } + } + ] + }, + "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 + } + ] + }, + "err": null +} 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..0ab13c79f3 --- /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..24ca57ef51 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.exp.json @@ -0,0 +1,329 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/quoted-var.d2,12:10:131-12:11:132", + "value": [ + { + "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/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/shape-label.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json new file mode 100644 index 0000000000..29d85cf4e2 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/shape-label.exp.json @@ -0,0 +1,177 @@ +{ + "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": [ + { + "string": "im 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/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/single-quoted.exp.json b/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.exp.json new file mode 100644 index 0000000000..5e1a454562 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/single-quoted.exp.json @@ -0,0 +1,174 @@ +{ + "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", + "raw_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/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/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/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 new file mode 100644 index 0000000000..8789c60c70 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/spread.exp.json @@ -0,0 +1,423 @@ +{ + "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": "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 + }, + { + "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 + } + ] + }, + "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..11ae2fe4d6 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/style.exp.json @@ -0,0 +1,221 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/basic/style.d2,5:14:52-5:15:53", + "value": [ + { + "string": "red" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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 +} 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..0ad0ba9f37 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/basic/sub-array.exp.json @@ -0,0 +1,221 @@ +{ + "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": [ + { + "string": "all" + } + ] + } + } + ] + } + } + } + } + ] + }, + "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/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/boards/layer-2.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json new file mode 100644 index 0000000000..891273336b --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer-2.exp.json @@ -0,0 +1,565 @@ +{ + "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": [ + { + "string": "layer var 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": [ + { + "string": "root var 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": "hi" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer-2.d2,11:8:108-11:9:109", + "value": [ + { + "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,12:11:124-12:12:125", + "value": [ + { + "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 +} 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..80e36aa1ed --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/layer.exp.json @@ -0,0 +1,302 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", + "value": [ + { + "string": "im 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": 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": "hi" + } + ] + } + } + ] + }, + "primary": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/layer.d2,7:8:51-7:9:52", + "value": [ + { + "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 +} 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\"" + } + ] + } +} 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..5f46293b97 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/overlay.exp.json @@ -0,0 +1,997 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,10:7:89-10:8:90", + "value": [ + { + "string": "im x var" + } + ] + } + } + } + }, + { + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,11:7:101-11:8:102", + "value": [ + { + "string": "im y var" + } + ] + } + } + } + } + ] + } + } + } + } + ] + } + } + } + }, + { + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,19:7:173-19:8:174", + "value": [ + { + "string": "im x var" + } + ] + } + } + } + }, + { + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/overlay.d2,20:7:185-20:8:186", + "value": [ + { + "string": "im y 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": 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": "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,19:7:173-19:8:174", + "value": [ + { + "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,20:7:185-20:8:186", + "value": [ + { + "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,10:7:89-10:8:90", + "value": [ + { + "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,11:7:101-11:8:102", + "value": [ + { + "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/replace.exp.json b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json new file mode 100644 index 0000000000..fc75006dd6 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/replace.exp.json @@ -0,0 +1,424 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,0:0:0-13:0:109", + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/replace.d2,10:7:98-10:8:99", + "value": [ + { + "string": "im replaced x 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": 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/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,10:7:98-10:8:99", + "value": [ + { + "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 +} 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..571e94ad86 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/boards/scenario.exp.json @@ -0,0 +1,362 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/boards/scenario.d2,7:8:54-7:9:55", + "value": [ + { + "string": "im 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": 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,7:8:54-7:9:55", + "value": [ + { + "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 +} 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..c740711a72 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json @@ -0,0 +1,15 @@ +{ + "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" + }, + { + "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/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..ca00beed9f --- /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: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-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/missing.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/missing.exp.json new file mode 100644 index 0000000000..c877996889 --- /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: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/multi-part-map.exp.json b/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json new file mode 100644 index 0000000000..055c954df2 --- /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 composite variable \"x\" as part of a string" + } + ] + } +} 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..e105b1ef05 --- /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: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/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\"" + } + ] + } +} 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" + } + ] + } +} 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/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 new file mode 100644 index 0000000000..85b10a3cea --- /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-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..3d31fd966e --- /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 composite variable \"x\" as part of a string" + } + ] + } +} 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..7101e2e4fc --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/label.exp.json @@ -0,0 +1,246 @@ +{ + "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": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/vars/override/label.d2,4:4:29-4:5:30", + "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 +} 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..cd51692583 --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/map.exp.json @@ -0,0 +1,313 @@ +{ + "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": [ + { + "string": "im nested 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": "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/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\"" + } + ] + } +} 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..25f7bf6a0e --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/recursive-var.exp.json @@ -0,0 +1,312 @@ +{ + "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": [ + { + "string": "a-b" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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 +} 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..f6beaba86d --- /dev/null +++ b/testdata/d2compiler/TestCompile2/vars/override/var-in-var.exp.json @@ -0,0 +1,344 @@ +{ + "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": [ + { + "string": "BlackSmith" + } + ] + } + } + } + } + ] + } + } + } + } + ] + }, + "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 +} 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..cf6fe40f1d --- /dev/null +++ b/testdata/d2ir/TestCompile/imports/vars/1.exp.json @@ -0,0 +1,244 @@ +{ + "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" + } + ] + } + } + } + } + } + ] + } + ], + "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" + } + ] + } + } + ] + } + } + ] + } + } + } + } + } + ] + }, + { + "name": "q", + "primary": { + "value": { + "range": "index.d2,0:20:20-0:21:21", + "value": [ + { + "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": { + "unquoted_string": { + "range": "index.d2,0:20:20-0:21:21", + "value": [ + { + "string": "var replaced" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null +} 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..6a962c22b7 --- /dev/null +++ b/testdata/d2ir/TestCompile/imports/vars/2.exp.json @@ -0,0 +1,388 @@ +{ + "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:20:20-0:21:21", + "value": [ + { + "string": "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": [ + { + "string": "2" + } + ] + } + } + } + } + } + ] + } + ], + "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..5c2b89aad4 --- /dev/null +++ b/testdata/d2ir/TestCompile/imports/vars/3.exp.json @@ -0,0 +1,388 @@ +{ + "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:27:27-0:28:28", + "value": [ + { + "string": "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": [ + { + "string": "1" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null +}