JS: Mark type-annotated nodes as SourceNode

This commit is contained in:
Asger F
2025-04-14 13:47:26 +02:00
parent 6e82b6eb1f
commit e07a03619d
4 changed files with 17 additions and 3 deletions

View File

@@ -333,7 +333,13 @@ module SourceNode {
astNode instanceof TaggedTemplateExpr or
astNode instanceof Templating::PipeRefExpr or
astNode instanceof Templating::TemplateVarRefExpr or
astNode instanceof StringLiteral
astNode instanceof StringLiteral or
astNode instanceof TypeAssertion
)
or
exists(VariableDeclarator decl |
exists(decl.getTypeAnnotation()) and
this = DataFlow::valueNode(decl.getBindingPattern())
)
or
DataFlow::parameterNode(this, _)

View File

@@ -189,7 +189,12 @@ module TypeResolution {
)
}
private predicate contextualType(Node value, Node type) {
predicate contextualType(Node value, Node type) {
exists(LocalVariable v |
type = v.getADeclaration().getTypeAnnotation() and
value = v.getAnAssignedExpr()
)
or
exists(InvokeExpr call, Function target, int i |
callTarget(call, target) and
value = call.getArgument(i) and
@@ -228,6 +233,8 @@ module TypeResolution {
predicate valueHasType(Node value, Node type) {
value.(BindingPattern).getTypeAnnotation() = type
or
value.(TypeAssertion).getTypeAnnotation() = type
or
exists(VarDecl decl |
// ValueFlow::step is restricted to variables with at most one assignment. Allow the type annotation
// of a variable to propagate to its uses, even if the variable has multiple assignments.