@@ -771,6 +771,7 @@ function judgeInjectArraySuspect(path, ctx) {
771771 if ( t . isExportDefaultDeclaration ( path . parent ) && ! node . id ) {
772772 // export default function(a) {}
773773 node . id = path . scope . generateUidIdentifier ( 'ngInjectExport' ) ;
774+ path . parentPath . scope . crawl ( ) ;
774775 path . parentPath . insertBefore ( buildInjectExpression ( node . params , node . id . name ) ) ;
775776 } else {
776777 // /*@ngInject */ function foo($scope) {}
@@ -780,6 +781,7 @@ function judgeInjectArraySuspect(path, ctx) {
780781 isFunctionExpressionWithArgs ( node . expression . right ) && ! path . get ( "expression.right" ) . $seen ) {
781782 // /*@ngInject */ foo.bar[0] = function($scope) {}
782783 let inject = buildInjectExpression ( node . expression . right . params , t . cloneDeep ( node . expression . left ) ) ;
784+ path . parentPath . scope . crawl ( ) ;
783785 path . insertAfter ( inject ) ;
784786
785787 } else if ( path = followReference ( path ) ) {
@@ -792,7 +794,7 @@ function judgeInjectArraySuspect(path, ctx) {
792794
793795 function buildInjectExpression ( params , name ) {
794796 let left = t . isNode ( name ) ? name : t . identifier ( name ) ;
795- let paramStrings = params . map ( param => t . stringLiteral ( param . name ) ) ;
797+ let paramStrings = params . map ( param => t . stringLiteral ( getNamedParam ( param ) ) ) ;
796798 let arr = t . arrayExpression ( paramStrings ) ; // ["$scope"]
797799 let member = t . memberExpression ( left , t . identifier ( "$inject" ) ) ; // foo.$inject =
798800 return t . expressionStatement ( t . assignmentExpression ( "=" , member , arr ) ) ;
@@ -810,6 +812,7 @@ function judgeInjectArraySuspect(path, ctx) {
810812 }
811813 block . unshiftContainer ( "body" , [ expr ] ) ;
812814 } else {
815+ path . parentPath . scope . crawl ( ) ;
813816 path . insertBefore ( buildInjectExpression ( params , name ) ) ;
814817 }
815818 }
@@ -820,6 +823,7 @@ function judgeInjectArraySuspect(path, ctx) {
820823 trailingComments = path . node . trailingComments ;
821824 path . node . trailingComments = [ ] ;
822825 }
826+ path . parentPath . scope . crawl ( ) ;
823827 let newNode = path . insertAfter ( buildInjectExpression ( params , name ) ) ;
824828 newNode . trailingComments = trailingComments ;
825829 }
@@ -870,6 +874,12 @@ function isGenericProviderName(node) {
870874 return t . isLiteral ( node ) && is . string ( node . value ) ;
871875}
872876
877+ function getNamedParam ( p ) {
878+ let param = p ;
879+ if ( t . isAssignmentPattern ( p ) ) param = p . left ;
880+ return param . name ;
881+ }
882+
873883function getConstructor ( node ) {
874884 var body = node . body . body ;
875885 for ( var i = 0 ; i < body . length ; i ++ ) {
0 commit comments