{"_id":"babel-plugin-fast-async","_rev":"3332125","name":"babel-plugin-fast-async","description":"fast-async/await transformer Babel plugin","dist-tags":{"latest":"6.1.2"},"maintainers":[{"name":"zsea","email":""}],"time":{"modified":"2024-07-10T07:26:44.000Z","created":"2016-12-19T09:19:49.891Z","6.1.2":"2016-12-19T09:19:49.891Z"},"users":{},"author":{"name":"Mat At Bread","email":"nodent@mailed.me.uk"},"repository":{"type":"git","url":"git+https://github.com/MatAtBread/fast-async.git"},"versions":{"6.1.2":{"name":"babel-plugin-fast-async","version":"6.1.2","dependencies":{"nodent":">=2.6.12"},"description":"fast-async/await transformer Babel plugin","main":"plugin.js","scripts":{"test":"cd tests && npm i && npm test"},"repository":{"type":"git","url":"git+https://github.com/MatAtBread/fast-async.git"},"keywords":["babel","plugin","Javascript","ES7","async","await"],"author":{"name":"Mat At Bread","email":"nodent@mailed.me.uk"},"license":"BSD-2-Clause","bugs":{"url":"https://github.com/MatAtBread/fast-async/issues"},"gitHead":"57673a4ecdceff31a0b62c844d98d3bb9299a329","homepage":"https://github.com/MatAtBread/fast-async#readme","_id":"babel-plugin-fast-async@6.1.2","_shasum":"ac4921fa2b7f4e1f51963be45f3b1018fd03cd9d","_from":".","_npmVersion":"3.9.5","_nodeVersion":"7.2.1","_npmUser":{"name":"zsea","email":"yjhgef@163.com"},"dist":{"shasum":"ac4921fa2b7f4e1f51963be45f3b1018fd03cd9d","size":6528,"noattachment":false,"key":"/babel-plugin-fast-async/-/babel-plugin-fast-async-6.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/babel-plugin-fast-async/download/babel-plugin-fast-async-6.1.2.tgz"},"maintainers":[{"name":"zsea","email":""}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/babel-plugin-fast-async-6.1.2.tgz_1482139187936_0.31250909250229597"},"directories":{},"publish_time":1482139189891,"_hasShrinkwrap":false,"_cnpm_publish_time":1482139189891,"_cnpmcore_publish_time":"2021-12-16T20:26:39.185Z"}},"readme":"###声明\r\n\r\n该库是`fast-async`的完全镜像。\r\n\r\nfast-async\r\n==========\r\n\r\n'fast-async' is a _Babel v6.x.x_ plugin that implements the ES7 keywords `async` and `await` using syntax transformation\r\nat compile-time, rather than generators.\r\n\r\nThe main reason for using 'fast-async' as opposed to Babel's default implementation of async/await is\r\nperformance (https://github.com/MatAtBread/nodent#performance) - it's 3-4 times faster in a browser/node, and\r\nas much as 10 times faster on a mobile browsers, mainly due to avoiding generators (and therefore regenerator).\r\n\r\nThere's a simple test (that just makes sure the plugin works and generates code that runs). More complete\r\ntest coverage is included with nodent.\r\n\r\nBecause 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.\r\n\r\nFor _Babel v5.x.x_ install fast-async@1.0.3\r\n\r\n> v6.1.x\r\nfast-async@>=6.1.0 can use nodent v2 or v3 (and acorn v3 or v4). Nodent v3 has the option of generating code with Promises which needs no runtime at all, at the cost of size and speed. v6.1.x can also reference the runtime via an import (useRuntimeModule option), rather than include the source inline.\r\n\r\nInstall\r\n-------\r\n```bash\r\nnpm install fast-async --save\r\n```\r\n  \r\nUsage\r\n-----\r\n\r\nJust include the plugin to the babel options. Minimal `.babelrc` example:\r\n```js\r\n{\r\n  \"plugins\": [\"fast-async\"]\r\n}\r\n```\r\n\r\nThat's all. Neither `babel-plugin-transform-runtime` nor `babel-polyfill` required. Your application, once compiled, will probably needs nodent's runtime = see [below](#runtimepattern).\r\n\r\nWith options:\r\n```js\r\n{\r\n  \"plugins\": [\r\n    [\"fast-async\", {\r\n      \"env\": {\r\n        \"augmentObject\": false,\r\n        \"dontMapStackTraces\": true,\r\n        \"dontInstallRequireHook\": true\r\n      },\r\n      \"compiler\": {\r\n        \"promises\": true,\r\n        \"generators\": false\r\n      },\r\n      \"runtimePattern\":null,\r\n      \"useRuntimeModule\":false\r\n    }]\r\n  ]\r\n}\r\n```\r\n\r\nTest\r\n----\r\nFrom the installation directory (e.g. node_modules/fast-async):\r\n```bash\r\nnpm test\r\n```\r\nOptions\r\n-------\r\nThe plugin accepts the following options object, which itself is optional, as are all members. These are based on the options in nodent,\r\nbut since much of the parsing is done by Babel some are unused.\r\n\r\n```js\r\nenv:{\r\n  log:function(string),        // Supplied routine to emit transformation warnings. Default: console.log\r\n  augmentObject:false,         // Add the nodent utilities asyncify() and isThenable() to Object.prototype\r\n  dontMapStackTraces:true,     // Don't install the stack trace hook that maps line numbers (default: true)\r\n  dontInstallRequireHook:false // Don't transform all JS files as they are loaded into node (default: true)\r\n},\r\ncompiler:{\r\n  promises:true,    // Use nodent's \"Promises\" mode. Set to false if your execution environment does not support Promises.\r\n  generators:false  // Transform into 'Generators' (sub-optimal, but it works)\r\n},\r\nruntimePattern:null,     // See below\r\nuseRuntimeModule:false  // See below\r\n```\r\n\r\nFor more information on the compiler options, see [ES7 and Promises](https://github.com/matatbread/nodent#es7-and-promises) in the nodent documentation.\r\n\r\n> 6.1.x\r\nThe dontMapStackTraces now defaults to `true` as having both nodent and babel map stack traces doesn't work well\r\n\r\nruntimePattern\r\n--------------\r\nBy default, fast-async will put the nodent runtime into every file containing an `async` function or `await` expression. \r\nIf your project is made up of more than one file, the constant redefinition of the runtime is a waste of time and space. You can \r\nspecify that you want the runtime in particular file(s) by setting the 'runtimePattern' to a regular expression (in quotes). \r\nOnly files that match the regular expression will have the runtime defined (which is global, so you only need it once). \r\n\r\nNote: At least one of the file(s) matching the \"runtimePattern\" must use either `await` or `async` as the runtime function (or `require('nodent-runtime')` if you set `\"useRuntimeModule\":true`) is only included for files that reference it.\r\n\r\nFor example:\r\n\r\n```js\r\n\"babel\": {\r\n  \"plugins\": [\r\n    \"syntax-async-functions\",\r\n    [\"fast-async\",{\r\n       \"runtimePattern\":\"test-input\\\\.js\"\r\n    }]\r\n  ]\r\n}\r\n```\r\nAlternatively, if you set runtimePattern to `\"directive\"`, the statement `\"use runtime-nodent\";` will be replaced with the runtime during compilation.\r\n\r\n> v6.1.x\r\nIf you specify the option `\"useRuntimeModule\":true`, the runtime is not included directly as source, but via an import of [nodent-runtime](https://github.com/MatAtBread/nodent-runtime), which is typically resolved to `require()` by babel. The nodent-runtime module must be added as a dependency in your target project. The runtime need only be included once in your entire project, and should precede any code that uses async or await.\r\n\r\nUseful Links\r\n------------\r\n\r\n* [nodent](https://github.com/MatAtBread/nodent)\r\n* [Babel plugins](http://babeljs.io/docs/advanced/plugins/)\r\n\r\nOnline performance checkers:\r\n\r\n* [nodent](http://nodent.mailed.me.uk/#function%20pause%28%29%20{%0A%20%20%20%20return%20new%20Promise%28function%20%28%24return%2C%20%24error%29%20{%0A%20%20%20%20%20%20%20%20setTimeout%28function%20%28%29%20{%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%24return%280%29%3B%0A%20%20%20%20%20%20%20%20}%2C%200%29%3B%0A%20%20%20%20}%29%3B%0A}%0A%0Aasync%20function%20doNothing%28%29%20{%0A%20%20%20%20return%3B%0A}%0A%0Aasync%20function%20test%28%29%20{%0A%20%20%20%20var%20t%20%3D%20Date.now%28%29%3B%0A%20%20%20%20for%20%28var%20j%20%3D%200%3B%20j%20%3C%2050%3B%20j%2B%2B%29%20{%0A%20%20%20%20%20%20%20%20for%20%28var%20i%20%3D%200%3B%20i%20%3C%201000%3B%20i%2B%2B%29%20{%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20doNothing%28%29%3B%0A%20%20%20%20%20%20%20%20}%0A%20%20%20%20%20%20%20%20await%20pause%28%29%3B%0A%20%20%20%20}%0A%20%20%20%20return%20Date.now%28%29%20-%20t%3B%0A}%0A%0Atest%28%29.then%28alert%29%3B%0A) 632ms (and shave off another 100ms by selecting 'Pure ES5' mode)\r\n* [babel](https://babeljs.io/repl/#?experimental=true&evaluate=true&loose=false&spec=false&code=function%20pause%28%29%20{%0A%20%20%20%20return%20new%20Promise%28function%20%28%24return%2C%20%24error%29%20{%0A%20%20%20%20%20%20%20%20setTimeout%28function%20%28%29%20{%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%24return%280%29%3B%0A%20%20%20%20%20%20%20%20}%2C%200%29%3B%0A%20%20%20%20}%29%3B%0A}%0A%0Aasync%20function%20doNothing%28%29%20{%0A%20%20%20%20return%3B%0A}%0A%0Aasync%20function%20test%28%29%20{%0A%20%20%20%20var%20t%20%3D%20Date.now%28%29%3B%0A%20%20%20%20for%20%28var%20j%20%3D%200%3B%20j%20%3C%2050%3B%20j%2B%2B%29%20{%0A%20%20%20%20%20%20%20%20for%20%28var%20i%20%3D%200%3B%20i%20%3C%201000%3B%20i%2B%2B%29%20{%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20doNothing%28%29%3B%0A%20%20%20%20%20%20%20%20}%0A%20%20%20%20%20%20%20%20await%20pause%28%29%3B%0A%20%20%20%20}%0A%20%20%20%20return%20Date.now%28%29%20-%20t%3B%0A}%0A%0Atest%28%29.then%28alert%2Calert%29%3B%0A) 1877ms - 3x slower\r\n* [traceur](https://google.github.io/traceur-compiler/demo/repl.html#%2F%2F%20Options%3A%20--annotations%20--array-comprehension%20--async-functions%20--async-generators%20--exponentiation%20--export-from-extended%20--for-on%20--generator-comprehension%20--member-variables%20--proper-tail-calls%20--require%20--symbols%20--types%20%0Afunction%20pause%28%29%20{%0A%20%20%20%20return%20new%20Promise%28function%20%28%24return%2C%20%24error%29%20{%0A%20%20%20%20%20%20%20%20setTimeout%28function%20%28%29%20{%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20%24return%280%29%3B%0A%20%20%20%20%20%20%20%20}%2C%200%29%3B%0A%20%20%20%20}%29%3B%0A}%0A%0Aasync%20function%20doNothing%28%29%20{%0A%20%20%20%20return%3B%0A}%0A%0Aasync%20function%20test%28%29%20{%0A%20%20%20%20var%20t%20%3D%20Date.now%28%29%3B%0A%20%20%20%20for%20%28var%20j%20%3D%200%3B%20j%20%3C%2050%3B%20j%2B%2B%29%20{%0A%20%20%20%20%20%20%20%20for%20%28var%20i%20%3D%200%3B%20i%20%3C%201000%3B%20i%2B%2B%29%20{%0A%20%20%20%20%20%20%20%20%20%20%20%20await%20doNothing%28%29%3B%0A%20%20%20%20%20%20%20%20}%0A%20%20%20%20%20%20%20%20await%20pause%28%29%3B%0A%20%20%20%20}%0A%20%20%20%20return%20Date.now%28%29%20-%20t%3B%0A}%0A%0Atest%28%29.then%28alert%2Calert%29%3B%20%0A) 2488ms - 4x slower\r\n","_attachments":{},"homepage":"https://github.com/MatAtBread/fast-async#readme","bugs":{"url":"https://github.com/MatAtBread/fast-async/issues"},"license":"BSD-2-Clause"}