File: localGetReferences.ts

package info (click to toggle)
node-typescript 4.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 396,552 kB
  • sloc: javascript: 1,444,377; makefile: 7; sh: 3
file content (248 lines) | stat: -rw-r--r-- 7,278 bytes parent folder | download
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/// <reference path='fourslash.ts'/>

// @Filename: localGetReferences_1.ts
////// Comment Refence Test: g/*1*/lobalVar
////// References to a variable declared in global.
////[|var [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 0 |}globalVar|]: number = 2;|]
////
////class fooCls {
////    // References to static variable declared in a class.
////    [|static [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 2 |}clsSVar|] = 1;|]
////    // References to a variable declared in a class.
////    [|[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 4 |}clsVar|] = 1;|]
////
////    constructor ([|public [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 6 |}clsParam|]: number|]) {
////        //Increments
////        [|{| "isWriteAccess": true |}globalVar|]++;
////        this.[|{| "isWriteAccess": true |}clsVar|]++;
////        fooCls.[|{| "isWriteAccess": true |}clsSVar|]++;
////        // References to a class parameter.
////        this.[|{| "isWriteAccess": true |}clsParam|]++;
////        modTest.modVar++;
////    }
////}
////
////// References to a function parameter.
////[|function [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 12 |}foo|]([|[|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 14 |}x|]: number|]) {
////    // References to a variable declared in a function.
////    [|var [|{| "isWriteAccess": true, "isDefinition": true, "contextRangeIndex": 16 |}fnVar|] = 1;|]
////
////    //Increments
////    fooCls.[|{| "isWriteAccess": true |}clsSVar|]++;
////    [|{| "isWriteAccess": true |}globalVar|]++;
////    modTest.modVar++;
////    [|{| "isWriteAccess": true |}fnVar|]++;
////
////    //Return
////    return [|{| "isWriteAccess": true |}x|]++;
////}|]
////
////module modTest {
////    //Declare
////    export var modVar:number;
////
////    //Increments
////    [|{| "isWriteAccess": true |}globalVar|]++;
////    fooCls.[|{| "isWriteAccess": true |}clsSVar|]++;
////    modVar++;
////
////    class testCls {
////        static boo = [|foo|];
////    }
////
////    function testFn(){
////        static boo = [|foo|];
////
////        //Increments
////        [|{| "isWriteAccess": true |}globalVar|]++;
////        fooCls.[|{| "isWriteAccess": true |}clsSVar|]++;
////        modVar++;
////    }
////
////    module testMod {
////        var boo = [|foo|];
////    }
////}
////
//////Type test
////var clsTest: fooCls;
////
//////Arguments
////// References to a class argument.
////clsTest = new fooCls([|globalVar|]);
////// References to a function argument.
////[|foo|]([|globalVar|]);
////
//////Increments
////fooCls.[|{| "isWriteAccess": true |}clsSVar|]++;
////modTest.modVar++;
////[|{| "isWriteAccess": true |}globalVar|] = [|globalVar|] + [|globalVar|];
////
//////ETC - Other cases
////[|{| "isWriteAccess": true |}globalVar|] = 3;
////// References to illegal assignment.
////[|{| "isWriteAccess": true |}foo|] = [|foo|] + 1;
/////*3*/err = err++;
/////*4*/
//////Shadowed fn Parameter
////function shdw([|[|{| "isWriteAccess": true, "isDefinition": true, "shadow": true, "contextRangeIndex": 39 |}globalVar|]: number|]) {
////    //Increments
////    [|{| "isWriteAccess": true, "shadow": true |}globalVar|]++;
////    return [|{| "shadow": true |}globalVar|];
////}
////
//////Remotes
//////Type test
////var remoteclsTest: remotefooCls;
////
//////Arguments
////remoteclsTest = new remotefooCls(remoteglobalVar);
////remotefoo(remoteglobalVar);
////
//////Increments
////remotefooCls.remoteclsSVar++;
////remotemodTest.remotemodVar++;
////remoteglobalVar = remoteglobalVar + remoteglobalVar;
////
//////ETC - Other cases
////remoteglobalVar = 3;
////
//////Find References misses method param
////var
////
////
////
//// array = ["f", "o", "o"];
////
////array.forEach(
////
////
////function([|{| "isWriteAccess": true, "isDefinition": true |}str|]) {
////
////
////
////   // Reference misses function parameter.
////   return [|str|] + " ";
////
////});

// @Filename: localGetReferences_2.ts
////var remoteglobalVar: number = 2;
////
////class remotefooCls {
////	//Declare
////	remoteclsVar = 1;
////	static remoteclsSVar = 1;
////
////	constructor(public remoteclsParam: number) {
////		//Increments
////		remoteglobalVar++;
////		this.remoteclsVar++;
////		remotefooCls.remoteclsSVar++;
////		this.remoteclsParam++;
////		remotemodTest.remotemodVar++;
////	}
////}
////
////function remotefoo(remotex: number) {
////	//Declare
////	var remotefnVar = 1;
////
////	//Increments
////	remotefooCls.remoteclsSVar++;
////	remoteglobalVar++;
////	remotemodTest.remotemodVar++;
////	remotefnVar++;
////
////	//Return
////	return remotex++;
////}
////
////module remotemodTest {
////	//Declare
////	export var remotemodVar: number;
////
////	//Increments
////	remoteglobalVar++;
////	remotefooCls.remoteclsSVar++;
////	remotemodVar++;
////
////	class remotetestCls {
////		static remoteboo = remotefoo;
////	}
////`
////	function remotetestFn(){
////        static remoteboo = remotefoo;
////
////		//Increments
////		remoteglobalVar++;
////		remotefooCls.remoteclsSVar++;
////		remotemodVar++;
////    }
////
////	module remotetestMod {
////		var remoteboo = remotefoo;
////	}
////}

// References to comment.
goTo.marker("1");
verify.noReferences();

// References to unresolved symbol.
goTo.marker("3");
verify.noReferences();

// References to no context.
goTo.marker("4");
verify.noReferences();

test.rangesByText().forEach((ranges, text) => {
    switch (text) {
        case "var globalVar: number = 2;":
        case "static clsSVar = 1;":
        case "clsVar = 1;":
        case "public clsParam: number":
        case `function foo(x: number) {
    // References to a variable declared in a function.
    var fnVar = 1;

    //Increments
    fooCls.clsSVar++;
    globalVar++;
    modTest.modVar++;
    fnVar++;

    //Return
    return x++;
}`:
        case "x: number":
        case "var fnVar = 1;":
        case "globalVar: number":
            return;
    }

    if (text === "globalVar") {
        verify.singleReferenceGroup("(parameter) globalVar: number", ranges.filter(isShadow));
        verify.singleReferenceGroup("var globalVar: number", ranges.filter(r => !isShadow(r)));
        return;
    }

    const definition = (() => {
        switch (text) {
            case "fnVar": return "(local var) fnVar: number";
            case "clsSVar": return "(property) fooCls.clsSVar: number";
            case "clsVar": return "(property) fooCls.clsVar: number";
            case "clsParam": return "(property) fooCls.clsParam: number";
            case "foo": return "function foo(x: number): number";
            case "x": return "(parameter) x: number";
            case "str": return "(parameter) str: string";
            default: throw new Error(text);
        }
    })();
    verify.singleReferenceGroup(definition, ranges);
});

function isShadow(r) {
    return r.marker && r.marker.data && r.marker.data.shadow;
}