Add ES2024/ES2025 polyfills with fixes for reduce bug, groupBy prototype safety, and iterator resilience#105
Merged
mattcosta7 merged 3 commits intomainfrom Feb 20, 2026
Conversation
…safety, and iterator resilience Co-authored-by: mattcosta7 <8616962+mattcosta7@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix Iterator.prototype.reduce polyfill bug for Safari compatibility
Add ES2024/ES2025 polyfills with fixes for reduce bug, groupBy prototype safety, and iterator resilience
Feb 20, 2026
8 tasks
alidusha
previously approved these changes
Feb 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds ES2024/ES2025 polyfills (Object.groupBy, Map.groupBy, Promise.try, Iterator helpers/Iterator.from) with Safari-compatibility fixes, plus a corresponding test suite, and wires these polyfills into the library’s exported polyfills set.
Changes:
- Introduces new polyfill modules for
Object.groupBy,Map.groupBy,Promise.try, and Iterator helpers (including areduceinitialValue detection fix + chaining fallback). - Adds test coverage for the new polyfills, including
reduce()edge cases and__proto__handling forObject.groupBy. - Exports/registers the new polyfills in
src/index.tsand updates the lockfile.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/iterator-helpers.ts | Implements iterator helper polyfills, Iterator.from, and reduce fix; adds fallback prototype behavior |
| src/object-groupby.ts | Adds Object.groupBy polyfill using null-prototype result + own-property checks |
| src/map-groupby.ts | Adds Map.groupBy polyfill |
| src/promise-try.ts | Adds Promise.try polyfill |
| src/index.ts | Registers new polyfills in the exported polyfills object |
| test/iterator-helpers.js | Adds iterator helper tests, including reduce() edge cases and chaining |
| test/object-groupby.js | Adds Object.groupBy tests including __proto__ safety |
| test/map-groupby.js | Adds Map.groupBy tests |
| test/promise-try.js | Adds Promise.try tests |
| package-lock.json | Lockfile metadata changes (adds "peer": true flags in several entries) |
Comments suppressed due to low confidence (1)
src/iterator-helpers.ts:314
- isSupported() treats globalThis.Iterator as supported only when
typeof IteratorConstructor === 'object'and only checks'from' in IteratorConstructor. If a native Iterator exists as a function/constructor (orfromexists but is non-callable), isSupported() can return false/true incorrectly and impact the library-wide isSupported() signal. Consider allowing function-or-object and verifyingtypeof IteratorConstructor.from === 'function'(similar to other polyfills in this repo).
const IteratorConstructor = (globalThis as typeof globalThis & {Iterator?: {from?: unknown}}).Iterator
return (
IteratorPrototype !== null &&
'map' in IteratorPrototype &&
'filter' in IteratorPrototype &&
'take' in IteratorPrototype &&
'drop' in IteratorPrototype &&
'flatMap' in IteratorPrototype &&
'reduce' in IteratorPrototype &&
'toArray' in IteratorPrototype &&
'forEach' in IteratorPrototype &&
'some' in IteratorPrototype &&
'every' in IteratorPrototype &&
'find' in IteratorPrototype &&
IteratorConstructor !== undefined &&
typeof IteratorConstructor === 'object' &&
IteratorConstructor !== null &&
'from' in IteratorConstructor
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ve iterables in iteratorFrom, complete isPolyfilled check, string Iterator.from test Co-authored-by: mattcosta7 <8616962+mattcosta7@users.noreply.github.com>
manuelpuyol
approved these changes
Feb 20, 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.
getIteratorPrototype()– use Array iterator chain instead ofnew GeneratorFunction(...)to avoid CSP eval violationiteratorFrom()– box primitives withObject(obj)so strings and other primitive iterables are acceptedisPolyfilled()– check all 11 helper methods (filter, take, drop, flatMap, reduce, toArray, forEach, some, every, find, and map), not justmapIterator.from('abc')string testOriginal prompt
This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.