-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polyfill Symbol.asyncIterator everywhere
- Loading branch information
1 parent
877bc37
commit 574130c
Showing
5 changed files
with
20 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/// <reference lib="es2018.asynciterable" /> | ||
|
||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
export const AsyncIteratorPrototype: AsyncIterable<any> | undefined = | ||
export const AsyncIteratorPrototype: AsyncIterable<any> = | ||
Object.getPrototypeOf(Object.getPrototypeOf(async function* (): AsyncIterableIterator<any> {}).prototype); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,13 @@ | ||
/// <reference lib="es2018.asynciterable" /> | ||
|
||
export let AsyncIteratorPrototype: AsyncIterable<any> | undefined; | ||
import { SymbolAsyncIterator } from '../../../lib/abstract-ops/ecmascript'; | ||
|
||
if (typeof Symbol.asyncIterator === 'symbol') { | ||
// We're running inside a ES2018+ environment, but we're compiling to an older syntax. | ||
// We cannot access %AsyncIteratorPrototype% without non-ES2018 syntax, but we can re-create it. | ||
AsyncIteratorPrototype = { | ||
// 25.1.3.1 %AsyncIteratorPrototype% [ @@asyncIterator ] ( ) | ||
// https://tc39.github.io/ecma262/#sec-asynciteratorprototype-asynciterator | ||
[Symbol.asyncIterator](this: AsyncIterator<any>) { | ||
return this; | ||
} | ||
}; | ||
Object.defineProperty(AsyncIteratorPrototype, Symbol.asyncIterator, { enumerable: false }); | ||
} | ||
// We cannot access %AsyncIteratorPrototype% without non-ES2018 syntax, but we can re-create it. | ||
export const AsyncIteratorPrototype: AsyncIterable<any> = { | ||
// 25.1.3.1 %AsyncIteratorPrototype% [ @@asyncIterator ] ( ) | ||
// https://tc39.github.io/ecma262/#sec-asynciteratorprototype-asynciterator | ||
[SymbolAsyncIterator](this: AsyncIterator<any>) { | ||
return this; | ||
} | ||
}; | ||
Object.defineProperty(AsyncIteratorPrototype, SymbolAsyncIterator, { enumerable: false }); |