Open anchengjian opened 2 years ago
Input:
async function AAA () {} async function BBB () {}
babel.config.js
module.exports = function (api) { api.cache(false) return { presets: ['@babel/preset-env'], } }
Test Code:
const code = `async function AAA () {} async function BBB () {}` const babelcore = require("@babel/core"); const res = babelcore.transformSync(code, { filename: '/a/b/c', plugins: [ [ "babel-plugin-transform-async-to-promises", { externalHelpers: true } ], ], }); console.log(res.code)
Output:
"use strict"; var _helpers = require("babel-plugin-transform-async-to-promises/helpers"); var BBB = function BBB() { return _await(); // <--------- There is no _helpers here }; var AAA = function AAA() { return (0, _helpers._await)(); };
And, there is also a problem with the order of function declarations
The output is correct without @babel/preset-env (I guess the issue is caused by the transformation to commonjs).
Input:
babel.config.js
Test Code:
Output: