forked from TypeScriptToLua/TypeScriptToLua
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeadCodeAfterReturn.spec.ts
More file actions
61 lines (49 loc) · 1.58 KB
/
Copy pathdeadCodeAfterReturn.spec.ts
File metadata and controls
61 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import * as util from "../../util";
test("If dead code after return", () => {
util.testFunction`
if (true) {
return 3;
const b = 8;
}
`.expectToMatchJsResult();
});
test("switch dead code after return", () => {
util.testFunction`
switch ("abc" as string) {
case "def":
return 4;
let abc = 4;
case "abc":
return 5;
let def = 6;
}
`.expectToMatchJsResult();
});
test("Function dead code after return", () => {
util.testFunction`
function abc() { return 3; const a = 5; }
return abc();
`.expectToMatchJsResult();
});
test("Method dead code after return", () => {
util.testFunction`
class def { public static abc() { return 3; const a = 5; } }
return def.abc();
`.expectToMatchJsResult();
});
test("for dead code after return", () => {
const result = util.transpileAndExecute(`for (let i = 0; i < 10; i++) { return 3; const b = 8; }`);
expect(result).toBe(3);
});
test("for..in dead code after return", () => {
const result = util.transpileAndExecute(`for (let a in {"a": 5, "b": 8}) { return 3; const b = 8; }`);
expect(result).toBe(3);
});
test("for..of dead code after return", () => {
const result = util.transpileAndExecute(`for (let a of [1,2,4]) { return 3; const b = 8; }`);
expect(result).toBe(3);
});
test("while dead code after return", () => {
const result = util.transpileAndExecute(`while (true) { return 3; const b = 8; }`);
expect(result).toBe(3);
});