Skip to content

Commit

Permalink
Make hoistConstantJsx as an option
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Aug 5, 2023
1 parent edf596c commit 6068e69
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 9 additions & 0 deletions packages/forgetti/src/core/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export interface Preset {
hooks: HookRegistration[];
hocs: ImportDefinition[];
};
optimizations?: {
hoistConstantJsx?: boolean;
};
}

export interface Options {
Expand Down Expand Up @@ -125,6 +128,9 @@ export const PRESETS = {
},
],
},
optimizations: {
hoistConstantJsx: true,
},
}),
preact: createPreset({
filters: {
Expand Down Expand Up @@ -219,5 +225,8 @@ export const PRESETS = {
},
],
},
optimizations: {
hoistConstantJsx: true,
},
}),
};
6 changes: 4 additions & 2 deletions packages/forgetti/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,15 @@ export default function forgettiPlugin(): babel.PluginObj<State> {
},
};

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

Expand Down

0 comments on commit 6068e69

Please sign in to comment.