@@ -66,54 +66,51 @@ export function manipulatePluginOptions(pluginOpts, cwd = process.cwd()) {
6666 return pluginOpts ;
6767}
6868
69- export default ( { types : t } ) => ( {
70- manipulateOptions ( babelOptions ) {
71- let findPluginOptions = babelOptions . plugins . find ( plugin => plugin [ 0 ] === this ) [ 1 ] ;
72- findPluginOptions = manipulatePluginOptions ( findPluginOptions ) ;
73-
74- this . customCWD = findPluginOptions . cwd ;
75- } ,
76-
77- pre ( file ) {
78- let { customCWD } = this . plugin ;
79- if ( customCWD === 'babelrc' ) {
80- const startPath = ( file . opts . filename === 'unknown' )
81- ? './'
82- : file . opts . filename ;
83-
84- const { file : babelFile } = findBabelConfig . sync ( startPath ) ;
85- customCWD = babelFile
86- ? path . dirname ( babelFile )
87- : null ;
88- }
89-
90- this . moduleResolverCWD = customCWD || process . cwd ( ) ;
91- } ,
92-
93- visitor : {
94- CallExpression : {
95- exit ( nodePath , state ) {
96- if ( nodePath . node . seen ) {
97- return ;
98- }
69+ export default ( { types : t } ) => {
70+ const importVisitors = {
71+ CallExpression ( nodePath , state ) {
72+ transformRequireCall ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
73+ transformJestCalls ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
74+ transformSystemImportCall ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
75+ } ,
76+ ImportDeclaration ( nodePath , state ) {
77+ transformImportCall ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
78+ } ,
79+ ExportDeclaration ( nodePath , state ) {
80+ transformImportCall ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
81+ } ,
82+ } ;
9983
100- transformRequireCall ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
101- transformJestCalls ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
102- transformSystemImportCall ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
84+ return {
85+ manipulateOptions ( babelOptions ) {
86+ let findPluginOptions = babelOptions . plugins . find ( plugin => plugin [ 0 ] === this ) [ 1 ] ;
87+ findPluginOptions = manipulatePluginOptions ( findPluginOptions ) ;
10388
104- // eslint-disable-next-line no-param-reassign
105- nodePath . node . seen = true ;
106- } ,
89+ this . customCWD = findPluginOptions . cwd ;
10790 } ,
108- ImportDeclaration : {
109- exit ( nodePath , state ) {
110- transformImportCall ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
111- } ,
91+
92+ pre ( file ) {
93+ let { customCWD } = this . plugin ;
94+ if ( customCWD === 'babelrc' ) {
95+ const startPath = ( file . opts . filename === 'unknown' )
96+ ? './'
97+ : file . opts . filename ;
98+
99+ const { file : babelFile } = findBabelConfig . sync ( startPath ) ;
100+ customCWD = babelFile
101+ ? path . dirname ( babelFile )
102+ : null ;
103+ }
104+
105+ this . moduleResolverCWD = customCWD || process . cwd ( ) ;
112106 } ,
113- ExportDeclaration : {
114- exit ( nodePath , state ) {
115- transformImportCall ( t , nodePath , mapModule , state , this . moduleResolverCWD ) ;
107+
108+ visitor : {
109+ Program : {
110+ exit ( programPath , state ) {
111+ programPath . traverse ( importVisitors , state ) ;
112+ } ,
116113 } ,
117114 } ,
118- } ,
119- } ) ;
115+ } ;
116+ } ;
0 commit comments