@@ -771,6 +771,7 @@ function judgeInjectArraySuspect(path, ctx) {
771
771
if ( t . isExportDefaultDeclaration ( path . parent ) && ! node . id ) {
772
772
// export default function(a) {}
773
773
node . id = path . scope . generateUidIdentifier ( 'ngInjectExport' ) ;
774
+ path . parentPath . scope . crawl ( ) ;
774
775
path . parentPath . insertBefore ( buildInjectExpression ( node . params , node . id . name ) ) ;
775
776
} else {
776
777
// /*@ngInject */ function foo($scope) {}
@@ -780,6 +781,7 @@ function judgeInjectArraySuspect(path, ctx) {
780
781
isFunctionExpressionWithArgs ( node . expression . right ) && ! path . get ( "expression.right" ) . $seen ) {
781
782
// /*@ngInject */ foo.bar[0] = function($scope) {}
782
783
let inject = buildInjectExpression ( node . expression . right . params , t . cloneDeep ( node . expression . left ) ) ;
784
+ path . parentPath . scope . crawl ( ) ;
783
785
path . insertAfter ( inject ) ;
784
786
785
787
} else if ( path = followReference ( path ) ) {
@@ -792,7 +794,7 @@ function judgeInjectArraySuspect(path, ctx) {
792
794
793
795
function buildInjectExpression ( params , name ) {
794
796
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 ) ) ) ;
796
798
let arr = t . arrayExpression ( paramStrings ) ; // ["$scope"]
797
799
let member = t . memberExpression ( left , t . identifier ( "$inject" ) ) ; // foo.$inject =
798
800
return t . expressionStatement ( t . assignmentExpression ( "=" , member , arr ) ) ;
@@ -810,6 +812,7 @@ function judgeInjectArraySuspect(path, ctx) {
810
812
}
811
813
block . unshiftContainer ( "body" , [ expr ] ) ;
812
814
} else {
815
+ path . parentPath . scope . crawl ( ) ;
813
816
path . insertBefore ( buildInjectExpression ( params , name ) ) ;
814
817
}
815
818
}
@@ -820,6 +823,7 @@ function judgeInjectArraySuspect(path, ctx) {
820
823
trailingComments = path . node . trailingComments ;
821
824
path . node . trailingComments = [ ] ;
822
825
}
826
+ path . parentPath . scope . crawl ( ) ;
823
827
let newNode = path . insertAfter ( buildInjectExpression ( params , name ) ) ;
824
828
newNode . trailingComments = trailingComments ;
825
829
}
@@ -870,6 +874,12 @@ function isGenericProviderName(node) {
870
874
return t . isLiteral ( node ) && is . string ( node . value ) ;
871
875
}
872
876
877
+ function getNamedParam ( p ) {
878
+ let param = p ;
879
+ if ( t . isAssignmentPattern ( p ) ) param = p . left ;
880
+ return param . name ;
881
+ }
882
+
873
883
function getConstructor ( node ) {
874
884
var body = node . body . body ;
875
885
for ( var i = 0 ; i < body . length ; i ++ ) {
0 commit comments