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