Skip to content
This repository was archived by the owner on Mar 8, 2019. It is now read-only.

Commit c61afc9

Browse files
committed
feat: add functional flag export
closes #85
1 parent 97808d2 commit c61afc9

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

src/Documentation.ts

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ export class Documentation {
147147
})
148148

149149
return {
150+
...obj,
150151
// initialize non null params
151152
description: obj.description || '',
152153
tags: obj.tags || {},

src/parse-template.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ export default function parseTemplate(
3131
rootLeadingCommentArray && rootLeadingCommentArray.length > 1
3232
? rootLeadingCommentArray[1].trim()
3333
: ''
34+
35+
const functional = !!tpl.attrs.functional
36+
if (functional) {
37+
documentation.set('functional', functional)
38+
}
3439
if (ast) {
3540
traverse(ast, documentation, handlers, {
36-
functional: !!tpl.attrs.functional,
41+
functional,
3742
rootLeadingComment,
3843
})
3944
}

src/script-handlers/__tests__/componentHandler.ts

+13
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,17 @@ describe('componentHandler', () => {
7676
version: [{ description: '12.5.7', title: 'version' }],
7777
})
7878
})
79+
80+
it('should detect functional flags', () => {
81+
const src = `
82+
export default {
83+
functional:true
84+
}
85+
`
86+
const def = parse(src).get('default')
87+
if (def) {
88+
componentHandler(documentation, def)
89+
}
90+
expect(documentation.set).toHaveBeenCalledWith('functional', true)
91+
})
7992
})

src/script-handlers/componentHandler.ts

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ import getDoclets from '../utils/getDoclets'
66
import transformTagsIntoObject from '../utils/transformTagsIntoObject'
77

88
export default function propHandler(documentation: Documentation, path: NodePath) {
9+
// deal with functional flag
10+
if (bt.isObjectExpression(path.node)) {
11+
const functionalPath = path
12+
.get('properties')
13+
.filter((p: NodePath) => bt.isObjectProperty(p.node) && p.node.key.name === 'functional')
14+
15+
if (functionalPath.length) {
16+
const functionalValue = functionalPath[0].get('value').node
17+
if (bt.isBooleanLiteral(functionalValue)) {
18+
documentation.set('functional', functionalValue.value)
19+
}
20+
}
21+
}
22+
923
let componentCommentedPath = path.parentPath
1024
// in case of Vue.extend() structure
1125
if (bt.isCallExpression(componentCommentedPath.node)) {

tests/components/button-functional/__snapshots__/button-functional.test.ts.snap

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Object {
55
"description": "",
66
"displayName": "MyButton",
77
"events": Object {},
8+
"functional": true,
89
"methods": Array [],
910
"props": Object {
1011
"default": Object {

0 commit comments

Comments
 (0)