diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 6a900a0df..999f9677a 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -19,3 +19,4 @@ - Fix importing a file with nested boards [#1998](https://github.com/terrastruct/d2/pull/1998) - Fix importing a file with underscores in links [#1999](https://github.com/terrastruct/d2/pull/1999) - Replace a panic with an error message resulting from invalid `link` usage [#2011](https://github.com/terrastruct/d2/pull/2011) +- Fix globs not applying to scenarios on keys that were applied in earlier scenarios [#2021](https://github.com/terrastruct/d2/pull/2021) diff --git a/d2ir/compile.go b/d2ir/compile.go index 460b4329d..2dad21fbb 100644 --- a/d2ir/compile.go +++ b/d2ir/compile.go @@ -24,17 +24,6 @@ type globContext struct { appliedEdges map[string]struct{} } -func (g *globContext) copyApplied(from *globContext) { - g.appliedFields = make(map[string]struct{}) - for k, v := range from.appliedFields { - g.appliedFields[k] = v - } - g.appliedEdges = make(map[string]struct{}) - for k, v := range from.appliedEdges { - g.appliedEdges[k] = v - } -} - type compiler struct { err *d2parser.ParseError @@ -390,13 +379,22 @@ func (c *compiler) overlay(base *Map, f *Field) { func (g *globContext) copy() *globContext { g2 := *g g2.refctx = g.root.refctx.Copy() - return &g2 } +func (g *globContext) copyApplied(from *globContext) { + g.appliedFields = make(map[string]struct{}) + for k, v := range from.appliedFields { + g.appliedFields[k] = v + } + g.appliedEdges = make(map[string]struct{}) + for k, v := range from.appliedEdges { + g.appliedEdges[k] = v + } +} + func (g *globContext) prefixed(dst *Map) *globContext { g2 := g.copy() - prefix := d2ast.MakeKeyPath(RelIDA(g2.refctx.ScopeMap, dst)) g2.refctx.Key = g2.refctx.Key.Copy() if g2.refctx.Key.Key != nil {