@vue/typescript-plugin 3.1.0-alpha.0 → 3.1.0
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 +1 -9
- package/lib/requests/index.d.ts +0 -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
package/index.js
CHANGED
|
@@ -11,7 +11,6 @@ const getComponentSlots_1 = require("./lib/requests/getComponentSlots");
|
|
|
11
11
|
const getElementAttrs_1 = require("./lib/requests/getElementAttrs");
|
|
12
12
|
const getElementNames_1 = require("./lib/requests/getElementNames");
|
|
13
13
|
const getImportPathForFile_1 = require("./lib/requests/getImportPathForFile");
|
|
14
|
-
const getReactiveReferences_1 = require("./lib/requests/getReactiveReferences");
|
|
15
14
|
const isRefAtPosition_1 = require("./lib/requests/isRefAtPosition");
|
|
16
15
|
const windowsPathReg = /\\/g;
|
|
17
16
|
const project2Service = new WeakMap();
|
|
@@ -125,12 +124,6 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
|
|
|
125
124
|
const { languageService } = getLanguageService(fileName);
|
|
126
125
|
return createResponse((0, getElementNames_1.getElementNames)(ts, languageService.getProgram(), fileName));
|
|
127
126
|
});
|
|
128
|
-
session.addProtocolHandler('_vue:getReactiveReferences', request => {
|
|
129
|
-
const [fileName, position] = request.arguments;
|
|
130
|
-
const { languageService, language } = getLanguageService(fileName);
|
|
131
|
-
const sourceScript = language.scripts.get(fileName);
|
|
132
|
-
return createResponse((0, getReactiveReferences_1.getReactiveReferences)(ts, language, languageService, sourceScript, fileName, position, sourceScript?.generated ? sourceScript.snapshot.getLength() : 0));
|
|
133
|
-
});
|
|
134
127
|
projectService.logger.info('Vue specific commands are successfully added.');
|
|
135
128
|
function createResponse(res) {
|
|
136
129
|
return {
|
|
@@ -155,8 +148,7 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
|
|
|
155
148
|
};
|
|
156
149
|
}
|
|
157
150
|
function getLanguageService(fileName) {
|
|
158
|
-
|
|
159
|
-
const { project } = session.getFileAndProject({
|
|
151
|
+
const { project } = session['getFileAndProject']({
|
|
160
152
|
file: fileName,
|
|
161
153
|
projectFileName: undefined,
|
|
162
154
|
});
|
package/lib/requests/index.d.ts
CHANGED
|
@@ -11,7 +11,6 @@ export interface Requests {
|
|
|
11
11
|
getComponentSlots(fileName: string): Response<ReturnType<typeof import('./getComponentSlots.js')['getComponentSlots']>>;
|
|
12
12
|
getElementAttrs(fileName: string, tag: string): Response<ReturnType<typeof import('./getElementAttrs.js')['getElementAttrs']>>;
|
|
13
13
|
getElementNames(fileName: string): Response<ReturnType<typeof import('./getElementNames.js')['getElementNames']>>;
|
|
14
|
-
getReactiveReferences(fileName: string, position: number): Response<ReturnType<typeof import('./getReactiveReferences.js')['getReactiveReferences']>>;
|
|
15
14
|
getDocumentHighlights(fileName: string, position: number): Response<ts.DocumentHighlights[]>;
|
|
16
15
|
getEncodedSemanticClassifications(fileName: string, span: ts.TextSpan): Response<ts.Classifications>;
|
|
17
16
|
getQuickInfoAtPosition(fileName: string, position: ts.LineAndCharacter): Response<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue/typescript-plugin",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@volar/typescript": "2.4.23",
|
|
17
|
-
"@vue/language-core": "3.1.0
|
|
17
|
+
"@vue/language-core": "3.1.0",
|
|
18
18
|
"@vue/shared": "^3.5.0",
|
|
19
19
|
"path-browserify": "^1.0.1"
|
|
20
20
|
},
|
|
@@ -22,5 +22,5 @@
|
|
|
22
22
|
"@types/node": "^22.10.4",
|
|
23
23
|
"@types/path-browserify": "^1.0.1"
|
|
24
24
|
},
|
|
25
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "fa32cb67b68c4fd01a146c7e2a276ffa022df268"
|
|
26
26
|
}
|
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;
|
package/lib/proxy.js
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createVueLanguageServiceProxy = createVueLanguageServiceProxy;
|
|
4
|
-
const language_core_1 = require("@vue/language-core");
|
|
5
|
-
const shared_1 = require("@vue/shared");
|
|
6
|
-
const windowsPathReg = /\\/g;
|
|
7
|
-
function createVueLanguageServiceProxy(ts, language, languageService, vueOptions) {
|
|
8
|
-
const proxyCache = new Map();
|
|
9
|
-
const getProxyMethod = (target, p) => {
|
|
10
|
-
switch (p) {
|
|
11
|
-
case 'getCompletionsAtPosition':
|
|
12
|
-
return getCompletionsAtPosition(ts, language, vueOptions, target[p]);
|
|
13
|
-
case 'getCompletionEntryDetails':
|
|
14
|
-
return getCompletionEntryDetails(language, target[p]);
|
|
15
|
-
case 'getCodeFixesAtPosition':
|
|
16
|
-
return getCodeFixesAtPosition(target[p]);
|
|
17
|
-
case 'getDefinitionAndBoundSpan':
|
|
18
|
-
return getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, target[p]);
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
return new Proxy(languageService, {
|
|
22
|
-
get(target, p, receiver) {
|
|
23
|
-
if (!proxyCache.has(p)) {
|
|
24
|
-
proxyCache.set(p, getProxyMethod(target, p));
|
|
25
|
-
}
|
|
26
|
-
return proxyCache.get(p) ?? Reflect.get(target, p, receiver);
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function getCompletionsAtPosition(ts, language, vueOptions, getCompletionsAtPosition) {
|
|
31
|
-
return (filePath, position, options, formattingSettings) => {
|
|
32
|
-
const fileName = filePath.replace(windowsPathReg, '/');
|
|
33
|
-
const result = getCompletionsAtPosition(fileName, position, options, formattingSettings);
|
|
34
|
-
if (result) {
|
|
35
|
-
// filter __VLS_
|
|
36
|
-
result.entries = result.entries.filter(entry => !entry.name.includes('__VLS_')
|
|
37
|
-
&& !entry.labelDetails?.description?.includes('__VLS_'));
|
|
38
|
-
// filter global variables in template and styles
|
|
39
|
-
const sourceScript = language.scripts.get(fileName);
|
|
40
|
-
const root = sourceScript?.generated?.root;
|
|
41
|
-
if (root instanceof language_core_1.VueVirtualCode) {
|
|
42
|
-
const blocks = [
|
|
43
|
-
root.sfc.template,
|
|
44
|
-
...root.sfc.styles,
|
|
45
|
-
];
|
|
46
|
-
const ranges = blocks.filter(Boolean).map(block => [
|
|
47
|
-
block.startTagEnd,
|
|
48
|
-
block.endTagStart,
|
|
49
|
-
]);
|
|
50
|
-
if (ranges.some(([start, end]) => position >= start && position <= end)) {
|
|
51
|
-
const globalKinds = new Set(['var', 'function', 'module']);
|
|
52
|
-
const globalsOrKeywords = ts.Completions.SortText.GlobalsOrKeywords;
|
|
53
|
-
const sortTexts = new Set([
|
|
54
|
-
globalsOrKeywords,
|
|
55
|
-
'z' + globalsOrKeywords,
|
|
56
|
-
globalsOrKeywords + '1',
|
|
57
|
-
]);
|
|
58
|
-
result.entries = result.entries.filter(entry => !(entry.kind === 'const' && entry.name in vueOptions.macros) && (!globalKinds.has(entry.kind)
|
|
59
|
-
|| !sortTexts.has(entry.sortText)
|
|
60
|
-
|| (0, shared_1.isGloballyAllowed)(entry.name)));
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
// modify label
|
|
64
|
-
for (const item of result.entries) {
|
|
65
|
-
if (item.source) {
|
|
66
|
-
const originalName = item.name;
|
|
67
|
-
for (const vueExt of vueOptions.extensions) {
|
|
68
|
-
const suffix = (0, shared_1.capitalize)(vueExt.slice(1)); // .vue -> Vue
|
|
69
|
-
if (item.source.endsWith(vueExt) && item.name.endsWith(suffix)) {
|
|
70
|
-
item.name = (0, shared_1.capitalize)(item.name.slice(0, -suffix.length));
|
|
71
|
-
if (item.insertText) {
|
|
72
|
-
// #2286
|
|
73
|
-
item.insertText = item.insertText.replace(`${suffix}$1`, '$1');
|
|
74
|
-
}
|
|
75
|
-
if (item.data) {
|
|
76
|
-
// @ts-expect-error
|
|
77
|
-
item.data.__isComponentAutoImport = {
|
|
78
|
-
ext: vueExt,
|
|
79
|
-
suffix,
|
|
80
|
-
originalName,
|
|
81
|
-
newName: item.insertText,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (item.data) {
|
|
88
|
-
// @ts-expect-error
|
|
89
|
-
item.data.__isAutoImport = {
|
|
90
|
-
fileName,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
function getCompletionEntryDetails(language, getCompletionEntryDetails) {
|
|
100
|
-
return (...args) => {
|
|
101
|
-
const details = getCompletionEntryDetails(...args);
|
|
102
|
-
// modify import statement
|
|
103
|
-
// @ts-expect-error
|
|
104
|
-
if (args[6]?.__isComponentAutoImport) {
|
|
105
|
-
// @ts-expect-error
|
|
106
|
-
const { originalName, newName } = args[6].__isComponentAutoImport;
|
|
107
|
-
for (const codeAction of details?.codeActions ?? []) {
|
|
108
|
-
for (const change of codeAction.changes) {
|
|
109
|
-
for (const textChange of change.textChanges) {
|
|
110
|
-
textChange.newText = textChange.newText.replace('import ' + originalName + ' from ', 'import ' + newName + ' from ');
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
// @ts-expect-error
|
|
116
|
-
if (args[6]?.__isAutoImport) {
|
|
117
|
-
// @ts-expect-error
|
|
118
|
-
const { fileName } = args[6].__isAutoImport;
|
|
119
|
-
const sourceScript = language.scripts.get(fileName);
|
|
120
|
-
if (sourceScript?.generated?.root instanceof language_core_1.VueVirtualCode) {
|
|
121
|
-
const { sfc } = sourceScript.generated.root;
|
|
122
|
-
if (!sfc.script && !sfc.scriptSetup) {
|
|
123
|
-
for (const codeAction of details?.codeActions ?? []) {
|
|
124
|
-
for (const change of codeAction.changes) {
|
|
125
|
-
for (const textChange of change.textChanges) {
|
|
126
|
-
textChange.newText = `<script setup lang="ts">${textChange.newText}</script>\n\n`;
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
break;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return details;
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
function getCodeFixesAtPosition(getCodeFixesAtPosition) {
|
|
140
|
-
return (...args) => {
|
|
141
|
-
let result = getCodeFixesAtPosition(...args);
|
|
142
|
-
// filter __VLS_
|
|
143
|
-
result = result.filter(entry => !entry.description.includes('__VLS_'));
|
|
144
|
-
return result;
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
function getDefinitionAndBoundSpan(ts, language, languageService, vueOptions, getDefinitionAndBoundSpan) {
|
|
148
|
-
return (fileName, position) => {
|
|
149
|
-
const result = getDefinitionAndBoundSpan(fileName, position);
|
|
150
|
-
if (!result?.definitions?.length) {
|
|
151
|
-
return result;
|
|
152
|
-
}
|
|
153
|
-
const program = languageService.getProgram();
|
|
154
|
-
const sourceScript = language.scripts.get(fileName);
|
|
155
|
-
if (!sourceScript?.generated) {
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
|
-
const root = sourceScript.generated.root;
|
|
159
|
-
if (!(root instanceof language_core_1.VueVirtualCode)) {
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
if (!root.sfc.template
|
|
163
|
-
|| position < root.sfc.template.startTagEnd
|
|
164
|
-
|| position > root.sfc.template.endTagStart) {
|
|
165
|
-
return result;
|
|
166
|
-
}
|
|
167
|
-
const definitions = new Set(result.definitions);
|
|
168
|
-
const skippedDefinitions = [];
|
|
169
|
-
// #5275
|
|
170
|
-
if (result.definitions.length >= 2) {
|
|
171
|
-
for (const definition of result.definitions) {
|
|
172
|
-
if (root.sfc.content[definition.textSpan.start - 1] === '@'
|
|
173
|
-
|| root.sfc.content.slice(definition.textSpan.start - 5, definition.textSpan.start) === 'v-on:') {
|
|
174
|
-
skippedDefinitions.push(definition);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
for (const definition of result.definitions) {
|
|
179
|
-
if (vueOptions.extensions.some(ext => definition.fileName.endsWith(ext))) {
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
|
-
const sourceFile = program.getSourceFile(definition.fileName);
|
|
183
|
-
if (!sourceFile) {
|
|
184
|
-
continue;
|
|
185
|
-
}
|
|
186
|
-
visit(sourceFile, definition, sourceFile);
|
|
187
|
-
}
|
|
188
|
-
for (const definition of skippedDefinitions) {
|
|
189
|
-
definitions.delete(definition);
|
|
190
|
-
}
|
|
191
|
-
return {
|
|
192
|
-
definitions: [...definitions],
|
|
193
|
-
textSpan: result.textSpan,
|
|
194
|
-
};
|
|
195
|
-
function visit(node, definition, sourceFile) {
|
|
196
|
-
if (ts.isPropertySignature(node) && node.type) {
|
|
197
|
-
proxy(node.name, node.type, definition, sourceFile);
|
|
198
|
-
}
|
|
199
|
-
else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.type && !node.initializer) {
|
|
200
|
-
proxy(node.name, node.type, definition, sourceFile);
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
ts.forEachChild(node, child => visit(child, definition, sourceFile));
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
function proxy(name, type, definition, sourceFile) {
|
|
207
|
-
const { textSpan, fileName } = definition;
|
|
208
|
-
const start = name.getStart(sourceFile);
|
|
209
|
-
const end = name.getEnd();
|
|
210
|
-
if (start !== textSpan.start || end - start !== textSpan.length) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
if (!ts.isIndexedAccessTypeNode(type)) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const pos = type.indexType.getStart(sourceFile);
|
|
217
|
-
const res = getDefinitionAndBoundSpan(fileName, pos);
|
|
218
|
-
if (res?.definitions?.length) {
|
|
219
|
-
for (const definition of res.definitions) {
|
|
220
|
-
definitions.add(definition);
|
|
221
|
-
}
|
|
222
|
-
skippedDefinitions.push(definition);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
//# sourceMappingURL=proxy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefineSlots = getDefineSlots;
|
|
4
|
-
const language_core_1 = require("@vue/language-core");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
function getDefineSlots(fileName) {
|
|
7
|
-
const { typescript: ts, language, languageService, getFileId } = this;
|
|
8
|
-
const volarFile = language.scripts.get(getFileId(fileName));
|
|
9
|
-
if (!(volarFile?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const vueCode = volarFile.generated.root;
|
|
13
|
-
const slots = (0, utils_1.getTypeAliasType)(ts, languageService, vueCode, '__VLS_Slots');
|
|
14
|
-
return slots?.type.getProperties().map(prop => prop.getName());
|
|
15
|
-
}
|
|
16
|
-
//# sourceMappingURL=getDefineSlots.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 getMissingPropsDiagnostics(this: RequestContext, fileName: string): undefined;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getMissingPropsDiagnostics = getMissingPropsDiagnostics;
|
|
4
|
-
const language_core_1 = require("@vue/language-core");
|
|
5
|
-
function getMissingPropsDiagnostics(fileName) {
|
|
6
|
-
const { typescript: ts, language, languageService, asScriptId } = this;
|
|
7
|
-
const volarFile = language.scripts.get(asScriptId(fileName));
|
|
8
|
-
if (!(volarFile?.generated?.root instanceof language_core_1.VueVirtualCode)) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const vueCode = volarFile.generated.root;
|
|
12
|
-
const program = languageService.getProgram();
|
|
13
|
-
const sourceFile = program.getSourceFile(vueCode.fileName);
|
|
14
|
-
if (!sourceFile) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const checker = program.getTypeChecker();
|
|
18
|
-
ts.forEachChild(sourceFile, function visit(node) {
|
|
19
|
-
if (ts.isVariableDeclaration(node)
|
|
20
|
-
&& node.initializer
|
|
21
|
-
&& ts.isCallExpression(node.initializer)
|
|
22
|
-
&& ts.isIdentifier(node.initializer.expression)
|
|
23
|
-
&& /^__VLS_\d+$/.test(node.initializer.expression.text)) {
|
|
24
|
-
const firstArg = node.initializer.arguments[0];
|
|
25
|
-
const type = checker.getTypeAtLocation(firstArg);
|
|
26
|
-
const contextualType = checker.getContextualType(firstArg);
|
|
27
|
-
if (contextualType) {
|
|
28
|
-
const subtype = contextualType.isUnion()
|
|
29
|
-
? contextualType.types.find(subtype => checker.isTypeAssignableTo(subtype, type))
|
|
30
|
-
: contextualType;
|
|
31
|
-
void subtype;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
ts.forEachChild(node, visit);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
//# sourceMappingURL=getMissingPropsDiagnostics.js.map
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/// <reference types="@volar/typescript" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.getPropertiesAtLocation = getPropertiesAtLocation;
|
|
5
|
-
const language_core_1 = require("@vue/language-core");
|
|
6
|
-
function getPropertiesAtLocation(fileName, position) {
|
|
7
|
-
const { languageService, language, typescript: ts } = this;
|
|
8
|
-
// mapping
|
|
9
|
-
const sourceScript = language.scripts.get(fileName);
|
|
10
|
-
const root = sourceScript?.generated?.root;
|
|
11
|
-
if (!sourceScript?.generated || !(root instanceof language_core_1.VueVirtualCode)) {
|
|
12
|
-
return [];
|
|
13
|
-
}
|
|
14
|
-
const virtualScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(root);
|
|
15
|
-
if (!virtualScript) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
let mapped = false;
|
|
19
|
-
for (const [_sourceScript, map] of language.maps.forEach(virtualScript.code)) {
|
|
20
|
-
for (const [position2, mapping] of map.toGeneratedLocation(position)) {
|
|
21
|
-
if ((0, language_core_1.isCompletionEnabled)(mapping.data)) {
|
|
22
|
-
position = position2;
|
|
23
|
-
mapped = true;
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
if (mapped) {
|
|
28
|
-
break;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (!mapped) {
|
|
32
|
-
return [];
|
|
33
|
-
}
|
|
34
|
-
position += sourceScript.snapshot.getLength();
|
|
35
|
-
const program = languageService.getProgram();
|
|
36
|
-
const sourceFile = program.getSourceFile(fileName);
|
|
37
|
-
if (!sourceFile) {
|
|
38
|
-
return [];
|
|
39
|
-
}
|
|
40
|
-
const node = findPositionIdentifier(sourceFile, sourceFile, position);
|
|
41
|
-
if (!node) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
const checker = program.getTypeChecker();
|
|
45
|
-
const type = checker.getTypeAtLocation(node);
|
|
46
|
-
const props = type.getProperties();
|
|
47
|
-
return props.map(prop => prop.name);
|
|
48
|
-
function findPositionIdentifier(sourceFile, node, offset) {
|
|
49
|
-
let result;
|
|
50
|
-
node.forEachChild(child => {
|
|
51
|
-
if (!result) {
|
|
52
|
-
if (child.end === offset && ts.isIdentifier(child)) {
|
|
53
|
-
result = child;
|
|
54
|
-
}
|
|
55
|
-
else if (child.end >= offset && child.getStart(sourceFile) < offset) {
|
|
56
|
-
result = findPositionIdentifier(sourceFile, child, offset);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
return result;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=getPropertiesAtLocation.js.map
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { type Language, type SourceScript } from '@vue/language-core';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
|
-
export declare function getReactiveReferences(ts: typeof import('typescript'), language: Language, languageService: ts.LanguageService, sourceScript: SourceScript | undefined, fileName: string, position: number, leadingOffset?: number): {
|
|
4
|
-
dependencyRanges: {
|
|
5
|
-
start: number;
|
|
6
|
-
end: number;
|
|
7
|
-
}[];
|
|
8
|
-
dependentRanges: {
|
|
9
|
-
start: number;
|
|
10
|
-
end: number;
|
|
11
|
-
}[];
|
|
12
|
-
} | undefined;
|
|
@@ -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
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type Language, type SourceScript, type VueVirtualCode } from '@vue/language-core';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
|
-
export declare function isRefAtLocation(ts: typeof import('typescript'), language: Language, program: ts.Program, sourceScript: SourceScript, virtualCode: VueVirtualCode, position: number, isTsPlugin: boolean): boolean;
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/// <reference types="@volar/typescript" />
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.isRefAtLocation = isRefAtLocation;
|
|
5
|
-
const language_core_1 = require("@vue/language-core");
|
|
6
|
-
function isRefAtLocation(ts, language, program, sourceScript, virtualCode, position, isTsPlugin) {
|
|
7
|
-
const serviceScript = sourceScript.generated.languagePlugin.typescript?.getServiceScript(virtualCode);
|
|
8
|
-
if (!serviceScript) {
|
|
9
|
-
return false;
|
|
10
|
-
}
|
|
11
|
-
let mapped = false;
|
|
12
|
-
for (const [_sourceScript, map] of language.maps.forEach(serviceScript.code)) {
|
|
13
|
-
for (const [position2, mapping] of map.toGeneratedLocation(position)) {
|
|
14
|
-
if ((0, language_core_1.isCompletionEnabled)(mapping.data)) {
|
|
15
|
-
position = position2;
|
|
16
|
-
mapped = true;
|
|
17
|
-
break;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
if (mapped) {
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
if (!mapped) {
|
|
25
|
-
return false;
|
|
26
|
-
}
|
|
27
|
-
position += isTsPlugin ? sourceScript.snapshot.getLength() : 0;
|
|
28
|
-
const sourceFile = program.getSourceFile(virtualCode.fileName);
|
|
29
|
-
if (!sourceFile) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
const node = findPositionIdentifier(sourceFile, sourceFile, position);
|
|
33
|
-
if (!node) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
const checker = program.getTypeChecker();
|
|
37
|
-
const type = checker.getTypeAtLocation(node);
|
|
38
|
-
const props = type.getProperties();
|
|
39
|
-
return props.some(prop => prop.escapedName === 'value' && prop.flags & ts.SymbolFlags.Accessor);
|
|
40
|
-
function findPositionIdentifier(sourceFile, node, offset) {
|
|
41
|
-
let result;
|
|
42
|
-
node.forEachChild(child => {
|
|
43
|
-
if (!result) {
|
|
44
|
-
if (child.end === offset && ts.isIdentifier(child)) {
|
|
45
|
-
result = child;
|
|
46
|
-
}
|
|
47
|
-
else if (child.end >= offset && child.getStart(sourceFile) < offset) {
|
|
48
|
-
result = findPositionIdentifier(sourceFile, child, offset);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
//# sourceMappingURL=isRefAtLocation.js.map
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.resolveModuleName = resolveModuleName;
|
|
4
|
-
function resolveModuleName(fileName, moduleName) {
|
|
5
|
-
const { typescript: ts, languageServiceHost } = this;
|
|
6
|
-
const compilerOptions = languageServiceHost.getCompilationSettings();
|
|
7
|
-
const ext = moduleName.split('.').pop();
|
|
8
|
-
const result = ts.resolveModuleName(moduleName, fileName, {
|
|
9
|
-
...compilerOptions,
|
|
10
|
-
allowArbitraryExtensions: true,
|
|
11
|
-
}, {
|
|
12
|
-
fileExists(fileName) {
|
|
13
|
-
fileName = transformFileName(fileName, ext);
|
|
14
|
-
return languageServiceHost.fileExists(fileName);
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
const resolveFileName = result.resolvedModule?.resolvedFileName;
|
|
18
|
-
return {
|
|
19
|
-
name: resolveFileName ? transformFileName(resolveFileName, ext) : undefined,
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function transformFileName(fileName, ext) {
|
|
23
|
-
if (ext && fileName.endsWith(`.d.${ext}.ts`)) {
|
|
24
|
-
return fileName.slice(0, -`.d.${ext}.ts`.length) + `.${ext}`;
|
|
25
|
-
}
|
|
26
|
-
return fileName;
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=resolveModuleName.js.map
|
package/lib/requests/types.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Language } from '@vue/language-core';
|
|
2
|
-
import type * as ts from 'typescript';
|
|
3
|
-
export interface RequestContext {
|
|
4
|
-
typescript: typeof ts;
|
|
5
|
-
languageService: ts.LanguageService;
|
|
6
|
-
languageServiceHost: ts.LanguageServiceHost;
|
|
7
|
-
language: Language<string>;
|
|
8
|
-
}
|
package/lib/requests/types.js
DELETED