File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ var isTypeInSingleTypeCollection = require('../utils/is-type-in-single-type-coll
77var defaultTypeForCollection = require ( '../utils/default-type-for-collection' ) ;
88var calculateCollectionInfo = require ( '../utils/calculate-collection-info' ) ;
99var importDeclarationsTransform = require ( '../transforms/import-declarations' ) ;
10+ var renameImportHelperTransform = require ( '../transforms/rename-helper-import' ) ;
1011var inflection = require ( 'inflection' ) ;
1112var PodsSupport = require ( '../utils/pods-support' ) ;
1213var typeForPodFile = PodsSupport . typeForPodFile ;
@@ -176,6 +177,14 @@ var FileInfo = CoreObject.extend({
176177 } ,
177178 { jscodeshift } ) ;
178179
180+ // Fixes "import { helper } from '@ember/component/helper'"
181+ // to "import { helper as buildHelper } from '@ember/component/helper'"
182+ newContents = renameImportHelperTransform (
183+ {
184+ source : newContents
185+ } ,
186+ { jscodeshift } ) ;
187+
179188 var fullPath = path . join ( this . projectRoot , this . sourceRelativePath ) ;
180189
181190 fse . writeFileSync ( fullPath , newContents , { encoding : 'utf-8' } ) ;
Original file line number Diff line number Diff line change @@ -5,28 +5,6 @@ function transformer(file, api) {
55
66 var root = j ( file . source ) ;
77
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-
308 root . find ( j . ImportDeclaration )
319 . find ( j . Literal )
3210 . forEach ( function ( path ) {
Original file line number Diff line number Diff line change 1+ function transformer ( file , api ) {
2+ var j = api . jscodeshift ;
3+
4+ var foundHelper = false ;
5+
6+ var root = j ( file . source ) ;
7+
8+ // Replaces:
9+ // import { helper } from '@ember/component/helper';
10+ // With:
11+ // import { helper as buildHelper } from '@ember/component/helper';
12+ root . find ( j . ImportDeclaration , {
13+ source : { value : '@ember/component/helper' } ,
14+ } ) . filter ( path => {
15+ return path . value . specifiers [ 0 ] . local . name === 'helper' ;
16+ } )
17+ . forEach ( function ( path ) {
18+ foundHelper = true ;
19+ var specifier = j . importSpecifier (
20+ j . identifier ( 'helper' ) ,
21+ j . identifier ( 'buildHelper' )
22+ ) ;
23+
24+ path . value . specifiers [ 0 ] = specifier ;
25+ } ) ;
26+
27+ // Replace helper(...) with buildHelper(...)
28+ if ( foundHelper ) {
29+ root . find ( j . CallExpression , {
30+ callee : { name : 'helper' }
31+ } ) . forEach ( path => {
32+ path . value . callee . name = 'buildHelper' ;
33+ } ) ;
34+ }
35+
36+ return root . toSource ( ) ;
37+ }
38+
39+ module . exports = transformer ;
You can’t perform that action at this time.
0 commit comments