fix double globs in multiple scenarios

This commit is contained in:
Alexander Wang 2024-11-04 14:58:06 -08:00
parent a814db60b4
commit db83fb8d1a
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
8 changed files with 1568 additions and 537 deletions

View file

@ -14,3 +14,4 @@
- Render: fixes edge case of a 3d shape with outside label being cut off [#2132](https://github.com/terrastruct/d2/pull/2132)
- Composition: labels for boards set with shorthand `x: y` was not applied [#2182](https://github.com/terrastruct/d2/pull/2182)
- Globs: double globs (`**`) were erroring when used with multiple scenario boards [#2195](https://github.com/terrastruct/d2/pull/2195)

View file

@ -1006,6 +1006,21 @@ func (mk *Key) HasTripleGlob() bool {
return false
}
func (mk *Key) HasMultiGlob() bool {
if mk.Key.HasMultiGlob() {
return true
}
for _, e := range mk.Edges {
if e.Src.HasMultiGlob() || e.Dst.HasMultiGlob() {
return true
}
}
if mk.EdgeKey.HasMultiGlob() {
return true
}
return false
}
func (mk *Key) SupportsGlobFilters() bool {
if mk.Key.HasGlob() && len(mk.Edges) == 0 {
return true

View file

@ -3576,6 +3576,40 @@ steps: {
`, `d2/testdata/d2compiler/TestCompile2/boards/errs/duplicate_board.d2:9:2: board name one already used by another board`)
},
},
{
name: "style-nested-boards",
run: func(t *testing.T) {
g, _ := assertCompile(t, `**.style.stroke: black
scenarios: {
a: {
x
}
b: {
x
}
}
steps: {
c: {
x
}
d: {
x
}
}
layers: {
e: {
x
}
}
`, ``)
assert.Equal(t, "black", g.Scenarios[0].Objects[0].Style.Stroke.Value)
assert.Equal(t, "black", g.Scenarios[1].Objects[0].Style.Stroke.Value)
assert.Equal(t, "black", g.Steps[0].Objects[0].Style.Stroke.Value)
assert.Equal(t, "black", g.Steps[1].Objects[0].Style.Stroke.Value)
assert.Equal(t, (*d2graph.Scalar)(nil), g.Layers[0].Objects[0].Style.Stroke)
},
},
}
for _, tc := range tca {

View file

@ -456,7 +456,7 @@ func (c *compiler) ampersandFilterMap(dst *Map, ast, scopeAST *d2ast.Map) bool {
return false
}
var ks string
if gctx.refctx.Key.HasTripleGlob() {
if gctx.refctx.Key.HasMultiGlob() {
ks = d2format.Format(d2ast.MakeKeyPath(IDA(dst)))
} else {
ks = d2format.Format(d2ast.MakeKeyPath(BoardIDA(dst)))
@ -488,7 +488,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.HasTripleGlob() {
if !g.refctx.Key.HasMultiGlob() {
// Triple globs already apply independently to each board
g2.copyApplied(g)
}

View file

@ -784,7 +784,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.HasTripleGlob() {
if refctx.Key.HasMultiGlob() {
ks = d2format.Format(d2ast.MakeKeyPath(IDA(f)))
} else {
ks = d2format.Format(d2ast.MakeKeyPath(BoardIDA(f)))
@ -937,7 +937,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.HasTripleGlob() {
if grefctx.Key.HasMultiGlob() {
ks = d2format.Format(d2ast.MakeKeyPath(IDA(f)))
} else {
ks = d2format.Format(d2ast.MakeKeyPath(BoardIDA(f)))
@ -1134,7 +1134,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.HasTripleGlob() {
if refctx.Key.HasMultiGlob() {
ks = d2format.Format(d2ast.MakeKeyPath(IDA(e)))
} else {
ks = d2format.Format(d2ast.MakeKeyPath(BoardIDA(e)))
@ -1352,7 +1352,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.HasTripleGlob() {
if refctx.Key.HasMultiGlob() {
ks = d2format.Format(d2ast.MakeKeyPath(IDA(e2)))
} else {
ks = d2format.Format(d2ast.MakeKeyPath(BoardIDA(e2)))

File diff suppressed because it is too large Load diff

View file

@ -186,240 +186,6 @@
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
},
"key_path": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:13:14",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:2:3",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:3:4-1:8:9",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:18:19",
"key": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:13:14",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:2:3",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:3:4-1:8:9",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:15:16-1:18:19",
"value": [
{
"string": "red",
"raw_string": "red"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
},
"key_path": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:13:14",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:2:3",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:3:4-1:8:9",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:18:19",
"key": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:13:14",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:2:3",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:3:4-1:8:9",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:15:16-1:18:19",
"value": [
{
"string": "red",
"raw_string": "red"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
}
]
}
@ -1587,240 +1353,6 @@
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
},
"key_path": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:13:14",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:2:3",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:3:4-1:8:9",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:18:19",
"key": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:13:14",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:2:3",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:3:4-1:8:9",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:15:16-1:18:19",
"value": [
{
"string": "red",
"raw_string": "red"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
},
"key_path": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:13:14",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:2:3",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:3:4-1:8:9",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:18:19",
"key": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:13:14",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:0:1-1:2:3",
"value": [
{
"string": "**",
"raw_string": "**"
}
],
"pattern": [
"*",
"",
"*"
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:3:4-1:8:9",
"value": [
{
"string": "style",
"raw_string": "style"
}
]
}
},
{
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:9:10-1:13:14",
"value": [
{
"string": "fill",
"raw_string": "fill"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/alixander-review/5.d2,1:15:16-1:18:19",
"value": [
{
"string": "red",
"raw_string": "red"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
}
]
}

View file

@ -594,6 +594,69 @@
}
},
"references": [
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:12:18",
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:8:14-1:12:18",
"value": [
{
"string": "page",
"raw_string": "page"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
@ -736,6 +799,69 @@
}
},
"references": [
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:12:18",
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:8:14-1:12:18",
"value": [
{
"string": "page",
"raw_string": "page"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
@ -878,6 +1004,69 @@
}
},
"references": [
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:12:18",
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:8:14-1:12:18",
"value": [
{
"string": "page",
"raw_string": "page"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
@ -1020,6 +1209,69 @@
}
},
"references": [
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:12:18",
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:8:14-1:12:18",
"value": [
{
"string": "page",
"raw_string": "page"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
@ -1162,69 +1414,6 @@
}
},
"references": [
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
},
"key_path": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"context": {
"edge": null,
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:12:18",
"key": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"path": [
{
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",
"value": [
{
"string": "shape",
"raw_string": "shape"
}
]
}
}
]
},
"primary": {},
"value": {
"unquoted_string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:8:14-1:12:18",
"value": [
{
"string": "page",
"raw_string": "page"
}
]
}
}
}
},
"due_to_glob": true,
"due_to_lazy_glob": true
},
{
"string": {
"range": "TestCompile/patterns/double-glob/defaults.d2,1:1:7-1:6:12",