swc/packages/helpers/esm/_async_generator_delegate.js
Jiwon Choi 69719c2acb
refactor(es/helpers): Remove unnecessary exports (#9225)
**Description:**

Helper methods were exporting twice, `_` and it's own function name.
We can map the build script to export `_` as it's own name (filename).
Therefore we export only once as `_`, and map the name on the build
script.

```js
// helpers/_foo.js

function _foo() {
  // ...
}

export { _foo as _ }
```
```js
// index.js

// We know the func name will be `_foo` based on the filename.
export { _ as _foo } from '_foo.js'
```

Closes #9203

---------

Co-authored-by: magic-akari <akari.ccino@gmail.com>
2024-07-13 17:13:25 +09:00

48 lines
1.1 KiB
JavaScript

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 _ };