Skip to content

Commit

Permalink
feat(gatsby-transformer-react-docgen): upgrade to react-docgen… (#16094)
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense authored and sidharthachatterjee committed Aug 9, 2019
1 parent d5ba6cc commit 16f7670
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/gatsby-transformer-react-docgen/package.json
Expand Up @@ -11,7 +11,7 @@
"@babel/runtime": "^7.0.0",
"@babel/types": "^7.0.0",
"common-tags": "^1.4.0",
"react-docgen": "^4.1.0",
"react-docgen": "^5.0.0-beta.1",
"react-docgen-displayname-handler": " ^2.1.0"
},
"devDependencies": {
Expand Down
@@ -0,0 +1,138 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`transformer-react-doc-gen: onCreateNode flowTypes should add flow type info: flow types 1`] = `
Array [
Object {
"name": "number",
},
Object {
"elements": Array [
Object {
"name": "literal",
"value": "\\"string\\"",
},
Object {
"name": "literal",
"value": "\\"otherstring\\"",
},
Object {
"name": "number",
},
],
"name": "union",
"raw": "\\"string\\" | \\"otherstring\\" | number",
},
Object {
"elements": Array [
Object {
"name": "any",
},
],
"name": "Array",
"raw": "Array<any>",
},
Object {
"name": "signature",
"raw": "(value: string) => void",
"signature": Object {
"arguments": Array [
Object {
"name": "value",
"type": Object {
"name": "string",
},
},
],
"return": Object {
"name": "void",
},
},
"type": "function",
},
Object {
"name": "signature",
"raw": "{ subvalue: ?boolean }",
"signature": Object {
"properties": Array [
Object {
"key": "subvalue",
"value": Object {
"name": "boolean",
"nullable": true,
"required": true,
},
},
],
},
"type": "object",
},
]
`;

exports[`transformer-react-doc-gen: onCreateNode tsTypes should add TS type info: typescript types 1`] = `
Array [
Object {
"name": "number",
},
Object {
"elements": Array [
Object {
"name": "literal",
"value": "string",
},
Object {
"name": "literal",
"value": "otherstring",
},
Object {
"name": "number",
},
],
"name": "union",
"raw": "\\"string\\" | \\"otherstring\\" | number",
},
Object {
"elements": Array [
Object {
"name": "any",
},
],
"name": "Array",
"raw": "Array<any>",
},
Object {
"name": "signature",
"raw": "(value: string) => void",
"signature": Object {
"arguments": Array [
Object {
"name": "value",
"type": Object {
"name": "string",
},
},
],
"return": Object {
"name": "void",
},
},
"type": "function",
},
Object {
"name": "signature",
"raw": "{ subvalue: boolean }",
"signature": Object {
"properties": Array [
Object {
"key": "subvalue",
"value": Object {
"name": "boolean",
"required": true,
},
},
],
},
"type": "object",
},
]
`;
@@ -0,0 +1,27 @@
import React, { Component } from "react"

interface Props {
/** Description of prop "foo". */
primitive: number
/** Description of prop "bar". */
literalsAndUnion: "string" | "otherstring" | number
arr: Array<any>
func?: (value: string) => void
obj?: { subvalue: boolean }
}

const foo: number = 1 as const
/**
* General component description.
*/
export default class MyComponent extends Component<Props, void> {
props: Props

render(): ReactElement {
// ...
}
}

export function Foo(props: Props) {
return <div />
}
Expand Up @@ -193,11 +193,28 @@ describe(`transformer-react-doc-gen: onCreateNode`, () => {
})
it(`should add flow type info`, async () => {
await run(node)
const created = createdNodes.find(f => !!f.flowType)

expect(created.flowType).toEqual({
name: `number`,
const created = createdNodes.map(f => f.flowType).filter(Boolean)

expect(created).toMatchSnapshot(`flow types`)
})
})

