vue-component-meta 3.1.7 → 3.2.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.d.ts +3 -9
- package/index.js +49 -5
- package/lib/checker.d.ts +16 -0
- package/lib/checker.js +176 -0
- package/lib/componentMeta.d.ts +7 -0
- package/lib/componentMeta.js +192 -0
- package/lib/helpers.d.ts +6 -0
- package/lib/helpers.js +119 -0
- package/lib/schemaResolvers.d.ts +13 -0
- package/lib/schemaResolvers.js +344 -0
- package/lib/scriptSetup.d.ts +4 -0
- package/lib/scriptSetup.js +133 -0
- package/lib/types.d.ts +39 -9
- package/package.json +13 -9
- package/lib/base.d.ts +0 -33
- package/lib/base.js +0 -906
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSchemaResolvers = createSchemaResolvers;
|
|
4
|
+
const scriptSetup_1 = require("./scriptSetup");
|
|
5
|
+
const publicPropsInterfaces = new Set([
|
|
6
|
+
'PublicProps',
|
|
7
|
+
'VNodeProps',
|
|
8
|
+
'AllowedComponentProps',
|
|
9
|
+
'ComponentCustomProps',
|
|
10
|
+
]);
|
|
11
|
+
function createSchemaResolvers(ts, typeChecker, printer, language, options, deprecatedOptions) {
|
|
12
|
+
const visited = new Set();
|
|
13
|
+
function shouldIgnore(subtype) {
|
|
14
|
+
const name = getFullyQualifiedName(subtype);
|
|
15
|
+
if (name === 'any') {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (visited.has(subtype)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (options === false) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
if (typeof options === 'object') {
|
|
25
|
+
for (const item of options.ignore ?? []) {
|
|
26
|
+
if (typeof item === 'function') {
|
|
27
|
+
const result = item(name, subtype, typeChecker);
|
|
28
|
+
if (typeof result === 'boolean') {
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (name === item) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
function reducer(acc, cur) {
|
|
40
|
+
acc[cur.name] = cur;
|
|
41
|
+
return acc;
|
|
42
|
+
}
|
|
43
|
+
function getJsDocTags(target) {
|
|
44
|
+
return target.getJsDocTags(typeChecker).map(tag => ({
|
|
45
|
+
name: tag.name,
|
|
46
|
+
text: tag.text !== undefined ? ts.displayPartsToString(tag.text) : undefined,
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
function resolveNestedProperties(propSymbol) {
|
|
50
|
+
const subtype = typeChecker.getTypeOfSymbol(propSymbol);
|
|
51
|
+
let schema;
|
|
52
|
+
let declarations;
|
|
53
|
+
let global = false;
|
|
54
|
+
let _default;
|
|
55
|
+
let required = !(propSymbol.flags & ts.SymbolFlags.Optional);
|
|
56
|
+
for (const decl of propSymbol.declarations ?? []) {
|
|
57
|
+
if (isPublicProp(decl)) {
|
|
58
|
+
global = true;
|
|
59
|
+
}
|
|
60
|
+
if (ts.isPropertyAssignment(decl) && ts.isObjectLiteralExpression(decl.initializer)) {
|
|
61
|
+
for (const option of decl.initializer.properties) {
|
|
62
|
+
if (ts.isPropertyAssignment(option)) {
|
|
63
|
+
const key = option.name.getText();
|
|
64
|
+
if (key === 'default') {
|
|
65
|
+
const defaultExp = (0, scriptSetup_1.resolveDefaultOptionExpression)(ts, option.initializer);
|
|
66
|
+
_default = printer.printNode(ts.EmitHint.Expression, defaultExp, decl.getSourceFile());
|
|
67
|
+
}
|
|
68
|
+
else if (key === 'required') {
|
|
69
|
+
if (option.initializer.getText() === 'true') {
|
|
70
|
+
required = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
name: propSymbol.getEscapedName().toString(),
|
|
79
|
+
global,
|
|
80
|
+
default: _default,
|
|
81
|
+
description: ts.displayPartsToString(propSymbol.getDocumentationComment(typeChecker)),
|
|
82
|
+
tags: getJsDocTags(propSymbol),
|
|
83
|
+
required,
|
|
84
|
+
type: getFullyQualifiedName(subtype),
|
|
85
|
+
get schema() {
|
|
86
|
+
return schema ??= resolveSchema(subtype);
|
|
87
|
+
},
|
|
88
|
+
get declarations() {
|
|
89
|
+
if (deprecatedOptions.noDeclarations) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
return this.getDeclarations();
|
|
93
|
+
},
|
|
94
|
+
get rawType() {
|
|
95
|
+
if (deprecatedOptions.rawType) {
|
|
96
|
+
return this.getTypeObject();
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
getDeclarations() {
|
|
100
|
+
return declarations ??= getDeclarations(propSymbol.declarations ?? []);
|
|
101
|
+
},
|
|
102
|
+
getTypeObject() {
|
|
103
|
+
return subtype;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
function isPublicProp(declaration) {
|
|
108
|
+
let parent = declaration.parent;
|
|
109
|
+
while (parent) {
|
|
110
|
+
if (ts.isInterfaceDeclaration(parent) || ts.isTypeAliasDeclaration(parent)) {
|
|
111
|
+
if (publicPropsInterfaces.has(parent.name.text)) {
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
parent = parent.parent;
|
|
117
|
+
}
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
function resolveSlotProperties(prop) {
|
|
121
|
+
const propType = typeChecker.getNonNullableType(typeChecker.getTypeOfSymbol(prop));
|
|
122
|
+
const signatures = propType.getCallSignatures();
|
|
123
|
+
const paramType = signatures[0]?.parameters[0];
|
|
124
|
+
const subtype = paramType
|
|
125
|
+
? typeChecker.getTypeOfSymbol(paramType)
|
|
126
|
+
: typeChecker.getAnyType();
|
|
127
|
+
let schema;
|
|
128
|
+
let declarations;
|
|
129
|
+
return {
|
|
130
|
+
name: prop.getName(),
|
|
131
|
+
type: getFullyQualifiedName(subtype),
|
|
132
|
+
description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
|
|
133
|
+
tags: getJsDocTags(prop),
|
|
134
|
+
get schema() {
|
|
135
|
+
return schema ??= resolveSchema(subtype);
|
|
136
|
+
},
|
|
137
|
+
get declarations() {
|
|
138
|
+
if (deprecatedOptions.noDeclarations) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
return this.getDeclarations();
|
|
142
|
+
},
|
|
143
|
+
get rawType() {
|
|
144
|
+
if (deprecatedOptions.rawType) {
|
|
145
|
+
return this.getTypeObject();
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
getDeclarations() {
|
|
149
|
+
return declarations ??= getDeclarations(prop.declarations ?? []);
|
|
150
|
+
},
|
|
151
|
+
getTypeObject() {
|
|
152
|
+
return subtype;
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
function resolveExposedProperties(expose) {
|
|
157
|
+
const subtype = typeChecker.getTypeOfSymbol(expose);
|
|
158
|
+
let schema;
|
|
159
|
+
let declarations;
|
|
160
|
+
return {
|
|
161
|
+
name: expose.getName(),
|
|
162
|
+
type: getFullyQualifiedName(subtype),
|
|
163
|
+
description: ts.displayPartsToString(expose.getDocumentationComment(typeChecker)),
|
|
164
|
+
tags: getJsDocTags(expose),
|
|
165
|
+
get schema() {
|
|
166
|
+
return schema ??= resolveSchema(subtype);
|
|
167
|
+
},
|
|
168
|
+
get declarations() {
|
|
169
|
+
if (deprecatedOptions.noDeclarations) {
|
|
170
|
+
return [];
|
|
171
|
+
}
|
|
172
|
+
return this.getDeclarations();
|
|
173
|
+
},
|
|
174
|
+
get rawType() {
|
|
175
|
+
if (deprecatedOptions.rawType) {
|
|
176
|
+
return this.getTypeObject();
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
getDeclarations() {
|
|
180
|
+
return declarations ??= getDeclarations(expose.declarations ?? []);
|
|
181
|
+
},
|
|
182
|
+
getTypeObject() {
|
|
183
|
+
return subtype;
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function resolveEventSignature(call) {
|
|
188
|
+
let schema;
|
|
189
|
+
let declarations;
|
|
190
|
+
let subtype;
|
|
191
|
+
let symbol;
|
|
192
|
+
let subtypeStr = '[]';
|
|
193
|
+
let getSchema = () => [];
|
|
194
|
+
if (call.parameters.length >= 2) {
|
|
195
|
+
symbol = call.parameters[1];
|
|
196
|
+
subtype = typeChecker.getTypeOfSymbol(symbol);
|
|
197
|
+
if (call.parameters[1].valueDeclaration?.dotDotDotToken) {
|
|
198
|
+
subtypeStr = getFullyQualifiedName(subtype);
|
|
199
|
+
getSchema = () => typeChecker.getTypeArguments(subtype).map(resolveSchema);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
subtypeStr = '[';
|
|
203
|
+
for (let i = 1; i < call.parameters.length; i++) {
|
|
204
|
+
subtypeStr += getFullyQualifiedName(typeChecker.getTypeOfSymbol(call.parameters[i]))
|
|
205
|
+
+ ', ';
|
|
206
|
+
}
|
|
207
|
+
subtypeStr = subtypeStr.slice(0, -2) + ']';
|
|
208
|
+
getSchema = () => {
|
|
209
|
+
const result = [];
|
|
210
|
+
for (let i = 1; i < call.parameters.length; i++) {
|
|
211
|
+
result.push(resolveSchema(typeChecker.getTypeOfSymbol(call.parameters[i])));
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
name: typeChecker.getTypeOfSymbol(call.parameters[0]).value,
|
|
219
|
+
description: ts.displayPartsToString(call.getDocumentationComment(typeChecker)),
|
|
220
|
+
tags: getJsDocTags(call),
|
|
221
|
+
type: subtypeStr,
|
|
222
|
+
signature: typeChecker.signatureToString(call),
|
|
223
|
+
get schema() {
|
|
224
|
+
return schema ??= getSchema();
|
|
225
|
+
},
|
|
226
|
+
get declarations() {
|
|
227
|
+
if (deprecatedOptions.noDeclarations) {
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
return this.getDeclarations();
|
|
231
|
+
},
|
|
232
|
+
get rawType() {
|
|
233
|
+
if (deprecatedOptions.rawType) {
|
|
234
|
+
return this.getTypeObject();
|
|
235
|
+
}
|
|
236
|
+
},
|
|
237
|
+
getDeclarations() {
|
|
238
|
+
return declarations ??= call.declaration ? getDeclarations([call.declaration]) : [];
|
|
239
|
+
},
|
|
240
|
+
getTypeObject() {
|
|
241
|
+
return subtype;
|
|
242
|
+
},
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
function resolveCallbackSchema(signature) {
|
|
246
|
+
let schema;
|
|
247
|
+
return {
|
|
248
|
+
kind: 'event',
|
|
249
|
+
type: typeChecker.signatureToString(signature),
|
|
250
|
+
get schema() {
|
|
251
|
+
return schema ??= signature.parameters.length
|
|
252
|
+
? typeChecker
|
|
253
|
+
.getTypeArguments(typeChecker.getTypeOfSymbol(signature.parameters[0]))
|
|
254
|
+
.map(resolveSchema)
|
|
255
|
+
: undefined;
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
function resolveSchema(subtype) {
|
|
260
|
+
const type = getFullyQualifiedName(subtype);
|
|
261
|
+
if (shouldIgnore(subtype)) {
|
|
262
|
+
return type;
|
|
263
|
+
}
|
|
264
|
+
visited.add(subtype);
|
|
265
|
+
if (subtype.isUnion()) {
|
|
266
|
+
let schema;
|
|
267
|
+
return {
|
|
268
|
+
kind: 'enum',
|
|
269
|
+
type,
|
|
270
|
+
get schema() {
|
|
271
|
+
return schema ??= subtype.types.map(resolveSchema);
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
else if (typeChecker.isArrayLikeType(subtype)) {
|
|
276
|
+
let schema;
|
|
277
|
+
return {
|
|
278
|
+
kind: 'array',
|
|
279
|
+
type,
|
|
280
|
+
get schema() {
|
|
281
|
+
return schema ??= typeChecker.getTypeArguments(subtype).map(resolveSchema);
|
|
282
|
+
},
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
else if (subtype.getCallSignatures().length === 0
|
|
286
|
+
&& (subtype.isClassOrInterface() || subtype.isIntersection()
|
|
287
|
+
|| subtype.objectFlags & ts.ObjectFlags.Anonymous)) {
|
|
288
|
+
let schema;
|
|
289
|
+
return {
|
|
290
|
+
kind: 'object',
|
|
291
|
+
type,
|
|
292
|
+
get schema() {
|
|
293
|
+
return schema ??= subtype.getProperties().map(resolveNestedProperties).reduce(reducer, {});
|
|
294
|
+
},
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
else if (subtype.getCallSignatures().length === 1) {
|
|
298
|
+
return resolveCallbackSchema(subtype.getCallSignatures()[0]);
|
|
299
|
+
}
|
|
300
|
+
return type;
|
|
301
|
+
}
|
|
302
|
+
function getFullyQualifiedName(type) {
|
|
303
|
+
const str = typeChecker.typeToString(type, undefined, ts.TypeFormatFlags.UseFullyQualifiedType | ts.TypeFormatFlags.NoTruncation);
|
|
304
|
+
if (str.includes('import(')) {
|
|
305
|
+
return str.replace(/import\(.*?\)\./g, '');
|
|
306
|
+
}
|
|
307
|
+
return str;
|
|
308
|
+
}
|
|
309
|
+
function getDeclarations(declaration) {
|
|
310
|
+
return declaration.map(getDeclaration).filter(d => !!d);
|
|
311
|
+
}
|
|
312
|
+
function getDeclaration(declaration) {
|
|
313
|
+
const fileName = declaration.getSourceFile().fileName;
|
|
314
|
+
const sourceScript = language.scripts.get(fileName);
|
|
315
|
+
if (sourceScript?.generated) {
|
|
316
|
+
const script = sourceScript.generated.languagePlugin.typescript?.getServiceScript(sourceScript.generated.root);
|
|
317
|
+
if (script) {
|
|
318
|
+
for (const [sourceScript, map] of language.maps.forEach(script.code)) {
|
|
319
|
+
for (const [start] of map.toSourceLocation(declaration.getStart())) {
|
|
320
|
+
for (const [end] of map.toSourceLocation(declaration.getEnd())) {
|
|
321
|
+
return {
|
|
322
|
+
file: sourceScript.id,
|
|
323
|
+
range: [start, end],
|
|
324
|
+
};
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
return {
|
|
332
|
+
file: declaration.getSourceFile().fileName,
|
|
333
|
+
range: [declaration.getStart(), declaration.getEnd()],
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
resolveNestedProperties,
|
|
338
|
+
resolveSlotProperties,
|
|
339
|
+
resolveEventSignature,
|
|
340
|
+
resolveExposedProperties,
|
|
341
|
+
resolveSchema,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
//# sourceMappingURL=schemaResolvers.js.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as core from '@vue/language-core';
|
|
2
|
+
import type * as ts from 'typescript';
|
|
3
|
+
export declare function getDefaultsFromScriptSetup(ts: typeof import('typescript'), printer: ts.Printer, language: core.Language<string>, componentPath: string): Map<string, string> | undefined;
|
|
4
|
+
export declare function resolveDefaultOptionExpression(ts: typeof import('typescript'), _default: ts.Expression): ts.Expression;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getDefaultsFromScriptSetup = getDefaultsFromScriptSetup;
|
|
37
|
+
exports.resolveDefaultOptionExpression = resolveDefaultOptionExpression;
|
|
38
|
+
const core = __importStar(require("@vue/language-core"));
|
|
39
|
+
function getDefaultsFromScriptSetup(ts, printer, language, componentPath) {
|
|
40
|
+
const sourceScript = language.scripts.get(componentPath);
|
|
41
|
+
const virtualCode = sourceScript?.generated?.root;
|
|
42
|
+
if (!virtualCode) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const sourceFile = virtualCode.sfc.scriptSetup?.ast;
|
|
46
|
+
if (!sourceFile) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const scriptSetupRanges = core.parseScriptSetupRanges(ts, sourceFile, virtualCode.vueCompilerOptions);
|
|
50
|
+
if (scriptSetupRanges) {
|
|
51
|
+
return collectPropDefaultsFromScriptSetup(ts, printer, sourceFile, scriptSetupRanges);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function collectPropDefaultsFromScriptSetup(ts, printer, sourceFile, scriptSetupRanges) {
|
|
55
|
+
const result = new Map();
|
|
56
|
+
if (scriptSetupRanges.withDefaults?.arg) {
|
|
57
|
+
const obj = findObjectLiteralExpression(ts, scriptSetupRanges.withDefaults.arg.node);
|
|
58
|
+
if (obj) {
|
|
59
|
+
for (const prop of obj.properties) {
|
|
60
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
61
|
+
const name = prop.name.getText(sourceFile);
|
|
62
|
+
const expNode = resolveDefaultOptionExpression(ts, prop.initializer);
|
|
63
|
+
const expText = printer.printNode(ts.EmitHint.Expression, expNode, sourceFile);
|
|
64
|
+
result.set(name, expText);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
else if (scriptSetupRanges.defineProps?.destructured) {
|
|
70
|
+
for (const [name, initializer] of scriptSetupRanges.defineProps.destructured) {
|
|
71
|
+
if (initializer) {
|
|
72
|
+
const expText = printer.printNode(ts.EmitHint.Expression, initializer, sourceFile);
|
|
73
|
+
result.set(name, expText);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (scriptSetupRanges.defineModel) {
|
|
78
|
+
for (const defineModel of scriptSetupRanges.defineModel) {
|
|
79
|
+
const obj = defineModel.arg ? findObjectLiteralExpression(ts, defineModel.arg.node) : undefined;
|
|
80
|
+
if (obj) {
|
|
81
|
+
const name = defineModel.name
|
|
82
|
+
? sourceFile.text.slice(defineModel.name.start, defineModel.name.end).slice(1, -1)
|
|
83
|
+
: 'modelValue';
|
|
84
|
+
const _default = resolveModelOption(ts, printer, sourceFile, obj);
|
|
85
|
+
if (_default) {
|
|
86
|
+
result.set(name, _default);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
function findObjectLiteralExpression(ts, node) {
|
|
94
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
95
|
+
return node;
|
|
96
|
+
}
|
|
97
|
+
let result;
|
|
98
|
+
node.forEachChild(child => {
|
|
99
|
+
if (!result) {
|
|
100
|
+
result = findObjectLiteralExpression(ts, child);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
function resolveModelOption(ts, printer, sourceFile, options) {
|
|
106
|
+
let _default;
|
|
107
|
+
for (const prop of options.properties) {
|
|
108
|
+
if (ts.isPropertyAssignment(prop)) {
|
|
109
|
+
const name = prop.name.getText(sourceFile);
|
|
110
|
+
if (name === 'default') {
|
|
111
|
+
const expNode = resolveDefaultOptionExpression(ts, prop.initializer);
|
|
112
|
+
const expText = printer.printNode(ts.EmitHint.Expression, expNode, sourceFile) ?? expNode.getText(sourceFile);
|
|
113
|
+
_default = expText;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return _default;
|
|
118
|
+
}
|
|
119
|
+
function resolveDefaultOptionExpression(ts, _default) {
|
|
120
|
+
if (ts.isArrowFunction(_default)) {
|
|
121
|
+
if (ts.isBlock(_default.body)) {
|
|
122
|
+
return _default; // TODO
|
|
123
|
+
}
|
|
124
|
+
else if (ts.isParenthesizedExpression(_default.body)) {
|
|
125
|
+
return _default.body.expression;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
return _default.body;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return _default;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=scriptSetup.js.map
|
package/lib/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as ts from 'typescript';
|
|
2
|
-
export type ComponentMetaChecker = ReturnType<typeof import('./
|
|
2
|
+
export type ComponentMetaChecker = ReturnType<typeof import('./checker')['createCheckerBase']>;
|
|
3
3
|
export interface Declaration {
|
|
4
4
|
file: string;
|
|
5
5
|
range: [number, number];
|
|
@@ -20,21 +20,25 @@ export declare enum TypeMeta {
|
|
|
20
20
|
}
|
|
21
21
|
export interface PropertyMeta {
|
|
22
22
|
name: string;
|
|
23
|
-
default?: string;
|
|
24
23
|
description: string;
|
|
24
|
+
type: string;
|
|
25
|
+
default?: string;
|
|
25
26
|
global: boolean;
|
|
26
27
|
required: boolean;
|
|
27
|
-
type: string;
|
|
28
28
|
tags: {
|
|
29
29
|
name: string;
|
|
30
30
|
text?: string;
|
|
31
31
|
}[];
|
|
32
|
-
declarations: Declaration[];
|
|
33
32
|
schema: PropertyMetaSchema;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated use `getDeclarations()` instead
|
|
35
|
+
*/
|
|
36
|
+
declarations: Declaration[];
|
|
34
37
|
/**
|
|
35
38
|
* @deprecated use `getTypeObject()` instead
|
|
36
39
|
*/
|
|
37
40
|
rawType?: ts.Type;
|
|
41
|
+
getDeclarations(): Declaration[];
|
|
38
42
|
getTypeObject(): ts.Type;
|
|
39
43
|
}
|
|
40
44
|
export interface EventMeta {
|
|
@@ -46,36 +50,56 @@ export interface EventMeta {
|
|
|
46
50
|
name: string;
|
|
47
51
|
text?: string;
|
|
48
52
|
}[];
|
|
49
|
-
declarations: Declaration[];
|
|
50
53
|
schema: PropertyMetaSchema[];
|
|
54
|
+
/**
|
|
55
|
+
* @deprecated use `getDeclarations()` instead
|
|
56
|
+
*/
|
|
57
|
+
declarations: Declaration[];
|
|
51
58
|
/**
|
|
52
59
|
* @deprecated use `getTypeObject()` instead
|
|
53
60
|
*/
|
|
54
61
|
rawType?: ts.Type;
|
|
62
|
+
getDeclarations(): Declaration[];
|
|
55
63
|
getTypeObject(): ts.Type | undefined;
|
|
56
64
|
}
|
|
57
65
|
export interface SlotMeta {
|
|
58
66
|
name: string;
|
|
59
|
-
type: string;
|
|
60
67
|
description: string;
|
|
61
|
-
|
|
68
|
+
type: string;
|
|
69
|
+
tags: {
|
|
70
|
+
name: string;
|
|
71
|
+
text?: string;
|
|
72
|
+
}[];
|
|
62
73
|
schema: PropertyMetaSchema;
|
|
74
|
+
/**
|
|
75
|
+
* @deprecated use `getDeclarations()` instead
|
|
76
|
+
*/
|
|
77
|
+
declarations: Declaration[];
|
|
63
78
|
/**
|
|
64
79
|
* @deprecated use `getTypeObject()` instead
|
|
65
80
|
*/
|
|
66
81
|
rawType?: ts.Type;
|
|
82
|
+
getDeclarations(): Declaration[];
|
|
67
83
|
getTypeObject(): ts.Type;
|
|
68
84
|
}
|
|
69
85
|
export interface ExposeMeta {
|
|
70
86
|
name: string;
|
|
71
87
|
description: string;
|
|
72
88
|
type: string;
|
|
73
|
-
|
|
89
|
+
tags: {
|
|
90
|
+
name: string;
|
|
91
|
+
text?: string;
|
|
92
|
+
}[];
|
|
74
93
|
schema: PropertyMetaSchema;
|
|
94
|
+
/**
|
|
95
|
+
* @deprecated use `getDeclarations()` instead
|
|
96
|
+
*/
|
|
97
|
+
declarations: Declaration[];
|
|
75
98
|
/**
|
|
76
99
|
* @deprecated use `getTypeObject()` instead
|
|
77
100
|
*/
|
|
78
101
|
rawType?: ts.Type;
|
|
102
|
+
getDeclarations(): Declaration[];
|
|
79
103
|
getTypeObject(): ts.Type;
|
|
80
104
|
}
|
|
81
105
|
export type PropertyMetaSchema = string | {
|
|
@@ -104,9 +128,15 @@ export type MetaCheckerSchemaOptions = boolean | {
|
|
|
104
128
|
};
|
|
105
129
|
export interface MetaCheckerOptions {
|
|
106
130
|
schema?: MetaCheckerSchemaOptions;
|
|
107
|
-
forceUseTs?: boolean;
|
|
108
131
|
printer?: ts.PrinterOptions;
|
|
132
|
+
/**
|
|
133
|
+
* @deprecated No longer needed, this is default behavior now
|
|
134
|
+
*/
|
|
109
135
|
noDeclarations?: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated No longer needed, this is default behavior now
|
|
138
|
+
*/
|
|
139
|
+
forceUseTs?: boolean;
|
|
110
140
|
/**
|
|
111
141
|
* @deprecated No longer needed, use `getTypeObject()` instead
|
|
112
142
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-component-meta",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"**/*.js",
|
|
@@ -13,17 +13,21 @@
|
|
|
13
13
|
"directory": "packages/component-meta"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@volar/typescript": "2.4.
|
|
17
|
-
"@vue/language-core": "3.
|
|
18
|
-
"path-browserify": "^1.0.1"
|
|
19
|
-
"vue-component-type-helpers": "3.1.7"
|
|
20
|
-
},
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"typescript": "*"
|
|
16
|
+
"@volar/typescript": "2.4.27",
|
|
17
|
+
"@vue/language-core": "3.2.0",
|
|
18
|
+
"path-browserify": "^1.0.1"
|
|
23
19
|
},
|
|
24
20
|
"devDependencies": {
|
|
25
21
|
"@types/node": "^22.10.4",
|
|
26
22
|
"@types/path-browserify": "^1.0.1"
|
|
27
23
|
},
|
|
28
|
-
"
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"typescript": "*"
|
|
26
|
+
},
|
|
27
|
+
"peerDependenciesMeta": {
|
|
28
|
+
"typescript": {
|
|
29
|
+
"optional": true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "3138110d767d3d6110899bc46518b53c4b456271"
|
|
29
33
|
}
|
package/lib/base.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type * as ts from 'typescript';
|
|
2
|
-
import type { ComponentMeta, MetaCheckerOptions } from './types';
|
|
3
|
-
export * from './types';
|
|
4
|
-
export declare function createCheckerByJsonConfigBase(ts: typeof import('typescript'), rootDir: string, json: any, checkerOptions?: MetaCheckerOptions): {
|
|
5
|
-
getExportNames: (componentPath: string) => string[];
|
|
6
|
-
getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
|
|
7
|
-
updateFile(fileName: string, text: string): void;
|
|
8
|
-
deleteFile(fileName: string): void;
|
|
9
|
-
reload(): void;
|
|
10
|
-
clearCache(): void;
|
|
11
|
-
getProgram(): ts.Program | undefined;
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated use `getProgram()` instead
|
|
14
|
-
*/
|
|
15
|
-
__internal__: {
|
|
16
|
-
tsLs: ts.LanguageService;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
export declare function createCheckerBase(ts: typeof import('typescript'), tsconfig: string, checkerOptions?: MetaCheckerOptions): {
|
|
20
|
-
getExportNames: (componentPath: string) => string[];
|
|
21
|
-
getComponentMeta: (componentPath: string, exportName?: string) => ComponentMeta;
|
|
22
|
-
updateFile(fileName: string, text: string): void;
|
|
23
|
-
deleteFile(fileName: string): void;
|
|
24
|
-
reload(): void;
|
|
25
|
-
clearCache(): void;
|
|
26
|
-
getProgram(): ts.Program | undefined;
|
|
27
|
-
/**
|
|
28
|
-
* @deprecated use `getProgram()` instead
|
|
29
|
-
*/
|
|
30
|
-
__internal__: {
|
|
31
|
-
tsLs: ts.LanguageService;
|
|
32
|
-
};
|
|
33
|
-
};
|