attribute
This commit is contained in:
parent
c2b5cb9e56
commit
0749d4fb41
3 changed files with 230 additions and 10 deletions
|
|
@ -2956,16 +2956,16 @@ a -> b
|
|||
assert.Equal(t, 0, len(g.Edges))
|
||||
},
|
||||
},
|
||||
// {
|
||||
// name: "attribute",
|
||||
// run: func(t *testing.T) {
|
||||
// g := assertCompile(t, `
|
||||
// a.style.opacity: 0.2
|
||||
// a.style.opacity: null
|
||||
// `, "")
|
||||
// assert.Equal(t, "0.2", g.Objects[0].Attributes.Style.Opacity.Value)
|
||||
// },
|
||||
// },
|
||||
{
|
||||
name: "attribute",
|
||||
run: func(t *testing.T) {
|
||||
g := assertCompile(t, `
|
||||
a.style.opacity: 0.2
|
||||
a.style.opacity: null
|
||||
`, "")
|
||||
assert.Equal(t, (*d2graph.Scalar)(nil), g.Objects[0].Attributes.Style.Opacity)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tca {
|
||||
|
|
|
|||
15
d2ir/d2ir.go
15
d2ir/d2ir.go
|
|
@ -777,6 +777,21 @@ func (m *Map) DeleteField(ida ...string) *Field {
|
|||
}
|
||||
}
|
||||
m.Fields = append(m.Fields[:i], m.Fields[i+1:]...)
|
||||
|
||||
// If a field was deleted from a keyword-holder keyword and that holder is empty,
|
||||
// then that holder becomes meaningless and should be deleted too
|
||||
parent := ParentField(f)
|
||||
for keyword := range d2graph.ReservedKeywordHolders {
|
||||
if parent != nil && parent.Name == keyword && len(parent.Map().Fields) == 0 {
|
||||
styleParentMap := ParentMap(parent)
|
||||
for i, f := range styleParentMap.Fields {
|
||||
if f.Name == keyword {
|
||||
styleParentMap.Fields = append(styleParentMap.Fields[:i], styleParentMap.Fields[i+1:]...)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return f
|
||||
}
|
||||
if f.Map() != nil {
|
||||
|
|
|
|||
205
testdata/d2compiler/TestCompile2/nulls/basic/attribute.exp.json
generated
vendored
Normal file
205
testdata/d2compiler/TestCompile2/nulls/basic/attribute.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,205 @@
|
|||
{
|
||||
"graph": {
|
||||
"name": "",
|
||||
"isFolderOnly": false,
|
||||
"ast": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,0:0:0-3:3:47",
|
||||
"nodes": [
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:0:1-1:20:21",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:0:1-1:15:16",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:0:1-1:1:2",
|
||||
"value": [
|
||||
{
|
||||
"string": "a",
|
||||
"raw_string": "a"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:2:3-1:7:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "style",
|
||||
"raw_string": "style"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:8:9-1:15:16",
|
||||
"value": [
|
||||
{
|
||||
"string": "opacity",
|
||||
"raw_string": "opacity"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"number": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:17:18-1:20:21",
|
||||
"raw": "0.2",
|
||||
"value": "1/5"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"map_key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,2:0:22-2:21:43",
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,2:0:22-2:15:37",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,2:0:22-2:1:23",
|
||||
"value": [
|
||||
{
|
||||
"string": "a",
|
||||
"raw_string": "a"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,2:2:24-2:7:29",
|
||||
"value": [
|
||||
{
|
||||
"string": "style",
|
||||
"raw_string": "style"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,2:8:30-2:15:37",
|
||||
"value": [
|
||||
{
|
||||
"string": "opacity",
|
||||
"raw_string": "opacity"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"primary": {},
|
||||
"value": {
|
||||
"null": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,2:17:39-2:21:43"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"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": "a",
|
||||
"id_val": "a",
|
||||
"references": [
|
||||
{
|
||||
"key": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:0:1-1:15:16",
|
||||
"path": [
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:0:1-1:1:2",
|
||||
"value": [
|
||||
{
|
||||
"string": "a",
|
||||
"raw_string": "a"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:2:3-1:7:8",
|
||||
"value": [
|
||||
{
|
||||
"string": "style",
|
||||
"raw_string": "style"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"unquoted_string": {
|
||||
"range": "d2/testdata/d2compiler/TestCompile2/nulls/basic/attribute.d2,1:8:9-1:15:16",
|
||||
"value": [
|
||||
{
|
||||
"string": "opacity",
|
||||
"raw_string": "opacity"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"key_path_index": 0,
|
||||
"map_key_edge_index": -1
|
||||
}
|
||||
],
|
||||
"attributes": {
|
||||
"label": {
|
||||
"value": "a"
|
||||
},
|
||||
"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