mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Refactor reactive scope representation
This commit is contained in:
@@ -68,9 +68,7 @@ class Builder {
|
||||
startScope(scope: ReactiveScope): void {
|
||||
const block: ReactiveBlock = {
|
||||
kind: "block",
|
||||
id: scope.id,
|
||||
range: scope.range,
|
||||
dependencies: scope.dependencies,
|
||||
scope,
|
||||
instructions: [],
|
||||
};
|
||||
this.append(block, undefined);
|
||||
@@ -80,8 +78,8 @@ class Builder {
|
||||
|
||||
visitId(id: InstructionId): void {
|
||||
for (let i = 0; i < this.#stack.length; i++) {
|
||||
const scope = this.#stack[i]!;
|
||||
if (scope.kind === "scope" && id >= scope.block.range.end) {
|
||||
const entry = this.#stack[i]!;
|
||||
if (entry.kind === "scope" && id >= entry.block.scope.range.end) {
|
||||
this.#stack.length = i;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -52,9 +52,7 @@ export type ReactiveFunction = {
|
||||
|
||||
export type ReactiveBlock = {
|
||||
kind: "block";
|
||||
id: ScopeId;
|
||||
range: MutableRange;
|
||||
dependencies: Set<Place>;
|
||||
scope: ReactiveScope;
|
||||
instructions: ReactiveBasicBlock;
|
||||
};
|
||||
|
||||
|
||||
@@ -36,9 +36,9 @@ export function printReactiveFunction(fn: ReactiveFunction): string {
|
||||
|
||||
export function printReactiveBlock(writer: Writer, block: ReactiveBlock): void {
|
||||
writer.writeLine(
|
||||
`scope @${block.id} [${block.range.start}:${
|
||||
block.range.end
|
||||
}] deps=[${Array.from(block.dependencies)
|
||||
`scope @${block.scope.id} [${block.scope.range.start}:${
|
||||
block.scope.range.end
|
||||
}] deps=[${Array.from(block.scope.dependencies)
|
||||
.map((dep) => printPlace(dep))
|
||||
.join(", ")}] {`
|
||||
);
|
||||
|
||||
@@ -64,9 +64,9 @@ function visit(
|
||||
item.instructions,
|
||||
scopeDependencies,
|
||||
scopeDeclarations,
|
||||
item.range.start
|
||||
item.scope.range.start
|
||||
);
|
||||
item.dependencies = scopeDependencies;
|
||||
item.scope.dependencies = scopeDependencies;
|
||||
for (const dep of scopeDependencies) {
|
||||
// propagate dependencies upward using the same rules as
|
||||
// normal dependency collection. child scopes may have dependencies
|
||||
|
||||
Reference in New Issue
Block a user