fix: inherit parent override in reflect template - #55
Merged
aspirisen merged 1 commit intoJul 27, 2026
Conversation
aspirisen
approved these changes
Jul 27, 2026
|
🎉 This PR is included in version 0.10.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Collaborator
|
Thank you for the contribution ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When calling
reflect()on a lens that is itself the result of a previousreflect(), fields accessed through the getter's dictionary proxy resolved to plain paths instead of going through the parent's override mapping.For example:
The second
reflectlostreflect1's mapping (bar → foo) and resolvedbaras a literal path.Root cause
In
LensCore#reflect, a freshtemplatelens is created to back the dictionary proxy. However, this template did not inherit the parent lens'soverride, so when the getter calledtemplate.focus('bar'), thefocusmethod took the plain-lens branch (LensCore.ts:95) — which just appendsbartotemplate.path— instead of resolving through the parent's override mapping.Failing test
tests/object-reflect.test.ts > reflect can be called on the result of a previous reflectThe first assertion passed (
reflect1.focus('bar').interop().namewas'foo'), the second failed (reflect2.focus('baz').interop().namewas'bar'instead of'foo').Fix
Inherit the parent's
overrideon the template before invoking the getter (src/LensCore.ts:114):This way
template.focus('bar')resolves throughreflect1's override topath='foo'. After the getter returns, the template's override is replaced with the new mapping (template.override = override), so the inherited override is only used during getter execution and doesn't leak into the returned lens. Theifguard avoids a type error underexactOptionalPropertyTypes: true.All 55 unit tests pass with no type errors.