mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[facepalm] Fix bug w missing deps
While reviewing @poteto's PR I noticed that there were some cases of missing dependencies. I tracked it down to a bug I introduced [here](https://github.com/facebook/react-forget/commit/5b827eb85ce0b09a72e620449d1d676071c2e0b9#r100646304). Decl.id is meant to be the id of the instruction that declares the variable. We then test to see if a dependency is later than that. If the Decl.id is incorrectly too high, then we miss some dependencies thinking they aren't defined yet.
This commit is contained in:
@@ -151,6 +151,7 @@ class Context {
|
||||
}
|
||||
|
||||
const decl = this.#declarations.get(maybeDependency.place.identifier.id);
|
||||
|
||||
// if decl is undefined here, then this is a free var
|
||||
// (all other decls e.g. `let x;` should be initialized in BuildHIR)
|
||||
|
||||
@@ -376,7 +377,7 @@ function visitInstruction(context: Context, instr: ReactiveInstruction): void {
|
||||
} else {
|
||||
context.declare(lvalue.place.identifier, {
|
||||
kind: DeclKind.Dynamic,
|
||||
id: lvalue.place.identifier.mutableRange.start,
|
||||
id: instr.id,
|
||||
scope: context.currentScope,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,14 +48,16 @@ function Component(props) {
|
||||
}
|
||||
|
||||
y.push(props.p2);
|
||||
const c_3 = $[3] !== y;
|
||||
const c_3 = $[3] !== x$0;
|
||||
const c_4 = $[4] !== y;
|
||||
let t0;
|
||||
if (c_3) {
|
||||
if (c_3 || c_4) {
|
||||
t0 = <Component x={x$0} y={y}></Component>;
|
||||
$[3] = y;
|
||||
$[4] = t0;
|
||||
$[3] = x$0;
|
||||
$[4] = y;
|
||||
$[5] = t0;
|
||||
} else {
|
||||
t0 = $[4];
|
||||
t0 = $[5];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
@@ -87,8 +87,9 @@ function foo(a, b, c) {
|
||||
}
|
||||
}
|
||||
const c_8 = $[8] !== y;
|
||||
const c_9 = $[9] !== x$0;
|
||||
let t0;
|
||||
if (c_8) {
|
||||
if (c_8 || c_9) {
|
||||
t0 = (
|
||||
<div>
|
||||
{y}
|
||||
@@ -96,9 +97,10 @@ function foo(a, b, c) {
|
||||
</div>
|
||||
);
|
||||
$[8] = y;
|
||||
$[9] = t0;
|
||||
$[9] = x$0;
|
||||
$[10] = t0;
|
||||
} else {
|
||||
t0 = $[9];
|
||||
t0 = $[10];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
@@ -46,8 +46,9 @@ function Component(props) {
|
||||
y$0 = $[3];
|
||||
}
|
||||
const c_4 = $[4] !== x;
|
||||
const c_5 = $[5] !== y$0;
|
||||
let t0;
|
||||
if (c_4) {
|
||||
if (c_4 || c_5) {
|
||||
t0 = (
|
||||
<Component>
|
||||
{x}
|
||||
@@ -55,9 +56,10 @@ function Component(props) {
|
||||
</Component>
|
||||
);
|
||||
$[4] = x;
|
||||
$[5] = t0;
|
||||
$[5] = y$0;
|
||||
$[6] = t0;
|
||||
} else {
|
||||
t0 = $[5];
|
||||
t0 = $[6];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
@@ -83,14 +83,16 @@ function Component(props) {
|
||||
child = $[6];
|
||||
}
|
||||
y$0.push(props.p4);
|
||||
const c_7 = $[7] !== child;
|
||||
const c_7 = $[7] !== y$0;
|
||||
const c_8 = $[8] !== child;
|
||||
let t0;
|
||||
if (c_7) {
|
||||
if (c_7 || c_8) {
|
||||
t0 = <Component data={y$0}>{child}</Component>;
|
||||
$[7] = child;
|
||||
$[8] = t0;
|
||||
$[7] = y$0;
|
||||
$[8] = child;
|
||||
$[9] = t0;
|
||||
} else {
|
||||
t0 = $[8];
|
||||
t0 = $[9];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
@@ -66,14 +66,16 @@ function Component(props) {
|
||||
child = $[6];
|
||||
}
|
||||
y$0.push(props.p4);
|
||||
const c_7 = $[7] !== child;
|
||||
const c_7 = $[7] !== y$0;
|
||||
const c_8 = $[8] !== child;
|
||||
let t0;
|
||||
if (c_7) {
|
||||
if (c_7 || c_8) {
|
||||
t0 = <Component data={y$0}>{child}</Component>;
|
||||
$[7] = child;
|
||||
$[8] = t0;
|
||||
$[7] = y$0;
|
||||
$[8] = child;
|
||||
$[9] = t0;
|
||||
} else {
|
||||
t0 = $[8];
|
||||
t0 = $[9];
|
||||
}
|
||||
return t0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user