Skip to content

Commit 7686304

Browse files
committed
chore(snapshots): fixing snapshots
1 parent d38f8c0 commit 7686304

File tree

4 files changed

+75
-131
lines changed

4 files changed

+75
-131
lines changed

workspaces/adventure-pack/goodies/typescript/Iterator.from/index.test.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { describe, expect, it } from "@jest/globals";
22

3-
import "./index";
43
import "../Iterator.prototype.map";
54
import "../Iterator.prototype.filter";
65

@@ -9,6 +8,9 @@ import "../Iterator.prototype.filter";
98
(globalThis as Record<string, unknown>).Iterator as Record<string, unknown>
109
).from;
1110

11+
// eslint-disable-next-line import-x/first
12+
import "./index";
13+
1214
describe("Iterator.from", () => {
1315
it("can convert an Array to an Iterator", () => {
1416
const array = [-3, 1, -4, 1, -5];

workspaces/adventure-pack/goodies/typescript/Iterator.from/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { iteratorPrototype } from "../Iterator.prototype";
2-
import "../Iterator.prototype.toIterable";
1+
import "../Iterator.prototype.toIterable/index.ts";
2+
import { iteratorPrototype } from "../Iterator.prototype/index.ts";
33

44
declare global {
55
interface IteratorConstructor {

workspaces/adventure-pack/src/app/__tests__/__snapshots__/equip-test.ts.snap

Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,6 @@ Function.returnThis = function () {
13641364
/////////////////////////// END ADVENTURE PACK CODE ////////////////////////////"
13651365
`;
13661366

1367-
<<<<<<< HEAD
1368-
=======
13691367
exports[`App can equip single goody: JavaScript Iterator.from 1`] = `
13701368
"////////////////////////// BEGIN ADVENTURE PACK CODE ///////////////////////////
13711369
// Adventure Pack commit fake-commit-hash
@@ -1386,34 +1384,33 @@ iteratorPrototype.toIterable = function () {
13861384

13871385
globalThis.Iterator ??= {};
13881386

1389-
globalThis.Iterator = {
1390-
from(object) {
1391-
if (typeof object[Symbol.iterator] === "function") {
1392-
const iterable = object;
1393-
const iterator = iterable[Symbol.iterator]();
1394-
return iteratorPrototype.toIterable.call(iterator);
1395-
}
1387+
globalThis.Iterator.from ??= function (object) {
1388+
const toIterable = iteratorPrototype.toIterable;
13961389

1397-
if (Object.prototype.isPrototypeOf.call(iteratorPrototype, object)) {
1398-
return iteratorPrototype.toIterable.call(object);
1399-
}
1390+
const iteratorFactory = object[Symbol.iterator];
1391+
if (typeof iteratorFactory === "function") {
1392+
return toIterable.call(iteratorFactory.call(object));
1393+
}
14001394

1401-
if (typeof object.next === "function") {
1402-
return (function* () {
1403-
yield* iteratorPrototype.toIterable.call(object);
1404-
})();
1405-
}
1395+
// eslint-disable-next-line no-prototype-builtins
1396+
if (iteratorPrototype.isPrototypeOf(object)) {
1397+
return toIterable.call(object);
1398+
}
14061399

1407-
throw new TypeError(
1408-
"Object is not an iterator, iterable, or an object with a next method",
1409-
);
1410-
},
1400+
if (typeof object.next === "function") {
1401+
return (function* () {
1402+
yield* toIterable.call(object);
1403+
})();
1404+
}
1405+
1406+
throw new TypeError(
1407+
"Object is not an iterator, iterable, or an object with a next method",
1408+
);
14111409
};
14121410

14131411
/////////////////////////// END ADVENTURE PACK CODE ////////////////////////////"
14141412
`;
14151413

1416-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
14171414
exports[`App can equip single goody: JavaScript Iterator.prototype 1`] = `
14181415
"////////////////////////// BEGIN ADVENTURE PACK CODE ///////////////////////////
14191416
// Adventure Pack commit fake-commit-hash
@@ -2111,29 +2108,18 @@ exports[`App can equip single goody: JavaScript Map.groupBy 1`] = `
21112108

21122109
Map.groupBy ??= function (iterable, callbackFn) {
21132110
const groups = new Map();
2114-
<<<<<<< HEAD
21152111

21162112
let index = 0;
21172113
for (const value of iterable) {
21182114
const key = callbackFn(value, index++);
2119-
=======
2120-
let index = 0;
2121-
for (const value of iterable) {
2122-
const key = callbackFn(value, index);
2123-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
21242115
const group = groups.get(key);
21252116
if (group == null) {
21262117
groups.set(key, [value]);
21272118
} else {
21282119
group.push(value);
21292120
}
2130-
<<<<<<< HEAD
21312121
}
21322122

2133-
=======
2134-
++index;
2135-
}
2136-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
21372123
return groups;
21382124
};
21392125

@@ -3341,8 +3327,6 @@ Function.returnThis = function <T>(this: T): T {
33413327
/////////////////////////// END ADVENTURE PACK CODE ////////////////////////////"
33423328
`;
33433329

3344-
<<<<<<< HEAD
3345-
=======
33463330
exports[`App can equip single goody: TypeScript Iterator.from 1`] = `
33473331
"////////////////////////// BEGIN ADVENTURE PACK CODE ///////////////////////////
33483332
// Adventure Pack commit fake-commit-hash
@@ -3384,40 +3368,38 @@ iteratorPrototype.toIterable = function <T>(
33843368

33853369
(globalThis as Record<string, unknown>).Iterator ??= {};
33863370

3387-
(globalThis as Record<string, unknown>).Iterator = {
3388-
from<T>(
3371+
((globalThis as Record<string, unknown>).Iterator as { from: unknown }).from ??=
3372+
function <T>(
33893373
object: Iterator<T> | Iterable<T> | { next(): IteratorResult<T> },
33903374
): IterableIterator<T> {
3391-
if (typeof (object as Iterable<T>)[Symbol.iterator] === "function") {
3392-
const iterable = object as Iterable<T>;
3393-
const iterator = iterable[Symbol.iterator]();
3394-
return iteratorPrototype.toIterable.call(iterator) as IterableIterator<T>;
3375+
const toIterable = iteratorPrototype.toIterable as (
3376+
this: Iterator<T>,
3377+
) => IterableIterator<T>;
3378+
3379+
const iteratorFactory = (object as Iterable<T>)[Symbol.iterator];
3380+
if (typeof iteratorFactory === "function") {
3381+
return toIterable.call(iteratorFactory.call(object));
33953382
}
33963383

3397-
if (Object.prototype.isPrototypeOf.call(iteratorPrototype, object)) {
3398-
return iteratorPrototype.toIterable.call(
3399-
object as Iterator<T>,
3400-
) as IterableIterator<T>;
3384+
// eslint-disable-next-line no-prototype-builtins
3385+
if (iteratorPrototype.isPrototypeOf(object)) {
3386+
return toIterable.call(object as Iterator<T>);
34013387
}
34023388

3403-
if (typeof (object as { next(): IteratorResult<T> }).next === "function") {
3404-
return (function* (): IterableIterator<T> {
3405-
yield* iteratorPrototype.toIterable.call(
3406-
object as Iterator<T>,
3407-
) as Iterable<T>;
3389+
if (typeof (object as Record<string, unknown>).next === "function") {
3390+
return (function* () {
3391+
yield* toIterable.call(object as Iterator<T>);
34083392
})();
34093393
}
34103394

34113395
throw new TypeError(
34123396
"Object is not an iterator, iterable, or an object with a next method",
34133397
);
3414-
},
3415-
};
3398+
};
34163399

34173400
/////////////////////////// END ADVENTURE PACK CODE ////////////////////////////"
34183401
`;
34193402

3420-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
34213403
exports[`App can equip single goody: TypeScript Iterator.prototype 1`] = `
34223404
"////////////////////////// BEGIN ADVENTURE PACK CODE ///////////////////////////
34233405
// Adventure Pack commit fake-commit-hash
@@ -4530,29 +4512,18 @@ Map.groupBy ??= function <K, V>(
45304512
callbackFn: (value: V, index: number) => K,
45314513
): Map<K, V[]> {
45324514
const groups = new Map<K, V[]>();
4533-
<<<<<<< HEAD
45344515

45354516
let index = 0;
45364517
for (const value of iterable) {
45374518
const key = callbackFn(value, index++);
4538-
=======
4539-
let index = 0;
4540-
for (const value of iterable) {
4541-
const key = callbackFn(value, index);
4542-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
45434519
const group = groups.get(key);
45444520
if (group == null) {
45454521
groups.set(key, [value]);
45464522
} else {
45474523
group.push(value);
45484524
}
4549-
<<<<<<< HEAD
45504525
}
45514526

4552-
=======
4553-
++index;
4554-
}
4555-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
45564527
return groups;
45574528
};
45584529

workspaces/adventure-pack/src/app/__tests__/__snapshots__/render-test.ts.snap

Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -800,40 +800,37 @@ exports[`App can render goody: JavaScript Function.returnThis 1`] = `
800800
};"
801801
`;
802802
803-
<<<<<<< HEAD
804-
=======
805803
exports[`App can render goody: JavaScript Iterator.from 1`] = `
806804
"import "Iterator.prototype";
807805
import "Iterator.prototype.toIterable";
808806
809807
globalThis.Iterator ??= {};
810808
811-
globalThis.Iterator = {
812-
from(object) {
813-
if (typeof object[Symbol.iterator] === "function") {
814-
const iterable = object;
815-
const iterator = iterable[Symbol.iterator]();
816-
return iteratorPrototype.toIterable.call(iterator);
817-
}
809+
globalThis.Iterator.from ??= function (object) {
810+
const toIterable = iteratorPrototype.toIterable;
818811
819-
if (Object.prototype.isPrototypeOf.call(iteratorPrototype, object)) {
820-
return iteratorPrototype.toIterable.call(object);
821-
}
812+
const iteratorFactory = object[Symbol.iterator];
813+
if (typeof iteratorFactory === "function") {
814+
return toIterable.call(iteratorFactory.call(object));
815+
}
822816
823-
if (typeof object.next === "function") {
824-
return (function* () {
825-
yield* iteratorPrototype.toIterable.call(object);
826-
})();
827-
}
817+
// eslint-disable-next-line no-prototype-builtins
818+
if (iteratorPrototype.isPrototypeOf(object)) {
819+
return toIterable.call(object);
820+
}
828821
829-
throw new TypeError(
830-
"Object is not an iterator, iterable, or an object with a next method",
831-
);
832-
},
822+
if (typeof object.next === "function") {
823+
return (function* () {
824+
yield* toIterable.call(object);
825+
})();
826+
}
827+
828+
throw new TypeError(
829+
"Object is not an iterator, iterable, or an object with a next method",
830+
);
833831
};"
834832
`;
835833
836-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
837834
exports[`App can render goody: JavaScript Iterator.prototype 1`] = `
838835
"export const iteratorPrototype = Object.getPrototypeOf(
839836
Object.getPrototypeOf([].values()),
@@ -1162,29 +1159,18 @@ iteratorPrototype.toSet ??= function () {
11621159
exports[`App can render goody: JavaScript Map.groupBy 1`] = `
11631160
"Map.groupBy ??= function (iterable, callbackFn) {
11641161
const groups = new Map();
1165-
<<<<<<< HEAD
11661162
11671163
let index = 0;
11681164
for (const value of iterable) {
11691165
const key = callbackFn(value, index++);
1170-
=======
1171-
let index = 0;
1172-
for (const value of iterable) {
1173-
const key = callbackFn(value, index);
1174-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
11751166
const group = groups.get(key);
11761167
if (group == null) {
11771168
groups.set(key, [value]);
11781169
} else {
11791170
group.push(value);
11801171
}
1181-
<<<<<<< HEAD
11821172
}
11831173
1184-
=======
1185-
++index;
1186-
}
1187-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
11881174
return groups;
11891175
};"
11901176
`;
@@ -1984,8 +1970,6 @@ Function.returnThis = function <T>(this: T): T {
19841970
};"
19851971
`;
19861972
1987-
<<<<<<< HEAD
1988-
=======
19891973
exports[`App can render goody: TypeScript Iterator.from 1`] = `
19901974
"import "Iterator.prototype";
19911975
import "Iterator.prototype.toIterable";
@@ -2002,38 +1986,36 @@ declare global {
20021986
20031987
(globalThis as Record<string, unknown>).Iterator ??= {};
20041988
2005-
(globalThis as Record<string, unknown>).Iterator = {
2006-
from<T>(
1989+
((globalThis as Record<string, unknown>).Iterator as { from: unknown }).from ??=
1990+
function <T>(
20071991
object: Iterator<T> | Iterable<T> | { next(): IteratorResult<T> },
20081992
): IterableIterator<T> {
2009-
if (typeof (object as Iterable<T>)[Symbol.iterator] === "function") {
2010-
const iterable = object as Iterable<T>;
2011-
const iterator = iterable[Symbol.iterator]();
2012-
return iteratorPrototype.toIterable.call(iterator) as IterableIterator<T>;
1993+
const toIterable = iteratorPrototype.toIterable as (
1994+
this: Iterator<T>,
1995+
) => IterableIterator<T>;
1996+
1997+
const iteratorFactory = (object as Iterable<T>)[Symbol.iterator];
1998+
if (typeof iteratorFactory === "function") {
1999+
return toIterable.call(iteratorFactory.call(object));
20132000
}
20142001
2015-
if (Object.prototype.isPrototypeOf.call(iteratorPrototype, object)) {
2016-
return iteratorPrototype.toIterable.call(
2017-
object as Iterator<T>,
2018-
) as IterableIterator<T>;
2002+
// eslint-disable-next-line no-prototype-builtins
2003+
if (iteratorPrototype.isPrototypeOf(object)) {
2004+
return toIterable.call(object as Iterator<T>);
20192005
}
20202006
2021-
if (typeof (object as { next(): IteratorResult<T> }).next === "function") {
2022-
return (function* (): IterableIterator<T> {
2023-
yield* iteratorPrototype.toIterable.call(
2024-
object as Iterator<T>,
2025-
) as Iterable<T>;
2007+
if (typeof (object as Record<string, unknown>).next === "function") {
2008+
return (function* () {
2009+
yield* toIterable.call(object as Iterator<T>);
20262010
})();
20272011
}
20282012
20292013
throw new TypeError(
20302014
"Object is not an iterator, iterable, or an object with a next method",
20312015
);
2032-
},
2033-
};"
2016+
};"
20342017
`;
20352018
2036-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
20372019
exports[`App can render goody: TypeScript Iterator.prototype 1`] = `
20382020
"export const iteratorPrototype = Object.getPrototypeOf(
20392021
Object.getPrototypeOf([].values()),
@@ -2602,29 +2584,18 @@ Map.groupBy ??= function <K, V>(
26022584
callbackFn: (value: V, index: number) => K,
26032585
): Map<K, V[]> {
26042586
const groups = new Map<K, V[]>();
2605-
<<<<<<< HEAD
26062587
26072588
let index = 0;
26082589
for (const value of iterable) {
26092590
const key = callbackFn(value, index++);
2610-
=======
2611-
let index = 0;
2612-
for (const value of iterable) {
2613-
const key = callbackFn(value, index);
2614-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
26152591
const group = groups.get(key);
26162592
if (group == null) {
26172593
groups.set(key, [value]);
26182594
} else {
26192595
group.push(value);
26202596
}
2621-
<<<<<<< HEAD
26222597
}
26232598
2624-
=======
2625-
++index;
2626-
}
2627-
>>>>>>> 319cf8b (chore(pr): Applying 1st round of PR feedback)
26282599
return groups;
26292600
};"
26302601
`;

0 commit comments

Comments
 (0)