JS: recognize binding decorators on classes

This commit is contained in:
Esben Sparre Andreasen
2018-10-08 07:58:12 +02:00
parent 4720c5ab60
commit a668f906bc
2 changed files with 19 additions and 1 deletions

View File

@@ -45,7 +45,11 @@ private predicate isBoundInMethod(MethodDeclaration method) {
)
or
exists (Expr decoration, string name |
decoration = method.getADecorator().getExpression() and
(
decoration = method.getADecorator().getExpression()
or
decoration = method.getDeclaringType().(ClassDefinition).getADecorator().getExpression()
) and
name.regexpMatch("(?i).*(bind|bound).*") |
// @autobind
decoration.(Identifier).getName() = name or

View File

@@ -120,4 +120,18 @@ class Component1 extends React.Component {
}
@autobind
class Component2 extends React.Component {
render() {
return <div>
<div onClick={this.bound_throughClassDecorator_autobind}/> // OK
</div>;
}
bound_throughClassDecorator_autobind() {
this.setState({ });
}
}
// semmle-extractor-options: --experimental