@@ -37,10 +37,10 @@ export function isClassComponent(node: TSESTree.Node): node is TSESTreeClass {
3737 if ( "superClass" in node && node . superClass != null ) {
3838 const re = / ^ (?: P u r e ) ? C o m p o n e n t $ / u;
3939 switch ( true ) {
40- case node . superClass . type === AST . Identifier :
40+ case Check . isIdentifier ( node . superClass ) :
4141 return re . test ( node . superClass . name ) ;
4242 case node . superClass . type === AST . MemberExpression
43- && node . superClass . property . type === AST . Identifier :
43+ && Check . isIdentifier ( node . superClass . property ) :
4444 return re . test ( node . superClass . property . name ) ;
4545 }
4646 }
@@ -57,10 +57,10 @@ export function isPureComponent(node: TSESTree.Node) {
5757 if ( "superClass" in node && node . superClass != null ) {
5858 const re = / ^ P u r e C o m p o n e n t $ / u;
5959 switch ( true ) {
60- case node . superClass . type === AST . Identifier :
60+ case Check . isIdentifier ( node . superClass ) :
6161 return re . test ( node . superClass . name ) ;
6262 case node . superClass . type === AST . MemberExpression
63- && node . superClass . property . type === AST . Identifier :
63+ && Check . isIdentifier ( node . superClass . property ) :
6464 return re . test ( node . superClass . property . name ) ;
6565 }
6666 }
@@ -75,7 +75,7 @@ function createLifecycleChecker(methodName: string, isStatic = false) {
7575 return ( node : TSESTree . Node ) : node is TSESTreeMethodOrPropertyDefinition => (
7676 Check . isPropertyOrMethod ( node )
7777 && node . static === isStatic
78- && node . key . type === AST . Identifier
78+ && Check . isIdentifier ( node . key )
7979 && node . key . name === methodName
8080 ) ;
8181}
@@ -110,7 +110,6 @@ export const isUnsafeComponentWillMount = createLifecycleChecker("UNSAFE_compone
110110export const isUnsafeComponentWillReceiveProps = createLifecycleChecker ( "UNSAFE_componentWillReceiveProps" ) ;
111111/** @deprecated Class components are legacy. */
112112export const isUnsafeComponentWillUpdate = createLifecycleChecker ( "UNSAFE_componentWillUpdate" ) ;
113-
114113/** @deprecated Class components are legacy. */
115114export const isGetDefaultProps = createLifecycleChecker ( "getDefaultProps" , true ) ;
116115/** @deprecated Class components are legacy. */
@@ -130,7 +129,7 @@ export const isGetDerivedStateFromError = createLifecycleChecker("getDerivedStat
130129 */
131130export function isRenderMethodLike ( node : TSESTree . Node ) : node is TSESTreeMethodOrPropertyDefinition {
132131 return Check . isPropertyOrMethod ( node )
133- && node . key . type === AST . Identifier
132+ && Check . isIdentifier ( node . key )
134133 && node . key . name . startsWith ( "render" )
135134 && Check . isOneOf ( [ AST . ClassDeclaration , AST . ClassExpression ] ) ( node . parent . parent ) ;
136135}
@@ -144,9 +143,8 @@ export function isRenderMethodCallback(node: TSESTreeFunction) {
144143 const parent = node . parent ;
145144 const grandparent = parent . parent ;
146145 const greatGrandparent = grandparent ?. parent ;
147- return greatGrandparent != null
148- && isRenderMethodLike ( parent )
149- && isClassComponent ( greatGrandparent ) ;
146+ if ( greatGrandparent == null ) return false ;
147+ return isRenderMethodLike ( parent ) && isClassComponent ( greatGrandparent ) ;
150148}
151149
152150// #endregion
@@ -163,7 +161,7 @@ export function isThisSetStateCall(node: TSESTree.CallExpression) {
163161 const callee = Extract . unwrap ( node . callee ) ;
164162 return (
165163 callee . type === AST . MemberExpression
166- && callee . object . type === AST . ThisExpression
164+ && Extract . unwrap ( callee . object ) . type === AST . ThisExpression
167165 && Extract . getCalleeName ( node ) === "setState"
168166 ) ;
169167}
@@ -178,11 +176,12 @@ export function isAssignmentToThisState(node: TSESTree.AssignmentExpression) {
178176 const { left } = node ;
179177 let current : TSESTree . Node = Extract . unwrap ( left ) ;
180178 while ( current . type === AST . MemberExpression ) {
181- const { object, property } = current ;
182- if ( object . type === AST . ThisExpression && property . type === AST . Identifier && property . name === "state" ) {
179+ const object = Extract . unwrap ( current . object ) ;
180+ const property = current . property ;
181+ if ( object . type === AST . ThisExpression && Check . isIdentifier ( property , "state" ) ) {
183182 return true ;
184183 }
185- current = Extract . unwrap ( object ) ;
184+ current = object ;
186185 }
187186 return false ;
188187}
0 commit comments