Skip to content

Add iterator implementation to Collections#680

Merged
Daniel15 merged 1 commit into
facebook:mainfrom
codingjoe:issues/679/collection-iterator
May 19, 2026
Merged

Add iterator implementation to Collections#680
Daniel15 merged 1 commit into
facebook:mainfrom
codingjoe:issues/679/collection-iterator

Conversation

@codingjoe

@codingjoe codingjoe commented Jan 7, 2026

Copy link
Copy Markdown
Contributor

ES6 iterators support the new for..of syntax. Since a Collection wraps an Array, we can lean on ECMAScript's new iterator delegation.

Resolve #679

I am working on esupgrade a tool to upgrade JS/TS code to widely available ECMAScript features. It's built on this wonderful tool. I'd really love to keep esupgrade's code base up to date too, and using for..of loops and generators would help tremendously.

Thanks for your consideration and for publishing this under a free license <3

Copilot AI review requested due to automatic review settings January 7, 2026 22:41
@changeset-bot

changeset-bot Bot commented Jan 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eca1a75

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
jscodeshift Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jan 7, 2026

Copy link
Copy Markdown

@codingjoe is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds ES6 iterator support to the Collection class, enabling the use of for-of loops when working with Collections. The implementation uses a generator function that delegates to the underlying __paths array.

Key changes:

  • Implements Symbol.iterator as a generator method in the Collection class
  • Adds test coverage for the new iterator functionality

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Collection.js Adds iterator implementation using generator delegation and JSDoc annotations
src/tests/Collection-test.js Adds test case verifying iterator works correctly with for-of loops

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Collection.js Outdated
Comment thread src/Collection.js Outdated
@codingjoe codingjoe force-pushed the issues/679/collection-iterator branch 3 times, most recently from 24499e4 to c06da00 Compare January 7, 2026 22:49
ES6 iterators support the new for..of syntax. Since a Collection wraps an Array,
we can lean on ECMAScripts new iterator delegation.

Resolve facebook#679
@codingjoe codingjoe force-pushed the issues/679/collection-iterator branch from c06da00 to eca1a75 Compare January 7, 2026 22:51
Comment thread src/Collection.js
@Daniel15

Daniel15 commented Jan 7, 2026

Copy link
Copy Markdown
Member

Looks pretty good to me! Just left a small comment inline.

@codingjoe codingjoe requested a review from Daniel15 January 8, 2026 13:52
@codingjoe

codingjoe commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

/ping @Daniel15 :)

@Daniel15 Daniel15 merged commit 0ced828 into facebook:main May 19, 2026
1 of 2 checks passed
@codingjoe codingjoe deleted the issues/679/collection-iterator branch May 20, 2026 09:25
@codingjoe

Copy link
Copy Markdown
Contributor Author

<3 thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Collection isn't iterable

3 participants