@@ -47,11 +47,7 @@ export function createTypings(moduleName: string|null, programAst: any, options:
4747 const tripleSlashDirectives : dom . TripleSlashDirective [ ] = [ ] ;
4848 const m = dom . create . module ( moduleName || 'moduleName' ) ;
4949
50- if ( hasReactClass ( ast , reactComponentName ) ) {
51- m . members . push ( dom . create . importNamed ( reactComponentName || 'Component' , reactImport ) ) ;
52- } else {
53- tripleSlashDirectives . push ( dom . create . tripleSlashReferenceTypesDirective ( 'react' ) ) ;
54- }
50+ m . members . push ( dom . create . importAll ( 'React' , reactImport ) ) ;
5551
5652 if ( importStatements . length > 0 ) {
5753 importStatements . forEach ( importStatement => {
@@ -104,18 +100,20 @@ function createExportedTypes(m: dom.ModuleDeclaration, ast: AstQuery, componentN
104100function createExportedClassComponent ( m : dom . ModuleDeclaration , componentName : string ,
105101 reactComponentName : string | undefined , exportType : dom . DeclarationFlags , interf : dom . InterfaceDeclaration ) : void {
106102 const classDecl = dom . create . class ( componentName ) ;
107- classDecl . baseType = dom . create . interface ( `${ reactComponentName || 'Component' } <${ interf . name } , any>` ) ;
103+ classDecl . baseType = dom . create . interface ( `React. ${ reactComponentName || 'Component' } <${ interf . name } , any>` ) ;
108104 classDecl . flags = exportType ;
109105 classDecl . members . push ( dom . create . method ( 'render' , [ ] , dom . create . namedTypeReference ( 'JSX.Element' ) ) ) ;
110106 m . members . push ( classDecl ) ;
111107}
112108
113109function createExportedFunctionalComponent ( m : dom . ModuleDeclaration , componentName : string , propTypes : any ,
114110 exportType : dom . DeclarationFlags , interf : dom . InterfaceDeclaration ) : void {
115- const funcDelc = dom . create . function ( componentName , propTypes ? [ dom . create . parameter ( 'props' , interf ) ] : [ ] ,
116- dom . create . namedTypeReference ( 'JSX.Element' ) ) ;
117- funcDelc . flags = exportType ;
118- m . members . push ( funcDelc ) ;
111+
112+ const typeDecl = dom . create . alias (
113+ componentName ,
114+ dom . create . namedTypeReference ( `React.SFC${ propTypes ? `<${ interf . name } >` : '' } ` ) ) ;
115+ typeDecl . flags = exportType ;
116+ m . members . push ( typeDecl ) ;
119117}
120118
121119function createPropTypeTypings ( interf : dom . InterfaceDeclaration , ast : AstQuery , propTypes : any ,
@@ -269,36 +267,6 @@ function getImportedPropTypes(ast: AstQuery): ImportedPropType[] {
269267 } ) ) ;
270268}
271269
272- function hasReactClass ( ast : AstQuery , reactComponentName : string | undefined ) : boolean {
273- const res = ast . query ( `
274- // ClassDeclaration[
275- '${ reactComponentName } ' == 'undefined'
276- ?
277- /:superClass MemberExpression[
278- /:object Identifier[@name == 'React'] &&
279- /:property Identifier[@name == 'Component']
280- ]
281- :
282- /:superClass Identifier[@name == '${ reactComponentName } ']
283- ]
284- ,
285- // VariableDeclaration
286- / VariableDeclarator[
287- /:init CallExpression[
288- '${ reactComponentName } ' == 'undefined'
289- ?
290- /:arguments MemberExpression[
291- /:object Identifier[@name == 'React'] &&
292- /:property Identifier[@name == 'Component']
293- ]
294- :
295- /:arguments Identifier[@name == '${ reactComponentName } ']
296- ]
297- ]
298- ` ) ;
299- return res . length > 0 ;
300- }
301-
302270function getInstanceOfPropTypes ( ast : AstQuery , importedPropTypes : ImportedPropTypes ) : string [ ] {
303271 const { propTypesName, propTypes} = importedPropTypes ;
304272 const instanceOfPropType = propTypes . find ( ( { importedName} ) => importedName === 'instanceOf' ) ;
0 commit comments