mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Track next scope id on Environment
Currently we allocate all reactive scopes during a single pass, InferReactiveScopeVariables, using a local incrementing number to assign ScopeIds. This means we can't easily create additional scopes later since we don't know the next available scope id. Here we add `Environment.nextScopeId` and use that to synthesize scope ids.
This commit is contained in:
@@ -24,10 +24,12 @@ import {
|
||||
FunctionType,
|
||||
IdentifierId,
|
||||
PolyType,
|
||||
ScopeId,
|
||||
Type,
|
||||
ValueKind,
|
||||
makeBlockId,
|
||||
makeIdentifierId,
|
||||
makeScopeId,
|
||||
} from "./HIR";
|
||||
import {
|
||||
BuiltInMixedReadonlyId,
|
||||
@@ -412,6 +414,7 @@ export class Environment {
|
||||
#shapes: ShapeRegistry;
|
||||
#nextIdentifer: number = 0;
|
||||
#nextBlock: number = 0;
|
||||
#nextScope: number = 0;
|
||||
config: EnvironmentConfig;
|
||||
|
||||
#contextIdentifiers: Set<t.Identifier>;
|
||||
@@ -460,6 +463,10 @@ export class Environment {
|
||||
return makeBlockId(this.#nextBlock++);
|
||||
}
|
||||
|
||||
get nextScopeId(): ScopeId {
|
||||
return makeScopeId(this.#nextScope++);
|
||||
}
|
||||
|
||||
isContextIdentifier(node: t.Identifier): boolean {
|
||||
return this.#contextIdentifiers.has(node);
|
||||
}
|
||||
|
||||
+1
-2
@@ -12,7 +12,6 @@ import {
|
||||
IdentifierId,
|
||||
Instruction,
|
||||
makeInstructionId,
|
||||
makeScopeId,
|
||||
Place,
|
||||
ReactiveScope,
|
||||
} from "../HIR/HIR";
|
||||
@@ -102,7 +101,7 @@ export function inferReactiveScopeVariables(fn: HIRFunction): void {
|
||||
let scope = scopes.get(groupIdentifier);
|
||||
if (scope === undefined) {
|
||||
scope = {
|
||||
id: makeScopeId(scopes.size),
|
||||
id: fn.env.nextScopeId,
|
||||
range: identifier.mutableRange,
|
||||
dependencies: new Set(),
|
||||
declarations: new Map(),
|
||||
|
||||
Reference in New Issue
Block a user