Skip to content

Commit acf627d

Browse files
committed
fix: correctly generate declaration for custom SFC
fix #394
1 parent 35574d4 commit acf627d

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

examples/vue/components/CustomSFC.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script lang="ts" setup></script>
2+
3+
<template>
4+
<div>test</div>
5+
</template>
6+
7+
<i18n lang="json">
8+
{
9+
"zh-cn": {
10+
"test": "test"
11+
},
12+
"en": {
13+
"test": "test"
14+
}
15+
}
16+
</i18n>

examples/vue/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import NoDirectExport from '@/components/NoDirectExport.vue'
1313

1414
import OutsideTsProps from '@/components/outside-ts-props'
1515
import GenericProps from '@/components/GenericProps.vue'
16+
import CustomSFC from '@/components/CustomSFC.vue'
1617

1718
import JsSetup from '../components/JsSetup.vue'
1819
import CssVar from '../components/CssVar.vue'
@@ -47,7 +48,8 @@ export {
4748
JsSetup,
4849
CssVar,
4950
OutsideTsProps,
50-
GenericProps
51+
GenericProps,
52+
CustomSFC
5153
}
5254

5355
export default DefaultImport

src/plugin.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
120120

121121
const rootFiles = new Set<string>()
122122
const outputFiles = new Map<string, string>()
123+
const transformedFiles = new Set<string>()
123124

124125
const setOutputFile = (path: string, content: string) => {
125126
outputFiles.set(path, content)
@@ -394,22 +395,23 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
394395

395396
async transform(code, id) {
396397
let resolver: Resolver | undefined
397-
id = normalizePath(id)
398+
id = normalizePath(id).split('?')[0]
398399

399400
if (
400401
!host ||
401402
!program ||
402403
!filter(id) ||
403-
(!(resolver = resolvers.find(r => r.supports(id))) && !tjsRE.test(id))
404+
(!(resolver = resolvers.find(r => r.supports(id))) && !tjsRE.test(id)) ||
405+
transformedFiles.has(id)
404406
) {
405407
return
406408
}
407409

408410
const startTime = Date.now()
409411
const outDir = outDirs[0]
410412

411-
id = id.split('?')[0]
412413
rootFiles.delete(id)
414+
transformedFiles.add(id)
413415

414416
if (resolver) {
415417
const result = await resolver.transform({
@@ -487,6 +489,8 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
487489
},
488490

489491
async writeBundle() {
492+
transformedFiles.clear()
493+
490494
if (!host || !program || bundled) return
491495

492496
bundled = true

0 commit comments

Comments
 (0)