dillon1000/react
Commit
Browse files Fix temporaries accessed outside of their defining scope
Fixed a bug identified in repro cases earlier in the stack. The case is where some later value is composed of several values, say A and B, where A is an identifier that is reassigned within B. Also, the mutable range of B surrounds the evaluation of A. In this case, the reference to A gets lowered to a temporary (say a t0 = LoadLocal A), and that temporary is created within the reactive scope for B. PropagateScopeDependencies bypasses LoadLocal indirections, and considers the reference to the temporary (t0) as if it was a reference to the identifier (A). That breaks the whole reason we lower Identifiers to temporaries - to preserve evaluation order. This PR fixes the bug by promoting temporaries to names values if they are referenced outside their defining scope. So, the reference to t0 stays a reference to t0, which correctly preserves the value of A at the right point in time. This is all much easier to see in the new test case.
Changed paths6 files
First-parent comparisoncompiler/forget/src/ReactiveScopes/PropagateScopeDependencies.ts ModifiedD compiler/forget/src/__tests__/fixtures/compiler/error.jsx-tag-evaluation-order.expect.md DeletedA compiler/forget/src/__tests__/fixtures/compiler/jsx-tag-evaluation-order-non-global.expect.md AddedR compiler/forget/src/__tests__/fixtures/compiler/error.jsx-tag-evaluation-order.js →compiler/forget/src/__tests__/fixtures/compiler/jsx-tag-evaluation-order-non-global.js RenamedA compiler/forget/src/__tests__/fixtures/compiler/reassigned-temporary-accessed-outside-scope.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/reassigned-temporary-accessed-outside-scope.js AddedPatch
Files changed
Rendering syntax-highlighted changes…