Skip to content

Commit

Permalink
d2ir: Fix Alex's null glob problem
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Aug 30, 2023
1 parent 4523b50 commit d03082d
Show file tree
Hide file tree
Showing 22 changed files with 23,599 additions and 6,097 deletions.
2 changes: 2 additions & 0 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,8 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) {
// If new board type, use that as the new scope AST, otherwise, carry on
scopeAST = refctx.ScopeAST
}
} else {
scopeAST = refctx.ScopeAST
}
c.mapRefContextStack = append(c.mapRefContextStack, refctx)
c.compileMap(f.Map(), refctx.Key.Value.Map, scopeAST)
Expand Down
16 changes: 16 additions & 0 deletions d2ir/d2ir.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,14 @@ func (m *Map) EnsureField(kp *d2ast.KeyPath, refctx *RefContext, create bool, c

var fa []*Field
err := m.ensureField(i, kp, refctx, create, gctx, c, &fa)
if len(fa) > 0 && c != nil && len(c.globRefContextStack) == 0 {
for _, gctx2 := range c.globContexts() {
old := c.lazyGlobBeingApplied
c.lazyGlobBeingApplied = true
c.compileKey(gctx2.refctx)
c.lazyGlobBeingApplied = old
}
}
return fa, err
}

Expand Down Expand Up @@ -1091,6 +1099,14 @@ func (m *Map) CreateEdge(eid *EdgeID, refctx *RefContext, c *compiler) ([]*Edge,
gctx = c.ensureGlobContext(refctx)
}
err := m.createEdge(eid, refctx, gctx, c, &ea)
if len(ea) > 0 && c != nil && len(c.globRefContextStack) == 0 {
for _, gctx2 := range c.globContexts() {
old := c.lazyGlobBeingApplied
c.lazyGlobBeingApplied = true
c.compileKey(gctx2.refctx)
c.lazyGlobBeingApplied = old
}
}
return ea, err
}

Expand Down
25 changes: 24 additions & 1 deletion d2ir/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,29 @@ a.icon: null
b.icon: https://icons.terrastruct.com/essentials%2F073-add.svg
b.icon: null
# Shape nulling works
*.shape: circle
a.shape: null
b.shape: null
`)
assert.Success(t, err)
assertQuery(t, m, 2, 0, nil, "")
assertQuery(t, m, 0, 0, nil, "a")
assertQuery(t, m, 0, 0, nil, "b")
},
},
{
name: "override/7",
run: func(t testing.TB) {
m, err := compile(t, `
# Nulling glob doesn't work
*a.icon: https://icons.terrastruct.com/essentials%2F073-add.svg
a.icon: null
# Regular icon nulling works
b.icon: https://icons.terrastruct.com/essentials%2F073-add.svg
b.icon: null
# Shape nulling works
*.shape: circle
a.shape: null
Expand Down Expand Up @@ -689,7 +712,7 @@ class: {
}
`)
assert.Success(t, err)
assertQuery(t, m, 10, 0, nil, "")
assertQuery(t, m, 13, 0, nil, "")
},
},
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

162 changes: 0 additions & 162 deletions testdata/d2ir/TestCompile/filters/label-filter/2.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 64 additions & 0 deletions testdata/d2ir/TestCompile/filters/lazy-filter.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d03082d

Please sign in to comment.