JS: Add support for index expressions

This commit is contained in:
Asger F
2025-06-12 13:32:51 +02:00
parent b1d4776b17
commit c8b2674206
3 changed files with 16 additions and 0 deletions

View File

@@ -130,6 +130,13 @@ module TypeResolution {
or
SummaryTypeTracker::basicLoadStep(object.(AST::ValueNode).flow(),
member.(AST::ValueNode).flow(), contents)
or
exists(IndexExpr index |
not exists(index.getPropertyName()) and
object = index.getBase() and
member = index and
contents = DataFlow::ContentSet::arrayElement()
)
}
predicate callTarget(InvokeExpr call, Function target) {

View File

@@ -0,0 +1,8 @@
import * as express from 'express';
interface I {
[s: string]: express.Request;
}
function t1(obj: I, x: string) {
obj[x]; // $ hasUnderlyingType='express'.Request
}

View File

@@ -30,6 +30,7 @@
| globals.ts:1:13:1:14 | el | HTMLElement |
| globals.ts:6:13:6:14 | el | HTMLInputElement |
| globals.ts:9:13:9:15 | req | Express.Request |
| indexExpr.ts:7:5:7:10 | obj[x] | 'express'.Request |
| jsdoc.js:7:13:7:15 | req | 'express'.Request |
| jsdoc.js:13:13:13:15 | res | 'express'.Response |
| namedImport.ts:3:13:3:15 | req | 'express'.Request |