Skip to content

Deprecate prepend option on project reference #52312

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

Merged
merged 3 commits into from
Jan 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 49 additions & 22 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -4350,27 +4356,47 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}

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) {
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);
}
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);
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/testRunner/unittests/tsbuild/amdModulesWithOut.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
3 changes: 3 additions & 0 deletions src/testRunner/unittests/tsbuild/javascriptProjectEmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"ignoreDeprecations":"5.0",
"composite": true,
"outFile": "sub-project.js",

Expand All @@ -150,6 +151,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"ignoreDeprecations":"5.0",
"composite": true,
"outFile": "sub-project-2.js",

Expand All @@ -162,6 +164,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
"/src/tsconfig.json": Utils.dedent`
{
"compilerOptions": {
"ignoreDeprecations":"5.0",
"composite": true,
"outFile": "src.js"
},
Expand Down
1 change: 1 addition & 0 deletions src/testRunner/unittests/tsbuild/outFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/testRunner/unittests/tsbuildWatch/programUpdates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }]
})
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const myVar = 30;
//// [/src/app/tsconfig.json]
{
"compilerOptions": {
"ignoreDeprecations": "5.0",
"target": "es5",
"module": "amd",
"composite": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ appfile4Spread(10, ...appfile4_ar);
//// [/src/app/tsconfig.json]
{
"compilerOptions": {
"ignoreDeprecations": "5.0",
"target": "es5",
"module": "amd",
"composite": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const myVar = 30;
//// [/src/app/tsconfig.json]
{
"compilerOptions": {
"ignoreDeprecations": "5.0",
"target": "es5",
"module": "amd",
"composite": true,
Expand Down
Loading