Last active
September 16, 2024 12:36
-
-
Save nikolaybotev/56e916666c214e0cf501672414e90b1d to your computer and use it in GitHub Desktop.
Setup AsyncIteratorPrototype for Common.js Async Iterator Helpers polyfill on async generators (CommonJS version)
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); | |
} | |
const configurator = require("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
require
it at the top of your entry-point, to enable Async Iterator Helper polyfills from core-js on async generator functions, e.g.: