forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextractConstants.ts
87 lines (72 loc) · 2.26 KB
/
extractConstants.ts
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/// <reference path="extractTestHelpers.ts" />
namespace ts {
describe("extractConstants", () => {
testExtractConstant("extractConstant_TopLevel",
`let x = [#|1|];`);
testExtractConstant("extractConstant_Namespace",
`namespace N {
let x = [#|1|];
}`);
testExtractConstant("extractConstant_Class",
`class C {
x = [#|1|];
}`);
testExtractConstant("extractConstant_Method",
`class C {
M() {
let x = [#|1|];
}
}`);
testExtractConstant("extractConstant_Function",
`function F() {
let x = [#|1|];
}`);
testExtractConstant("extractConstant_ExpressionStatement",
`[#|"hello";|]`);
testExtractConstant("extractConstant_ExpressionStatementExpression",
`[#|"hello"|];`);
testExtractConstant("extractConstant_BlockScopes_NoDependencies",
`for (let i = 0; i < 10; i++) {
for (let j = 0; j < 10; j++) {
let x = [#|1|];
}
}`);
testExtractConstant("extractConstant_ClassInsertionPosition",
`class C {
a = 1;
b = 2;
M1() { }
M2() { }
M3() {
let x = [#|1|];
}
}`);
testExtractConstant("extractConstant_Parameters",
`function F() {
let w = 1;
let x = [#|w + 1|];
}`);
testExtractConstant("extractConstant_TypeParameters",
`function F<T>(t: T) {
let x = [#|t + 1|];
}`);
// TODO (acasey): handle repeated substitution
// testExtractConstant("extractConstant_RepeatedSubstitution",
// `namespace X {
// export const j = 10;
// export const y = [#|j * j|];
// }`);
testExtractConstantFailed("extractConstant_BlockScopes_Dependencies",
`for (let i = 0; i < 10; i++) {
for (let j = 0; j < 10; j++) {
let x = [#|i + 1|];
}
}`);
});
function testExtractConstant(caption: string, text: string) {
testExtractSymbol(caption, text, "extractConstant", Diagnostics.Extract_constant);
}
function testExtractConstantFailed(caption: string, text: string) {
testExtractSymbolFailed(caption, text, Diagnostics.Extract_constant);
}
}