Skip to content

Commit 0706993

Browse files
authored
Merge pull request #2378 from alixander/fix-comment-array-bug
d2ir: do not interpret comment in array as array node
2 parents c09d29f + 06b29a5 commit 0706993

File tree

4 files changed

+235
-0
lines changed

4 files changed

+235
-0
lines changed

ci/release/changelogs/next.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
- Compiler:
2222
- fixes panic when `sql_shape` shape value had mixed casing [#2349](https://github.com/terrastruct/d2/pull/2349)
2323
- fixes support for `center` in `d2-config` [#2360](https://github.com/terrastruct/d2/pull/2360)
24+
- fixes panic when comment lines appear in arrays [#2378](https://github.com/terrastruct/d2/pull/2378)
2425
- CLI: fetch and render remote images of mimetype octet-stream correctly [#2370](https://github.com/terrastruct/d2/pull/2370)

d2compiler/compile_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -4409,6 +4409,24 @@ a: {
44094409
assert.Equal(t, 2, len(g.Objects[0].SQLTable.Columns[0].Constraint))
44104410
},
44114411
},
4412+
{
4413+
name: "comment-array",
4414+
run: func(t *testing.T) {
4415+
assertCompile(t, `
4416+
vars: {
4417+
list: [
4418+
"a";
4419+
"b";
4420+
"c";
4421+
"d"
4422+
# e
4423+
]
4424+
}
4425+
4426+
a
4427+
`, "")
4428+
},
4429+
},
44124430
{
44134431
name: "spread-array",
44144432
run: func(t *testing.T) {

d2ir/compile.go

+2
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,8 @@ func (c *compiler) compileArray(dst *Array, a *d2ast.Array, scopeAST *d2ast.Map)
12821282
Value: []d2ast.InterpolationBox{{Substitution: an.Substitution}},
12831283
},
12841284
}
1285+
case *d2ast.Comment:
1286+
continue
12851287
}
12861288

12871289
dst.Values = append(dst.Values, irv)

testdata/d2compiler/TestCompile2/vars/basic/comment-array.exp.json

+214
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)