d2ir: Add exception for &label filter
This commit is contained in:
parent
976ec17476
commit
1800ae3448
4 changed files with 1300 additions and 1 deletions
|
|
@ -804,6 +804,10 @@ func (kp *KeyPath) Copy() *KeyPath {
|
||||||
return &kp2
|
return &kp2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (kp *KeyPath) Last() *StringBox {
|
||||||
|
return kp.Path[len(kp.Path)-1]
|
||||||
|
}
|
||||||
|
|
||||||
func IsDoubleGlob(pattern []string) bool {
|
func IsDoubleGlob(pattern []string) bool {
|
||||||
return len(pattern) == 3 && pattern[0] == "*" && pattern[1] == "" && pattern[2] == "*"
|
return len(pattern) == 3 && pattern[0] == "*" && pattern[1] == "" && pattern[2] == "*"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -414,6 +414,7 @@ func (c *compiler) compileMap(dst *Map, ast, scopeAST *d2ast.Map) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, n := range ast.Nodes {
|
for _, n := range ast.Nodes {
|
||||||
switch {
|
switch {
|
||||||
case n.MapKey != nil:
|
case n.MapKey != nil:
|
||||||
|
|
@ -554,8 +555,31 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if len(fa) == 0 {
|
if len(fa) == 0 {
|
||||||
|
if refctx.Key.Key.Last().ScalarString() != "label" {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
kp := refctx.Key.Key.Copy()
|
||||||
|
kp.Path = kp.Path[:len(kp.Path)-1]
|
||||||
|
if len(kp.Path) == 0 {
|
||||||
|
fa = append(fa, ParentField(refctx.ScopeMap))
|
||||||
|
} else {
|
||||||
|
fa, err = refctx.ScopeMap.EnsureField(kp, refctx, false, c)
|
||||||
|
if err != nil {
|
||||||
|
c.err.Errors = append(c.err.Errors, err.(d2ast.Error))
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, f := range fa {
|
||||||
|
label := f.Name
|
||||||
|
if f.Primary_ != nil {
|
||||||
|
label = f.Primary_.Value.ScalarString()
|
||||||
|
}
|
||||||
|
if label != refctx.Key.Value.ScalarBox().Unbox().ScalarString() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
for _, f := range fa {
|
for _, f := range fa {
|
||||||
ok := c._ampersandFilter(f, refctx)
|
ok := c._ampersandFilter(f, refctx)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
||||||
|
|
@ -96,6 +96,31 @@ x -> y
|
||||||
assertQuery(t, m, 0, 0, nil, "(x -> y)[1]")
|
assertQuery(t, m, 0, 0, nil, "(x -> y)[1]")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "id-filter",
|
||||||
|
run: func(t testing.TB) {
|
||||||
|
m, err := compile(t, `
|
||||||
|
x
|
||||||
|
y
|
||||||
|
p: p
|
||||||
|
|
||||||
|
*.style.opacity: 0.1
|
||||||
|
*: {
|
||||||
|
&label: x
|
||||||
|
style.opacity: 1
|
||||||
|
}
|
||||||
|
*: {
|
||||||
|
&label: p
|
||||||
|
style.opacity: 0.5
|
||||||
|
}
|
||||||
|
`)
|
||||||
|
assert.Success(t, err)
|
||||||
|
assertQuery(t, m, 9, 0, nil, "")
|
||||||
|
assertQuery(t, m, 0, 0, 1, "x.style.opacity")
|
||||||
|
assertQuery(t, m, 0, 0, 0.1, "y.style.opacity")
|
||||||
|
assertQuery(t, m, 0, 0, 0.5, "p.style.opacity")
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
runa(t, tca)
|
runa(t, tca)
|
||||||
|
|
|
||||||
1246
testdata/d2ir/TestCompile/filters/id-filter.exp.json
generated
vendored
Normal file
1246
testdata/d2ir/TestCompile/filters/id-filter.exp.json
generated
vendored
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue