@@ -54,7 +54,7 @@ function getInitialClassInfo() {
54
54
// shadowing, assignments, etc. To keep things simple, we only
55
55
// maintain one set of aliases per method and accept that it will
56
56
// produce some false negatives.
57
- aliases : new Set ( )
57
+ aliases : null
58
58
} ;
59
59
}
60
60
@@ -86,6 +86,7 @@ module.exports = {
86
86
87
87
const isAliasedStateReference =
88
88
node . type === 'Identifier' &&
89
+ classInfo . aliases &&
89
90
classInfo . aliases . has ( node . name ) ;
90
91
91
92
return isDirectStateReference || isAliasedStateReference ;
@@ -124,7 +125,10 @@ module.exports = {
124
125
for ( const prop of node . properties ) {
125
126
if ( prop . type === 'Property' ) {
126
127
addUsedStateField ( prop . key ) ;
127
- } else if ( prop . type === 'ExperimentalRestProperty' ) {
128
+ } else if (
129
+ prop . type === 'ExperimentalRestProperty' &&
130
+ classInfo . aliases
131
+ ) {
128
132
classInfo . aliases . add ( getName ( prop . argument ) ) ;
129
133
}
130
134
}
@@ -135,14 +139,14 @@ module.exports = {
135
139
function handleAssignment ( left , right ) {
136
140
switch ( left . type ) {
137
141
case 'Identifier' :
138
- if ( isStateReference ( right ) ) {
142
+ if ( isStateReference ( right ) && classInfo . aliases ) {
139
143
classInfo . aliases . add ( left . name ) ;
140
144
}
141
145
break ;
142
146
case 'ObjectPattern' :
143
147
if ( isStateReference ( right ) ) {
144
148
handleStateDestructuring ( left ) ;
145
- } else if ( isThisExpression ( right ) ) {
149
+ } else if ( isThisExpression ( right ) && classInfo . aliases ) {
146
150
for ( const prop of left . properties ) {
147
151
if ( prop . type === 'Property' && getName ( prop . key ) === 'state' ) {
148
152
const name = getName ( prop . value ) ;
@@ -244,6 +248,18 @@ module.exports = {
244
248
}
245
249
} ,
246
250
251
+ 'ClassProperty:exit' ( node ) {
252
+ if (
253
+ classInfo &&
254
+ ! node . static &&
255
+ node . value &&
256
+ node . value . type === 'ArrowFunctionExpression'
257
+ ) {
258
+ // Forget our set of local aliases.
259
+ classInfo . aliases = null ;
260
+ }
261
+ } ,
262
+
247
263
MethodDefinition ( ) {
248
264
if ( ! classInfo ) {
249
265
return ;
@@ -252,6 +268,14 @@ module.exports = {
252
268
classInfo . aliases = new Set ( ) ;
253
269
} ,
254
270
271
+ 'MethodDefinition:exit' ( ) {
272
+ if ( ! classInfo ) {
273
+ return ;
274
+ }
275
+ // Forget our set of local aliases.
276
+ classInfo . aliases = null ;
277
+ } ,
278
+
255
279
FunctionExpression ( node ) {
256
280
if ( ! classInfo ) {
257
281
return ;
0 commit comments