diff --git a/src/core/declaration.ts b/src/core/declaration.ts index a66a3fc4..809a2939 100644 --- a/src/core/declaration.ts +++ b/src/core/declaration.ts @@ -127,8 +127,7 @@ declare module '@vue/runtime-core' {` code += ` export interface GlobalComponents { ${declarations.component.join('\n ')} - } -` + }` } if (Object.keys(declarations.directive).length > 0) { code += ` diff --git a/test/__snapshots__/dts.test.ts.snap b/test/__snapshots__/dts.test.ts.snap index 44267f2d..2b8a00a5 100644 --- a/test/__snapshots__/dts.test.ts.snap +++ b/test/__snapshots__/dts.test.ts.snap @@ -1,6 +1,6 @@ // Vitest Snapshot v1 -exports[`dts > getDeclaration 1`] = ` +exports[`dts > components only 1`] = ` "// generated by unplugin-vue-components // We suggest you to commit this file into source control // Read more: https://github.com/vuejs/core/pull/3399 @@ -14,7 +14,40 @@ declare module '@vue/runtime-core' { RouterView: typeof import('vue-router')['RouterView'] TestComp: typeof import('test/component/TestComp')['default'] } +} +" +`; + +exports[`dts > directive only 1`] = ` +"// generated by unplugin-vue-components +// We suggest you to commit this file into source control +// Read more: https://github.com/vuejs/core/pull/3399 +import '@vue/runtime-core' +export {} + +declare module '@vue/runtime-core' { + export interface ComponentCustomProperties { + vLoading: typeof import('test/directive/Loading')['default'] + } +} +" +`; + +exports[`dts > getDeclaration 1`] = ` +"// generated by unplugin-vue-components +// We suggest you to commit this file into source control +// Read more: https://github.com/vuejs/core/pull/3399 +import '@vue/runtime-core' + +export {} + +declare module '@vue/runtime-core' { + export interface GlobalComponents { + RouterLink: typeof import('vue-router')['RouterLink'] + RouterView: typeof import('vue-router')['RouterView'] + TestComp: typeof import('test/component/TestComp')['default'] + } export interface ComponentCustomProperties { vLoading: typeof import('test/directive/Loading')['default'] } @@ -74,7 +107,6 @@ declare module '@vue/runtime-core' { SomeComp: typeof import('test/component/SomeComp')['default'] TestComp: typeof import('test/component/TestComp')['default'] } - export interface ComponentCustomProperties { vDirective: typeof import('foo') vLoading: typeof import('test/directive/Loading')['default'] @@ -98,7 +130,6 @@ declare module '@vue/runtime-core' { RouterView: typeof import('vue-router')['RouterView'] TestComp: typeof import('test/component/TestComp')['default'] } - export interface ComponentCustomProperties { vLoading: typeof import('test/directive/Loading')['default'] } diff --git a/test/dts.test.ts b/test/dts.test.ts index ec0de04b..7a47515a 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -83,6 +83,31 @@ const _directive_loading = _resolveDirective("loading")` expect(contents).toContain('vSome') }) + test('components only', async () => { + const ctx = new Context({ + resolvers: resolver, + directives: true, + }) + const code = 'const _component_test_comp = _resolveComponent("test-comp")' + await ctx.transform(code, '') + + const declarations = getDeclaration(ctx, 'test.d.ts') + expect(declarations).toMatchSnapshot() + }) + + test('directive only', async () => { + const ctx = new Context({ + resolvers: resolver, + directives: true, + types: [], + }) + const code = 'const _directive_loading = _resolveDirective("loading")' + await ctx.transform(code, '') + + const declarations = getDeclaration(ctx, 'test.d.ts') + expect(declarations).toMatchSnapshot() + }) + test('parseDeclaration', async () => { const code = ` // generated by unplugin-vue-components