Skip to content

Commit ca5fef0

Browse files
committed
[compiler] Flatten scopes based on fallthrough, not scope range
Once we create scopes, we should prefer to use the block structure to identify active scope ranges rather than the scope range. They _should_ always be in sync, but ultimately the block structure determine the active range (ie the id of the 'scope' terminal and the terminal's fallthrough block). ghstack-source-id: 730b6d1 Pull Request resolved: #30398
1 parent 7c70878 commit ca5fef0

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

compiler/packages/babel-plugin-react-compiler/src/ReactiveScopes/FlattenScopesWithHooksOrUseHIR.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
HIRFunction,
1212
LabelTerminal,
1313
PrunedScopeTerminal,
14-
ReactiveScope,
1514
getHookKind,
1615
isUseOperator,
1716
} from '../HIR';
@@ -39,12 +38,11 @@ import {retainWhere} from '../Utils/utils';
3938
* to ensure the hook call does not inadvertently become conditional.
4039
*/
4140
export function flattenScopesWithHooksOrUseHIR(fn: HIRFunction): void {
42-
const activeScopes: Array<{block: BlockId; scope: ReactiveScope}> = [];
41+
const activeScopes: Array<{block: BlockId; fallthrough: BlockId}> = [];
4342
const prune: Array<BlockId> = [];
4443

4544
for (const [, block] of fn.body.blocks) {
46-
const firstId = block.instructions[0]?.id ?? block.terminal.id;
47-
retainWhere(activeScopes, current => current.scope.range.end > firstId);
45+
retainWhere(activeScopes, current => current.fallthrough !== block.id);
4846

4947
for (const instr of block.instructions) {
5048
const {value} = instr;
@@ -66,7 +64,7 @@ export function flattenScopesWithHooksOrUseHIR(fn: HIRFunction): void {
6664
if (block.terminal.kind === 'scope') {
6765
activeScopes.push({
6866
block: block.id,
69-
scope: block.terminal.scope,
67+
fallthrough: block.terminal.fallthrough,
7068
});
7169
}
7270
}

0 commit comments

Comments
 (0)