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

feature request: custom helpers #6487

Open
NodeGuy opened this issue Oct 15, 2017 · 5 comments

Comments

@NodeGuy
Copy link

commented Oct 15, 2017

From the README for babel-helpers:

NOTE: This package is only meant to be used by the packages inluded in this repository. There is currently no way for third-party plugins to define an helper.

I would like to be able to write a third-party plugin that defines its own helper.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Oct 15, 2017

Hey @NodeGuy! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@xtuc

This comment has been minimized.

Copy link
Member

commented Oct 15, 2017

Just to be clear, you want to override some of Babel's helper functions like the spread syntax one? Or do you want to inject a function during your own transformation?

Could you please add an example?

@NodeGuy

This comment has been minimized.

Copy link
Author

commented Oct 15, 2017

Thank you for asking. I would like to write my own version of asyncToGenerator for my plugin.

helpers.asyncToGenerator = defineHelper(`
export default function _asyncToGenerator(fn) {
return function () {
var self = this, args = arguments;
return new Promise(function (resolve, reject) {
var gen = fn.apply(self, args);
function step(key, arg) {
try {
var info = gen[key](arg);
var value = info.value;
} catch (error) {
reject(error);
return;
}
if (info.done) {
resolve(value);
} else {
Promise.resolve(value).then(_next, _throw);
}
}
function _next(value) { step("next", value); }
function _throw(err) { step("throw", err); }
_next();
});
};
}
`);

@msz

This comment has been minimized.

Copy link

commented Jul 6, 2018

👍 I would also like to do the same thing as @NodeGuy.

@Gcaufy

This comment has been minimized.

Copy link
Contributor

commented Sep 20, 2018

@NodeGuy @msz
Same to me, I would like to do the same thing, to overwrite asyncToGenerator helper.
Let me know if you guys have a solution about it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.