fix vars nil check

This commit is contained in:
Alexander Wang 2024-11-23 18:50:30 -08:00
parent bc4cfa5243
commit da0f3a5dea
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
4 changed files with 164 additions and 20 deletions

View file

@ -739,7 +739,7 @@ dora: {
}
`)
assert.Success(t, err)
assert.Equal(t, "grid-columns", m.Fields[1].Map().Fields[0].Name)
assert.Equal(t, "grid-columns", m.Fields[1].Map().Fields[0].Name.ScalarString())
},
},
}

View file

@ -890,7 +890,7 @@ func (m *Map) ensureField(i int, kp *d2ast.KeyPath, refctx *RefContext, create b
}
for _, f := range m.Fields {
if !(strings.EqualFold(f.Name.ScalarString(), head.ScalarString()) && f.Name.IsUnquoted() == head.IsUnquoted()) {
if !(f.Name != nil && strings.EqualFold(f.Name.ScalarString(), head.ScalarString()) && f.Name.IsUnquoted() == head.IsUnquoted()) {
continue
}

View file

@ -1,7 +1,15 @@
{
"fields": [
{
"name": "x",
"name": {
"range": "TestCompile/classes/basic.d2,0:0:0-0:1:1",
"value": [
{
"string": "x",
"raw_string": "x"
}
]
},
"references": [
{
"string": {
@ -59,19 +67,51 @@
]
},
{
"name": "classes",
"name": {
"range": "TestCompile/classes/basic.d2,1:0:2-1:7:9",
"value": [
{
"string": "classes",
"raw_string": "classes"
}
]
},
"composite": {
"fields": [
{
"name": "mango",
"name": {
"range": "TestCompile/classes/basic.d2,2:2:15-2:7:20",
"value": [
{
"string": "mango",
"raw_string": "mango"
}
]
},
"composite": {
"fields": [
{
"name": "style",
"name": {
"range": "TestCompile/classes/basic.d2,3:4:28-3:9:33",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
},
"composite": {
"fields": [
{
"name": "fill",
"name": {
"range": "TestCompile/classes/basic.d2,3:10:34-3:14:38",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
},
"primary": {
"value": {
"range": "TestCompile/classes/basic.d2,3:16:40-3:22:46",

View file

@ -1,15 +1,39 @@
{
"fields": [
{
"name": "vars",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,0:0:0-0:4:4",
"value": [
{
"string": "vars",
"raw_string": "vars"
}
]
},
"composite": {
"fields": [
{
"name": "person-shape",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,1:2:10-1:14:22",
"value": [
{
"string": "person-shape",
"raw_string": "person-shape"
}
]
},
"composite": {
"fields": [
{
"name": "grid-columns",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,2:4:30-2:16:42",
"value": [
{
"string": "grid-columns",
"raw_string": "grid-columns"
}
]
},
"primary": {
"value": {
"range": "TestCompile/vars/spread-in-place.d2,2:18:44-2:19:45",
@ -80,7 +104,15 @@
]
},
{
"name": "grid-rows",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,3:4:50-3:13:59",
"value": [
{
"string": "grid-rows",
"raw_string": "grid-rows"
}
]
},
"primary": {
"value": {
"range": "TestCompile/vars/spread-in-place.d2,3:15:61-3:16:62",
@ -151,7 +183,15 @@
]
},
{
"name": "grid-gap",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,4:4:67-4:12:75",
"value": [
{
"string": "grid-gap",
"raw_string": "grid-gap"
}
]
},
"primary": {
"value": {
"range": "TestCompile/vars/spread-in-place.d2,4:14:77-4:15:78",
@ -222,7 +262,15 @@
]
},
{
"name": "head",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,5:4:83-5:8:87",
"value": [
{
"string": "head",
"raw_string": "head"
}
]
},
"references": [
{
"string": {
@ -280,7 +328,15 @@
]
},
{
"name": "body",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,6:4:92-6:8:96",
"value": [
{
"string": "body",
"raw_string": "body"
}
]
},
"references": [
{
"string": {
@ -763,11 +819,27 @@
]
},
{
"name": "dora",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,10:0:104-10:4:108",
"value": [
{
"string": "dora",
"raw_string": "dora"
}
]
},
"composite": {
"fields": [
{
"name": "grid-columns",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,2:4:30-2:16:42",
"value": [
{
"string": "grid-columns",
"raw_string": "grid-columns"
}
]
},
"primary": {
"value": {
"range": "TestCompile/vars/spread-in-place.d2,2:18:44-2:19:45",
@ -838,7 +910,15 @@
]
},
{
"name": "grid-rows",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,3:4:50-3:13:59",
"value": [
{
"string": "grid-rows",
"raw_string": "grid-rows"
}
]
},
"primary": {
"value": {
"range": "TestCompile/vars/spread-in-place.d2,3:15:61-3:16:62",
@ -909,7 +989,15 @@
]
},
{
"name": "grid-gap",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,4:4:67-4:12:75",
"value": [
{
"string": "grid-gap",
"raw_string": "grid-gap"
}
]
},
"primary": {
"value": {
"range": "TestCompile/vars/spread-in-place.d2,4:14:77-4:15:78",
@ -980,7 +1068,15 @@
]
},
{
"name": "head",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,5:4:83-5:8:87",
"value": [
{
"string": "head",
"raw_string": "head"
}
]
},
"references": [
{
"string": {
@ -1038,7 +1134,15 @@
]
},
{
"name": "body",
"name": {
"range": "TestCompile/vars/spread-in-place.d2,12:2:135-12:6:139",
"value": [
{
"string": "body",
"raw_string": "body"
}
]
},
"references": [
{
"string": {