mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
This is a quick "good enough" first pass at computing function expression context variables. It definitely needs to be overhauled, but it's enough to make a lot of common cases work correctly. First, this PR adds a hand-rolled Visitor trait for `estree`. Long-term that should probably be code-generated, but there are some subtleties to it such as the `visit_lvalue(callback)` helper which has to be wrapped around various calls (or we need some other way to distinguish identifiers within lvalues from identifiers within rvaluess). So for now it makes sense to hand-roll it until we are more confident in exactly how it should work. Given that visitor, i was able to port part of the existing `gatherCapturedDeps()` to Rust with some modifications. Note that we assume _something_ has run name resolution on the estree to match up identifiers to the declaration they refer to. But we don't store information about parent scopes so we can't walk up to check where things were defined. Instead we do the following: * Build up a list of all referenced identifiers * Also build up a set of bindings defined in the function itself * After visiting, filter our the first list to only include identifiers not defined by the function itself, and to eliminate duplicates. This covers the majority of cases: the most obvious gap is nested function expressions though actually that should just work.