d2oracle: Fix out_of_newline_container
This commit is contained in:
parent
2dfa0bef86
commit
11d1c111d5
3 changed files with 213 additions and 2 deletions
|
|
@ -178,7 +178,7 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
|
|||
}
|
||||
}
|
||||
scopeObjIDA := d2ir.IDA(fr.Context.ScopeMap)
|
||||
scopeObj, _ := obj.Graph.Root.HasChild(scopeObjIDA)
|
||||
scopeObj, _ := obj.Graph.Root.HasChildIDVal(scopeObjIDA)
|
||||
obj.References = append(obj.References, d2graph.Reference{
|
||||
Key: fr.KeyPath,
|
||||
KeyPathIndex: fr.KeyPathIndex(),
|
||||
|
|
@ -382,7 +382,7 @@ func (c *compiler) compileEdge(obj *d2graph.Object, e *d2ir.Edge) {
|
|||
edge.Attributes.Label.MapKey = e.LastPrimaryKey()
|
||||
for _, er := range e.References {
|
||||
scopeObjIDA := d2ir.IDA(er.Context.ScopeMap)
|
||||
scopeObj, _ := edge.Src.Graph.Root.HasChild(d2graphIDA(scopeObjIDA))
|
||||
scopeObj, _ := edge.Src.Graph.Root.HasChildIDVal(d2graphIDA(scopeObjIDA))
|
||||
edge.References = append(edge.References, d2graph.EdgeReference{
|
||||
Edge: er.Context.Edge,
|
||||
MapKey: er.Context.Key,
|
||||
|
|
|
|||
|
|
@ -558,6 +558,38 @@ func (obj *Object) HasChild(ids []string) (*Object, bool) {
|
|||
return child, true
|
||||
}
|
||||
|
||||
// Keep in sync with HasChild.
|
||||
func (obj *Object) HasChildIDVal(ids []string) (*Object, bool) {
|
||||
if len(ids) == 0 {
|
||||
return obj, true
|
||||
}
|
||||
if len(ids) == 1 && ids[0] != "style" {
|
||||
_, ok := ReservedKeywords[ids[0]]
|
||||
if ok {
|
||||
return obj, true
|
||||
}
|
||||
}
|
||||
|
||||
id := ids[0]
|
||||
ids = ids[1:]
|
||||
|
||||
var child *Object
|
||||
for _, ch2 := range obj.ChildrenArray {
|
||||
if ch2.IDVal == id {
|
||||
child = ch2
|
||||
break
|
||||
}
|
||||
}
|
||||
if child == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if len(ids) >= 1 {
|
||||
return child.HasChildIDVal(ids)
|
||||
}
|
||||
return child, true
|
||||
}
|
||||
|
||||
func (obj *Object) HasEdge(mk *d2ast.Key) (*Edge, bool) {
|
||||
ea, ok := obj.FindEdges(mk)
|
||||
if !ok {
|
||||
|
|
|
|||
179
testdata/d2oracle/TestMove/out_of_newline_container.exp.json
generated
vendored
Normal file
179
testdata/d2oracle/TestMove/out_of_newline_container.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,179 @@
|
|||
{
|
||||
"graph": {
|
||||
"name": "",
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,0:0:0-2:0:8",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,0:0:0-0:5:5",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,0:0:0-0:5:5",
|
||||
"path": [
|
||||
{
|
||||
"double_quoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "a\n",
|
||||
"raw_string": "a\\n"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,1:0:6-1:1:7",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,1:0:6-1:1:7",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,1:0:6-1:1:7",
|
||||
"value": [
|
||||
{
|
||||
"string": "b",
|
||||
"raw_string": "b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"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\\n\"",
|
||||
"id_val": "a\n",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,0:0:0-0:5:5",
|
||||
"path": [
|
||||
{
|
||||
"double_quoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,0:0:0-0:5:5",
|
||||
"value": [
|
||||
{
|
||||
"string": "a\n",
|
||||
"raw_string": "a\\n"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "a\n"
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "b",
|
||||
"id_val": "b",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,1:0:6-1:1:7",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2oracle/TestMove/out_of_newline_container.d2,1:0:6-1:1:7",
|
||||
"value": [
|
||||
{
|
||||
"string": "b",
|
||||
"raw_string": "b"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "b"
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": "rectangle"
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
},
|
||||
"constraint": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": "<nil>"
|
||||
}
|
||||
Loading…
Reference in a new issue