11import { transform } from '@babel/standalone' ;
2- import { PluginItem , PluginObj } from '@babel/core' ;
2+ import { PluginItem } from '@babel/core' ;
33import removeImports from 'babel-plugin-transform-remove-imports' ;
4+ import replaceExportDefault from 'babel-plugin-transform-replace-export-default' ;
45import { Options } from '../' ;
56
6- export function defaultExportReplace ( ) : PluginObj {
7- return {
8- name : 'transform-replace-export-default-to-return' ,
9- visitor : {
10- ExportDefaultDeclaration ( path , opts ) {
11- const declaration = path . node . declaration ;
12- if ( declaration . type === 'ClassDeclaration' || declaration . type === 'FunctionDeclaration' ) {
13- declaration . id . name = `return ${ declaration . id . name } ` ;
14- } else if ( declaration . type === 'Identifier' ) {
15- declaration . name = `return ${ declaration . name } ` ;
16- }
17- if ( declaration ) {
18- path . replaceWith ( declaration ) ;
19- }
20- } ,
21- } ,
22- } ;
23- }
24-
257export const getTransformValue = ( str : string , filename : string , opts : Options ) => {
268 try {
279 const plugins : PluginItem [ ] = [ ...( opts . babelPlugins || [ ] ) ] ;
@@ -31,7 +13,7 @@ export const getTransformValue = (str: string, filename: string, opts: Options)
3113 const result = transform ( str , {
3214 filename,
3315 presets : [ 'env' , 'es2015' , 'react' , 'typescript' ] ,
34- plugins : [ ...plugins , defaultExportReplace ] ,
16+ plugins : [ ...plugins , replaceExportDefault ] ,
3517 } ) ;
3618 return result . code ;
3719 } catch ( err ) {
0 commit comments