mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
dprint the codebase (#54820)
This commit is contained in:
@@ -149,7 +149,7 @@ function getCountKey(program: Program, file: SourceFile) {
|
||||
function updateReportDiagnostic(
|
||||
sys: System,
|
||||
existing: DiagnosticReporter,
|
||||
options: CompilerOptions | BuildOptions
|
||||
options: CompilerOptions | BuildOptions,
|
||||
): DiagnosticReporter {
|
||||
return shouldBePretty(sys, options) ?
|
||||
createDiagnosticReporter(sys, /*pretty*/ true) :
|
||||
@@ -185,7 +185,7 @@ function createColors(sys: System) {
|
||||
bold: (str: string) => str,
|
||||
blue: (str: string) => str,
|
||||
blueBackground: (str: string) => str,
|
||||
brightWhite: (str: string) => str
|
||||
brightWhite: (str: string) => str,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ function createColors(sys: System) {
|
||||
bold,
|
||||
blue,
|
||||
brightWhite,
|
||||
blueBackground
|
||||
blueBackground,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -249,13 +249,12 @@ function generateOptionOutput(sys: System, option: CommandLineOption, rightAlign
|
||||
|
||||
// value type and possible value
|
||||
const valueCandidates = getValueCandidate(option);
|
||||
const defaultValueDescription =
|
||||
typeof option.defaultValueDescription === "object"
|
||||
? getDiagnosticText(option.defaultValueDescription)
|
||||
: formatDefaultValue(
|
||||
option.defaultValueDescription,
|
||||
option.type === "list" || option.type === "listOrElement" ? option.element.type : option.type
|
||||
);
|
||||
const defaultValueDescription = typeof option.defaultValueDescription === "object"
|
||||
? getDiagnosticText(option.defaultValueDescription)
|
||||
: formatDefaultValue(
|
||||
option.defaultValueDescription,
|
||||
option.type === "list" || option.type === "listOrElement" ? option.element.type : option.type,
|
||||
);
|
||||
const terminalWidth = sys.getWidthOfTerminal?.() ?? 0;
|
||||
|
||||
// Note: child_process might return `terminalWidth` as undefined.
|
||||
@@ -300,14 +299,14 @@ function generateOptionOutput(sys: System, option: CommandLineOption, rightAlign
|
||||
|
||||
function formatDefaultValue(
|
||||
defaultValue: CommandLineOption["defaultValueDescription"],
|
||||
type: CommandLineOption["type"]
|
||||
type: CommandLineOption["type"],
|
||||
) {
|
||||
return defaultValue !== undefined && typeof type === "object"
|
||||
// e.g. ScriptTarget.ES2015 -> "es6/es2015"
|
||||
? arrayFrom(type.entries())
|
||||
.filter(([, value]) => value === defaultValue)
|
||||
.map(([name]) => name)
|
||||
.join("/")
|
||||
.filter(([, value]) => value === defaultValue)
|
||||
.map(([name]) => name)
|
||||
.join("/")
|
||||
: String(defaultValue);
|
||||
}
|
||||
|
||||
@@ -361,7 +360,7 @@ function generateOptionOutput(sys: System, option: CommandLineOption, rightAlign
|
||||
|
||||
return {
|
||||
valueType: getValueType(option),
|
||||
possibleValues: getPossibleValues(option)
|
||||
possibleValues: getPossibleValues(option),
|
||||
};
|
||||
|
||||
function getValueType(option: CommandLineOption) {
|
||||
@@ -396,7 +395,7 @@ function generateOptionOutput(sys: System, option: CommandLineOption, rightAlign
|
||||
default:
|
||||
// Map<string, number | string>
|
||||
// Group synonyms: es6/es2015
|
||||
const inverted: { [value: string]: string[] } = {};
|
||||
const inverted: { [value: string]: string[]; } = {};
|
||||
option.type.forEach((value, name) => {
|
||||
(inverted[value] ||= []).push(name);
|
||||
});
|
||||
@@ -469,7 +468,7 @@ function generateSectionOptionsOutput(sys: System, sectionName: string, options:
|
||||
|
||||
function printEasyHelp(sys: System, simpleOptions: readonly CommandLineOption[]) {
|
||||
const colors = createColors(sys);
|
||||
let output: string[] = [...getHeader(sys,`${getDiagnosticText(Diagnostics.tsc_Colon_The_TypeScript_Compiler)} - ${getDiagnosticText(Diagnostics.Version_0, version)}`)];
|
||||
let output: string[] = [...getHeader(sys, `${getDiagnosticText(Diagnostics.tsc_Colon_The_TypeScript_Compiler)} - ${getDiagnosticText(Diagnostics.Version_0, version)}`)];
|
||||
output.push(colors.bold(getDiagnosticText(Diagnostics.COMMON_COMMANDS)) + sys.newLine + sys.newLine);
|
||||
|
||||
example("tsc", Diagnostics.Compiles_the_current_project_tsconfig_json_in_the_working_directory);
|
||||
@@ -486,7 +485,7 @@ function printEasyHelp(sys: System, simpleOptions: readonly CommandLineOption[])
|
||||
output = [
|
||||
...output,
|
||||
...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.COMMAND_LINE_FLAGS), cliCommands, /*subCategory*/ false, /*beforeOptionsDescription*/ undefined, /*afterOptionsDescription*/ undefined),
|
||||
...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.COMMON_COMPILER_OPTIONS), configOpts, /*subCategory*/ false, /*beforeOptionsDescription*/ undefined, formatMessage(Diagnostics.You_can_learn_about_all_of_the_compiler_options_at_0, "https://aka.ms/tsc"))
|
||||
...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.COMMON_COMPILER_OPTIONS), configOpts, /*subCategory*/ false, /*beforeOptionsDescription*/ undefined, formatMessage(Diagnostics.You_can_learn_about_all_of_the_compiler_options_at_0, "https://aka.ms/tsc")),
|
||||
];
|
||||
|
||||
for (const line of output) {
|
||||
@@ -503,7 +502,7 @@ function printEasyHelp(sys: System, simpleOptions: readonly CommandLineOption[])
|
||||
}
|
||||
|
||||
function printAllHelp(sys: System, compilerOptions: readonly CommandLineOption[], buildOptions: readonly CommandLineOption[], watchOptions: readonly CommandLineOption[]) {
|
||||
let output: string[] = [...getHeader(sys,`${getDiagnosticText(Diagnostics.tsc_Colon_The_TypeScript_Compiler)} - ${getDiagnosticText(Diagnostics.Version_0, version)}`)];
|
||||
let output: string[] = [...getHeader(sys, `${getDiagnosticText(Diagnostics.tsc_Colon_The_TypeScript_Compiler)} - ${getDiagnosticText(Diagnostics.Version_0, version)}`)];
|
||||
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.ALL_COMPILER_OPTIONS), compilerOptions, /*subCategory*/ true, /*beforeOptionsDescription*/ undefined, formatMessage(Diagnostics.You_can_learn_about_all_of_the_compiler_options_at_0, "https://aka.ms/tsc"))];
|
||||
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.WATCH_OPTIONS), watchOptions, /*subCategory*/ false, getDiagnosticText(Diagnostics.Including_watch_w_will_start_watching_the_current_project_for_the_file_changes_Once_set_you_can_config_watch_mode_with_Colon))];
|
||||
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.BUILD_OPTIONS), buildOptions, /*subCategory*/ false, formatMessage(Diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0, "https://aka.ms/tsc-composite-builds"))];
|
||||
@@ -513,7 +512,7 @@ function printAllHelp(sys: System, compilerOptions: readonly CommandLineOption[]
|
||||
}
|
||||
|
||||
function printBuildHelp(sys: System, buildOptions: readonly CommandLineOption[]) {
|
||||
let output: string[] = [...getHeader(sys,`${getDiagnosticText(Diagnostics.tsc_Colon_The_TypeScript_Compiler)} - ${getDiagnosticText(Diagnostics.Version_0, version)}`)];
|
||||
let output: string[] = [...getHeader(sys, `${getDiagnosticText(Diagnostics.tsc_Colon_The_TypeScript_Compiler)} - ${getDiagnosticText(Diagnostics.Version_0, version)}`)];
|
||||
output = [...output, ...generateSectionOptionsOutput(sys, getDiagnosticText(Diagnostics.BUILD_OPTIONS), buildOptions, /*subCategory*/ false, formatMessage(Diagnostics.Using_build_b_will_make_tsc_behave_more_like_a_build_orchestrator_than_a_compiler_This_is_used_to_trigger_building_composite_projects_which_you_can_learn_more_about_at_0, "https://aka.ms/tsc-composite-builds"))];
|
||||
for (const line of output) {
|
||||
sys.write(line);
|
||||
@@ -637,7 +636,7 @@ function executeCommandLineWorker(
|
||||
const currentDirectory = sys.getCurrentDirectory();
|
||||
const commandLineOptions = convertToOptionsWithAbsolutePaths(
|
||||
commandLine.options,
|
||||
fileName => getNormalizedAbsolutePath(fileName, currentDirectory)
|
||||
fileName => getNormalizedAbsolutePath(fileName, currentDirectory),
|
||||
);
|
||||
if (configFileName) {
|
||||
const extendedConfigCache = new Map<string, ExtendedConfigCacheEntry>();
|
||||
@@ -647,7 +646,7 @@ function executeCommandLineWorker(
|
||||
reportDiagnostic = updateReportDiagnostic(
|
||||
sys,
|
||||
reportDiagnostic,
|
||||
configParseResult.options
|
||||
configParseResult.options,
|
||||
);
|
||||
configParseResult.errors.forEach(reportDiagnostic);
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
@@ -659,7 +658,7 @@ function executeCommandLineWorker(
|
||||
reportDiagnostic = updateReportDiagnostic(
|
||||
sys,
|
||||
reportDiagnostic,
|
||||
configParseResult.options
|
||||
configParseResult.options,
|
||||
);
|
||||
if (isWatchSet(configParseResult.options)) {
|
||||
if (reportWatchModeWithoutSysSupport(sys, reportDiagnostic)) return;
|
||||
@@ -678,7 +677,7 @@ function executeCommandLineWorker(
|
||||
sys,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
configParseResult
|
||||
configParseResult,
|
||||
);
|
||||
}
|
||||
else {
|
||||
@@ -686,7 +685,7 @@ function executeCommandLineWorker(
|
||||
sys,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
configParseResult
|
||||
configParseResult,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -699,7 +698,7 @@ function executeCommandLineWorker(
|
||||
reportDiagnostic = updateReportDiagnostic(
|
||||
sys,
|
||||
reportDiagnostic,
|
||||
commandLineOptions
|
||||
commandLineOptions,
|
||||
);
|
||||
if (isWatchSet(commandLineOptions)) {
|
||||
if (reportWatchModeWithoutSysSupport(sys, reportDiagnostic)) return;
|
||||
@@ -717,7 +716,7 @@ function executeCommandLineWorker(
|
||||
sys,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
{ ...commandLine, options: commandLineOptions }
|
||||
{ ...commandLine, options: commandLineOptions },
|
||||
);
|
||||
}
|
||||
else {
|
||||
@@ -725,7 +724,7 @@ function executeCommandLineWorker(
|
||||
sys,
|
||||
cb,
|
||||
reportDiagnostic,
|
||||
{ ...commandLine, options: commandLineOptions }
|
||||
{ ...commandLine, options: commandLineOptions },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -748,14 +747,15 @@ export function executeCommandLine(
|
||||
if (isBuild(commandLineArgs)) {
|
||||
const { buildOptions, watchOptions, projects, errors } = parseBuildCommand(commandLineArgs.slice(1));
|
||||
if (buildOptions.generateCpuProfile && system.enableCPUProfiler) {
|
||||
system.enableCPUProfiler(buildOptions.generateCpuProfile, () => performBuild(
|
||||
system,
|
||||
cb,
|
||||
buildOptions,
|
||||
watchOptions,
|
||||
projects,
|
||||
errors
|
||||
));
|
||||
system.enableCPUProfiler(buildOptions.generateCpuProfile, () =>
|
||||
performBuild(
|
||||
system,
|
||||
cb,
|
||||
buildOptions,
|
||||
watchOptions,
|
||||
projects,
|
||||
errors,
|
||||
));
|
||||
}
|
||||
else {
|
||||
return performBuild(
|
||||
@@ -764,18 +764,19 @@ export function executeCommandLine(
|
||||
buildOptions,
|
||||
watchOptions,
|
||||
projects,
|
||||
errors
|
||||
errors,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const commandLine = parseCommandLine(commandLineArgs, path => system.readFile(path));
|
||||
if (commandLine.options.generateCpuProfile && system.enableCPUProfiler) {
|
||||
system.enableCPUProfiler(commandLine.options.generateCpuProfile, () => executeCommandLineWorker(
|
||||
system,
|
||||
cb,
|
||||
commandLine,
|
||||
));
|
||||
system.enableCPUProfiler(commandLine.options.generateCpuProfile, () =>
|
||||
executeCommandLineWorker(
|
||||
system,
|
||||
cb,
|
||||
commandLine,
|
||||
));
|
||||
}
|
||||
else {
|
||||
return executeCommandLineWorker(system, cb, commandLine);
|
||||
@@ -797,13 +798,13 @@ function performBuild(
|
||||
buildOptions: BuildOptions,
|
||||
watchOptions: WatchOptions | undefined,
|
||||
projects: string[],
|
||||
errors: Diagnostic[]
|
||||
errors: Diagnostic[],
|
||||
) {
|
||||
// Update to pretty if host supports it
|
||||
const reportDiagnostic = updateReportDiagnostic(
|
||||
sys,
|
||||
createDiagnosticReporter(sys),
|
||||
buildOptions
|
||||
buildOptions,
|
||||
);
|
||||
|
||||
if (buildOptions.locale) {
|
||||
@@ -839,7 +840,7 @@ function performBuild(
|
||||
/*createProgram*/ undefined,
|
||||
reportDiagnostic,
|
||||
createBuilderStatusReporter(sys, shouldBePretty(sys, buildOptions)),
|
||||
createWatchStatusReporter(sys, buildOptions)
|
||||
createWatchStatusReporter(sys, buildOptions),
|
||||
);
|
||||
const solutionPerformance = enableSolutionPerformance(sys, buildOptions);
|
||||
updateSolutionBuilderHost(sys, cb, buildHost, solutionPerformance);
|
||||
@@ -847,10 +848,12 @@ function performBuild(
|
||||
let reportBuildStatistics = false;
|
||||
buildHost.onWatchStatusChange = (d, newLine, options, errorCount) => {
|
||||
onWatchStatusChange?.(d, newLine, options, errorCount);
|
||||
if (reportBuildStatistics && (
|
||||
d.code === Diagnostics.Found_0_errors_Watching_for_file_changes.code ||
|
||||
d.code === Diagnostics.Found_1_error_Watching_for_file_changes.code
|
||||
)) {
|
||||
if (
|
||||
reportBuildStatistics && (
|
||||
d.code === Diagnostics.Found_0_errors_Watching_for_file_changes.code ||
|
||||
d.code === Diagnostics.Found_1_error_Watching_for_file_changes.code
|
||||
)
|
||||
) {
|
||||
reportSolutionBuilderTimes(builder, solutionPerformance);
|
||||
}
|
||||
};
|
||||
@@ -866,7 +869,7 @@ function performBuild(
|
||||
/*createProgram*/ undefined,
|
||||
reportDiagnostic,
|
||||
createBuilderStatusReporter(sys, shouldBePretty(sys, buildOptions)),
|
||||
createReportErrorSummary(sys, buildOptions)
|
||||
createReportErrorSummary(sys, buildOptions),
|
||||
);
|
||||
const solutionPerformance = enableSolutionPerformance(sys, buildOptions);
|
||||
updateSolutionBuilderHost(sys, cb, buildHost, solutionPerformance);
|
||||
@@ -887,7 +890,7 @@ function performCompilation(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
reportDiagnostic: DiagnosticReporter,
|
||||
config: ParsedCommandLine
|
||||
config: ParsedCommandLine,
|
||||
) {
|
||||
const { fileNames, options, projectReferences } = config;
|
||||
const host = createCompilerHostWorker(options, /*setParentNodes*/ undefined, sys);
|
||||
@@ -901,14 +904,14 @@ function performCompilation(
|
||||
options,
|
||||
projectReferences,
|
||||
host,
|
||||
configFileParsingDiagnostics: getConfigFileParsingDiagnostics(config)
|
||||
configFileParsingDiagnostics: getConfigFileParsingDiagnostics(config),
|
||||
};
|
||||
const program = createProgram(programOptions);
|
||||
const exitStatus = emitFilesAndReportErrorsAndGetExitStatus(
|
||||
program,
|
||||
reportDiagnostic,
|
||||
s => sys.write(s + sys.newLine),
|
||||
createReportErrorSummary(sys, options)
|
||||
createReportErrorSummary(sys, options),
|
||||
);
|
||||
reportStatistics(sys, program, /*solutionPerformance*/ undefined);
|
||||
cb(program);
|
||||
@@ -919,7 +922,7 @@ function performIncrementalCompilation(
|
||||
sys: System,
|
||||
cb: ExecuteCommandLineCallbacks,
|
||||
reportDiagnostic: DiagnosticReporter,
|
||||
config: ParsedCommandLine
|
||||
config: ParsedCommandLine,
|
||||
) {
|
||||
const { options, fileNames, projectReferences } = config;
|
||||
enableStatisticsAndTracing(sys, options, /*isBuildMode*/ false);
|
||||
@@ -936,7 +939,7 @@ function performIncrementalCompilation(
|
||||
afterProgramEmitAndDiagnostics: builderProgram => {
|
||||
reportStatistics(sys, builderProgram.getProgram(), /*solutionPerformance*/ undefined);
|
||||
cb(builderProgram);
|
||||
}
|
||||
},
|
||||
});
|
||||
return sys.exit(exitStatus);
|
||||
}
|
||||
@@ -1003,7 +1006,7 @@ function createWatchOfConfigFile(
|
||||
watchOptionsToExtend,
|
||||
system,
|
||||
reportDiagnostic,
|
||||
reportWatchStatus: createWatchStatusReporter(system, configParseResult.options)
|
||||
reportWatchStatus: createWatchStatusReporter(system, configParseResult.options),
|
||||
});
|
||||
updateWatchCompilationHost(system, cb, watchCompilerHost);
|
||||
watchCompilerHost.configFileParsingResult = configParseResult;
|
||||
@@ -1025,7 +1028,7 @@ function createWatchOfFilesAndCompilerOptions(
|
||||
watchOptions,
|
||||
system,
|
||||
reportDiagnostic,
|
||||
reportWatchStatus: createWatchStatusReporter(system, options)
|
||||
reportWatchStatus: createWatchStatusReporter(system, options),
|
||||
});
|
||||
updateWatchCompilationHost(system, cb, watchCompilerHost);
|
||||
return createWatchProgram(watchCompilerHost);
|
||||
@@ -1074,7 +1077,8 @@ function createSolutionPerfomrance(): SolutionPerformance {
|
||||
|
||||
function reportSolutionBuilderTimes(
|
||||
builder: SolutionBuilder<EmitAndSemanticDiagnosticsBuilderProgram>,
|
||||
solutionPerformance: SolutionPerformance | undefined) {
|
||||
solutionPerformance: SolutionPerformance | undefined,
|
||||
) {
|
||||
if (!solutionPerformance) return;
|
||||
|
||||
if (!performance.isEnabled()) {
|
||||
@@ -1128,8 +1132,7 @@ function enableStatisticsAndTracing(system: System, compilerOptions: CompilerOpt
|
||||
}
|
||||
|
||||
if (canTrace(system, compilerOptions)) {
|
||||
startTracing(isBuildMode ? "build" : "project",
|
||||
compilerOptions.generateTrace!, compilerOptions.configFilePath);
|
||||
startTracing(isBuildMode ? "build" : "project", compilerOptions.generateTrace!, compilerOptions.configFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1280,7 +1283,7 @@ function writeConfigFile(
|
||||
sys: System,
|
||||
reportDiagnostic: DiagnosticReporter,
|
||||
options: CompilerOptions,
|
||||
fileNames: string[]
|
||||
fileNames: string[],
|
||||
) {
|
||||
const currentDirectory = sys.getCurrentDirectory();
|
||||
const file = normalizePath(combinePaths(currentDirectory, "tsconfig.json"));
|
||||
@@ -1289,7 +1292,7 @@ function writeConfigFile(
|
||||
}
|
||||
else {
|
||||
sys.writeFile(file, generateTSConfig(options, fileNames, sys.newLine));
|
||||
const output: string[] = [sys.newLine, ...getHeader(sys,"Created a new tsconfig.json with:")];
|
||||
const output: string[] = [sys.newLine, ...getHeader(sys, "Created a new tsconfig.json with:")];
|
||||
output.push(getCompilerOptionsDiffValue(options, sys.newLine) + sys.newLine + sys.newLine);
|
||||
output.push(`You can learn more at https://aka.ms/tsconfig` + sys.newLine);
|
||||
for (const line of output) {
|
||||
|
||||
Reference in New Issue
Block a user