remove primary
This commit is contained in:
parent
7fd7003f77
commit
ea60464d6c
4 changed files with 296 additions and 0 deletions
|
|
@ -909,6 +909,9 @@ func deleteObject(g *d2graph.Graph, key *d2ast.KeyPath, obj *d2graph.Object) (*d
|
||||||
|
|
||||||
if len(ref.MapKey.Edges) == 0 {
|
if len(ref.MapKey.Edges) == 0 {
|
||||||
isSuffix := ref.KeyPathIndex == len(ref.Key.Path)-1
|
isSuffix := ref.KeyPathIndex == len(ref.Key.Path)-1
|
||||||
|
if isSuffix && ref.MapKey != nil {
|
||||||
|
ref.MapKey.Primary = d2ast.ScalarBox{}
|
||||||
|
}
|
||||||
ref.Key.Path = append(ref.Key.Path[:ref.KeyPathIndex], ref.Key.Path[ref.KeyPathIndex+1:]...)
|
ref.Key.Path = append(ref.Key.Path[:ref.KeyPathIndex], ref.Key.Path[ref.KeyPathIndex+1:]...)
|
||||||
withoutSpecial := go2.Filter(ref.Key.Path, func(x *d2ast.StringBox) bool {
|
withoutSpecial := go2.Filter(ref.Key.Path, func(x *d2ast.StringBox) bool {
|
||||||
_, isReserved := d2graph.ReservedKeywords[x.Unbox().ScalarString()]
|
_, isReserved := d2graph.ReservedKeywords[x.Unbox().ScalarString()]
|
||||||
|
|
|
||||||
|
|
@ -4862,6 +4862,17 @@ Text 2
|
||||||
key: `a.b.c`,
|
key: `a.b.c`,
|
||||||
|
|
||||||
exp: `a.b
|
exp: `a.b
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "drop_value_with_primary",
|
||||||
|
text: `a.b: hello {
|
||||||
|
shape: circle
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
key: `a.b`,
|
||||||
|
|
||||||
|
exp: `a
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -4875,6 +4886,19 @@ Text 2
|
||||||
exp: `b: {
|
exp: `b: {
|
||||||
shape: circle
|
shape: circle
|
||||||
}
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "save_map_with_primary",
|
||||||
|
text: `a.b: hello {
|
||||||
|
shape: circle
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
key: `a`,
|
||||||
|
|
||||||
|
exp: `b: hello {
|
||||||
|
shape: circle
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
|
||||||
110
testdata/d2oracle/TestDelete/drop_value_with_primary.exp.json
generated
vendored
Normal file
110
testdata/d2oracle/TestDelete/drop_value_with_primary.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,110 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/drop_value_with_primary.d2,0:0:0-1:0:2",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/drop_value_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/drop_value_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/drop_value_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "a",
|
||||||
|
"raw_string": "a"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"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": "a",
|
||||||
|
"id_val": "a",
|
||||||
|
"label_dimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/drop_value_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/drop_value_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "a",
|
||||||
|
"raw_string": "a"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "a"
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": {
|
||||||
|
"value": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": "<nil>"
|
||||||
|
}
|
||||||
159
testdata/d2oracle/TestDelete/save_map_with_primary.exp.json
generated
vendored
Normal file
159
testdata/d2oracle/TestDelete/save_map_with_primary.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,159 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,0:0:0-3:0:29",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,0:0:0-2:1:28",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "b",
|
||||||
|
"raw_string": "b"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,0:3:3-0:8:8",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "hello",
|
||||||
|
"raw_string": "hello"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": {
|
||||||
|
"map": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,0:9:9-2:0:27",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,1:2:13-1:15:26",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,1:2:13-1:7:18",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,1:2:13-1:7:18",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "shape",
|
||||||
|
"raw_string": "shape"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,1:9:20-1:15:26",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "circle",
|
||||||
|
"raw_string": "circle"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"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": "b",
|
||||||
|
"id_val": "b",
|
||||||
|
"label_dimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2oracle/TestDelete/save_map_with_primary.d2,0:0:0-0:1:1",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "b",
|
||||||
|
"raw_string": "b"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "hello"
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "circle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": {
|
||||||
|
"value": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": "<nil>"
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue