-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Description
Feature Request
If a babel helper is to refer to another babel helper, then it can't because we don't know in advance what the name of the injected helpers will be.
e.g. in packages/babel-helpers/src/helpers.js file, if you have
helpers.a = template(`(function () {c();});`);
helpers.c = template(`(function () {});`);Then it can't work.
Proposal
I propose that if you want to depend on another helper, then use this:
helpers.a = template(`function a() {babelHelpers.c();}`);
helpers.c = template(`function c() {}`);To implement, we'll use a regex which finds babelHelper\.[a-zA-Z0-9]+ and then see if a helper by that name has been injected already using file.addHelper(...) API. If it has, then we replace it by the name of the injected helper
This won't break anything and all code using this will be opt-in since you have to prefix your helper access by babelHelper.
Scope for expansion
Right now, I'll coarsely implement this such that it requires that all the helpers you depend on have been included in the file already using file.addHelpers because it's urgently required by the current design of the decorators transform I'm eager to push for review.
Later on, this could be used to automatically include the dependencies. (This should be easy, could even be beginner-friendly)