vue-component-meta 1.0.21 → 1.0.24
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 +2 -2
- package/out/index.js +83 -62
- package/out/types.d.ts +5 -5
- package/package.json +4 -4
package/out/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as vue from '@volar/vue-language-core';
|
|
2
2
|
import type * as ts from 'typescript/lib/tsserverlibrary';
|
|
3
|
-
import type { MetaCheckerOptions, ComponentMeta
|
|
4
|
-
export
|
|
3
|
+
import type { MetaCheckerOptions, ComponentMeta } from './types';
|
|
4
|
+
export * from './types';
|
|
5
5
|
export type ComponentMetaChecker = ReturnType<typeof baseCreate>;
|
|
6
6
|
export declare function createComponentMetaCheckerByJsonConfig(root: string, json: any, checkerOptions?: MetaCheckerOptions, ts?: typeof import('typescript/lib/tsserverlibrary')): {
|
|
7
7
|
updateFile(fileName: string, text: string): void;
|
package/out/index.js
CHANGED
|
@@ -1,8 +1,23 @@
|
|
|
1
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
2
|
+
if (k2 === undefined) k2 = k;
|
|
3
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
4
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
5
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
6
|
+
}
|
|
7
|
+
Object.defineProperty(o, k2, desc);
|
|
8
|
+
}) : (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
o[k2] = m[k];
|
|
11
|
+
}));
|
|
12
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
13
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
14
|
+
};
|
|
1
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
16
|
exports.baseCreate = exports.createComponentMetaChecker = exports.createComponentMetaCheckerByJsonConfig = void 0;
|
|
3
17
|
const vue = require("@volar/vue-language-core");
|
|
4
18
|
const embedded = require("@volar/language-core");
|
|
5
19
|
const path = require("typesafe-path/posix");
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
6
21
|
const extraFileExtensions = [{
|
|
7
22
|
extension: 'vue',
|
|
8
23
|
isMixedContent: true,
|
|
@@ -57,9 +72,6 @@ function createComponentMetaCheckerWorker(loadParsedCommandLine, checkerOptions,
|
|
|
57
72
|
} });
|
|
58
73
|
}
|
|
59
74
|
function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
60
|
-
/**
|
|
61
|
-
* Meta
|
|
62
|
-
*/
|
|
63
75
|
const globalComponentSnapshot = ts.ScriptSnapshot.fromString('<script setup lang="ts"></script>');
|
|
64
76
|
const metaSnapshots = {};
|
|
65
77
|
const host = new Proxy({
|
|
@@ -94,7 +106,8 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
|
94
106
|
return _host[prop];
|
|
95
107
|
},
|
|
96
108
|
});
|
|
97
|
-
const
|
|
109
|
+
const vueCompilerOptions = vue.resolveVueCompilerOptions(host.getVueCompilationSettings());
|
|
110
|
+
const vueLanguageModules = ts ? vue.createLanguageModules(ts, host.getCompilationSettings(), vueCompilerOptions) : [];
|
|
98
111
|
const core = embedded.createLanguageContext(host, vueLanguageModules);
|
|
99
112
|
const proxyApis = checkerOptions.forceUseTs ? {
|
|
100
113
|
getScriptKind: (fileName) => {
|
|
@@ -181,9 +194,9 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
|
181
194
|
// fill defaults
|
|
182
195
|
const printer = ts.createPrinter(checkerOptions.printer);
|
|
183
196
|
const snapshot = host.getScriptSnapshot(componentPath);
|
|
184
|
-
const vueSourceFile = (_a = core.virtualFiles.
|
|
197
|
+
const vueSourceFile = (_a = core.virtualFiles.getSource(componentPath)) === null || _a === void 0 ? void 0 : _a.root;
|
|
185
198
|
const vueDefaults = vueSourceFile && exportName === 'default'
|
|
186
|
-
? (vueSourceFile instanceof vue.VueFile ? readVueComponentDefaultProps(vueSourceFile, printer, ts) : {})
|
|
199
|
+
? (vueSourceFile instanceof vue.VueFile ? readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOptions) : {})
|
|
187
200
|
: {};
|
|
188
201
|
const tsDefaults = !vueSourceFile ? readTsComponentDefaultProps(componentPath.substring(componentPath.lastIndexOf('.') + 1), // ts | js | tsx | jsx
|
|
189
202
|
snapshot.getText(0, snapshot.getLength()), exportName, printer, ts) : {};
|
|
@@ -214,9 +227,7 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
|
214
227
|
return [];
|
|
215
228
|
}
|
|
216
229
|
function getSlots() {
|
|
217
|
-
|
|
218
|
-
const target = (_a = _host.getVueCompilationSettings().target) !== null && _a !== void 0 ? _a : 3;
|
|
219
|
-
const propertyName = target < 3 ? '$scopedSlots' : '$slots';
|
|
230
|
+
const propertyName = vueCompilerOptions.target < 3 ? '$scopedSlots' : '$slots';
|
|
220
231
|
const $slots = symbolProperties.find(prop => prop.escapedName === propertyName);
|
|
221
232
|
if ($slots) {
|
|
222
233
|
const type = typeChecker.getTypeOfSymbolAtLocation($slots, symbolNode);
|
|
@@ -272,139 +283,149 @@ function baseCreate(_host, checkerOptions, globalComponentName, ts) {
|
|
|
272
283
|
}
|
|
273
284
|
exports.baseCreate = baseCreate;
|
|
274
285
|
function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: options }, ts) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const ignore = typeof options === 'object' ? [...(_a = options === null || options === void 0 ? void 0 : options.ignore) !== null && _a !== void 0 ? _a : []] : [];
|
|
286
|
+
const visited = new Set();
|
|
287
|
+
;
|
|
278
288
|
function shouldIgnore(subtype) {
|
|
289
|
+
var _a;
|
|
279
290
|
const name = typeChecker.typeToString(subtype);
|
|
280
291
|
if (name === 'any') {
|
|
281
292
|
return true;
|
|
282
293
|
}
|
|
283
|
-
if (
|
|
284
|
-
return
|
|
294
|
+
if (visited.has(subtype)) {
|
|
295
|
+
return true;
|
|
285
296
|
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
297
|
+
if (typeof options === 'object') {
|
|
298
|
+
for (const item of (_a = options.ignore) !== null && _a !== void 0 ? _a : []) {
|
|
299
|
+
if (typeof item === 'function') {
|
|
300
|
+
const result = item(name, subtype, typeChecker);
|
|
301
|
+
if (typeof result === 'boolean')
|
|
302
|
+
return result;
|
|
303
|
+
}
|
|
304
|
+
else if (name === item) {
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
294
307
|
}
|
|
295
308
|
}
|
|
296
309
|
return false;
|
|
297
310
|
}
|
|
298
|
-
function setVisited(subtype) {
|
|
299
|
-
const type = typeChecker.typeToString(subtype);
|
|
300
|
-
ignore.push(type);
|
|
301
|
-
}
|
|
302
311
|
function reducer(acc, cur) {
|
|
303
312
|
acc[cur.name] = cur;
|
|
304
313
|
return acc;
|
|
305
314
|
}
|
|
306
315
|
function resolveNestedProperties(prop) {
|
|
307
316
|
const subtype = typeChecker.getTypeOfSymbolAtLocation(prop, symbolNode);
|
|
308
|
-
|
|
317
|
+
let schema;
|
|
309
318
|
return {
|
|
310
319
|
name: prop.getEscapedName().toString(),
|
|
311
320
|
global: false,
|
|
312
321
|
description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
|
|
313
|
-
tags: prop.getJsDocTags(typeChecker).map(tag => {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
text: (_a = tag.text) === null || _a === void 0 ? void 0 : _a.map(part => part.text).join(''),
|
|
318
|
-
});
|
|
319
|
-
}),
|
|
322
|
+
tags: prop.getJsDocTags(typeChecker).map(tag => ({
|
|
323
|
+
name: tag.name,
|
|
324
|
+
text: tag.text !== undefined ? ts.displayPartsToString(tag.text) : undefined,
|
|
325
|
+
})),
|
|
320
326
|
required: !(prop.flags & ts.SymbolFlags.Optional),
|
|
321
327
|
type: typeChecker.typeToString(subtype),
|
|
322
328
|
rawType: rawType ? subtype : undefined,
|
|
323
|
-
schema
|
|
329
|
+
get schema() {
|
|
330
|
+
return schema !== null && schema !== void 0 ? schema : (schema = resolveSchema(subtype));
|
|
331
|
+
},
|
|
324
332
|
};
|
|
325
333
|
}
|
|
326
334
|
function resolveSlotProperties(prop) {
|
|
327
335
|
const subtype = typeChecker.getTypeOfSymbolAtLocation(typeChecker.getTypeOfSymbolAtLocation(prop, symbolNode).getCallSignatures()[0].parameters[0], symbolNode);
|
|
328
|
-
|
|
336
|
+
let schema;
|
|
329
337
|
return {
|
|
330
338
|
name: prop.getName(),
|
|
331
339
|
type: typeChecker.typeToString(subtype),
|
|
332
340
|
rawType: rawType ? subtype : undefined,
|
|
333
341
|
description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
|
|
334
|
-
schema
|
|
342
|
+
get schema() {
|
|
343
|
+
return schema !== null && schema !== void 0 ? schema : (schema = resolveSchema(subtype));
|
|
344
|
+
},
|
|
335
345
|
};
|
|
336
346
|
}
|
|
337
347
|
function resolveExposedProperties(expose) {
|
|
338
348
|
const subtype = typeChecker.getTypeOfSymbolAtLocation(expose, symbolNode);
|
|
339
|
-
|
|
349
|
+
let schema;
|
|
340
350
|
return {
|
|
341
351
|
name: expose.getName(),
|
|
342
352
|
type: typeChecker.typeToString(subtype),
|
|
343
353
|
rawType: rawType ? subtype : undefined,
|
|
344
354
|
description: ts.displayPartsToString(expose.getDocumentationComment(typeChecker)),
|
|
345
|
-
schema
|
|
355
|
+
get schema() {
|
|
356
|
+
return schema !== null && schema !== void 0 ? schema : (schema = resolveSchema(subtype));
|
|
357
|
+
},
|
|
346
358
|
};
|
|
347
359
|
}
|
|
348
360
|
function resolveEventSignature(call) {
|
|
349
361
|
const subtype = typeChecker.getTypeOfSymbolAtLocation(call.parameters[1], symbolNode);
|
|
350
|
-
|
|
351
|
-
? typeChecker.getTypeArguments(subtype).map(resolveSchema)
|
|
352
|
-
: undefined;
|
|
362
|
+
let schema;
|
|
353
363
|
return {
|
|
354
364
|
name: typeChecker.getTypeOfSymbolAtLocation(call.parameters[0], symbolNode).value,
|
|
355
365
|
type: typeChecker.typeToString(subtype),
|
|
356
366
|
rawType: rawType ? subtype : undefined,
|
|
357
367
|
signature: typeChecker.signatureToString(call),
|
|
358
|
-
schema
|
|
368
|
+
get schema() {
|
|
369
|
+
return schema !== null && schema !== void 0 ? schema : (schema = typeChecker.getTypeArguments(subtype).map(resolveSchema));
|
|
370
|
+
},
|
|
359
371
|
};
|
|
360
372
|
}
|
|
361
373
|
function resolveCallbackSchema(signature) {
|
|
362
|
-
|
|
363
|
-
? typeChecker
|
|
364
|
-
.getTypeArguments(typeChecker.getTypeOfSymbolAtLocation(signature.parameters[0], symbolNode))
|
|
365
|
-
.map(resolveSchema)
|
|
366
|
-
: undefined;
|
|
374
|
+
let schema;
|
|
367
375
|
return {
|
|
368
376
|
kind: 'event',
|
|
369
377
|
type: typeChecker.signatureToString(signature),
|
|
370
|
-
schema
|
|
378
|
+
get schema() {
|
|
379
|
+
return schema !== null && schema !== void 0 ? schema : (schema = signature.parameters.length > 0
|
|
380
|
+
? typeChecker
|
|
381
|
+
.getTypeArguments(typeChecker.getTypeOfSymbolAtLocation(signature.parameters[0], symbolNode))
|
|
382
|
+
.map(resolveSchema)
|
|
383
|
+
: undefined);
|
|
384
|
+
},
|
|
371
385
|
};
|
|
372
386
|
}
|
|
373
387
|
function resolveSchema(subtype) {
|
|
374
388
|
const type = typeChecker.typeToString(subtype);
|
|
375
|
-
let schema = type;
|
|
376
389
|
if (shouldIgnore(subtype)) {
|
|
377
390
|
return type;
|
|
378
391
|
}
|
|
379
|
-
|
|
392
|
+
visited.add(subtype);
|
|
380
393
|
if (subtype.isUnion()) {
|
|
381
|
-
schema
|
|
394
|
+
let schema;
|
|
395
|
+
return {
|
|
382
396
|
kind: 'enum',
|
|
383
397
|
type,
|
|
384
|
-
schema
|
|
398
|
+
get schema() {
|
|
399
|
+
return schema !== null && schema !== void 0 ? schema : (schema = subtype.types.map(resolveSchema));
|
|
400
|
+
},
|
|
385
401
|
};
|
|
386
402
|
}
|
|
387
403
|
// @ts-ignore - typescript internal, isArrayLikeType exists
|
|
388
404
|
else if (typeChecker.isArrayLikeType(subtype)) {
|
|
389
|
-
schema
|
|
405
|
+
let schema;
|
|
406
|
+
return {
|
|
390
407
|
kind: 'array',
|
|
391
408
|
type,
|
|
392
|
-
schema
|
|
409
|
+
get schema() {
|
|
410
|
+
return schema !== null && schema !== void 0 ? schema : (schema = typeChecker.getTypeArguments(subtype).map(resolveSchema));
|
|
411
|
+
},
|
|
393
412
|
};
|
|
394
413
|
}
|
|
395
414
|
else if (subtype.getCallSignatures().length === 0 &&
|
|
396
415
|
(subtype.isClassOrInterface() || subtype.isIntersection() || subtype.objectFlags & ts.ObjectFlags.Anonymous)) {
|
|
397
|
-
|
|
398
|
-
|
|
416
|
+
let schema;
|
|
417
|
+
return {
|
|
399
418
|
kind: 'object',
|
|
400
419
|
type,
|
|
401
|
-
schema
|
|
420
|
+
get schema() {
|
|
421
|
+
return schema !== null && schema !== void 0 ? schema : (schema = subtype.getProperties().map(resolveNestedProperties).reduce(reducer, {}));
|
|
422
|
+
},
|
|
402
423
|
};
|
|
403
424
|
}
|
|
404
425
|
else if (subtype.getCallSignatures().length === 1) {
|
|
405
|
-
|
|
426
|
+
return resolveCallbackSchema(subtype.getCallSignatures()[0]);
|
|
406
427
|
}
|
|
407
|
-
return
|
|
428
|
+
return type;
|
|
408
429
|
}
|
|
409
430
|
return {
|
|
410
431
|
resolveNestedProperties,
|
|
@@ -414,7 +435,7 @@ function createSchemaResolvers(typeChecker, symbolNode, { rawType, schema: optio
|
|
|
414
435
|
resolveSchema,
|
|
415
436
|
};
|
|
416
437
|
}
|
|
417
|
-
function readVueComponentDefaultProps(vueSourceFile, printer, ts) {
|
|
438
|
+
function readVueComponentDefaultProps(vueSourceFile, printer, ts, vueCompilerOptions) {
|
|
418
439
|
let result = {};
|
|
419
440
|
scriptSetupWorker();
|
|
420
441
|
scriptWorker();
|
|
@@ -422,7 +443,7 @@ function readVueComponentDefaultProps(vueSourceFile, printer, ts) {
|
|
|
422
443
|
function scriptSetupWorker() {
|
|
423
444
|
var _a;
|
|
424
445
|
const descriptor = vueSourceFile.sfc;
|
|
425
|
-
const scriptSetupRanges = descriptor.scriptSetupAst ? vue.parseScriptSetupRanges(ts, descriptor.scriptSetupAst) : undefined;
|
|
446
|
+
const scriptSetupRanges = descriptor.scriptSetupAst ? vue.parseScriptSetupRanges(ts, descriptor.scriptSetupAst, vueCompilerOptions) : undefined;
|
|
426
447
|
if (descriptor.scriptSetup && (scriptSetupRanges === null || scriptSetupRanges === void 0 ? void 0 : scriptSetupRanges.withDefaultsArg)) {
|
|
427
448
|
const defaultsText = descriptor.scriptSetup.content.substring(scriptSetupRanges.withDefaultsArg.start, scriptSetupRanges.withDefaultsArg.end);
|
|
428
449
|
const ast = ts.createSourceFile('/tmp.' + descriptor.scriptSetup.lang, '(' + defaultsText + ')', ts.ScriptTarget.Latest);
|
package/out/types.d.ts
CHANGED
|
@@ -17,28 +17,28 @@ export interface PropertyMeta {
|
|
|
17
17
|
name: string;
|
|
18
18
|
text?: string;
|
|
19
19
|
}[];
|
|
20
|
-
schema
|
|
20
|
+
schema: PropertyMetaSchema;
|
|
21
21
|
}
|
|
22
22
|
export interface EventMeta {
|
|
23
23
|
name: string;
|
|
24
24
|
type: string;
|
|
25
25
|
rawType?: ts.Type;
|
|
26
26
|
signature: string;
|
|
27
|
-
schema
|
|
27
|
+
schema: PropertyMetaSchema[];
|
|
28
28
|
}
|
|
29
29
|
export interface SlotMeta {
|
|
30
30
|
name: string;
|
|
31
31
|
type: string;
|
|
32
32
|
rawType?: ts.Type;
|
|
33
33
|
description: string;
|
|
34
|
-
schema
|
|
34
|
+
schema: PropertyMetaSchema;
|
|
35
35
|
}
|
|
36
36
|
export interface ExposeMeta {
|
|
37
37
|
name: string;
|
|
38
38
|
description: string;
|
|
39
39
|
type: string;
|
|
40
40
|
rawType?: ts.Type;
|
|
41
|
-
schema
|
|
41
|
+
schema: PropertyMetaSchema;
|
|
42
42
|
}
|
|
43
43
|
export type PropertyMetaSchema = string | {
|
|
44
44
|
kind: 'enum';
|
|
@@ -67,6 +67,6 @@ export type MetaCheckerSchemaOptions = boolean | {
|
|
|
67
67
|
export interface MetaCheckerOptions {
|
|
68
68
|
schema?: MetaCheckerSchemaOptions;
|
|
69
69
|
forceUseTs?: boolean;
|
|
70
|
-
printer?:
|
|
70
|
+
printer?: ts.PrinterOptions;
|
|
71
71
|
rawType?: boolean;
|
|
72
72
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-component-meta",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.24",
|
|
4
4
|
"main": "out/index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -13,12 +13,12 @@
|
|
|
13
13
|
"directory": "vue-language-tools/vue-component-meta"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/language-core": "1.0.
|
|
17
|
-
"@volar/vue-language-core": "1.0.
|
|
16
|
+
"@volar/language-core": "1.0.24",
|
|
17
|
+
"@volar/vue-language-core": "1.0.24",
|
|
18
18
|
"typesafe-path": "^0.2.2"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
21
|
"typescript": "*"
|
|
22
22
|
},
|
|
23
|
-
"gitHead": "
|
|
23
|
+
"gitHead": "46da609e8914e29642f4707dec31507ad51b03fc"
|
|
24
24
|
}
|