Merge pull request #2378 from alixander/fix-comment-array-bug
d2ir: do not interpret comment in array as array node
This commit is contained in:
commit
0706993099
4 changed files with 235 additions and 0 deletions
|
|
@ -21,4 +21,5 @@
|
||||||
- Compiler:
|
- Compiler:
|
||||||
- fixes panic when `sql_shape` shape value had mixed casing [#2349](https://github.com/terrastruct/d2/pull/2349)
|
- fixes panic when `sql_shape` shape value had mixed casing [#2349](https://github.com/terrastruct/d2/pull/2349)
|
||||||
- fixes support for `center` in `d2-config` [#2360](https://github.com/terrastruct/d2/pull/2360)
|
- fixes support for `center` in `d2-config` [#2360](https://github.com/terrastruct/d2/pull/2360)
|
||||||
|
- fixes panic when comment lines appear in arrays [#2378](https://github.com/terrastruct/d2/pull/2378)
|
||||||
- CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370)
|
- CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370)
|
||||||
|
|
|
||||||
|
|
@ -4409,6 +4409,24 @@ a: {
|
||||||
assert.Equal(t, 2, len(g.Objects[0].SQLTable.Columns[0].Constraint))
|
assert.Equal(t, 2, len(g.Objects[0].SQLTable.Columns[0].Constraint))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "comment-array",
|
||||||
|
run: func(t *testing.T) {
|
||||||
|
assertCompile(t, `
|
||||||
|
vars: {
|
||||||
|
list: [
|
||||||
|
"a";
|
||||||
|
"b";
|
||||||
|
"c";
|
||||||
|
"d"
|
||||||
|
# e
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
a
|
||||||
|
`, "")
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "spread-array",
|
name: "spread-array",
|
||||||
run: func(t *testing.T) {
|
run: func(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -1282,6 +1282,8 @@ func (c *compiler) compileArray(dst *Array, a *d2ast.Array, scopeAST *d2ast.Map)
|
||||||
Value: []d2ast.InterpolationBox{{Substitution: an.Substitution}},
|
Value: []d2ast.InterpolationBox{{Substitution: an.Substitution}},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
case *d2ast.Comment:
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
dst.Values = append(dst.Values, irv)
|
dst.Values = append(dst.Values, irv)
|
||||||
|
|
|
||||||
214
testdata/d2compiler/TestCompile2/vars/basic/comment-array.exp.json
generated
vendored
Normal file
214
testdata/d2compiler/TestCompile2/vars/basic/comment-array.exp.json
generated
vendored
Normal file
|
|
@ -0,0 +1,214 @@
|
||||||
|
{
|
||||||
|
"graph": {
|
||||||
|
"name": "",
|
||||||
|
"isFolderOnly": false,
|
||||||
|
"ast": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,0:0:0-12:0:71",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,1:0:1-9:1:67",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,1:0:1-1:4:5",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,1:0:1-1:4:5",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "vars",
|
||||||
|
"raw_string": "vars"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"map": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,1:6:7-9:1:67",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,2:2:11-8:3:65",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,2:2:11-2:6:15",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,2:2:11-2:6:15",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "list",
|
||||||
|
"raw_string": "list"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"primary": {},
|
||||||
|
"value": {
|
||||||
|
"array": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,2:8:17-8:2:64",
|
||||||
|
"nodes": [
|
||||||
|
{
|
||||||
|
"double_quoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,3:4:23-3:7:26",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "a",
|
||||||
|
"raw_string": "a"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"double_quoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,4:4:32-4:7:35",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "b",
|
||||||
|
"raw_string": "b"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"double_quoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,5:4:41-5:7:44",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "c",
|
||||||
|
"raw_string": "c"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"double_quoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,6:4:50-6:7:53",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "d",
|
||||||
|
"raw_string": "d"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"comment": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,7:4:58-7:7:61",
|
||||||
|
"value": "e"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"map_key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,11:0:69-11:1:70",
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,11:0:69-11:1:70",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,11:0:69-11:1:70",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "a",
|
||||||
|
"raw_string": "a"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"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": "a",
|
||||||
|
"id_val": "a",
|
||||||
|
"references": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,11:0:69-11:1:70",
|
||||||
|
"path": [
|
||||||
|
{
|
||||||
|
"unquoted_string": {
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/basic/comment-array.d2,11:0:69-11:1:70",
|
||||||
|
"value": [
|
||||||
|
{
|
||||||
|
"string": "a",
|
||||||
|
"raw_string": "a"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"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