Skip to content

fix(invoke): return undefined when an intermediate path is missing - #2217

Open
taham8875 wants to merge 1 commit into
toss:mainfrom
taham8875:fix/compat-invoke-missing-parent
Open

taham8875 wants to merge 1 commit into
toss:mainfrom
taham8875:fix/compat-invoke-missing-parent

Conversation

@taham8875

Copy link
Copy Markdown

Summary

Fixes #2216

invoke in compat called a method on the root object when a key in the middle of the path was missing. lodash returns undefined in that case. Details and repro are in the issue.

Changes

  • Resolve the parent the same way lodash's parent() does: the object itself for single-key paths, otherwise get on the parent path with no default.
  • Add a test that fails without the fix, covering a missing middle key and the ['ab'], 'a[0]' crash.

- 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
Copilot AI balanced review requested due to automatic review settings November 13, 2026 21:35
@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
es-toolkit Ready Ready Preview Nov 13, 2026 9:39pm UTC

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

1 active deployment
Preview — 39e87a4b Deployed Nov 13, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compat/invoke calls a method on the root object when a middle key is missing

2 participants