diff --git a/d2ir/compile.go b/d2ir/compile.go index 03db8f72f2..b1413840e6 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -344,6 +344,20 @@ func (c *compiler) overlay(base *Map, f *Field) { } func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) { + for _, n := range ast.Nodes { + switch { + case n.MapKey != nil: + ok := c.ampersandFilter(&RefContext{ + Key: n.MapKey, + Scope: ast, + ScopeMap: dst, + ScopeAST: scopeAST, + }) + if !ok { + return + } + } + } for _, n := range ast.Nodes { switch { case n.MapKey != nil: @@ -407,32 +421,57 @@ func (c *compiler) compileField(dst *Map, kp *d2ast.KeyPath, refctx *RefContext) } } -func (c *compiler) _compileField(f *Field, refctx *RefContext) { - if refctx.Key.Ampersand { - f2 := ParentMap(f).Map().GetField(refctx.Key.Key.IDA()...) - if f2 == nil { - return +func (c *compiler) ampersandFilter(refctx *RefContext) bool { + if !refctx.Key.Ampersand { + return true + } + if len(refctx.Key.Edges) > 0 { + return true + } + + fa, err := refctx.ScopeMap.EnsureField(refctx.Key.Key, refctx, false) + if err != nil { + c.err.Errors = append(c.err.Errors, err.(d2ast.Error)) + return false + } + if len(fa) == 0 { + return false + } + for _, f := range fa { + ok := c._ampersandFilter(f, refctx) + if !ok { + return false } - if refctx.Key.Primary.Unbox() != nil { - if f2.Primary_ == nil { - return - } - if refctx.Key.Primary.Unbox().ScalarString() != f2.Primary_.Value.ScalarString() { - return - } + } + return true +} + +func (c *compiler) _ampersandFilter(f *Field, refctx *RefContext) bool { + f2 := ParentMap(f).Map().GetField(refctx.Key.Key.IDA()...) + if f2 == nil { + return false + } + if refctx.Key.Primary.Unbox() != nil { + if f2.Primary_ == nil { + return false } - if refctx.Key.Value.ScalarBox().Unbox() != nil { - if f2.Primary_ == nil { - return - } - if refctx.Key.Value.ScalarBox().Unbox().ScalarString() != f2.Primary_.Value.ScalarString() { - println(refctx.Key.Value.ScalarBox().Unbox().ScalarString()) - println(f2.Primary_.Value.ScalarString()) - return - } + if refctx.Key.Primary.Unbox().ScalarString() != f2.Primary_.Value.ScalarString() { + return false } } + if refctx.Key.Value.ScalarBox().Unbox() != nil { + if f2.Primary_ == nil { + return false + } + if refctx.Key.Value.ScalarBox().Unbox().ScalarString() != f2.Primary_.Value.ScalarString() { + return false + } + } + + return true +} +func (c *compiler) _compileField(f *Field, refctx *RefContext) { if len(refctx.Key.Edges) == 0 && refctx.Key.Value.Null != nil { // For vars, if we delete the field, it may just resolve to an outer scope var of the same name // Instead we keep it around, so that resolveSubstitutions can find it diff --git a/d2ir/filter_test.go b/d2ir/filter_test.go index 9ba4c3559d..fa9d807610 100644 --- a/d2ir/filter_test.go +++ b/d2ir/filter_test.go @@ -11,7 +11,7 @@ func testCompileFilters(t *testing.T) { tca := []testCase{ { - name: "escaped", + name: "base", run: func(t testing.TB) { m, err := compile(t, `jacob: { shape: circle @@ -24,9 +24,27 @@ jeremy: { label: I'm a rectangle }`) assert.Success(t, err) - t.Log(m.String()) assertQuery(t, m, 1, 0, nil, "jacob") - assertQuery(t, m, 2, 0, "", "jeremy") + assertQuery(t, m, 2, 0, nil, "jeremy") + assertQuery(t, m, 0, 0, "I'm a rectangle", "jeremy.label") + }, + }, + { + name: "order", + run: func(t testing.TB) { + m, err := compile(t, `jacob: { + shape: circle +} +jeremy: { + shape: rectangle +} +*: { + label: I'm a rectangle + &shape: rectangle +}`) + assert.Success(t, err) + assertQuery(t, m, 1, 0, nil, "jacob") + assertQuery(t, m, 2, 0, nil, "jeremy") assertQuery(t, m, 0, 0, "I'm a rectangle", "jeremy.label") }, }, diff --git a/testdata/d2ir/TestCompile/filters/base#01.exp.json b/testdata/d2ir/TestCompile/filters/base#01.exp.json new file mode 100644 index 0000000000..0521ab4f35 --- /dev/null +++ b/testdata/d2ir/TestCompile/filters/base#01.exp.json @@ -0,0 +1,560 @@ +{ + "fields": [ + { + "name": "jacob", + "composite": { + "fields": [ + { + "name": "shape", + "primary": { + "value": { + "range": "TestCompile/filters/base#01.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:14:23", + "key": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + }, + { + "string": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base#01.d2,7:1:62-7:18:79", + "ampersand": true, + "key": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,7:9:70-7:18:79", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base#01.d2,0:0:0-2:1:25", + "key": { + "range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "TestCompile/filters/base#01.d2,0:7:7-2:1:25", + "nodes": [ + { + "map_key": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:14:23", + "key": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + ] + } + } + } + } + } + ] + }, + { + "name": "jeremy", + "composite": { + "fields": [ + { + "name": "shape", + "primary": { + "value": { + "range": "TestCompile/filters/base#01.d2,7:9:70-7:18:79", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:17:53", + "key": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,4:8:44-4:17:53", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + }, + { + "string": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base#01.d2,7:1:62-7:18:79", + "ampersand": true, + "key": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,7:9:70-7:18:79", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + } + ] + }, + { + "name": "label", + "primary": { + "value": { + "range": "TestCompile/filters/base#01.d2,8:8:88-8:23:103", + "value": [ + { + "string": "I'm a rectangle", + "raw_string": "I'm a rectangle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base#01.d2,8:1:81-8:23:103", + "key": { + "range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,8:1:81-8:6:86", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,8:8:88-8:23:103", + "value": [ + { + "string": "I'm a rectangle", + "raw_string": "I'm a rectangle" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base#01.d2,3:0:26-5:1:55", + "key": { + "range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "TestCompile/filters/base#01.d2,3:8:34-5:1:55", + "nodes": [ + { + "map_key": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:17:53", + "key": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base#01.d2,4:8:44-4:17:53", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + ] + } + } + } + } + } + ] + } + ], + "edges": null +} diff --git a/testdata/d2ir/TestCompile/filters/base.exp.json b/testdata/d2ir/TestCompile/filters/base.exp.json new file mode 100644 index 0000000000..7e7ac04810 --- /dev/null +++ b/testdata/d2ir/TestCompile/filters/base.exp.json @@ -0,0 +1,622 @@ +{ + "fields": [ + { + "name": "jacob", + "composite": { + "fields": [ + { + "name": "shape", + "primary": { + "value": { + "range": "TestCompile/filters/base.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base.d2,1:1:10-1:14:23", + "key": { + "range": "TestCompile/filters/base.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + }, + { + "string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base.d2,7:1:62-7:18:79", + "ampersand": true, + "key": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:9:70-7:18:79", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base.d2,0:0:0-0:5:5", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base.d2,0:0:0-2:1:25", + "key": { + "range": "TestCompile/filters/base.d2,0:0:0-0:5:5", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "TestCompile/filters/base.d2,0:7:7-2:1:25", + "nodes": [ + { + "map_key": { + "range": "TestCompile/filters/base.d2,1:1:10-1:14:23", + "key": { + "range": "TestCompile/filters/base.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + ] + } + } + } + } + } + ] + }, + { + "name": "jeremy", + "composite": { + "fields": [ + { + "name": "shape", + "primary": { + "value": { + "range": "TestCompile/filters/base.d2,7:9:70-7:18:79", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base.d2,4:1:37-4:17:53", + "key": { + "range": "TestCompile/filters/base.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,4:8:44-4:17:53", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + }, + { + "string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base.d2,7:1:62-7:18:79", + "ampersand": true, + "key": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:9:70-7:18:79", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + }, + { + "string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base.d2,7:1:62-7:18:79", + "ampersand": true, + "key": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:2:63-7:7:68", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,7:9:70-7:18:79", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + } + ] + }, + { + "name": "label", + "primary": { + "value": { + "range": "TestCompile/filters/base.d2,8:8:88-8:23:103", + "value": [ + { + "string": "I'm a rectangle", + "raw_string": "I'm a rectangle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base.d2,8:1:81-8:6:86", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base.d2,8:1:81-8:6:86", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,8:1:81-8:6:86", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base.d2,8:1:81-8:23:103", + "key": { + "range": "TestCompile/filters/base.d2,8:1:81-8:6:86", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,8:1:81-8:6:86", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,8:8:88-8:23:103", + "value": [ + { + "string": "I'm a rectangle", + "raw_string": "I'm a rectangle" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/base.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/base.d2,3:0:26-3:6:32", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/base.d2,3:0:26-5:1:55", + "key": { + "range": "TestCompile/filters/base.d2,3:0:26-3:6:32", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "TestCompile/filters/base.d2,3:8:34-5:1:55", + "nodes": [ + { + "map_key": { + "range": "TestCompile/filters/base.d2,4:1:37-4:17:53", + "key": { + "range": "TestCompile/filters/base.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/base.d2,4:8:44-4:17:53", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + ] + } + } + } + } + } + ] + } + ], + "edges": null +} diff --git a/testdata/d2ir/TestCompile/filters/escaped.exp.json b/testdata/d2ir/TestCompile/filters/escaped.exp.json index 6553327a5b..c6257902d2 100644 --- a/testdata/d2ir/TestCompile/filters/escaped.exp.json +++ b/testdata/d2ir/TestCompile/filters/escaped.exp.json @@ -142,83 +142,6 @@ } } ] - }, - { - "name": "label", - "primary": { - "value": { - "range": "TestCompile/filters/escaped.d2,8:8:88-8:23:103", - "value": [ - { - "string": "I'm a rectangle", - "raw_string": "I'm a rectangle" - } - ] - } - }, - "references": [ - { - "string": { - "range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86", - "value": [ - { - "string": "label", - "raw_string": "label" - } - ] - }, - "key_path": { - "range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86", - "path": [ - { - "unquoted_string": { - "range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86", - "value": [ - { - "string": "label", - "raw_string": "label" - } - ] - } - } - ] - }, - "context": { - "edge": null, - "key": { - "range": "TestCompile/filters/escaped.d2,8:1:81-8:23:103", - "key": { - "range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86", - "path": [ - { - "unquoted_string": { - "range": "TestCompile/filters/escaped.d2,8:1:81-8:6:86", - "value": [ - { - "string": "label", - "raw_string": "label" - } - ] - } - } - ] - }, - "primary": {}, - "value": { - "unquoted_string": { - "range": "TestCompile/filters/escaped.d2,8:8:88-8:23:103", - "value": [ - { - "string": "I'm a rectangle", - "raw_string": "I'm a rectangle" - } - ] - } - } - } - } - } - ] } ], "edges": null diff --git a/testdata/d2ir/TestCompile/filters/order.exp.json b/testdata/d2ir/TestCompile/filters/order.exp.json new file mode 100644 index 0000000000..68d9f7314f --- /dev/null +++ b/testdata/d2ir/TestCompile/filters/order.exp.json @@ -0,0 +1,622 @@ +{ + "fields": [ + { + "name": "jacob", + "composite": { + "fields": [ + { + "name": "shape", + "primary": { + "value": { + "range": "TestCompile/filters/order.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/order.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/order.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/order.d2,1:1:10-1:14:23", + "key": { + "range": "TestCompile/filters/order.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + }, + { + "string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/order.d2,8:1:86-8:18:103", + "ampersand": true, + "key": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:9:94-8:18:103", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/order.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/order.d2,0:0:0-0:5:5", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/order.d2,0:0:0-2:1:25", + "key": { + "range": "TestCompile/filters/order.d2,0:0:0-0:5:5", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,0:0:0-0:5:5", + "value": [ + { + "string": "jacob", + "raw_string": "jacob" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "TestCompile/filters/order.d2,0:7:7-2:1:25", + "nodes": [ + { + "map_key": { + "range": "TestCompile/filters/order.d2,1:1:10-1:14:23", + "key": { + "range": "TestCompile/filters/order.d2,1:1:10-1:6:15", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,1:1:10-1:6:15", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,1:8:17-1:14:23", + "value": [ + { + "string": "circle", + "raw_string": "circle" + } + ] + } + } + } + } + ] + } + } + } + } + } + ] + }, + { + "name": "jeremy", + "composite": { + "fields": [ + { + "name": "shape", + "primary": { + "value": { + "range": "TestCompile/filters/order.d2,8:9:94-8:18:103", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/order.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/order.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/order.d2,4:1:37-4:17:53", + "key": { + "range": "TestCompile/filters/order.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,4:8:44-4:17:53", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + }, + { + "string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/order.d2,8:1:86-8:18:103", + "ampersand": true, + "key": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:9:94-8:18:103", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + }, + { + "string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/order.d2,8:1:86-8:18:103", + "ampersand": true, + "key": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:2:87-8:7:92", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,8:9:94-8:18:103", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + } + ] + }, + { + "name": "label", + "primary": { + "value": { + "range": "TestCompile/filters/order.d2,7:8:69-7:23:84", + "value": [ + { + "string": "I'm a rectangle", + "raw_string": "I'm a rectangle" + } + ] + } + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/order.d2,7:1:62-7:6:67", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/order.d2,7:1:62-7:6:67", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,7:1:62-7:6:67", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/order.d2,7:1:62-7:23:84", + "key": { + "range": "TestCompile/filters/order.d2,7:1:62-7:6:67", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,7:1:62-7:6:67", + "value": [ + { + "string": "label", + "raw_string": "label" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,7:8:69-7:23:84", + "value": [ + { + "string": "I'm a rectangle", + "raw_string": "I'm a rectangle" + } + ] + } + } + } + } + } + ] + } + ], + "edges": null + }, + "references": [ + { + "string": { + "range": "TestCompile/filters/order.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + }, + "key_path": { + "range": "TestCompile/filters/order.d2,3:0:26-3:6:32", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + } + } + ] + }, + "context": { + "edge": null, + "key": { + "range": "TestCompile/filters/order.d2,3:0:26-5:1:55", + "key": { + "range": "TestCompile/filters/order.d2,3:0:26-3:6:32", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,3:0:26-3:6:32", + "value": [ + { + "string": "jeremy", + "raw_string": "jeremy" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "TestCompile/filters/order.d2,3:8:34-5:1:55", + "nodes": [ + { + "map_key": { + "range": "TestCompile/filters/order.d2,4:1:37-4:17:53", + "key": { + "range": "TestCompile/filters/order.d2,4:1:37-4:6:42", + "path": [ + { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,4:1:37-4:6:42", + "value": [ + { + "string": "shape", + "raw_string": "shape" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "TestCompile/filters/order.d2,4:8:44-4:17:53", + "value": [ + { + "string": "rectangle", + "raw_string": "rectangle" + } + ] + } + } + } + } + ] + } + } + } + } + } + ] + } + ], + "edges": null +}