set the ast range path
This commit is contained in:
parent
c50fab758a
commit
232c47d21a
3 changed files with 185 additions and 0 deletions
|
|
@ -3515,6 +3515,23 @@ svc_1."think about A"
|
||||||
svc_1.t2 -> b: do with B
|
svc_1.t2 -> b: do with B
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "layer-import-nested-layer",
|
||||||
|
|
||||||
|
text: `...@meow
|
||||||
|
`,
|
||||||
|
files: map[string]string{
|
||||||
|
"meow.d2": `layers: {
|
||||||
|
1: {
|
||||||
|
asdf
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`,
|
||||||
|
},
|
||||||
|
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||||
|
tassert.Equal(t, "d2/testdata/d2compiler/TestCompile/meow.d2", g.Layers[0].AST.Range.Path)
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
|
|
|
||||||
|
|
@ -1458,6 +1458,12 @@ func (m *Map) AST() d2ast.Node {
|
||||||
astMap := &d2ast.Map{
|
astMap := &d2ast.Map{
|
||||||
Range: d2ast.MakeRange(",0:0:0-1:0:0"),
|
Range: d2ast.MakeRange(",0:0:0-1:0:0"),
|
||||||
}
|
}
|
||||||
|
if m.parent != nil {
|
||||||
|
f, ok := m.parent.(*Field)
|
||||||
|
if ok {
|
||||||
|
astMap.Range.Path = f.Name.GetRange().Path
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, f := range m.Fields {
|
for _, f := range m.Fields {
|
||||||
astMap.Nodes = append(astMap.Nodes, d2ast.MakeMapNodeBox(f.AST().(d2ast.MapNode)))
|
astMap.Nodes = append(astMap.Nodes, d2ast.MakeMapNodeBox(f.AST().(d2ast.MapNode)))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
162
testdata/d2compiler/TestCompile/layer-import-nested-layer.exp.json
generated
vendored
Normal file
162
testdata/d2compiler/TestCompile/layer-import-nested-layer.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,162 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": true,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/layer-import-nested-layer.d2,0:0:0-1:0:9",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"import": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/layer-import-nested-layer.d2,0:0:0-0:8:8",
|
||||||
|
"spread": true,
|
||||||
|
"pre": "",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/layer-import-nested-layer.d2,0:4:4-0:8:8",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "meow",
|
||||||
|
"raw_string": "meow"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"id": "",
|
||||||
|
"id_val": "",
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
},
|
||||||
|
"edges": null,
|
||||||
|
"objects": null,
|
||||||
|
"layers": [
|
||||||
|
{
|
||||||
|
"name": "1",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/meow.d2,0:0:0-1:0:0",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": ",0:0:0-0:0:0",
|
||||||
|
"key": {
|
||||||
|
"range": ",0:0:0-0:0:0",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/meow.d2,2:4:21-2:8:25",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "asdf",
|
||||||
|
"raw_string": "asdf"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"id": "",
|
||||||
|
"id_val": "",
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
},
|
||||||
|
"edges": null,
|
||||||
|
"objects": [
|
||||||
|
{
|
||||||
|
"id": "asdf",
|
||||||
|
"id_val": "asdf",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/meow.d2,2:4:21-2:8:25",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile/meow.d2,2:4:21-2:8:25",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "asdf",
|
||||||
|
"raw_string": "asdf"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"key_path_index": 0,
|
||||||
|
"map_key_edge_index": -1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"attributes": {
|
||||||
|
"label": {
|
||||||
|
"value": "asdf"
|
||||||
|
},
|
||||||
|
"labelDimensions": {
|
||||||
|
"width": 0,
|
||||||
|
"height": 0
|
||||||
|
},
|
||||||
|
"style": {},
|
||||||
|
"near_key": null,
|
||||||
|
"shape": {
|
||||||
|
"value": "rectangle"
|
||||||
|
},
|
||||||
|
"direction": {
|
||||||
|
"value": ""
|
||||||
|
},
|
||||||
|
"constraint": null
|
||||||
|
},
|
||||||
|
"zIndex": 0
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"err": null
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue