@@ -636,6 +636,9 @@ class Parser extends Tapable {
636
636
}
637
637
638
638
walkFunctionDeclaration ( statement ) {
639
+ statement . params . forEach ( param => {
640
+ this . walkPattern ( param ) ;
641
+ } ) ;
639
642
this . inScope ( statement . params , function ( ) {
640
643
if ( statement . body . type === "BlockStatement" ) {
641
644
this . prewalkStatement ( statement . body ) ;
@@ -797,24 +800,15 @@ class Parser extends Tapable {
797
800
switch ( declarator . type ) {
798
801
case "VariableDeclarator" :
799
802
{
800
- const renameIdentifier = declarator . init && this . getRenameIdentifier ( declarator . init ) ;
801
- if ( renameIdentifier && declarator . id . type === "Identifier" && this . applyPluginsBailResult1 ( "can-rename " + renameIdentifier , declarator . init ) ) {
802
- // renaming with "var a = b;"
803
- if ( ! this . applyPluginsBailResult1 ( "rename " + renameIdentifier , declarator . init ) ) {
804
- this . scope . renames [ "$" + declarator . id . name ] = this . scope . renames [ "$" + renameIdentifier ] || renameIdentifier ;
805
- const idx = this . scope . definitions . indexOf ( declarator . id . name ) ;
806
- if ( idx >= 0 ) this . scope . definitions . splice ( idx , 1 ) ;
807
- }
808
- } else {
809
- this . enterPattern ( declarator . id , ( name , decl ) => {
810
- if ( ! this . applyPluginsBailResult1 ( "var-" + declarator . kind + " " + name , decl ) ) {
811
- if ( ! this . applyPluginsBailResult1 ( "var " + name , decl ) ) {
812
- this . scope . renames [ "$" + name ] = undefined ;
803
+ this . enterPattern ( declarator . id , ( name , decl ) => {
804
+ if ( ! this . applyPluginsBailResult1 ( "var-" + declarator . kind + " " + name , decl ) ) {
805
+ if ( ! this . applyPluginsBailResult1 ( "var " + name , decl ) ) {
806
+ this . scope . renames [ "$" + name ] = undefined ;
807
+ if ( this . scope . definitions . indexOf ( name ) < 0 )
813
808
this . scope . definitions . push ( name ) ;
814
- }
815
809
}
816
- } ) ;
817
- }
810
+ }
811
+ } ) ;
818
812
break ;
819
813
}
820
814
}
@@ -827,7 +821,14 @@ class Parser extends Tapable {
827
821
case "VariableDeclarator" :
828
822
{
829
823
const renameIdentifier = declarator . init && this . getRenameIdentifier ( declarator . init ) ;
830
- if ( ! renameIdentifier || declarator . id . type !== "Identifier" || ! this . applyPluginsBailResult1 ( "can-rename " + renameIdentifier , declarator . init ) ) {
824
+ if ( renameIdentifier && declarator . id . type === "Identifier" && this . applyPluginsBailResult1 ( "can-rename " + renameIdentifier , declarator . init ) ) {
825
+ // renaming with "var a = b;"
826
+ if ( ! this . applyPluginsBailResult1 ( "rename " + renameIdentifier , declarator . init ) ) {
827
+ this . scope . renames [ "$" + declarator . id . name ] = this . scope . renames [ "$" + renameIdentifier ] || renameIdentifier ;
828
+ const idx = this . scope . definitions . indexOf ( declarator . id . name ) ;
829
+ if ( idx >= 0 ) this . scope . definitions . splice ( idx , 1 ) ;
830
+ }
831
+ } else {
831
832
this . walkPattern ( declarator . id ) ;
832
833
if ( declarator . init )
833
834
this . walkExpression ( declarator . init ) ;
@@ -845,6 +846,11 @@ class Parser extends Tapable {
845
846
this [ "walk" + pattern . type ] ( pattern ) ;
846
847
}
847
848
849
+ walkAssignmentPattern ( pattern ) {
850
+ this . walkExpression ( pattern . right ) ;
851
+ this . walkPattern ( pattern . left ) ;
852
+ }
853
+
848
854
walkObjectPattern ( pattern ) {
849
855
for ( let i = 0 , len = pattern . properties . length ; i < len ; i ++ ) {
850
856
const prop = pattern . properties [ i ] ;
@@ -912,6 +918,9 @@ class Parser extends Tapable {
912
918
}
913
919
914
920
walkFunctionExpression ( expression ) {
921
+ expression . params . forEach ( param => {
922
+ this . walkPattern ( param ) ;
923
+ } ) ;
915
924
this . inScope ( expression . params , function ( ) {
916
925
if ( expression . body . type === "BlockStatement" ) {
917
926
this . prewalkStatement ( expression . body ) ;
@@ -923,6 +932,9 @@ class Parser extends Tapable {
923
932
}
924
933
925
934
walkArrowFunctionExpression ( expression ) {
935
+ expression . params . forEach ( param => {
936
+ this . walkPattern ( param ) ;
937
+ } ) ;
926
938
this . inScope ( expression . params , function ( ) {
927
939
if ( expression . body . type === "BlockStatement" ) {
928
940
this . prewalkStatement ( expression . body ) ;
@@ -1192,7 +1204,6 @@ class Parser extends Tapable {
1192
1204
1193
1205
enterAssignmentPattern ( pattern , onIdent ) {
1194
1206
this . enterPattern ( pattern . left , onIdent ) ;
1195
- this . walkExpression ( pattern . right ) ;
1196
1207
}
1197
1208
1198
1209
evaluateExpression ( expression ) {
0 commit comments