Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(component-meta): make schema.ignore accept functions #2232

Merged
merged 1 commit into from Dec 19, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 14 additions & 3 deletions vue-language-tools/vue-component-meta/src/index.ts
Expand Up @@ -427,16 +427,27 @@ function createSchemaResolvers(
const ignore = typeof options === 'object' ? [...options?.ignore ?? []] : [];

function shouldIgnore(subtype: ts.Type) {
const type = typeChecker.typeToString(subtype);
if (type === 'any') {
const name = typeChecker.typeToString(subtype);
if (name === 'any') {
return true;
}

if (ignore.length === 0) {
return false;
}

return ignore.includes(type);
for (const item of ignore) {
if (typeof item === 'function') {
const result = item(name, subtype, typeChecker);
if (result != null)
return result
}
else if (name === item) {
return true;
}
}

return false;
}

function setVisited(subtype: ts.Type) {
Expand Down
7 changes: 6 additions & 1 deletion vue-language-tools/vue-component-meta/src/types.ts
Expand Up @@ -46,8 +46,13 @@ export type PropertyMetaSchema = string
| { kind: 'object', type: string, schema?: Record<string, PropertyMeta>; };

export type MetaCheckerSchemaOptions = boolean | {
ignore?: string[];
/**
* A list of type names to be ignored in expending in schema.
* Can be functions to ignore types dynamically.
*/
ignore?: (string | ((name: string, type: ts.Type, typeChecker: ts.TypeChecker) => boolean | void | undefined | null))[];
};

export interface MetaCheckerOptions {
schema?: MetaCheckerSchemaOptions;
forceUseTs?: boolean;
Expand Down