From aaca7ee8d4b17aa1144399d168a9e3044b379afe Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Wed, 12 Feb 2020 00:11:48 +0000 Subject: [PATCH 01/70] Support for importing types by devongovett Squashed commit of the following: commit 3b3bbf63063b0d2f98d6c7cd87eee19e253b2d91 Author: Daniel Tschinder Date: Thu Nov 21 21:52:40 2019 +0100 Add additional test commit 048646d1cd726c0ba6fd84d8e9abffc0a7060a57 Author: Daniel Tschinder Date: Thu Nov 21 21:41:41 2019 +0100 Fix order of deps commit e69ef4f37271592f3b98a198931790fe7baa8a17 Author: Daniel Tschinder Date: Thu Nov 21 21:39:59 2019 +0100 Add mjs commit 26874eeb1507e13c52a681003c525baebb038289 Merge: 02649b7 b3601b6 Author: Daniel Tschinder Date: Fri Oct 25 22:25:43 2019 +0200 Merge branch 'master' into importing # Conflicts: # src/utils/isReactComponentClass.js commit 02649b700b73762d0576da10ec0cea1f3af6f715 Merge: 8c0a15f aa54200 Author: Daniel Tschinder Date: Fri Oct 25 22:21:51 2019 +0200 Merge branch 'master' into importing # Conflicts: # src/__tests__/__snapshots__/main-test.js.snap # src/__tests__/fixtures/component_28.tsx commit 8c0a15fcae4053b1d2115bd7dbd24252cf70b228 Author: Devon Govett Date: Sat May 4 17:56:04 2019 -0700 Missing typedef commit 08b5e7f7fd5b9ffacd2ce753f8f3ce6cd1a15bcb Author: Devon Govett Date: Sat May 4 17:45:34 2019 -0700 Fix lint commit c180af85a42cbb447dc265684fe0e06c2124a0bc Author: Devon Govett Date: Sat May 4 15:08:19 2019 -0700 Support named re-exports commit 80200c8f43513ab93b3acf1097098c3ae99491c0 Author: Devon Govett Date: Sat May 4 13:18:59 2019 -0700 Handle recursive imports commit 79a814f038df087b99fdad0e762150a0d0423a24 Author: Devon Govett Date: Sat May 4 13:09:16 2019 -0700 Support export all declaration commit 840ca88c3bcb5b0fb5b69edb55b1ac0f8b805876 Author: Devon Govett Date: Fri May 3 23:25:57 2019 -0700 Handle namespace imports commit 268b828e94abfe938234bf47585c95f3d9a2174d Author: Devon Govett Date: Fri May 3 22:51:00 2019 -0700 Add noop browser version of resolveImportedValue commit 00b3d350a89ddda3ec24ef3fcff4138fa51ba0e5 Author: Devon Govett Date: Sun Apr 28 21:59:00 2019 -0700 Initial support for importing prop types --- package.json | 4 + src/__tests__/__snapshots__/main-test.js.snap | 226 ++++++++++++++++++ src/__tests__/fixtures/component_27.tsx | 2 +- src/__tests__/fixtures/component_33.tsx | 17 ++ src/__tests__/fixtures/component_34.js | 13 + src/__tests__/fixtures/component_35.js | 10 + src/__tests__/fixtures/component_36.js | 9 + src/__tests__/fixtures/component_37.js | 9 + src/__tests__/fixtures/component_38.js | 8 + src/__tests__/fixtures/component_39.tsx | 21 ++ src/__tests__/fixtures/component_40.js | 16 ++ src/babelParser.js | 12 +- .../__tests__/propDocblockHandler-test.js | 2 +- src/utils/getMemberValuePath.js | 2 +- src/utils/isReactComponentClass.js | 2 +- src/utils/resolveImportedValue.browser.js | 4 + src/utils/resolveImportedValue.js | 127 ++++++++++ src/utils/resolveToModule.js | 2 +- src/utils/resolveToValue.js | 86 +++++-- yarn.lock | 7 + 20 files changed, 556 insertions(+), 23 deletions(-) create mode 100644 src/__tests__/fixtures/component_33.tsx create mode 100644 src/__tests__/fixtures/component_34.js create mode 100644 src/__tests__/fixtures/component_35.js create mode 100644 src/__tests__/fixtures/component_36.js create mode 100644 src/__tests__/fixtures/component_37.js create mode 100644 src/__tests__/fixtures/component_38.js create mode 100644 src/__tests__/fixtures/component_39.tsx create mode 100644 src/__tests__/fixtures/component_40.js create mode 100644 src/utils/resolveImportedValue.browser.js create mode 100644 src/utils/resolveImportedValue.js diff --git a/package.json b/package.json index cd5d87206ad..ec918c814da 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "doctrine": "^3.0.0", "neo-async": "^2.6.1", "node-dir": "^0.1.10", + "resolve": "^1.10.1", "strip-indent": "^3.0.0" }, "devDependencies": { @@ -83,5 +84,8 @@ "src" ], "testRegex": "/__tests__/.*-test\\.js$" + }, + "browser": { + "./dist/utils/resolveImportedValue.js": "./dist/utils/resolveImportedValue.browser.js" } } diff --git a/src/__tests__/__snapshots__/main-test.js.snap b/src/__tests__/__snapshots__/main-test.js.snap index 30c6605c57d..90fdbcfd3d9 100644 --- a/src/__tests__/__snapshots__/main-test.js.snap +++ b/src/__tests__/__snapshots__/main-test.js.snap @@ -1577,3 +1577,229 @@ Object { }, } `; + +exports[`main fixtures processes component "component_33.tsx" without errors 1`] = ` +Object { + "description": "This is a typescript component with imported prop types", + "displayName": "ImportedExtendedComponent", + "methods": Array [], + "props": Object { + "bar": Object { + "description": "", + "required": true, + "tsType": Object { + "name": "number", + }, + }, + "foo": Object { + "description": "", + "required": true, + "tsType": Object { + "name": "string", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_34.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "CustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "color": Object { + "description": "", + "required": false, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_35.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperCustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_36.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperDuperCustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_37.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperDuperCustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_38.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperDuperCustomButton", + "methods": Array [], + "props": Object { + "children": Object { + "description": "", + "required": true, + "type": Object { + "name": "string", + }, + }, + "onClick": Object { + "description": "", + "required": false, + "type": Object { + "name": "func", + }, + }, + "style": Object { + "description": "", + "required": false, + "type": Object { + "name": "object", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_39.tsx" without errors 1`] = ` +Object { + "description": "This is a typescript component with imported prop types", + "displayName": "ImportedComponent", + "methods": Array [], + "props": Object { + "foo": Object { + "description": "", + "required": true, + "tsType": Object { + "name": "string", + }, + }, + }, +} +`; + +exports[`main fixtures processes component "component_40.js" without errors 1`] = ` +Object { + "description": "", + "displayName": "SuperDuperCustomButton", + "methods": Array [], + "props": Object { + "size": Object { + "defaultValue": Object { + "computed": true, + "value": "Sizes.EXTRA_LARGE", + }, + "description": "", + "required": false, + "type": Object { + "computed": true, + "name": "enum", + "value": "Object.values(Sizes)", + }, + }, + }, +} +`; diff --git a/src/__tests__/fixtures/component_27.tsx b/src/__tests__/fixtures/component_27.tsx index ea49e8b716d..eb5cc2f3fed 100644 --- a/src/__tests__/fixtures/component_27.tsx +++ b/src/__tests__/fixtures/component_27.tsx @@ -8,7 +8,7 @@ import React, { Component } from 'react'; -interface Props { +export interface Props { foo: string } diff --git a/src/__tests__/fixtures/component_33.tsx b/src/__tests__/fixtures/component_33.tsx new file mode 100644 index 00000000000..0be4a2226a9 --- /dev/null +++ b/src/__tests__/fixtures/component_33.tsx @@ -0,0 +1,17 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +import React, { Component } from 'react'; +import ExtendedProps from './component_39'; + +/** + * This is a typescript component with imported prop types + */ +export function ImportedExtendedComponent(props: ExtendedProps) { + return

Hello world

; +} diff --git a/src/__tests__/fixtures/component_34.js b/src/__tests__/fixtures/component_34.js new file mode 100644 index 00000000000..4b227a5bc62 --- /dev/null +++ b/src/__tests__/fixtures/component_34.js @@ -0,0 +1,13 @@ +import Button from './component_6'; +import PropTypes from 'prop-types'; + +export function CustomButton({color, ...otherProps}) { + return