@@ -10,17 +10,24 @@ import cacher from './utils/cacher'
10
10
11
11
const ERROR_EMPTY_DOCUMENT = 'The passed source is empty'
12
12
13
+ export interface ParseOptions {
14
+ filePath : string
15
+ lang ?: 'ts' | 'js'
16
+ nameFilter ?: string [ ]
17
+ aliases ?: { [ alias : string ] : string }
18
+ }
19
+
13
20
/**
14
21
* parses the source and returns the doc
15
22
* @param {string } source code whose documentation is parsed
16
23
* @param {string } filePath path of the current file against whom to resolve the mixins
17
24
* @returns {object } documentation object
18
25
*/
19
- export function parseFile ( filePath : string , documentation : Documentation , nameFilter ?: string [ ] ) {
20
- const source = fs . readFileSync ( filePath , {
26
+ export function parseFile ( documentation : Documentation , opt : ParseOptions ) {
27
+ const source = fs . readFileSync ( opt . filePath , {
21
28
encoding : 'utf-8' ,
22
29
} )
23
- return parseSource ( source , filePath , documentation , nameFilter )
30
+ return parseSource ( documentation , source , opt )
24
31
}
25
32
26
33
/**
@@ -29,13 +36,8 @@ export function parseFile(filePath: string, documentation: Documentation, nameFi
29
36
* @param {string } filePath path of the current file against whom to resolve the mixins
30
37
* @returns {object } documentation object
31
38
*/
32
- export function parseSource (
33
- source : string ,
34
- filePath : string ,
35
- documentation : Documentation ,
36
- nameFilter ?: string [ ] ,
37
- ) {
38
- const singleFileComponent = / \. v u e $ / i. test ( path . extname ( filePath ) )
39
+ export function parseSource ( documentation : Documentation , source : string , opt : ParseOptions ) {
40
+ const singleFileComponent = / \. v u e $ / i. test ( path . extname ( opt . filePath ) )
39
41
let parts : SFCDescriptor | null = null
40
42
41
43
if ( source === '' ) {
@@ -48,21 +50,22 @@ export function parseSource(
48
50
49
51
const scriptSource = parts ? ( parts . script ? parts . script . content : undefined ) : source
50
52
if ( scriptSource ) {
51
- const lang =
53
+ opt . lang =
52
54
( parts && parts . script && parts . script . attrs && parts . script . attrs . lang === 'ts' ) ||
53
- / \. t s x ? $ / i. test ( path . extname ( filePath ) )
55
+ / \. t s x ? $ / i. test ( path . extname ( opt . filePath ) )
54
56
? 'ts'
55
57
: 'js'
56
- parseScript ( scriptSource , documentation , handlers , { lang, filePath, nameFilter } )
58
+
59
+ parseScript ( scriptSource , documentation , handlers , opt )
57
60
}
58
61
59
62
// get slots from template
60
63
if ( parts && parts . template ) {
61
- parseTemplate ( parts . template , documentation , templateHandlers , filePath )
64
+ parseTemplate ( parts . template , documentation , templateHandlers , opt . filePath )
62
65
}
63
66
64
67
if ( ! documentation . get ( 'displayName' ) ) {
65
68
// a component should always have a display name
66
- documentation . set ( 'displayName' , path . basename ( filePath ) . replace ( / \. \w + $ / , '' ) )
69
+ documentation . set ( 'displayName' , path . basename ( opt . filePath ) . replace ( / \. \w + $ / , '' ) )
67
70
}
68
71
}
0 commit comments