Skip to content

Commit 8f6165c

Browse files
committed
print synthetic constructors in PrintAst.ql
1 parent 5b1ed97 commit 8f6165c

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

javascript/ql/src/semmle/javascript/PrintAst.qll

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,12 @@ private predicate shouldPrint(Locatable e, Location l) {
3030
exists(PrintAstConfiguration config | config.shouldPrint(e, l))
3131
}
3232

33-
/** Holds if the given element does not need to be rendered in the AST, due to being compiler-generated or being a `TopLevel`. */
33+
/** Holds if the given element does not need to be rendered in the AST, due to being the `TopLevel` for a file. */
3434
private predicate isNotNeeded(Locatable el) {
35-
exists(ClassDefinition c, ConstructorDeclaration constructor |
36-
constructor = c.getConstructor() and
37-
constructor.isSynthetic() and
38-
el = constructor
39-
)
40-
or
4135
el instanceof TopLevel and
4236
el.getLocation().getStartLine() = 0 and
4337
el.getLocation().getStartColumn() = 0
4438
or
45-
exists(ASTNode parent | isNotNeeded(parent) and not parent instanceof TopLevel |
46-
el = parent.getAChild()
47-
)
48-
or
4939
// relaxing aggresive type inference.
5040
none()
5141
}

javascript/ql/test/library-tests/TypeScript/TypeAnnotations/printAst.expected

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,18 +589,30 @@ nodes
589589
| tst.ts:98:1:98:14 | [ClassDefinition,TypeDefinition] class C1<S> {} | semmle.label | [ClassDefinition,TypeDefinition] class C1<S> {} |
590590
| tst.ts:98:1:98:14 | [ClassDefinition,TypeDefinition] class C1<S> {} | semmle.order | 62 |
591591
| tst.ts:98:7:98:8 | [VarDecl] C1 | semmle.label | [VarDecl] C1 |
592+
| tst.ts:98:9:98:8 | [BlockStmt] {} | semmle.label | [BlockStmt] {} |
593+
| tst.ts:98:9:98:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | [ClassInitializedMember,ConstructorDefinition] constructor() {} |
594+
| tst.ts:98:9:98:8 | [FunctionExpr] () {} | semmle.label | [FunctionExpr] () {} |
595+
| tst.ts:98:9:98:8 | [Label] constructor | semmle.label | [Label] constructor |
592596
| tst.ts:98:10:98:10 | [Identifier] S | semmle.label | [Identifier] S |
593597
| tst.ts:98:10:98:10 | [TypeParameter] S | semmle.label | [TypeParameter] S |
594598
| tst.ts:99:1:99:16 | [ClassDefinition,TypeDefinition] class C2<S,T> {} | semmle.label | [ClassDefinition,TypeDefinition] class C2<S,T> {} |
595599
| tst.ts:99:1:99:16 | [ClassDefinition,TypeDefinition] class C2<S,T> {} | semmle.order | 63 |
596600
| tst.ts:99:7:99:8 | [VarDecl] C2 | semmle.label | [VarDecl] C2 |
601+
| tst.ts:99:9:99:8 | [BlockStmt] {} | semmle.label | [BlockStmt] {} |
602+
| tst.ts:99:9:99:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | [ClassInitializedMember,ConstructorDefinition] constructor() {} |
603+
| tst.ts:99:9:99:8 | [FunctionExpr] () {} | semmle.label | [FunctionExpr] () {} |
604+
| tst.ts:99:9:99:8 | [Label] constructor | semmle.label | [Label] constructor |
597605
| tst.ts:99:10:99:10 | [Identifier] S | semmle.label | [Identifier] S |
598606
| tst.ts:99:10:99:10 | [TypeParameter] S | semmle.label | [TypeParameter] S |
599607
| tst.ts:99:12:99:12 | [Identifier] T | semmle.label | [Identifier] T |
600608
| tst.ts:99:12:99:12 | [TypeParameter] T | semmle.label | [TypeParameter] T |
601609
| tst.ts:100:1:100:29 | [ClassDefinition,TypeDefinition] class C ... ber> {} | semmle.label | [ClassDefinition,TypeDefinition] class C ... ber> {} |
602610
| tst.ts:100:1:100:29 | [ClassDefinition,TypeDefinition] class C ... ber> {} | semmle.order | 64 |
603611
| tst.ts:100:7:100:8 | [VarDecl] C3 | semmle.label | [VarDecl] C3 |
612+
| tst.ts:100:9:100:8 | [BlockStmt] {} | semmle.label | [BlockStmt] {} |
613+
| tst.ts:100:9:100:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | [ClassInitializedMember,ConstructorDefinition] constructor() {} |
614+
| tst.ts:100:9:100:8 | [FunctionExpr] () {} | semmle.label | [FunctionExpr] () {} |
615+
| tst.ts:100:9:100:8 | [Label] constructor | semmle.label | [Label] constructor |
604616
| tst.ts:100:10:100:10 | [Identifier] S | semmle.label | [Identifier] S |
605617
| tst.ts:100:10:100:25 | [TypeParameter] S extends number | semmle.label | [TypeParameter] S extends number |
606618
| tst.ts:100:20:100:25 | [KeywordTypeExpr] number | semmle.label | [KeywordTypeExpr] number |
@@ -1954,12 +1966,28 @@ edges
19541966
| tst.ts:98:1:98:14 | [ClassDefinition,TypeDefinition] class C1<S> {} | file://:0:0:0:0 | (TypeParameters) | semmle.order | -100 |
19551967
| tst.ts:98:1:98:14 | [ClassDefinition,TypeDefinition] class C1<S> {} | tst.ts:98:7:98:8 | [VarDecl] C1 | semmle.label | 1 |
19561968
| tst.ts:98:1:98:14 | [ClassDefinition,TypeDefinition] class C1<S> {} | tst.ts:98:7:98:8 | [VarDecl] C1 | semmle.order | 1 |
1969+
| tst.ts:98:1:98:14 | [ClassDefinition,TypeDefinition] class C1<S> {} | tst.ts:98:9:98:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | 2 |
1970+
| tst.ts:98:1:98:14 | [ClassDefinition,TypeDefinition] class C1<S> {} | tst.ts:98:9:98:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.order | 2 |
1971+
| tst.ts:98:9:98:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:98:9:98:8 | [FunctionExpr] () {} | semmle.label | 2 |
1972+
| tst.ts:98:9:98:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:98:9:98:8 | [FunctionExpr] () {} | semmle.order | 2 |
1973+
| tst.ts:98:9:98:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:98:9:98:8 | [Label] constructor | semmle.label | 1 |
1974+
| tst.ts:98:9:98:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:98:9:98:8 | [Label] constructor | semmle.order | 1 |
1975+
| tst.ts:98:9:98:8 | [FunctionExpr] () {} | tst.ts:98:9:98:8 | [BlockStmt] {} | semmle.label | 5 |
1976+
| tst.ts:98:9:98:8 | [FunctionExpr] () {} | tst.ts:98:9:98:8 | [BlockStmt] {} | semmle.order | 5 |
19571977
| tst.ts:98:10:98:10 | [TypeParameter] S | tst.ts:98:10:98:10 | [Identifier] S | semmle.label | 1 |
19581978
| tst.ts:98:10:98:10 | [TypeParameter] S | tst.ts:98:10:98:10 | [Identifier] S | semmle.order | 1 |
19591979
| tst.ts:99:1:99:16 | [ClassDefinition,TypeDefinition] class C2<S,T> {} | file://:0:0:0:0 | (TypeParameters) | semmle.label | -100 |
19601980
| tst.ts:99:1:99:16 | [ClassDefinition,TypeDefinition] class C2<S,T> {} | file://:0:0:0:0 | (TypeParameters) | semmle.order | -100 |
19611981
| tst.ts:99:1:99:16 | [ClassDefinition,TypeDefinition] class C2<S,T> {} | tst.ts:99:7:99:8 | [VarDecl] C2 | semmle.label | 1 |
19621982
| tst.ts:99:1:99:16 | [ClassDefinition,TypeDefinition] class C2<S,T> {} | tst.ts:99:7:99:8 | [VarDecl] C2 | semmle.order | 1 |
1983+
| tst.ts:99:1:99:16 | [ClassDefinition,TypeDefinition] class C2<S,T> {} | tst.ts:99:9:99:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | 2 |
1984+
| tst.ts:99:1:99:16 | [ClassDefinition,TypeDefinition] class C2<S,T> {} | tst.ts:99:9:99:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.order | 2 |
1985+
| tst.ts:99:9:99:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:99:9:99:8 | [FunctionExpr] () {} | semmle.label | 2 |
1986+
| tst.ts:99:9:99:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:99:9:99:8 | [FunctionExpr] () {} | semmle.order | 2 |
1987+
| tst.ts:99:9:99:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:99:9:99:8 | [Label] constructor | semmle.label | 1 |
1988+
| tst.ts:99:9:99:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:99:9:99:8 | [Label] constructor | semmle.order | 1 |
1989+
| tst.ts:99:9:99:8 | [FunctionExpr] () {} | tst.ts:99:9:99:8 | [BlockStmt] {} | semmle.label | 5 |
1990+
| tst.ts:99:9:99:8 | [FunctionExpr] () {} | tst.ts:99:9:99:8 | [BlockStmt] {} | semmle.order | 5 |
19631991
| tst.ts:99:10:99:10 | [TypeParameter] S | tst.ts:99:10:99:10 | [Identifier] S | semmle.label | 1 |
19641992
| tst.ts:99:10:99:10 | [TypeParameter] S | tst.ts:99:10:99:10 | [Identifier] S | semmle.order | 1 |
19651993
| tst.ts:99:12:99:12 | [TypeParameter] T | tst.ts:99:12:99:12 | [Identifier] T | semmle.label | 1 |
@@ -1968,6 +1996,14 @@ edges
19681996
| tst.ts:100:1:100:29 | [ClassDefinition,TypeDefinition] class C ... ber> {} | file://:0:0:0:0 | (TypeParameters) | semmle.order | -100 |
19691997
| tst.ts:100:1:100:29 | [ClassDefinition,TypeDefinition] class C ... ber> {} | tst.ts:100:7:100:8 | [VarDecl] C3 | semmle.label | 1 |
19701998
| tst.ts:100:1:100:29 | [ClassDefinition,TypeDefinition] class C ... ber> {} | tst.ts:100:7:100:8 | [VarDecl] C3 | semmle.order | 1 |
1999+
| tst.ts:100:1:100:29 | [ClassDefinition,TypeDefinition] class C ... ber> {} | tst.ts:100:9:100:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | 2 |
2000+
| tst.ts:100:1:100:29 | [ClassDefinition,TypeDefinition] class C ... ber> {} | tst.ts:100:9:100:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.order | 2 |
2001+
| tst.ts:100:9:100:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:100:9:100:8 | [FunctionExpr] () {} | semmle.label | 2 |
2002+
| tst.ts:100:9:100:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:100:9:100:8 | [FunctionExpr] () {} | semmle.order | 2 |
2003+
| tst.ts:100:9:100:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:100:9:100:8 | [Label] constructor | semmle.label | 1 |
2004+
| tst.ts:100:9:100:8 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:100:9:100:8 | [Label] constructor | semmle.order | 1 |
2005+
| tst.ts:100:9:100:8 | [FunctionExpr] () {} | tst.ts:100:9:100:8 | [BlockStmt] {} | semmle.label | 5 |
2006+
| tst.ts:100:9:100:8 | [FunctionExpr] () {} | tst.ts:100:9:100:8 | [BlockStmt] {} | semmle.order | 5 |
19712007
| tst.ts:100:10:100:25 | [TypeParameter] S extends number | tst.ts:100:10:100:10 | [Identifier] S | semmle.label | 1 |
19722008
| tst.ts:100:10:100:25 | [TypeParameter] S extends number | tst.ts:100:10:100:10 | [Identifier] S | semmle.order | 1 |
19732009
| tst.ts:100:10:100:25 | [TypeParameter] S extends number | tst.ts:100:20:100:25 | [KeywordTypeExpr] number | semmle.label | 2 |

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,10 @@ nodes
429429
| type_definition_objects.ts:3:1:3:17 | [ExportDeclaration] export class C {} | semmle.order | 54 |
430430
| type_definition_objects.ts:3:8:3:17 | [ClassDefinition,TypeDefinition] class C {} | semmle.label | [ClassDefinition,TypeDefinition] class C {} |
431431
| type_definition_objects.ts:3:14:3:14 | [VarDecl] C | semmle.label | [VarDecl] C |
432+
| type_definition_objects.ts:3:16:3:15 | [BlockStmt] {} | semmle.label | [BlockStmt] {} |
433+
| type_definition_objects.ts:3:16:3:15 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | [ClassInitializedMember,ConstructorDefinition] constructor() {} |
434+
| type_definition_objects.ts:3:16:3:15 | [FunctionExpr] () {} | semmle.label | [FunctionExpr] () {} |
435+
| type_definition_objects.ts:3:16:3:15 | [Label] constructor | semmle.label | [Label] constructor |
432436
| type_definition_objects.ts:4:1:4:17 | [DeclStmt] let classObj = ... | semmle.label | [DeclStmt] let classObj = ... |
433437
| type_definition_objects.ts:4:1:4:17 | [DeclStmt] let classObj = ... | semmle.order | 55 |
434438
| type_definition_objects.ts:4:5:4:12 | [VarDecl] classObj | semmle.label | [VarDecl] classObj |
@@ -476,6 +480,10 @@ nodes
476480
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | semmle.label | [ClassDefinition,TypeDefinition] class C ... x: T } |
477481
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | semmle.order | 63 |
478482
| type_definitions.ts:8:7:8:7 | [VarDecl] C | semmle.label | [VarDecl] C |
483+
| type_definitions.ts:8:8:8:7 | [BlockStmt] {} | semmle.label | [BlockStmt] {} |
484+
| type_definitions.ts:8:8:8:7 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | [ClassInitializedMember,ConstructorDefinition] constructor() {} |
485+
| type_definitions.ts:8:8:8:7 | [FunctionExpr] () {} | semmle.label | [FunctionExpr] () {} |
486+
| type_definitions.ts:8:8:8:7 | [Label] constructor | semmle.label | [Label] constructor |
479487
| type_definitions.ts:8:9:8:9 | [Identifier] T | semmle.label | [Identifier] T |
480488
| type_definitions.ts:8:9:8:9 | [TypeParameter] T | semmle.label | [TypeParameter] T |
481489
| type_definitions.ts:9:3:9:3 | [Label] x | semmle.label | [Label] x |
@@ -1171,6 +1179,14 @@ edges
11711179
| type_definition_objects.ts:3:1:3:17 | [ExportDeclaration] export class C {} | type_definition_objects.ts:3:8:3:17 | [ClassDefinition,TypeDefinition] class C {} | semmle.order | 1 |
11721180
| type_definition_objects.ts:3:8:3:17 | [ClassDefinition,TypeDefinition] class C {} | type_definition_objects.ts:3:14:3:14 | [VarDecl] C | semmle.label | 1 |
11731181
| type_definition_objects.ts:3:8:3:17 | [ClassDefinition,TypeDefinition] class C {} | type_definition_objects.ts:3:14:3:14 | [VarDecl] C | semmle.order | 1 |
1182+
| type_definition_objects.ts:3:8:3:17 | [ClassDefinition,TypeDefinition] class C {} | type_definition_objects.ts:3:16:3:15 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | 2 |
1183+
| type_definition_objects.ts:3:8:3:17 | [ClassDefinition,TypeDefinition] class C {} | type_definition_objects.ts:3:16:3:15 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.order | 2 |
1184+
| type_definition_objects.ts:3:16:3:15 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | type_definition_objects.ts:3:16:3:15 | [FunctionExpr] () {} | semmle.label | 2 |
1185+
| type_definition_objects.ts:3:16:3:15 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | type_definition_objects.ts:3:16:3:15 | [FunctionExpr] () {} | semmle.order | 2 |
1186+
| type_definition_objects.ts:3:16:3:15 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | type_definition_objects.ts:3:16:3:15 | [Label] constructor | semmle.label | 1 |
1187+
| type_definition_objects.ts:3:16:3:15 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | type_definition_objects.ts:3:16:3:15 | [Label] constructor | semmle.order | 1 |
1188+
| type_definition_objects.ts:3:16:3:15 | [FunctionExpr] () {} | type_definition_objects.ts:3:16:3:15 | [BlockStmt] {} | semmle.label | 5 |
1189+
| type_definition_objects.ts:3:16:3:15 | [FunctionExpr] () {} | type_definition_objects.ts:3:16:3:15 | [BlockStmt] {} | semmle.order | 5 |
11741190
| type_definition_objects.ts:4:1:4:17 | [DeclStmt] let classObj = ... | type_definition_objects.ts:4:5:4:16 | [VariableDeclarator] classObj = C | semmle.label | 1 |
11751191
| type_definition_objects.ts:4:1:4:17 | [DeclStmt] let classObj = ... | type_definition_objects.ts:4:5:4:16 | [VariableDeclarator] classObj = C | semmle.order | 1 |
11761192
| type_definition_objects.ts:4:5:4:16 | [VariableDeclarator] classObj = C | type_definition_objects.ts:4:5:4:12 | [VarDecl] classObj | semmle.label | 1 |
@@ -1231,8 +1247,16 @@ edges
12311247
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | file://:0:0:0:0 | (TypeParameters) | semmle.order | -100 |
12321248
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | type_definitions.ts:8:7:8:7 | [VarDecl] C | semmle.label | 1 |
12331249
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | type_definitions.ts:8:7:8:7 | [VarDecl] C | semmle.order | 1 |
1250+
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | type_definitions.ts:8:8:8:7 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | 2 |
1251+
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | type_definitions.ts:8:8:8:7 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.order | 2 |
12341252
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | type_definitions.ts:9:3:9:6 | [FieldDeclaration] x: T | semmle.label | 4 |
12351253
| type_definitions.ts:8:1:10:1 | [ClassDefinition,TypeDefinition] class C ... x: T } | type_definitions.ts:9:3:9:6 | [FieldDeclaration] x: T | semmle.order | 4 |
1254+
| type_definitions.ts:8:8:8:7 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | type_definitions.ts:8:8:8:7 | [FunctionExpr] () {} | semmle.label | 2 |
1255+
| type_definitions.ts:8:8:8:7 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | type_definitions.ts:8:8:8:7 | [FunctionExpr] () {} | semmle.order | 2 |
1256+
| type_definitions.ts:8:8:8:7 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | type_definitions.ts:8:8:8:7 | [Label] constructor | semmle.label | 1 |
1257+
| type_definitions.ts:8:8:8:7 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | type_definitions.ts:8:8:8:7 | [Label] constructor | semmle.order | 1 |
1258+
| type_definitions.ts:8:8:8:7 | [FunctionExpr] () {} | type_definitions.ts:8:8:8:7 | [BlockStmt] {} | semmle.label | 5 |
1259+
| type_definitions.ts:8:8:8:7 | [FunctionExpr] () {} | type_definitions.ts:8:8:8:7 | [BlockStmt] {} | semmle.order | 5 |
12361260
| type_definitions.ts:8:9:8:9 | [TypeParameter] T | type_definitions.ts:8:9:8:9 | [Identifier] T | semmle.label | 1 |
12371261
| type_definitions.ts:8:9:8:9 | [TypeParameter] T | type_definitions.ts:8:9:8:9 | [Identifier] T | semmle.order | 1 |
12381262
| type_definitions.ts:9:3:9:6 | [FieldDeclaration] x: T | type_definitions.ts:9:3:9:3 | [Label] x | semmle.label | 1 |

0 commit comments

Comments
 (0)