JSPM

  • Created
  • Published
  • Downloads 16600
  • Score
    100M100P100Q171984F
  • License BSD-2-Clause

fast-async/await transformer Babel plugin

Package Exports

  • fast-async

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (fast-async) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

fast-async

'fast-async' is a Babel v6.x.x plugin that implements the ES7 keywords async and await using syntax transformation at compile-time rather than generators.

The main reason for using 'fast-async' as opposed to Babel's default implementation of async/await is performance (https://github.com/MatAtBread/nodent#performance) - it's 3-4 times faster in a browser/node, and as much as 10 times faster on a mobile browsers, mainly due to avoiding generators (and therefore regenerator).

There's a simple test (that just makes sure the plugin works and generates code that runs). More complete test coverage is included with nodent.

Because Babel parses the code, the ES7 extensions possible with nodent (await anywhere, async return and async throw) are not supported, however full implementation of async function containing await expressions is implemented.

For Babel v5.x.x install fast-async@1.0.3

Install

npm install fast-async

Test

From the installation directory (e.g. node_modules/fast-async):

npm test

Options

The plugin accepts the following options object, which itself is optional, as are all members. These are based on the options in nodent, but since much of the parsing is done by Babel some are unused.

env:{
    log:function(string),        // Supplied routine to emit transformation warnings. Default: console.log
    augmentObject:false,         // Add the nodent utilities asyncify() and isThenable() to Object.prototype
    dontMapStackTraces:false,    // Don't install the stack trace hook that maps line numbers
    asyncStackTrace:false,       // Provide async stack traces
    dontInstallRequireHook:false // Don't transform all JS files as they are loaded into node
},
compiler:{
    promises:true,    // Use nodent's "Promises" mode. Set to false if your execution environment does not support Promises.
    generators:false  // Transform into 'Generators'.
}

For more information on the compiler options, see ES7 and Promises in the nodent documentation.

Online performance checkers:

  • nodent 632ms (and shave off another 100ms by selecting 'Pure ES5' mode)
  • babel 1877ms - 3x slower
  • traceur 2488ms - 4x slower