d2ir: Ensure new scenario map doesn't re overlay

This commit is contained in:
Anmol Sethi 2023-08-30 04:35:07 -07:00
parent 88b885a753
commit 4523b503a7
No known key found for this signature in database
GPG key ID: 8CEF1878FF10ADEB
3 changed files with 2645 additions and 19 deletions

View file

@ -693,31 +693,31 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) {
c.compileArray(a, refctx.Key.Value.Array, refctx.ScopeAST) c.compileArray(a, refctx.Key.Value.Array, refctx.ScopeAST)
f.Composite = a f.Composite = a
} else if refctx.Key.Value.Map != nil { } else if refctx.Key.Value.Map != nil {
scopeAST := refctx.Key.Value.Map
if f.Map() == nil { if f.Map() == nil {
f.Composite = &Map{ f.Composite = &Map{
parent: f, parent: f,
} }
} switch NodeBoardKind(f) {
scopeAST := refctx.Key.Value.Map case BoardScenario:
switch NodeBoardKind(f) { c.overlay(ParentBoard(f).Map(), f)
case BoardScenario: case BoardStep:
c.overlay(ParentBoard(f).Map(), f) stepsMap := ParentMap(f)
case BoardStep: for i := range stepsMap.Fields {
stepsMap := ParentMap(f) if stepsMap.Fields[i] == f {
for i := range stepsMap.Fields { if i == 0 {
if stepsMap.Fields[i] == f { c.overlay(ParentBoard(f).Map(), f)
if i == 0 { } else {
c.overlay(ParentBoard(f).Map(), f) c.overlay(stepsMap.Fields[i-1].Map(), f)
} else { }
c.overlay(stepsMap.Fields[i-1].Map(), f) break
} }
break
} }
case BoardLayer:
default:
// If new board type, use that as the new scope AST, otherwise, carry on
scopeAST = refctx.ScopeAST
} }
case BoardLayer:
default:
// If new board type, use that as the new scope AST, otherwise, carry on
scopeAST = refctx.ScopeAST
} }
c.mapRefContextStack = append(c.mapRefContextStack, refctx) c.mapRefContextStack = append(c.mapRefContextStack, refctx)
c.compileMap(f.Map(), refctx.Key.Value.Map, scopeAST) c.compileMap(f.Map(), refctx.Key.Value.Map, scopeAST)

View file

@ -416,10 +416,27 @@ scenarios: {
} }
}`) }`)
assert.Success(t, err) assert.Success(t, err)
assertQuery(t, m, 8, 2, nil, "")
assertQuery(t, m, 0, 0, nil, "(a -> b)[0]") assertQuery(t, m, 0, 0, nil, "(a -> b)[0]")
}, },
}, },
{
name: "multiple-scenario-map",
run: func(t testing.TB) {
m, err := compile(t, `a -> b: { style.opacity: 0.3 }
scenarios: {
1: {
(a -> b)[0].style.opacity: 0.1
}
1: {
z
}
}`)
assert.Success(t, err)
assertQuery(t, m, 11, 2, nil, "")
assertQuery(t, m, 0, 0, 0.1, "scenarios.1.(a -> b)[0].style.opacity")
},
},
} }
runa(t, tca) runa(t, tca)
} }

File diff suppressed because it is too large Load diff