Skip to content

Commit 1e451bc

Browse files
committed
JS: Restrict Expr.getDocumentation()
1 parent ed56939 commit 1e451bc

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
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/tests.expected

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ test_OtherExpr_getDocumentation
138138
| tst.js:55:1:55:16 | project.TriState | tst.js:51:1:54:3 | /**\\n * ... er}\\n */ |
139139
| tst.js:55:9:55:16 | TriState | tst.js:51:1:54:3 | /**\\n * ... er}\\n */ |
140140
| tst.js:55:20:59:1 | {\\n TRU ... BE: 0\\n} | tst.js:51:1:54:3 | /**\\n * ... er}\\n */ |
141-
| tst.js:57:11:57:11 | 1 | tst.js:51:1:54:3 | /**\\n * ... er}\\n */ |
142141
| tst.js:62:1:62:3 | foo | tst.js:61:1:61:14 | /** @export */ |
143142
| tst.js:62:1:62:17 | foo.MyPublicClass | tst.js:61:1:61:14 | /** @export */ |
144143
| tst.js:62:1:62:27 | foo.MyP ... ototype | tst.js:61:1:61:14 | /** @export */ |
@@ -194,9 +193,6 @@ test_OtherExpr_getDocumentation
194193
| tst.js:158:1:158:14 | this.handlers_ | tst.js:153:1:157:3 | /**\\n * ... ate\\n */ |
195194
| tst.js:158:6:158:14 | handlers_ | tst.js:153:1:157:3 | /**\\n * ... ate\\n */ |
196195
| tst.js:158:18:158:24 | [1,2,3] | tst.js:153:1:157:3 | /**\\n * ... ate\\n */ |
197-
| tst.js:158:19:158:19 | 1 | tst.js:153:1:157:3 | /**\\n * ... ate\\n */ |
198-
| tst.js:158:21:158:21 | 2 | tst.js:153:1:157:3 | /**\\n * ... ate\\n */ |
199-
| tst.js:158:23:158:23 | 3 | tst.js:153:1:157:3 | /**\\n * ... ate\\n */ |
200196
| tst.js:166:1:166:4 | goog | tst.js:160:1:165:3 | /**\\n * ... ted\\n */ |
201197
| tst.js:166:1:166:7 | goog.ui | tst.js:160:1:165:3 | /**\\n * ... ted\\n */ |
202198
| tst.js:166:1:166:17 | goog.ui.Component | tst.js:160:1:165:3 | /**\\n * ... ted\\n */ |
@@ -252,7 +248,6 @@ test_OtherExpr_getDocumentation
252248
| tst.js:258:34:258:36 | foo | tst.js:258:1:258:28 | /** @ty ... ng>} */ |
253249
| tst.js:258:34:258:48 | foo = new Foo() | tst.js:258:1:258:28 | /** @ty ... ng>} */ |
254250
| tst.js:258:40:258:48 | new Foo() | tst.js:258:1:258:28 | /** @ty ... ng>} */ |
255-
| tst.js:258:44:258:46 | Foo | tst.js:258:1:258:28 | /** @ty ... ng>} */ |
256251
| tst.js:259:40:259:50 | (new Foo()) | tst.js:259:11:259:38 | /** @ty ... ng>} */ |
257252
| tst.js:259:41:259:49 | new Foo() | tst.js:259:11:259:38 | /** @ty ... ng>} */ |
258253
| tst.js:266:1:266:3 | Bar | tst.js:261:1:265:3 | /**\\n * ... e T\\n */ |
@@ -285,31 +280,13 @@ test_OtherExpr_getDocumentation
285280
| tst.js:343:1:343:8 | identity | tst.js:338:1:342:3 | /**\\n * ... e T\\n */ |
286281
| tst.js:345:27:345:29 | msg | tst.js:345:1:345:21 | /** @ty ... ing} */ |
287282
| tst.js:345:27:345:69 | msg = i ... world") | tst.js:345:1:345:21 | /** @ty ... ing} */ |
288-
| tst.js:345:33:345:40 | identity | tst.js:345:1:345:21 | /** @ty ... ing} */ |
289-
| tst.js:345:33:345:49 | identity("hello") | tst.js:345:1:345:21 | /** @ty ... ing} */ |
290283
| tst.js:345:33:345:69 | identit ... world") | tst.js:345:1:345:21 | /** @ty ... ing} */ |
291-
| tst.js:345:42:345:48 | "hello" | tst.js:345:1:345:21 | /** @ty ... ing} */ |
292-
| tst.js:345:53:345:60 | identity | tst.js:345:1:345:21 | /** @ty ... ing} */ |
293-
| tst.js:345:53:345:69 | identity("world") | tst.js:345:1:345:21 | /** @ty ... ing} */ |
294-
| tst.js:345:62:345:68 | "world" | tst.js:345:1:345:21 | /** @ty ... ing} */ |
295284
| tst.js:346:27:346:29 | sum | tst.js:346:1:346:21 | /** @ty ... ber} */ |
296285
| tst.js:346:27:346:57 | sum = i ... tity(2) | tst.js:346:1:346:21 | /** @ty ... ber} */ |
297-
| tst.js:346:33:346:40 | identity | tst.js:346:1:346:21 | /** @ty ... ber} */ |
298-
| tst.js:346:33:346:43 | identity(2) | tst.js:346:1:346:21 | /** @ty ... ber} */ |
299286
| tst.js:346:33:346:57 | identit ... tity(2) | tst.js:346:1:346:21 | /** @ty ... ber} */ |
300-
| tst.js:346:42:346:42 | 2 | tst.js:346:1:346:21 | /** @ty ... ber} */ |
301-
| tst.js:346:47:346:54 | identity | tst.js:346:1:346:21 | /** @ty ... ber} */ |
302-
| tst.js:346:47:346:57 | identity(2) | tst.js:346:1:346:21 | /** @ty ... ber} */ |
303-
| tst.js:346:56:346:56 | 2 | tst.js:346:1:346:21 | /** @ty ... ber} */ |
304287
| tst.js:347:27:347:29 | sum | tst.js:347:1:347:21 | /** @ty ... ber} */ |
305288
| tst.js:347:27:347:59 | sum = i ... ty("2") | tst.js:347:1:347:21 | /** @ty ... ber} */ |
306-
| tst.js:347:33:347:40 | identity | tst.js:347:1:347:21 | /** @ty ... ber} */ |
307-
| tst.js:347:33:347:43 | identity(2) | tst.js:347:1:347:21 | /** @ty ... ber} */ |
308289
| tst.js:347:33:347:59 | identit ... ty("2") | tst.js:347:1:347:21 | /** @ty ... ber} */ |
309-
| tst.js:347:42:347:42 | 2 | tst.js:347:1:347:21 | /** @ty ... ber} */ |
310-
| tst.js:347:47:347:54 | identity | tst.js:347:1:347:21 | /** @ty ... ber} */ |
311-
| tst.js:347:47:347:59 | identity("2") | tst.js:347:1:347:21 | /** @ty ... ber} */ |
312-
| tst.js:347:56:347:58 | "2" | tst.js:347:1:347:21 | /** @ty ... ber} */ |
313290
| tst.js:349:37:349:51 | string_or_undef | tst.js:349:1:349:31 | /** @ty ... ned} */ |
314291
| tst.js:349:37:349:51 | string_or_undef | tst.js:349:1:349:31 | /** @ty ... ned} */ |
315292
| tst.js:366:3:366:15 | classicMethod | tst.js:363:3:365:5 | /**\\n ... p\\n */ |

0 commit comments

Comments
 (0)