JS: Handle name resolution through dynamic imports

This commit is contained in:
Asger F
2025-06-10 11:25:32 +02:00
parent 7cc248703a
commit b1d4776b17
3 changed files with 24 additions and 1 deletions

View File

@@ -46,6 +46,9 @@ module NameResolution {
this instanceof Module this instanceof Module
or or
this instanceof NamespaceDefinition // `module {}` or `enum {}` statement 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 name = expr.getName() and
node2 = expr 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 { private signature module TypeResolutionInputSig {
@@ -334,6 +350,12 @@ module NameResolution {
) )
or or
storeToVariable(result, name, mod.(Closure::ClosureModule).getExportsVariable()) storeToVariable(result, name, mod.(Closure::ClosureModule).getExportsVariable())
or
exists(DynamicImportExpr imprt |
mod = imprt and
name = "$$promise-content" and
result = imprt.getImportedPathExpr()
)
} }
/** /**

View File

@@ -1,4 +1,4 @@
async function t1() { async function t1() {
const e = await import('./dynamicImportLib'); const e = await import('./dynamicImportLib');
e.getRequest(); // $ MISSING: hasUnderlyingType='express'.Request e.getRequest(); // $ hasUnderlyingType='express'.Request
} }

View File

@@ -15,6 +15,7 @@
| contextualTypes.ts:27:16:27:18 | req | 'express'.Request | | contextualTypes.ts:27:16:27:18 | req | 'express'.Request |
| contextualTypes.ts:34:20:34:22 | req | 'express'.Request | | contextualTypes.ts:34:20:34:22 | req | 'express'.Request |
| contextualTypes.ts:41:16:41:18 | 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:3:13:3:15 | req | 'express'.Request |
| expressBulkExport.use.ts:6:13:6:15 | res | 'express'.Response | | expressBulkExport.use.ts:6:13:6:15 | res | 'express'.Response |
| expressExportAssign.use.ts:3:13:3:15 | req | 'express'.Request | | expressExportAssign.use.ts:3:13:3:15 | req | 'express'.Request |