From a23e99bedf1d65841d162951f10ce35b907a5680 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 14 Jun 2024 17:46:50 +0200 Subject: [PATCH] fix(compiler-sfc): support @vue-ignore comment on more type sources --- .../__tests__/compileScript/resolveType.spec.ts | 12 ++++++++++++ packages/compiler-sfc/src/script/resolveType.ts | 12 ++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts b/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts index 608549de6f3..0b5549cc407 100644 --- a/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts +++ b/packages/compiler-sfc/__tests__/compileScript/resolveType.spec.ts @@ -137,6 +137,18 @@ describe('resolveType', () => { }) }) + test('intersection type with ignore', () => { + expect( + resolve(` + type Foo = { foo: number } + type Bar = { bar: string } + defineProps() + `).props, + ).toStrictEqual({ + foo: ['Number'], + }) + }) + // #7553 test('union type', () => { expect( diff --git a/packages/compiler-sfc/src/script/resolveType.ts b/packages/compiler-sfc/src/script/resolveType.ts index ce0be17425f..5a4c84b4ab7 100644 --- a/packages/compiler-sfc/src/script/resolveType.ts +++ b/packages/compiler-sfc/src/script/resolveType.ts @@ -165,6 +165,12 @@ function innerResolveTypeElements( scope: TypeScope, typeParameters?: Record, ): ResolvedElements { + if ( + node.leadingComments && + node.leadingComments.some(c => c.value.includes('@vue-ignore')) + ) { + return { props: {} } + } switch (node.type) { case 'TSTypeLiteral': return typeElementsToMap(ctx, node.members, scope, typeParameters) @@ -414,12 +420,6 @@ function resolveInterfaceMembers( ) if (node.extends) { for (const ext of node.extends) { - if ( - ext.leadingComments && - ext.leadingComments.some(c => c.value.includes('@vue-ignore')) - ) { - continue - } try { const { props, calls } = resolveTypeElements(ctx, ext, scope) for (const key in props) {