Skip to content

Commit

Permalink
fix(docz-core): async plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed May 15, 2018
1 parent 4ac6d7e commit ddfbcf1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/docz-core/src/utils/plugin-hast.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import visit from 'unist-util-visit'
import is from 'unist-util-is'
import nodeToString from 'hast-util-to-string'

import { format } from '../utils/format'
Expand Down Expand Up @@ -41,11 +41,15 @@ const addComponentsProp = (node: any) => {
}
}

export const plugin = () => async (tree: any, file: any) => {
visit(tree, 'jsx', visitor)

async function visitor(node: any, idx: any, parent: any): Promise<void> {
export const plugin = () => (tree: any, file: any) => {
async function visitor(node: any): Promise<void> {
await addCodeProp(node)
addComponentsProp(node)
}

const nodes = [
tree.children.filter((node: any) => is('jsx', node)).map(visitor),
]

return Promise.all(nodes).then(() => tree)
}

0 comments on commit ddfbcf1

Please sign in to comment.