Skip to content

Commit

Permalink
feat(component-meta): make schema.ignore accept functions (#2232)
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Dec 19, 2022
1 parent 7f050a1 commit f979b75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
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

0 comments on commit f979b75

Please sign in to comment.