Skip to content

Commit fe7ec40

Browse files
authored
Merge pull request terrastruct#1755 from alixander/glob-imp
globs: fix imported case
2 parents 3edfaa4 + 12b166b commit fe7ec40

File tree

4 files changed

+467
-2
lines changed

4 files changed

+467
-2
lines changed

ci/release/changelogs/next.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@
3333
- 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)
3434
- Fixes content sometimes escaping cloud shapes. [#1736](https://github.com/terrastruct/d2/pull/1736)
3535
- Fixes panic using a glob filter (e.g. `&a`) outside globs. [#1748](https://github.com/terrastruct/d2/pull/1748)
36+
- Fixes glob keys with import values (e.g. `user*: @lib/user`). [#1755](https://github.com/terrastruct/d2/pull/1755)

d2ir/compile.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,10 @@ func (c *compiler) ampersandFilterMap(dst *Map, ast, scopeAST *d2ast.Map) bool {
419419
func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
420420
var globs []*globContext
421421
if len(c.globContextStack) > 0 {
422-
previousGlobs := c.globContextStack[len(c.globContextStack)-1]
423-
if NodeBoardKind(dst) == BoardLayer {
422+
previousGlobs := c.globContexts()
423+
// A root layer with existing glob context stack implies it's an import
424+
// In which case, the previous globs should be inherited (the else block)
425+
if NodeBoardKind(dst) == BoardLayer && !dst.Root() {
424426
for _, g := range previousGlobs {
425427
if g.refctx.Key.HasTripleGlob() {
426428
globs = append(globs, g.prefixed(dst))

d2ir/import_test.go

+15
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,21 @@ label: meow`,
184184
assertQuery(t, m, 0, 0, 1, "hi")
185185
},
186186
},
187+
{
188+
name: "pattern-value",
189+
run: func(t testing.TB) {
190+
_, err := compileFS(t, "index.d2", map[string]string{
191+
"index.d2": `userWebsite
192+
userMobile
193+
194+
user*: @x
195+
`,
196+
"x.d2": `shape: person
197+
label: meow`,
198+
})
199+
assert.Success(t, err)
200+
},
201+
},
187202
}
188203

189204
runa(t, tca)

0 commit comments

Comments
 (0)