mirror of
https://github.com/github/codeql.git
synced 2026-04-29 10:45:15 +02:00
JS: simplify isReactImportForJSX to isReactForJSX
This commit is contained in:
@@ -49,17 +49,20 @@ predicate isPropertyFilter(UnusedLocal v) {
|
||||
)
|
||||
}
|
||||
|
||||
predicate hasJsxInScope(UnusedLocal v) {
|
||||
any(JSXNode n).getParent+() = v.getScope().getScopeElement()
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if `v` is an import of React, and there is a JSX element that implicitly
|
||||
* references it.
|
||||
*/
|
||||
predicate isReactImportForJSX(UnusedLocal v) {
|
||||
exists(JSXNode jsx, TopLevel tl |
|
||||
jsx.getTopLevel() = tl and
|
||||
v.getADeclaration().getTopLevel() = tl and
|
||||
(
|
||||
v.getName() = "React"
|
||||
or
|
||||
* Holds if `v` is a "React" variable that is implicitly used by a JSX element.
|
||||
*/
|
||||
predicate isReactForJSX(UnusedLocal v) {
|
||||
hasJsxInScope(v) and
|
||||
(
|
||||
v.getName() = "React"
|
||||
or
|
||||
exists(TopLevel tl |
|
||||
tl = v.getADeclaration().getTopLevel() |
|
||||
// legacy `@jsx` pragmas
|
||||
exists(JSXPragma p | p.getTopLevel() = tl | p.getDOMName() = v.getName())
|
||||
or
|
||||
@@ -69,12 +72,6 @@ predicate isReactImportForJSX(UnusedLocal v) {
|
||||
plugin.getJsxFactoryVariableName() = v.getName()
|
||||
)
|
||||
)
|
||||
|
|
||||
v.getADeclaration() = any(ImportDeclaration imp).getASpecifier().getLocal()
|
||||
or
|
||||
exists(VariableDeclarator vd | vd.getBindingPattern() = v.getADeclaration() |
|
||||
vd.getInit() instanceof Require
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -158,7 +155,7 @@ predicate whitelisted(UnusedLocal v) {
|
||||
// exclude variables used to filter out unwanted properties
|
||||
isPropertyFilter(v) or
|
||||
// exclude imports of React that are implicitly referenced by JSX
|
||||
isReactImportForJSX(v) or
|
||||
isReactForJSX(v) or
|
||||
// exclude names that are used as types
|
||||
exists (VarDecl vd |
|
||||
v = vd.getVariable() |
|
||||
|
||||
Reference in New Issue
Block a user