fix underscore move
This commit is contained in:
parent
30905b6e62
commit
ba7ef0b661
3 changed files with 276 additions and 3 deletions
|
|
@ -1168,7 +1168,7 @@ func move(g *d2graph.Graph, key, newKey string) (*d2graph.Graph, error) {
|
|||
}
|
||||
|
||||
ida := d2graph.Key(ref.Key)
|
||||
resolvedObj, resolvedIDA, err := d2graph.ResolveUnderscoreKey(ida, obj)
|
||||
resolvedObj, resolvedIDA, err := d2graph.ResolveUnderscoreKey(ida, ref.ScopeObj)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -2087,11 +2087,11 @@ func getMostNestedRefs(obj *d2graph.Object) []d2graph.Reference {
|
|||
if err != nil {
|
||||
mostKey = &d2ast.KeyPath{}
|
||||
}
|
||||
_, resolvedScopeKey, err := d2graph.ResolveUnderscoreKey(d2graph.Key(scopeKey), obj)
|
||||
_, resolvedScopeKey, err := d2graph.ResolveUnderscoreKey(d2graph.Key(scopeKey), ref.ScopeObj)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
_, resolvedMostKey, err := d2graph.ResolveUnderscoreKey(d2graph.Key(mostKey), obj)
|
||||
_, resolvedMostKey, err := d2graph.ResolveUnderscoreKey(d2graph.Key(mostKey), ref.ScopeObj)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2025,6 +2025,24 @@ c: {
|
|||
d
|
||||
b
|
||||
}
|
||||
`,
|
||||
},
|
||||
|
||||
{
|
||||
name: "nested-underscore-move-out",
|
||||
text: `guitar: {
|
||||
books: {
|
||||
_._.pipe
|
||||
}
|
||||
}
|
||||
`,
|
||||
key: `pipe`,
|
||||
newKey: `guitar.pipe`,
|
||||
|
||||
exp: `guitar: {
|
||||
books
|
||||
pipe
|
||||
}
|
||||
`,
|
||||
},
|
||||
{
|
||||
|
|
|
|||
255
testdata/d2oracle/TestMove/nested-underscore-move-out.exp.json
generated
vendored
Normal file
255
testdata/d2oracle/TestMove/nested-underscore-move-out.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
{
|
||||
"graph": {
|
||||
"name": "",
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,0:0:0-4:0:27",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,0:0:0-3:1:26",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,0:0:0-0:6:6",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,0:0:0-0:6:6",
|
||||
"value": [
|
||||
{
|
||||
"string": "guitar",
|
||||
"raw_string": "guitar"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"map": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,0:8:8-3:0:25",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,1:2:12-1:7:17",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,1:2:12-1:7:17",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,1:2:12-1:7:17",
|
||||
"value": [
|
||||
{
|
||||
"string": "books",
|
||||
"raw_string": "books"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,2:2:20-2:6:24",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,2:2:20-2:6:24",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,2:2:20-2:6:24",
|
||||
"value": [
|
||||
{
|
||||
"string": "pipe",
|
||||
"raw_string": "pipe"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "guitar",
|
||||
"id_val": "guitar",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,0:0:0-0:6:6",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,0:0:0-0:6:6",
|
||||
"value": [
|
||||
{
|
||||
"string": "guitar",
|
||||
"raw_string": "guitar"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "guitar"
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "books",
|
||||
"id_val": "books",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,1:2:12-1:7:17",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,1:2:12-1:7:17",
|
||||
"value": [
|
||||
{
|
||||
"string": "books",
|
||||
"raw_string": "books"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "books"
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "pipe",
|
||||
"id_val": "pipe",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,2:2:20-2:6:24",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/nested-underscore-move-out.d2,2:2:20-2:6:24",
|
||||
"value": [
|
||||
{
|
||||
"string": "pipe",
|
||||
"raw_string": "pipe"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "pipe"
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": "<nil>"
|
||||
}
|
||||
Loading…
Reference in a new issue