Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected output with externalHelpers: true #81

Open
anchengjian opened this issue Feb 25, 2022 · 2 comments
Open

unexpected output with externalHelpers: true #81

anchengjian opened this issue Feb 25, 2022 · 2 comments

Comments

@anchengjian
Copy link

anchengjian commented Feb 25, 2022

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)();
};
@anchengjian
Copy link
Author

And, there is also a problem with the order of function declarations

@anchengjian anchengjian changed the title unexpected outpu with externalHelpers: true unexpected output with externalHelpers: true Feb 25, 2022
@dmail
Copy link

dmail commented May 30, 2022

The output is correct without @babel/preset-env (I guess the issue is caused by the transformation to commonjs).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants