Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | 6x 10x 10x 10x 5x 5x 5x 2x 2x 2x 3x 3x 3x 3x | import { PluginObj, PluginPass } from '@babel/core';
export type Options = {
removeExportDefault?: boolean;
}
export default function defaultExportReplace(): PluginObj<PluginPass> {
return {
name: 'transform-replace-export-default',
visitor: {
ExportDefaultDeclaration(path, state) {
const declaration = path.node.declaration;
const { removeExportDefault } = state.opts as Options;
if (removeExportDefault) {
declaration.type === 'Identifier' ? path.remove() : path.replaceWith(declaration);
return;
}
if (declaration.type === 'ClassDeclaration' || declaration.type === 'FunctionDeclaration') {
// @ts-ignore
path.node.type = 'ReturnStatement';
// @ts-ignore
path.node.argument = declaration;
path.replaceWith(path.node);
} else Eif (declaration.type === 'Identifier') {
// declaration.name = `return ${declaration.name}`;
// @ts-ignore
path.node.type = 'ReturnStatement';
// @ts-ignore
path.node.argument = declaration;
path.replaceWith(path.node);
}
},
},
};
} |