Deprecate prepend option on project reference (#52312)

This commit is contained in:
Sheetal Nandi
2023-01-20 12:10:18 -08:00
committed by GitHub
parent 81d04341e8
commit 181cf21b68
62 changed files with 938 additions and 28 deletions

View File

@@ -4307,17 +4307,23 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}
function verifyDeprecatedCompilerOptions() {
function getVersionForDeprecationDiagnostics(reportInvalidIgnoreDeprecations: boolean) {
const version = typeScriptVersion || versionMajorMinor;
const ignoreDeprecations = options.ignoreDeprecations;
if (ignoreDeprecations) {
if (ignoreDeprecations === DeprecationVersion.v5_0 && (version === DeprecationVersion.v5_0 || version === DeprecationVersion.v5_5)) {
return;
}
else {
else if (reportInvalidIgnoreDeprecations) {
createOptionValueDiagnostic("ignoreDeprecations", Diagnostics.Invalid_value_for_ignoreDeprecations);
}
}
return version;
}
function verifyDeprecatedCompilerOptions() {
const version = getVersionForDeprecationDiagnostics(/*reportInvalidIgnoreDeprecations*/ true);
if (!version) return;
if (options.target === ScriptTarget.ES3) {
createDeprecatedDiagnosticForOption(version, "target", "ES3");
}
@@ -4350,27 +4356,47 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}
function createDeprecatedDiagnosticForOption(version: string, name: string, value?: string, useInstead?: string) {
if (version === DeprecationVersion.v6_0) {
if (useInstead) {
const details = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Use_0_instead, useInstead);
const chain = chainDiagnosticMessages(details, Diagnostics.Flag_0_is_deprecated_Please_remove_it_from_your_configuration, value || name);
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, chain);
}
else {
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, Diagnostics.Flag_0_is_deprecated_Please_remove_it_from_your_configuration, value || name);
function verifyDeprecatedProjectReference(ref: ProjectReference, parentFile: JsonSourceFile | undefined, index: number) {
if (ref.prepend) {
const version = getVersionForDeprecationDiagnostics(/*reportInvalidIgnoreDeprecations*/ false);
if (version) {
createDeprecatedOptionForVersionDiagnostic(
version,
(message, arg0, arg1, arg2) => createDiagnosticForReference(parentFile, index, message, arg0, arg1, arg2),
"prepend",
);
}
}
}
function createDeprecatedDiagnosticForOption(version: string, name: string, value?: string, useInstead?: string) {
return createDeprecatedOptionForVersionDiagnostic(
version,
(message, arg0, arg1, arg2) => {
if (useInstead) {
const details = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Use_0_instead, useInstead);
const chain = chainDiagnosticMessages(details, message, arg0, arg1, arg2);
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, chain);
}
else {
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, message, arg0, arg1, arg2);
}
},
name,
value,
);
}
function createDeprecatedOptionForVersionDiagnostic(
version: string,
createDiagnostic: (message: DiagnosticMessage, arg0: string, arg1?: string, arg2?: string) => void,
name: string,
value?: string) {
if (version === DeprecationVersion.v6_0) {
createDiagnostic(Diagnostics.Flag_0_is_deprecated_Please_remove_it_from_your_configuration, value || name);
}
else {
if (useInstead) {
const details = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Use_0_instead, useInstead);
const chain = chainDiagnosticMessages(details, Diagnostics.Flag_0_is_deprecated_and_will_stop_functioning_in_TypeScript_1_Specify_ignoreDeprecations_Colon_2_to_silence_this_error, value || name, DeprecationVersion.v5_5, DeprecationVersion.v5_0);
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, chain);
}
else {
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined,
Diagnostics.Flag_0_is_deprecated_and_will_stop_functioning_in_TypeScript_1_Specify_ignoreDeprecations_Colon_2_to_silence_this_error, value || name, DeprecationVersion.v5_5, DeprecationVersion.v5_0);
}
createDiagnostic(Diagnostics.Flag_0_is_deprecated_and_will_stop_functioning_in_TypeScript_1_Specify_ignoreDeprecations_Colon_2_to_silence_this_error, value || name, DeprecationVersion.v5_5, DeprecationVersion.v5_0);
}
}
@@ -4514,6 +4540,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
forEachProjectReference(projectReferences, resolvedProjectReferences, (resolvedRef, parent, index) => {
const ref = (parent ? parent.commandLine.projectReferences : projectReferences)![index];
const parentFile = parent && parent.sourceFile as JsonSourceFile;
verifyDeprecatedProjectReference(ref, parentFile, index);
if (!resolvedRef) {
createDiagnosticForReference(parentFile, index, Diagnostics.File_0_not_found, ref.path);
return;
@@ -4608,14 +4635,14 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
createDiagnosticForOption(/*onKey*/ false, option1, /*option2*/ undefined, message, arg0, arg1);
}
function createDiagnosticForReference(sourceFile: JsonSourceFile | undefined, index: number, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number) {
function createDiagnosticForReference(sourceFile: JsonSourceFile | undefined, index: number, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number) {
const referencesSyntax = firstDefined(getTsConfigPropArray(sourceFile || options.configFile, "references"),
property => isArrayLiteralExpression(property.initializer) ? property.initializer : undefined);
if (referencesSyntax && referencesSyntax.elements.length > index) {
programDiagnostics.add(createDiagnosticForNodeInSourceFile(sourceFile || options.configFile!, referencesSyntax.elements[index], message, arg0, arg1));
programDiagnostics.add(createDiagnosticForNodeInSourceFile(sourceFile || options.configFile!, referencesSyntax.elements[index], message, arg0, arg1, arg2));
}
else {
programDiagnostics.add(createCompilerDiagnostic(message, arg0, arg1));
programDiagnostics.add(createCompilerDiagnostic(message, arg0, arg1, arg2));
}
}

View File

@@ -59,6 +59,11 @@ describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
subScenario: "modules and globals mixed in amd",
});
verifyOutFileScenario({
subScenario: "prepend reports deprecation error",
modifyFs: fs => replaceText(fs, "/src/app/tsconfig.json", `"ignoreDeprecations": "5.0",`, ""),
});
// Prologues
describe("Prologues", () => {
verifyOutFileScenario({

View File

@@ -125,6 +125,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"ignoreDeprecations":"5.0",
"composite": true,
"outFile": "sub-project.js",
@@ -150,6 +151,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"ignoreDeprecations":"5.0",
"composite": true,
"outFile": "sub-project-2.js",
@@ -162,6 +164,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
"/src/tsconfig.json": Utils.dedent`
{
"compilerOptions": {
"ignoreDeprecations":"5.0",
"composite": true,
"outFile": "src.js"
},

View File

@@ -611,6 +611,7 @@ ${internal} enum internalEnum { a, b, c }`);
}));
fs.writeFileSync("/src/third/tsconfig.json", JSON.stringify({
compilerOptions: {
ignoreDeprecations: "5.0",
composite: true,
declaration: true,
declarationMap: false,

View File

@@ -274,7 +274,7 @@ export class someClass2 { }`),
const logicTsConfig: File = {
path: logic[0].path,
content: JSON.stringify({
compilerOptions: { composite: true, declaration: true, outFile: "index.js" },
compilerOptions: { ignoreDeprecations: "5.0", composite: true, declaration: true, outFile: "index.js" },
references: [{ path: "../core", prepend: true }]
})
};