Skip to content

Commit

Permalink
d2ir: Fixup lazy globs across imports
Browse files Browse the repository at this point in the history
  • Loading branch information
nhooyr committed Sep 4, 2023
1 parent b1f9083 commit 5ac1db3
Show file tree
Hide file tree
Showing 5 changed files with 1,438 additions and 5 deletions.
3 changes: 0 additions & 3 deletions d2ir/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,6 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
if !gctx.refctx.Key.HasTripleGlob() {
continue
}
if gctx.refctx.ScopeMap != impn.Map() {
continue
}
gctx2 := gctx.copy()
gctx2.refctx.ScopeMap = dst
c.compileKey(gctx2.refctx)
Expand Down
3 changes: 2 additions & 1 deletion d2ir/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (c *compiler) _import(imp *d2ast.Import) (Node, bool) {
if !ok {
return nil, false
}
nilScopeMap(ir)
// Not sure why this was here...
// nilScopeMap(ir)
if len(imp.IDA()) > 0 {
f := ir.GetField(imp.IDA()...)
if f == nil {
Expand Down
22 changes: 21 additions & 1 deletion d2ir/pattern_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ two
},
},
{
name: "import-glob",
name: "import-glob/1",
run: func(t testing.TB) {
m, err := compileFS(t, "index.d2", map[string]string{
"index.d2": "before; ...@globs.d2; after",
Expand All @@ -750,6 +750,26 @@ two
assertQuery(t, m, 0, 0, "meow", "after")
},
},
{
name: "import-glob/2",
run: func(t testing.TB) {
m, err := compileFS(t, "index.d2", map[string]string{
"index.d2": `...@rules.d2
hi
`,
"rules.d2": `***.style.fill: red
***: meow
x`,
})
assert.Success(t, err)

assertQuery(t, m, 6, 0, nil, "")
assertQuery(t, m, 2, 0, "meow", "hi")
assertQuery(t, m, 2, 0, "meow", "x")
assertQuery(t, m, 0, 0, "red", "hi.style.fill")
assertQuery(t, m, 0, 0, "red", "x.style.fill")
},
},
}

runa(t, tca)
Expand Down
Loading

0 comments on commit 5ac1db3

Please sign in to comment.