Skip to content

Commit c5116b2

Browse files
committed
feat: isDefaultExport
1 parent 6da37fb commit c5116b2

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A work in progress cli tool for extracting type information & tsdoc from Svelte
1313
- [x] Slots
1414
- [ ] Configure Svelte Version
1515
- [x] Extract from TS/JS Files
16-
- [ ] Bool for default export
16+
- [x] Bool for default export
1717
- [ ] Better typings for somethings
1818

1919
## Example

src/files/typescript.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1+
import type { ExportBit, ParsedTSFile } from '../types'
12
import type { TSDocParser } from '@microsoft/tsdoc'
2-
import type { Bit, ParsedTSFile } from '../types'
33
import type { SourceFile } from 'ts-morph'
44

55
import { parseCommentFromNode } from '../comments'
66
import { getType } from '../utils/nodes'
77
import ts from 'typescript'
88

99
export function parseTSFile(file_name: string, file: SourceFile, tsdoc: TSDocParser): ParsedTSFile {
10-
const export_bits: Bit[] = []
10+
const export_bits: ExportBit[] = []
1111

1212
//? Loop over all the export declarations
1313
for (const [name, declarations] of file.getExportedDeclarations()) {
@@ -18,7 +18,6 @@ export function parseTSFile(file_name: string, file: SourceFile, tsdoc: TSDocPar
1818
)
1919
}
2020

21-
//? Let's only deal with a single array cast
2221
const [declaration] = declarations
2322

2423
const tsdoc_node_parent = declaration.getFirstChildIfKind(ts.SyntaxKind.JSDoc)
@@ -32,6 +31,7 @@ export function parseTSFile(file_name: string, file: SourceFile, tsdoc: TSDocPar
3231
export_bits.push({
3332
name,
3433
type: getType(declaration),
34+
isDefaultExport: name == 'default',
3535
comment: tsdoc_node_parent ? parseCommentFromNode(tsdoc_node_parent, tsdoc) : undefined,
3636
})
3737
}

src/types.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,13 @@ export interface Bit {
8282
comment?: TSDocComment
8383
}
8484

85+
export interface ExportBit extends Bit {
86+
/**
87+
* Whether the export is the default
88+
*/
89+
isDefaultExport: boolean
90+
}
91+
8592
export interface SlotBit extends Omit<Bit, 'type'> {
8693
/**
8794
* The props of the slot

0 commit comments

Comments
 (0)