1 1
import * as bt from '@babel/types'
2
import { NodePath } from 'ast-types/lib/node-path'
3
import Documentation, { ParamTag, ParamType, Tag } from '../Documentation'
4 1
import getDoclets from '../utils/getDoclets'
5 1
import getProperties from './utils/getProperties'
6 1
import getDocblock from '../utils/getDocblock'
7

8
export interface TypedParamTag extends ParamTag {
9
	type: ParamType
10
}
11

12
/**
13
 * Extract slots information form the render function of an object-style VueJs component
14
 * @param documentation
15
 * @param path
16
 */
17 1
export default function slotHandler(documentation: Documentation, path: NodePath): Promise<void> {
18 1
	if (bt.isObjectExpression(path.node)) {
19 1
		const renderPath = getProperties(path, 'render')
20

21 1
		if (!renderPath.length) {
22 1
			return Promise.resolve()
23
		}
24

25 1
		let i = 0
26 1
		let docBlock = getDocblock(renderPath[0], { commentIndex: i })
27 1
		while (docBlock) {
28
			// if no doc block return
29 1
			if (!docBlock || !docBlock.length) {
30 0
				return Promise.resolve()
31
			}
32

33 1
			const jsDoc = getDoclets(docBlock)
34 1
			if (jsDoc.tags) {
35 1
				const slotTag = jsDoc.tags.find(a => a.title === 'slot') as Tag
36 1
				if (slotTag) {
37 1
					const name = typeof slotTag.content === 'string' ? slotTag.content : 'default'
38 1
					const slotDescriptor = documentation.getSlotDescriptor(name)
39 1
					slotDescriptor.description = jsDoc.description
40 1
					const bindingsTag = jsDoc.tags.filter(t => t.title === 'binding') as ParamTag[]
41 1
					if (bindingsTag) {
42 1
						slotDescriptor.bindings = bindingsTag
43
					}
44
				}
45
			}
46 1
			docBlock = getDocblock(renderPath[0], { commentIndex: ++i })
47
		}
48
	}
49 1
	return Promise.resolve()
50
}

Read our documentation on viewing source code .

Loading