@@ -12,6 +12,9 @@ import * as tsickle from './tsickle';
12
12
interface Settings {
13
13
/** If provided, path to save externs to. */
14
14
externsPath ? : string ;
15
+
16
+ /** If provided, convert every type to the Closure {?} type */
17
+ isUntyped: boolean ;
15
18
}
16
19
17
20
function usage ( ) {
@@ -22,6 +25,7 @@ example:
22
25
23
26
tsickle flags are:
24
27
--externs=PATH save generated Closure externs.js to PATH
28
+ --untyped convert every type in TypeScript to the Closure {?} type
25
29
` ) ;
26
30
}
27
31
@@ -30,7 +34,7 @@ tsickle flags are:
30
34
* the arguments to pass on to tsc.
31
35
*/
32
36
function loadSettingsFromArgs ( args : string [ ] ) : { settings: Settings , tscArgs : string [ ] } {
33
- let settings : Settings = { } ;
37
+ let settings : Settings = { isUntyped : false } ;
34
38
let parsedArgs = minimist ( args ) ;
35
39
for ( let flag of Object . keys ( parsedArgs ) ) {
36
40
switch ( flag ) {
@@ -42,6 +46,9 @@ function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: str
42
46
case 'externs' :
43
47
settings . externsPath = parsedArgs [ flag ] ;
44
48
break ;
49
+ case 'untyped' :
50
+ settings . isUntyped = true ;
51
+ break ;
45
52
case '_' :
46
53
// This is part of the minimist API, and holds args after the '--'.
47
54
break ;
@@ -129,7 +136,7 @@ function createSourceReplacingCompilerHost(
129
136
* Compiles TypeScript code into Closure-compiler-ready JS.
130
137
* Doesn't write any files to disk; all JS content is returned in a map.
131
138
*/
132
- function toClosureJS ( options : ts . CompilerOptions , fileNames : string [ ] ) :
139
+ function toClosureJS ( options : ts . CompilerOptions , fileNames : string [ ] , isUntyped : boolean ) :
133
140
{ jsFiles ?: { [ fileName : string ] : string } , externs ?: string , errors ?: ts . Diagnostic [ ] } {
134
141
// Parse and load the program without tsickle processing.
135
142
// This is so:
@@ -141,10 +148,8 @@ function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
141
148
return { errors} ;
142
149
}
143
150
144
- // TODO(evanm): let the user configure tsickle options via the command line.
145
- // Or, better, just make tsickle always work without needing any options.
146
151
const tsickleOptions : tsickle . Options = {
147
- untyped : true ,
152
+ untyped : isUntyped ,
148
153
} ;
149
154
150
155
// Process each input file with tsickle and save the output.
@@ -201,7 +206,7 @@ function main(args: string[]) {
201
206
// Run tsickle+TSC to convert inputs to Closure JS files.
202
207
let jsFiles : { [ fileName : string ] : string } ;
203
208
let externs : string ;
204
- ( { jsFiles, externs, errors} = toClosureJS ( options , fileNames ) ) ;
209
+ ( { jsFiles, externs, errors} = toClosureJS ( options , fileNames , settings . isUntyped ) ) ;
205
210
if ( errors && errors . length > 0 ) {
206
211
console . error ( tsickle . formatDiagnostics ( errors ) ) ;
207
212
process . exit ( 1 ) ;
0 commit comments