@@ -52,21 +52,23 @@ export interface Options {
52
52
export function cli ( options : any ) : void {
53
53
getStdin ( ) . then ( stdinCode => {
54
54
if ( options . topLevelModule ) {
55
- process . stdout . write ( generateFromSource ( null , stdinCode ) ) ;
55
+ process . stdout . write ( generateFromSource ( null , stdinCode , { } , options . reactImport || 'react' ) ) ;
56
56
} else if ( options . moduleName ) {
57
- process . stdout . write ( generateFromSource ( options . moduleName , stdinCode ) ) ;
57
+ process . stdout . write ( generateFromSource ( options . moduleName , stdinCode , { } , options . reactImport || 'react' ) ) ;
58
58
}
59
59
} ) ;
60
60
}
61
61
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 {
63
64
if ( ! options . filename ) {
64
65
options . filename = path ;
65
66
}
66
- return generateFromSource ( moduleName , fs . readFileSync ( path ) . toString ( ) , options ) ;
67
+ return generateFromSource ( moduleName , fs . readFileSync ( path ) . toString ( ) , options , reactImport ) ;
67
68
}
68
69
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 {
70
72
const ast = babylon . parse ( code , {
71
73
sourceType : 'module' ,
72
74
allowReturnOutsideFunction : true ,
@@ -92,12 +94,13 @@ export function generateFromSource(moduleName: string|null, code: string, option
92
94
if ( ! options . source ) {
93
95
options . source = code ;
94
96
}
95
- return generateFromAst ( moduleName , ast , options ) ;
97
+ return generateFromAst ( moduleName , ast , options , reactImport ) ;
96
98
}
97
99
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 {
99
102
if ( options . generator ) {
100
103
return generateTypings ( moduleName , ast , options ) ;
101
104
}
102
- return createTypings ( moduleName , ast , options ) ;
105
+ return createTypings ( moduleName , ast , options , reactImport ) ;
103
106
}
0 commit comments