@@ -49,24 +49,29 @@ predicate isPropertyFilter(UnusedLocal v) {
4949 )
5050}
5151
52+ predicate hasJsxInScope ( UnusedLocal v ) {
53+ any ( JSXNode n ) .getParent + ( ) = v .getScope ( ) .getScopeElement ( )
54+ }
55+
5256/**
53- * Holds if `v` is an import of React, and there is a JSX element that implicitly
54- * references it.
55- */
56- predicate isReactImportForJSX ( UnusedLocal v ) {
57- exists ( ImportSpecifier is |
58- is .getLocal ( ) = v .getADeclaration ( ) and
59- exists ( JSXNode jsx | jsx .getTopLevel ( ) = is .getTopLevel ( ) )
60- |
57+ * Holds if `v` is a "React" variable that is implicitly used by a JSX element.
58+ */
59+ predicate isReactForJSX ( UnusedLocal v ) {
60+ hasJsxInScope ( v ) and
61+ (
6162 v .getName ( ) = "React"
6263 or
63- // legacy `@jsx` pragmas
64- exists ( JSXPragma p | p .getTopLevel ( ) = is .getTopLevel ( ) | p .getDOMName ( ) = v .getName ( ) )
65- or
66- // JSX pragma from a .babelrc file
67- exists ( Babel:: TransformReactJsxConfig plugin |
68- plugin .appliesTo ( is .getTopLevel ( ) ) and
69- plugin .getJsxFactoryVariableName ( ) = v .getName ( ) )
64+ exists ( TopLevel tl |
65+ tl = v .getADeclaration ( ) .getTopLevel ( ) |
66+ // legacy `@jsx` pragmas
67+ exists ( JSXPragma p | p .getTopLevel ( ) = tl | p .getDOMName ( ) = v .getName ( ) )
68+ or
69+ // JSX pragma from a .babelrc file
70+ exists ( Babel:: TransformReactJsxConfig plugin |
71+ plugin .appliesTo ( tl ) and
72+ plugin .getJsxFactoryVariableName ( ) = v .getName ( )
73+ )
74+ )
7075 )
7176}
7277
@@ -150,7 +155,7 @@ predicate whitelisted(UnusedLocal v) {
150155 // exclude variables used to filter out unwanted properties
151156 isPropertyFilter ( v ) or
152157 // exclude imports of React that are implicitly referenced by JSX
153- isReactImportForJSX ( v ) or
158+ isReactForJSX ( v ) or
154159 // exclude names that are used as types
155160 exists ( VarDecl vd |
156161 v = vd .getVariable ( ) |
0 commit comments