Skip to content

Commit 8339740

Browse files
committed
fix: support null and any return type
1 parent b3c3e2a commit 8339740

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

@plotly/dash-generator-test-component-typescript/package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

@plotly/dash-generator-test-component-typescript/src/components/WrappedHTML.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import {WrappedHTMLProps} from '../props';
2+
import { WrappedHTMLProps } from '../props';
33

44
/**
55
* Component docstring

@plotly/dash-generator-test-component-typescript/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ export {
1717
FCComponent,
1818
EmptyComponent,
1919
MixedComponent,
20-
RequiredChildrenComponent,
20+
RequiredChildrenComponent
2121
};

dash/extract-meta.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -726,22 +726,23 @@ function gatherComponents(sources, components = {}) {
726726
}
727727
}
728728

729-
const isArrowFunction = typeSymbol.declarations && typeSymbol.declarations[0].kind === ts.SyntaxKind.ArrowFunction
729+
const isArrowFunction = ts.isArrowFunction(declaration)
730730
const isClass = ts.isClassDeclaration(declaration);
731+
const isFunction = ts.isFunctionDeclaration(declaration)
731732

732-
if (!isArrowFunction && !isClass) {
733+
if (!isArrowFunction && !isClass && !isFunction) {
733734
// we do not care about these exports
734735
return null
735736
}
736737

737-
// if (isArrowFunction) {
738-
// const signature = checker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
739-
// const returnType = checker.typeToString(signature.getReturnType());
740-
// if (returnType !== 'Element') {
741-
// // Not JSX so no need to classifiy as compnent
742-
// return null;
743-
// }
744-
// }
738+
if (isArrowFunction || isFunction) {
739+
const signature = checker.getSignaturesOfType(type, ts.SignatureKind.Call)[0];
740+
const returnType = checker.typeToString(signature.getReturnType());
741+
if (!['Element', 'any', 'null'].includes(returnType)) {
742+
// Not JSX so no need to classifiy as compnent
743+
return null;
744+
}
745+
}
745746

746747
let defaultProps = getDefaultProps(typeSymbol, source);
747748
const propsType = getPropsForFunctionalComponent(type);

0 commit comments

Comments
 (0)