Created
September 16, 2024 12:03
-
-
Save nikolaybotev/acab33b7387e4773bc1749f1c556efbb to your computer and use it in GitHub Desktop.
Setup AsyncIteratorPrototype for Common.js Async Iterator Helpers polyfill on async generators
This file contains hidden or 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
const asyncGeneratorInstancePrototype = Object.getPrototypeOf(async function*(){}()); | |
const AsyncGeneratorPrototype = Object.getPrototypeOf(asyncGeneratorInstancePrototype); | |
let AsyncIteratorPrototype; | |
if (AsyncGeneratorPrototype === Object.prototype) { | |
// Fix-up for babel's transform-async-generator-functions | |
AsyncIteratorPrototype = {}; | |
const newAsyncGeneratorPrototype = Object.create(AsyncIteratorPrototype); | |
Object.setPrototypeOf(asyncGeneratorInstancePrototype, newAsyncGeneratorPrototype); | |
} else { | |
AsyncIteratorPrototype = Object.getPrototypeOf(AsyncGeneratorPrototype); | |
} | |
import configurator from "core-js/configurator.js"; | |
configurator({ AsyncIteratorPrototype }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this file to your project and
import
it at the top of your entry-point, to enable Async Iterator Helper polyfills from core-js on async generator functions, e.g.: