swc/packages/swc-helpers/esm/_async_generator_delegate.js
magic-akari a13a78e3fe
feat(es/helpers): Use named export and unify import path (#7182)
**BREAKING CHANGE:**

Breaking changes for `@swc/helpers`. A new major version `0.5.0` is required.


**Related issue:**

 - Closes https://github.com/swc-project/swc/issues/7157
2023-04-04 03:05:47 +00:00

48 lines
1.1 KiB
JavaScript

export function _async_generator_delegate(inner, awaitWrap) {
var iter = {}, waiting = false;
function pump(key, value) {
waiting = true;
value = new Promise(function(resolve) {
resolve(inner[key](value));
});
return { done: false, value: awaitWrap(value) };
}
if (typeof Symbol === "function" && Symbol.iterator) {
iter[Symbol.iterator] = function() {
return this;
};
}
iter.next = function(value) {
if (waiting) {
waiting = false;
return value;
}
return pump("next", value);
};
if (typeof inner.throw === "function") {
iter.throw = function(value) {
if (waiting) {
waiting = false;
throw value;
}
return pump("throw", value);
};
}
if (typeof inner.return === "function") {
iter.return = function(value) {
return pump("return", value);
};
}
return iter;
}
export { _async_generator_delegate as _ };