Skip to content

Commit 487dc29

Browse files
refactor(component-meta): deprecated rawType and __internal__.tsLs (#5808)
1 parent 9f3d8cc commit 487dc29

File tree

3 files changed

+1062
-967
lines changed

3 files changed

+1062
-967
lines changed

packages/component-meta/lib/base.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,12 @@ function baseCreate(
275275
scriptSnapshots.clear();
276276
projectVersion++;
277277
},
278+
getProgram() {
279+
return tsLs.getProgram();
280+
},
281+
/**
282+
* @deprecated use `getProgram()` instead
283+
*/
278284
__internal__: {
279285
tsLs,
280286
},
@@ -650,13 +656,16 @@ function createSchemaResolvers(
650656
})),
651657
required: !(prop.flags & ts.SymbolFlags.Optional),
652658
type: getFullyQualifiedName(subtype),
653-
rawType: rawType ? subtype : undefined,
654659
get declarations() {
655660
return declarations ??= getDeclarations(prop.declarations ?? []);
656661
},
657662
get schema() {
658663
return schema ??= resolveSchema(subtype);
659664
},
665+
rawType: rawType ? subtype : undefined,
666+
getTypeObject() {
667+
return subtype;
668+
},
660669
};
661670
}
662671
function resolveSlotProperties(prop: ts.Symbol): SlotMeta {
@@ -670,14 +679,17 @@ function createSchemaResolvers(
670679
return {
671680
name: prop.getName(),
672681
type: getFullyQualifiedName(subtype),
673-
rawType: rawType ? subtype : undefined,
674682
description: ts.displayPartsToString(prop.getDocumentationComment(typeChecker)),
675683
get declarations() {
676684
return declarations ??= getDeclarations(prop.declarations ?? []);
677685
},
678686
get schema() {
679687
return schema ??= resolveSchema(subtype);
680688
},
689+
rawType: rawType ? subtype : undefined,
690+
getTypeObject() {
691+
return subtype;
692+
},
681693
};
682694
}
683695
function resolveExposedProperties(expose: ts.Symbol): ExposeMeta {
@@ -688,25 +700,30 @@ function createSchemaResolvers(
688700
return {
689701
name: expose.getName(),
690702
type: getFullyQualifiedName(subtype),
691-
rawType: rawType ? subtype : undefined,
692703
description: ts.displayPartsToString(expose.getDocumentationComment(typeChecker)),
693704
get declarations() {
694705
return declarations ??= getDeclarations(expose.declarations ?? []);
695706
},
696707
get schema() {
697708
return schema ??= resolveSchema(subtype);
698709
},
710+
rawType: rawType ? subtype : undefined,
711+
getTypeObject() {
712+
return subtype;
713+
},
699714
};
700715
}
701716
function resolveEventSignature(call: ts.Signature): EventMeta {
702717
let schema: PropertyMetaSchema[] | undefined;
703718
let declarations: Declaration[] | undefined;
704-
let subtype = undefined;
719+
let subtype: ts.Type | undefined;
720+
let symbol: ts.Symbol | undefined;
705721
let subtypeStr = '[]';
706722
let getSchema = () => [] as PropertyMetaSchema[];
707723

708724
if (call.parameters.length >= 2) {
709-
subtype = typeChecker.getTypeOfSymbolAtLocation(call.parameters[1]!, symbolNode);
725+
symbol = call.parameters[1]!;
726+
subtype = typeChecker.getTypeOfSymbolAtLocation(symbol, symbolNode);
710727
if ((call.parameters[1]!.valueDeclaration as any)?.dotDotDotToken) {
711728
subtypeStr = getFullyQualifiedName(subtype);
712729
getSchema = () => typeChecker.getTypeArguments(subtype! as ts.TypeReference).map(resolveSchema);
@@ -736,14 +753,17 @@ function createSchemaResolvers(
736753
text: tag.text !== undefined ? ts.displayPartsToString(tag.text) : undefined,
737754
})),
738755
type: subtypeStr,
739-
rawType: rawType ? subtype : undefined,
740756
signature: typeChecker.signatureToString(call),
741757
get declarations() {
742758
return declarations ??= call.declaration ? getDeclarations([call.declaration]) : [];
743759
},
744760
get schema() {
745761
return schema ??= getSchema();
746762
},
763+
rawType: rawType ? subtype : undefined,
764+
getTypeObject() {
765+
return subtype;
766+
},
747767
};
748768
}
749769
function resolveCallbackSchema(signature: ts.Signature): PropertyMetaSchema {

packages/component-meta/lib/types.ts

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,39 +30,55 @@ export interface PropertyMeta {
3030
global: boolean;
3131
required: boolean;
3232
type: string;
33-
rawType?: ts.Type;
3433
tags: { name: string; text?: string }[];
3534
declarations: Declaration[];
3635
schema: PropertyMetaSchema;
36+
/**
37+
* @deprecated use `getTypeObject()` instead
38+
*/
39+
rawType?: ts.Type;
40+
getTypeObject(): ts.Type;
3741
}
3842

3943
export interface EventMeta {
4044
name: string;
4145
description: string;
4246
type: string;
43-
rawType?: ts.Type;
4447
signature: string;
4548
tags: { name: string; text?: string }[];
4649
declarations: Declaration[];
4750
schema: PropertyMetaSchema[];
51+
/**
52+
* @deprecated use `getTypeObject()` instead
53+
*/
54+
rawType?: ts.Type;
55+
getTypeObject(): ts.Type | undefined;
4856
}
4957

5058
export interface SlotMeta {
5159
name: string;
5260
type: string;
53-
rawType?: ts.Type;
5461
description: string;
5562
declarations: Declaration[];
5663
schema: PropertyMetaSchema;
64+
/**
65+
* @deprecated use `getTypeObject()` instead
66+
*/
67+
rawType?: ts.Type;
68+
getTypeObject(): ts.Type;
5769
}
5870

5971
export interface ExposeMeta {
6072
name: string;
6173
description: string;
6274
type: string;
63-
rawType?: ts.Type;
6475
declarations: Declaration[];
6576
schema: PropertyMetaSchema;
77+
/**
78+
* @deprecated use `getTypeObject()` instead
79+
*/
80+
rawType?: ts.Type;
81+
getTypeObject(): ts.Type;
6682
}
6783

6884
export type PropertyMetaSchema =
@@ -85,6 +101,9 @@ export interface MetaCheckerOptions {
85101
schema?: MetaCheckerSchemaOptions;
86102
forceUseTs?: boolean;
87103
printer?: ts.PrinterOptions;
88-
rawType?: boolean;
89104
noDeclarations?: boolean;
105+
/**
106+
* @deprecated No longer needed, use `getTypeObject()` instead
107+
*/
108+
rawType?: boolean;
90109
}

0 commit comments

Comments
 (0)