-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allows emitting buildInfo when --noEmit is specified #39122
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -462,7 +462,6 @@ namespace ts { | |
{ | ||
name: "noEmit", | ||
type: "boolean", | ||
affectsEmit: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally, I find this surprising enough that I'd leave it present but commented out and with an explanation. |
||
showInSimplifiedHelpView: true, | ||
category: Diagnostics.Basic_Options, | ||
description: Diagnostics.Do_not_emit_outputs, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1719,7 +1719,7 @@ namespace ts { | |
|
||
function getSemanticDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken | undefined): readonly Diagnostic[] { | ||
return concatenate( | ||
getBindAndCheckDiagnosticsForFile(sourceFile, cancellationToken), | ||
filterSemanticDiagnotics(getBindAndCheckDiagnosticsForFile(sourceFile, cancellationToken), options), | ||
getProgramDiagnostics(sourceFile) | ||
); | ||
} | ||
|
@@ -3011,10 +3011,6 @@ namespace ts { | |
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified)); | ||
} | ||
|
||
if (!options.listFilesOnly && options.noEmit && isIncrementalCompilation(options)) { | ||
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noEmit", options.incremental ? "incremental" : "composite"); | ||
} | ||
|
||
verifyProjectReferences(); | ||
|
||
// List of collected files is complete; validate exhautiveness if this is a project with a file list | ||
|
@@ -3269,7 +3265,7 @@ namespace ts { | |
} | ||
|
||
function verifyProjectReferences() { | ||
const buildInfoPath = !options.noEmit && !options.suppressOutputPathCheck ? getTsBuildInfoEmitOutputFilePath(options) : undefined; | ||
const buildInfoPath = !options.suppressOutputPathCheck ? getTsBuildInfoEmitOutputFilePath(options) : undefined; | ||
forEachProjectReference(projectReferences, resolvedProjectReferences, (resolvedRef, index, parent) => { | ||
const ref = (parent ? parent.commandLine.projectReferences : projectReferences)![index]; | ||
const parentFile = parent && parent.sourceFile as JsonSourceFile; | ||
|
@@ -3278,11 +3274,12 @@ namespace ts { | |
return; | ||
} | ||
const options = resolvedRef.commandLine.options; | ||
if (!options.composite) { | ||
if (!options.composite || options.noEmit) { | ||
// ok to not have composite if the current program is container only | ||
const inputs = parent ? parent.commandLine.fileNames : rootNames; | ||
if (inputs.length) { | ||
createDiagnosticForReference(parentFile, index, Diagnostics.Referenced_project_0_must_have_setting_composite_Colon_true, ref.path); | ||
if (!options.composite) createDiagnosticForReference(parentFile, index, Diagnostics.Referenced_project_0_must_have_setting_composite_Colon_true, ref.path); | ||
if (options.noEmit) createDiagnosticForReference(parentFile, index, Diagnostics.Referenced_project_0_may_not_disable_emit, ref.path); | ||
} | ||
} | ||
if (ref.prepend) { | ||
|
@@ -3648,7 +3645,13 @@ namespace ts { | |
cancellationToken: CancellationToken | undefined | ||
): EmitResult | undefined { | ||
const options = program.getCompilerOptions(); | ||
if (options.noEmit) return emitSkippedWithNoDiagnostics; | ||
if (options.noEmit) { | ||
// Cache the semantic diagnostics | ||
program.getSemanticDiagnostics(sourceFile, cancellationToken); | ||
return sourceFile || outFile(options) ? | ||
emitSkippedWithNoDiagnostics : | ||
program.emitBuildInfo(writeFile, cancellationToken); | ||
} | ||
|
||
// If the noEmitOnError flag is set, then check if we have any errors so far. If so, | ||
// immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we | ||
|
@@ -3675,6 +3678,11 @@ namespace ts { | |
return { diagnostics, sourceMaps: undefined, emittedFiles, emitSkipped: true }; | ||
} | ||
|
||
/*@internal*/ | ||
export function filterSemanticDiagnotics(diagnostic: readonly Diagnostic[], option: CompilerOptions): readonly Diagnostic[] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably be named There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's also a typo in the function name. |
||
return filter(diagnostic, d => !d.skippedOn || !option[d.skippedOn]); | ||
} | ||
|
||
/*@internal*/ | ||
interface CompilerHostLike { | ||
useCaseSensitiveFileNames(): boolean; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having trouble wrapping my head around what this does and would find an explanation helpful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
location, message, arg0, ...
are the existing error logging parameters.key: keyof CompilerOptions
is a typesafe way to assert thatkey
, while a string, actually refers to a property inCompilerOptions
. That way the string can safely be used as a property name ofCompilerOptions
infilterSemanticDiagnostics
:filter(diagnostics, d => !d.skippedOn || !options[d.skippedOn])
This keeps diagnostics that
errorSkippedOn
, so didn't setskippedOn
-OR-
skippedOn
, which is guaranteed to be the name of a property in compiler options, say "noEmit". For the "noEmit" example,!options[d.skippedOn]
is equivalent to!options.noEmit
.This meta-programming JS would require an enum plus a switch-case conversion in C# I think. Or the meta-programming facilities there, though the result wouldn't be as typesafe as in Typescript.