[be] Refactor capturePureScopes to be more generic
Sathya Gunasekaran committed
Jan 14, 2023 at 10:19 UTC
e8cad1584c6d9ec31993636a709886b4fbf9bc78
1 file changed
+11
-14
compiler/forget/src/HIR/BuildHIR.ts
+11
-14
@@ -1625,21 +1625,18 @@ function lowerAssignment(
1625
}
1626
}
1627
1628
-function capturePureScopes(
1629
- currentScope: Scope,
1630
- componentScope: Scope
1631
-): Set<Scope> {
1632
- let pureScopes: Set<Scope> = new Set();
1633
- while (currentScope) {
1634
- pureScopes.add(currentScope);
1628
+function captureScopes({ from, to }: { from: Scope; to: Scope }): Set<Scope> {
1629
+ let scopes: Set<Scope> = new Set();
1630
+ while (from) {
1631
+ scopes.add(from);
1632
1636
- if (currentScope === componentScope) {
1633
+ if (from === to) {
1634
break;
1635
}
1636
1640
- currentScope = currentScope.parent;
1637
+ from = from.parent;
1638
}
1642
- return pureScopes;
1639
+ return scopes;
1640
}
1641
1642
function gatherCapturedDeps(
@@ -1651,10 +1648,10 @@ function gatherCapturedDeps(
1648
1649
// Capture all the scopes from the parent of this function up to and including
1650
// the component scope.
1654
- const pureScopes: Set<Scope> = capturePureScopes(
1655
- fn.scope.parent,
1656
- componentScope
1657
- );
1651
+ const pureScopes: Set<Scope> = captureScopes({
1652
+ from: fn.scope.parent,
1653
+ to: componentScope,
1654
+ });
1655
1656
fn.get("body").traverse({
1657
Expression(path) {