From 6068e693babeff667cf7aa53fd465411b1c5f7d8 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sat, 5 Aug 2023 17:59:04 +0800 Subject: [PATCH] Make hoistConstantJsx as an option --- packages/forgetti/src/core/presets.ts | 9 +++++++++ packages/forgetti/src/index.ts | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/forgetti/src/core/presets.ts b/packages/forgetti/src/core/presets.ts index 0c7fb74..3193755 100644 --- a/packages/forgetti/src/core/presets.ts +++ b/packages/forgetti/src/core/presets.ts @@ -39,6 +39,9 @@ export interface Preset { hooks: HookRegistration[]; hocs: ImportDefinition[]; }; + optimizations?: { + hoistConstantJsx?: boolean; + }; } export interface Options { @@ -125,6 +128,9 @@ export const PRESETS = { }, ], }, + optimizations: { + hoistConstantJsx: true, + }, }), preact: createPreset({ filters: { @@ -219,5 +225,8 @@ export const PRESETS = { }, ], }, + optimizations: { + hoistConstantJsx: true, + }, }), }; diff --git a/packages/forgetti/src/index.ts b/packages/forgetti/src/index.ts index 69f31b8..3389140 100644 --- a/packages/forgetti/src/index.ts +++ b/packages/forgetti/src/index.ts @@ -275,13 +275,15 @@ export default function forgettiPlugin(): babel.PluginObj { }, }; - // Register all import specifiers programPath.traverse({ + // Register all import specifiers ImportDeclaration(path) { extractImportIdentifiers(ctx, path); }, JSXElement(path) { - hoistConstantJSX(ctx, path); + if (preset.optimizations?.hoistConstantJsx) { + hoistConstantJSX(ctx, path); + } }, });