mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
TS: Use contextual typing for literals
This commit is contained in:
@@ -176,7 +176,10 @@ export function augmentAst(ast: AugmentedSourceFile, code: string, project: Proj
|
||||
|
||||
if (typeChecker != null) {
|
||||
if (isTypedNode(node)) {
|
||||
let type = typeChecker.getTypeAtLocation(node);
|
||||
let contextualType = isContextuallyTypedNode(node)
|
||||
? typeChecker.getContextualType(node)
|
||||
: null;
|
||||
let type = contextualType || typeChecker.getTypeAtLocation(node);
|
||||
if (type != null) {
|
||||
let id = typeTable.buildType(type);
|
||||
if (id != null) {
|
||||
@@ -326,3 +329,10 @@ function isTypedNode(node: ts.Node): boolean {
|
||||
return ts.isTypeNode(node);
|
||||
}
|
||||
}
|
||||
|
||||
type ContextuallyTypedNode = (ts.ArrayLiteralExpression | ts.ObjectLiteralExpression) & AugmentedNode;
|
||||
|
||||
function isContextuallyTypedNode(node: ts.Node): node is ContextuallyTypedNode {
|
||||
let kind = node.kind;
|
||||
return kind === ts.SyntaxKind.ArrayLiteralExpression || kind === ts.SyntaxKind.ObjectLiteralExpression;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user