Repository navigation
Conversation
- Resolve the parent like lodash: the object itself for single-key paths, otherwise the value at the parent path - Stop falling back to the root object, which called an unrelated method (or threw) when a middle key was missing
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change correcting missing-parent handling in invoke.
No open issues 🎉
What changed in this PR
Fixes #2216 by aligning es-toolkit/compat’s invoke with Lodash when an intermediate path is missing, preventing unintended calls to methods on the root object.
Changes:
- Preserve the root object for single-key paths without using it as a fallback for missing parent paths.
- Add regression tests for undefined and absent parents, array-form paths, and the reported
['ab'], 'a[0]'crash.
| File | Description |
|---|---|
src/compat/util/invoke.ts |
Removes the root-object fallback when resolving nested parents. |
src/compat/util/invoke.spec.ts |
Tests that missing intermediate paths return undefined. |
Review effort: Balanced
This branch was successfully deployed
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.
Summary
Fixes #2216
invokein compat called a method on the root object when a key in the middle of the path was missing. lodash returnsundefinedin that case. Details and repro are in the issue.Changes
parent()does: the object itself for single-key paths, otherwisegeton the parent path with no default.['ab'], 'a[0]'crash.