11import type { SlotBit , Bit , ParsedSvelteFile } from '../types'
22import type { TSDocParser } from '@microsoft/tsdoc'
3+ import type { FileParserContext } from './files'
34import type { SourceFile , Node } from 'ts-morph'
45
56import { getName , getType , isExported , toBit } from '../utils/nodes'
67import { parseCommentFromNode } from '../comments'
78import ts from 'typescript'
89
9- export function parseSvelteFile (
10- file_name : string ,
11- file : SourceFile ,
12- parser : TSDocParser ,
13- ) : ParsedSvelteFile {
10+ export function parseSvelteFile ( {
11+ file_name,
12+ input_file_path,
13+ file,
14+ tsdoc,
15+ } : FileParserContext ) : ParsedSvelteFile {
1416 //? Get the component name from the file name
1517 const componentName = file_name . replace ( '.svelte' , '' )
1618
1719 //? Get the props, events, slots nodes
1820 const stuff = extractSvelteTypeNodes ( file )
1921
2022 //? Parse the props, events, slots nodes to bits
21- const slots = stuff . slots ?. map < SlotBit > ( ( n ) => parseSlot ( n , parser ) ) || [ ]
22- const events = stuff . events ?. map < Bit > ( ( n ) => toBit ( n , parser ) ) || [ ]
23- const props = stuff . props ?. map < Bit > ( ( n ) => toBit ( n , parser ) ) || [ ]
23+ const slots = stuff . slots ?. map < SlotBit > ( ( n ) => parseSlot ( n , tsdoc ) ) || [ ]
24+ const events = stuff . events ?. map < Bit > ( ( n ) => toBit ( n , tsdoc ) ) || [ ]
25+ const props = stuff . props ?. map < Bit > ( ( n ) => toBit ( n , tsdoc ) ) || [ ]
2426
2527 //? Extract the export bits
26- const variables = extractModuleExports ( componentName , file , parser )
28+ const variables = extractModuleExports ( componentName , file , tsdoc )
2729
2830 return {
2931 fileName : file_name ,
32+ filePath : input_file_path ,
3033 componentName,
3134 props,
3235 events,
@@ -121,7 +124,7 @@ function extractSvelteTypeNodes(file: SourceFile) {
121124 }
122125}
123126
124- function parseSlot ( node : Node , parser : TSDocParser ) : SlotBit {
127+ function parseSlot ( node : Node , tsdoc : TSDocParser ) : SlotBit {
125128 /**
126129 * ? Slots look like this
127130 *
@@ -146,16 +149,16 @@ function parseSlot(node: Node, parser: TSDocParser): SlotBit {
146149 . getChildrenOfKind ( ts . SyntaxKind . TypeLiteral ) [ 0 ]
147150 ?. getChildSyntaxList ( )
148151 ?. getChildren ( )
149- ?. map ( ( node ) => toBit ( node , parser ) )
152+ ?. map ( ( node ) => toBit ( node , tsdoc ) )
150153
151154 return {
152- comment : parseCommentFromNode ( node , parser ) ,
155+ comment : parseCommentFromNode ( node , tsdoc ) ,
153156 name : getName ( node ) || 'it broke' ,
154157 props : props || [ ] ,
155158 }
156159}
157160
158- function extractModuleExports ( componentName : string , file : SourceFile , parser : TSDocParser ) {
161+ function extractModuleExports ( componentName : string , file : SourceFile , tsdoc : TSDocParser ) {
159162 //? Nodes we don't care about, they are handled elsewhere
160163 const ignoredNodeNames = [
161164 'default' ,
@@ -181,14 +184,14 @@ function extractModuleExports(componentName: string, file: SourceFile, parser: T
181184 ) !
182185
183186 return {
184- comment : parseCommentFromNode ( node , parser ) ,
187+ comment : parseCommentFromNode ( node , tsdoc ) ,
185188 name : getName ( declaration ) || 'it broke ahjk' ,
186189 type : getType ( declaration ) ,
187190 }
188191 }
189192
190193 default :
191- return toBit ( node , parser )
194+ return toBit ( node , tsdoc )
192195 }
193196 } )
194197 )
0 commit comments