dillon1000/react
Commit
Browse files Construct LoadGlobal; consume hook info from types
Updates BuildHIR to produce LoadGlobal instructions for references to globals. Note that this breaks our previous strategy of finding hook calls: that relied on looking at the callee of a CallExpression and checking its name, which relied on the callee not being lowered to a temporary. By lowering the name (eg `useState`) to a temporary first, we now no longer see the name at the callsite. Thankfully @gsathya solved this for us already by teaching type inference about hooks, and more generally implementing type inference. I updated this so that we infer the type of a LoadGlobal if the name is a hook: the type inference picks this up and propagates the type forward correctly. So now, all places that needed to check for a hook can just look at the type and everything works. This is much more robust than before - you can now reassign a hook to a local variable and we'll still detect that when you call it, you're calling a hook.
Changed paths11 files
First-parent comparisoncompiler/forget/src/HIR/BuildHIR.ts ModifiedM compiler/forget/src/HIR/Globals.ts ModifiedM compiler/forget/src/HIR/HIR.ts ModifiedM compiler/forget/src/HIR/HIRBuilder.ts ModifiedM compiler/forget/src/Inference/DropMemoCalls.ts ModifiedM compiler/forget/src/Inference/InferReferenceEffects.ts ModifiedM compiler/forget/src/ReactiveScopes/FlattenScopesWithHooks.ts ModifiedM compiler/forget/src/ReactiveScopes/InferReactiveIdentifiers.ts ModifiedM compiler/forget/src/TypeInference/InferTypes.ts ModifiedA compiler/forget/src/__tests__/fixtures/hir/useRef-rename-mutable.expect.md AddedA compiler/forget/src/__tests__/fixtures/hir/useRef-rename-mutable.js AddedPatch
Files changed
Rendering syntax-highlighted changes…