Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#### Bugfixes ⛑️

- actors in sequence diagrams with labels and icons together no longer overlap, position keywords now work too [#2548](https://github.com/terrastruct/d2/pull/2548)
- fix double glob behavior in scenarios (wasn't propagating correctly) [#2557](https://github.com/terrastruct/d2/pull/2557)

---

Expand Down
19 changes: 19 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,25 @@ k: {
assert.Equal(t, "red", g.Objects[2].Style.Fill.Value)
},
},
{
name: "scenario-glob",

text: `**.style.opacity: 0.2
x.style.opacity: 1
z

scenarios: {
y: {
z.style.opacity: 1
}
}

`,
assertions: func(t *testing.T, g *d2graph.Graph) {
assert.Equal(t, "x", g.Scenarios[0].Objects[0].ID)
assert.Equal(t, "1", g.Scenarios[0].Objects[0].Style.Opacity.Value)
},
},
{
name: "import-scenario",

Expand Down
6 changes: 3 additions & 3 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ func (c *compiler) ampersandFilterMap(dst *Map, ast, scopeAST *d2ast.Map) bool {
return false
}
var ks string
if gctx.refctx.Key.HasMultiGlob() {
if gctx.refctx.Key.HasTripleGlob() {
ks = d2format.Format(d2ast.MakeKeyPathString(IDA(dst)))
} else {
ks = d2format.Format(d2ast.MakeKeyPathString(BoardIDA(dst)))
Expand Down Expand Up @@ -516,7 +516,7 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
for _, g := range previousGlobs {
gctx2 := g.copy()
gctx2.refctx.ScopeMap = dst
if !g.refctx.Key.HasMultiGlob() {
if !g.refctx.Key.HasTripleGlob() {
// Triple globs already apply independently to each board
gctx2.copyApplied(g)
}
Expand All @@ -528,7 +528,7 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
// We don't want globs applied in a given scenario to affect future boards
// Copying the applied fields and edges keeps the applications scoped to this board
// Note that this is different from steps, where applications carry over
if !g.refctx.Key.HasMultiGlob() {
if !g.refctx.Key.HasTripleGlob() {
// Triple globs already apply independently to each board
g2.copyApplied(g)
}
Expand Down
8 changes: 4 additions & 4 deletions d2ir/d2ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ func (m *Map) ensureField(i int, kp *d2ast.KeyPath, refctx *RefContext, create b
filter := func(f *Field, passthrough bool) bool {
if gctx != nil {
var ks string
if refctx.Key.HasMultiGlob() {
if refctx.Key.HasTripleGlob() {
ks = d2format.Format(d2ast.MakeKeyPathString(IDA(f)))
} else {
ks = d2format.Format(d2ast.MakeKeyPathString(BoardIDA(f)))
Expand Down Expand Up @@ -1021,7 +1021,7 @@ func (m *Map) ensureField(i int, kp *d2ast.KeyPath, refctx *RefContext, create b
}
for _, grefctx := range c.globRefContextStack {
var ks string
if grefctx.Key.HasMultiGlob() {
if grefctx.Key.HasTripleGlob() {
ks = d2format.Format(d2ast.MakeKeyPathString(IDA(f)))
} else {
ks = d2format.Format(d2ast.MakeKeyPathString(BoardIDA(f)))
Expand Down Expand Up @@ -1234,7 +1234,7 @@ func (m *Map) getEdges(eid *EdgeID, refctx *RefContext, gctx *globContext, ea *[
for _, e := range ea2 {
if gctx != nil {
var ks string
if refctx.Key.HasMultiGlob() {
if refctx.Key.HasTripleGlob() {
ks = d2format.Format(d2ast.MakeKeyPathString(IDA(e)))
} else {
ks = d2format.Format(d2ast.MakeKeyPathString(BoardIDA(e)))
Expand Down Expand Up @@ -1452,7 +1452,7 @@ func (m *Map) createEdge2(eid *EdgeID, refctx *RefContext, gctx *globContext, c
e2 := e.Copy(e.Parent()).(*Edge)
e2.ID = e2.ID.Copy()
e2.ID.Index = nil
if refctx.Key.HasMultiGlob() {
if refctx.Key.HasTripleGlob() {
ks = d2format.Format(d2ast.MakeKeyPathString(IDA(e2)))
} else {
ks = d2format.Format(d2ast.MakeKeyPathString(BoardIDA(e2)))
Expand Down
8 changes: 2 additions & 6 deletions d2ir/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@ func (m *Map) _doubleGlob(fa *[]*Field) {
continue
}
if _, ok := d2ast.ReservedKeywords[f.Name.ScalarString()]; ok && f.Name.IsUnquoted() {
if f.Name.ScalarString() == "layers" {
if _, ok := d2ast.BoardKeywords[f.Name.ScalarString()]; ok {
continue
}
if _, ok := d2ast.BoardKeywords[f.Name.ScalarString()]; !ok {
continue
}
// We don't ever want to append layers, scenarios or steps directly.
if f.Map() != nil {
f.Map()._tripleGlob(fa)
f.Map()._doubleGlob(fa)
}
continue
}
Expand Down
17 changes: 8 additions & 9 deletions d2ir/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,13 @@ Spiderman 3
name: "scenarios",
run: func(t testing.TB) {
m, err := compile(t, `
a
b
c
d

**: something
** -> **

scenarios: {
meow: {
Expand All @@ -288,17 +295,9 @@ scenarios: {
h
}
}

a
b
c
d

**: something
** -> **
`)
assert.Success(t, err)
assertQuery(t, m, 10, 24, nil, "")
assertQuery(t, m, 14, (4*3)+(8*7), nil, "")
assertQuery(t, m, 0, 0, "something", "**")
assertQuery(t, m, 0, 0, nil, "(* -> *)[*]")
},
Expand Down
Loading