Skip to content

Commit 04aea33

Browse files
committed
JS: Use type resolution for Typeannotation.getClass
1 parent 879fa61 commit 04aea33

3 files changed

Lines changed: 5 additions & 13 deletions

File tree

javascript/ql/lib/semmle/javascript/JSDoc.qll

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,8 @@ class JSDocNamedTypeExpr extends JSDocTypeExpr {
395395
this instanceof JSDocQualifiedTypeAccess
396396
}
397397

398+
private predicate test() { not this.getTopLevel().isExterns() }
399+
398400
/**
399401
* Gets the name directly as it appears in this type, including any qualifiers.
400402
*
@@ -451,8 +453,6 @@ class JSDocAppliedTypeExpr extends @jsdoc_applied_type_expr, JSDocTypeExpr {
451453
* For example, in `Array<string>`, `string` is the only argument type.
452454
*/
453455
JSDocTypeExpr getAnArgument() { result = this.getArgument(_) }
454-
455-
override DataFlow::ClassNode getClass() { result = this.getHead().getClass() }
456456
}
457457

458458
/**
@@ -472,8 +472,6 @@ class JSDocNullableTypeExpr extends @jsdoc_nullable_type_expr, JSDocTypeExpr {
472472
predicate isPrefix() { jsdoc_prefix_qualifier(this) }
473473

474474
override JSDocTypeExpr getAnUnderlyingType() { result = this.getTypeExpr().getAnUnderlyingType() }
475-
476-
override DataFlow::ClassNode getClass() { result = this.getTypeExpr().getClass() }
477475
}
478476

479477
/**
@@ -493,8 +491,6 @@ class JSDocNonNullableTypeExpr extends @jsdoc_non_nullable_type_expr, JSDocTypeE
493491
predicate isPrefix() { jsdoc_prefix_qualifier(this) }
494492

495493
override JSDocTypeExpr getAnUnderlyingType() { result = this.getTypeExpr().getAnUnderlyingType() }
496-
497-
override DataFlow::ClassNode getClass() { result = this.getTypeExpr().getClass() }
498494
}
499495

500496
/**
@@ -599,8 +595,6 @@ class JSDocOptionalParameterTypeExpr extends @jsdoc_optional_type_expr, JSDocTyp
599595
override JSDocTypeExpr getAnUnderlyingType() {
600596
result = this.getUnderlyingType().getAnUnderlyingType()
601597
}
602-
603-
override DataFlow::ClassNode getClass() { result = this.getUnderlyingType().getClass() }
604598
}
605599

606600
/**

javascript/ql/lib/semmle/javascript/TypeAnnotations.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,7 @@ class TypeAnnotation extends @type_annotation, NodeInStmtContainer {
133133
*
134134
* This unfolds nullability modifiers and generic type applications.
135135
*/
136-
DataFlow::ClassNode getClass() { none() }
136+
final DataFlow::ClassNode getClass() {
137+
UnderlyingTypes::nodeHasUnderlyingClassType(this, result.getAstNode())
138+
}
137139
}

javascript/ql/lib/semmle/javascript/TypeScript.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,6 @@ class TypeExpr extends ExprOrType, @typeexpr, TypeAnnotation {
576576
override Function getEnclosingFunction() { result = ExprOrType.super.getEnclosingFunction() }
577577

578578
override TopLevel getTopLevel() { result = ExprOrType.super.getTopLevel() }
579-
580-
override DataFlow::ClassNode getClass() {
581-
UnderlyingTypes::nodeHasUnderlyingClassType(this, result.getAstNode())
582-
}
583579
}
584580

585581
/**

0 commit comments

Comments
 (0)