@@ -618,30 +618,32 @@ export default function (babel) {
618618 }
619619
620620 const specifierNames = imports [ importPath ] ;
621- const specifiers = [ ] ;
622621
623622 if ( useRequire ) {
624623 // eg; `const { map, uniq } = require('lodash');`
625624 for ( const specifierName of specifierNames ) {
626625 const importIdentifier = t . identifier ( specifierName ) ;
627- specifiers . push ( t . objectProperty ( importIdentifier , importIdentifier , false , true ) ) ;
626+
627+ const requireCall = t . callExpression ( t . identifier ( "require" ) , [
628+ t . stringLiteral ( importPath + '/' + specifierName )
629+ ] ) ;
630+ const requireStmt = t . variableDeclaration ( "const" , [
631+ t . variableDeclarator ( importIdentifier , requireCall ) ,
632+ ] ) ;
633+
634+ declarations . push ( requireStmt ) ;
628635 }
629- const requirePattern = t . objectPattern ( specifiers ) ;
630- const requireCall = t . callExpression ( t . identifier ( "require" ) , [
631- t . stringLiteral ( importPath )
632- ] ) ;
633- const requireStmt = t . variableDeclaration ( "const" , [
634- t . variableDeclarator ( requirePattern , requireCall ) ,
635- ] ) ;
636- declarations . push ( requireStmt ) ;
637636 } else {
638637 // eg; `import { map, uniq } from 'lodash';`
639638 for ( const specifierName of specifierNames ) {
640639 const importIdentifier = t . identifier ( specifierName ) ;
641- specifiers . push ( t . importSpecifier ( importIdentifier , importIdentifier ) ) ;
640+ const importSpecifier = t . importDefaultSpecifier ( importIdentifier ) ;
641+ const importDeclaration = t . importDeclaration (
642+ [ importSpecifier ] ,
643+ t . stringLiteral ( importPath + '/' + specifierName )
644+ ) ;
645+ declarations . push ( importDeclaration ) ;
642646 }
643- const importDeclaration = t . importDeclaration ( specifiers , t . stringLiteral ( importPath ) ) ;
644- declarations . push ( importDeclaration ) ;
645647 }
646648 }
647649 path . unshiftContainer ( "body ", declarations ) ;
0 commit comments