Skip to content

Commit 8f9ad1f

Browse files
authored
Merge pull request github#11872 from erik-krogh/jsAst
JS: Fixup some problems in PrintAST
2 parents 15ead6d + 7ae27bc commit 8f9ad1f

File tree

7 files changed

+291
-123
lines changed

7 files changed

+291
-123
lines changed

javascript/ql/lib/semmle/javascript/PrintAst.qll

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,17 @@ 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 the `TopLevel` for a file. */
33+
/**
34+
* Holds if the given element does not need to be rendered in the AST.
35+
* Either due to being the `TopLevel` for a file, or an internal node representing a decorator list.
36+
*/
3437
private predicate isNotNeeded(Locatable el) {
3538
el instanceof TopLevel and
3639
el.getLocation().getStartLine() = 0 and
3740
el.getLocation().getStartColumn() = 0
3841
or
42+
el instanceof @decorator_list // there is no public API for this.
43+
or
3944
// relaxing aggressive type inference.
4045
none()
4146
}
@@ -500,9 +505,11 @@ private module PrintJavaScript {
500505
override Parameter element;
501506

502507
override AstNode getChildNode(int childIndex) {
503-
childIndex = 0 and result = element.getTypeAnnotation()
508+
result = super.getChildNode(childIndex) // in case the parameter is a destructuring pattern
509+
or
510+
childIndex = -2 and result = element.getTypeAnnotation()
504511
or
505-
childIndex = 1 and result = element.getDefault()
512+
childIndex = -1 and result = element.getDefault()
506513
}
507514
}
508515

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
nodes
2+
| file://:0:0:0:0 | (Arguments) | semmle.label | (Arguments) |
3+
| file://:0:0:0:0 | (Parameters) | semmle.label | (Parameters) |
4+
| tst.ts:1:1:1:22 | [DeclStmt] const Dec = ... | semmle.label | [DeclStmt] const Dec = ... |
5+
| tst.ts:1:1:1:22 | [DeclStmt] const Dec = ... | semmle.order | 1 |
6+
| tst.ts:1:7:1:9 | [VarDecl] Dec | semmle.label | [VarDecl] Dec |
7+
| tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | semmle.label | [VariableDeclarator] Dec: any = null |
8+
| tst.ts:1:12:1:14 | [KeywordTypeExpr] any | semmle.label | [KeywordTypeExpr] any |
9+
| tst.ts:1:18:1:21 | [Literal] null | semmle.label | [Literal] null |
10+
| tst.ts:3:1:3:6 | [Decorator] @Dec() | semmle.label | [Decorator] @Dec() |
11+
| tst.ts:3:2:3:4 | [VarRef] Dec | semmle.label | [VarRef] Dec |
12+
| tst.ts:3:2:3:6 | [CallExpr] Dec() | semmle.label | [CallExpr] Dec() |
13+
| tst.ts:4:1:8:1 | [ExportDeclaration] export ... id {} } | semmle.label | [ExportDeclaration] export ... id {} } |
14+
| tst.ts:4:1:8:1 | [ExportDeclaration] export ... id {} } | semmle.order | 2 |
15+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | semmle.label | [ClassDefinition,TypeDefinition] class O ... id {} } |
16+
| tst.ts:4:14:4:30 | [VarDecl] OperatorResolvers | semmle.label | [VarDecl] OperatorResolvers |
17+
| tst.ts:4:32:4:31 | [BlockStmt] {} | semmle.label | [BlockStmt] {} |
18+
| tst.ts:4:32:4:31 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | [ClassInitializedMember,ConstructorDefinition] constructor() {} |
19+
| tst.ts:4:32:4:31 | [FunctionExpr] () {} | semmle.label | [FunctionExpr] () {} |
20+
| tst.ts:4:32:4:31 | [Label] constructor | semmle.label | [Label] constructor |
21+
| tst.ts:5:3:5:8 | [Decorator] @Dec() | semmle.label | [Decorator] @Dec() |
22+
| tst.ts:5:4:5:6 | [VarRef] Dec | semmle.label | [VarRef] Dec |
23+
| tst.ts:5:4:5:8 | [CallExpr] Dec() | semmle.label | [CallExpr] Dec() |
24+
| tst.ts:6:3:6:8 | [Decorator] @Dec() | semmle.label | [Decorator] @Dec() |
25+
| tst.ts:6:4:6:6 | [VarRef] Dec | semmle.label | [VarRef] Dec |
26+
| tst.ts:6:4:6:8 | [CallExpr] Dec() | semmle.label | [CallExpr] Dec() |
27+
| tst.ts:7:3:7:11 | [Label] operators | semmle.label | [Label] operators |
28+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | semmle.label | [ClassInitializedMember,MethodDefinition] operators(): void {} |
29+
| tst.ts:7:3:7:22 | [FunctionExpr] operators(): void {} | semmle.label | [FunctionExpr] operators(): void {} |
30+
| tst.ts:7:16:7:19 | [KeywordTypeExpr] void | semmle.label | [KeywordTypeExpr] void |
31+
| tst.ts:7:21:7:22 | [BlockStmt] {} | semmle.label | [BlockStmt] {} |
32+
| tst.ts:10:1:10:41 | [DeclStmt] const createMethodDecorator = ... | semmle.label | [DeclStmt] const createMethodDecorator = ... |
33+
| tst.ts:10:1:10:41 | [DeclStmt] const createMethodDecorator = ... | semmle.order | 3 |
34+
| tst.ts:10:7:10:27 | [VarDecl] createMethodDecorator | semmle.label | [VarDecl] createMethodDecorator |
35+
| tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | semmle.label | [VariableDeclarator] createM ... = null |
36+
| tst.ts:10:31:10:33 | [KeywordTypeExpr] any | semmle.label | [KeywordTypeExpr] any |
37+
| tst.ts:10:37:10:40 | [Literal] null | semmle.label | [Literal] null |
38+
| tst.ts:12:1:12:21 | [VarRef] createMethodDecorator | semmle.label | [VarRef] createMethodDecorator |
39+
| tst.ts:12:1:14:2 | [CallExpr] createM ... { }) | semmle.label | [CallExpr] createM ... { }) |
40+
| tst.ts:12:1:14:3 | [ExprStmt] createM ... }); | semmle.label | [ExprStmt] createM ... }); |
41+
| tst.ts:12:1:14:3 | [ExprStmt] createM ... }); | semmle.order | 4 |
42+
| tst.ts:12:23:14:1 | [ArrowFunctionExpr] ({ args ... { } | semmle.label | [ArrowFunctionExpr] ({ args ... { } |
43+
| tst.ts:12:24:12:40 | [ObjectPattern,Parameter] { args, context } | semmle.label | [ObjectPattern,Parameter] { args, context } |
44+
| tst.ts:12:26:12:29 | [Label] args | semmle.label | [Label] args |
45+
| tst.ts:12:26:12:29 | [PropertyPattern] args | semmle.label | [PropertyPattern] args |
46+
| tst.ts:12:26:12:29 | [VarDecl] args | semmle.label | [VarDecl] args |
47+
| tst.ts:12:32:12:38 | [Label] context | semmle.label | [Label] context |
48+
| tst.ts:12:32:12:38 | [PropertyPattern] context | semmle.label | [PropertyPattern] context |
49+
| tst.ts:12:32:12:38 | [VarDecl] context | semmle.label | [VarDecl] context |
50+
| tst.ts:12:43:12:46 | [SimpleParameter] next | semmle.label | [SimpleParameter] next |
51+
| tst.ts:12:52:14:1 | [BlockStmt] { } | semmle.label | [BlockStmt] { } |
52+
edges
53+
| file://:0:0:0:0 | (Arguments) | tst.ts:12:23:14:1 | [ArrowFunctionExpr] ({ args ... { } | semmle.label | 0 |
54+
| file://:0:0:0:0 | (Arguments) | tst.ts:12:23:14:1 | [ArrowFunctionExpr] ({ args ... { } | semmle.order | 0 |
55+
| file://:0:0:0:0 | (Parameters) | tst.ts:12:24:12:40 | [ObjectPattern,Parameter] { args, context } | semmle.label | 0 |
56+
| file://:0:0:0:0 | (Parameters) | tst.ts:12:24:12:40 | [ObjectPattern,Parameter] { args, context } | semmle.order | 0 |
57+
| file://:0:0:0:0 | (Parameters) | tst.ts:12:43:12:46 | [SimpleParameter] next | semmle.label | 1 |
58+
| file://:0:0:0:0 | (Parameters) | tst.ts:12:43:12:46 | [SimpleParameter] next | semmle.order | 1 |
59+
| tst.ts:1:1:1:22 | [DeclStmt] const Dec = ... | tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | semmle.label | 1 |
60+
| tst.ts:1:1:1:22 | [DeclStmt] const Dec = ... | tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | semmle.order | 1 |
61+
| tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | tst.ts:1:7:1:9 | [VarDecl] Dec | semmle.label | 1 |
62+
| tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | tst.ts:1:7:1:9 | [VarDecl] Dec | semmle.order | 1 |
63+
| tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | tst.ts:1:12:1:14 | [KeywordTypeExpr] any | semmle.label | 2 |
64+
| tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | tst.ts:1:12:1:14 | [KeywordTypeExpr] any | semmle.order | 2 |
65+
| tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | tst.ts:1:18:1:21 | [Literal] null | semmle.label | 3 |
66+
| tst.ts:1:7:1:21 | [VariableDeclarator] Dec: any = null | tst.ts:1:18:1:21 | [Literal] null | semmle.order | 3 |
67+
| tst.ts:3:1:3:6 | [Decorator] @Dec() | tst.ts:3:2:3:6 | [CallExpr] Dec() | semmle.label | 1 |
68+
| tst.ts:3:1:3:6 | [Decorator] @Dec() | tst.ts:3:2:3:6 | [CallExpr] Dec() | semmle.order | 1 |
69+
| tst.ts:3:2:3:6 | [CallExpr] Dec() | tst.ts:3:2:3:4 | [VarRef] Dec | semmle.label | 0 |
70+
| tst.ts:3:2:3:6 | [CallExpr] Dec() | tst.ts:3:2:3:4 | [VarRef] Dec | semmle.order | 0 |
71+
| tst.ts:4:1:8:1 | [ExportDeclaration] export ... id {} } | tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | semmle.label | 1 |
72+
| tst.ts:4:1:8:1 | [ExportDeclaration] export ... id {} } | tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | semmle.order | 1 |
73+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | tst.ts:3:1:3:6 | [Decorator] @Dec() | semmle.label | 1 |
74+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | tst.ts:3:1:3:6 | [Decorator] @Dec() | semmle.order | 1 |
75+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | tst.ts:4:14:4:30 | [VarDecl] OperatorResolvers | semmle.label | 2 |
76+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | tst.ts:4:14:4:30 | [VarDecl] OperatorResolvers | semmle.order | 2 |
77+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | tst.ts:4:32:4:31 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.label | 3 |
78+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | tst.ts:4:32:4:31 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | semmle.order | 3 |
79+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | semmle.label | 4 |
80+
| tst.ts:4:8:8:1 | [ClassDefinition,TypeDefinition] class O ... id {} } | tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | semmle.order | 4 |
81+
| tst.ts:4:32:4:31 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:4:32:4:31 | [FunctionExpr] () {} | semmle.label | 2 |
82+
| tst.ts:4:32:4:31 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:4:32:4:31 | [FunctionExpr] () {} | semmle.order | 2 |
83+
| tst.ts:4:32:4:31 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:4:32:4:31 | [Label] constructor | semmle.label | 1 |
84+
| tst.ts:4:32:4:31 | [ClassInitializedMember,ConstructorDefinition] constructor() {} | tst.ts:4:32:4:31 | [Label] constructor | semmle.order | 1 |
85+
| tst.ts:4:32:4:31 | [FunctionExpr] () {} | tst.ts:4:32:4:31 | [BlockStmt] {} | semmle.label | 5 |
86+
| tst.ts:4:32:4:31 | [FunctionExpr] () {} | tst.ts:4:32:4:31 | [BlockStmt] {} | semmle.order | 5 |
87+
| tst.ts:5:3:5:8 | [Decorator] @Dec() | tst.ts:5:4:5:8 | [CallExpr] Dec() | semmle.label | 1 |
88+
| tst.ts:5:3:5:8 | [Decorator] @Dec() | tst.ts:5:4:5:8 | [CallExpr] Dec() | semmle.order | 1 |
89+
| tst.ts:5:4:5:8 | [CallExpr] Dec() | tst.ts:5:4:5:6 | [VarRef] Dec | semmle.label | 0 |
90+
| tst.ts:5:4:5:8 | [CallExpr] Dec() | tst.ts:5:4:5:6 | [VarRef] Dec | semmle.order | 0 |
91+
| tst.ts:6:3:6:8 | [Decorator] @Dec() | tst.ts:6:4:6:8 | [CallExpr] Dec() | semmle.label | 1 |
92+
| tst.ts:6:3:6:8 | [Decorator] @Dec() | tst.ts:6:4:6:8 | [CallExpr] Dec() | semmle.order | 1 |
93+
| tst.ts:6:4:6:8 | [CallExpr] Dec() | tst.ts:6:4:6:6 | [VarRef] Dec | semmle.label | 0 |
94+
| tst.ts:6:4:6:8 | [CallExpr] Dec() | tst.ts:6:4:6:6 | [VarRef] Dec | semmle.order | 0 |
95+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | tst.ts:5:3:5:8 | [Decorator] @Dec() | semmle.label | 1 |
96+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | tst.ts:5:3:5:8 | [Decorator] @Dec() | semmle.order | 1 |
97+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | tst.ts:6:3:6:8 | [Decorator] @Dec() | semmle.label | 2 |
98+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | tst.ts:6:3:6:8 | [Decorator] @Dec() | semmle.order | 2 |
99+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | tst.ts:7:3:7:11 | [Label] operators | semmle.label | 3 |
100+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | tst.ts:7:3:7:11 | [Label] operators | semmle.order | 3 |
101+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | tst.ts:7:3:7:22 | [FunctionExpr] operators(): void {} | semmle.label | 4 |
102+
| tst.ts:7:3:7:22 | [ClassInitializedMember,MethodDefinition] operators(): void {} | tst.ts:7:3:7:22 | [FunctionExpr] operators(): void {} | semmle.order | 4 |
103+
| tst.ts:7:3:7:22 | [FunctionExpr] operators(): void {} | tst.ts:7:16:7:19 | [KeywordTypeExpr] void | semmle.label | 4 |
104+
| tst.ts:7:3:7:22 | [FunctionExpr] operators(): void {} | tst.ts:7:16:7:19 | [KeywordTypeExpr] void | semmle.order | 4 |
105+
| tst.ts:7:3:7:22 | [FunctionExpr] operators(): void {} | tst.ts:7:21:7:22 | [BlockStmt] {} | semmle.label | 5 |
106+
| tst.ts:7:3:7:22 | [FunctionExpr] operators(): void {} | tst.ts:7:21:7:22 | [BlockStmt] {} | semmle.order | 5 |
107+
| tst.ts:10:1:10:41 | [DeclStmt] const createMethodDecorator = ... | tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | semmle.label | 1 |
108+
| tst.ts:10:1:10:41 | [DeclStmt] const createMethodDecorator = ... | tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | semmle.order | 1 |
109+
| tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | tst.ts:10:7:10:27 | [VarDecl] createMethodDecorator | semmle.label | 1 |
110+
| tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | tst.ts:10:7:10:27 | [VarDecl] createMethodDecorator | semmle.order | 1 |
111+
| tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | tst.ts:10:31:10:33 | [KeywordTypeExpr] any | semmle.label | 2 |
112+
| tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | tst.ts:10:31:10:33 | [KeywordTypeExpr] any | semmle.order | 2 |
113+
| tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | tst.ts:10:37:10:40 | [Literal] null | semmle.label | 3 |
114+
| tst.ts:10:7:10:40 | [VariableDeclarator] createM ... = null | tst.ts:10:37:10:40 | [Literal] null | semmle.order | 3 |
115+
| tst.ts:12:1:14:2 | [CallExpr] createM ... { }) | file://:0:0:0:0 | (Arguments) | semmle.label | 1 |
116+
| tst.ts:12:1:14:2 | [CallExpr] createM ... { }) | file://:0:0:0:0 | (Arguments) | semmle.order | 1 |
117+
| tst.ts:12:1:14:2 | [CallExpr] createM ... { }) | tst.ts:12:1:12:21 | [VarRef] createMethodDecorator | semmle.label | 0 |
118+
| tst.ts:12:1:14:2 | [CallExpr] createM ... { }) | tst.ts:12:1:12:21 | [VarRef] createMethodDecorator | semmle.order | 0 |
119+
| tst.ts:12:1:14:3 | [ExprStmt] createM ... }); | tst.ts:12:1:14:2 | [CallExpr] createM ... { }) | semmle.label | 1 |
120+
| tst.ts:12:1:14:3 | [ExprStmt] createM ... }); | tst.ts:12:1:14:2 | [CallExpr] createM ... { }) | semmle.order | 1 |
121+
| tst.ts:12:23:14:1 | [ArrowFunctionExpr] ({ args ... { } | file://:0:0:0:0 | (Parameters) | semmle.label | 1 |
122+
| tst.ts:12:23:14:1 | [ArrowFunctionExpr] ({ args ... { } | file://:0:0:0:0 | (Parameters) | semmle.order | 1 |
123+
| tst.ts:12:23:14:1 | [ArrowFunctionExpr] ({ args ... { } | tst.ts:12:52:14:1 | [BlockStmt] { } | semmle.label | 5 |
124+
| tst.ts:12:23:14:1 | [ArrowFunctionExpr] ({ args ... { } | tst.ts:12:52:14:1 | [BlockStmt] { } | semmle.order | 5 |
125+
| tst.ts:12:24:12:40 | [ObjectPattern,Parameter] { args, context } | tst.ts:12:26:12:29 | [PropertyPattern] args | semmle.label | 1 |
126+
| tst.ts:12:24:12:40 | [ObjectPattern,Parameter] { args, context } | tst.ts:12:26:12:29 | [PropertyPattern] args | semmle.order | 1 |
127+
| tst.ts:12:24:12:40 | [ObjectPattern,Parameter] { args, context } | tst.ts:12:32:12:38 | [PropertyPattern] context | semmle.label | 2 |
128+
| tst.ts:12:24:12:40 | [ObjectPattern,Parameter] { args, context } | tst.ts:12:32:12:38 | [PropertyPattern] context | semmle.order | 2 |
129+
| tst.ts:12:26:12:29 | [PropertyPattern] args | tst.ts:12:26:12:29 | [Label] args | semmle.label | 1 |
130+
| tst.ts:12:26:12:29 | [PropertyPattern] args | tst.ts:12:26:12:29 | [Label] args | semmle.order | 1 |
131+
| tst.ts:12:26:12:29 | [PropertyPattern] args | tst.ts:12:26:12:29 | [VarDecl] args | semmle.label | 2 |
132+
| tst.ts:12:26:12:29 | [PropertyPattern] args | tst.ts:12:26:12:29 | [VarDecl] args | semmle.order | 2 |
133+
| tst.ts:12:32:12:38 | [PropertyPattern] context | tst.ts:12:32:12:38 | [Label] context | semmle.label | 1 |
134+
| tst.ts:12:32:12:38 | [PropertyPattern] context | tst.ts:12:32:12:38 | [Label] context | semmle.order | 1 |
135+
| tst.ts:12:32:12:38 | [PropertyPattern] context | tst.ts:12:32:12:38 | [VarDecl] context | semmle.label | 2 |
136+
| tst.ts:12:32:12:38 | [PropertyPattern] context | tst.ts:12:32:12:38 | [VarDecl] context | semmle.order | 2 |
137+
graphProperties
138+
| semmle.graphKind | tree |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import javascript
2+
import semmle.javascript.PrintAst
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"experimentalDecorators": true
4+
},
5+
"include": ["**/*.ts"],
6+
"lib": ["es2015", "dom"]
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const Dec: any = null;
2+
3+
@Dec()
4+
export class OperatorResolvers {
5+
@Dec()
6+
@Dec()
7+
operators(): void {}
8+
}
9+
10+
const createMethodDecorator : any = null;
11+
12+
createMethodDecorator(({ args, context }, next) => {
13+
14+
});

0 commit comments

Comments
 (0)