Skip to content

Commit

Permalink
collectExports returns an object for components
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Apr 20, 2018
1 parent 4a75f7f commit e4dedd6
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 55 deletions.
13 changes: 9 additions & 4 deletions scripts/genDocs/utils/collectExports/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ const collectExports = filepath => {

//
return {
components: namedExports.concat(defaultExports).map(node => ({
name: node.name,
props: getPropTable(content, node.propDef, null)
}))
components: namedExports.concat(defaultExports).reduce(
(prev, node) => ({
...prev,
[node.name]: {
props: getPropTable(content, node.propDef, null)
}
}),
{}
)
}
}

Expand Down
91 changes: 41 additions & 50 deletions scripts/genDocs/utils/collectExports/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@ test('collects named arrow-function component exports', () => {
`)
)

expect(collectExports('root/quark-web/src/components/section/a.js').components).toEqual([
{
name: 'Foo',
props: {
a: {
value: 'string',
required: true,
nullable: false
}
expect(collectExports('root/quark-web/src/components/section/a.js').components.Foo).toEqual({
props: {
a: {
value: 'string',
required: true,
nullable: false
}
}
])
})
})

test('collects named class-based exports', () => {
Expand All @@ -42,18 +39,15 @@ test('collects named class-based exports', () => {
`)
)

expect(collectExports('root/quark-web/src/components/section/a.js').components).toEqual([
{
name: 'Foo',
props: {
a: {
value: 'string',
required: true,
nullable: false
}
expect(collectExports('root/quark-web/src/components/section/a.js').components.Foo).toEqual({
props: {
a: {
value: 'string',
required: true,
nullable: false
}
}
])
})
})

test('collects default component exports from arrow-function reference', () => {
Expand All @@ -72,18 +66,17 @@ test('collects default component exports from arrow-function reference', () => {
`)
)

expect(collectExports('root/quark-web/src/components/section/a.js').components).toEqual([
{
name: DEFAULT_EXPORT,
props: {
a: {
value: 'string',
required: true,
nullable: false
}
expect(
collectExports('root/quark-web/src/components/section/a.js').components[DEFAULT_EXPORT]
).toEqual({
props: {
a: {
value: 'string',
required: true,
nullable: false
}
}
])
})
})

test('collects default component exports from class reference', () => {
Expand All @@ -103,18 +96,17 @@ test('collects default component exports from class reference', () => {
`)
)

expect(collectExports('root/quark-web/src/components/section/a.js').components).toEqual([
{
name: DEFAULT_EXPORT,
props: {
a: {
value: 'string',
required: true,
nullable: false
}
expect(
collectExports('root/quark-web/src/components/section/a.js').components[DEFAULT_EXPORT]
).toEqual({
props: {
a: {
value: 'string',
required: true,
nullable: false
}
}
])
})
})

test('collects inline default component exports', () => {
Expand All @@ -131,18 +123,17 @@ test('collects inline default component exports', () => {
`)
)

expect(collectExports('root/quark-web/src/components/section/a.js').components).toEqual([
{
name: DEFAULT_EXPORT,
props: {
a: {
value: 'string',
required: true,
nullable: false
}
expect(
collectExports('root/quark-web/src/components/section/a.js').components[DEFAULT_EXPORT]
).toEqual({
props: {
a: {
value: 'string',
required: true,
nullable: false
}
}
])
})
})

test('collects type exports', () => {})
Expand Down
2 changes: 1 addition & 1 deletion scripts/genDocs/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './parse'
export collectDeclarations from './collectDeclarations'
export collectExports from './collectExports'
export getPropTable from './getPropTable'
export getLocation from './getLocation'

0 comments on commit e4dedd6

Please sign in to comment.