Skip to content

Commit

Permalink
Lazily compute helper metadata
Browse files Browse the repository at this point in the history
- When using `@babel/runtime`, we don't need the metadata so we can skip computing it
- This fixes a Babel 8 bug introduced in the prev commit, because FileClass
is not initialized when not using inline helpers
  • Loading branch information
nicolo-ribaudo committed Mar 9, 2022
1 parent 84ebbfc commit de7eb9f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/babel-helpers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,15 @@ function loadHelper(name: string) {
);
};

const metadata = getHelperMetadata(fn());
// We compute the helper metadata lazily, so that we skip that
// work if we only need the `.minVersion` (for example because
// of a call to `.availableHelper` when `@babel/rutime`).
let metadata: HelperMetadata | null = null;

helperData[name] = {
build(getDependency, id, localBindings) {
const file = fn();
metadata ||= getHelperMetadata(file);
permuteHelperAST(file, metadata, id, localBindings, getDependency);

return {
Expand All @@ -299,7 +303,10 @@ function loadHelper(name: string) {
minVersion() {
return helper.minVersion;
},
dependencies: metadata.dependencies,
get dependencies() {
metadata ||= getHelperMetadata(fn());
return metadata.dependencies;
},
};
}

Expand Down

0 comments on commit de7eb9f

Please sign in to comment.