Skip to content

Interdependence of Babel Helpers #6030

@peey

Description

@peey

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has PRPR: Internal 🏠A type of pull request used for our changelog categoriesoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions