Skip to content

Commit

Permalink
perf: avoid loadFullConfig when creating block hoist plugin (#13223)
Browse files Browse the repository at this point in the history
* perf: avoid loadFullConfig when creating block hoist plugin

* address code review comments
  • Loading branch information
JLHwung committed Apr 27, 2021
1 parent a0e20ac commit 88da2e8
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions packages/babel-core/src/transformation/block-hoist-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import loadConfig from "../config";

import type { Plugin } from "../config";
import traverse from "@babel/traverse";
import Plugin from "../config/plugin";

let LOADED_PLUGIN: Plugin | void;

export default function loadBlockHoistPlugin(): Plugin {
if (!LOADED_PLUGIN) {
// Lazy-init the internal plugin to remove the init-time circular
// dependency between plugins being passed @babel/core's export object,
// which loads this file, and this 'loadConfig' loading plugins.
const config = loadConfig.sync({
babelrc: false,
configFile: false,
browserslistConfigFile: false,
plugins: [blockHoistPlugin],
});
LOADED_PLUGIN = config ? config.passes[0][0] : undefined;
if (!LOADED_PLUGIN) throw new Error("Assertion failure");
// cache the loaded blockHoist plugin plugin
LOADED_PLUGIN = new Plugin(
{
...blockHoistPlugin,
visitor: traverse.explode(blockHoistPlugin.visitor),
},
{},
);
}

return LOADED_PLUGIN;
Expand Down

0 comments on commit 88da2e8

Please sign in to comment.