Merge pull request #348 from alixander/unresolved-obj
fix unresolved scope obj setting in compiler
This commit is contained in:
commit
874a54fff8
3 changed files with 213 additions and 4 deletions
|
|
@ -252,11 +252,8 @@ func (c *compiler) compileKey(obj *d2graph.Object, m *d2ast.Map, mk *d2ast.Key)
|
|||
c.errorf(mk.Range.Start, mk.Range.End, err.Error())
|
||||
return
|
||||
}
|
||||
if resolvedObj != obj {
|
||||
obj = resolvedObj
|
||||
}
|
||||
|
||||
parent := obj
|
||||
parent := resolvedObj
|
||||
if len(resolvedIDA) > 0 {
|
||||
unresolvedObj := obj
|
||||
obj = parent.EnsureChild(resolvedIDA)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
tassert "github.com/stretchr/testify/assert"
|
||||
"oss.terrastruct.com/util-go/assert"
|
||||
"oss.terrastruct.com/util-go/diff"
|
||||
|
||||
|
|
@ -209,6 +210,20 @@ x: {
|
|||
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "underscore_unresolved_obj",
|
||||
|
||||
text: `
|
||||
x: {
|
||||
_.y
|
||||
}
|
||||
`,
|
||||
assertions: func(t *testing.T, g *d2graph.Graph) {
|
||||
tassert.Equal(t, "y", g.Objects[1].ID)
|
||||
tassert.Equal(t, g.Root.AbsID(), g.Objects[1].References[0].ScopeObj.AbsID())
|
||||
tassert.Equal(t, g.Objects[0].AbsID(), g.Objects[1].References[0].UnresolvedScopeObj.AbsID())
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "underscore_parent_not_root",
|
||||
|
||||
|
|
|
|||
197
testdata/d2compiler/TestCompile/underscore_unresolved_obj.exp.json
generated
vendored
Normal file
197
testdata/d2compiler/TestCompile/underscore_unresolved_obj.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,197 @@
|
|||
{
|
||||
"graph": {
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,0:0:0-4:0:13",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,1:0:1-3:1:12",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,1:0:1-1:1:2",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,1:0:1-1:1:2",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"map": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,1:3:4-3:0:11",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,2:1:7-2:4:10",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,2:1:7-2:4:10",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,2:1:7-2:2:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "_",
|
||||
"raw_string": "_"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,2:3:9-2:4:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "y",
|
||||
"raw_string": "y"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"root": {
|
||||
"id": "",
|
||||
"id_val": "",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": ""
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
"edges": null,
|
||||
"objects": [
|
||||
{
|
||||
"id": "x",
|
||||
"id_val": "x",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,1:0:1-1:1:2",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,1:0:1-1:1:2",
|
||||
"value": [
|
||||
{
|
||||
"string": "x",
|
||||
"raw_string": "x"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "x"
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
},
|
||||
{
|
||||
"id": "y",
|
||||
"id_val": "y",
|
||||
"label_dimensions": {
|
||||
"width": 0,
|
||||
"height": 0
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,2:1:7-2:4:10",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,2:1:7-2:2:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "_",
|
||||
"raw_string": "_"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile/underscore_unresolved_obj.d2,2:3:9-2:4:10",
|
||||
"value": [
|
||||
{
|
||||
"string": "y",
|
||||
"raw_string": "y"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 1,
|
||||
"map_key_edge_index": 0
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "y"
|
||||
},
|
||||
"style": {},
|
||||
"near_key": null,
|
||||
"shape": {
|
||||
"value": ""
|
||||
},
|
||||
"direction": {
|
||||
"value": ""
|
||||
}
|
||||
},
|
||||
"zIndex": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
"err": null
|
||||
}
|
||||
Loading…
Reference in a new issue