Skip to content

Commit eddbdff

Browse files
committed
JS: Add more tests for implicit returns
1 parent 6a63f5b commit eddbdff

5 files changed

Lines changed: 48 additions & 0 deletions

File tree

javascript/ql/test/library-tests/Flow/AbstractValues.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@
168168
| h.js:2:23:2:22 | default constructor of class C |
169169
| h_import.js:1:1:3:0 | exports object of module h_import |
170170
| h_import.js:1:1:3:0 | module object of module h_import |
171+
| implicit-returns.js:1:1:27:0 | exports object of module implicit-returns |
172+
| implicit-returns.js:1:1:27:0 | module object of module implicit-returns |
173+
| implicit-returns.js:3:1:12:1 | function endWithLoop |
174+
| implicit-returns.js:3:1:12:1 | instance of function endWithLoop |
175+
| implicit-returns.js:14:1:16:1 | function useLoop |
176+
| implicit-returns.js:14:1:16:1 | instance of function useLoop |
177+
| implicit-returns.js:18:1:22:1 | function endWithShortIf |
178+
| implicit-returns.js:18:1:22:1 | instance of function endWithShortIf |
179+
| implicit-returns.js:24:1:26:1 | function useShortIf |
180+
| implicit-returns.js:24:1:26:1 | instance of function useShortIf |
171181
| import.js:1:1:13:0 | exports object of module import |
172182
| import.js:1:1:13:0 | module object of module import |
173183
| imports.ts:1:1:8:0 | exports object of module imports |

javascript/ql/test/library-tests/Flow/abseval.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,11 @@
142142
| globals.html:26:52:26:53 | x2 | globals.html:26:57:26:66 | someGlobal | file://:0:0:0:0 | non-zero value |
143143
| globals.html:26:52:26:53 | x2 | globals.html:26:57:26:66 | someGlobal | file://:0:0:0:0 | true |
144144
| h_import.js:2:5:2:6 | ff | h_import.js:2:10:2:10 | f | h.js:1:8:1:22 | function f |
145+
| implicit-returns.js:4:9:4:9 | i | implicit-returns.js:4:13:4:13 | 0 | file://:0:0:0:0 | 0 |
146+
| implicit-returns.js:15:9:15:9 | x | implicit-returns.js:15:13:15:25 | endWithLoop() | file://:0:0:0:0 | true |
147+
| implicit-returns.js:15:9:15:9 | x | implicit-returns.js:15:13:15:25 | endWithLoop() | file://:0:0:0:0 | undefined |
148+
| implicit-returns.js:25:9:25:9 | x | implicit-returns.js:25:13:25:28 | endWithShortIf() | file://:0:0:0:0 | true |
149+
| implicit-returns.js:25:9:25:9 | x | implicit-returns.js:25:13:25:28 | endWithShortIf() | file://:0:0:0:0 | undefined |
145150
| import.js:2:5:2:5 | m | import.js:2:9:2:13 | mixin | mixins.js:1:16:1:32 | anonymous function |
146151
| import.js:5:5:5:7 | myf | import.js:5:11:5:11 | f | n.js:1:1:1:15 | function f |
147152
| import.js:8:5:8:11 | someVar | import.js:8:15:8:23 | someStuff | file://:0:0:0:0 | indefinite value (call) |

javascript/ql/test/library-tests/Flow/getAPrototype.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
| globals.html:22:7:22:21 | instance of function x | globals.html:22:7:22:21 | instance of function x |
3131
| globals.html:26:23:26:69 | instance of anonymous function | globals.html:26:23:26:69 | instance of anonymous function |
3232
| h.js:1:8:1:22 | instance of function f | h.js:1:8:1:22 | instance of function f |
33+
| implicit-returns.js:3:1:12:1 | instance of function endWithLoop | implicit-returns.js:3:1:12:1 | instance of function endWithLoop |
34+
| implicit-returns.js:14:1:16:1 | instance of function useLoop | implicit-returns.js:14:1:16:1 | instance of function useLoop |
35+
| implicit-returns.js:18:1:22:1 | instance of function endWithShortIf | implicit-returns.js:18:1:22:1 | instance of function endWithShortIf |
36+
| implicit-returns.js:24:1:26:1 | instance of function useShortIf | implicit-returns.js:24:1:26:1 | instance of function useShortIf |
3337
| instances.js:1:1:4:1 | instance of function A | instances.js:1:1:4:1 | instance of function A |
3438
| instances.js:3:14:3:26 | instance of anonymous function | instances.js:3:14:3:26 | instance of anonymous function |
3539
| instances.js:6:19:6:31 | instance of anonymous function | instances.js:6:19:6:31 | instance of anonymous function |
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import 'dummy';
2+
3+
function endWithLoop() {
4+
var i = 0;
5+
while (i < 10) {
6+
if (Math.random() * 10 < i) {
7+
return true;
8+
}
9+
++i;
10+
}
11+
// Can fall over end
12+
}
13+
14+
function useLoop() {
15+
let x = endWithLoop(); // can be true or undefined
16+
}
17+
18+
function endWithShortIf() {
19+
if (something() < 10) {
20+
return true;
21+
}
22+
}
23+
24+
function useShortIf() {
25+
let x = endWithShortIf(); // true or undefined
26+
}

javascript/ql/test/library-tests/Flow/types.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@
7878
| globals.html:26:40:26:41 | x1 | globals.html:26:45:26:45 | x | boolean, class, date, function, null, number, object, regular expression,string or undefined |
7979
| globals.html:26:52:26:53 | x2 | globals.html:26:57:26:66 | someGlobal | boolean, class, date, function, null, number, object, regular expression,string or undefined |
8080
| h_import.js:2:5:2:6 | ff | h_import.js:2:10:2:10 | f | function |
81+
| implicit-returns.js:4:9:4:9 | i | implicit-returns.js:4:13:4:13 | 0 | number |
82+
| implicit-returns.js:15:9:15:9 | x | implicit-returns.js:15:13:15:25 | endWithLoop() | boolean or undefined |
83+
| implicit-returns.js:25:9:25:9 | x | implicit-returns.js:25:13:25:28 | endWithShortIf() | boolean or undefined |
8184
| import.js:2:5:2:5 | m | import.js:2:9:2:13 | mixin | function |
8285
| import.js:5:5:5:7 | myf | import.js:5:11:5:11 | f | function |
8386
| import.js:8:5:8:11 | someVar | import.js:8:15:8:23 | someStuff | boolean, class, date, function, null, number, object, regular expression,string or undefined |

0 commit comments

Comments
 (0)