@vue/language-server 3.0.7-alpha.1 → 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 CHANGED
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const language_server_1 = require("@volar/language-server");
4
3
  const simpleProject_1 = require("@volar/language-server/lib/project/simpleProject");
5
4
  const node_1 = require("@volar/language-server/node");
6
5
  const language_core_1 = require("@vue/language-core");
7
6
  const language_service_1 = require("@vue/language-service");
8
7
  const ts = require("typescript");
9
8
  const vscode_uri_1 = require("vscode-uri");
10
- const reactivityAnalyze_1 = require("./lib/reactivityAnalyze");
11
- const reactivityAnalyzeLS_1 = require("./lib/reactivityAnalyzeLS");
12
9
  const connection = (0, node_1.createConnection)();
13
10
  const server = (0, node_1.createServer)(connection);
14
11
  const tsserverRequestHandlers = new Map();
@@ -102,8 +99,11 @@ connection.onInitialize(params => {
102
99
  getImportPathForFile(...args) {
103
100
  return sendTsServerRequest('_vue:getImportPathForFile', args);
104
101
  },
105
- getPropertiesAtLocation(...args) {
106
- return sendTsServerRequest('_vue:getPropertiesAtLocation', args);
102
+ getReactiveReferences(...args) {
103
+ return sendTsServerRequest('_vue:getReactiveReferences', args);
104
+ },
105
+ isRefAtPosition(...args) {
106
+ return sendTsServerRequest('_vue:isRefAtPosition', args);
107
107
  },
108
108
  getDocumentHighlights(fileName, position) {
109
109
  return sendTsServerRequest('_vue:documentHighlights-full', {
@@ -158,155 +158,4 @@ connection.onInitialize(params => {
158
158
  });
159
159
  connection.onInitialized(server.initialized);
160
160
  connection.onShutdown(server.shutdown);
161
- connection.onRequest('vue/interpolationRanges', async (params) => {
162
- const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
163
- const languageService = await server.project.getLanguageService(uri);
164
- if (languageService) {
165
- const sourceFile = languageService.context.language.scripts.get(uri);
166
- if (sourceFile?.generated) {
167
- const ranges = [];
168
- for (const code of (0, language_core_1.forEachEmbeddedCode)(sourceFile.generated.root)) {
169
- const codeText = code.snapshot.getText(0, code.snapshot.getLength());
170
- if ((code.id.startsWith('template_inline_ts_')
171
- && codeText.startsWith('0 +')
172
- && codeText.endsWith('+ 0;'))
173
- || (code.id.startsWith('style_') && code.id.endsWith('_inline_ts'))) {
174
- for (const mapping of code.mappings) {
175
- for (let i = 0; i < mapping.sourceOffsets.length; i++) {
176
- ranges.push([
177
- mapping.sourceOffsets[i],
178
- mapping.sourceOffsets[i] + mapping.lengths[i],
179
- ]);
180
- }
181
- }
182
- }
183
- }
184
- return ranges;
185
- }
186
- }
187
- return [];
188
- });
189
- const cacheDocuments = new Map();
190
- connection.onRequest('vue/reactivityAnalyze', async (params) => {
191
- if (params.syncDocument) {
192
- const document = language_server_1.TextDocument.create(params.textDocument.uri, params.syncDocument.languageId, 0, params.syncDocument.content);
193
- const snapshot = ts.ScriptSnapshot.fromString(params.syncDocument.content);
194
- cacheDocuments.set(params.textDocument.uri, [document, snapshot]);
195
- }
196
- const uri = vscode_uri_1.URI.parse(params.textDocument.uri);
197
- const languageService = await server.project.getLanguageService(uri);
198
- const sourceScript = languageService.context.language.scripts.get(uri);
199
- let document;
200
- let snapshot;
201
- if (sourceScript) {
202
- document = languageService.context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot);
203
- snapshot = sourceScript.snapshot;
204
- }
205
- else if (cacheDocuments.has(params.textDocument.uri)) {
206
- const [doc, snap] = cacheDocuments.get(params.textDocument.uri);
207
- document = doc;
208
- snapshot = snap;
209
- }
210
- if (!document || !snapshot) {
211
- return;
212
- }
213
- let offset = document.offsetAt(params.position);
214
- if (sourceScript?.generated) {
215
- const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
216
- if (!serviceScript) {
217
- return;
218
- }
219
- const map = languageService.context.language.maps.get(serviceScript.code, sourceScript);
220
- let embeddedOffset;
221
- for (const [mapped, mapping] of map.toGeneratedLocation(offset)) {
222
- if ((0, language_core_1.isReferencesEnabled)(mapping.data)) {
223
- embeddedOffset = mapped;
224
- break;
225
- }
226
- }
227
- if (embeddedOffset === undefined) {
228
- return;
229
- }
230
- offset = embeddedOffset;
231
- const embeddedUri = languageService.context.encodeEmbeddedDocumentUri(sourceScript.id, serviceScript.code.id);
232
- document = languageService.context.documents.get(embeddedUri, serviceScript.code.languageId, serviceScript.code.snapshot);
233
- snapshot = serviceScript.code.snapshot;
234
- }
235
- const { languageService: tsLs, fileName } = (0, reactivityAnalyzeLS_1.getLanguageService)(ts, snapshot, document.languageId);
236
- const result = (0, reactivityAnalyze_1.analyze)(ts, tsLs, fileName, offset);
237
- if (!result) {
238
- return;
239
- }
240
- const subscribers = [];
241
- const dependencies = [];
242
- if (sourceScript?.generated) {
243
- const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
244
- if (!serviceScript) {
245
- return;
246
- }
247
- const docs = [
248
- languageService.context.documents.get(sourceScript.id, sourceScript.languageId, sourceScript.snapshot),
249
- document,
250
- languageService.context.language.maps.get(serviceScript.code, sourceScript),
251
- ];
252
- for (const dependency of result.dependencies) {
253
- let start = document.positionAt(dependency.getStart(result.sourceFile));
254
- let end = document.positionAt(dependency.getEnd());
255
- if (ts.isBlock(dependency) && dependency.statements.length) {
256
- const { statements } = dependency;
257
- start = document.positionAt(statements[0].getStart(result.sourceFile));
258
- end = document.positionAt(statements[statements.length - 1].getEnd());
259
- }
260
- const sourceRange = (0, language_service_1.getSourceRange)(docs, { start, end });
261
- if (sourceRange) {
262
- dependencies.push(sourceRange);
263
- }
264
- }
265
- for (const subscriber of result.subscribers) {
266
- if (!subscriber.sideEffectInfo) {
267
- continue;
268
- }
269
- let start = document.positionAt(subscriber.sideEffectInfo.handler.getStart(result.sourceFile));
270
- let end = document.positionAt(subscriber.sideEffectInfo.handler.getEnd());
271
- if (ts.isBlock(subscriber.sideEffectInfo.handler) && subscriber.sideEffectInfo.handler.statements.length) {
272
- const { statements } = subscriber.sideEffectInfo.handler;
273
- start = document.positionAt(statements[0].getStart(result.sourceFile));
274
- end = document.positionAt(statements[statements.length - 1].getEnd());
275
- }
276
- const sourceRange = (0, language_service_1.getSourceRange)(docs, { start, end });
277
- if (sourceRange) {
278
- subscribers.push(sourceRange);
279
- }
280
- }
281
- }
282
- else {
283
- for (const dependency of result.dependencies) {
284
- let start = document.positionAt(dependency.getStart(result.sourceFile));
285
- let end = document.positionAt(dependency.getEnd());
286
- if (ts.isBlock(dependency) && dependency.statements.length) {
287
- const { statements } = dependency;
288
- start = document.positionAt(statements[0].getStart(result.sourceFile));
289
- end = document.positionAt(statements[statements.length - 1].getEnd());
290
- }
291
- dependencies.push({ start, end });
292
- }
293
- for (const subscriber of result.subscribers) {
294
- if (!subscriber.sideEffectInfo) {
295
- continue;
296
- }
297
- let start = document.positionAt(subscriber.sideEffectInfo.handler.getStart(result.sourceFile));
298
- let end = document.positionAt(subscriber.sideEffectInfo.handler.getEnd());
299
- if (ts.isBlock(subscriber.sideEffectInfo.handler) && subscriber.sideEffectInfo.handler.statements.length) {
300
- const { statements } = subscriber.sideEffectInfo.handler;
301
- start = document.positionAt(statements[0].getStart(result.sourceFile));
302
- end = document.positionAt(statements[statements.length - 1].getEnd());
303
- }
304
- subscribers.push({ start, end });
305
- }
306
- }
307
- return {
308
- subscribers,
309
- dependencies,
310
- };
311
- });
312
161
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/language-server",
3
- "version": "3.0.7-alpha.1",
3
+ "version": "3.0.8",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "**/*.js",
@@ -17,9 +17,9 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@volar/language-server": "2.4.23",
20
- "@vue/language-core": "3.0.7-alpha.1",
21
- "@vue/language-service": "3.0.7-alpha.1",
22
- "@vue/typescript-plugin": "3.0.7-alpha.1",
20
+ "@vue/language-core": "3.0.8",
21
+ "@vue/language-service": "3.0.8",
22
+ "@vue/typescript-plugin": "3.0.8",
23
23
  "vscode-uri": "^3.0.8"
24
24
  },
25
25
  "peerDependencies": {
@@ -29,5 +29,5 @@
29
29
  "@typescript/server-harness": "latest",
30
30
  "@volar/test-utils": "2.4.23"
31
31
  },
32
- "gitHead": "320fc626c871e9ff17c0e4e92ea7ddb0c7641f34"
32
+ "gitHead": "f7bdeaa7bb476df1fc8ff46c504d75c1869b0be9"
33
33
  }
@@ -1,27 +0,0 @@
1
- import type * as ts from 'typescript';
2
- declare const enum TrackKind {
3
- AccessDotValue = 0,
4
- AccessAnyValue = 1,
5
- Call = 2
6
- }
7
- interface SignalNode {
8
- bindingInfo?: {
9
- isRef: boolean;
10
- name: ts.BindingName;
11
- trackKinds: TrackKind[];
12
- };
13
- trackInfo?: {
14
- depsHandler: ts.Node;
15
- needToUse: boolean;
16
- };
17
- sideEffectInfo?: {
18
- isEffect: boolean;
19
- handler: ts.Node;
20
- };
21
- }
22
- export declare function analyze(ts: typeof import('typescript'), languageService: ts.LanguageService, fileName: string, position: number): {
23
- sourceFile: ts.SourceFile;
24
- subscribers: SignalNode[];
25
- dependencies: ts.Node[];
26
- } | undefined;
27
- export {};
@@ -1,460 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.analyze = analyze;
4
- const language_core_1 = require("@vue/language-core");
5
- function analyze(ts, languageService, fileName, position) {
6
- const sourceFile = languageService.getProgram().getSourceFile(fileName);
7
- const { signals, dotValueAccesses, dotAnyAccesses, functionCalls } = collect(ts, sourceFile);
8
- let signal = findSignalByNamePosition(position);
9
- if (!signal) {
10
- signal = findEffectByEffectHandlerPosition(position);
11
- if (signal?.bindingInfo) {
12
- position = signal.bindingInfo.name.getStart(sourceFile);
13
- }
14
- }
15
- if (!signal) {
16
- return;
17
- }
18
- const subscribers = signal.bindingInfo
19
- ? findSubscribers(signal.bindingInfo.name, signal.bindingInfo.trackKinds)
20
- : [];
21
- const dependencies = signal
22
- ? findDependencies(signal)
23
- : [];
24
- if ((!signal.sideEffectInfo?.isEffect && !subscribers.length)
25
- || (!signal.bindingInfo?.isRef && !dependencies.length)) {
26
- return;
27
- }
28
- return {
29
- sourceFile,
30
- subscribers: [...new Set(subscribers)],
31
- dependencies: [...new Set(dependencies)],
32
- };
33
- function findDependencies(signal, visited = new Set()) {
34
- if (visited.has(signal)) {
35
- return [];
36
- }
37
- visited.add(signal);
38
- const nodes = [];
39
- let hasRef = signal.bindingInfo?.isRef ?? false;
40
- if (signal.trackInfo) {
41
- const { needToUse } = signal.trackInfo;
42
- visit(signal.trackInfo.depsHandler, needToUse);
43
- signal.trackInfo.depsHandler.forEachChild(child => visit(child, needToUse));
44
- }
45
- if (!hasRef) {
46
- return [];
47
- }
48
- return nodes;
49
- function visit(node, needToUse, parentIsPropertyAccess = false) {
50
- if (!needToUse) {
51
- if (!parentIsPropertyAccess && ts.isIdentifier(node)) {
52
- const definition = languageService.getDefinitionAtPosition(fileName, node.getStart(sourceFile));
53
- for (const info of definition ?? []) {
54
- if (info.fileName !== fileName) {
55
- continue;
56
- }
57
- const signal = findSignalByNamePosition(info.textSpan.start);
58
- if (!signal) {
59
- continue;
60
- }
61
- if (signal.bindingInfo) {
62
- nodes.push(signal.bindingInfo.name);
63
- hasRef ||= signal.bindingInfo.isRef;
64
- }
65
- if (signal.sideEffectInfo) {
66
- nodes.push(signal.sideEffectInfo.handler);
67
- }
68
- const deps = findDependencies(signal, visited);
69
- nodes.push(...deps);
70
- hasRef ||= deps.length > 0;
71
- }
72
- }
73
- }
74
- else if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node) || ts.isCallExpression(node)) {
75
- const definition = languageService.getDefinitionAtPosition(fileName, node.expression.getStart(sourceFile));
76
- for (const info of definition ?? []) {
77
- if (info.fileName !== fileName) {
78
- continue;
79
- }
80
- const signal = findSignalByNamePosition(info.textSpan.start);
81
- if (!signal) {
82
- continue;
83
- }
84
- const oldSize = nodes.length;
85
- if (signal.bindingInfo) {
86
- for (const trackKind of signal.bindingInfo.trackKinds) {
87
- if (ts.isPropertyAccessExpression(node)) {
88
- if (trackKind === 0 /* TrackKind.AccessDotValue */ && node.name.text === 'value') {
89
- nodes.push(signal.bindingInfo.name);
90
- hasRef ||= signal.bindingInfo.isRef;
91
- }
92
- if (trackKind === 1 /* TrackKind.AccessAnyValue */ && node.name.text !== '') {
93
- nodes.push(signal.bindingInfo.name);
94
- hasRef ||= signal.bindingInfo.isRef;
95
- }
96
- }
97
- else if (ts.isElementAccessExpression(node)) {
98
- if (trackKind === 1 /* TrackKind.AccessAnyValue */) {
99
- nodes.push(signal.bindingInfo.name);
100
- hasRef ||= signal.bindingInfo.isRef;
101
- }
102
- }
103
- else if (ts.isCallExpression(node)) {
104
- if (trackKind === 2 /* TrackKind.Call */) {
105
- nodes.push(signal.bindingInfo.name);
106
- hasRef ||= signal.bindingInfo.isRef;
107
- }
108
- }
109
- }
110
- }
111
- const signalDetected = nodes.length > oldSize;
112
- if (signalDetected) {
113
- if (signal.sideEffectInfo) {
114
- nodes.push(signal.sideEffectInfo.handler);
115
- }
116
- const deps = findDependencies(signal, visited);
117
- nodes.push(...deps);
118
- hasRef ||= deps.length > 0;
119
- }
120
- }
121
- }
122
- node.forEachChild(child => visit(child, needToUse, ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)));
123
- }
124
- }
125
- function findSubscribers(refName, trackKinds, visited = new Set()) {
126
- return (0, language_core_1.collectBindingRanges)(ts, refName, sourceFile)
127
- .map(range => findSubscribersWorker(range, trackKinds, visited))
128
- .flat();
129
- }
130
- function findSubscribersWorker(refName, trackKinds, visited = new Set()) {
131
- if (visited.has(refName.start)) {
132
- return [];
133
- }
134
- visited.add(refName.start);
135
- const references = languageService.findReferences(fileName, refName.start);
136
- if (!references) {
137
- return [];
138
- }
139
- const result = [];
140
- for (const reference of references) {
141
- for (const reference2 of reference.references) {
142
- if (reference2.fileName !== fileName) {
143
- continue;
144
- }
145
- const effect = findEffectByDepsHandlerPosition(reference2.textSpan.start);
146
- if (effect?.trackInfo) {
147
- if (effect.trackInfo.needToUse) {
148
- let match = false;
149
- for (const trackKind of trackKinds) {
150
- if (trackKind === 1 /* TrackKind.AccessAnyValue */) {
151
- match = dotAnyAccesses.has(reference2.textSpan.start + reference2.textSpan.length);
152
- }
153
- else if (trackKind === 0 /* TrackKind.AccessDotValue */) {
154
- match = dotValueAccesses.has(reference2.textSpan.start + reference2.textSpan.length);
155
- }
156
- else if (trackKind === 2 /* TrackKind.Call */) {
157
- match = functionCalls.has(reference2.textSpan.start + reference2.textSpan.length);
158
- }
159
- if (match) {
160
- break;
161
- }
162
- }
163
- if (!match) {
164
- continue;
165
- }
166
- }
167
- let hasEffect = effect.sideEffectInfo?.isEffect;
168
- if (effect.bindingInfo) {
169
- const subs = findSubscribers(effect.bindingInfo.name, effect.bindingInfo.trackKinds, visited);
170
- result.push(...subs);
171
- hasEffect ||= subs.length > 0;
172
- }
173
- if (hasEffect) {
174
- result.push(effect);
175
- }
176
- }
177
- }
178
- }
179
- return result;
180
- }
181
- function findSignalByNamePosition(position) {
182
- return signals.find(ref => ref.bindingInfo && ref.bindingInfo.name.getStart(sourceFile) <= position
183
- && ref.bindingInfo.name.getEnd() >= position);
184
- }
185
- function findEffectByEffectHandlerPosition(position) {
186
- return signals.filter(ref => ref.sideEffectInfo && ref.sideEffectInfo.handler.getStart(sourceFile) <= position
187
- && ref.sideEffectInfo.handler.getEnd() >= position).sort((a, b) => a.sideEffectInfo.handler.getWidth(sourceFile) - b.sideEffectInfo.handler.getWidth(sourceFile))[0];
188
- }
189
- function findEffectByDepsHandlerPosition(position) {
190
- return signals.filter(ref => ref.trackInfo && ref.trackInfo.depsHandler.getStart(sourceFile) <= position
191
- && ref.trackInfo.depsHandler.getEnd() >= position).sort((a, b) => a.trackInfo.depsHandler.getWidth(sourceFile) - b.trackInfo.depsHandler.getWidth(sourceFile))[0];
192
- }
193
- }
194
- function collect(ts, sourceFile) {
195
- const signals = [];
196
- const dotValueAccesses = new Set();
197
- const dotAnyAccesses = new Set();
198
- const functionCalls = new Set();
199
- sourceFile.forEachChild(function visit(node) {
200
- if (ts.isVariableDeclaration(node)) {
201
- if (node.initializer && ts.isCallExpression(node.initializer)) {
202
- const call = node.initializer;
203
- if (ts.isIdentifier(call.expression)) {
204
- const callName = call.expression.escapedText;
205
- if (callName === 'ref' || callName === 'shallowRef' || callName === 'toRef' || callName === 'useTemplateRef'
206
- || callName === 'defineModel') {
207
- signals.push({
208
- bindingInfo: {
209
- isRef: true,
210
- name: node.name,
211
- trackKinds: [0 /* TrackKind.AccessDotValue */],
212
- },
213
- });
214
- }
215
- else if (callName === 'reactive' || callName === 'shallowReactive' || callName === 'defineProps'
216
- || callName === 'withDefaults') {
217
- signals.push({
218
- bindingInfo: {
219
- isRef: true,
220
- name: node.name,
221
- trackKinds: [1 /* TrackKind.AccessAnyValue */],
222
- },
223
- });
224
- }
225
- // TODO: toRefs
226
- }
227
- }
228
- }
229
- else if (ts.isFunctionDeclaration(node)) {
230
- if (node.name && node.body) {
231
- signals.push({
232
- bindingInfo: {
233
- isRef: false,
234
- name: node.name,
235
- trackKinds: [2 /* TrackKind.Call */],
236
- },
237
- trackInfo: {
238
- depsHandler: node.body,
239
- needToUse: true,
240
- },
241
- sideEffectInfo: {
242
- isEffect: false,
243
- handler: node.body,
244
- },
245
- });
246
- }
247
- }
248
- else if (ts.isVariableStatement(node)) {
249
- for (const declaration of node.declarationList.declarations) {
250
- const name = declaration.name;
251
- const callback = declaration.initializer;
252
- if (callback && ts.isIdentifier(name) && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback))) {
253
- signals.push({
254
- bindingInfo: {
255
- isRef: false,
256
- name: name,
257
- trackKinds: [2 /* TrackKind.Call */],
258
- },
259
- trackInfo: {
260
- depsHandler: callback,
261
- needToUse: true,
262
- },
263
- sideEffectInfo: {
264
- isEffect: false,
265
- handler: callback,
266
- },
267
- });
268
- }
269
- }
270
- }
271
- else if (ts.isParameter(node)) {
272
- if (node.type && ts.isTypeReferenceNode(node.type)) {
273
- const typeName = node.type.typeName.getText(sourceFile);
274
- if (typeName.endsWith('Ref')) {
275
- signals.push({
276
- bindingInfo: {
277
- isRef: true,
278
- name: node.name,
279
- trackKinds: [0 /* TrackKind.AccessDotValue */],
280
- },
281
- });
282
- }
283
- }
284
- }
285
- else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression)) {
286
- const call = node;
287
- const callName = node.expression.escapedText;
288
- if ((callName === 'effect' || callName === 'watchEffect') && call.arguments.length) {
289
- const callback = call.arguments[0];
290
- if (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) {
291
- signals.push({
292
- trackInfo: {
293
- depsHandler: callback.body,
294
- needToUse: true,
295
- },
296
- sideEffectInfo: {
297
- isEffect: true,
298
- handler: callback.body,
299
- },
300
- });
301
- }
302
- }
303
- if (callName === 'watch' && call.arguments.length >= 2) {
304
- const depsCallback = call.arguments[0];
305
- const effectCallback = call.arguments[1];
306
- if (ts.isArrowFunction(effectCallback) || ts.isFunctionExpression(effectCallback)) {
307
- if (ts.isArrowFunction(depsCallback) || ts.isFunctionExpression(depsCallback)) {
308
- signals.push({
309
- trackInfo: {
310
- depsHandler: depsCallback.body,
311
- needToUse: true,
312
- },
313
- sideEffectInfo: {
314
- isEffect: true,
315
- handler: effectCallback.body,
316
- },
317
- });
318
- }
319
- else {
320
- signals.push({
321
- trackInfo: {
322
- depsHandler: depsCallback,
323
- needToUse: false,
324
- },
325
- sideEffectInfo: {
326
- isEffect: true,
327
- handler: effectCallback.body,
328
- },
329
- });
330
- }
331
- }
332
- }
333
- else if ((0, language_core_1.hyphenateAttr)(callName).startsWith('use-')) {
334
- signals.push({
335
- bindingInfo: ts.isVariableDeclaration(call.parent)
336
- ? {
337
- isRef: true,
338
- name: call.parent.name,
339
- trackKinds: [1 /* TrackKind.AccessAnyValue */, 2 /* TrackKind.Call */],
340
- }
341
- : undefined,
342
- trackInfo: {
343
- depsHandler: call,
344
- needToUse: false,
345
- },
346
- });
347
- }
348
- else if ((callName === 'computed' || (0, language_core_1.hyphenateAttr)(callName).endsWith('-computed')) && call.arguments.length) {
349
- const arg = call.arguments[0];
350
- if (ts.isArrowFunction(arg) || ts.isFunctionExpression(arg)) {
351
- signals.push({
352
- bindingInfo: ts.isVariableDeclaration(call.parent)
353
- ? {
354
- isRef: true,
355
- name: call.parent.name,
356
- trackKinds: [0 /* TrackKind.AccessDotValue */],
357
- }
358
- : undefined,
359
- trackInfo: {
360
- depsHandler: arg.body,
361
- needToUse: true,
362
- },
363
- sideEffectInfo: {
364
- isEffect: true,
365
- handler: arg.body,
366
- },
367
- });
368
- }
369
- else if (ts.isIdentifier(arg)) {
370
- signals.push({
371
- bindingInfo: ts.isVariableDeclaration(call.parent)
372
- ? {
373
- isRef: true,
374
- name: call.parent.name,
375
- trackKinds: [0 /* TrackKind.AccessDotValue */],
376
- }
377
- : undefined,
378
- trackInfo: {
379
- depsHandler: arg,
380
- needToUse: false,
381
- },
382
- });
383
- }
384
- else if (ts.isObjectLiteralExpression(arg)) {
385
- for (const prop of arg.properties) {
386
- if (prop.name?.getText(sourceFile) === 'get') {
387
- if (ts.isPropertyAssignment(prop)) {
388
- const callback = prop.initializer;
389
- if (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) {
390
- signals.push({
391
- bindingInfo: ts.isVariableDeclaration(call.parent)
392
- ? {
393
- isRef: true,
394
- name: call.parent.name,
395
- trackKinds: [0 /* TrackKind.AccessDotValue */],
396
- }
397
- : undefined,
398
- trackInfo: {
399
- depsHandler: callback.body,
400
- needToUse: true,
401
- },
402
- sideEffectInfo: {
403
- isEffect: true,
404
- handler: callback.body,
405
- },
406
- });
407
- }
408
- }
409
- else if (ts.isMethodDeclaration(prop) && prop.body) {
410
- signals.push({
411
- bindingInfo: ts.isVariableDeclaration(call.parent)
412
- ? {
413
- isRef: true,
414
- name: call.parent.name,
415
- trackKinds: [0 /* TrackKind.AccessDotValue */],
416
- }
417
- : undefined,
418
- trackInfo: {
419
- depsHandler: prop.body,
420
- needToUse: true,
421
- },
422
- sideEffectInfo: {
423
- isEffect: true,
424
- handler: prop.body,
425
- },
426
- });
427
- }
428
- }
429
- }
430
- }
431
- }
432
- }
433
- node.forEachChild(visit);
434
- });
435
- sourceFile.forEachChild(function visit(node) {
436
- if (ts.isPropertyAccessExpression(node)) {
437
- if (node.name.text === 'value') {
438
- dotValueAccesses.add(node.expression.getEnd());
439
- dotAnyAccesses.add(node.expression.getEnd());
440
- }
441
- else if (node.name.text !== '') {
442
- dotAnyAccesses.add(node.expression.getEnd());
443
- }
444
- }
445
- else if (ts.isElementAccessExpression(node)) {
446
- dotAnyAccesses.add(node.expression.getEnd());
447
- }
448
- else if (ts.isCallExpression(node)) {
449
- functionCalls.add(node.expression.getEnd());
450
- }
451
- node.forEachChild(visit);
452
- });
453
- return {
454
- signals,
455
- dotValueAccesses,
456
- dotAnyAccesses,
457
- functionCalls,
458
- };
459
- }
460
- //# sourceMappingURL=reactivityAnalyze.js.map
@@ -1,5 +0,0 @@
1
- import type * as ts from 'typescript';
2
- export declare function getLanguageService(ts: typeof import('typescript'), snapshot: ts.IScriptSnapshot, languageId: string): {
3
- languageService: ts.LanguageService;
4
- fileName: string;
5
- };
@@ -1,40 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLanguageService = getLanguageService;
4
- let currentProjectVersion = -1;
5
- let currentFileName = '';
6
- let currentSnapshot;
7
- let languageService;
8
- const host = {
9
- getProjectVersion: () => currentProjectVersion.toString(),
10
- getScriptFileNames: () => [currentFileName],
11
- getScriptVersion: () => currentProjectVersion.toString(),
12
- getScriptSnapshot: fileName => fileName === currentFileName ? currentSnapshot : undefined,
13
- getCompilationSettings: () => ({
14
- allowJs: true,
15
- }),
16
- getCurrentDirectory: () => '',
17
- getDefaultLibFileName: () => '',
18
- readFile: () => undefined,
19
- fileExists: fileName => fileName === currentFileName,
20
- };
21
- // TODO: share with volar-service-typescript
22
- function getLanguageService(ts, snapshot, languageId) {
23
- if (currentSnapshot !== snapshot) {
24
- currentSnapshot = snapshot;
25
- currentFileName = '/tmp.' + (languageId === 'javascript'
26
- ? 'js'
27
- : languageId === 'typescriptreact'
28
- ? 'tsx'
29
- : languageId === 'javascriptreact'
30
- ? 'jsx'
31
- : 'ts');
32
- currentProjectVersion++;
33
- }
34
- languageService ??= ts.createLanguageService(host);
35
- return {
36
- languageService,
37
- fileName: currentFileName,
38
- };
39
- }
40
- //# sourceMappingURL=reactivityAnalyzeLS.js.map