describe(`tsTypes`, () => {
beforeEach(() => {
node.__fixture = `typescript.tsx`
})

it(`should add TS type info`, async () => {
await run(node, {
parserOpts: {
plugins: [`jsx`, `typescript`, `classProperties`],
},
})

const created = createdNodes.map(f => f.tsType).filter(Boolean)

expect(created).toMatchSnapshot(`typescript types`)
})
})
})
Expand Up @@ -93,6 +93,7 @@ function extendProp() {
return {
type: { type: PropTypeValue },
flowType: { type: GraphQLJSON },
tsType: { type: GraphQLJSON },
defaultValue: { type: PropDefaultValue },
doclets: { type: GraphQLJSON },
docblock: {
Expand Down
90 changes: 70 additions & 20 deletions yarn.lock
Expand Up @@ -37,6 +37,13 @@
dependencies:
"@babel/highlight" "^7.0.0"

"@babel/code-frame@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d"
integrity sha512-27d4lZoomVyo51VegxI20xZPuSHusqbQag/ztrBC7wegWoQ1nLREPVSKSW8byhTlzTKyNE4ifaTA6lCp7JjpFw==
dependencies:
"@babel/highlight" "^7.0.0"

"@babel/core@^7.0.0":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.0.1.tgz#406658caed0e9686fa4feb5c2f3cefb6161c0f41"
Expand Down Expand Up @@ -133,6 +140,26 @@
semver "^5.4.1"
source-map "^0.5.0"

"@babel/core@^7.4.4":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/core/-/core-7.5.5.tgz#17b2686ef0d6bc58f963dddd68ab669755582c30"
integrity sha512-i4qoSr2KTtce0DmkuuQBV4AuQgGPUcPXMr9L5MyYAtk06z068lQ10a4O009fe5OB/DfNV+h+qqT7ddNV8UnRjg==
dependencies:
"@babel/code-frame" "^7.5.5"
"@babel/generator" "^7.5.5"
"@babel/helpers" "^7.5.5"
"@babel/parser" "^7.5.5"
"@babel/template" "^7.4.4"
"@babel/traverse" "^7.5.5"
"@babel/types" "^7.5.5"
convert-source-map "^1.1.0"
debug "^4.1.0"
json5 "^2.1.0"
lodash "^4.17.13"
resolve "^1.3.2"
semver "^5.4.1"
source-map "^0.5.0"

"@babel/generator@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.0.0.tgz#1efd58bffa951dc846449e58ce3a1d7f02d393aa"
Expand Down Expand Up @@ -186,7 +213,7 @@

"@babel/generator@^7.5.5":
version "7.5.5"
resolved "https://registry.npmjs.org/@babel/generator/-/generator-7.5.5.tgz#873a7f936a3c89491b43536d12245b626664e3cf"
resolved "https://registry.yarnpkg.com/@babel/generator/-/generator-7.5.5.tgz#873a7f936a3c89491b43536d12245b626664e3cf"
integrity sha512-ETI/4vyTSxTzGnU2c49XHv2zhExkv9JHLTwDAFz85kmcwuShvYG2H08FwgIguQf4JC75CBnXAUM5PqeF4fj0nQ==
dependencies:
"@babel/types" "^7.5.5"
Expand Down Expand Up @@ -567,6 +594,15 @@
"@babel/traverse" "^7.4.4"
"@babel/types" "^7.4.4"

"@babel/helpers@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/helpers/-/helpers-7.5.5.tgz#63908d2a73942229d1e6685bc2a0e730dde3b75e"
integrity sha512-nRq2BUhxZFnfEn/ciJuhklHvFOqjJUD5wpx+1bxUF2axL9C+v4DE/dmp5sT2dKnpOs4orZWzpAZqlCy8QqE/7g==
dependencies:
"@babel/template" "^7.4.4"
"@babel/traverse" "^7.5.5"
"@babel/types" "^7.5.5"

"@babel/highlight@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/highlight/-/highlight-7.0.0.tgz#f710c38c8d458e6dd9a201afb637fcb781ce99e4"
Expand Down Expand Up @@ -616,6 +652,11 @@
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.4.5.tgz#04af8d5d5a2b044a2a1bffacc1e5e6673544e872"
integrity sha512-9mUqkL1FF5T7f0WDFfAoDdiMVPWsdD1gZYzSnaXsxUCUqzuch/8of9G3VUSNiZmMBoRxT3neyVsqeiL/ZPcjew==

"@babel/parser@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.5.5.tgz#02f077ac8817d3df4a832ef59de67565e71cca4b"
integrity sha512-E5BN68cqR7dhKan1SfqgPGhQ178bkVKpXTPEXnFJBrEt8/DKRZlybmy+IgYLTeN7tp1R5Ccmbm2rBk17sHYU3g==

"@babel/plugin-proposal-async-generator-functions@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/plugin-proposal-async-generator-functions/-/plugin-proposal-async-generator-functions-7.0.0.tgz#5d1eb6b44fd388b97f964350007ab9da090b1d70"
Expand Down Expand Up @@ -2042,6 +2083,21 @@
globals "^11.1.0"
lodash "^4.17.11"

"@babel/traverse@^7.5.5":
version "7.5.5"
resolved "https://registry.yarnpkg.com/@babel/traverse/-/traverse-7.5.5.tgz#f664f8f368ed32988cd648da9f72d5ca70f165bb"
integrity sha512-MqB0782whsfffYfSjH4TM+LMjrJnhCNEDMDIjeTpl+ASaUvxcjoiVCo/sM1GhS1pHOXYfWVCYneLjMckuUxDaQ==
dependencies:
"@babel/code-frame" "^7.5.5"
"@babel/generator" "^7.5.5"
"@babel/helper-function-name" "^7.1.0"
"@babel/helper-split-export-declaration" "^7.4.4"
"@babel/parser" "^7.5.5"
"@babel/types" "^7.5.5"
debug "^4.1.0"
globals "^11.1.0"
lodash "^4.17.13"

"@babel/types@^7.0.0", "@babel/types@^7.0.0-beta.49":
version "7.0.0"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.0.0.tgz#6e191793d3c854d19c6749989e3bc55f0e962118"
Expand Down Expand Up @@ -2085,7 +2141,7 @@

"@babel/types@^7.5.5":
version "7.5.5"
resolved "https://registry.npmjs.org/@babel/types/-/types-7.5.5.tgz#97b9f728e182785909aa4ab56264f090a028d18a"
resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.5.5.tgz#97b9f728e182785909aa4ab56264f090a028d18a"
integrity sha512-s63F9nJioLqOlW3UkyMd+BYhXt44YuaFm/VV0VwuteqjYwRrObkU7ra9pY4wAJR3oXi8hJrMcrcJdO/HH33vtw==
dependencies:
esutils "^2.0.2"
Expand Down Expand Up @@ -4021,9 +4077,10 @@ ast-types@0.11.5:
version "0.11.5"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.11.5.tgz#9890825d660c03c28339f315e9fa0a360e31ec28"

ast-types@0.12.2:
version "0.12.2"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.12.2.tgz#341656049ee328ac03fc805c156b49ebab1e4462"
ast-types@^0.12.4:
version "0.12.4"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.12.4.tgz#71ce6383800f24efc9a1a3308f3a6e420a0974d1"
integrity sha512-ky/YVYCbtVAS8TdMIaTiPFHwEpRB5z1hctepJplTr3UW5q8TDrpIMCILyk8pmLxGtn2KCtC/lSn7zOsaI7nzDw==

ast-types@^0.7.0:
version "0.7.8"
Expand Down Expand Up @@ -13965,7 +14022,7 @@ lodash@^4.11.1, lodash@^4.11.2, lodash@^4.13.1, lodash@^4.15.0, lodash@^4.17.10,

lodash@^4.17.13:
version "4.17.15"
resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.15.tgz#b447f6670a0455bbfeedd11392eff330ea097548"
integrity sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==

lodash@^4.17.14:
Expand Down Expand Up @@ -17209,17 +17266,19 @@ react-dev-utils@^4.2.3:
dependencies:
ast-types "0.11.5"

react-docgen@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/react-docgen/-/react-docgen-4.1.0.tgz#218887feba5b2c36af337879a27e74bda90ed7cb"
react-docgen@^5.0.0-beta.1:
version "5.0.0-beta.1"
resolved "https://registry.yarnpkg.com/react-docgen/-/react-docgen-5.0.0-beta.1.tgz#3654ab8f5cb7abacbfc122c1950c45d8e77048da"
integrity sha512-CbbHF5jXrgyXuP3gQcN1zG4YpNj5QQuxTsEhKH3UXQN01V4cho/eL926ya6ecCWryUtlK97QGRxtK48KbCtXEQ==
dependencies:
"@babel/core" "^7.0.0"
"@babel/core" "^7.4.4"
"@babel/runtime" "^7.0.0"
ast-types "^0.12.4"
async "^2.1.4"
commander "^2.19.0"
doctrine "^3.0.0"
node-dir "^0.1.10"
recast "^0.17.3"
strip-indent "^2.0.0"

react-dom@^16.4.2, react-dom@^16.8.4, react-dom@^16.8.6:
version "16.8.6"
Expand Down Expand Up @@ -17492,15 +17551,6 @@ recast@^0.15.0:
private "~0.1.5"
source-map "~0.6.1"

recast@^0.17.3:
version "0.17.3"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.17.3.tgz#f49a9c9a64c59b55f6c93b5a53e3cffd7a13354d"
dependencies:
ast-types "0.12.2"
esprima "~4.0.0"
private "^0.1.8"
source-map "~0.6.1"

rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
Expand Down

0 comments on commit 16f7670

Please sign in to comment.