@@ -947,6 +947,7 @@ class Parser extends Tapable {
947947 for ( const param of statement . params )
948948 this . walkPattern ( param ) ;
949949 this . inScope ( statement . params , ( ) => {
950+ this . scope . topLevelScope = false ;
950951 if ( statement . body . type === "BlockStatement" ) {
951952 this . prewalkStatement ( statement . body ) ;
952953 this . walkStatement ( statement . body ) ;
@@ -1272,6 +1273,9 @@ class Parser extends Tapable {
12721273 case "TemplateLiteral" :
12731274 this . walkTemplateLiteral ( expression ) ;
12741275 break ;
1276+ case "ThisExpression" :
1277+ this . walkThisExpression ( expression ) ;
1278+ break ;
12751279 case "UnaryExpression" :
12761280 this . walkUnaryExpression ( expression ) ;
12771281 break ;
@@ -1315,6 +1319,7 @@ class Parser extends Tapable {
13151319 for ( const param of expression . params )
13161320 this . walkPattern ( param ) ;
13171321 this . inScope ( expression . params , ( ) => {
1322+ this . scope . topLevelScope = false ;
13181323 if ( expression . body . type === "BlockStatement" ) {
13191324 this . prewalkStatement ( expression . body ) ;
13201325 this . walkStatement ( expression . body ) ;
@@ -1564,6 +1569,13 @@ class Parser extends Tapable {
15641569 this . walkExpression ( expression . property ) ;
15651570 }
15661571
1572+ walkThisExpression ( expression ) {
1573+ const expressionHook = this . hooks . expression . get ( "this" ) ;
1574+ if ( expressionHook !== undefined ) {
1575+ expressionHook . call ( expression ) ;
1576+ }
1577+ }
1578+
15671579 walkIdentifier ( expression ) {
15681580 if ( ! this . scope . definitions . has ( expression . name ) ) {
15691581 const hook = this . hooks . expression . for ( this . scope . renames . get ( expression . name ) || expression . name ) ;
@@ -1578,6 +1590,7 @@ class Parser extends Tapable {
15781590 inScope ( params , fn ) {
15791591 const oldScope = this . scope ;
15801592 this . scope = {
1593+ topLevelScope : oldScope . topLevelScope ,
15811594 inTry : false ,
15821595 inShorthand : false ,
15831596 definitions : oldScope . definitions . createChild ( ) ,
@@ -1774,6 +1787,7 @@ class Parser extends Tapable {
17741787 const oldState = this . state ;
17751788 const oldComments = this . comments ;
17761789 this . scope = {
1790+ topLevelScope : true ,
17771791 inTry : false ,
17781792 definitions : new StackedSetMap ( ) ,
17791793 renames : new StackedSetMap ( )
0 commit comments