diff --git a/d2oracle/edit.go b/d2oracle/edit.go index 47c620acd..7b48a4997 100644 --- a/d2oracle/edit.go +++ b/d2oracle/edit.go @@ -1605,7 +1605,7 @@ func move(g *d2graph.Graph, key, newKey string, includeDescendants bool) (*d2gra } appendUniqueMapKey(toScope, detachedMK) - } else if ((!includeDescendants && len(ida) > 1) || (includeDescendants && ref.KeyPathIndex > 0)) && (endsWithReserved || !isExplicit || go2.Contains(mostNestedRefs, ref)) { + } else if len(ida) > 1 && (endsWithReserved || !isExplicit || go2.Contains(mostNestedRefs, ref)) { // 2. Split detachedMK := &d2ast.Key{Key: cloneKey(ref.MapKey.Key)} if includeDescendants { diff --git a/d2oracle/edit_test.go b/d2oracle/edit_test.go index aa689f696..c0314a2e0 100644 --- a/d2oracle/edit_test.go +++ b/d2oracle/edit_test.go @@ -4326,6 +4326,22 @@ b: { d } } +`, + }, + { + name: "include_descendants_underscore_regression", + text: `x: { + _.a +} +a +`, + key: `a`, + newKey: `x.a`, + includeDescendants: true, + + exp: `x: { + a +} `, }, } diff --git a/testdata/d2oracle/TestMove/include_descendants_underscore_regression.exp.json b/testdata/d2oracle/TestMove/include_descendants_underscore_regression.exp.json new file mode 100644 index 000000000..a4876c486 --- /dev/null +++ b/testdata/d2oracle/TestMove/include_descendants_underscore_regression.exp.json @@ -0,0 +1,186 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,0:0:0-3:0:11", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,0:0:0-2:1:10", + "key": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,0:3:3-2:0:9", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,1:2:7-1:3:8", + "key": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,1:2:7-1:3:8", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,1:2:7-1:3:8", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,0:0:0-0:1:1", + "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": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,1:2:7-1:3:8", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestMove/include_descendants_underscore_regression.d2,1:2:7-1:3:8", + "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": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +} diff --git a/testdata/d2oracle/TestMove/underscore_regression.exp.json b/testdata/d2oracle/TestMove/underscore_regression.exp.json new file mode 100644 index 000000000..6b5b44a3a --- /dev/null +++ b/testdata/d2oracle/TestMove/underscore_regression.exp.json @@ -0,0 +1,186 @@ +{ + "graph": { + "name": "", + "isFolderOnly": false, + "ast": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,0:0:0-3:0:11", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,0:0:0-2:1:10", + "key": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,0:0:0-0:1:1", + "value": [ + { + "string": "x", + "raw_string": "x" + } + ] + } + } + ] + }, + "primary": {}, + "value": { + "map": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,0:3:3-2:0:9", + "nodes": [ + { + "map_key": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,1:2:7-1:3:8", + "key": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,1:2:7-1:3:8", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,1:2:7-1:3:8", + "value": [ + { + "string": "a", + "raw_string": "a" + } + ] + } + } + ] + }, + "primary": {}, + "value": {} + } + } + ] + } + } + } + } + ] + }, + "root": { + "id": "", + "id_val": "", + "attributes": { + "label": { + "value": "" + }, + "labelDimensions": { + "width": 0, + "height": 0 + }, + "style": {}, + "near_key": null, + "shape": { + "value": "" + }, + "direction": { + "value": "" + }, + "constraint": { + "value": "" + } + }, + "zIndex": 0 + }, + "edges": null, + "objects": [ + { + "id": "x", + "id_val": "x", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,0:0:0-0:1:1", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,0:0:0-0:1:1", + "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": { + "value": "" + } + }, + "zIndex": 0 + }, + { + "id": "a", + "id_val": "a", + "references": [ + { + "key": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,1:2:7-1:3:8", + "path": [ + { + "unquoted_string": { + "range": "d2/testdata/d2oracle/TestMove/underscore_regression.d2,1:2:7-1:3:8", + "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": { + "value": "" + } + }, + "zIndex": 0 + } + ] + }, + "err": "" +}