All Projects → sgilroy → async-await-codemod

sgilroy / async-await-codemod

Licence: other
Codemod script for migrating promise-based functions to use async/await syntax

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to async-await-codemod

express-mongoose-es8-rest-api
A Boilerplate for developing Rest api's in Node.js using express with support for ES6,ES7,ES8 ,Mongoose,JWT for authentication,Standardjs for linting
Stars: ✭ 20 (-9.09%)
Mutual labels:  async-await, es8
ember-angle-brackets-codemod
Codemod to convert curly braces syntax to angle brackets syntax
Stars: ✭ 58 (+163.64%)
Mutual labels:  codemod, jscodeshift
tiny-treeshaker
🌳🥤 A tiny codemod for tree shaking (experimental) 🌳🥤
Stars: ✭ 92 (+318.18%)
Mutual labels:  codemod, jscodeshift
es5-function-to-class-codemod
📦 Transform ES5 Functions to ES6 Classes
Stars: ✭ 30 (+36.36%)
Mutual labels:  codemod, jscodeshift
preact-codemod
🍧 Shave some bytes by using Preact.
Stars: ✭ 39 (+77.27%)
Mutual labels:  codemod, jscodeshift
font-awesome-codemod
⚙️ Font Awesome codemod script
Stars: ✭ 46 (+109.09%)
Mutual labels:  codemod, jscodeshift
jscodeshift-typescript-example
jscodeshift typescript codemod example
Stars: ✭ 27 (+22.73%)
Mutual labels:  codemod, jscodeshift
codemod-v4
codemod cli for antd v4 upgrade
Stars: ✭ 84 (+281.82%)
Mutual labels:  codemod, jscodeshift
AsyncClipboardService
📋 An async & low-level windows clipboard service implementation for .NET, C#
Stars: ✭ 14 (-36.36%)
Mutual labels:  async-await
async
Asynchronous programming for R -- async/await and generators/yield
Stars: ✭ 37 (+68.18%)
Mutual labels:  async-await
babel-plugin-hyperscript-to-jsx
This plugin transforms react-hyperscript into JSX. Intended to be used as codemod.
Stars: ✭ 20 (-9.09%)
Mutual labels:  codemod
action-eslint
🐋🐬 TypeScript/JavaScript ESLint action
Stars: ✭ 24 (+9.09%)
Mutual labels:  async-await
AsyncTcpClient
An asynchronous variant of TcpClient and TcpListener for .NET Standard.
Stars: ✭ 125 (+468.18%)
Mutual labels:  async-await
Keeping-Up-With-the-Javascripts
Code snippets and challenges for the "Keeping Up With the Javascripts" course, available at Pirple.com
Stars: ✭ 104 (+372.73%)
Mutual labels:  es8
koa2-example-app
An app that is built using koa2 and async/await
Stars: ✭ 85 (+286.36%)
Mutual labels:  async-await
is-async-supported
Check if async/await is available natively
Stars: ✭ 16 (-27.27%)
Mutual labels:  async-await
django-codemod
A tool to automatically fix Django deprecations.
Stars: ✭ 145 (+559.09%)
Mutual labels:  codemod
react-app-simple-chat-app
A Simple Chat Application using MERN stack (MongoDB, Express JS, React JS, Node JS) and Socket.io for real time chatting
Stars: ✭ 41 (+86.36%)
Mutual labels:  async-await
graphql2ts
Transform .graphql to graphql-js typescript
Stars: ✭ 41 (+86.36%)
Mutual labels:  codemod
banana
🍌 Modern C++ Telegram Bot API library
Stars: ✭ 30 (+36.36%)
Mutual labels:  async-await

async-await-codemod

Build Status Code Style: prettier

This repository contains a codemod script for use with JSCodeshift that migrates promise-based functions to use async/await syntax.

The excellent sinon-codemod repository was used as inspiration and served as a template for this repository.

This codemod is based in part on work done by @cpojer https://github.com/cpojer/js-codemod/pull/49/commits/19ed546d8a47127d3d115f933d924106c98e1b8b and the further work of @cassilup https://github.com/cassilup/async-await-codemod-demo

Setup & Run

  • npm install -g jscodeshift
  • git clone https://github.com/sgilroy/async-await-codemod.git or download a zip file from https://github.com/sgilroy/async-await-codemod/archive/master.zip
  • Run npm install in the async-await-codemod directory
    • Alternatively, run yarn to install in the async-await-codemod directory
  • jscodeshift -t <codemod-script> <path>
  • Use the -d option for a dry-run and use -p to print the output for comparison

async-await

ES2017 natively supports a special syntax for working with promises called "async/await".

With promises:

function makeRequest() {
  return getJSON().then(data => {
    console.log(data);
    return 'done';
  });
}

With async/await:

async function makeRequestFunction() {
  const data = await getJSON();
  console.log(data);
  return 'done';
}

Included Scripts

async-await

Converts each asynchronous function (a function which contains a .then() call) to async, and uses await instead of .then() to simplify the behavior of using promises synchronously.

jscodeshift -t async-await-codemod/async-await.js <path>

await-promise-chain

Unravels chained promise calls of the style foo.then().then() as multiple await calls. Note that this changes the structure and scope of blocks of code and can thus result in different behavior, such as by variables being in scope that otherwise would not.

This should generally be used after the async-await codemod, and the changes should be examined and tested carefully to avoid unwanted bugs or subtle problems.

jscodeshift -t async-await-codemod/await-promise-chain.js <path>
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].