Skip to content

Commit 79e5440

Browse files
committed
fix: should collect indentifier module declaration
fix #419
1 parent b191904 commit 79e5440

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

examples/ts-vite/src/modules.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,13 @@ declare module 'tslib' {
22
export type Test = { newField: string }
33
}
44

5+
declare global {
6+
// eslint-disable-next-line @typescript-eslint/no-namespace
7+
namespace jest {
8+
interface Matchers<R> {
9+
toChildSnapshot: (filename: string, name: string) => R
10+
}
11+
}
12+
}
13+
514
export {}

packages/unplugin-dts/src/core/transform.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,15 +245,18 @@ export function transformCode(options: {
245245
node.body.statements.some(isVLSNode)
246246
) {
247247
s.remove(node.pos, node.end)
248-
} else if (ts.isStringLiteral(node.name)) {
249-
const libName = toLibName(node.name.text)
248+
} else {
249+
let libName = ''
250+
if (ts.isStringLiteral(node.name)) {
251+
libName = toLibName(node.name.text)
250252

251-
if (libName !== node.name.text) {
252-
s.update(node.name.pos, node.name.end, ` '${libName}'`)
253+
if (libName !== node.name.text) {
254+
s.update(node.name.pos, node.name.end, ` '${libName}'`)
255+
}
253256
}
254257

255258
if (
256-
!libName.startsWith('.') &&
259+
(!libName || !libName.startsWith('.')) &&
257260
node.modifiers?.[0] &&
258261
node.modifiers[0].kind === ts.SyntaxKind.DeclareKeyword &&
259262
!node.body.statements.some(

0 commit comments

Comments
 (0)