You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, the page on scoping within GritQL fails to clearly mention a notable fact about patterns - parameters flow bidirectionally across boundaries.
Any metavariables passed as parameters will be mutated upon returning to the calling scope, a concept that I only discovered after trying random stuff on the playground for 2 hours straight.
As such, I suggest adding an example where a pattern is used to "bind" portions of a larger match to variables at callsites.
Contrived example snippet
// matches an `expect(x).toBe(y)` call and binds the results to `name` and `value`.
pattern match_expect($name, $value) {
`expect($name).toBe($value)`
}
// n and v are filled in with the values set during match_expect
match_expect(name=$n, value=$v) where {
$n <: `foo` => `bar`,
$v <: `baz` => `quux`,
}
Currently, the page on scoping within GritQL fails to clearly mention a notable fact about
patterns - parameters flow bidirectionally across boundaries.Any metavariables passed as parameters will be mutated upon returning to the calling scope, a concept that I only discovered after trying random stuff on the playground for 2 hours straight.
As such, I suggest adding an example where a pattern is used to "bind" portions of a larger match to variables at callsites.
Contrived example snippet
converts
expect(foo).toBe(baz)==>expect(bar).toBe(quux)Note
I put this here mainly for inspiration; you folks can likely come up with much better examples than me.