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

ReferenceError: _async is not defined #84

Open
dmail opened this issue Jul 4, 2022 · 1 comment
Open

ReferenceError: _async is not defined #84

dmail opened this issue Jul 4, 2022 · 1 comment

Comments

@dmail
Copy link

dmail commented Jul 4, 2022

It's possible to generate code where _async helper is not injected resulting in a ReferenceError.

function _await(value, then, direct) {
  if (direct) {
    return then ? then(value) : value;
  }

  if (!value || !value.then) {
    value = Promise.resolve(value);
  }

  return then ? value.then(then) : value;
}

System.register([], function (_export, _context) {
  "use strict";

  var answer;
  return {
    setters: [],
    execute: _async(function () {
      return _await(Promise.resolve(), function () {
        _export("answer", answer = 42);
      });
    })
  };
});

☝️ The code above can be generated with the following js:

const { transform } = require("@babel/core")

const { code } = transform(
  `await Promise.resolve()
  export const answer = 42`,
  {
    plugins: [
      require("@babel/plugin-transform-modules-systemjs"),
      [
        require("babel-plugin-transform-async-to-promises"),
        {
          topLevelAwait: "return",
        },
      ],
    ],
  },
)

console.log(code)
@dmail dmail changed the title _async is not defined ReferenceError: _async is not defined Jul 4, 2022
@dmail
Copy link
Author

dmail commented Jul 4, 2022

The following patch fix the issue

case "return": {
+ helperReference(this, path, '_async')
  rewriteAsyncBlock( 

At

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

1 participant