@vue/typescript-plugin 3.0.7 → 3.0.8
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 +2 -2
- package/lib/common.js +2 -2
- package/lib/requests/getReactiveReferences.d.ts +3 -10
- package/lib/requests/getReactiveReferences.js +44 -595
- package/package.json +4 -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/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 +1,54 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
/// <reference types="@volar/typescript" />
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
3
|
exports.getReactiveReferences = getReactiveReferences;
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const typescript_1 = require("@volar/typescript");
|
|
5
|
+
const laplacenoma_1 = require("laplacenoma");
|
|
6
|
+
const rulesVue = require("laplacenoma/rules/vue");
|
|
7
|
+
const analyzer = (0, laplacenoma_1.createAnalyzer)({
|
|
8
|
+
rules: rulesVue,
|
|
9
|
+
});
|
|
10
|
+
let currentVersion = -1;
|
|
11
|
+
let currentFileName = '';
|
|
12
|
+
let currentSnapshot;
|
|
13
|
+
let languageService;
|
|
14
|
+
let languageServiceHost;
|
|
15
|
+
function getReactiveReferences(ts, language, sourceScript, position, leadingOffset = 0) {
|
|
16
|
+
if (currentSnapshot !== sourceScript.snapshot || currentFileName !== sourceScript.id) {
|
|
17
|
+
currentSnapshot = sourceScript.snapshot;
|
|
18
|
+
currentFileName = sourceScript.id;
|
|
19
|
+
currentVersion++;
|
|
20
|
+
}
|
|
21
|
+
if (!languageService) {
|
|
22
|
+
languageServiceHost = {
|
|
23
|
+
getProjectVersion: () => currentVersion.toString(),
|
|
24
|
+
getScriptVersion: () => currentVersion.toString(),
|
|
25
|
+
getScriptFileNames: () => [currentFileName],
|
|
26
|
+
getScriptSnapshot: fileName => fileName === currentFileName ? currentSnapshot : undefined,
|
|
27
|
+
getCompilationSettings: () => ({ allowJs: true, allowNonTsExtensions: true }),
|
|
28
|
+
getCurrentDirectory: () => '',
|
|
29
|
+
getDefaultLibFileName: () => '',
|
|
30
|
+
readFile: () => undefined,
|
|
31
|
+
fileExists: fileName => fileName === currentFileName,
|
|
32
|
+
};
|
|
33
|
+
(0, typescript_1.decorateLanguageServiceHost)(ts, language, languageServiceHost);
|
|
34
|
+
const proxied = (0, typescript_1.createProxyLanguageService)(ts.createLanguageService(languageServiceHost));
|
|
35
|
+
proxied.initialize(language);
|
|
36
|
+
languageService = proxied.proxy;
|
|
37
|
+
}
|
|
38
|
+
const sourceFile = languageService.getProgram().getSourceFile(sourceScript.id);
|
|
39
|
+
const serviceScript = sourceScript.generated?.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
|
9
40
|
const map = serviceScript ? language.maps.get(serviceScript.code, sourceScript) : undefined;
|
|
10
41
|
const toSourceRange = map
|
|
11
|
-
? (
|
|
12
|
-
for (const [mappedStart, mappedEnd] of map.toSourceRange(
|
|
13
|
-
return {
|
|
42
|
+
? (pos, end) => {
|
|
43
|
+
for (const [mappedStart, mappedEnd] of map.toSourceRange(pos - leadingOffset, end - leadingOffset, false)) {
|
|
44
|
+
return { pos: mappedStart, end: mappedEnd };
|
|
14
45
|
}
|
|
15
46
|
}
|
|
16
|
-
: (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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);
|
|
47
|
+
: (pos, end) => ({ pos, end });
|
|
48
|
+
return analyzer.analyze(sourceFile, position, {
|
|
49
|
+
typescript: ts,
|
|
50
|
+
languageService,
|
|
51
|
+
toSourceRange,
|
|
597
52
|
});
|
|
598
|
-
return {
|
|
599
|
-
signals,
|
|
600
|
-
allValuePropertyAccess,
|
|
601
|
-
allPropertyAccess,
|
|
602
|
-
allFunctionCalls,
|
|
603
|
-
};
|
|
604
53
|
}
|
|
605
54
|
//# sourceMappingURL=getReactiveReferences.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@volar/typescript": "2.4.23",
|
|
17
|
-
"@vue/language-core": "3.0.
|
|
17
|
+
"@vue/language-core": "3.0.8",
|
|
18
18
|
"@vue/shared": "^3.5.0",
|
|
19
|
+
"laplacenoma": "^0.0.3",
|
|
19
20
|
"path-browserify": "^1.0.1"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
22
23
|
"@types/node": "^22.10.4",
|
|
23
24
|
"@types/path-browserify": "^1.0.1"
|
|
24
25
|
},
|
|
25
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "f7bdeaa7bb476df1fc8ff46c504d75c1869b0be9"
|
|
26
27
|
}
|
package/lib/proxy.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type Language, type VueCompilerOptions } from '@vue/language-core';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
|
-
export declare function createVueLanguageServiceProxy(ts: typeof import('typescript'), language: Language<string>, languageService: ts.LanguageService, vueOptions: VueCompilerOptions): ts.LanguageService;
|