@@ -2,19 +2,47 @@ import * as fs from 'fs'
22import * as path from 'path'
33import { parseComponent , SFCDescriptor } from 'vue-template-compiler'
44import { Documentation } from './Documentation'
5- import parseScript from './parse-script'
6- import parseTemplate from './parse-template'
7- import handlers from './script-handlers'
5+ import parseScript , { Handler as ScriptHandler } from './parse-script'
6+ import parseTemplate , { Handler as TemplateHandler } from './parse-template'
7+ import scriptHandlers from './script-handlers'
88import templateHandlers from './template-handlers'
99import cacher from './utils/cacher'
1010
1111const ERROR_EMPTY_DOCUMENT = 'The passed source is empty'
1212
13- export interface ParseOptions {
13+ export { ScriptHandler , TemplateHandler }
14+
15+ export interface ParseOptions extends DocGenOptions {
1416 filePath : string
17+ /**
18+ * In what language is the component written
19+ * @default undefined - let the system decide
20+ */
1521 lang ?: 'ts' | 'js'
22+ }
23+
24+ export interface DocGenOptions {
25+ /**
26+ * Which exported variables should be looked at
27+ * @default undefined - means treat all dependencies
28+ */
1629 nameFilter ?: string [ ]
17- aliases ?: { [ alias : string ] : string }
30+ /**
31+ * What alias should be replaced in requires and imports
32+ */
33+ alias ?: { [ alias : string ] : string }
34+ /**
35+ * What directories should be searched when resolving modules
36+ */
37+ modules ?: string [ ]
38+ /**
39+ * Handlers that will be added at the end of the script analysis
40+ */
41+ addScriptHandlers ?: ScriptHandler [ ]
42+ /**
43+ * Handlers that will be added at the end of the template analysis
44+ */
45+ addTemplateHandlers ?: TemplateHandler [ ]
1846}
1947
2048/**
@@ -50,7 +78,13 @@ export function parseSource(documentation: Documentation, source: string, opt: P
5078
5179 // get slots and props from template
5280 if ( parts && parts . template ) {
53- parseTemplate ( parts . template , documentation , templateHandlers , opt . filePath )
81+ const addTemplateHandlers : TemplateHandler [ ] = opt . addTemplateHandlers || [ ]
82+ parseTemplate (
83+ parts . template ,
84+ documentation ,
85+ [ ...templateHandlers , ...addTemplateHandlers ] ,
86+ opt . filePath ,
87+ )
5488 }
5589
5690 const scriptSource = parts ? ( parts . script ? parts . script . content : undefined ) : source
@@ -60,8 +94,8 @@ export function parseSource(documentation: Documentation, source: string, opt: P
6094 / \. t s x ? $ / i. test ( path . extname ( opt . filePath ) )
6195 ? 'ts'
6296 : 'js'
63-
64- parseScript ( scriptSource , documentation , handlers , opt )
97+ const addScriptHandlers : ScriptHandler [ ] = opt . addScriptHandlers || [ ]
98+ parseScript ( scriptSource , documentation , [ ... scriptHandlers , ... addScriptHandlers ] , opt )
6599 }
66100
67101 if ( ! documentation . get ( 'displayName' ) ) {
0 commit comments