Skip to content

Commit 8b60314

Browse files
authored
Merge pull request #1617 from asger-semmle/documentable
Approved by xiemaisi
2 parents 247848c + 1e451bc commit 8b60314

File tree

8 files changed

+290
-89
lines changed

8 files changed

+290
-89
lines changed

javascript/ql/src/semmle/javascript/Expr.qll

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,27 @@ class ExprOrType extends @exprortype, Documentable {
3434
result = getOwnDocumentation()
3535
or
3636
// if there is no JSDoc for the expression itself, check the enclosing property or statement
37+
not exists(getOwnDocumentation()) and
3738
(
38-
not exists(getOwnDocumentation()) and
39-
if getParent() instanceof Property
40-
then result = getParent().(Property).getDocumentation()
41-
else
42-
if getParent() instanceof MethodDeclaration
43-
then result = getParent().(MethodDeclaration).getDocumentation()
44-
else result = getEnclosingStmt().getDocumentation()
39+
exists(Property prop | prop = getParent() |
40+
result = prop.getDocumentation()
41+
)
42+
or
43+
exists(MethodDeclaration decl | decl = getParent() |
44+
result = decl.getDocumentation()
45+
)
46+
or
47+
exists(VariableDeclarator decl | decl = getParent() |
48+
result = decl.getDocumentation()
49+
)
50+
or
51+
exists(DeclStmt stmt | this = stmt.getDecl(0) |
52+
result = stmt.getDocumentation()
53+
)
54+
or
55+
exists(DotExpr dot | this = dot.getProperty() |
56+
result = dot.getDocumentation()
57+
)
4558
)
4659
}
4760

@@ -50,7 +63,7 @@ class ExprOrType extends @exprortype, Documentable {
5063
exists(Token tk | tk = result.getComment().getNextToken() |
5164
tk = this.getFirstToken()
5265
or
53-
exists(Expr p | p.stripParens() = this | tk = p.getFirstToken())
66+
exists(Expr p | p.getUnderlyingValue() = this | tk = p.getFirstToken())
5467
)
5568
}
5669

javascript/ql/test/library-tests/JSDoc/AssignExpr_getDocumentation.qll

Lines changed: 0 additions & 5 deletions
This file was deleted.

javascript/ql/test/library-tests/JSDoc/Function_getDocumentation.qll

Lines changed: 0 additions & 3 deletions
This file was deleted.

javascript/ql/test/library-tests/JSDoc/VarDeclStmt_getDocumentation.qll

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import javascript
2+
3+
query predicate test_AssignExpr_getDocumentation(AssignExpr assgn, JSDoc res) {
4+
res = assgn.getDocumentation()
5+
}
6+
7+
query predicate test_Function_getDocumentation(Function f, JSDoc res) { res = f.getDocumentation() }
8+
9+
query predicate test_VarDeclStmt_getDocumentation(VarDeclStmt vds, JSDoc res) {
10+
res = vds.getDocumentation()
11+
}
12+
13+
query predicate test_OtherExpr_getDocumentation(Expr e, JSDoc res) {
14+
res = e.getDocumentation() and
15+
(
16+
not e instanceof AssignExpr and
17+
not e instanceof Function
18+
)
19+
}

javascript/ql/test/library-tests/JSDoc/tests.expected

Lines changed: 248 additions & 64 deletions
Large diffs are not rendered by default.

javascript/ql/test/library-tests/JSDoc/tests.ql

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import JSDocUnionTypeExpr
22
import JSDocArrayTypeExpr
33
import Parameter_getDocumentation
44
import JSDocRestParameterTypeExpr
5-
import AssignExpr_getDocumentation
5+
import getDocumentation
66
import JSDocRecordTypeExpr
77
import JSDoc
88
import JSDocTag
@@ -11,10 +11,8 @@ import JSDocFunctionTypeExpr
1111
import JSDocNullableTypeExpr
1212
import next_token
1313
import JSDocTypeExpr
14-
import Function_getDocumentation
1514
import JSDocOptionalParameterTypeExpr
1615
import getParameterTag
17-
import VarDeclStmt_getDocumentation
1816
import JSDocAppliedTypeExpr
1917
import JSDocNonNullableTypeExpr
2018
import ParExpr_getDocumentation

javascript/ql/test/library-tests/JSDoc/tst.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function foo(/** number */ a, /** number */ b) {
155155
* @type {Function[]}
156156
* @private
157157
*/
158-
this.handlers_ = [];
158+
this.handlers_ = [1,2,3];
159159

160160
/**
161161
* Sets the component's root element to the given element.

0 commit comments

Comments
 (0)