diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 14069f10c..4a04e7e04 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -17,8 +17,10 @@ - Support `validate` command. [#2415](https://github.com/terrastruct/d2/pull/2415) - Watch mode ignores backup files (e.g. files created by certain editors like Helix). [#2131](https://github.com/terrastruct/d2/issues/2131) - Support for `--omit-version` flag. [#2377](https://github.com/terrastruct/d2/issues/2377) + - Casing is ignored for plugin names [#2486](https://github.com/terrastruct/d2/pull/2486) - Compiler: - `link`s can be set to root path, e.g. `/xyz`. [#2357](https://github.com/terrastruct/d2/issues/2357) + - When importing a file, attempt resolving substitutions at the imported file scope first [#2482](https://github.com/terrastruct/d2/pull/2482) - Parser: - impose max key length. It's almost certainly a mistake if an ID gets too long, e.g. missing quotes [#2465](https://github.com/terrastruct/d2/pull/2465) - Render: @@ -35,6 +37,7 @@ - fixes globs not applying to spread substitutions [#2426](https://github.com/terrastruct/d2/issues/2426) - fixes panic when classes were mixed with layers incorrectly [#2448](https://github.com/terrastruct/d2/pull/2448) - fixes panic when gradient colors are used in sketch mode [#2481](https://github.com/terrastruct/d2/pull/2487) + - fixes panic using glob ampersand filters with composite values [#2489](https://github.com/terrastruct/d2/pull/2489) - Formatter: - fixes substitutions in quotes surrounded by text [#2462](https://github.com/terrastruct/d2/pull/2462) - CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370) diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 5a56d1e89..702295099 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -1714,6 +1714,41 @@ steps: { assert.Equal(t, 1, len(g.Layers[0].Steps)) }, }, + { + name: "composite-glob-filter", + + text: ` +*: { + &shape: [a; b] +} +k +`, + expErr: `d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites +d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites`, + }, + { + name: "import-nested-var", + + text: `...@models.environment +`, + files: map[string]string{ + "models.d2": ` +vars: { + c: { + k + } +} + +environment: { + ...${c} +} +`, + }, + assertions: func(t *testing.T, g *d2graph.Graph) { + assert.Equal(t, 1, len(g.Objects)) + assert.Equal(t, "k", g.Objects[0].AbsID()) + }, + }, { name: "import-connections", @@ -5653,7 +5688,18 @@ d: { &level: 1 style.stroke: yellow } +(** -> **)[*]: { + &src.level: 0 + &dst.level: 0 + style.stroke: blue +} a.b.c + +x -> y +a: { + 1 -> 2 +} +a.1 -> x `, ``) assert.Equal(t, "a", g.Objects[0].ID) assert.Equal(t, "red", g.Objects[0].Attributes.Style.Fill.Value) @@ -5666,6 +5712,15 @@ a.b.c assert.Equal(t, "c", g.Objects[2].ID) assert.Equal(t, (*d2graph.Scalar)(nil), g.Objects[2].Attributes.Style.Fill) assert.Equal(t, (*d2graph.Scalar)(nil), g.Objects[2].Attributes.Style.Stroke) + + assert.Equal(t, "(x -> y)[0]", g.Edges[0].AbsID()) + assert.Equal(t, "blue", g.Edges[0].Attributes.Style.Stroke.Value) + + assert.Equal(t, "a.(1 -> 2)[0]", g.Edges[1].AbsID()) + assert.Equal(t, (*d2graph.Scalar)(nil), g.Edges[1].Attributes.Style.Stroke) + + assert.Equal(t, "(a.1 -> x)[0]", g.Edges[2].AbsID()) + assert.Equal(t, (*d2graph.Scalar)(nil), g.Edges[2].Attributes.Style.Stroke) }, }, { diff --git a/d2ir/compile.go b/d2ir/compile.go index 47031ddfe..91c0739e8 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -755,6 +755,13 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool { return false } + secondPart := keyPath.Path[1].Unbox().ScalarString() + value := refctx.Key.Value.ScalarBox().Unbox().ScalarString() + + if len(keyPath.Path) == 2 && c._ampersandPropertyFilter(secondPart, value, node, refctx.Key) { + return true + } + propKeyPath := &d2ast.KeyPath{ Path: keyPath.Path[1:], } @@ -789,7 +796,7 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool { return false } if len(fa) == 0 { - if refctx.Key.Value.ScalarBox().Unbox().ScalarString() == "*" { + if refctx.Key.Value.ScalarBox().Unbox() != nil && refctx.Key.Value.ScalarBox().Unbox().ScalarString() == "*" { return false } // The field/edge has no value for this filter @@ -840,53 +847,7 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool { }, } return c._ampersandFilter(f, refctx) - case "leaf": - raw := refctx.Key.Value.ScalarBox().Unbox().ScalarString() - boolVal, err := strconv.ParseBool(raw) - if err != nil { - c.errorf(refctx.Key, `&leaf must be "true" or "false", got %q`, raw) - return false - } - f := refctx.ScopeMap.Parent().(*Field) - isLeaf := f.Map() == nil || !f.Map().IsContainer() - return isLeaf == boolVal - case "level": - raw := refctx.Key.Value.ScalarBox().Unbox().ScalarString() - levelVal, err := strconv.Atoi(raw) - if err != nil { - c.errorf(refctx.Key, `&level must be a non-negative integer, got %q`, raw) - return false - } - if levelVal < 0 { - c.errorf(refctx.Key, `&level must be a non-negative integer, got %d`, levelVal) - return false - } - - f := refctx.ScopeMap.Parent().(*Field) - level := 0 - parent := ParentField(f) - for parent != nil && parent.Name.ScalarString() != "root" && NodeBoardKind(parent) == "" { - level++ - parent = ParentField(parent) - } - return level == levelVal - case "connected": - raw := refctx.Key.Value.ScalarBox().Unbox().ScalarString() - boolVal, err := strconv.ParseBool(raw) - if err != nil { - c.errorf(refctx.Key, `&connected must be "true" or "false", got %q`, raw) - return false - } - f := refctx.ScopeMap.Parent().(*Field) - isConnected := false - for _, r := range f.References { - if r.InEdge() { - isConnected = true - break - } - } - return isConnected == boolVal case "label": f := &Field{} n := refctx.ScopeMap.Parent() @@ -978,7 +939,10 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool { return dstPath == filterValue default: - return false + f := refctx.ScopeMap.Parent().(*Field) + propName := refctx.Key.Key.Last().ScalarString() + value := refctx.Key.Value.ScalarBox().Unbox().ScalarString() + return c._ampersandPropertyFilter(propName, value, f, refctx.Key) } } for _, f := range fa { @@ -990,6 +954,70 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool { return true } +// handles filters that are not based on fields +func (c *compiler) _ampersandPropertyFilter(propName string, value string, node *Field, key *d2ast.Key) bool { + switch propName { + case "level": + levelVal, err := strconv.Atoi(value) + if err != nil { + c.errorf(key, `&level must be a non-negative integer, got %q`, value) + return false + } + if levelVal < 0 { + c.errorf(key, `&level must be a non-negative integer, got %d`, levelVal) + return false + } + + level := 0 + parent := ParentField(node) + for parent != nil && parent.Name.ScalarString() != "root" && NodeBoardKind(parent) == "" { + level++ + parent = ParentField(parent) + } + return level == levelVal + case "leaf": + boolVal, err := strconv.ParseBool(value) + if err != nil { + c.errorf(key, `&leaf must be "true" or "false", got %q`, value) + return false + } + isLeaf := node.Map() == nil || !node.Map().IsContainer() + return isLeaf == boolVal + case "connected": + boolVal, err := strconv.ParseBool(value) + if err != nil { + c.errorf(key, `&connected must be "true" or "false", got %q`, value) + return false + } + isConnected := false + for _, r := range node.References { + if r.InEdge() { + isConnected = true + break + } + } + return isConnected == boolVal + case "label": + f := &Field{} + if node.Primary() == nil { + f.Primary_ = &Scalar{ + Value: node.Name, + } + } else { + f.Primary_ = node.Primary() + } + propKey := &d2ast.Key{ + Key: key.Key, + Value: key.Value, + } + propRefCtx := &RefContext{ + Key: propKey, + } + return c._ampersandFilter(f, propRefCtx) + } + return false +} + func (c *compiler) _ampersandFilter(f *Field, refctx *RefContext) bool { if refctx.Key.Value.ScalarBox().Unbox() == nil { c.errorf(refctx.Key, "glob filters cannot be composites") diff --git a/d2ir/import.go b/d2ir/import.go index 6f593c5c7..2d6630203 100644 --- a/d2ir/import.go +++ b/d2ir/import.go @@ -111,6 +111,14 @@ func (c *compiler) __import(imp *d2ast.Import) (*Map, bool) { c.compileMap(ir, ast, ast) + // We attempt to resolve variables in the imported file scope first + // But ignore errors, in case the variable is meant to be resolved at the + // importer + savedErrors := make([]d2ast.Error, len(c.err.Errors)) + copy(savedErrors, c.err.Errors) + c.compileSubstitutions(ir, nil) + c.err.Errors = savedErrors + c.seenImports[impPath] = struct{}{} return ir, true diff --git a/d2plugin/plugin.go b/d2plugin/plugin.go index 6708e5e03..fdf2ec25f 100644 --- a/d2plugin/plugin.go +++ b/d2plugin/plugin.go @@ -9,6 +9,7 @@ import ( "context" "encoding/json" "os/exec" + "strings" "oss.terrastruct.com/util-go/xexec" "oss.terrastruct.com/util-go/xmain" @@ -170,7 +171,7 @@ func FindPlugin(ctx context.Context, ps []Plugin, name string) (Plugin, error) { if err != nil { return nil, err } - if info.Name == name { + if strings.EqualFold(info.Name, name) { return p, nil } } diff --git a/testdata/d2compiler/TestCompile/composite-glob-filter.exp.json b/testdata/d2compiler/TestCompile/composite-glob-filter.exp.json new file mode 100644 index 000000000..f7cc9c42a --- /dev/null +++ b/testdata/d2compiler/TestCompile/composite-glob-filter.exp.json @@ -0,0 +1,15 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2,2:2:8-2:16:22", + "errmsg": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites" + }, + { + "range": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2,2:2:8-2:16:22", + "errmsg": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites" + } + ] + } +} diff --git a/testdata/d2compiler/TestCompile/import-nested-var.exp.json b/testdata/d2compiler/TestCompile/import-nested-var.exp.json new file mode 100644 index 000000000..a2ec401d7 --- /dev/null +++ b/testdata/d2compiler/TestCompile/import-nested-var.exp.json @@ -0,0 +1,116 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-1:0:23", + "nodes": [ + { + "import": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:0:0-0:22:22", + "spread": true, + "pre": "", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:4:4-0:10:10", + "value": [ + { + "string": "models", + "raw_string": "models" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/import-nested-var.d2,0:11:11-0:22:22", + "value": [ + { + "string": "environment", + "raw_string": "environment" + } + ] + } + } + ] + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "k", + "id_val": "k", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile/models.d2,3:4:20-3:5:21", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile/models.d2,3:4:20-3:5:21", + "value": [ + { + "string": "k", + "raw_string": "k" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + } + ], + "attributes": { + "label": { + "value": "k" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ] + }, + "err": null +} diff --git a/testdata/d2compiler/TestCompile2/globs/level-filter.exp.json b/testdata/d2compiler/TestCompile2/globs/level-filter.exp.json index 6f03fe650..acec6846c 100644 --- a/testdata/d2compiler/TestCompile2/globs/level-filter.exp.json +++ b/testdata/d2compiler/TestCompile2/globs/level-filter.exp.json @@ -3,7 +3,7 @@ "name": "", "isFolderOnly": false, "ast": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,0:0:0-10:0:88", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,0:0:0-21:0:193", "nodes": [ { "map_key": { @@ -223,13 +223,206 @@ }, { "map_key": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-13:1:153", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:1:83-9:9:91", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:1:83-9:3:85", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:1:83-9:3:85", + "value": [ + { + "string": "**", + "raw_string": "**" + } + ], + "pattern": [ + "*", + "", + "*" + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:7:89-9:9:91", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:7:89-9:9:91", + "value": [ + { + "string": "**", + "raw_string": "**" + } + ], + "pattern": [ + "*", + "", + "*" + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "edge_index": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:10:92-9:13:95", + "int": null, + "glob": true + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:15:97-13:1:153", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,10:2:101-10:15:114", + "ampersand": true, + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,10:3:102-10:12:111", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,10:3:102-10:6:105", + "value": [ + { + "string": "src", + "raw_string": "src" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,10:7:106-10:12:111", + "value": [ + { + "string": "level", + "raw_string": "level" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,10:14:113-10:15:114", + "raw": "0", + "value": "0" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,11:2:117-11:15:130", + "ampersand": true, + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,11:3:118-11:12:127", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,11:3:118-11:6:121", + "value": [ + { + "string": "dst", + "raw_string": "dst" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,11:7:122-11:12:127", + "value": [ + { + "string": "level", + "raw_string": "level" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "number": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,11:14:129-11:15:130", + "raw": "0", + "value": "0" + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,12:2:133-12:20:151", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,12:2:133-12:14:145", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,12:2:133-12:7:138", + "value": [ + { + "string": "style", + "raw_string": "style" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,12:8:139-12:14:145", + "value": [ + { + "string": "stroke", + "raw_string": "stroke" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,12:16:147-12:20:151", + "value": [ + { + "string": "blue", + "raw_string": "blue" + } + ] + } + } + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:5:159", "key": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:5:159", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:1:83", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:1:155", "value": [ { "string": "a", @@ -240,7 +433,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:2:84-9:3:85", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:2:156-14:3:157", "value": [ { "string": "b", @@ -251,7 +444,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:4:86-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:4:158-14:5:159", "value": [ { "string": "c", @@ -265,6 +458,184 @@ "primary": {}, "value": {} } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:0:161-16:6:167", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:0:161-16:6:167", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:0:161-16:1:162", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:0:161-16:1:162", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:5:166-16:6:167", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:5:166-16:6:167", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,17:0:168-19:1:183", + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,17:0:168-17:1:169", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,17:0:168-17:1:169", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,17:3:171-19:1:183", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:2:175-18:8:181", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:2:175-18:8:181", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:2:175-18:3:176", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:2:175-18:3:176", + "value": [ + { + "string": "1", + "raw_string": "1" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:7:180-18:8:181", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:7:180-18:8:181", + "value": [ + { + "string": "2", + "raw_string": "2" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } + } + ] + } + } + } + }, + { + "map_key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:0:184-20:8:192", + "edges": [ + { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:0:184-20:8:192", + "src": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:0:184-20:3:187", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:0:184-20:1:185", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:2:186-20:3:187", + "value": [ + { + "string": "1", + "raw_string": "1" + } + ] + } + } + ] + }, + "src_arrow": "", + "dst": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:7:191-20:8:192", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:7:191-20:8:192", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "dst_arrow": ">" + } + ], + "primary": {}, + "value": {} + } } ] }, @@ -292,7 +663,108 @@ }, "zIndex": 0 }, - "edges": null, + "edges": [ + { + "index": 0, + "isCurve": false, + "src_arrow": false, + "dst_arrow": true, + "references": [ + { + "map_key_edge_index": 0 + }, + { + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "stroke": { + "value": "blue" + } + }, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "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": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "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": {}, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + } + ], "objects": [ { "id": "a", @@ -300,11 +772,11 @@ "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:5:159", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:1:83", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:1:155", "value": [ { "string": "a", @@ -315,7 +787,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:2:84-9:3:85", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:2:156-14:3:157", "value": [ { "string": "b", @@ -326,7 +798,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:4:86-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:4:158-14:5:159", "value": [ { "string": "c", @@ -339,6 +811,57 @@ }, "key_path_index": 0, "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,17:0:168-17:1:169", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,17:0:168-17:1:169", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": -1 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:0:184-20:3:187", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:0:184-20:1:185", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:2:186-20:3:187", + "value": [ + { + "string": "1", + "raw_string": "1" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 } ], "attributes": { @@ -372,11 +895,11 @@ "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:5:159", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:1:83", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:1:155", "value": [ { "string": "a", @@ -387,7 +910,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:2:84-9:3:85", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:2:156-14:3:157", "value": [ { "string": "b", @@ -398,7 +921,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:4:86-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:4:158-14:5:159", "value": [ { "string": "c", @@ -444,11 +967,11 @@ "references": [ { "key": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:5:159", "path": [ { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:0:82-9:1:83", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:0:154-14:1:155", "value": [ { "string": "a", @@ -459,7 +982,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:2:84-9:3:85", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:2:156-14:3:157", "value": [ { "string": "b", @@ -470,7 +993,7 @@ }, { "unquoted_string": { - "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,9:4:86-9:5:87", + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,14:4:158-14:5:159", "value": [ { "string": "c", @@ -505,6 +1028,257 @@ "constraint": null }, "zIndex": 0 + }, + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:0:161-16:1:162", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:0:161-16:1:162", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:7:191-20:8:192", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:7:191-20:8:192", + "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": { + "fill": { + "value": "red" + } + }, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "y", + "id_val": "y", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:5:166-16:6:167", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,16:5:166-16:6:167", + "value": [ + { + "string": "y", + "raw_string": "y" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "y" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "fill": { + "value": "red" + } + }, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "1", + "id_val": "1", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:2:175-18:3:176", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:2:175-18:3:176", + "value": [ + { + "string": "1", + "raw_string": "1" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + }, + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:0:184-20:3:187", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:0:184-20:1:185", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + }, + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,20:2:186-20:3:187", + "value": [ + { + "string": "1", + "raw_string": "1" + } + ] + } + } + ] + }, + "key_path_index": 1, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "1" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "stroke": { + "value": "yellow" + } + }, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 + }, + { + "id": "2", + "id_val": "2", + "references": [ + { + "key": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:7:180-18:8:181", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2compiler/TestCompile2/globs/level-filter.d2,18:7:180-18:8:181", + "value": [ + { + "string": "2", + "raw_string": "2" + } + ] + } + } + ] + }, + "key_path_index": 0, + "map_key_edge_index": 0 + } + ], + "attributes": { + "label": { + "value": "2" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": { + "stroke": { + "value": "yellow" + } + }, + "iconStyle": {}, + "near_key": null, + "shape": { + "value": "rectangle" + }, + "direction": { + "value": "" + }, + "constraint": null + }, + "zIndex": 0 } ] },