Skip to content

Commit eeb45e0

Browse files
committed
fix: export type * as '...'
1 parent 2384744 commit eeb45e0

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,8 @@ export function dts(): Plugin {
190190
}
191191
}
192192

193+
if (!s.hasChanged()) return
194+
193195
const str = s.toString()
194196
// console.log(str)
195197
return str
@@ -405,6 +407,7 @@ function patchImportSource(s: MagicStringAST, node: Node) {
405407
// - import { type ... } from '...'
406408
// - export type { ... }
407409
// - export { type ... }
410+
// - export type * as '...'
408411
// - import Foo = require("./bar")
409412
// - export = Foo
410413
// - export default x
@@ -435,6 +438,15 @@ function rewriteImportExport(s: MagicStringAST, node: Node) {
435438
)
436439
}
437440
return true
441+
} else if (node.type === 'ExportAllDeclaration') {
442+
if (node.exportKind === 'type') {
443+
s.overwrite(
444+
node.start,
445+
node.source.start,
446+
s.slice(node.start, node.source.start).replace(RE_TYPE, ''),
447+
)
448+
}
449+
return true
438450
} else if (node.type === 'TSImportEqualsDeclaration') {
439451
if (node.moduleReference.type === 'TSExternalModuleReference') {
440452
s.overwriteNode(

tests/fixtures/type-only-import-export/known-diff.patch renamed to tests/fixtures/type-only-import-export/diff.patch

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Index: diff.patch
22
===================================================================
33
--- diff.patch
44
+++ diff.patch
5-
@@ -1,36 +1,27 @@
5+
@@ -1,36 +1,29 @@
66
// index.d.ts
77
-export { default as A } from 'a';
88
-export { default as D } from 'd';
@@ -46,16 +46,19 @@ Index: diff.patch
4646
+import { K as K1 } from 'k1';
4747
+import { M as M1 } from 'm1';
4848
+import * as I from 'i';
49+
+import * as O from 'o';
4950
+export * from 'i1'
51+
+export * from 'n'
5052
+interface Foo {}
5153
declare class BarType { }
5254
declare class BarValue { }
53-
interface O {}
55+
-interface O {}
56+
+interface O$1 {}
5457
declare class X {}
5558
-interface Foo {
5659
+interface Foo$1 {
5760
inline: string
5861
}
5962
-export { BarType, BarValue, X };
6063
-export { Foo$1 as Foo, Foo as FooInlne, O as O1 };
61-
+export { A, B, B1 as B2, B1 as B3, BarType, BarValue, C, C as C1, D, E3 as E2, E3, E4, F, Foo, Foo$1 as FooInlne, G, G1, H1, I, J, K1, L, M1, O as O1, X, E as default };
64+
+export { A, B, B1 as B2, B1 as B3, BarType, BarValue, C, C as C1, D, E3 as E2, E3, E4, F, Foo, Foo$1 as FooInlne, G, G1, H1, I, J, K1, L, M1, O, O$1 as O1, X, E as default };

tests/fixtures/type-only-import-export/snapshot.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ import { H as H1 } from "h1";
1515
import { K as K1 } from "k1";
1616
import { M as M1 } from "m1";
1717
import * as I from "i";
18+
import * as O from "o";
1819

1920
export * from "i1"
2021

22+
export * from "n"
23+
2124
//#region tests/fixtures/type-only-import-export/foo.d.ts
2225
interface Foo {}
2326

@@ -28,11 +31,11 @@ declare class BarValue { }
2831

2932
//#endregion
3033
//#region tests/fixtures/type-only-import-export/index.d.ts
31-
interface O {}
34+
interface O$1 {}
3235
declare class X {}
3336
interface Foo$1 {
3437
inline: string
3538
}
3639

3740
//#endregion
38-
export { A, B, B1 as B2, B1 as B3, BarType, BarValue, C, C as C1, D, E3 as E2, E3, E4, F, Foo, Foo$1 as FooInlne, G, G1, H1, I, J, K1, L, M1, O as O1, X, E as default };
41+
export { A, B, B1 as B2, B1 as B3, BarType, BarValue, C, C as C1, D, E3 as E2, E3, E4, F, Foo, Foo$1 as FooInlne, G, G1, H1, I, J, K1, L, M1, O, O$1 as O1, X, E as default };

0 commit comments

Comments
 (0)