@vue/typescript-plugin 3.1.0-alpha.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +35 -56
- package/lib/requests/index.d.ts +0 -1
- package/lib/requests/isRefAtPosition.js +4 -1
- package/package.json +3 -3
- package/lib/proxy.d.ts +0 -3
- package/lib/proxy.js +0 -227
- package/lib/requests/getComponentHighlights.d.ts +0 -1
- package/lib/requests/getComponentHighlights.js +0 -3
- package/lib/requests/getCurrentComponentSlots.d.ts +0 -1
- package/lib/requests/getCurrentComponentSlots.js +0 -3
- package/lib/requests/getDefineSlotNames.d.ts +0 -1
- package/lib/requests/getDefineSlotNames.js +0 -3
- package/lib/requests/getDefineSlots.d.ts +0 -2
- package/lib/requests/getDefineSlots.js +0 -16
- package/lib/requests/getMissingPropsDiagnostics.d.ts +0 -10
- package/lib/requests/getMissingPropsDiagnostics.js +0 -40
- package/lib/requests/getPropertiesAtLocation.d.ts +0 -2
- package/lib/requests/getPropertiesAtLocation.js +0 -63
- package/lib/requests/getReactiveReferences.d.ts +0 -12
- package/lib/requests/getReactiveReferences.js +0 -605
- package/lib/requests/getReactiveVariableSpans.d.ts +0 -3
- package/lib/requests/getReactiveVariableSpans.js +0 -30
- package/lib/requests/getSemanticClassfications.d.ts +0 -3
- package/lib/requests/getSemanticClassfications.js +0 -8
- package/lib/requests/getVariableProperties.d.ts +0 -10
- package/lib/requests/getVariableProperties.js +0 -16
- package/lib/requests/isRefAtLocation.d.ts +0 -3
- package/lib/requests/isRefAtLocation.js +0 -55
- package/lib/requests/resolveModuleName.d.ts +0 -4
- package/lib/requests/resolveModuleName.js +0 -28
- package/lib/requests/types.d.ts +0 -8
- package/lib/requests/types.js +0 -3
|
@@ -1,605 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/// <reference types="@volar/typescript" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getReactiveReferences = getReactiveReferences;
|
|
5
|
-
const language_core_1 = require("@vue/language-core");
|
|
6
|
-
const analyzeCache = new WeakMap();
|
|
7
|
-
function getReactiveReferences(ts, language, languageService, sourceScript, fileName, position, leadingOffset = 0) {
|
|
8
|
-
const serviceScript = sourceScript?.generated?.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
|
9
|
-
const map = serviceScript ? language.maps.get(serviceScript.code, sourceScript) : undefined;
|
|
10
|
-
const toSourceRange = map
|
|
11
|
-
? (start, end) => {
|
|
12
|
-
for (const [mappedStart, mappedEnd] of map.toSourceRange(start - leadingOffset, end - leadingOffset, false)) {
|
|
13
|
-
return { start: mappedStart, end: mappedEnd };
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
: (start, end) => ({ start, end });
|
|
17
|
-
const sourceFile = languageService.getProgram().getSourceFile(fileName);
|
|
18
|
-
if (!analyzeCache.has(sourceFile)) {
|
|
19
|
-
analyzeCache.set(sourceFile, analyze(ts, sourceFile, toSourceRange));
|
|
20
|
-
}
|
|
21
|
-
const { signals, allValuePropertyAccess, allPropertyAccess, allFunctionCalls, } = analyzeCache.get(sourceFile);
|
|
22
|
-
const info = findSignalByBindingRange(position) ?? findSignalByCallbackRange(position);
|
|
23
|
-
if (!info) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
const dependents = info.binding ? findDependents(info.binding.ast, info.binding.accessTypes) : [];
|
|
27
|
-
const dependencies = findDependencies(info);
|
|
28
|
-
if ((!info.isDependent && !dependents.length) || (!info.isDependency && !dependencies.length)) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const dependencyRanges = [];
|
|
32
|
-
const dependentRanges = [];
|
|
33
|
-
for (const dependency of dependencies) {
|
|
34
|
-
let { ast } = dependency;
|
|
35
|
-
if (ts.isBlock(ast) && ast.statements.length) {
|
|
36
|
-
const sourceRange = toSourceRange(ast.statements[0].getStart(sourceFile), ast.statements[ast.statements.length - 1].end);
|
|
37
|
-
if (sourceRange) {
|
|
38
|
-
dependencyRanges.push({ start: sourceRange.start, end: sourceRange.end });
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
dependencyRanges.push({ start: dependency.start, end: dependency.end });
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
for (const { callback } of dependents) {
|
|
46
|
-
if (!callback) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
if (ts.isBlock(callback.ast) && callback.ast.statements.length) {
|
|
50
|
-
const { statements } = callback.ast;
|
|
51
|
-
const sourceRange = toSourceRange(statements[0].getStart(sourceFile), statements[statements.length - 1].end);
|
|
52
|
-
if (sourceRange) {
|
|
53
|
-
dependencyRanges.push({ start: sourceRange.start, end: sourceRange.end });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
dependentRanges.push({ start: callback.start, end: callback.end });
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return { dependencyRanges, dependentRanges };
|
|
61
|
-
function findDependencies(signal, visited = new Set()) {
|
|
62
|
-
if (visited.has(signal)) {
|
|
63
|
-
return [];
|
|
64
|
-
}
|
|
65
|
-
visited.add(signal);
|
|
66
|
-
const nodes = [];
|
|
67
|
-
let hasDependency = signal.isDependency;
|
|
68
|
-
if (signal.accessor) {
|
|
69
|
-
const { requiredAccess } = signal.accessor;
|
|
70
|
-
visit(signal.accessor, requiredAccess);
|
|
71
|
-
signal.accessor.ast.forEachChild(child => {
|
|
72
|
-
const childRange = toSourceRange(child.getStart(sourceFile), child.end);
|
|
73
|
-
if (childRange) {
|
|
74
|
-
visit({
|
|
75
|
-
...childRange,
|
|
76
|
-
ast: child,
|
|
77
|
-
}, requiredAccess);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
if (!hasDependency) {
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
return nodes;
|
|
85
|
-
function visit(node, requiredAccess, parentIsPropertyAccess = false) {
|
|
86
|
-
if (!requiredAccess) {
|
|
87
|
-
if (!parentIsPropertyAccess && ts.isIdentifier(node.ast)) {
|
|
88
|
-
const definition = languageService.getDefinitionAtPosition(sourceFile.fileName, node.start);
|
|
89
|
-
for (const info of definition ?? []) {
|
|
90
|
-
if (info.fileName !== sourceFile.fileName) {
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
const signal = findSignalByBindingRange(info.textSpan.start);
|
|
94
|
-
if (!signal) {
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (signal.binding) {
|
|
98
|
-
nodes.push(signal.binding);
|
|
99
|
-
hasDependency ||= signal.isDependency;
|
|
100
|
-
}
|
|
101
|
-
if (signal.callback) {
|
|
102
|
-
nodes.push(signal.callback);
|
|
103
|
-
}
|
|
104
|
-
const deps = findDependencies(signal, visited);
|
|
105
|
-
nodes.push(...deps);
|
|
106
|
-
hasDependency ||= deps.length > 0;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
else if (ts.isPropertyAccessExpression(node.ast) || ts.isElementAccessExpression(node.ast)
|
|
111
|
-
|| ts.isCallExpression(node.ast)) {
|
|
112
|
-
const definition = languageService.getDefinitionAtPosition(sourceFile.fileName, node.start);
|
|
113
|
-
for (const info of definition ?? []) {
|
|
114
|
-
if (info.fileName !== sourceFile.fileName) {
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
const signal = findSignalByBindingRange(info.textSpan.start);
|
|
118
|
-
if (!signal) {
|
|
119
|
-
continue;
|
|
120
|
-
}
|
|
121
|
-
const oldSize = nodes.length;
|
|
122
|
-
if (signal.binding) {
|
|
123
|
-
for (const accessType of signal.binding.accessTypes) {
|
|
124
|
-
if (ts.isPropertyAccessExpression(node.ast)) {
|
|
125
|
-
if (accessType === 0 /* ReactiveAccessType.ValueProperty */ && node.ast.name.text === 'value') {
|
|
126
|
-
nodes.push(signal.binding);
|
|
127
|
-
hasDependency ||= signal.isDependency;
|
|
128
|
-
}
|
|
129
|
-
if (accessType === 1 /* ReactiveAccessType.AnyProperty */ && node.ast.name.text !== '') {
|
|
130
|
-
nodes.push(signal.binding);
|
|
131
|
-
hasDependency ||= signal.isDependency;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
else if (ts.isElementAccessExpression(node.ast)) {
|
|
135
|
-
if (accessType === 1 /* ReactiveAccessType.AnyProperty */) {
|
|
136
|
-
nodes.push(signal.binding);
|
|
137
|
-
hasDependency ||= signal.isDependency;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
else if (ts.isCallExpression(node.ast)) {
|
|
141
|
-
if (accessType === 2 /* ReactiveAccessType.Call */) {
|
|
142
|
-
nodes.push(signal.binding);
|
|
143
|
-
hasDependency ||= signal.isDependency;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const signalDetected = nodes.length > oldSize;
|
|
149
|
-
if (signalDetected) {
|
|
150
|
-
if (signal.callback) {
|
|
151
|
-
nodes.push(signal.callback);
|
|
152
|
-
}
|
|
153
|
-
const deps = findDependencies(signal, visited);
|
|
154
|
-
nodes.push(...deps);
|
|
155
|
-
hasDependency ||= deps.length > 0;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
node.ast.forEachChild(child => {
|
|
160
|
-
const childRange = toSourceRange(child.getStart(sourceFile), child.end);
|
|
161
|
-
if (childRange) {
|
|
162
|
-
visit({
|
|
163
|
-
...childRange,
|
|
164
|
-
ast: child,
|
|
165
|
-
}, requiredAccess, ts.isPropertyAccessExpression(node.ast) || ts.isElementAccessExpression(node.ast));
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function findDependents(node, trackKinds, visited = new Set()) {
|
|
171
|
-
return (0, language_core_1.collectBindingRanges)(ts, node, sourceFile)
|
|
172
|
-
.map(range => {
|
|
173
|
-
const sourceRange = toSourceRange(range.start, range.end);
|
|
174
|
-
if (sourceRange) {
|
|
175
|
-
return findDependentsWorker(sourceRange.start, trackKinds, visited);
|
|
176
|
-
}
|
|
177
|
-
return [];
|
|
178
|
-
})
|
|
179
|
-
.flat();
|
|
180
|
-
}
|
|
181
|
-
function findDependentsWorker(pos, accessTypes, visited = new Set()) {
|
|
182
|
-
if (visited.has(pos)) {
|
|
183
|
-
return [];
|
|
184
|
-
}
|
|
185
|
-
visited.add(pos);
|
|
186
|
-
const references = languageService.findReferences(sourceFile.fileName, pos);
|
|
187
|
-
if (!references) {
|
|
188
|
-
return [];
|
|
189
|
-
}
|
|
190
|
-
const result = [];
|
|
191
|
-
for (const reference of references) {
|
|
192
|
-
for (const reference2 of reference.references) {
|
|
193
|
-
if (reference2.fileName !== sourceFile.fileName) {
|
|
194
|
-
continue;
|
|
195
|
-
}
|
|
196
|
-
const effect = findSignalByAccessorRange(reference2.textSpan.start);
|
|
197
|
-
if (effect?.accessor) {
|
|
198
|
-
let match = false;
|
|
199
|
-
if (effect.accessor.requiredAccess) {
|
|
200
|
-
for (const accessType of accessTypes) {
|
|
201
|
-
if (accessType === 1 /* ReactiveAccessType.AnyProperty */) {
|
|
202
|
-
match ||= allPropertyAccess.has(reference2.textSpan.start + reference2.textSpan.length);
|
|
203
|
-
}
|
|
204
|
-
else if (accessType === 0 /* ReactiveAccessType.ValueProperty */) {
|
|
205
|
-
match ||= allValuePropertyAccess.has(reference2.textSpan.start + reference2.textSpan.length);
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
match ||= allFunctionCalls.has(reference2.textSpan.start + reference2.textSpan.length);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
if (match) {
|
|
213
|
-
let hasDependent = effect.isDependent;
|
|
214
|
-
if (effect.binding) {
|
|
215
|
-
const dependents = findDependents(effect.binding.ast, effect.binding.accessTypes, visited);
|
|
216
|
-
result.push(...dependents);
|
|
217
|
-
hasDependent ||= dependents.length > 0;
|
|
218
|
-
}
|
|
219
|
-
if (hasDependent) {
|
|
220
|
-
result.push(effect);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
return result;
|
|
227
|
-
}
|
|
228
|
-
function findSignalByBindingRange(position) {
|
|
229
|
-
return signals.find(ref => ref.binding && ref.binding.start <= position
|
|
230
|
-
&& ref.binding.end >= position);
|
|
231
|
-
}
|
|
232
|
-
function findSignalByCallbackRange(position) {
|
|
233
|
-
return signals.filter(ref => ref.callback && ref.callback.start <= position
|
|
234
|
-
&& ref.callback.end >= position).sort((a, b) => (a.callback.end - a.callback.start) - (b.callback.end - b.callback.start))[0];
|
|
235
|
-
}
|
|
236
|
-
function findSignalByAccessorRange(position) {
|
|
237
|
-
return signals.filter(ref => ref.accessor && ref.accessor.start <= position
|
|
238
|
-
&& ref.accessor.end >= position).sort((a, b) => (a.accessor.end - a.accessor.start) - (b.accessor.end - b.accessor.start))[0];
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
function analyze(ts, sourceFile, toSourceRange) {
|
|
242
|
-
const signals = [];
|
|
243
|
-
const allValuePropertyAccess = new Set();
|
|
244
|
-
const allPropertyAccess = new Set();
|
|
245
|
-
const allFunctionCalls = new Set();
|
|
246
|
-
sourceFile.forEachChild(function visit(node) {
|
|
247
|
-
if (ts.isVariableDeclaration(node)) {
|
|
248
|
-
if (node.initializer && ts.isCallExpression(node.initializer)) {
|
|
249
|
-
const call = node.initializer;
|
|
250
|
-
if (ts.isIdentifier(call.expression)) {
|
|
251
|
-
const callName = call.expression.escapedText;
|
|
252
|
-
if (callName === 'ref' || callName === 'shallowRef' || callName === 'toRef' || callName === 'useTemplateRef'
|
|
253
|
-
|| callName === 'defineModel') {
|
|
254
|
-
const nameRange = toSourceRange(node.name.getStart(sourceFile), node.name.end);
|
|
255
|
-
if (nameRange) {
|
|
256
|
-
signals.push({
|
|
257
|
-
isDependency: true,
|
|
258
|
-
isDependent: false,
|
|
259
|
-
binding: {
|
|
260
|
-
...nameRange,
|
|
261
|
-
ast: node.name,
|
|
262
|
-
accessTypes: [0 /* ReactiveAccessType.ValueProperty */],
|
|
263
|
-
},
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else if (callName === 'reactive' || callName === 'shallowReactive' || callName === 'defineProps'
|
|
268
|
-
|| callName === 'withDefaults') {
|
|
269
|
-
const nameRange = toSourceRange(node.name.getStart(sourceFile), node.name.end);
|
|
270
|
-
if (nameRange) {
|
|
271
|
-
signals.push({
|
|
272
|
-
isDependency: true,
|
|
273
|
-
isDependent: false,
|
|
274
|
-
binding: {
|
|
275
|
-
...nameRange,
|
|
276
|
-
ast: node.name,
|
|
277
|
-
accessTypes: [1 /* ReactiveAccessType.AnyProperty */],
|
|
278
|
-
},
|
|
279
|
-
});
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
// TODO: toRefs
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
else if (ts.isFunctionDeclaration(node)) {
|
|
287
|
-
if (node.name && node.body) {
|
|
288
|
-
const nameRange = toSourceRange(node.name.getStart(sourceFile), node.name.end);
|
|
289
|
-
const bodyRange = toSourceRange(node.body.getStart(sourceFile), node.body.end);
|
|
290
|
-
if (nameRange && bodyRange) {
|
|
291
|
-
signals.push({
|
|
292
|
-
isDependency: false,
|
|
293
|
-
isDependent: false,
|
|
294
|
-
binding: {
|
|
295
|
-
...nameRange,
|
|
296
|
-
ast: node.name,
|
|
297
|
-
accessTypes: [2 /* ReactiveAccessType.Call */],
|
|
298
|
-
},
|
|
299
|
-
accessor: {
|
|
300
|
-
...bodyRange,
|
|
301
|
-
ast: node.body,
|
|
302
|
-
requiredAccess: true,
|
|
303
|
-
},
|
|
304
|
-
callback: {
|
|
305
|
-
...bodyRange,
|
|
306
|
-
ast: node.body,
|
|
307
|
-
},
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
else if (ts.isVariableStatement(node)) {
|
|
313
|
-
for (const declaration of node.declarationList.declarations) {
|
|
314
|
-
const name = declaration.name;
|
|
315
|
-
const callback = declaration.initializer;
|
|
316
|
-
if (callback && ts.isIdentifier(name) && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))) {
|
|
317
|
-
const nameRange = toSourceRange(name.getStart(sourceFile), name.end);
|
|
318
|
-
const callbackRange = toSourceRange(callback.getStart(sourceFile), callback.end);
|
|
319
|
-
if (nameRange && callbackRange) {
|
|
320
|
-
signals.push({
|
|
321
|
-
isDependency: false,
|
|
322
|
-
isDependent: false,
|
|
323
|
-
binding: {
|
|
324
|
-
...nameRange,
|
|
325
|
-
ast: name,
|
|
326
|
-
accessTypes: [2 /* ReactiveAccessType.Call */],
|
|
327
|
-
},
|
|
328
|
-
accessor: {
|
|
329
|
-
...callbackRange,
|
|
330
|
-
ast: callback,
|
|
331
|
-
requiredAccess: true,
|
|
332
|
-
},
|
|
333
|
-
callback: {
|
|
334
|
-
...callbackRange,
|
|
335
|
-
ast: callback,
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
else if (ts.isParameter(node)) {
|
|
343
|
-
if (node.type && ts.isTypeReferenceNode(node.type)) {
|
|
344
|
-
const typeName = node.type.typeName.getText(sourceFile);
|
|
345
|
-
if (typeName.endsWith('Ref')) {
|
|
346
|
-
const nameRange = toSourceRange(node.name.getStart(sourceFile), node.name.end);
|
|
347
|
-
if (nameRange) {
|
|
348
|
-
signals.push({
|
|
349
|
-
isDependency: true,
|
|
350
|
-
isDependent: false,
|
|
351
|
-
binding: {
|
|
352
|
-
...nameRange,
|
|
353
|
-
ast: node.name,
|
|
354
|
-
accessTypes: [0 /* ReactiveAccessType.ValueProperty */],
|
|
355
|
-
},
|
|
356
|
-
});
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
|
|
362
|
-
const call = node;
|
|
363
|
-
const callName = node.expression.escapedText;
|
|
364
|
-
if ((callName === 'effect' || callName === 'watchEffect') && call.arguments.length) {
|
|
365
|
-
const callback = call.arguments[0];
|
|
366
|
-
if (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) {
|
|
367
|
-
const callbackRange = toSourceRange(callback.getStart(sourceFile), callback.end);
|
|
368
|
-
if (callbackRange) {
|
|
369
|
-
signals.push({
|
|
370
|
-
isDependency: false,
|
|
371
|
-
isDependent: true,
|
|
372
|
-
accessor: {
|
|
373
|
-
...callbackRange,
|
|
374
|
-
ast: callback.body,
|
|
375
|
-
requiredAccess: true,
|
|
376
|
-
},
|
|
377
|
-
callback: {
|
|
378
|
-
...callbackRange,
|
|
379
|
-
ast: callback.body,
|
|
380
|
-
},
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
if (callName === 'watch' && call.arguments.length >= 2) {
|
|
386
|
-
const depsCallback = call.arguments[0];
|
|
387
|
-
const effectCallback = call.arguments[1];
|
|
388
|
-
if (ts.isArrowFunction(effectCallback) || ts.isFunctionExpression(effectCallback)) {
|
|
389
|
-
const depsRange = toSourceRange(depsCallback.getStart(sourceFile), depsCallback.end);
|
|
390
|
-
const effectRange = toSourceRange(effectCallback.getStart(sourceFile), effectCallback.end);
|
|
391
|
-
if (depsRange && effectRange) {
|
|
392
|
-
if (ts.isArrowFunction(depsCallback) || ts.isFunctionExpression(depsCallback)) {
|
|
393
|
-
signals.push({
|
|
394
|
-
isDependency: false,
|
|
395
|
-
isDependent: true,
|
|
396
|
-
accessor: {
|
|
397
|
-
...depsRange,
|
|
398
|
-
ast: depsCallback.body,
|
|
399
|
-
requiredAccess: true,
|
|
400
|
-
},
|
|
401
|
-
callback: {
|
|
402
|
-
...effectRange,
|
|
403
|
-
ast: effectCallback.body,
|
|
404
|
-
},
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
else {
|
|
408
|
-
signals.push({
|
|
409
|
-
isDependency: false,
|
|
410
|
-
isDependent: true,
|
|
411
|
-
accessor: {
|
|
412
|
-
...depsRange,
|
|
413
|
-
ast: depsCallback,
|
|
414
|
-
requiredAccess: false,
|
|
415
|
-
},
|
|
416
|
-
callback: {
|
|
417
|
-
...effectRange,
|
|
418
|
-
ast: effectCallback.body,
|
|
419
|
-
},
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
else if ((0, language_core_1.hyphenateAttr)(callName).startsWith('use-')) {
|
|
426
|
-
let binding;
|
|
427
|
-
if (ts.isVariableDeclaration(call.parent)) {
|
|
428
|
-
const nameRange = toSourceRange(call.parent.name.getStart(sourceFile), call.parent.name.end);
|
|
429
|
-
if (nameRange) {
|
|
430
|
-
binding = {
|
|
431
|
-
...nameRange,
|
|
432
|
-
ast: call.parent.name,
|
|
433
|
-
accessTypes: [1 /* ReactiveAccessType.AnyProperty */, 2 /* ReactiveAccessType.Call */],
|
|
434
|
-
};
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
const callRange = toSourceRange(call.getStart(sourceFile), call.end);
|
|
438
|
-
if (callRange) {
|
|
439
|
-
signals.push({
|
|
440
|
-
isDependency: true,
|
|
441
|
-
isDependent: false,
|
|
442
|
-
binding,
|
|
443
|
-
accessor: {
|
|
444
|
-
...callRange,
|
|
445
|
-
ast: call,
|
|
446
|
-
requiredAccess: false,
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
else if ((callName === 'computed' || (0, language_core_1.hyphenateAttr)(callName).endsWith('-computed')) && call.arguments.length) {
|
|
452
|
-
const arg = call.arguments[0];
|
|
453
|
-
if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) {
|
|
454
|
-
let binding;
|
|
455
|
-
if (ts.isVariableDeclaration(call.parent)) {
|
|
456
|
-
const nameRange = toSourceRange(call.parent.name.getStart(sourceFile), call.parent.name.end);
|
|
457
|
-
if (nameRange) {
|
|
458
|
-
binding = {
|
|
459
|
-
...nameRange,
|
|
460
|
-
ast: call.parent.name,
|
|
461
|
-
accessTypes: [0 /* ReactiveAccessType.ValueProperty */],
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
const argRange = toSourceRange(arg.getStart(sourceFile), arg.end);
|
|
466
|
-
if (argRange) {
|
|
467
|
-
signals.push({
|
|
468
|
-
isDependency: true,
|
|
469
|
-
isDependent: true,
|
|
470
|
-
binding,
|
|
471
|
-
accessor: {
|
|
472
|
-
...argRange,
|
|
473
|
-
ast: arg.body,
|
|
474
|
-
requiredAccess: true,
|
|
475
|
-
},
|
|
476
|
-
callback: {
|
|
477
|
-
...argRange,
|
|
478
|
-
ast: arg.body,
|
|
479
|
-
},
|
|
480
|
-
});
|
|
481
|
-
}
|
|
482
|
-
}
|
|
483
|
-
else if (ts.isIdentifier(arg)) {
|
|
484
|
-
let binding;
|
|
485
|
-
if (ts.isVariableDeclaration(call.parent)) {
|
|
486
|
-
const nameRange = toSourceRange(call.parent.name.getStart(sourceFile), call.parent.name.end);
|
|
487
|
-
if (nameRange) {
|
|
488
|
-
binding = {
|
|
489
|
-
...nameRange,
|
|
490
|
-
ast: call.parent.name,
|
|
491
|
-
accessTypes: [0 /* ReactiveAccessType.ValueProperty */],
|
|
492
|
-
};
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
const argRange = toSourceRange(arg.getStart(sourceFile), arg.end);
|
|
496
|
-
if (argRange) {
|
|
497
|
-
signals.push({
|
|
498
|
-
isDependency: true,
|
|
499
|
-
isDependent: false,
|
|
500
|
-
binding,
|
|
501
|
-
accessor: {
|
|
502
|
-
...argRange,
|
|
503
|
-
ast: arg,
|
|
504
|
-
requiredAccess: false,
|
|
505
|
-
},
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
else if (ts.isObjectLiteralExpression(arg)) {
|
|
510
|
-
for (const prop of arg.properties) {
|
|
511
|
-
if (prop.name?.getText(sourceFile) === 'get') {
|
|
512
|
-
let binding;
|
|
513
|
-
if (ts.isVariableDeclaration(call.parent)) {
|
|
514
|
-
const nameRange = toSourceRange(call.parent.name.getStart(sourceFile), call.parent.name.end);
|
|
515
|
-
if (nameRange) {
|
|
516
|
-
binding = {
|
|
517
|
-
...nameRange,
|
|
518
|
-
ast: call.parent.name,
|
|
519
|
-
accessTypes: [0 /* ReactiveAccessType.ValueProperty */],
|
|
520
|
-
};
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
if (ts.isPropertyAssignment(prop)) {
|
|
524
|
-
const callback = prop.initializer;
|
|
525
|
-
if (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) {
|
|
526
|
-
const callbackRange = toSourceRange(callback.getStart(sourceFile), callback.end);
|
|
527
|
-
if (callbackRange) {
|
|
528
|
-
signals.push({
|
|
529
|
-
isDependency: true,
|
|
530
|
-
isDependent: true,
|
|
531
|
-
binding,
|
|
532
|
-
accessor: {
|
|
533
|
-
...callbackRange,
|
|
534
|
-
ast: callback.body,
|
|
535
|
-
requiredAccess: true,
|
|
536
|
-
},
|
|
537
|
-
callback: {
|
|
538
|
-
...callbackRange,
|
|
539
|
-
ast: callback.body,
|
|
540
|
-
},
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
else if (ts.isMethodDeclaration(prop) && prop.body) {
|
|
546
|
-
const bodyRange = toSourceRange(prop.body.getStart(sourceFile), prop.body.end);
|
|
547
|
-
if (bodyRange) {
|
|
548
|
-
signals.push({
|
|
549
|
-
isDependency: true,
|
|
550
|
-
isDependent: true,
|
|
551
|
-
binding,
|
|
552
|
-
accessor: {
|
|
553
|
-
...bodyRange,
|
|
554
|
-
ast: prop.body,
|
|
555
|
-
requiredAccess: true,
|
|
556
|
-
},
|
|
557
|
-
callback: {
|
|
558
|
-
...bodyRange,
|
|
559
|
-
ast: prop.body,
|
|
560
|
-
},
|
|
561
|
-
});
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
node.forEachChild(visit);
|
|
570
|
-
});
|
|
571
|
-
sourceFile.forEachChild(function visit(node) {
|
|
572
|
-
if (ts.isPropertyAccessExpression(node)) {
|
|
573
|
-
const sourceRange = toSourceRange(node.expression.end, node.expression.end);
|
|
574
|
-
if (sourceRange) {
|
|
575
|
-
if (node.name.text === 'value') {
|
|
576
|
-
allValuePropertyAccess.add(sourceRange.end);
|
|
577
|
-
allPropertyAccess.add(sourceRange.end);
|
|
578
|
-
}
|
|
579
|
-
else if (node.name.text !== '') {
|
|
580
|
-
allPropertyAccess.add(sourceRange.end);
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
}
|
|
584
|
-
else if (ts.isElementAccessExpression(node)) {
|
|
585
|
-
const sourceRange = toSourceRange(node.expression.end, node.expression.end);
|
|
586
|
-
if (sourceRange) {
|
|
587
|
-
allPropertyAccess.add(sourceRange.end);
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
else if (ts.isCallExpression(node)) {
|
|
591
|
-
const sourceRange = toSourceRange(node.expression.end, node.expression.end);
|
|
592
|
-
if (sourceRange) {
|
|
593
|
-
allFunctionCalls.add(sourceRange.end);
|
|
594
|
-
}
|
|
595
|
-
}
|
|
596
|
-
node.forEachChild(visit);
|
|
597
|
-
});
|
|
598
|
-
return {
|
|
599
|
-
signals,
|
|
600
|
-
allValuePropertyAccess,
|
|
601
|
-
allPropertyAccess,
|
|
602
|
-
allFunctionCalls,
|
|
603
|
-
};
|
|
604
|
-
}
|
|
605
|
-
//# sourceMappingURL=getReactiveReferences.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { SourceScript } from '@vue/language-core';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
|
-
export declare function getReactiveVariableSpans(ts: typeof import('typescript'), program: ts.Program, sourceScript: SourceScript, fileName: string, isTsPlugin: boolean): ts.TextSpan[];
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getReactiveVariableSpans = getReactiveVariableSpans;
|
|
4
|
-
function getReactiveVariableSpans(ts, program, sourceScript, fileName, isTsPlugin) {
|
|
5
|
-
const sourceFile = program.getSourceFile(fileName);
|
|
6
|
-
if (!sourceFile) {
|
|
7
|
-
return [];
|
|
8
|
-
}
|
|
9
|
-
const checker = program.getTypeChecker();
|
|
10
|
-
const minusOffset = isTsPlugin ? sourceScript.snapshot.getLength() : 0;
|
|
11
|
-
const variableSpans = [];
|
|
12
|
-
ts.forEachChild(sourceFile, function visit(node) {
|
|
13
|
-
if (ts.isIdentifier(node)) {
|
|
14
|
-
const symbol = checker.getSymbolAtLocation(node);
|
|
15
|
-
if (symbol) {
|
|
16
|
-
const type = checker.getTypeOfSymbol(symbol);
|
|
17
|
-
const properties = type.getProperties();
|
|
18
|
-
if (properties.some(prop => prop.getName().startsWith('__@RefSymbol@'))) {
|
|
19
|
-
variableSpans.push({
|
|
20
|
-
start: node.getStart(sourceFile) - minusOffset,
|
|
21
|
-
length: node.getWidth(),
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
ts.forEachChild(node, visit);
|
|
27
|
-
});
|
|
28
|
-
return variableSpans;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=getReactiveVariableSpans.js.map
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSemanticClassifications = getSemanticClassifications;
|
|
4
|
-
function getSemanticClassifications(fileName, span) {
|
|
5
|
-
const { languageService, typescript: ts } = this;
|
|
6
|
-
return languageService.getSemanticClassifications(fileName, span, ts.SemanticClassificationFormat.TwentyTwenty);
|
|
7
|
-
}
|
|
8
|
-
//# sourceMappingURL=getSemanticClassfications.js.map
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { RequestContext } from './types';
|
|
2
|
-
export interface ComponentPropInfo {
|
|
3
|
-
name: string;
|
|
4
|
-
required?: boolean;
|
|
5
|
-
deprecated?: boolean;
|
|
6
|
-
isAttribute?: boolean;
|
|
7
|
-
commentMarkdown?: string;
|
|
8
|
-
values?: string[];
|
|
9
|
-
}
|
|
10
|
-
export declare function getVariableProperties(this: RequestContext, fileName: string, variableName: string): string[] | undefined;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getVariableProperties = getVariableProperties;
|
|
4
|
-
const language_core_1 = require("@vue/language-core");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
function getVariableProperties(fileName, variableName) {
|
|
7
|
-
const { typescript: ts, language, languageService, asScriptId } = this;
|
|
8
|
-
const volarFile = language.scripts.get(asScriptId(fileName));
|
|
9
|
-
if (!(volarFile?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const vueCode = volarFile.generated.root;
|
|
13
|
-
const variable = (0, utils_1.getVariableType)(ts, languageService, vueCode, variableName);
|
|
14
|
-
return variable?.type.getProperties().map(prop => prop.name);
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=getVariableProperties.js.map
|