@@ -3,8 +3,31 @@ var path_utils = require('../utils/path');
33function transformer ( file , api ) {
44 var j = api . jscodeshift ;
55
6- return j ( file . source )
7- . find ( j . ImportDeclaration )
6+ var root = j ( file . source ) ;
7+
8+ var foundHelper ;
9+
10+ root . find ( j . ImportDeclaration , {
11+ source : { value : '@ember/component/helper' } ,
12+ } ) . filter ( path => {
13+ return path . value . specifiers [ 0 ] . local . name === 'helper' ;
14+ } )
15+ . forEach ( function ( path ) {
16+ foundHelper = true ;
17+ var specifier = j . importSpecifier ( j . identifier ( 'helper' ) , j . identifier ( 'buildHelper' ) ) ;
18+
19+ path . value . specifiers [ 0 ] = specifier ;
20+ } ) ;
21+
22+ if ( foundHelper ) {
23+ root . find ( j . CallExpression , {
24+ callee : { name : 'helper' }
25+ } ) . forEach ( path => {
26+ path . value . callee . name = 'buildHelper' ;
27+ } ) ;
28+ }
29+
30+ root . find ( j . ImportDeclaration )
831 . find ( j . Literal )
932 . forEach ( function ( path ) {
1033 var importPath = path . value . value + '.js' ;
@@ -55,9 +78,9 @@ function transformer(file, api) {
5578 // remove extension
5679 newImportPath = newImportPath . slice ( 0 , - targetFileInfo . ext . length ) ;
5780 j ( path ) . replaceWith ( j . literal ( newImportPath ) ) ;
58- } )
59- . toSource ( ) ;
81+ } ) ;
6082
83+ return root . toSource ( ) ;
6184}
6285
6386module . exports = transformer ;
0 commit comments