@@ -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 . detectStrictMode ( statement . body . body ) ;
952953 this . prewalkStatement ( statement . body ) ;
@@ -1263,6 +1264,9 @@ class Parser extends Tapable {
12631264 case "TemplateLiteral" :
12641265 this . walkTemplateLiteral ( expression ) ;
12651266 break ;
1267+ case "ThisExpression" :
1268+ this . walkThisExpression ( expression ) ;
1269+ break ;
12661270 case "UnaryExpression" :
12671271 this . walkUnaryExpression ( expression ) ;
12681272 break ;
@@ -1306,6 +1310,7 @@ class Parser extends Tapable {
13061310 for ( const param of expression . params )
13071311 this . walkPattern ( param ) ;
13081312 this . inScope ( expression . params , ( ) => {
1313+ this . scope . topLevelScope = false ;
13091314 if ( expression . body . type === "BlockStatement" ) {
13101315 this . detectStrictMode ( expression . body . body ) ;
13111316 this . prewalkStatement ( expression . body ) ;
@@ -1557,6 +1562,13 @@ class Parser extends Tapable {
15571562 this . walkExpression ( expression . property ) ;
15581563 }
15591564
1565+ walkThisExpression ( expression ) {
1566+ const expressionHook = this . hooks . expression . get ( "this" ) ;
1567+ if ( expressionHook !== undefined ) {
1568+ expressionHook . call ( expression ) ;
1569+ }
1570+ }
1571+
15601572 walkIdentifier ( expression ) {
15611573 if ( ! this . scope . definitions . has ( expression . name ) ) {
15621574 const hook = this . hooks . expression . get ( this . scope . renames . get ( expression . name ) || expression . name ) ;
@@ -1571,6 +1583,7 @@ class Parser extends Tapable {
15711583 inScope ( params , fn ) {
15721584 const oldScope = this . scope ;
15731585 this . scope = {
1586+ topLevelScope : oldScope . topLevelScope ,
15741587 inTry : false ,
15751588 inShorthand : false ,
15761589 isStrict : oldScope . isStrict ,
@@ -1778,6 +1791,7 @@ class Parser extends Tapable {
17781791 const oldState = this . state ;
17791792 const oldComments = this . comments ;
17801793 this . scope = {
1794+ topLevelScope : true ,
17811795 inTry : false ,
17821796 inShorthand : false ,
17831797 isStrict : false ,
0 commit comments