Skip to content

Commit 37c3c5d

Browse files
committed
Refactoring
1 parent b8f33f6 commit 37c3c5d

File tree

1 file changed

+12
-17
lines changed

1 file changed

+12
-17
lines changed

src/tsc/tsc.ts

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,10 @@ namespace ts {
5353
}
5454

5555
export function executeCommandLine(args: string[]): void {
56-
if (args.length > 0 && ((args[0].toLowerCase() === "--build") || (args[0].toLowerCase() === "-b"))) {
57-
const result = performBuild(args.slice(1));
58-
// undefined = in watch mode, do not exit
59-
if (result !== undefined) {
60-
return sys.exit(result);
61-
}
62-
else {
63-
return;
56+
if (args.length > 0 && args[0].charCodeAt(0) === CharacterCodes.minus) {
57+
const firstOption = args[0].slice(args[0].charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase();
58+
if (firstOption === "build" || firstOption === "b") {
59+
return performBuild(args.slice(1));
6460
}
6561
}
6662

@@ -164,30 +160,30 @@ namespace ts {
164160
}
165161
}
166162

167-
function performBuild(args: string[]): number | undefined {
163+
function performBuild(args: string[]) {
168164
const { buildOptions, projects, errors } = parseBuildCommand(args);
169165
if (errors.length > 0) {
170166
errors.forEach(reportDiagnostic);
171-
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
167+
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
172168
}
173169

174170
if (buildOptions.help) {
175171
printVersion();
176172
printHelp(buildOpts, "--build ");
177-
return ExitStatus.Success;
173+
return sys.exit(ExitStatus.Success);
178174
}
179175

180176
// Update to pretty if host supports it
181177
updateReportDiagnostic();
182178
if (projects.length === 0) {
183179
printVersion();
184180
printHelp(buildOpts, "--build ");
185-
return ExitStatus.Success;
181+
return sys.exit(ExitStatus.Success);
186182
}
187183

188184
if (!sys.getModifiedTime || !sys.setModifiedTime || (buildOptions.clean && !sys.deleteFile)) {
189185
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--build"));
190-
return ExitStatus.DiagnosticsPresent_OutputsSkipped;
186+
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
191187
}
192188
if (buildOptions.watch) {
193189
reportWatchModeWithoutSysSupport();
@@ -196,16 +192,15 @@ namespace ts {
196192
// TODO: change this to host if watch => watchHost otherwiue without wathc
197193
const builder = createSolutionBuilder(createSolutionBuilderWithWatchHost(sys, reportDiagnostic, createBuilderStatusReporter(sys, shouldBePretty()), createWatchStatusReporter()), projects, buildOptions);
198194
if (buildOptions.clean) {
199-
return builder.cleanAllProjects();
195+
return sys.exit(builder.cleanAllProjects());
200196
}
201197

202198
if (buildOptions.watch) {
203199
builder.buildAllProjects();
204-
builder.startWatching();
205-
return undefined;
200+
return builder.startWatching();
206201
}
207202

208-
return builder.buildAllProjects();
203+
return sys.exit(builder.buildAllProjects());
209204
}
210205

211206
function performCompilation(rootNames: string[], projectReferences: ReadonlyArray<ProjectReference> | undefined, options: CompilerOptions, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>) {

0 commit comments

Comments
 (0)