Skip to content

Commit 589901f

Browse files
committed
fix: correctly match normal export
fix #362
1 parent b4bf8db commit 589901f

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

src/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import debug from 'debug'
1111
import { cyan, green, yellow } from 'kolorist'
1212
import { rollupDeclarationFiles } from './rollup'
1313
import { JsonResolver, SvelteResolver, VueResolver, parseResolvers } from './resolvers'
14-
import { hasExportDefault, hasNamedExport, normalizeGlob, transformCode } from './transform'
14+
import { hasExportDefault, hasNormalExport, normalizeGlob, transformCode } from './transform'
1515
import {
1616
editSourceMapDir,
1717
ensureAbsolute,
@@ -674,7 +674,7 @@ export function dtsPlugin(options: PluginOptions = {}): import('vite').Plugin {
674674
let content = ''
675675

676676
if (emittedFiles.has(sourceEntry)) {
677-
if (hasNamedExport(emittedFiles.get(sourceEntry)!)) {
677+
if (hasNormalExport(emittedFiles.get(sourceEntry)!)) {
678678
content += `export * from '${fromPath}'\n`
679679
}
680680

src/transform.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,18 +247,22 @@ export function transformCode(options: {
247247
}
248248
}
249249

250-
export function hasNamedExport(content: string) {
250+
export function hasNormalExport(content: string) {
251251
const ast = ts.createSourceFile('a.ts', content, ts.ScriptTarget.Latest)
252252

253253
let has = false
254254

255255
walkSourceFile(ast, node => {
256-
if (ts.isExportDeclaration(node) && node.exportClause && ts.isNamedExports(node.exportClause)) {
257-
for (const element of node.exportClause.elements) {
258-
if (element.name.escapedText !== 'default') {
259-
has = true
260-
break
256+
if (ts.isExportDeclaration(node)) {
257+
if (node.exportClause && ts.isNamedExports(node.exportClause)) {
258+
for (const element of node.exportClause.elements) {
259+
if (element.name.escapedText !== 'default') {
260+
has = true
261+
break
262+
}
261263
}
264+
} else {
265+
has = true
262266
}
263267
} else if ('modifiers' in node && Array.isArray(node.modifiers) && node.modifiers.length > 1) {
264268
for (let i = 0, len = node.modifiers.length; i < len; ++i) {

0 commit comments

Comments
 (0)