Skip to content

Commit d18130d

Browse files
committed
Consolidate checks in emitFilesAndReportErrors
1 parent caf0041 commit d18130d

File tree

6 files changed

+30
-35
lines changed

6 files changed

+30
-35
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29651,7 +29651,7 @@ namespace ts {
2965129651

2965229652
function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) {
2965329653
// no rest parameters \ declaration context \ overload - no codegen impact
29654-
if (languageVersion >= ScriptTarget.ES2015 || shouldSuppressEmit(compilerOptions) || !hasRestParameter(node) || node.flags & NodeFlags.Ambient || nodeIsMissing((<FunctionLikeDeclaration>node).body)) {
29654+
if (languageVersion >= ScriptTarget.ES2015 || compilerOptions.noEmit || !hasRestParameter(node) || node.flags & NodeFlags.Ambient || nodeIsMissing((<FunctionLikeDeclaration>node).body)) {
2965529655
return;
2965629656
}
2965729657

@@ -29726,7 +29726,7 @@ namespace ts {
2972629726

2972729727
function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: Identifier) {
2972829728
// No need to check for require or exports for ES6 modules and later
29729-
if (moduleKind >= ModuleKind.ES2015 || shouldSuppressEmit(compilerOptions)) {
29729+
if (moduleKind >= ModuleKind.ES2015 || compilerOptions.noEmit) {
2973029730
return;
2973129731
}
2973229732

@@ -29749,7 +29749,7 @@ namespace ts {
2974929749
}
2975029750

2975129751
function checkCollisionWithGlobalPromiseInGeneratedCode(node: Node, name: Identifier): void {
29752-
if (languageVersion >= ScriptTarget.ES2017 || shouldSuppressEmit(compilerOptions) || !needCollisionCheckForIdentifier(node, name, "Promise")) {
29752+
if (languageVersion >= ScriptTarget.ES2017 || compilerOptions.noEmit || !needCollisionCheckForIdentifier(node, name, "Promise")) {
2975329753
return;
2975429754
}
2975529755

@@ -35639,7 +35639,7 @@ namespace ts {
3563935639
return grammarErrorOnNode(node.exclamationToken, Diagnostics.Definite_assignment_assertions_can_only_be_used_along_with_a_type_annotation);
3564035640
}
3564135641

35642-
if (compilerOptions.module !== ModuleKind.ES2015 && compilerOptions.module !== ModuleKind.ESNext && compilerOptions.module !== ModuleKind.System && !shouldSuppressEmit(compilerOptions) &&
35642+
if (compilerOptions.module !== ModuleKind.ES2015 && compilerOptions.module !== ModuleKind.ESNext && compilerOptions.module !== ModuleKind.System && !compilerOptions.noEmit &&
3564335643
!(node.parent.parent.flags & NodeFlags.Ambient) && hasModifier(node.parent.parent, ModifierFlags.Export)) {
3564435644
checkESModuleMarker(node.name);
3564535645
}

src/compiler/emitter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ namespace ts {
332332
// Write build information if applicable
333333
if (!buildInfoPath || targetSourceFile || emitSkipped) return;
334334
const program = host.getProgramBuildInfo();
335-
if (host.isEmitBlocked(buildInfoPath) || shouldSuppressEmit(compilerOptions)) {
335+
if (host.isEmitBlocked(buildInfoPath) || compilerOptions.noEmit) {
336336
emitSkipped = true;
337337
return;
338338
}
@@ -349,7 +349,7 @@ namespace ts {
349349
}
350350

351351
// Make sure not to write js file and source map file if any of them cannot be written
352-
if ((jsFilePath && host.isEmitBlocked(jsFilePath)) || shouldSuppressEmit(compilerOptions)) {
352+
if ((jsFilePath && host.isEmitBlocked(jsFilePath)) || compilerOptions.noEmit) {
353353
emitSkipped = true;
354354
return;
355355
}
@@ -436,7 +436,7 @@ namespace ts {
436436
onEmitNode: declarationTransform.emitNodeWithNotification,
437437
substituteNode: declarationTransform.substituteNode,
438438
});
439-
const declBlocked = (!!declarationTransform.diagnostics && !!declarationTransform.diagnostics.length) || !!host.isEmitBlocked(declarationFilePath) || !!shouldSuppressEmit(compilerOptions);
439+
const declBlocked = (!!declarationTransform.diagnostics && !!declarationTransform.diagnostics.length) || !!host.isEmitBlocked(declarationFilePath) || !!compilerOptions.noEmit;
440440
emitSkipped = emitSkipped || declBlocked;
441441
if (!declBlocked || forceDtsEmit) {
442442
Debug.assert(declarationTransform.transformed.length === 1, "Should only see one output from the decl transform");

src/compiler/program.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1583,11 +1583,11 @@ namespace ts {
15831583
function emitWorker(program: Program, sourceFile: SourceFile | undefined, writeFileCallback: WriteFileCallback | undefined, cancellationToken: CancellationToken | undefined, emitOnlyDtsFiles?: boolean, customTransformers?: CustomTransformers, forceDtsEmit?: boolean): EmitResult {
15841584
let declarationDiagnostics: readonly Diagnostic[] = [];
15851585

1586-
if (options.listFilesOnly || (!forceDtsEmit && shouldSuppressEmit(options))) {
1587-
return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emittedFiles: undefined, emitSkipped: true };
1588-
}
1589-
15901586
if (!forceDtsEmit) {
1587+
if (options.noEmit) {
1588+
return { diagnostics: declarationDiagnostics, sourceMaps: undefined, emittedFiles: undefined, emitSkipped: true };
1589+
}
1590+
15911591
// If the noEmitOnError flag is set, then check if we have any errors so far. If so,
15921592
// immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we
15931593
// get any preEmit diagnostics, not just the ones
@@ -2037,9 +2037,7 @@ namespace ts {
20372037
}
20382038

20392039
function getGlobalDiagnostics(): SortedReadonlyArray<Diagnostic> {
2040-
return !options.listFilesOnly && rootNames.length
2041-
? sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice())
2042-
: emptyArray as any as SortedReadonlyArray<Diagnostic>;
2040+
return rootNames.length ? sortAndDeduplicateDiagnostics(getDiagnosticsProducingTypeChecker().getGlobalDiagnostics().slice()) : emptyArray as any as SortedReadonlyArray<Diagnostic>;
20432041
}
20442042

20452043
function getConfigFileParsingDiagnostics(): readonly Diagnostic[] {
@@ -3092,7 +3090,7 @@ namespace ts {
30923090
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "emitDeclarationOnly", "declaration", "composite");
30933091
}
30943092

3095-
if (shouldSuppressEmit(options)) {
3093+
if (options.noEmit) {
30963094
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "emitDeclarationOnly", "noEmit");
30973095
}
30983096
}
@@ -3115,7 +3113,7 @@ namespace ts {
31153113
}
31163114

31173115
// If the emit is enabled make sure that every output file is unique and not overwriting any of the input files
3118-
if (!shouldSuppressEmit(options) && !options.suppressOutputPathCheck) {
3116+
if (!options.noEmit && !options.suppressOutputPathCheck) {
31193117
const emitHost = getEmitHost();
31203118
const emitFilesSeen = createMap<true>();
31213119
forEachEmittedFile(emitHost, (emitFileNames) => {
@@ -3184,7 +3182,7 @@ namespace ts {
31843182
}
31853183

31863184
function verifyProjectReferences() {
3187-
const buildInfoPath = !shouldSuppressEmit(options) && !options.suppressOutputPathCheck ? getTsBuildInfoEmitOutputFilePath(options) : undefined;
3185+
const buildInfoPath = !options.noEmit && !options.suppressOutputPathCheck ? getTsBuildInfoEmitOutputFilePath(options) : undefined;
31883186
forEachProjectReference(projectReferences, resolvedProjectReferences, (resolvedRef, index, parent) => {
31893187
const ref = (parent ? parent.commandLine.projectReferences : projectReferences)![index];
31903188
const parentFile = parent && parent.sourceFile as JsonSourceFile;
@@ -3325,7 +3323,7 @@ namespace ts {
33253323
}
33263324

33273325
function isEmittedFile(file: string): boolean {
3328-
if (shouldSuppressEmit(options)) {
3326+
if (options.noEmit) {
33293327
return false;
33303328
}
33313329

src/compiler/tsbuild.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ namespace ts {
167167
/*@internal*/ preserveWatchOutput?: boolean;
168168
/*@internal*/ listEmittedFiles?: boolean;
169169
/*@internal*/ listFiles?: boolean;
170-
/*@internal*/ listFilesOnly?: boolean;
171170
/*@internal*/ pretty?: boolean;
172171
incremental?: boolean;
173172

@@ -1924,7 +1923,7 @@ namespace ts {
19241923
}
19251924

19261925
function isOutputFile(state: SolutionBuilderState, fileName: string, configFile: ParsedCommandLine) {
1927-
if (shouldSuppressEmit(configFile.options)) return false;
1926+
if (configFile.options.noEmit) return false;
19281927

19291928
// ts or tsx files are not output
19301929
if (!fileExtensionIs(fileName, Extension.Dts) &&

src/compiler/utilities.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7619,14 +7619,6 @@ namespace ts {
76197619
return option.strictFlag ? getStrictOptionValue(options, option.name as StrictOptionName) : options[option.name];
76207620
}
76217621

7622-
export function shouldSuppressEmit(options: CompilerOptions): boolean {
7623-
return !!options.noEmit || !!options.listFilesOnly;
7624-
}
7625-
7626-
export function shouldListFiles(options: CompilerOptions): boolean {
7627-
return !!options.listFiles || !!options.listFilesOnly;
7628-
}
7629-
76307622
export function hasZeroOrOneAsteriskCharacter(str: string): boolean {
76317623
let seenAsterisk = false;
76327624
for (let i = 0; i < str.length; i++) {
@@ -8347,8 +8339,7 @@ namespace ts {
83478339
// If skipLibCheck is enabled, skip reporting errors if file is a declaration file.
83488340
// If skipDefaultLibCheck is enabled, skip reporting errors if file contains a
83498341
// '/// <reference no-default-lib="true"/>' directive.
8350-
return options.listFilesOnly ||
8351-
(options.skipLibCheck && sourceFile.isDeclarationFile ||
8342+
return (options.skipLibCheck && sourceFile.isDeclarationFile ||
83528343
options.skipDefaultLibCheck && sourceFile.hasNoDefaultLib) ||
83538344
host.isSourceOfProjectReferenceRedirect(sourceFile.fileName);
83548345
}

src/compiler/watch.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ namespace ts {
129129
}
130130

131131
export function listFiles(program: ProgramToEmitFilesAndReportErrors, writeFileName: (s: string) => void) {
132-
if (shouldListFiles(program.getCompilerOptions())) {
132+
if (program.getCompilerOptions().listFiles || program.getCompilerOptions().listFilesOnly) {
133133
forEach(program.getSourceFiles(), file => {
134134
writeFileName(file.fileName);
135135
});
@@ -149,6 +149,8 @@ namespace ts {
149149
emitOnlyDtsFiles?: boolean,
150150
customTransformers?: CustomTransformers
151151
) {
152+
const isListFilesOnly = !!program.getCompilerOptions().listFilesOnly;
153+
152154
// First get and report any syntactic errors.
153155
const diagnostics = program.getConfigFileParsingDiagnostics().slice();
154156
const configFileParsingDiagnosticsLength = diagnostics.length;
@@ -158,15 +160,20 @@ namespace ts {
158160
// semantic errors.
159161
if (diagnostics.length === configFileParsingDiagnosticsLength) {
160162
addRange(diagnostics, program.getOptionsDiagnostics(cancellationToken));
161-
addRange(diagnostics, program.getGlobalDiagnostics(cancellationToken));
162163

163-
if (diagnostics.length === configFileParsingDiagnosticsLength) {
164-
addRange(diagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
164+
if (!isListFilesOnly) {
165+
addRange(diagnostics, program.getGlobalDiagnostics(cancellationToken));
166+
167+
if (diagnostics.length === configFileParsingDiagnosticsLength) {
168+
addRange(diagnostics, program.getSemanticDiagnostics(/*sourceFile*/ undefined, cancellationToken));
169+
}
165170
}
166171
}
167172

168173
// Emit and report any errors we ran into.
169-
const emitResult = program.emit(/*targetSourceFile*/ undefined, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
174+
const emitResult = isListFilesOnly
175+
? { emitSkipped: true, diagnostics: emptyArray }
176+
: program.emit(/*targetSourceFile*/ undefined, writeFile, cancellationToken, emitOnlyDtsFiles, customTransformers);
170177
const { emittedFiles, diagnostics: emitDiagnostics } = emitResult;
171178
addRange(diagnostics, emitDiagnostics);
172179

0 commit comments

Comments
 (0)