Skip to content

Add Iterator.prototype bindings #7506

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

nojaf
Copy link
Collaborator

@nojaf nojaf commented May 23, 2025

This may be a bit controversial, but I've added bindings for Iterators and Generators and corrected some bindings, resulting in a minor breaking change.

Copy link

pkg-pr-new bot commented May 23, 2025

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript-lang/rescript@7506

@rescript/darwin-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-arm64@7506

@rescript/linux-arm64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-arm64@7506

@rescript/linux-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/linux-x64@7506

@rescript/darwin-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/darwin-x64@7506

@rescript/win32-x64

npm i https://pkg.pr.new/rescript-lang/rescript/@rescript/win32-x64@7506

commit: c40bf36

@nojaf nojaf marked this pull request as ready for review May 23, 2025 08:55
external toArrayWithMapper: (t<'a>, 'a => 'b) => array<'b> = "Array.from"

let forEach = (iterator, f) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm for this change 👍

Iterator.forEach's behaviour was different to Iterator.prototype.forEach as the latter only calls its callback with yielded values, not the iterator's final return value.

Copy link
Member

@cknitt cknitt left a comment

Choose a reason for hiding this comment

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

Great stuff, thanks a lot!

But could you use tests (using assertEqual) instead of doing Console.logs in the doc strings?

package.json Outdated
@@ -86,6 +86,7 @@
"@types/node": "^20.14.9",
"@types/semver": "^7.7.0",
"@yarnpkg/types": "^4.0.1",
"es-iterator-helpers": "1.2.1",
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should move to Node 22 for dev instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm unsure how straightforward it is to use one Node version for x and another for y. I'm curious to hear what @cometkim thinks!

Copy link
Member

Choose a reason for hiding this comment

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

I meant increase it from 20 to 22 in .nvmrc. This would then be picked up by CI, and by your node version manager when working in local dev.

The minimum version in package.json can remain 20 as that's still supported for another year.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I see. How can we ensure that we don't use any newer Node features in our CLI scripts? That happened some time ago.

Copy link
Member

Choose a reason for hiding this comment

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

We could run the test-integration step of the CI build with the oldest supported node version. (Not sure if that would catch everything though, it should also try rescript format then for example.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, that could work.

@nojaf
Copy link
Collaborator Author

nojaf commented May 23, 2025

But could you use tests (using assertEqual) instead of doing Console.logs in the doc strings?

Yep, will do! I'm less familiar with that part of the codebase.

@@ -1,5 +1,9 @@
include Core_IntlTests

%%raw(`
import 'es-iterator-helpers/auto';
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be removed now (should work without it in Node 22).

@@ -478,7 +478,7 @@ jobs:
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
node-version: 20
Copy link
Member

Choose a reason for hiding this comment

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

Let's add a comment here:

Suggested change
node-version: 20
# Run integration tests with the oldest supported node version.
node-version: 20

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.

3 participants