Skip to content

Commit c40bf36

Browse files
committed
Polyfill iterator
1 parent 273219e commit c40bf36

File tree

8 files changed

+1013
-43
lines changed

8 files changed

+1013
-43
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
"@types/node": "^20.14.9",
8787
"@types/semver": "^7.7.0",
8888
"@yarnpkg/types": "^4.0.1",
89+
"es-iterator-helpers": "1.2.1",
8990
"mocha": "10.8.2",
9091
"nyc": "15.0.0",
9192
"semver": "^7.7.2",

tests/docstring_tests/DocTest.res

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,12 @@ let main = async () => {
235235
})
236236

237237
if codeExamples->Array.length > 0 {
238-
let content = `describe("${key}", () => {
238+
let content = `
239+
%%raw(\`
240+
import 'es-iterator-helpers/auto';
241+
\`)
242+
243+
describe("${key}", () => {
239244
${codeExamples->Array.join("\n")}
240245
})`
241246
output->Array.push(content)

tests/docstring_tests/DocTest.res.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/tests/src/core/Core_IteratorTests.mjs

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import * as Test from "./Test.mjs";
44
import * as Primitive_object from "rescript/lib/es6/Primitive_object.js";
55
import * as Stdlib_AsyncIterator from "rescript/lib/es6/Stdlib_AsyncIterator.js";
66

7+
import 'es-iterator-helpers/auto';
8+
;
9+
710
let eq = Primitive_object.equal;
811

912
let iterator = ((() => {
@@ -16,24 +19,6 @@ let syncResult = {
1619
contents: undefined
1720
};
1821

19-
if (!Iterator.prototype.forEach) {
20-
Iterator.prototype.forEach = function forEach(callback, thisArg) {
21-
if (typeof callback !== 'function') {
22-
throw new TypeError(callback + ' is not a function');
23-
}
24-
25-
let index = 0;
26-
let result = this.next();
27-
28-
while (!result.done) {
29-
callback.call(thisArg, result.value, index, this);
30-
result = this.next();
31-
index++;
32-
}
33-
};
34-
}
35-
;
36-
3722
iterator.forEach(v => {
3823
if (v === "b") {
3924
syncResult.contents = "b";
@@ -45,7 +30,7 @@ iterator.forEach(v => {
4530
Test.run([
4631
[
4732
"Core_IteratorTests.res",
48-
38,
33+
23,
4934
20,
5035
34
5136
],
@@ -77,7 +62,7 @@ await Stdlib_AsyncIterator.forEach(asyncIterator, v => {
7762
Test.run([
7863
[
7964
"Core_IteratorTests.res",
80-
61,
65+
46,
8166
20,
8267
35
8368
],
@@ -113,7 +98,7 @@ await Stdlib_AsyncIterator.forEach(asyncIterator$1, v => {
11398
Test.run([
11499
[
115100
"Core_IteratorTests.res",
116-
86,
101+
71,
117102
20,
118103
54
119104
],
@@ -127,4 +112,4 @@ export {
127112
asyncResult,
128113
asyncIterator$1 as asyncIterator,
129114
}
130-
/* iterator Not a pure module */
115+
/* Not a pure module */

tests/tests/src/core/Core_IteratorTests.res

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
%%raw(`
2+
import 'es-iterator-helpers/auto';
3+
`)
4+
15
let eq = (a, b) => a == b
26

37
let iterator: Iterator.t<string> = %raw(`
@@ -10,25 +14,6 @@ let iterator: Iterator.t<string> = %raw(`
1014

1115
let syncResult = ref(None)
1216

13-
%%raw(`
14-
if (!Iterator.prototype.forEach) {
15-
Iterator.prototype.forEach = function forEach(callback, thisArg) {
16-
if (typeof callback !== 'function') {
17-
throw new TypeError(callback + ' is not a function');
18-
}
19-
20-
let index = 0;
21-
let result = this.next();
22-
23-
while (!result.done) {
24-
callback.call(thisArg, result.value, index, this);
25-
result = this.next();
26-
index++;
27-
}
28-
};
29-
}
30-
`)
31-
3217
iterator->Iterator.forEach(v => {
3318
if v == "b" {
3419
syncResult.contents = Some("b")

tests/tests/src/core/Core_TempTests.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import * as Core_IntlTests from "./intl/Core_IntlTests.mjs";
1111
import * as Primitive_bigint from "rescript/lib/es6/Primitive_bigint.js";
1212
import * as Primitive_option from "rescript/lib/es6/Primitive_option.js";
1313

14+
import 'es-iterator-helpers/auto';
15+
;
16+
1417
console.info("");
1518

1619
console.info("Array");

tests/tests/src/core/Core_TempTests.res

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
include Core_IntlTests
22

3+
%%raw(`
4+
import 'es-iterator-helpers/auto';
5+
`)
6+
37
Console.info("")
48
Console.info("Array")
59
Console.info("---")

0 commit comments

Comments
 (0)