Skip to content

Commit 972d283

Browse files
author
James Judd
committed
Configure typed/untyped converstion from the CLI and default to typed
tsickle was defaulting to untyped conversions, i.e., every TypeScript type was converted to the Closure {?} type. Now it defaults to typed and allows the user to configure whether types should be converted to {?} or an actual type.
1 parent 60e669c commit 972d283

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/main.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ const internalExternsFileName = 'tsickle_externs.js';
1919
interface Settings {
2020
/** If provided, path to save externs to. */
2121
externsPath?: string;
22+
23+
/** If provided, convert every type to the Closure {?} type */
24+
isTyped: boolean;
2225
}
2326

2427
function usage() {
@@ -29,6 +32,7 @@ example:
2932
3033
tsickle flags are:
3134
--externs=PATH save generated Closure externs.js to PATH
35+
--untyped convert every type in TypeScript to the Closure {?} type
3236
`);
3337
}
3438

@@ -37,7 +41,7 @@ tsickle flags are:
3741
* the arguments to pass on to tsc.
3842
*/
3943
function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: string[]} {
40-
let settings: Settings = {};
44+
let settings: Settings = {isTyped: true};
4145
let parsedArgs = minimist(args);
4246
for (let flag of Object.keys(parsedArgs)) {
4347
switch (flag) {
@@ -49,6 +53,9 @@ function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: str
4953
case 'externs':
5054
settings.externsPath = parsedArgs[flag];
5155
break;
56+
case 'untyped':
57+
settings.isTyped = false;
58+
break;
5259
case '_':
5360
// This is part of the minimist API, and holds args after the '--'.
5461
break;
@@ -136,7 +143,7 @@ function createSourceReplacingCompilerHost(
136143
* Compiles TypeScript code into Closure-compiler-ready JS.
137144
* Doesn't write any files to disk; all JS content is returned in a map.
138145
*/
139-
function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
146+
function toClosureJS(options: ts.CompilerOptions, fileNames: string[], isTyped: boolean):
140147
{jsFiles?: {[fileName: string]: string}, errors?: ts.Diagnostic[]} {
141148
// Parse and load the program without tsickle processing.
142149
// This is so:
@@ -148,10 +155,8 @@ function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
148155
return {errors};
149156
}
150157

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.
153158
const tsickleOptions: tsickle.Options = {
154-
untyped: true,
159+
untyped: !isTyped,
155160
};
156161

157162
// Process each input file with tsickle and save the output.
@@ -207,7 +212,7 @@ function main(args: string[]) {
207212

208213
// Run tsickle+TSC to convert inputs to Closure JS files.
209214
let jsFiles: {[fileName: string]: string};
210-
({jsFiles, errors} = toClosureJS(options, fileNames));
215+
({jsFiles, errors} = toClosureJS(options, fileNames, settings.isTyped));
211216
if (errors && errors.length > 0) {
212217
console.error(tsickle.formatDiagnostics(errors));
213218
process.exit(1);

0 commit comments

Comments
 (0)