Skip to content

Commit c8b2674

Browse files
committed
JS: Add support for index expressions
1 parent b1d4776 commit c8b2674

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

javascript/ql/lib/semmle/javascript/internal/TypeResolution.qll

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ module TypeResolution {
130130
or
131131
SummaryTypeTracker::basicLoadStep(object.(AST::ValueNode).flow(),
132132
member.(AST::ValueNode).flow(), contents)
133+
or
134+
exists(IndexExpr index |
135+
not exists(index.getPropertyName()) and
136+
object = index.getBase() and
137+
member = index and
138+
contents = DataFlow::ContentSet::arrayElement()
139+
)
133140
}
134141

135142
predicate callTarget(InvokeExpr call, Function target) {
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import * as express from 'express';
2+
3+
interface I {
4+
[s: string]: express.Request;
5+
}
6+
function t1(obj: I, x: string) {
7+
obj[x]; // $ hasUnderlyingType='express'.Request
8+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
| globals.ts:1:13:1:14 | el | HTMLElement |
3131
| globals.ts:6:13:6:14 | el | HTMLInputElement |
3232
| globals.ts:9:13:9:15 | req | Express.Request |
33+
| indexExpr.ts:7:5:7:10 | obj[x] | 'express'.Request |
3334
| jsdoc.js:7:13:7:15 | req | 'express'.Request |
3435
| jsdoc.js:13:13:13:15 | res | 'express'.Response |
3536
| namedImport.ts:3:13:3:15 | req | 'express'.Request |

0 commit comments

Comments
 (0)