d2ir: Fixup lazy globs across imports

This commit is contained in:
Anmol Sethi 2023-09-04 13:08:04 -07:00
parent b1f9083ba1
commit 64c2c8467a
No known key found for this signature in database
GPG key ID: 8CEF1878FF10ADEB
4 changed files with 1436 additions and 4 deletions

View file

@ -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)

View file

@ -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",
@ -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)

1415
testdata/d2ir/TestCompile/patterns/import-glob/2.exp.json generated vendored Normal file

File diff suppressed because it is too large Load diff