Skip to content

Commit 96f8a02

Browse files
committed
JS: Treat private-field methods as private
1 parent 057ee85 commit 96f8a02

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

javascript/ql/lib/semmle/javascript/Classes.qll

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,16 +516,37 @@ class MemberDeclaration extends @property, Documentable {
516516
*/
517517
predicate hasPublicKeyword() { has_public_keyword(this) }
518518

519+
/**
520+
* Holds if this member is considered private.
521+
*
522+
* This may occur in two cases:
523+
* - it is a TypeScript member annotated with the `private` keyword, or
524+
* - the member has a private name, such as `#foo`, referring to a private field in the class
525+
*/
526+
predicate isPrivate() { this.hasPrivateKeyword() or this.hasPrivateFieldName() }
527+
519528
/**
520529
* Holds if this is a TypeScript member annotated with the `private` keyword.
521530
*/
522-
predicate isPrivate() { has_private_keyword(this) }
531+
predicate hasPrivateKeyword() { has_private_keyword(this) }
523532

524533
/**
525534
* Holds if this is a TypeScript member annotated with the `protected` keyword.
526535
*/
527536
predicate isProtected() { has_protected_keyword(this) }
528537

538+
/**
539+
* Holds if the member has a private name, such as `#foo`, referring to a private field in the class.
540+
*
541+
* For example:
542+
* ```js
543+
* class Foo {
544+
* #method() {}
545+
* }
546+
* ```
547+
*/
548+
predicate hasPrivateFieldName() { this.getNameExpr().(Label).getName().charAt(0) = "#" }
549+
529550
/**
530551
* Gets the expression specifying the name of this member,
531552
* or nothing if this is a call signature.

0 commit comments

Comments
 (0)