@@ -1060,9 +1060,10 @@ class Parser extends Tapable {
10601060 }
10611061
10621062 walkFunctionDeclaration ( statement ) {
1063+ const wasTopLevel = this . scope . topLevelScope ;
1064+ this . scope . topLevelScope = false ;
10631065 for ( const param of statement . params ) this . walkPattern ( param ) ;
10641066 this . inScope ( statement . params , ( ) => {
1065- this . scope . topLevelScope = false ;
10661067 if ( statement . body . type === "BlockStatement" ) {
10671068 this . detectStrictMode ( statement . body . body ) ;
10681069 this . prewalkStatement ( statement . body ) ;
@@ -1071,6 +1072,7 @@ class Parser extends Tapable {
10711072 this . walkExpression ( statement . body ) ;
10721073 }
10731074 } ) ;
1075+ this . scope . topLevelScope = wasTopLevel ;
10741076 }
10751077
10761078 prewalkImportDeclaration ( statement ) {
@@ -1465,9 +1467,10 @@ class Parser extends Tapable {
14651467 }
14661468
14671469 walkFunctionExpression ( expression ) {
1470+ const wasTopLevel = this . scope . topLevelScope ;
1471+ this . scope . topLevelScope = false ;
14681472 for ( const param of expression . params ) this . walkPattern ( param ) ;
14691473 this . inScope ( expression . params , ( ) => {
1470- this . scope . topLevelScope = false ;
14711474 if ( expression . body . type === "BlockStatement" ) {
14721475 this . detectStrictMode ( expression . body . body ) ;
14731476 this . prewalkStatement ( expression . body ) ;
@@ -1476,6 +1479,7 @@ class Parser extends Tapable {
14761479 this . walkExpression ( expression . body ) ;
14771480 }
14781481 } ) ;
1482+ this . scope . topLevelScope = wasTopLevel ;
14791483 }
14801484
14811485 walkArrowFunctionExpression ( expression ) {
@@ -1621,10 +1625,10 @@ class Parser extends Tapable {
16211625 }
16221626 this . walkExpression ( argOrThis ) ;
16231627 } ;
1628+ const wasTopLevel = this . scope . topLevelScope ;
1629+ this . scope . topLevelScope = false ;
16241630 const params = functionExpression . params ;
1625- const renameThis = currentThis
1626- ? renameArgOrThis . call ( this , currentThis )
1627- : null ;
1631+ const renameThis = currentThis ? renameArgOrThis ( currentThis ) : null ;
16281632 const args = options . map ( renameArgOrThis ) ;
16291633 this . inScope ( params . filter ( ( identifier , idx ) => ! args [ idx ] ) , ( ) => {
16301634 if ( renameThis ) {
@@ -1641,6 +1645,7 @@ class Parser extends Tapable {
16411645 this . walkStatement ( functionExpression . body ) ;
16421646 } else this . walkExpression ( functionExpression . body ) ;
16431647 } ) ;
1648+ this . scope . topLevelScope = wasTopLevel ;
16441649 } ;
16451650 if (
16461651 expression . callee . type === "MemberExpression" &&
@@ -1652,8 +1657,7 @@ class Parser extends Tapable {
16521657 expression . arguments . length > 0
16531658 ) {
16541659 // (function(…) { }.call/bind(?, …))
1655- walkIIFE . call (
1656- this ,
1660+ walkIIFE (
16571661 expression . callee . object ,
16581662 expression . arguments . slice ( 1 ) ,
16591663 expression . arguments [ 0 ]
@@ -1663,7 +1667,7 @@ class Parser extends Tapable {
16631667 expression . arguments
16641668 ) {
16651669 // (function(…) { }(…))
1666- walkIIFE . call ( this , expression . callee , expression . arguments ) ;
1670+ walkIIFE ( expression . callee , expression . arguments , null ) ;
16671671 } else if ( expression . callee . type === "Import" ) {
16681672 result = this . hooks . importCall . call ( expression ) ;
16691673 if ( result === true ) return ;
0 commit comments