Skip to content

Commit 88da2e8

Browse files
authored
perf: avoid loadFullConfig when creating block hoist plugin (#13223)
* perf: avoid loadFullConfig when creating block hoist plugin * address code review comments
1 parent a0e20ac commit 88da2e8

1 file changed

Lines changed: 10 additions & 14 deletions

File tree

packages/babel-core/src/transformation/block-hoist-plugin.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
import loadConfig from "../config";
2-
3-
import type { Plugin } from "../config";
1+
import traverse from "@babel/traverse";
2+
import Plugin from "../config/plugin";
43

54
let LOADED_PLUGIN: Plugin | void;
65

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

2218
return LOADED_PLUGIN;

0 commit comments

Comments
 (0)