Skip to content

Commit

Permalink
Merge pull request #2378 from alixander/fix-comment-array-bug
Browse files Browse the repository at this point in the history
d2ir: do not interpret comment in array as array node
  • Loading branch information
alixander authored Feb 25, 2025
2 parents c09d29f + 06b29a5 commit 0706993
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
- Compiler:
- 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 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)
18 changes: 18 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4409,6 +4409,24 @@ a: {
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",
run: func(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,8 @@ func (c *compiler) compileArray(dst *Array, a *d2ast.Array, scopeAST *d2ast.Map)
Value: []d2ast.InterpolationBox{{Substitution: an.Substitution}},
},
}
case *d2ast.Comment:
continue
}

dst.Values = append(dst.Values, irv)
Expand Down
214 changes: 214 additions & 0 deletions testdata/d2compiler/TestCompile2/vars/basic/comment-array.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0706993

Please sign in to comment.