vue-component-meta 1.3.14 → 1.3.16
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/out/index.d.ts +1 -1
- package/out/index.js +95 -19
- package/out/types.d.ts +9 -0
- package/out/types.js +0 -1
- package/package.json +4 -4
package/out/index.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export declare function createComponentMetaChecker(tsconfigPath: string, checker
|
|
|
25
25
|
tsLs: ts.LanguageService;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
|
-
export declare function baseCreate(_host: vue.VueLanguageServiceHost, checkerOptions: MetaCheckerOptions, globalComponentName: string, ts: typeof import('typescript/lib/tsserverlibrary')): {
|
|
28
|
+
export declare function baseCreate(_host: vue.VueLanguageServiceHost, checkerOptions: MetaCheckerOptions, globalComponentName: string, ts: typeof import('typescript/lib/tsserverlibrary'), embeddedTypes: boolean): {
|
|
29
29
|
getExportNames: (componentPath: string) => string[];
|
|
30
30
|
getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
|
|
31
31
|
__internal__: {
|
package/out/index.js
CHANGED
|
@@ -16,7 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.baseCreate = exports.createComponentMetaChecker = exports.createComponentMetaCheckerByJsonConfig = void 0;
|
|
18
18
|
const vue = require("@volar/vue-language-core");
|
|
19
|
-
const
|
|
19
|
+
const language_core_1 = require("@volar/language-core");
|
|
20
20
|
const path = require("typesafe-path/posix");
|
|
21
21
|
__exportStar(require("./types"), exports);
|
|
22
22
|
const extraFileExtensions = [{
|
|
@@ -59,11 +59,10 @@ function createComponentMetaCheckerWorker(loadParsedCommandLine, checkerOptions,
|
|
|
59
59
|
}
|
|
60
60
|
return scriptSnapshots.get(fileName);
|
|
61
61
|
},
|
|
62
|
-
getTypeScriptModule: () => ts,
|
|
63
62
|
getVueCompilationSettings: () => parsedCommandLine.vueOptions,
|
|
64
63
|
};
|
|
65
64
|
return {
|
|
66
|
-
...baseCreate(_host, checkerOptions, globalComponentName, ts),
|
|
65
|
+
...baseCreate(_host, checkerOptions, globalComponentName, ts, false),
|
|
67
66
|
updateFile(fileName, text) {
|
|
68
67
|
fileName = fileName.replace(/\\/g, '/');
|
|
69
68
|
scriptSnapshots.set(fileName, ts.ScriptSnapshot.fromString(text));
|
|
@@ -87,7 +86,7 @@ function createComponentMetaCheckerWorker(loadParsedCommandLine, checkerOptions,
|
|
|
87
86
|
},
|
|
88
87
|
};
|
|
89
88
|
}
|
|
90
|
-
function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
89
|
+
function baseCreate(_host, checkerOptions, globalComponentName, ts, embeddedTypes) {
|
|
91
90
|
const globalComponentSnapshot = ts.ScriptSnapshot.fromString('<script setup lang="ts"></script>');
|
|
92
91
|
const metaSnapshots = {};
|
|
93
92
|
const host = new Proxy({
|
|
@@ -103,7 +102,7 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
|
103
102
|
getScriptSnapshot: fileName => {
|
|
104
103
|
if (isMetaFileName(fileName)) {
|
|
105
104
|
if (!metaSnapshots[fileName]) {
|
|
106
|
-
metaSnapshots[fileName] = ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName));
|
|
105
|
+
metaSnapshots[fileName] = ts.ScriptSnapshot.fromString(getMetaScriptContent(fileName, embeddedTypes));
|
|
107
106
|
}
|
|
108
107
|
return metaSnapshots[fileName];
|
|
109
108
|
}
|
|
@@ -124,7 +123,7 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
|
124
123
|
});
|
|
125
124
|
const vueCompilerOptions = vue.resolveVueCompilerOptions(host.getVueCompilationSettings());
|
|
126
125
|
const vueLanguageModules = ts ? vue.createLanguageModules(ts, host.getCompilationSettings(), vueCompilerOptions) : [];
|
|
127
|
-
const core =
|
|
126
|
+
const core = (0, language_core_1.createLanguageContext)(host, { typescript: ts }, vueLanguageModules);
|
|
128
127
|
const proxyApis = checkerOptions.forceUseTs ? {
|
|
129
128
|
getScriptKind: (fileName) => {
|
|
130
129
|
if (fileName.endsWith('.vue.js')) {
|
|
@@ -159,18 +158,50 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
|
159
158
|
function getMetaFileName(fileName) {
|
|
160
159
|
return (fileName.endsWith('.vue') ? fileName : fileName.substring(0, fileName.lastIndexOf('.'))) + '.meta.ts';
|
|
161
160
|
}
|
|
162
|
-
function getMetaScriptContent(fileName) {
|
|
163
|
-
|
|
161
|
+
function getMetaScriptContent(fileName, embeddedTypes) {
|
|
162
|
+
const importCode = embeddedTypes ? '' : `import('vue-component-type-helpers').`;
|
|
163
|
+
let code = `
|
|
164
164
|
import * as Components from '${fileName.substring(0, fileName.length - '.meta.ts'.length)}';
|
|
165
165
|
export default {} as { [K in keyof typeof Components]: ComponentMeta<typeof Components[K]>; };
|
|
166
166
|
|
|
167
167
|
interface ComponentMeta<T> {
|
|
168
|
-
props:
|
|
169
|
-
emit:
|
|
170
|
-
slots:
|
|
171
|
-
exposed:
|
|
172
|
-
};
|
|
173
|
-
|
|
168
|
+
props: ${importCode}ComponentProps<T>;
|
|
169
|
+
emit: ${importCode}ComponentEmit<T>;
|
|
170
|
+
slots: ${importCode}${vueCompilerOptions.target < 3 ? 'Vue2ComponentSlots' : 'ComponentSlots'}<T>;
|
|
171
|
+
exposed: ${importCode}ComponentExposed<T>;
|
|
172
|
+
};`.trim();
|
|
173
|
+
if (embeddedTypes) {
|
|
174
|
+
code += `
|
|
175
|
+
type ComponentProps<T> =
|
|
176
|
+
T extends (props: infer P, ...args: any) => any ? P :
|
|
177
|
+
T extends new () => { $props: infer P } ? NonNullable<P> :
|
|
178
|
+
{};
|
|
179
|
+
|
|
180
|
+
type ComponentSlots<T> =
|
|
181
|
+
T extends (props: any, ctx: { slots: infer S }, ...args: any) => any ? NonNullable<S> :
|
|
182
|
+
T extends new () => { $slots: infer S } ? NonNullable<S> :
|
|
183
|
+
{};
|
|
184
|
+
|
|
185
|
+
type ComponentEmit<T> =
|
|
186
|
+
T extends (props: any, ctx: { emit: infer E }, ...args: any) => any ? NonNullable<E> :
|
|
187
|
+
T extends new () => { $emit: infer E } ? NonNullable<E> :
|
|
188
|
+
{};
|
|
189
|
+
|
|
190
|
+
type ComponentExposed<T> =
|
|
191
|
+
T extends (props: any, ctx: { expose(exposed: infer E): any }, ...args: any) => any ? NonNullable<E> :
|
|
192
|
+
T extends new () => infer E ? E :
|
|
193
|
+
{};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Vue 2.x
|
|
197
|
+
*/
|
|
198
|
+
|
|
199
|
+
type Vue2ComponentSlots<T> =
|
|
200
|
+
T extends (props: any, ctx: { slots: infer S }, ...args: any) => any ? NonNullable<S> :
|
|
201
|
+
T extends new () => { $scopedSlots: infer S } ? NonNullable<S> :
|
|
202
|
+
{};`;
|
|
203
|
+
}
|
|
204
|
+
return code;
|
|
174
205
|
}
|
|
175
206
|
function getExportNames(componentPath) {
|
|
176
207
|
const program = tsLs.getProgram();
|
|
@@ -214,7 +245,7 @@ interface ComponentMeta<T> {
|
|
|
214
245
|
const properties = type.getProperties();
|
|
215
246
|
result = properties
|
|
216
247
|
.map((prop) => {
|
|
217
|
-
const { resolveNestedProperties, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts);
|
|
248
|
+
const { resolveNestedProperties, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts, core);
|
|
218
249
|
return resolveNestedProperties(prop);
|
|
219
250
|
})
|
|
220
251
|
.filter((prop) => !prop.name.match(propEventRegex));
|
|
@@ -258,7 +289,7 @@ interface ComponentMeta<T> {
|
|
|
258
289
|
const type = typeChecker.getTypeOfSymbolAtLocation($emit, symbolNode);
|
|
259
290
|
const calls = type.getCallSignatures();
|
|
260
291
|
return calls.map((call) => {
|
|
261
|
-
const { resolveEventSignature, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts);
|
|
292
|
+
const { resolveEventSignature, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts, core);
|
|
262
293
|
return resolveEventSignature(call);
|
|
263
294
|
}).filter(event => event.name);
|
|
264
295
|
}
|
|
@@ -270,7 +301,7 @@ interface ComponentMeta<T> {
|
|
|
270
301
|
const type = typeChecker.getTypeOfSymbolAtLocation($slots, symbolNode);
|
|
271
302
|
const properties = type.getProperties();
|
|
272
303
|
return properties.map((prop) => {
|
|
273
|
-
const { resolveSlotProperties, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts);
|
|
304
|
+
const { resolveSlotProperties, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts, core);
|
|
274
305
|
return resolveSlotProperties(prop);
|
|
275
306
|
});
|
|
276
307
|
}
|
|
@@ -284,7 +315,7 @@ interface ComponentMeta<T> {
|
|
|
284
315
|
// only exposed props will not have a valueDeclaration
|
|
285
316
|
!prop.valueDeclaration);
|
|
286
317
|
return properties.map((prop) => {
|
|
287
|
-
const { resolveExposedProperties, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts);
|
|
318
|
+
const { resolveExposedProperties, } = createSchemaResolvers(typeChecker, symbolNode, checkerOptions, ts, core);
|
|
288
319
|
return resolveExposedProperties(prop);
|
|
289
320
|
});
|
|
290
321
|
}
|
|
@@ -320,7 +351,7 @@ interface ComponentMeta<T> {
|
|
|
320
351
|
}
|
|
321
352
|
}
|
|
322
353
|
exports.baseCreate = baseCreate;
|
|
323
|
-
function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: options }, ts) {
|
|
354
|
+
function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: options, noDeclarations }, ts, core) {
|
|
324
355
|
const visited = new Set();
|
|
325
356
|
;
|
|
326
357
|
function shouldIgnore(subtype) {
|
|
@@ -352,6 +383,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
352
383
|
function resolveNestedProperties(prop) {
|
|
353
384
|
const subtype = typeChecker.getTypeOfSymbolAtLocation(prop, symbolNode);
|
|
354
385
|
let schema;
|
|
386
|
+
let declarations;
|
|
355
387
|
return {
|
|
356
388
|
name: prop.getEscapedName().toString(),
|
|
357
389
|
global: false,
|
|
@@ -363,6 +395,9 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
363
395
|
required: !(prop.flags & ts.SymbolFlags.Optional),
|
|
364
396
|
type: typeChecker.typeToString(subtype),
|
|
365
397
|
rawType: rawType ? subtype : undefined,
|
|
398
|
+
get declarations() {
|
|
399
|
+
return declarations ??= getDeclarations(prop.declarations ?? []);
|
|
400
|
+
},
|
|
366
401
|
get schema() {
|
|
367
402
|
return schema ??= resolveSchema(subtype);
|
|
368
403
|
},
|
|
@@ -374,11 +409,15 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
374
409
|
const paramType = signatures[0].parameters[0];
|
|
375
410
|
const subtype = typeChecker.getTypeOfSymbolAtLocation(paramType, symbolNode);
|
|
376
411
|
let schema;
|
|
412
|
+
let declarations;
|
|
377
413
|
return {
|
|
378
414
|
name: prop.getName(),
|
|
379
415
|
type: typeChecker.typeToString(subtype),
|
|
380
416
|
rawType: rawType ? subtype : undefined,
|
|
381
417
|
description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
|
|
418
|
+
get declarations() {
|
|
419
|
+
return declarations ??= getDeclarations(prop.declarations ?? []);
|
|
420
|
+
},
|
|
382
421
|
get schema() {
|
|
383
422
|
return schema ??= resolveSchema(subtype);
|
|
384
423
|
},
|
|
@@ -387,11 +426,15 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
387
426
|
function resolveExposedProperties(expose) {
|
|
388
427
|
const subtype = typeChecker.getTypeOfSymbolAtLocation(expose, symbolNode);
|
|
389
428
|
let schema;
|
|
429
|
+
let declarations;
|
|
390
430
|
return {
|
|
391
431
|
name: expose.getName(),
|
|
392
432
|
type: typeChecker.typeToString(subtype),
|
|
393
433
|
rawType: rawType ? subtype : undefined,
|
|
394
434
|
description: ts.displayPartsToString(expose.getDocumentationComment(typeChecker)),
|
|
435
|
+
get declarations() {
|
|
436
|
+
return declarations ??= getDeclarations(expose.declarations ?? []);
|
|
437
|
+
},
|
|
395
438
|
get schema() {
|
|
396
439
|
return schema ??= resolveSchema(subtype);
|
|
397
440
|
},
|
|
@@ -400,11 +443,15 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
400
443
|
function resolveEventSignature(call) {
|
|
401
444
|
const subtype = typeChecker.getTypeOfSymbolAtLocation(call.parameters[1], symbolNode);
|
|
402
445
|
let schema;
|
|
446
|
+
let declarations;
|
|
403
447
|
return {
|
|
404
448
|
name: typeChecker.getTypeOfSymbolAtLocation(call.parameters[0], symbolNode).value,
|
|
405
449
|
type: typeChecker.typeToString(subtype),
|
|
406
450
|
rawType: rawType ? subtype : undefined,
|
|
407
451
|
signature: typeChecker.signatureToString(call),
|
|
452
|
+
get declarations() {
|
|
453
|
+
return declarations ??= call.declaration ? getDeclarations([call.declaration]) : [];
|
|
454
|
+
},
|
|
408
455
|
get schema() {
|
|
409
456
|
return schema ??= typeChecker.getTypeArguments(subtype).map(resolveSchema);
|
|
410
457
|
},
|
|
@@ -467,6 +514,35 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
467
514
|
}
|
|
468
515
|
return type;
|
|
469
516
|
}
|
|
517
|
+
function getDeclarations(declaration) {
|
|
518
|
+
if (noDeclarations) {
|
|
519
|
+
return [];
|
|
520
|
+
}
|
|
521
|
+
return declaration.map(getDeclaration).filter(d => !!d);
|
|
522
|
+
}
|
|
523
|
+
function getDeclaration(declaration) {
|
|
524
|
+
const fileName = declaration.getSourceFile().fileName;
|
|
525
|
+
const [virtualFile] = core.virtualFiles.getVirtualFile(fileName);
|
|
526
|
+
if (virtualFile) {
|
|
527
|
+
const maps = core.virtualFiles.getMaps(virtualFile);
|
|
528
|
+
for (const [source, map] of maps) {
|
|
529
|
+
const start = map.toSourceOffset(declaration.getStart());
|
|
530
|
+
const end = map.toSourceOffset(declaration.getEnd());
|
|
531
|
+
if (start && end) {
|
|
532
|
+
return {
|
|
533
|
+
file: source,
|
|
534
|
+
range: [start[0], end[0]],
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
;
|
|
538
|
+
}
|
|
539
|
+
return undefined;
|
|
540
|
+
}
|
|
541
|
+
return {
|
|
542
|
+
file: declaration.getSourceFile().fileName,
|
|
543
|
+
range: [declaration.getStart(), declaration.getEnd()],
|
|
544
|
+
};
|
|
545
|
+
}
|
|
470
546
|
return {
|
|
471
547
|
resolveNestedProperties,
|
|
472
548
|
resolveSlotProperties,
|
package/out/types.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
2
|
+
export interface Declaration {
|
|
3
|
+
file: string;
|
|
4
|
+
range: [number, number];
|
|
5
|
+
}
|
|
2
6
|
export interface ComponentMeta {
|
|
3
7
|
props: PropertyMeta[];
|
|
4
8
|
events: EventMeta[];
|
|
@@ -17,6 +21,7 @@ export interface PropertyMeta {
|
|
|
17
21
|
name: string;
|
|
18
22
|
text?: string;
|
|
19
23
|
}[];
|
|
24
|
+
declarations: Declaration[];
|
|
20
25
|
schema: PropertyMetaSchema;
|
|
21
26
|
}
|
|
22
27
|
export interface EventMeta {
|
|
@@ -24,6 +29,7 @@ export interface EventMeta {
|
|
|
24
29
|
type: string;
|
|
25
30
|
rawType?: ts.Type;
|
|
26
31
|
signature: string;
|
|
32
|
+
declarations: Declaration[];
|
|
27
33
|
schema: PropertyMetaSchema[];
|
|
28
34
|
}
|
|
29
35
|
export interface SlotMeta {
|
|
@@ -31,6 +37,7 @@ export interface SlotMeta {
|
|
|
31
37
|
type: string;
|
|
32
38
|
rawType?: ts.Type;
|
|
33
39
|
description: string;
|
|
40
|
+
declarations: Declaration[];
|
|
34
41
|
schema: PropertyMetaSchema;
|
|
35
42
|
}
|
|
36
43
|
export interface ExposeMeta {
|
|
@@ -38,6 +45,7 @@ export interface ExposeMeta {
|
|
|
38
45
|
description: string;
|
|
39
46
|
type: string;
|
|
40
47
|
rawType?: ts.Type;
|
|
48
|
+
declarations: Declaration[];
|
|
41
49
|
schema: PropertyMetaSchema;
|
|
42
50
|
}
|
|
43
51
|
export type PropertyMetaSchema = string | {
|
|
@@ -69,4 +77,5 @@ export interface MetaCheckerOptions {
|
|
|
69
77
|
forceUseTs?: boolean;
|
|
70
78
|
printer?: ts.PrinterOptions;
|
|
71
79
|
rawType?: boolean;
|
|
80
|
+
noDeclarations?: boolean;
|
|
72
81
|
}
|
package/out/types.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-component-meta",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.16",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,13 +13,13 @@
|
|
|
13
13
|
"directory": "packages/vue-component-meta"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.4.0-alpha.
|
|
17
|
-
"@volar/vue-language-core": "1.3.
|
|
16
|
+
"@volar/language-core": "1.4.0-alpha.9",
|
|
17
|
+
"@volar/vue-language-core": "1.3.16",
|
|
18
18
|
"typesafe-path": "^0.2.2"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"typescript": "*",
|
|
22
22
|
"vue-component-type-helpers": "1.3.12"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "40066617609780f891a60eea1fc3c7c84cbc5505"
|
|
25
25
|
}
|