Skip to content

Commit a668f90

Browse files
author
Esben Sparre Andreasen
committed
JS: recognize binding decorators on classes
1 parent 4720c5a commit a668f90

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

javascript/ql/src/Expressions/UnboundEventHandlerReceiver.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ private predicate isBoundInMethod(MethodDeclaration method) {
4545
)
4646
or
4747
exists (Expr decoration, string name |
48-
decoration = method.getADecorator().getExpression() and
48+
(
49+
decoration = method.getADecorator().getExpression()
50+
or
51+
decoration = method.getDeclaringType().(ClassDefinition).getADecorator().getExpression()
52+
) and
4953
name.regexpMatch("(?i).*(bind|bound).*") |
5054
// @autobind
5155
decoration.(Identifier).getName() = name or

javascript/ql/test/query-tests/Expressions/UnboundEventHandlerReceiver/tst.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,18 @@ class Component1 extends React.Component {
120120

121121
}
122122

123+
@autobind
124+
class Component2 extends React.Component {
125+
126+
render() {
127+
return <div>
128+
<div onClick={this.bound_throughClassDecorator_autobind}/> // OK
129+
</div>;
130+
}
131+
132+
bound_throughClassDecorator_autobind() {
133+
this.setState({ });
134+
}
135+
136+
}
123137
// semmle-extractor-options: --experimental

0 commit comments

Comments
 (0)