Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove dts empty line #446

Merged
merged 2 commits into from Jul 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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