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); + } }, });