d2ir: Ensure new scenario map doesn't re overlay
This commit is contained in:
parent
88b885a753
commit
4523b503a7
3 changed files with 2645 additions and 19 deletions
|
|
@ -693,31 +693,31 @@ func (c *compiler) _compileField(f *Field, refctx *RefContext) {
|
|||
c.compileArray(a, refctx.Key.Value.Array, refctx.ScopeAST)
|
||||
f.Composite = a
|
||||
} else if refctx.Key.Value.Map != nil {
|
||||
scopeAST := refctx.Key.Value.Map
|
||||
if f.Map() == nil {
|
||||
f.Composite = &Map{
|
||||
parent: f,
|
||||
}
|
||||
}
|
||||
scopeAST := refctx.Key.Value.Map
|
||||
switch NodeBoardKind(f) {
|
||||
case BoardScenario:
|
||||
c.overlay(ParentBoard(f).Map(), f)
|
||||
case BoardStep:
|
||||
stepsMap := ParentMap(f)
|
||||
for i := range stepsMap.Fields {
|
||||
if stepsMap.Fields[i] == f {
|
||||
if i == 0 {
|
||||
c.overlay(ParentBoard(f).Map(), f)
|
||||
} else {
|
||||
c.overlay(stepsMap.Fields[i-1].Map(), f)
|
||||
switch NodeBoardKind(f) {
|
||||
case BoardScenario:
|
||||
c.overlay(ParentBoard(f).Map(), f)
|
||||
case BoardStep:
|
||||
stepsMap := ParentMap(f)
|
||||
for i := range stepsMap.Fields {
|
||||
if stepsMap.Fields[i] == f {
|
||||
if i == 0 {
|
||||
c.overlay(ParentBoard(f).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.compileMap(f.Map(), refctx.Key.Value.Map, scopeAST)
|
||||
|
|
|
|||
|
|
@ -416,10 +416,27 @@ scenarios: {
|
|||
}
|
||||
}`)
|
||||
assert.Success(t, err)
|
||||
|
||||
assertQuery(t, m, 8, 2, nil, "")
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
2609
testdata/d2ir/TestCompile/scenarios/multiple-scenario-map.exp.json
generated
vendored
Normal file
2609
testdata/d2ir/TestCompile/scenarios/multiple-scenario-map.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue