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

Add some nice warnings if plugins happen to return promises instead of sync values. #6818

Merged
merged 2 commits into from Nov 13, 2017

Conversation

loganfsmyth
Copy link
Member

This does nothing for current users. The intention with this is just a bit of future-proofing. I think at some point we'll want to add support for plugins that are async, either as a top-level promise-returning function like an async function(){}, or with async handler functions of like pre, post, parserOverride, or generatorOverride.

This PR does 2 things:

  • Add clear error messages to each of those call sites, so if they do return a promise, the user will have at least some hint of what to do. That way if we allow this eventually in 7.x and someone writes a plugin using it, and then a user runs it on an older 7.x release, they'll get some kind of feedback.
  • This adds an api.async() function that would allow a plugin to check if async logic is allowed in plugins. Where in the future it might return true if used via a Babel transform that allows async logic, like transform("", () => {}).

I'm imagining that in the future we might for instance have users doing

import asyncPlugin from "./async";
import syncPlugin from "./sync";
export default function(api, ...args) {
  return api.async() ? asyncPlugin(api, ...args) : syncPlugin(api, ...args);
}

which is certainly just a guess, but at least if we do go that route, plugins could rely on it being there in early 7.x versions too.

@babel-bot
Copy link
Collaborator

babel-bot commented Nov 13, 2017

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/5800/

@loganfsmyth loganfsmyth added the PR: Polish 💅 A type of pull request used for our changelog categories label Nov 13, 2017
Copy link
Member

@hzoo hzoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, I like the progress of setting this up for later

@loganfsmyth loganfsmyth merged commit e44cef3 into babel:master Nov 13, 2017
@loganfsmyth loganfsmyth deleted the async-warnings branch November 13, 2017 20:43
@lock lock bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 5, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Polish 💅 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

3 participants