From 53ad572e5a70fba41be29decbc00c3190d741dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90?= Date: Tue, 5 Jul 2022 20:06:40 +0800 Subject: [PATCH] fix: remove dts empty line --- src/core/declaration.ts | 3 +-- test/__snapshots__/dts.test.ts.snap | 37 ++++++++++++++++++++++++++--- test/dts.test.ts | 25 +++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/src/core/declaration.ts b/src/core/declaration.ts index 9922d6d4..0b2b9cc4 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 f00f87fd..a39fc625 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'] } @@ -37,7 +70,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'] @@ -61,7 +93,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 ccad2ce3..81ec029f 100644 --- a/test/dts.test.ts +++ b/test/dts.test.ts @@ -82,4 +82,29 @@ const _directive_loading = _resolveDirective("loading")` expect(contents).not.toContain('comment') 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() + }) })