Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 1dca59c

Browse files
authored
fix: allow empty or non-export input files (#213)
This fixes the behaviour of throwing if no export or propType definition was found in the given file. This reverts the error behaviour to the state of 0.13 FIX #212
1 parent 25737ff commit 1dca59c

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Diff for: src/generate-typigns.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export function generateTypings(moduleName: string|null, parsingResult: IParsing
2222
m.members.push(interf);
2323

2424
if (classname) {
25-
m.members.push(createReactClassDeclaration(componentName, exportType, propTypes, interf));
25+
m.members.push(createReactClassDeclaration(componentName, exportType as ExportType, propTypes, interf));
2626
} else if (functionname) {
27-
m.members.push(createReactFunctionDeclaration(componentName, exportType, interf));
27+
m.members.push(createReactFunctionDeclaration(componentName, exportType as ExportType, interf));
2828
}
2929

3030
if (moduleName === null) {

Diff for: src/index.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ export function generateFromSource(moduleName: string|null, code: string, option
110110

111111
export function generateFromAst(moduleName: string|null, ast: any, options: IOptions = {}): string {
112112
const parsingResult = parseAst(ast, options.instanceOfResolver);
113+
if (parsingResult.exportType === undefined) {
114+
return '';
115+
}
113116
if (options.generator) {
114117
return deprecatedGenerator(options.generator, moduleName, parsingResult);
115118
}
@@ -132,7 +135,7 @@ function deprecatedGenerator(generator: Generator, moduleName: string|null,
132135
generator.nl();
133136
generator.props(componentName, propTypes);
134137
generator.nl();
135-
generator.exportDeclaration(exportType, () => {
138+
generator.exportDeclaration(exportType as ExportType, () => {
136139
generator.class(componentName, !!propTypes);
137140
});
138141
};
@@ -154,7 +157,7 @@ export enum ExportType {
154157
* @internal
155158
*/
156159
export interface IParsingResult {
157-
exportType: ExportType;
160+
exportType: ExportType|undefined;
158161
classname: string|undefined;
159162
functionname: string|undefined;
160163
propTypes: IPropTypes;
@@ -208,9 +211,6 @@ function parseAst(ast: any, instanceOfResolver?: InstanceOfResolver): IParsingRe
208211
}
209212
}
210213

211-
if (exportType === undefined) {
212-
throw new Error('No exported component found');
213-
}
214214
return {
215215
exportType,
216216
classname,

0 commit comments

Comments
 (0)