@@ -52,21 +52,23 @@ export interface Options {
5252export function cli ( options : any ) : void {
5353 getStdin ( ) . then ( stdinCode => {
5454 if ( options . topLevelModule ) {
55- process . stdout . write ( generateFromSource ( null , stdinCode ) ) ;
55+ process . stdout . write ( generateFromSource ( null , stdinCode , { } , options . reactImport || 'react' ) ) ;
5656 } else if ( options . moduleName ) {
57- process . stdout . write ( generateFromSource ( options . moduleName , stdinCode ) ) ;
57+ process . stdout . write ( generateFromSource ( options . moduleName , stdinCode , { } , options . reactImport || 'react' ) ) ;
5858 }
5959 } ) ;
6060}
6161
62- export function generateFromFile ( moduleName : string | null , path : string , options : IOptions = { } ) : string {
62+ export function generateFromFile ( moduleName : string | null , path : string , options : IOptions = { } ,
63+ reactImport = 'react' ) : string {
6364 if ( ! options . filename ) {
6465 options . filename = path ;
6566 }
66- return generateFromSource ( moduleName , fs . readFileSync ( path ) . toString ( ) , options ) ;
67+ return generateFromSource ( moduleName , fs . readFileSync ( path ) . toString ( ) , options , reactImport ) ;
6768}
6869
69- export function generateFromSource ( moduleName : string | null , code : string , options : IOptions = { } ) : string {
70+ export function generateFromSource ( moduleName : string | null , code : string , options : IOptions = { } ,
71+ reactImport = 'react' ) : string {
7072 const ast = babylon . parse ( code , {
7173 sourceType : 'module' ,
7274 allowReturnOutsideFunction : true ,
@@ -92,12 +94,13 @@ export function generateFromSource(moduleName: string|null, code: string, option
9294 if ( ! options . source ) {
9395 options . source = code ;
9496 }
95- return generateFromAst ( moduleName , ast , options ) ;
97+ return generateFromAst ( moduleName , ast , options , reactImport ) ;
9698}
9799
98- export function generateFromAst ( moduleName : string | null , ast : any , options : IOptions = { } ) : string {
100+ export function generateFromAst ( moduleName : string | null , ast : any , options : IOptions = { } ,
101+ reactImport = 'react' ) : string {
99102 if ( options . generator ) {
100103 return generateTypings ( moduleName , ast , options ) ;
101104 }
102- return createTypings ( moduleName , ast , options ) ;
105+ return createTypings ( moduleName , ast , options , reactImport ) ;
103106}
0 commit comments