Socket
Socket
Sign inDemoInstall

babel-plugin-transform-async-to-promises

Package Overview
Dependencies
0
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    babel-plugin-transform-async-to-promises

Transform async/await to promise chains


Version published
Weekly downloads
239K
decreased by-25.85%
Maintainers
1
Install size
353 kB
Created
Weekly downloads
 

Readme

Source

babel-plugin-transform-async-to-promises

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

Build Status

Input:

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

Output:

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

Output with hoist enabled:

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

Output with inlineHelpers enabled:

const fetchAsObjectURL = function(url) {
	try {
		return Promise.resolve(fetch(url)).then(function(response) {
			return Promise.resolve(response.blob()).then(URL.createObjectURL);
		});
	} catch(e) {
		return Promise.reject(e);
	}
}

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

Keywords

FAQs

Last updated on 26 May 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc