Skip to content

Commit

Permalink
fix: remove dts empty line (#446)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
  • Loading branch information
sxzz and antfu committed Jul 6, 2022
1 parent 55914b5 commit a969bdf
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/core/declaration.ts
Expand Up @@ -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 += `
Expand Down
37 changes: 34 additions & 3 deletions 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
Expand All @@ -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']
}
Expand Down Expand Up @@ -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']
Expand All @@ -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']
}
Expand Down
25 changes: 25 additions & 0 deletions test/dts.test.ts
Expand Up @@ -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
Expand Down

0 comments on commit a969bdf

Please sign in to comment.