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

Use async-to-generator even when regenerator is enabled #10839

Merged
merged 1 commit into from Dec 9, 2019

Conversation

nicolo-ribaudo
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo commented Dec 8, 2019

Q                       A
Fixed Issues? #10830, #10678
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

While async-to-generator it isn't technically needed because regenerator already handles async functions, it doesn't play well with the Promise detection logic used by @babel/preset-env's useBuiltIns and @babel/transform-runtime.

The plugin exclusion logic isn't removed, because

  1. it will be useful when merging @babel/preset-modules into @babel/preset-env
  2. if/when regenerator will support injecting a custom promise, we can enable this optimization again

This PR effectively reverts the behavior introduced in #9481

While it isn't technically needed because regenerator already handles
async functions, it doesn't play well with the Promise detection logic
used by @babel/preset-env's useBuiltIns and @babel/transform-runtime.

The plugin exclusion logic isn't removed, because
1) it will be useful when merging @babel/preset-modules
    into @babel/preset-env
2) if/when regenerator will support injecting a custom promise,
    we can enable this optimization again
@nicolo-ribaudo nicolo-ribaudo added PR: Revert ↩️ A type of pull request used for our changelog categories i: regression labels Dec 8, 2019
@JLHwung JLHwung merged commit 2884bac into babel:master Dec 9, 2019
rwjblue added a commit to rwjblue/ember-cli-babel that referenced this pull request Dec 20, 2019
This reverts commit b31980e.

The change that required this was reverted in babel/babel#10839.
@kelly-tock
Copy link

@nicolo-ribaudo I just updated @babel/core to be 7.7.7 from 7.7.5. I am wondering why I am now getting this message when I am using async () => {} in certain scenarios:

newArrowCheck.js?10a5:3 Uncaught (in promise) TypeError: Cannot instantiate an arrow function
    at _newArrowCheck (newArrowCheck.js?10a5:3)
    at _callee$ (EditProfileModal.tsx?48ea:84)
    at tryCatch (runtime.js?96cf:45)
    at Generator.invoke [as _invoke] (runtime.js?96cf:271)
    at Generator.prototype.<computed> [as next] (runtime.js?96cf:97)
    at asyncGeneratorStep (asyncToGenerator.js?c973:3)
    at _next (asyncToGenerator.js?c973:25)
    at eval (asyncToGenerator.js?c973:32)
    at new Promise (<anonymous>)
    at eval (asyncToGenerator.js?c973:21)

some example code:

const onClose = async () => {
      try {
        await <thing that returns a promise>;
      } catch (err) {
        return;
      }
    }
  };

and is called from a click handler in a different react component.

my package.json for babel related things in a custom preset:

"devDependencies": {
    "@babel/core": "^7.7.7",
    "@babel/runtime": "^7.7.7"
  },
  "dependencies": {
    "@babel/core": "^7.7.7",
    "@babel/plugin-proposal-class-properties": "^7.7.4",
    "@babel/plugin-proposal-export-namespace-from": "^7.7.4",
    "@babel/plugin-proposal-function-sent": "^7.7.4",
    "@babel/plugin-proposal-json-strings": "^7.7.4",
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.7.4",
    "@babel/plugin-proposal-numeric-separator": "^7.7.4",
    "@babel/plugin-proposal-optional-chaining": "^7.7.5",
    "@babel/plugin-proposal-throw-expressions": "^7.7.4",
    "@babel/plugin-syntax-dynamic-import": "^7.7.4",
    "@babel/plugin-syntax-import-meta": "^7.7.4",
    "@babel/plugin-transform-react-constant-elements": "^7.7.4",
    "@babel/plugin-transform-react-inline-elements": "^7.7.4",
    "@babel/plugin-transform-runtime": "^7.7.6",
    "@babel/preset-env": "^7.7.7",
    "@babel/preset-react": "^7.7.4",
    "@babel/preset-typescript": "^7.7.7",
    "@babel/runtime": "^7.7.7",
    "@babel/runtime-corejs2": "^7.7.7",
    "babel-plugin-lodash": "^3.3.4",
    "regenerator-runtime": "^0.13.3"
  }

and in the app that uses this preset I have

 "@babel/runtime": "7.7.7",
"@babel/core": "7.7.7",
"@babel/plugin-transform-runtime": "^7.7.6",

@kelly-tock
Copy link

reverting back to 7.7.5 allows it to work again.

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Dec 23, 2019

Did it work before 7.7.0? If it did, then it's caused by some other change. Could you open a new issue? 🙏
Also, please include how you are calling onClose and your Babel config.

@kelly-tock
Copy link

it did, last week we were on 7.7.5 and this week updated. i'll open a new issue and link back to this one.

@kelly-tock
Copy link

core, preset env and runtime all got bumped recently so it could be one of those as well. this pr was in the change log and seemed related.

@kelly-tock
Copy link

@nicolo-ribaudo opened new issue. #10928

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Revert ↩️ A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants