dillon1000/react
Commit
Browse files [hir] Refactor useMemo inlining
Previously useMemo inlining created a new StoreLocal assignment (not
reassignment!) instruction for every return value. This breaks when the return
is inside a block (like an if-block) as the scope is tied to the block.
For example: ``` let x = useMemo(() => { if (...) { return { ... }; } })
``` would become: ``` if (...) { const temp = { ... }; } const x = temp; ```
This PR instead changes the inlining to declare a temporary in the function
prologue and then reassign values to it when replacing return statements.
``` let x = useMemo(() => { if (...) { return { ... }; } }) ```
becomes
``` let temp; if (...) { temp = { ... }; } const x = temp; ```Changed paths9 files
First-parent comparisoncompiler/forget/src/Inference/InlineUseMemo.ts ModifiedM compiler/forget/src/__tests__/fixtures/compiler/useMemo-if-else-multiple-return.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/useMemo-independently-memoizeable.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/useMemo-inlining-block-return.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/useMemo-labeled-statement-unconditional-return.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/useMemo-logical.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/useMemo-multiple-if-else.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/useMemo-simple.expect.md ModifiedM compiler/forget/src/__tests__/fixtures/compiler/useMemo-switch-no-fallthrough.expect.md ModifiedPatch
Files changed
Rendering syntax-highlighted changes…