@@ -636,6 +636,9 @@ class Parser extends Tapable {
636636 }
637637
638638 walkFunctionDeclaration ( statement ) {
639+ statement . params . forEach ( param => {
640+ this . walkPattern ( param ) ;
641+ } ) ;
639642 this . inScope ( statement . params , function ( ) {
640643 if ( statement . body . type === "BlockStatement" ) {
641644 this . prewalkStatement ( statement . body ) ;
@@ -797,24 +800,15 @@ class Parser extends Tapable {
797800 switch ( declarator . type ) {
798801 case "VariableDeclarator" :
799802 {
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 )
813808 this . scope . definitions . push ( name ) ;
814- }
815809 }
816- } ) ;
817- }
810+ }
811+ } ) ;
818812 break ;
819813 }
820814 }
@@ -827,7 +821,14 @@ class Parser extends Tapable {
827821 case "VariableDeclarator" :
828822 {
829823 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 {
831832 this . walkPattern ( declarator . id ) ;
832833 if ( declarator . init )
833834 this . walkExpression ( declarator . init ) ;
@@ -845,6 +846,11 @@ class Parser extends Tapable {
845846 this [ "walk" + pattern . type ] ( pattern ) ;
846847 }
847848
849+ walkAssignmentPattern ( pattern ) {
850+ this . walkExpression ( pattern . right ) ;
851+ this . walkPattern ( pattern . left ) ;
852+ }
853+
848854 walkObjectPattern ( pattern ) {
849855 for ( let i = 0 , len = pattern . properties . length ; i < len ; i ++ ) {
850856 const prop = pattern . properties [ i ] ;
@@ -912,6 +918,9 @@ class Parser extends Tapable {
912918 }
913919
914920 walkFunctionExpression ( expression ) {
921+ expression . params . forEach ( param => {
922+ this . walkPattern ( param ) ;
923+ } ) ;
915924 this . inScope ( expression . params , function ( ) {
916925 if ( expression . body . type === "BlockStatement" ) {
917926 this . prewalkStatement ( expression . body ) ;
@@ -923,6 +932,9 @@ class Parser extends Tapable {
923932 }
924933
925934 walkArrowFunctionExpression ( expression ) {
935+ expression . params . forEach ( param => {
936+ this . walkPattern ( param ) ;
937+ } ) ;
926938 this . inScope ( expression . params , function ( ) {
927939 if ( expression . body . type === "BlockStatement" ) {
928940 this . prewalkStatement ( expression . body ) ;
@@ -993,8 +1005,10 @@ class Parser extends Tapable {
9931005 }
9941006 } else {
9951007 this . walkExpression ( expression . right ) ;
996- this . scope . renames [ "$" + expression . left . name ] = undefined ;
997- this . walkExpression ( expression . left ) ;
1008+ this . walkPattern ( expression . left ) ;
1009+ this . enterPattern ( expression . left , ( name , decl ) => {
1010+ this . scope . renames [ "$" + name ] = undefined ;
1011+ } ) ;
9981012 }
9991013 }
10001014
@@ -1191,7 +1205,6 @@ class Parser extends Tapable {
11911205
11921206 enterAssignmentPattern ( pattern , onIdent ) {
11931207 this . enterPattern ( pattern . left , onIdent ) ;
1194- this . walkExpression ( pattern . right ) ;
11951208 }
11961209
11971210 evaluateExpression ( expression ) {
0 commit comments