fix(compat): read sparse array holes as undefined in toString - #2091
Merged
Conversation
toString mapped array elements with Array.prototype.map, which skips holes in a sparse array. lodash reads every index, so a hole is rendered as 'undefined' rather than dropped: toString([1, , 3]) // es-toolkit: '1,,3' // lodash: '1,undefined,3' Iterate by index so holes are converted the same way lodash does.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
raon0211
approved these changes
Sep 8, 2026
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
compat/toStringrenders an array by mapping its elements withArray.prototype.map, which skips holes in a sparse array. lodash reads every index, so a hole is converted asundefinedrather than dropped:Changes
Iterate the array by index instead of using
.map, so each hole is read asundefinedand converted through the same path as any other element. Dense arrays are unaffected, and the-0, symbol, and nested-array handling stay the same.Added tests for sparse inputs.
Verified
Ran the compat implementation against
lodashat runtime across sparse, dense, nested, nullish,-0, and symbol arrays. All outputs match.