Skip to content

Commit a969bdf

Browse files
sxzzantfu
andauthored
fix: remove dts empty line (#446)
Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
1 parent 55914b5 commit a969bdf

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

src/core/declaration.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ declare module '@vue/runtime-core' {`
127127
code += `
128128
export interface GlobalComponents {
129129
${declarations.component.join('\n ')}
130-
}
131-
`
130+
}`
132131
}
133132
if (Object.keys(declarations.directive).length > 0) {
134133
code += `

test/__snapshots__/dts.test.ts.snap

+34-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Vitest Snapshot v1
22

3-
exports[`dts > getDeclaration 1`] = `
3+
exports[`dts > components only 1`] = `
44
"// generated by unplugin-vue-components
55
// We suggest you to commit this file into source control
66
// Read more: https://github.com/vuejs/core/pull/3399
@@ -14,7 +14,40 @@ declare module '@vue/runtime-core' {
1414
RouterView: typeof import('vue-router')['RouterView']
1515
TestComp: typeof import('test/component/TestComp')['default']
1616
}
17+
}
18+
"
19+
`;
20+
21+
exports[`dts > directive only 1`] = `
22+
"// generated by unplugin-vue-components
23+
// We suggest you to commit this file into source control
24+
// Read more: https://github.com/vuejs/core/pull/3399
25+
import '@vue/runtime-core'
1726
27+
export {}
28+
29+
declare module '@vue/runtime-core' {
30+
export interface ComponentCustomProperties {
31+
vLoading: typeof import('test/directive/Loading')['default']
32+
}
33+
}
34+
"
35+
`;
36+
37+
exports[`dts > getDeclaration 1`] = `
38+
"// generated by unplugin-vue-components
39+
// We suggest you to commit this file into source control
40+
// Read more: https://github.com/vuejs/core/pull/3399
41+
import '@vue/runtime-core'
42+
43+
export {}
44+
45+
declare module '@vue/runtime-core' {
46+
export interface GlobalComponents {
47+
RouterLink: typeof import('vue-router')['RouterLink']
48+
RouterView: typeof import('vue-router')['RouterView']
49+
TestComp: typeof import('test/component/TestComp')['default']
50+
}
1851
export interface ComponentCustomProperties {
1952
vLoading: typeof import('test/directive/Loading')['default']
2053
}
@@ -74,7 +107,6 @@ declare module '@vue/runtime-core' {
74107
SomeComp: typeof import('test/component/SomeComp')['default']
75108
TestComp: typeof import('test/component/TestComp')['default']
76109
}
77-
78110
export interface ComponentCustomProperties {
79111
vDirective: typeof import('foo')
80112
vLoading: typeof import('test/directive/Loading')['default']
@@ -98,7 +130,6 @@ declare module '@vue/runtime-core' {
98130
RouterView: typeof import('vue-router')['RouterView']
99131
TestComp: typeof import('test/component/TestComp')['default']
100132
}
101-
102133
export interface ComponentCustomProperties {
103134
vLoading: typeof import('test/directive/Loading')['default']
104135
}

test/dts.test.ts

+25
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,31 @@ const _directive_loading = _resolveDirective("loading")`
8383
expect(contents).toContain('vSome')
8484
})
8585

86+
test('components only', async () => {
87+
const ctx = new Context({
88+
resolvers: resolver,
89+
directives: true,
90+
})
91+
const code = 'const _component_test_comp = _resolveComponent("test-comp")'
92+
await ctx.transform(code, '')
93+
94+
const declarations = getDeclaration(ctx, 'test.d.ts')
95+
expect(declarations).toMatchSnapshot()
96+
})
97+
98+
test('directive only', async () => {
99+
const ctx = new Context({
100+
resolvers: resolver,
101+
directives: true,
102+
types: [],
103+
})
104+
const code = 'const _directive_loading = _resolveDirective("loading")'
105+
await ctx.transform(code, '')
106+
107+
const declarations = getDeclaration(ctx, 'test.d.ts')
108+
expect(declarations).toMatchSnapshot()
109+
})
110+
86111
test('parseDeclaration', async () => {
87112
const code = `
88113
// generated by unplugin-vue-components

0 commit comments

Comments
 (0)