Skip to content

Commit

Permalink
Merge pull request #1755 from alixander/glob-imp
Browse files Browse the repository at this point in the history
globs: fix imported case
  • Loading branch information
alixander authored Dec 5, 2023
2 parents 3edfaa4 + 12b166b commit fe7ec40
Show file tree
Hide file tree
Showing 4 changed files with 467 additions and 2 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@
- Fixes incorrect grid cell positioning when the grid has a shape set and fixes content sometimes escaping circle shapes. [#1734](https://github.com/terrastruct/d2/pull/1734)
- Fixes content sometimes escaping cloud shapes. [#1736](https://github.com/terrastruct/d2/pull/1736)
- Fixes panic using a glob filter (e.g. `&a`) outside globs. [#1748](https://github.com/terrastruct/d2/pull/1748)
- Fixes glob keys with import values (e.g. `user*: @lib/user`). [#1755](https://github.com/terrastruct/d2/pull/1755)
6 changes: 4 additions & 2 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,10 @@ func (c *compiler) ampersandFilterMap(dst *Map, ast, scopeAST *d2ast.Map) bool {
func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
var globs []*globContext
if len(c.globContextStack) > 0 {
previousGlobs := c.globContextStack[len(c.globContextStack)-1]
if NodeBoardKind(dst) == BoardLayer {
previousGlobs := c.globContexts()
// A root layer with existing glob context stack implies it's an import
// In which case, the previous globs should be inherited (the else block)
if NodeBoardKind(dst) == BoardLayer && !dst.Root() {
for _, g := range previousGlobs {
if g.refctx.Key.HasTripleGlob() {
globs = append(globs, g.prefixed(dst))
Expand Down
15 changes: 15 additions & 0 deletions d2ir/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,21 @@ label: meow`,
assertQuery(t, m, 0, 0, 1, "hi")
},
},
{
name: "pattern-value",
run: func(t testing.TB) {
_, err := compileFS(t, "index.d2", map[string]string{
"index.d2": `userWebsite
userMobile
user*: @x
`,
"x.d2": `shape: person
label: meow`,
})
assert.Success(t, err)
},
},
}

runa(t, tca)
Expand Down
Loading

0 comments on commit fe7ec40

Please sign in to comment.