Skip to content

Commit

Permalink
fix: should process alias for module declaration
Browse files Browse the repository at this point in the history
fix #409
  • Loading branch information
qmhc committed Feb 27, 2025
1 parent 0da89cc commit 41167d5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
7 changes: 7 additions & 0 deletions examples/ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ export type { AliasType } from '@alias/type'

export type * from './namespace'
export type * from './modules'

declare module '@/test' {
interface TestBase {
name: string,
mail?: string
}
}
27 changes: 18 additions & 9 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function transformAlias(
aliasesExclude: (string | RegExp)[]
) {
if (
aliases.length &&
aliases?.length &&
!aliasesExclude.some(e => (isRegExp(e) ? e.test(importer) : String(e) === importer))
) {
const matchedAlias = aliases.find(alias => isAliasMatch(alias, importer))
Expand Down Expand Up @@ -245,14 +245,23 @@ export function transformCode(options: {
node.body.statements.some(isVLSNode)
) {
s.remove(node.pos, node.end)
} else if (
node.modifiers?.[0] &&
node.modifiers[0].kind === ts.SyntaxKind.DeclareKeyword &&
!node.body.statements.some(
s => ts.isExportAssignment(s) || ts.isExportDeclaration(s) || ts.isImportDeclaration(s)
)
) {
declareModules.push(s.slice(node.pos, node.end + 1))
} else if (ts.isStringLiteral(node.name)) {
const libName = toLibName(node.name.text)

if (libName !== node.name.text) {
s.update(node.name.pos, node.name.end, ` '${libName}'`)
}

if (
!libName.startsWith('.') &&
node.modifiers?.[0] &&
node.modifiers[0].kind === ts.SyntaxKind.DeclareKeyword &&
!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 41167d5

Please sign in to comment.