@vue/typescript-plugin 3.1.2 → 3.1.4

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
@@ -108,12 +108,12 @@ module.exports = (0, createLanguageServicePlugin_1.createLanguageServicePlugin)(
108
108
  session.addProtocolHandler('_vue:getElementAttrs', request => {
109
109
  const [fileName, tag] = request.arguments;
110
110
  const { project } = getProject(fileName);
111
- return createResponse((0, getElementAttrs_1.getElementAttrs)(ts, project.getLanguageService().getProgram(), fileName, tag));
111
+ return createResponse((0, getElementAttrs_1.getElementAttrs)(ts, project.getLanguageService().getProgram(), tag));
112
112
  });
113
113
  session.addProtocolHandler('_vue:getElementNames', request => {
114
114
  const [fileName] = request.arguments;
115
115
  const { project } = getProject(fileName);
116
- return createResponse((0, getElementNames_1.getElementNames)(ts, project.getLanguageService().getProgram(), fileName));
116
+ return createResponse((0, getElementNames_1.getElementNames)(ts, project.getLanguageService().getProgram()));
117
117
  });
118
118
  projectService.logger.info('Vue specific commands are successfully added.');
119
119
  function createResponse(res) {
package/lib/common.js CHANGED
@@ -15,7 +15,7 @@ function createVueLanguageServiceProxy(ts, language, languageService, vueOptions
15
15
  case 'getCodeFixesAtPosition':
16
16
  return getCodeFixesAtPosition(target[p]);
17
17
  case 'getDefinitionAndBoundSpan':
18
- return getDefinitionAndBoundSpan(ts, language, asScriptId, languageService, vueOptions, target[p]);
18
+ return getDefinitionAndBoundSpan(ts, language, asScriptId, target[p]);
19
19
  }
20
20
  };
21
21
  return new Proxy(languageService, {
@@ -151,84 +151,56 @@ function getCodeFixesAtPosition(getCodeFixesAtPosition) {
151
151
  return result;
152
152
  };
153
153
  }
154
- function getDefinitionAndBoundSpan(ts, language, asScriptId, languageService, vueOptions, getDefinitionAndBoundSpan) {
154
+ function getDefinitionAndBoundSpan(ts, language, asScriptId, getDefinitionAndBoundSpan) {
155
155
  return (fileName, position) => {
156
156
  const result = getDefinitionAndBoundSpan(fileName, position);
157
- if (!result?.definitions?.length) {
158
- return result;
159
- }
160
- const program = languageService.getProgram();
161
157
  const sourceScript = language.scripts.get(asScriptId(fileName));
162
- if (!sourceScript?.generated) {
163
- return result;
164
- }
165
- const root = sourceScript.generated.root;
158
+ const root = sourceScript?.generated?.root;
166
159
  if (!(root instanceof language_core_1.VueVirtualCode)) {
167
160
  return result;
168
161
  }
162
+ if (!result?.definitions?.length) {
163
+ const { template } = root.sfc;
164
+ if (template) {
165
+ const textSpan = {
166
+ start: template.start + 1,
167
+ length: 'template'.length,
168
+ };
169
+ if (position >= textSpan.start && position <= textSpan.start + textSpan.length) {
170
+ return {
171
+ textSpan,
172
+ definitions: [{
173
+ fileName,
174
+ textSpan,
175
+ kind: ts.ScriptElementKind.scriptElement,
176
+ name: fileName,
177
+ containerKind: ts.ScriptElementKind.unknown,
178
+ containerName: '',
179
+ }],
180
+ };
181
+ }
182
+ }
183
+ return;
184
+ }
169
185
  if (!root.sfc.template
170
186
  || position < root.sfc.template.startTagEnd
171
187
  || position > root.sfc.template.endTagStart) {
172
188
  return result;
173
189
  }
174
190
  const definitions = new Set(result.definitions);
175
- const skippedDefinitions = [];
176
191
  // #5275
177
192
  if (result.definitions.length >= 2) {
178
193
  for (const definition of result.definitions) {
179
194
  if (root.sfc.content[definition.textSpan.start - 1] === '@'
180
195
  || root.sfc.content.slice(definition.textSpan.start - 5, definition.textSpan.start) === 'v-on:') {
181
- skippedDefinitions.push(definition);
196
+ definitions.delete(definition);
182
197
  }
183
198
  }
184
199
  }
185
- for (const definition of result.definitions) {
186
- if (vueOptions.extensions.some(ext => definition.fileName.endsWith(ext))) {
187
- continue;
188
- }
189
- const sourceFile = program.getSourceFile(definition.fileName);
190
- if (!sourceFile) {
191
- continue;
192
- }
193
- visit(sourceFile, definition, sourceFile);
194
- }
195
- for (const definition of skippedDefinitions) {
196
- definitions.delete(definition);
197
- }
198
200
  return {
199
201
  definitions: [...definitions],
200
202
  textSpan: result.textSpan,
201
203
  };
202
- function visit(node, definition, sourceFile) {
203
- if (ts.isPropertySignature(node) && node.type) {
204
- proxy(node.name, node.type, definition, sourceFile);
205
- }
206
- else if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.type && !node.initializer) {
207
- proxy(node.name, node.type, definition, sourceFile);
208
- }
209
- else {
210
- ts.forEachChild(node, child => visit(child, definition, sourceFile));
211
- }
212
- }
213
- function proxy(name, type, definition, sourceFile) {
214
- const { textSpan, fileName } = definition;
215
- const start = name.getStart(sourceFile);
216
- const end = name.getEnd();
217
- if (start !== textSpan.start || end - start !== textSpan.length) {
218
- return;
219
- }
220
- if (!ts.isIndexedAccessTypeNode(type)) {
221
- return;
222
- }
223
- const pos = type.indexType.getStart(sourceFile);
224
- const res = getDefinitionAndBoundSpan(fileName, pos);
225
- if (res?.definitions?.length) {
226
- for (const definition of res.definitions) {
227
- definitions.add(definition);
228
- }
229
- skippedDefinitions.push(definition);
230
- }
231
- }
232
204
  };
233
205
  }
234
206
  //# sourceMappingURL=common.js.map
@@ -1,2 +1,2 @@
1
1
  import type * as ts from 'typescript';
2
- export declare function getElementAttrs(ts: typeof import('typescript'), program: ts.Program, fileName: string, tag: string): string[];
2
+ export declare function getElementAttrs(ts: typeof import('typescript'), program: ts.Program, tag: string): string[];
@@ -1,18 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getElementAttrs = getElementAttrs;
4
- const utils_1 = require("./utils");
5
- function getElementAttrs(ts, program, fileName, tag) {
4
+ function getElementAttrs(ts, program, tag) {
6
5
  const checker = program.getTypeChecker();
7
- const elements = (0, utils_1.getVariableType)(ts, program, fileName, '__VLS_elements');
6
+ const elements = checker.resolveName('__VLS_intrinsics', undefined, ts.SymbolFlags.Variable, false);
8
7
  if (!elements) {
9
8
  return [];
10
9
  }
11
- const elementType = elements.type.getProperty(tag);
10
+ const elementType = checker.getTypeOfSymbol(elements).getProperty(tag);
12
11
  if (!elementType) {
13
12
  return [];
14
13
  }
15
- const attrs = checker.getTypeOfSymbol(elementType).getProperties();
16
- return attrs.map(c => c.name);
14
+ return checker.getTypeOfSymbol(elementType).getProperties().map(c => c.name);
17
15
  }
18
16
  //# sourceMappingURL=getElementAttrs.js.map
@@ -1,2 +1,2 @@
1
1
  import type * as ts from 'typescript';
2
- export declare function getElementNames(ts: typeof import('typescript'), program: ts.Program, fileName: string): string[];
2
+ export declare function getElementNames(ts: typeof import('typescript'), program: ts.Program): string[];
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getElementNames = getElementNames;
4
- const utils_1 = require("./utils");
5
- function getElementNames(ts, program, fileName) {
6
- return (0, utils_1.getVariableType)(ts, program, fileName, '__VLS_elements')
7
- ?.type
8
- .getProperties()
9
- .map(c => c.name)
10
- ?? [];
4
+ function getElementNames(ts, program) {
5
+ const checker = program.getTypeChecker();
6
+ const elements = checker.resolveName('__VLS_intrinsics', undefined, ts.SymbolFlags.Variable, false);
7
+ if (!elements) {
8
+ return [];
9
+ }
10
+ return checker.getTypeOfSymbol(elements).getProperties().map(c => c.name);
11
11
  }
12
12
  //# sourceMappingURL=getElementNames.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vue/typescript-plugin",
3
- "version": "3.1.2",
3
+ "version": "3.1.4",
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.2",
17
+ "@vue/language-core": "3.1.4",
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": "77db3d889305e8c02740f4c14793bff0156ccdb8"
25
+ "gitHead": "9670176c727993d16f9224f48406077e20972353"
26
26
  }