Skip to content

Commit 072f83f

Browse files
ghostdevvbraebo
andcommitted
feat: handle multiple declarations by outputting twice
Co-authored-by: Braden Wiggins <[email protected]>
1 parent 02aa1c3 commit 072f83f

File tree

3 files changed

+49
-22
lines changed

3 files changed

+49
-22
lines changed

.changeset/yellow-buses-hammer.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'extractinator': minor
3+
---
4+
5+
feat: handle multiple declarations by outputting twice

src/files/typescript.ts

+17-22
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,24 @@ export function parseTSFile({
1515

1616
//? Loop over all the export declarations
1717
for (const [name, declarations] of file.getExportedDeclarations()) {
18-
// todo handle this
19-
if (declarations.length > 1) {
20-
throw new Error(
21-
`Multiple declarations are not handled yet, please file issue "${file_name}"`,
22-
)
23-
}
24-
25-
const [declaration] = declarations
18+
for (const declaration of declarations) {
19+
const tsdoc_node_parent = declaration.getFirstChildIfKind(ts.SyntaxKind.JSDoc)
20+
? //? Check whether the declaration has a comment
21+
declaration
22+
: //? Find the comment by traversing up the parent, this should be safe here
23+
declaration
24+
.getAncestors()
25+
.find((ancestor) => !!ancestor.getFirstChildIfKind(ts.SyntaxKind.JSDoc))
2626

27-
const tsdoc_node_parent = declaration.getFirstChildIfKind(ts.SyntaxKind.JSDoc)
28-
? //? Check whether the declaration has a comment
29-
declaration
30-
: //? Find the comment by traversing up the parent, this should be safe here
31-
declaration
32-
.getAncestors()
33-
.find((ancestor) => !!ancestor.getFirstChildIfKind(ts.SyntaxKind.JSDoc))
34-
35-
export_bits.push({
36-
name,
37-
type: getType(declaration),
38-
isDefaultExport: name == 'default',
39-
comment: tsdoc_node_parent ? parseCommentFromNode(tsdoc_node_parent, tsdoc) : undefined,
40-
})
27+
export_bits.push({
28+
name,
29+
type: getType(declaration),
30+
isDefaultExport: name == 'default',
31+
comment: tsdoc_node_parent
32+
? parseCommentFromNode(tsdoc_node_parent, tsdoc)
33+
: undefined,
34+
})
35+
}
4136
}
4237

4338
return {
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Adds two or three numbers together.
3+
* @param a The first number to add.
4+
* @param b The second number to add.
5+
* @returns The sum of the two numbers.
6+
*/
7+
export function add(a: number, b: number): number
8+
9+
/**
10+
* Adds two or three numbers together.
11+
* @param a The first number to add.
12+
* @param b The second number to add.
13+
* @param c The third number to add.
14+
* @returns The sum of the three numbers.
15+
*/
16+
export function add(a: number, b: number, c: number): number
17+
18+
/**
19+
* Adds two or three numbers together.
20+
* @param a The first number to add.
21+
* @param b The second number to add.
22+
* @param c Optional third number to add.
23+
* @returns The sum of the input numbers.
24+
*/
25+
export function add(a: number, b: number, c?: number): number {
26+
return a + b + (c ?? 0)
27+
}

0 commit comments

Comments
 (0)