From 07407006438e86916160f849ce9410b1344240bc Mon Sep 17 00:00:00 2001 From: liuyuan Date: Thu, 19 Dec 2024 11:05:48 +0800 Subject: [PATCH] feat: set esModuleInterop as default config --- package-lock.json | 4 ++-- .../FunctionalComponentWithDefaultImportReact.tsx | 13 +++++++++++++ src/__tests__/data/tsconfig.json | 1 + src/__tests__/parser.ts | 8 ++++++++ src/parser.ts | 3 ++- 5 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 src/__tests__/data/FunctionalComponentWithDefaultImportReact.tsx diff --git a/package-lock.json b/package-lock.json index 03dfe837..4dc8ac84 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "react-docgen-typescript", - "version": "2.2.3", + "version": "2.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "react-docgen-typescript", - "version": "2.2.3", + "version": "2.3.0", "license": "MIT", "devDependencies": { "@types/chai": "^4.1.0", diff --git a/src/__tests__/data/FunctionalComponentWithDefaultImportReact.tsx b/src/__tests__/data/FunctionalComponentWithDefaultImportReact.tsx new file mode 100644 index 00000000..ee335fa4 --- /dev/null +++ b/src/__tests__/data/FunctionalComponentWithDefaultImportReact.tsx @@ -0,0 +1,13 @@ +import React from 'react'; + +export interface JumbotronProps { + /** prop1 description */ + prop1: string; +} + +/** + * Jumbotron description + */ +export const Jumbotron: React.FC = props => { + return
Test
; +}; diff --git a/src/__tests__/data/tsconfig.json b/src/__tests__/data/tsconfig.json index 0c90c796..d0b75668 100644 --- a/src/__tests__/data/tsconfig.json +++ b/src/__tests__/data/tsconfig.json @@ -3,6 +3,7 @@ /* Basic Options */ "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'. */ "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ + "esModuleInterop": true, // "lib": [], /* Specify library files to be included in the compilation: */ // "allowJs": true, /* Allow javascript files to be compiled. */ // "checkJs": true, /* Report errors in .js files. */ diff --git a/src/__tests__/parser.ts b/src/__tests__/parser.ts index 16f9cfb7..e0db9b88 100644 --- a/src/__tests__/parser.ts +++ b/src/__tests__/parser.ts @@ -776,6 +776,14 @@ describe('parser', () => { }); }); + it('should parse functional component declared as React.FC with default import from react', () => { + check('FunctionalComponentWithDefaultImportReact', { + Jumbotron: { + prop1: { type: 'string', required: true } + } + }); + }); + it('should parse functional component defined as const with default value assignments in immediately destructured props', () => { check('FunctionalComponentWithDesctructuredProps', { FunctionalComponentWithDesctructuredProps: { diff --git a/src/parser.ts b/src/parser.ts index d21f31f9..0be4d448 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -113,7 +113,8 @@ export interface FileParser { export const defaultOptions: ts.CompilerOptions = { jsx: ts.JsxEmit.React, module: ts.ModuleKind.CommonJS, - target: ts.ScriptTarget.Latest + target: ts.ScriptTarget.Latest, + esModuleInterop: true }; /**