Skip to content

Issue with IE11 and missing Symbol.iterator #1850

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

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions __tests__/List.ts
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,20 @@ describe('List', () => {
expect(v2.toArray()).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, null]);
});

it('concat works like Array.prototype.concat even for IE11', () => {
const v1 = List([1, 2, 3]);
const a = [4];

// remove Symbol.iterator as IE11 does not handle it.
// See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/@@iterator#browser_compatibility
// @ts-expect-error -- simulate IE11
a[Symbol.iterator] = undefined;

const v2 = v1.concat(a);
expect(v1.toArray()).toEqual([1, 2, 3]);
expect(v2.toArray()).toEqual([1, 2, 3, 4]);
});

it('concat returns self when no changes', () => {
const v1 = List([1, 2, 3]);
expect(v1.concat([])).toBe(v1);
Expand Down
5 changes: 5 additions & 0 deletions src/Iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ export function iteratorDone() {
}

export function hasIterator(maybeIterable) {
if (Array.isArray(maybeIterable)) {
// IE11 trick as it does not support `Symbol.iterator`
return true;
}

return !!getIteratorFn(maybeIterable);
}

Expand Down