Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 33931b8

Browse files
jjuddevmar
authored andcommitted
Configure typed/untyped converstion from the CLI and default to typed (#157)
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 cf5903a commit 33931b8

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/main.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import * as tsickle from './tsickle';
1212
interface Settings {
1313
/** If provided, path to save externs to. */
1414
externsPath?: string;
15+
16+
/** If provided, convert every type to the Closure {?} type */
17+
isUntyped: boolean;
1518
}
1619

1720
function usage() {
@@ -22,6 +25,7 @@ example:
2225
2326
tsickle flags are:
2427
--externs=PATH save generated Closure externs.js to PATH
28+
--untyped convert every type in TypeScript to the Closure {?} type
2529
`);
2630
}
2731

@@ -30,7 +34,7 @@ tsickle flags are:
3034
* the arguments to pass on to tsc.
3135
*/
3236
function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: string[]} {
33-
let settings: Settings = {};
37+
let settings: Settings = {isUntyped: false};
3438
let parsedArgs = minimist(args);
3539
for (let flag of Object.keys(parsedArgs)) {
3640
switch (flag) {
@@ -42,6 +46,9 @@ function loadSettingsFromArgs(args: string[]): {settings: Settings, tscArgs: str
4246
case 'externs':
4347
settings.externsPath = parsedArgs[flag];
4448
break;
49+
case 'untyped':
50+
settings.isUntyped = true;
51+
break;
4552
case '_':
4653
// This is part of the minimist API, and holds args after the '--'.
4754
break;
@@ -129,7 +136,7 @@ function createSourceReplacingCompilerHost(
129136
* Compiles TypeScript code into Closure-compiler-ready JS.
130137
* Doesn't write any files to disk; all JS content is returned in a map.
131138
*/
132-
function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
139+
function toClosureJS(options: ts.CompilerOptions, fileNames: string[], isUntyped: boolean):
133140
{jsFiles?: {[fileName: string]: string}, externs?: string, errors?: ts.Diagnostic[]} {
134141
// Parse and load the program without tsickle processing.
135142
// This is so:
@@ -141,10 +148,8 @@ function toClosureJS(options: ts.CompilerOptions, fileNames: string[]):
141148
return {errors};
142149
}
143150

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.
146151
const tsickleOptions: tsickle.Options = {
147-
untyped: true,
152+
untyped: isUntyped,
148153
};
149154

150155
// Process each input file with tsickle and save the output.
@@ -201,7 +206,7 @@ function main(args: string[]) {
201206
// Run tsickle+TSC to convert inputs to Closure JS files.
202207
let jsFiles: {[fileName: string]: string};
203208
let externs: string;
204-
({jsFiles, externs, errors} = toClosureJS(options, fileNames));
209+
({jsFiles, externs, errors} = toClosureJS(options, fileNames, settings.isUntyped));
205210
if (errors && errors.length > 0) {
206211
console.error(tsickle.formatDiagnostics(errors));
207212
process.exit(1);

0 commit comments

Comments
 (0)