@@ -74,33 +74,34 @@ export default declare((api: BabelAPI) => {
7474
7575 const ext = path . extname ( importNode . source . value ) ;
7676
77- // Convert all non-JS imports into refs.
78- if ( ! allJsExtensions . has ( ext ) ) {
77+ if ( jsxComponentNames . size ) {
78+ let importCount = 0 ;
79+ // Convert JS imports that are used as components in JSX expressions into refs.
7980 for ( const specifier of importNode . specifiers ) {
8081 if ( t . isImportNamespaceSpecifier ( specifier ) )
8182 continue ;
8283 const { localName, info } = importInfo ( importNode , specifier , this . filename ! ) ;
83- importInfos . set ( localName , info ) ;
84+ if ( jsxComponentNames . has ( localName ) ) {
85+ importInfos . set ( localName , info ) ;
86+ ++ importCount ;
87+ }
88+ }
89+ // All the imports were from JSX => delete.
90+ if ( importCount && importCount === importNode . specifiers . length ) {
91+ p . skip ( ) ;
92+ p . remove ( ) ;
8493 }
85- p . skip ( ) ;
86- p . remove ( ) ;
8794 return ;
8895 }
8996
90- // Convert JS imports that are used as components in JSX expressions into refs.
91- let importCount = 0 ;
92- for ( const specifier of importNode . specifiers ) {
93- if ( t . isImportNamespaceSpecifier ( specifier ) )
94- continue ;
95- const { localName, info } = importInfo ( importNode , specifier , this . filename ! ) ;
96- if ( jsxComponentNames . has ( localName ) ) {
97+ // Convert all non-JS imports into refs.
98+ if ( ! allJsExtensions . has ( ext ) ) {
99+ for ( const specifier of importNode . specifiers ) {
100+ if ( t . isImportNamespaceSpecifier ( specifier ) )
101+ continue ;
102+ const { localName, info } = importInfo ( importNode , specifier , this . filename ! ) ;
97103 importInfos . set ( localName , info ) ;
98- ++ importCount ;
99104 }
100- }
101-
102- // All the imports were from JSX => delete.
103- if ( importCount && importCount === importNode . specifiers . length ) {
104105 p . skip ( ) ;
105106 p . remove ( ) ;
106107 }
0 commit comments