@@ -49,37 +49,41 @@ function transform(file, api) {
4949 let j = api . jscodeshift ;
5050 let root = j ( source ) ;
5151
52- let nativeDomImportStatement = root . find ( j . ImportDeclaration , {
52+ let nativeDomImportStatements = root . find ( j . ImportDeclaration , {
5353 source : { value : 'ember-native-dom-helpers' }
5454 } ) ;
55- if ( nativeDomImportStatement . length === 0 ) {
55+ if ( nativeDomImportStatements . length === 0 ) {
5656 return root . toSource ( { quote : 'single' } ) ;
5757 }
5858
5959 let newImports = [ ] ;
60- let oldSpecifiers = nativeDomImportStatement . get ( 'specifiers' ) ;
61- let newSpecifiers = [ ] ;
62- oldSpecifiers . each ( ( { node : specifier } ) => {
63- let importedName = specifier . imported . name ;
64- if ( importedName in importMigrationsLookup ) {
65- let mappedName = importMigrationsLookup [ importedName ] ;
66- // @todo local != imported
67- // let localName = specifier.local.name;
68- newImports . push ( mappedName ) ;
69- if ( importedName !== mappedName ) {
70- renameCallee ( j , root , importedName , mappedName ) ;
60+
61+ nativeDomImportStatements . forEach ( ( importStatement ) => {
62+ let oldSpecifiers = importStatement . get ( 'specifiers' ) ;
63+
64+ let newSpecifiers = [ ] ;
65+ oldSpecifiers . each ( ( { node : specifier } ) => {
66+ let importedName = specifier . imported . name ;
67+ if ( importedName in importMigrationsLookup ) {
68+ let mappedName = importMigrationsLookup [ importedName ] ;
69+ // @todo local != imported
70+ // let localName = specifier.local.name;
71+ newImports . push ( mappedName ) ;
72+ if ( importedName !== mappedName ) {
73+ renameCallee ( j , root , importedName , mappedName ) ;
74+ }
75+ } else {
76+ newSpecifiers . push ( specifier ) ;
7177 }
78+ } ) ;
79+
80+ if ( newSpecifiers . length > 0 ) {
81+ oldSpecifiers . replace ( newSpecifiers ) ;
7282 } else {
73- newSpecifiers . push ( specifier ) ;
83+ importStatement . prune ( ) ;
7484 }
7585 } ) ;
7686
77- if ( newSpecifiers . length > 0 ) {
78- oldSpecifiers . replace ( newSpecifiers ) ;
79- } else {
80- nativeDomImportStatement . remove ( ) ;
81- }
82-
8387 addImportStatement ( newImports ) ;
8488 writeImportStatements ( j , root ) ;
8589 return root . toSource ( { quote : 'single' } ) ;
0 commit comments