mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
JS: Handle name resolution through dynamic imports
This commit is contained in:
@@ -46,6 +46,9 @@ module NameResolution {
|
||||
this instanceof Module
|
||||
or
|
||||
this instanceof NamespaceDefinition // `module {}` or `enum {}` statement
|
||||
or
|
||||
// A module wrapped in a promise. We model this as a module exporting the actual module in a property called `$$promise-content`.
|
||||
this instanceof DynamicImportExpr
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,6 +235,19 @@ module NameResolution {
|
||||
name = expr.getName() and
|
||||
node2 = expr
|
||||
)
|
||||
or
|
||||
exists(AwaitExpr await |
|
||||
node1 = await.getOperand() and
|
||||
name = "$$promise-content" and
|
||||
node2 = await
|
||||
)
|
||||
or
|
||||
exists(MethodCallExpr call |
|
||||
call.getMethodName() = "then" and
|
||||
node1 = call.getReceiver() and
|
||||
name = "$$promise-content" and
|
||||
node2 = call.getArgument(0).(Function).getParameter(0)
|
||||
)
|
||||
}
|
||||
|
||||
private signature module TypeResolutionInputSig {
|
||||
@@ -334,6 +350,12 @@ module NameResolution {
|
||||
)
|
||||
or
|
||||
storeToVariable(result, name, mod.(Closure::ClosureModule).getExportsVariable())
|
||||
or
|
||||
exists(DynamicImportExpr imprt |
|
||||
mod = imprt and
|
||||
name = "$$promise-content" and
|
||||
result = imprt.getImportedPathExpr()
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
async function t1() {
|
||||
const e = await import('./dynamicImportLib');
|
||||
e.getRequest(); // $ MISSING: hasUnderlyingType='express'.Request
|
||||
e.getRequest(); // $ hasUnderlyingType='express'.Request
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
| contextualTypes.ts:27:16:27:18 | req | 'express'.Request |
|
||||
| contextualTypes.ts:34:20:34:22 | req | 'express'.Request |
|
||||
| contextualTypes.ts:41:16:41:18 | req | 'express'.Request |
|
||||
| dynamicImportUse.ts:3:5:3:18 | e.getRequest() | 'express'.Request |
|
||||
| expressBulkExport.use.ts:3:13:3:15 | req | 'express'.Request |
|
||||
| expressBulkExport.use.ts:6:13:6:15 | res | 'express'.Response |
|
||||
| expressExportAssign.use.ts:3:13:3:15 | req | 'express'.Request |
|
||||
|
||||
Reference in New Issue
Block a user