Skip to content

fix/compat array fill iteratee guard - #1952

Open
kojesung wants to merge 5 commits into
toss:mainfrom
kojesung:fix/compat-array-fill-iteratee-guard
Open

fix/compat array fill iteratee guard#1952
kojesung wants to merge 5 commits into
toss:mainfrom
kojesung:fix/compat-array-fill-iteratee-guard

Conversation

@kojesung

@kojesung kojesung commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Previously, es-toolkit/compat's fill appeared to fill each element of the inner arrays with the index the same as lodash when used as a .map callback on a 2D array like [[1, 2], [3, 4]]. However, this wasn't because an isIterateeCall guard existed; it succeeded only by coincidence, because the outer array passed in by .map turned into NaN after going through Math.floor(), and was then coincidentally reset to 0 by the if (!start) start = 0 handling in fill.ts. A test case was added for an exceptional situation where this coincidence does not hold (when the outer array has a single element).
  • When fill is used directly as a .map callback (array.map(fill)), lodash resets start/end to their default values via the isIterateeCall guard, but es-toolkit/compat's fill lacked this guard, causing it to behave differently from lodash in certain cases. Specifically, when the outer array has a single element ([[5]].map(fill)), Number([[5]]) coincidentally converts to 5, and start=5 ends up exceeding the array's length (1), so nothing gets filled — a bug. To prevent this case, the fix reuses the same isIterateeCall helper already used in every/slice/...

@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
es-toolkit Ready Ready Preview, Comment Jul 29, 2026 12:44am

Request Review

@kojesung kojesung changed the title Fix/compat array fill iteratee guard fix/compat array fill iteratee guard Jul 26, 2026
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.

1 participant