# babel-plugin-transform-async-await

> Transform async/await to promise chains

Latest version **1.0.0** (published 2018-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install babel-plugin-transform-async-await
pnpm add babel-plugin-transform-async-await
yarn add babel-plugin-transform-async-await
bun add babel-plugin-transform-async-await
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-08-05 |
| First published | 2018-08-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 227.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | tangshuang |
| Maintainers | tangshuang |
| Keywords | async, await, optimization, babel, compile, transform |

## Links

- npm: https://www.npmjs.com/package/babel-plugin-transform-async-await
- Repository: https://github.com/tangshuang/babel-plugin-transform-async-await
- Homepage: https://github.com/tangshuang/babel-plugin-transform-async-await#readme
- Issues: https://github.com/tangshuang/babel-plugin-transform-async-await/issues
- npm.io page: https://npm.io/package/babel-plugin-transform-async-await

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-08-05
- 0.7.0 — 2018-08-05

## README

babel-plugin-transform-async-await
========================================

FORK: this library if forked from babel-plugin-transform-async-to-promises, and modify `_async/_await` functions to be my own logic.

Babel plugin to transform `async` functions containing `await` expressions to the equivalent chain of `Promise` calls with use of minimal helper functions.

[![Build Status](https://travis-ci.org/rpetrich/babel-plugin-transform-async-to-promises.svg?branch=master)](https://travis-ci.org/rpetrich/babel-plugin-transform-async-to-promises)

### Install

```
npm i -D babel-plugin-transform-async-await
```

### Usage

Add this babel plugin into your config file `.babelrc` or config settings.

```
{
	"presets": [
    ["env", { "exclude": ["transform-async-to-generator", "transform-regenerator"] }],
		...
  ],
	...
	"plugins": [
		...
		"transform-async-await"
	]
}
```

Notice `env` preset's options, you should put exclude option to disable preset-env default plugins.

### Input:

```javascript
async function fetchAsObjectURL(url) {
	const response = await fetch(url);
	const blob = await response.blob();
	return URL.createObjectURL(blob);
}
```

### Output:

```javascript
var fetchAsObjectURL = _async(function(url) {
	return _await(fetch(url), function(response) {
		return _await(response.blob(), function(blob) {
			return URL.createObjectURL(blob);
		});
	});
});
```

### Output with hoisting enabled:

```javascript
var _URL$createObjectURL = function(blob) {
	return URL.createObjectURL(blob);
};
var _response$blob = function(response) {
	return _await(response.blob(), _URL$createObjectURL);
};
var fetchAsObjectURL = _async(function(url) {
	return _await(fetch(url), _response$blob);
});
```

## JavaScript Language Features

### Full Support
- `async`/`await`
- `for`/`while`/`do` loops (including loops that would exhaust stack if dispatched recursively)
- `switch` statements (including fallthrough and `default` cases)
- conditional expressions
- logical expressions
- `try`/`catch`
- `break`/`continue` statements (on both loops and labeled statements)
- `throw` expressions
- Function hoisting
- Variable hoisting
- Arrow functions
- Methods
- `arguments`
- `this`
- Proper member dereference order of operations
- Standards-compliant event loop scheduling

### Partial Support
- `Function.length`: `async` functions will often return a length of 0 (when the `_async` wrapper is used)

### No support
- `eval`: impossible to support without deep hooks into the runtime
- Async generator functions: not implemented or planned
- `Function.name`: rewrite pass removes function name instrumentation
- `new AsyncFunction(...)`: impossible to support without shipping babel and the plugin in the output

---
_Source: https://npm.io/package/babel-plugin-transform-async-await · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
