Skip to content

Commit 500291d

Browse files
committed
JS: Hide shadowed inherited members
1 parent f06b9a9 commit 500291d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

javascript/ql/lib/semmle/javascript/internal/TypeResolution.qll

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ module TypeResolution {
3434
}
3535

3636
/**
37-
* Holds if `host` is a type with a `content` of type `memberType`.
37+
* Holds if `host` is a type with a `content` of type `memberType`, not counting inherited members.
3838
*/
39-
private predicate typeMember(Node host, DataFlow::Content content, Node memberType) {
39+
private predicate typeOwnMember(Node host, DataFlow::Content content, Node memberType) {
4040
exists(MemberDeclaration decl | host = getMemberBase(decl) |
4141
exists(FieldDeclaration field |
4242
decl = field and
@@ -46,8 +46,13 @@ module TypeResolution {
4646
or
4747
exists(MethodDeclaration method |
4848
decl = method and
49-
content.asPropertyName() = method.getName() and
49+
content.asPropertyName() = method.getName()
50+
|
51+
not method instanceof AccessorMethodDeclaration and
5052
memberType = method.getBody() // use the Function as representative for the function type
53+
or
54+
method instanceof GetterMethodDeclaration and
55+
memberType = method.getBody().getReturnTypeAnnotation()
5156
)
5257
or
5358
decl instanceof IndexSignature and
@@ -72,8 +77,16 @@ module TypeResolution {
7277
memberType = type.getArgument(0)
7378
)
7479
)
80+
}
81+
82+
/**
83+
* Holds if `host` is a type with a `content` of type `memberType`, possible due to inheritance.
84+
*/
85+
private predicate typeMember(Node host, DataFlow::Content content, Node memberType) {
86+
typeOwnMember(host, content, memberType)
7587
or
7688
// Inherit members from base types
89+
not typeOwnMember(host, content, _) and
7790
exists(ClassOrInterface baseType | typeMember(baseType, content, memberType) |
7891
host.(ClassDefinition).getSuperClass() = trackClassValue(baseType)
7992
or

0 commit comments

Comments
 (0)