Skip to content

Commit 2d9a48b

Browse files
authored
fix: rework type-only export (#242)
1 parent c255bc4 commit 2d9a48b

93 files changed

Lines changed: 1551 additions & 617 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/fake-js.ts

Lines changed: 545 additions & 255 deletions
Large diffs are not rendered by default.

tests/__snapshots__/index.test.ts.snap

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ exports[`resolve dts 1`] = `
457457
//#region tests/fixtures/resolve-dts/mod.d.ts
458458
type Foo = string;
459459
//#endregion
460-
export { Foo };
460+
export { type Foo };
461461
// index.js
462462
"
463463
`;
@@ -571,5 +571,15 @@ declare const ns = 42;
571571
//#region tests/fixtures/type-only-export/all.d.ts
572572
declare const all = 42;
573573
//#endregion
574-
export { A as RuntimeA, type A as TypeA, A as TypeC, type B as TypeB, all, type namespace_d_exports as ns };"
574+
//#region tests/fixtures/type-only-export/chain-c.d.ts
575+
interface c {}
576+
declare const runtime = 1;
577+
//#endregion
578+
//#region tests/fixtures/type-only-export/chain-b.d.ts
579+
interface Local {}
580+
//#endregion
581+
//#region tests/fixtures/type-only-export/class-source.d.ts
582+
declare class TypeOnlyClass {}
583+
//#endregion
584+
export { A as RuntimeA, type A as TypeA, type A as TypeC, type B as TypeB, type TypeOnlyClass, type all, type c, type namespace_d_exports as ns, runtime, type Local as typeOnly };"
575585
`;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './chain-b'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface Local {}
2+
3+
export { type Local as typeOnly }
4+
export * from './chain-c'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
interface c {}
2+
const runtime = 1
3+
4+
export { type c, runtime }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './class-chain-b'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { type TypeOnlyClass } from './class-source'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class TypeOnlyClass {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export * from './mod'
22
export type * as ns from './namespace'
33
export type * from './all'
4+
export * from './chain-a'
5+
export * from './class-chain-a'
46
import { type RuntimeA } from './mod'
57
export { RuntimeA as TypeC }

tests/rollup-plugin-dts.test.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference lib="esnext.array" />
22

3+
import { format, type Options } from 'prettier'
34
import { access, glob, readFile, unlink } from 'node:fs/promises'
45
import path from 'node:path'
56
import process from 'node:process'
@@ -59,8 +60,17 @@ await testFixtures(
5960
path.resolve(dirname, 'snapshot.d.ts'),
6061
)
6162

62-
rollupSnapshot = cleanupCode(rollupSnapshot)
63-
rolldownSnapshot = cleanupCode(rolldownSnapshot)
63+
const prettierOptions: Options = {
64+
semi: false,
65+
parser: 'babel-ts',
66+
singleQuote: true,
67+
printWidth: 1,
68+
}
69+
rollupSnapshot = await format(cleanupCode(rollupSnapshot), prettierOptions)
70+
rolldownSnapshot = await format(
71+
cleanupCode(rolldownSnapshot),
72+
prettierOptions,
73+
)
6474
const diffPath = path.resolve(dirname, 'diff.patch')
6575
const knownDiffPath = path.resolve(dirname, 'known-diff.patch')
6676
const diff = createPatch(
@@ -103,12 +113,7 @@ function cleanupCode(text: string) {
103113
return `${text
104114
.replaceAll(/\/\/#region .*\n/g, '')
105115
.replaceAll('//#endregion', '')
106-
.replaceAll(/from "(.*)"/g, "from '$1'")
107-
.replaceAll('export type', 'export') // FIXME
108-
.replaceAll(/,$/gm, '')
109116
.split('\n')
110117
.filter((line) => line.trim() !== '')
111-
.join('\n')
112-
.replaceAll(/;$/gm, '')
113-
.trim()}\n`
118+
.join('\n')}\n`
114119
}

0 commit comments

Comments
 (0)