Skip to content

Commit

Permalink
fix: ignore walk for module declaration node
Browse files Browse the repository at this point in the history
fix #318
  • Loading branch information
qmhc committed Apr 11, 2024
1 parent 1880153 commit 1d65015
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/react/src/shims.ts
@@ -0,0 +1,9 @@
declare module 'foo' {
import type { ReactDOM } from 'react'

type Foo = {
bar: ReactDOM
}

export = Foo
}
2 changes: 1 addition & 1 deletion examples/react/vite.config.ts
Expand Up @@ -29,7 +29,7 @@ export default defineConfig({
exclude: ['src/ignore'],
// aliasesExclude: [/^@components/],
staticImport: true,
rollupTypes: true,
// rollupTypes: true,
insertTypesEntry: true
})
]
Expand Down
12 changes: 11 additions & 1 deletion src/transform.ts
Expand Up @@ -221,7 +221,17 @@ export function transformCode(options: {
}

if (ts.isModuleDeclaration(node)) {
declareModules.push(s.slice(node.pos, node.end + 1))
if (
node.body &&
ts.isModuleBlock(node.body) &&
!node.body.statements.some(
s => ts.isExportAssignment(s) || ts.isExportDeclaration(s) || ts.isImportDeclaration(s)
)
) {
declareModules.push(s.slice(node.pos, node.end + 1))
}

return false
}
})

Expand Down

0 comments on commit 1d65015

Please sign in to comment.