Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions packages/component-meta/lib/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,12 @@ function baseCreate(
scriptSnapshots.clear();
projectVersion++;
},
getProgram() {
return tsLs.getProgram();
},
/**
* @deprecated use `getProgram()` instead
*/
__internal__: {
tsLs,
},
Expand Down Expand Up @@ -650,13 +656,16 @@ function createSchemaResolvers(
})),
required: !(prop.flags & ts.SymbolFlags.Optional),
type: getFullyQualifiedName(subtype),
rawType: rawType ? subtype : undefined,
get declarations() {
return declarations ??= getDeclarations(prop.declarations ?? []);
},
get schema() {
return schema ??= resolveSchema(subtype);
},
rawType: rawType ? subtype : undefined,
getTypeObject() {
return subtype;
},
};
}
function resolveSlotProperties(prop: ts.Symbol): SlotMeta {
Expand All @@ -670,14 +679,17 @@ function createSchemaResolvers(
return {
name: prop.getName(),
type: getFullyQualifiedName(subtype),
rawType: rawType ? subtype : undefined,
description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
get declarations() {
return declarations ??= getDeclarations(prop.declarations ?? []);
},
get schema() {
return schema ??= resolveSchema(subtype);
},
rawType: rawType ? subtype : undefined,
getTypeObject() {
return subtype;
},
};
}
function resolveExposedProperties(expose: ts.Symbol): ExposeMeta {
Expand All @@ -688,25 +700,30 @@ function createSchemaResolvers(
return {
name: expose.getName(),
type: getFullyQualifiedName(subtype),
rawType: rawType ? subtype : undefined,
description: ts.displayPartsToString(expose.getDocumentationComment(typeChecker)),
get declarations() {
return declarations ??= getDeclarations(expose.declarations ?? []);
},
get schema() {
return schema ??= resolveSchema(subtype);
},
rawType: rawType ? subtype : undefined,
getTypeObject() {
return subtype;
},
};
}
function resolveEventSignature(call: ts.Signature): EventMeta {
let schema: PropertyMetaSchema[] | undefined;
let declarations: Declaration[] | undefined;
let subtype = undefined;
let subtype: ts.Type | undefined;
let symbol: ts.Symbol | undefined;
let subtypeStr = '[]';
let getSchema = () => [] as PropertyMetaSchema[];

if (call.parameters.length >= 2) {
subtype = typeChecker.getTypeOfSymbolAtLocation(call.parameters[1]!, symbolNode);
symbol = call.parameters[1]!;
subtype = typeChecker.getTypeOfSymbolAtLocation(symbol, symbolNode);
if ((call.parameters[1]!.valueDeclaration as any)?.dotDotDotToken) {
subtypeStr = getFullyQualifiedName(subtype);
getSchema = () => typeChecker.getTypeArguments(subtype! as ts.TypeReference).map(resolveSchema);
Expand Down Expand Up @@ -736,14 +753,17 @@ function createSchemaResolvers(
text: tag.text !== undefined ? ts.displayPartsToString(tag.text) : undefined,
})),
type: subtypeStr,
rawType: rawType ? subtype : undefined,
signature: typeChecker.signatureToString(call),
get declarations() {
return declarations ??= call.declaration ? getDeclarations([call.declaration]) : [];
},
get schema() {
return schema ??= getSchema();
},
rawType: rawType ? subtype : undefined,
getTypeObject() {
return subtype;
},
};
}
function resolveCallbackSchema(signature: ts.Signature): PropertyMetaSchema {
Expand Down
29 changes: 24 additions & 5 deletions packages/component-meta/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,55 @@ export interface PropertyMeta {
global: boolean;
required: boolean;
type: string;
rawType?: ts.Type;
tags: { name: string; text?: string }[];
declarations: Declaration[];
schema: PropertyMetaSchema;
/**
* @deprecated use `getTypeObject()` instead
*/
rawType?: ts.Type;
getTypeObject(): ts.Type;
}

export interface EventMeta {
name: string;
description: string;
type: string;
rawType?: ts.Type;
signature: string;
tags: { name: string; text?: string }[];
declarations: Declaration[];
schema: PropertyMetaSchema[];
/**
* @deprecated use `getTypeObject()` instead
*/
rawType?: ts.Type;
getTypeObject(): ts.Type | undefined;
}

export interface SlotMeta {
name: string;
type: string;
rawType?: ts.Type;
description: string;
declarations: Declaration[];
schema: PropertyMetaSchema;
/**
* @deprecated use `getTypeObject()` instead
*/
rawType?: ts.Type;
getTypeObject(): ts.Type;
}

export interface ExposeMeta {
name: string;
description: string;
type: string;
rawType?: ts.Type;
declarations: Declaration[];
schema: PropertyMetaSchema;
/**
* @deprecated use `getTypeObject()` instead
*/
rawType?: ts.Type;
getTypeObject(): ts.Type;
}

export type PropertyMetaSchema =
Expand All @@ -85,6 +101,9 @@ export interface MetaCheckerOptions {
schema?: MetaCheckerSchemaOptions;
forceUseTs?: boolean;
printer?: ts.PrinterOptions;
rawType?: boolean;
noDeclarations?: boolean;
/**
* @deprecated No longer needed, use `getTypeObject()` instead
*/
rawType?: boolean;
}
Loading