Skip to content

Commit

Permalink
globs: fix ampersand outside glob
Browse files Browse the repository at this point in the history
  • Loading branch information
alixander committed Nov 27, 2023
1 parent 5faa0ad commit 1816587
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ func (c *compiler) ampersandFilterMap(dst *Map, ast, scopeAST *d2ast.Map) bool {
ScopeAST: scopeAST,
})
if !ok {
if len(c.mapRefContextStack) == 0 {
return false
}
// Unapply glob if appropriate.
gctx := c.getGlobContext(c.mapRefContextStack[len(c.mapRefContextStack)-1])
if gctx == nil {
Expand Down
12 changes: 12 additions & 0 deletions d2ir/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,18 @@ classes: {
TestCompile/filters/errors/bad-syntax.d2:9:1: unexpected map termination character } in file map`)
},
},
{
name: "outside-glob",
run: func(t testing.TB) {
_, err := compile(t, `jacob.style: {
fill: red
multiple: true
}
&a
`)
assert.ErrorString(t, err, `TestCompile/filters/errors/outside-glob.d2:5:1: glob filters cannot be used outside globs`)
},
},
{
name: "no-glob",
run: func(t testing.TB) {
Expand Down
4 changes: 4 additions & 0 deletions testdata/d2ir/TestCompile/filters/outside-glob.exp.json

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

0 comments on commit 1816587

Please sign in to comment.