@@ -1059,16 +1059,18 @@ class Parser extends Tapable {
10591059 walkCallExpression ( expression ) {
10601060 let result ;
10611061
1062- function walkIIFE ( functionExpression , options ) {
1063- const params = functionExpression . params ;
1064- const args = options . map ( function ( arg ) {
1065- const renameIdentifier = this . getRenameIdentifier ( arg ) ;
1066- if ( renameIdentifier && this . applyPluginsBailResult1 ( "can-rename " + renameIdentifier , arg ) ) {
1067- if ( ! this . applyPluginsBailResult1 ( "rename " + renameIdentifier , arg ) )
1062+ function walkIIFE ( functionExpression , options , currentThis ) {
1063+ function renameArgOrThis ( argOrThis ) {
1064+ const renameIdentifier = this . getRenameIdentifier ( argOrThis ) ;
1065+ if ( renameIdentifier && this . applyPluginsBailResult1 ( "can-rename " + renameIdentifier , argOrThis ) ) {
1066+ if ( ! this . applyPluginsBailResult1 ( "rename " + renameIdentifier , argOrThis ) )
10681067 return renameIdentifier ;
10691068 }
1070- this . walkExpression ( arg ) ;
1071- } , this ) ;
1069+ this . walkExpression ( argOrThis ) ;
1070+ }
1071+ const params = functionExpression . params ;
1072+ const args = options . map ( renameArgOrThis , this ) ;
1073+ const renameThis = currentThis ? renameArgOrThis . call ( this , currentThis ) : null ;
10721074 this . inScope ( params . filter ( function ( identifier , idx ) {
10731075 return ! args [ idx ] ;
10741076 } ) , function ( ) {
@@ -1078,6 +1080,9 @@ class Parser extends Tapable {
10781080 if ( ! params [ i ] || params [ i ] . type !== "Identifier" ) continue ;
10791081 this . scope . renames [ "$" + params [ i ] . name ] = param ;
10801082 }
1083+ if ( renameThis ) {
1084+ this . scope . renames . $this = renameThis ;
1085+ }
10811086 if ( functionExpression . body . type === "BlockStatement" ) {
10821087 this . prewalkStatement ( functionExpression . body ) ;
10831088 this . walkStatement ( functionExpression . body ) ;
@@ -1090,11 +1095,10 @@ class Parser extends Tapable {
10901095 ! expression . callee . computed &&
10911096 ( [ "call" , "bind" ] ) . indexOf ( expression . callee . property . name ) >= 0 &&
10921097 expression . arguments &&
1093- expression . arguments . length > 1
1098+ expression . arguments . length > 0
10941099 ) {
10951100 // (function(...) { }.call/bind(?, ...))
1096- walkIIFE . call ( this , expression . callee . object , expression . arguments . slice ( 1 ) ) ;
1097- this . walkExpression ( expression . arguments [ 0 ] ) ;
1101+ walkIIFE . call ( this , expression . callee . object , expression . arguments . slice ( 1 ) , expression . arguments [ 0 ] ) ;
10981102 } else if ( expression . callee . type === "FunctionExpression" && expression . arguments ) {
10991103 // (function(...) { }(...))
11001104 walkIIFE . call ( this , expression . callee , expression . arguments ) ;
@@ -1134,8 +1138,13 @@ class Parser extends Tapable {
11341138 exprName . unshift ( expr . property . name || expr . property . value ) ;
11351139 expr = expr . object ;
11361140 }
1137- if ( expr . type === "Identifier" && this . scope . definitions . indexOf ( expr . name ) === - 1 ) {
1138- exprName . unshift ( this . scope . renames [ "$" + expr . name ] || expr . name ) ;
1141+ if ( ( expr . type === "Identifier" && this . scope . definitions . indexOf ( expr . name ) === - 1 ) ||
1142+ ( expr . type === "ThisExpression" && this . scope . renames . $this ) ) {
1143+ if ( expr . type === "Identifier" ) {
1144+ exprName . unshift ( this . scope . renames [ "$" + expr . name ] || expr . name ) ;
1145+ } else {
1146+ exprName . unshift ( this . scope . renames . $this ) ;
1147+ }
11391148 let result = this . applyPluginsBailResult1 ( "expression " + exprName . join ( "." ) , expression ) ;
11401149 if ( result === true )
11411150 return ;
0 commit comments