Skip to content

Commit ffd51e7

Browse files
committed
add getter for static initializer blocks
1 parent 9585481 commit ffd51e7

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ class ClassDefinition extends @class_definition, ClassOrInterface, AST::ValueNod
258258
}
259259

260260
override string getAPrimaryQlClass() { result = "ClassDefinition" }
261+
262+
/**
263+
* Gets a static initializer of this class, if any.
264+
*/
265+
BlockStmt getAStaticInitializerBlock() { result.getParent() = this }
261266
}
262267

263268
/**

javascript/ql/test/library-tests/TypeScript/Types/tests.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -670,3 +670,6 @@ unionIndex
670670
| { stillMyUnion: true; } | 1 | MyUnion \| { yetAnotherType: true; } |
671671
| { stillMyUnion: true; } | 1 | { myUnion: true; } \| { stillMyUnion: true; } |
672672
| { yetAnotherType: true; } | 2 | MyUnion \| { yetAnotherType: true; } |
673+
getAStaticInitializerBlock
674+
| tst.ts:179:3:192:3 | class F ... \\n } | tst.ts:185:5:187:5 | static ... ;\\n } |
675+
| tst.ts:179:3:192:3 | class F ... \\n } | tst.ts:188:5:190:5 | static ... ;\\n } |

javascript/ql/test/library-tests/TypeScript/Types/tests.ql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ query predicate unknownType(Expr e, Type type) {
3939
query CallSignatureType abstractSignature() { result.isAbstract() }
4040

4141
query UnionType unionIndex(Type element, int i) { result.getElementType(i) = element }
42+
43+
query BlockStmt getAStaticInitializerBlock(ClassDefinition cls) {
44+
result = cls.getAStaticInitializerBlock()
45+
}

0 commit comments

Comments
 (0)