Skip to content

Commit f0da6d1

Browse files
Some changes to tsc baselines for clarity (#38850)
* Baseline programs in tsc -b and tsc -incremental mode as well * Refactor outFile * Tests * Distinct input and output * Add helper to baseline serialized invocations of tsc on incremental edits * Input and output in watch mode * Update src/testRunner/unittests/tsbuild/helpers.ts Co-authored-by: Wesley Wigham <wewigham@microsoft.com> Co-authored-by: Wesley Wigham <wewigham@microsoft.com>
1 parent a88957e commit f0da6d1

File tree

445 files changed

+29291
-13370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

445 files changed

+29291
-13370
lines changed

src/compiler/builder.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ namespace ts {
173173
const compilerOptions = newProgram.getCompilerOptions();
174174
state.compilerOptions = compilerOptions;
175175
// With --out or --outFile, any change affects all semantic diagnostics so no need to cache them
176-
if (!compilerOptions.outFile && !compilerOptions.out) {
176+
if (!outFile(compilerOptions)) {
177177
state.semanticDiagnosticsPerFile = createMap<readonly Diagnostic[]>();
178178
}
179179
state.changedFilesSet = createMap<true>();
@@ -197,7 +197,7 @@ namespace ts {
197197
if (changedFilesSet) {
198198
copyEntries(changedFilesSet, state.changedFilesSet);
199199
}
200-
if (!compilerOptions.outFile && !compilerOptions.out && oldState!.affectedFilesPendingEmit) {
200+
if (!outFile(compilerOptions) && oldState!.affectedFilesPendingEmit) {
201201
state.affectedFilesPendingEmit = oldState!.affectedFilesPendingEmit.slice();
202202
state.affectedFilesPendingEmitKind = cloneMapOrUndefined(oldState!.affectedFilesPendingEmitKind);
203203
state.affectedFilesPendingEmitIndex = oldState!.affectedFilesPendingEmitIndex;
@@ -374,7 +374,7 @@ namespace ts {
374374
// so operations are performed directly on program, return program
375375
const program = Debug.checkDefined(state.program);
376376
const compilerOptions = program.getCompilerOptions();
377-
if (compilerOptions.outFile || compilerOptions.out) {
377+
if (outFile(compilerOptions)) {
378378
Debug.assert(!state.semanticDiagnosticsPerFile);
379379
return program;
380380
}
@@ -700,7 +700,7 @@ namespace ts {
700700
* Gets the program information to be emitted in buildInfo so that we can use it to create new program
701701
*/
702702
function getProgramBuildInfo(state: Readonly<ReusableBuilderProgramState>, getCanonicalFileName: GetCanonicalFileName): ProgramBuildInfo | undefined {
703-
if (state.compilerOptions.outFile || state.compilerOptions.out) return undefined;
703+
if (outFile(state.compilerOptions)) return undefined;
704704
const currentDirectory = Debug.checkDefined(state.program).getCurrentDirectory();
705705
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(getTsBuildInfoEmitOutputFilePath(state.compilerOptions)!, currentDirectory));
706706
const fileInfos: MapLike<BuilderState.FileInfo> = {};
@@ -933,7 +933,7 @@ namespace ts {
933933
let emitKind = BuilderFileEmit.Full;
934934
let isPendingEmitFile = false;
935935
if (!affected) {
936-
if (!state.compilerOptions.out && !state.compilerOptions.outFile) {
936+
if (!outFile(state.compilerOptions)) {
937937
const pendingAffectedFile = getNextAffectedFilePendingEmit(state);
938938
if (!pendingAffectedFile) {
939939
if (state.emittedBuildInfo) {
@@ -1071,7 +1071,7 @@ namespace ts {
10711071
function getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): readonly Diagnostic[] {
10721072
assertSourceFileOkWithoutNextAffectedCall(state, sourceFile);
10731073
const compilerOptions = Debug.checkDefined(state.program).getCompilerOptions();
1074-
if (compilerOptions.outFile || compilerOptions.out) {
1074+
if (outFile(compilerOptions)) {
10751075
Debug.assert(!state.semanticDiagnosticsPerFile);
10761076
// We dont need to cache the diagnostics just return them from program
10771077
return Debug.checkDefined(state.program).getSemanticDiagnostics(sourceFile, cancellationToken);

src/compiler/builderState.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ namespace ts {
403403
export function getAllDependencies(state: BuilderState, programOfThisState: Program, sourceFile: SourceFile): readonly string[] {
404404
const compilerOptions = programOfThisState.getCompilerOptions();
405405
// With --out or --outFile all outputs go into single file, all files depend on each other
406-
if (compilerOptions.outFile || compilerOptions.out) {
406+
if (outFile(compilerOptions)) {
407407
return getAllFileNames(state, programOfThisState);
408408
}
409409

@@ -519,7 +519,7 @@ namespace ts {
519519
const compilerOptions = programOfThisState.getCompilerOptions();
520520
// If `--out` or `--outFile` is specified, any new emit will result in re-emitting the entire project,
521521
// so returning the file itself is good enough.
522-
if (compilerOptions && (compilerOptions.out || compilerOptions.outFile)) {
522+
if (compilerOptions && outFile(compilerOptions)) {
523523
return [sourceFileWithUpdatedShape];
524524
}
525525
return getAllFilesExcludingDefaultLibraryFile(state, programOfThisState, sourceFileWithUpdatedShape);
@@ -534,7 +534,7 @@ namespace ts {
534534
}
535535

536536
const compilerOptions = programOfThisState.getCompilerOptions();
537-
if (compilerOptions && (compilerOptions.isolatedModules || compilerOptions.out || compilerOptions.outFile)) {
537+
if (compilerOptions && (compilerOptions.isolatedModules || outFile(compilerOptions))) {
538538
return [sourceFileWithUpdatedShape];
539539
}
540540

src/compiler/checker.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ namespace ts {
13521352
const declContainer = getEnclosingBlockScopeContainer(declaration);
13531353
if (declarationFile !== useFile) {
13541354
if ((moduleKind && (declarationFile.externalModuleIndicator || useFile.externalModuleIndicator)) ||
1355-
(!compilerOptions.outFile && !compilerOptions.out) ||
1355+
(!outFile(compilerOptions)) ||
13561356
isInTypeQuery(usage) ||
13571357
declaration.flags & NodeFlags.Ambient) {
13581358
// nodes are in different files and order cannot be determined
@@ -5201,7 +5201,7 @@ namespace ts {
52015201
const links = getSymbolLinks(symbol);
52025202
let specifier = links.specifierCache && links.specifierCache.get(contextFile.path);
52035203
if (!specifier) {
5204-
const isBundle = (compilerOptions.out || compilerOptions.outFile);
5204+
const isBundle = !!outFile(compilerOptions);
52055205
// For declaration bundles, we need to generate absolute paths relative to the common source dir for imports,
52065206
// just like how the declaration emitter does for the ambient module declarations - we can easily accomplish this
52075207
// using the `baseUrl` compiler option (which we would otherwise never use in declaration emit) and a non-relative

src/compiler/emitter.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace ts {
2525
includeBuildInfo?: boolean) {
2626
const sourceFiles = isArray(sourceFilesOrTargetSourceFile) ? sourceFilesOrTargetSourceFile : getSourceFilesToEmit(host, sourceFilesOrTargetSourceFile, forceDtsEmit);
2727
const options = host.getCompilerOptions();
28-
if (options.outFile || options.out) {
28+
if (outFile(options)) {
2929
const prepends = host.getPrependNodes();
3030
if (sourceFiles.length || prepends.length) {
3131
const bundle = createBundle(sourceFiles, prepends);
@@ -45,7 +45,7 @@ namespace ts {
4545
}
4646
}
4747
if (includeBuildInfo) {
48-
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(host.getCompilerOptions());
48+
const buildInfoPath = getTsBuildInfoEmitOutputFilePath(options);
4949
if (buildInfoPath) return action({ buildInfoPath }, /*sourceFileOrBundle*/ undefined);
5050
}
5151
}
@@ -55,7 +55,7 @@ namespace ts {
5555
const configFile = options.configFilePath;
5656
if (!isIncrementalCompilation(options)) return undefined;
5757
if (options.tsBuildInfoFile) return options.tsBuildInfoFile;
58-
const outPath = options.outFile || options.out;
58+
const outPath = outFile(options);
5959
let buildInfoExtensionLess: string;
6060
if (outPath) {
6161
buildInfoExtensionLess = removeFileExtension(outPath);
@@ -74,7 +74,7 @@ namespace ts {
7474

7575
/*@internal*/
7676
export function getOutputPathsForBundle(options: CompilerOptions, forceDtsPaths: boolean): EmitFileNames {
77-
const outPath = options.outFile || options.out!;
77+
const outPath = outFile(options)!;
7878
const jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
7979
const sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
8080
const declarationFilePath = (forceDtsPaths || getEmitDeclarations(options)) ? removeFileExtension(outPath) + Extension.Dts : undefined;
@@ -210,7 +210,7 @@ namespace ts {
210210
/*@internal*/
211211
export function getAllProjectOutputs(configFile: ParsedCommandLine, ignoreCase: boolean): readonly string[] {
212212
const { addOutput, getOutputs } = createAddOutput();
213-
if (configFile.options.outFile || configFile.options.out) {
213+
if (outFile(configFile.options)) {
214214
getSingleOutputFileNames(configFile, addOutput);
215215
}
216216
else {
@@ -226,7 +226,7 @@ namespace ts {
226226
inputFileName = normalizePath(inputFileName);
227227
Debug.assert(contains(commandLine.fileNames, inputFileName), `Expected fileName to be present in command line`);
228228
const { addOutput, getOutputs } = createAddOutput();
229-
if (commandLine.options.outFile || commandLine.options.out) {
229+
if (outFile(commandLine.options)) {
230230
getSingleOutputFileNames(commandLine, addOutput);
231231
}
232232
else {
@@ -237,7 +237,7 @@ namespace ts {
237237

238238
/*@internal*/
239239
export function getFirstProjectOutput(configFile: ParsedCommandLine, ignoreCase: boolean): string {
240-
if (configFile.options.outFile || configFile.options.out) {
240+
if (outFile(configFile.options)) {
241241
const { jsFilePath } = getOutputPathsForBundle(configFile.options, /*forceDtsPaths*/ false);
242242
return Debug.checkDefined(jsFilePath, `project ${configFile.options.configFilePath} expected to have at least one output`);
243243
}
@@ -404,7 +404,7 @@ namespace ts {
404404
const sourceFiles = isSourceFile(sourceFileOrBundle) ? [sourceFileOrBundle] : sourceFileOrBundle.sourceFiles;
405405
const filesForEmit = forceDtsEmit ? sourceFiles : filter(sourceFiles, isSourceFileNotJson);
406406
// Setup and perform the transformation to retrieve declarations from the input files
407-
const inputListOrBundle = (compilerOptions.outFile || compilerOptions.out) ? [createBundle(filesForEmit, !isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit;
407+
const inputListOrBundle = outFile(compilerOptions) ? [createBundle(filesForEmit, !isSourceFile(sourceFileOrBundle) ? sourceFileOrBundle.prepends : undefined)] : filesForEmit;
408408
if (emitOnlyDtsFiles && !getEmitDeclarations(compilerOptions)) {
409409
// Checker wont collect the linked aliases since thats only done when declaration is enabled.
410410
// Do that here when emitting only dts files

src/compiler/factory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1581,7 +1581,7 @@ namespace ts {
15811581
if (file.moduleName) {
15821582
return createLiteral(file.moduleName);
15831583
}
1584-
if (!file.isDeclarationFile && (options.out || options.outFile)) {
1584+
if (!file.isDeclarationFile && outFile(options)) {
15851585
return createLiteral(getExternalModuleNameFromPath(host, file.fileName));
15861586
}
15871587
return undefined;

src/compiler/program.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ namespace ts {
834834
if (rootNames.length) {
835835
for (const parsedRef of resolvedProjectReferences) {
836836
if (!parsedRef) continue;
837-
const out = parsedRef.commandLine.options.outFile || parsedRef.commandLine.options.out;
837+
const out = outFile(parsedRef.commandLine.options);
838838
if (useSourceOfProjectReferenceRedirect) {
839839
if (out || getEmitModuleKind(parsedRef.commandLine.options) === ModuleKind.None) {
840840
for (const fileName of parsedRef.commandLine.fileNames) {
@@ -1503,7 +1503,7 @@ namespace ts {
15031503
}
15041504

15051505
function emitBuildInfo(writeFileCallback?: WriteFileCallback): EmitResult {
1506-
Debug.assert(!options.out && !options.outFile);
1506+
Debug.assert(!outFile(options));
15071507
performance.mark("beforeEmit");
15081508
const emitResult = emitFiles(
15091509
notImplementedResolver,
@@ -1597,7 +1597,7 @@ namespace ts {
15971597
// This is because in the -out scenario all files need to be emitted, and therefore all
15981598
// files need to be type checked. And the way to specify that all files need to be type
15991599
// checked is to not pass the file to getEmitResolver.
1600-
const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver((options.outFile || options.out) ? undefined : sourceFile, cancellationToken);
1600+
const emitResolver = getDiagnosticsProducingTypeChecker().getEmitResolver(outFile(options) ? undefined : sourceFile, cancellationToken);
16011601

16021602
performance.mark("beforeEmit");
16031603

@@ -1674,7 +1674,7 @@ namespace ts {
16741674
function getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): readonly DiagnosticWithLocation[] {
16751675
const options = program.getCompilerOptions();
16761676
// collect diagnostics from the program only once if either no source file was specified or out/outFile is set (bundled emit)
1677-
if (!sourceFile || options.out || options.outFile) {
1677+
if (!sourceFile || outFile(options)) {
16781678
return getDeclarationDiagnosticsWorker(sourceFile, cancellationToken);
16791679
}
16801680
else {
@@ -2403,7 +2403,7 @@ namespace ts {
24032403
if (refFile && !useSourceOfProjectReferenceRedirect) {
24042404
const redirectProject = getProjectReferenceRedirectProject(fileName);
24052405
if (redirectProject) {
2406-
if (redirectProject.commandLine.options.outFile || redirectProject.commandLine.options.out) {
2406+
if (outFile(redirectProject.commandLine.options)) {
24072407
// Shouldnt create many to 1 mapping file in --out scenario
24082408
return undefined;
24092409
}
@@ -2535,7 +2535,7 @@ namespace ts {
25352535

25362536

25372537
function getProjectReferenceOutputName(referencedProject: ResolvedProjectReference, fileName: string) {
2538-
const out = referencedProject.commandLine.options.outFile || referencedProject.commandLine.options.out;
2538+
const out = outFile(referencedProject.commandLine.options);
25392539
return out ?
25402540
changeExtension(out, Extension.Dts) :
25412541
getOutputDeclarationFileName(fileName, referencedProject.commandLine, !host.useCaseSensitiveFileNames());
@@ -2577,7 +2577,7 @@ namespace ts {
25772577
mapFromToProjectReferenceRedirectSource = createMap();
25782578
forEachResolvedProjectReference(resolvedRef => {
25792579
if (resolvedRef) {
2580-
const out = resolvedRef.commandLine.options.outFile || resolvedRef.commandLine.options.out;
2580+
const out = outFile(resolvedRef.commandLine.options);
25812581
if (out) {
25822582
// Dont know which source file it means so return true?
25832583
const outputDts = changeExtension(out, Extension.Dts);
@@ -3001,12 +3001,13 @@ namespace ts {
30013001
}
30023002
}
30033003

3004+
const outputFile = outFile(options);
30043005
if (options.tsBuildInfoFile) {
30053006
if (!isIncrementalCompilation(options)) {
30063007
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "tsBuildInfoFile", "incremental", "composite");
30073008
}
30083009
}
3009-
else if (options.incremental && !options.outFile && !options.out && !options.configFilePath) {
3010+
else if (options.incremental && !outputFile && !options.configFilePath) {
30103011
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified));
30113012
}
30123013

@@ -3087,7 +3088,7 @@ namespace ts {
30873088
if (!getEmitDeclarations(options)) {
30883089
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "declarationDir", "declaration", "composite");
30893090
}
3090-
if (options.out || options.outFile) {
3091+
if (outputFile) {
30913092
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declarationDir", options.out ? "out" : "outFile");
30923093
}
30933094
}
@@ -3105,7 +3106,6 @@ namespace ts {
31053106
}
31063107

31073108
const languageVersion = options.target || ScriptTarget.ES3;
3108-
const outFile = options.outFile || options.out;
31093109

31103110
const firstNonAmbientExternalModuleSourceFile = find(files, f => isExternalModule(f) && !f.isDeclarationFile);
31113111
if (options.isolatedModules) {
@@ -3126,7 +3126,7 @@ namespace ts {
31263126
}
31273127

31283128
// Cannot specify module gen that isn't amd or system with --out
3129-
if (outFile && !options.emitDeclarationOnly) {
3129+
if (outputFile && !options.emitDeclarationOnly) {
31303130
if (options.module && !(options.module === ModuleKind.AMD || options.module === ModuleKind.System)) {
31313131
createDiagnosticForOptionName(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile", "module");
31323132
}
@@ -3286,7 +3286,7 @@ namespace ts {
32863286
}
32873287
}
32883288
if (ref.prepend) {
3289-
const out = options.outFile || options.out;
3289+
const out = outFile(options);
32903290
if (out) {
32913291
if (!host.fileExists(out)) {
32923292
createDiagnosticForReference(parentFile, index, Diagnostics.Output_file_0_from_project_1_does_not_exist, out, ref.path);
@@ -3421,7 +3421,7 @@ namespace ts {
34213421
}
34223422

34233423
// If options have --outFile or --out just check that
3424-
const out = options.outFile || options.out;
3424+
const out = outFile(options);
34253425
if (out) {
34263426
return isSameFile(filePath, out) || isSameFile(filePath, removeFileExtension(out) + Extension.Dts);
34273427
}
@@ -3504,7 +3504,7 @@ namespace ts {
35043504
mapOfDeclarationDirectories = createMap();
35053505
host.forEachResolvedProjectReference(ref => {
35063506
if (!ref) return;
3507-
const out = ref.commandLine.options.outFile || ref.commandLine.options.out;
3507+
const out = outFile(ref.commandLine.options);
35083508
if (out) {
35093509
mapOfDeclarationDirectories!.set(getDirectoryPath(host.toPath(out)), true);
35103510
}
@@ -3704,7 +3704,7 @@ namespace ts {
37043704
const ref = projectReferences[i];
37053705
const resolvedRefOpts = getCommandLine(ref, i);
37063706
if (ref.prepend && resolvedRefOpts && resolvedRefOpts.options) {
3707-
const out = resolvedRefOpts.options.outFile || resolvedRefOpts.options.out;
3707+
const out = outFile(resolvedRefOpts.options);
37083708
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
37093709
if (!out) continue;
37103710

0 commit comments

Comments
 (0)