Skip to content

Commit 181cf21

Browse files
authored
Deprecate prepend option on project reference (#52312)
1 parent 81d0434 commit 181cf21

File tree

62 files changed

+937
-27
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+937
-27
lines changed

src/compiler/program.ts

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4307,17 +4307,23 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
43074307
}
43084308
}
43094309

4310-
function verifyDeprecatedCompilerOptions() {
4310+
function getVersionForDeprecationDiagnostics(reportInvalidIgnoreDeprecations: boolean) {
43114311
const version = typeScriptVersion || versionMajorMinor;
43124312
const ignoreDeprecations = options.ignoreDeprecations;
43134313
if (ignoreDeprecations) {
43144314
if (ignoreDeprecations === DeprecationVersion.v5_0 && (version === DeprecationVersion.v5_0 || version === DeprecationVersion.v5_5)) {
43154315
return;
43164316
}
4317-
else {
4317+
else if (reportInvalidIgnoreDeprecations) {
43184318
createOptionValueDiagnostic("ignoreDeprecations", Diagnostics.Invalid_value_for_ignoreDeprecations);
43194319
}
43204320
}
4321+
return version;
4322+
}
4323+
4324+
function verifyDeprecatedCompilerOptions() {
4325+
const version = getVersionForDeprecationDiagnostics(/*reportInvalidIgnoreDeprecations*/ true);
4326+
if (!version) return;
43214327
if (options.target === ScriptTarget.ES3) {
43224328
createDeprecatedDiagnosticForOption(version, "target", "ES3");
43234329
}
@@ -4350,27 +4356,47 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
43504356
}
43514357
}
43524358

4359+
function verifyDeprecatedProjectReference(ref: ProjectReference, parentFile: JsonSourceFile | undefined, index: number) {
4360+
if (ref.prepend) {
4361+
const version = getVersionForDeprecationDiagnostics(/*reportInvalidIgnoreDeprecations*/ false);
4362+
if (version) {
4363+
createDeprecatedOptionForVersionDiagnostic(
4364+
version,
4365+
(message, arg0, arg1, arg2) => createDiagnosticForReference(parentFile, index, message, arg0, arg1, arg2),
4366+
"prepend",
4367+
);
4368+
}
4369+
}
4370+
}
4371+
43534372
function createDeprecatedDiagnosticForOption(version: string, name: string, value?: string, useInstead?: string) {
4373+
return createDeprecatedOptionForVersionDiagnostic(
4374+
version,
4375+
(message, arg0, arg1, arg2) => {
4376+
if (useInstead) {
4377+
const details = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Use_0_instead, useInstead);
4378+
const chain = chainDiagnosticMessages(details, message, arg0, arg1, arg2);
4379+
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, chain);
4380+
}
4381+
else {
4382+
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, message, arg0, arg1, arg2);
4383+
}
4384+
},
4385+
name,
4386+
value,
4387+
);
4388+
}
4389+
4390+
function createDeprecatedOptionForVersionDiagnostic(
4391+
version: string,
4392+
createDiagnostic: (message: DiagnosticMessage, arg0: string, arg1?: string, arg2?: string) => void,
4393+
name: string,
4394+
value?: string) {
43544395
if (version === DeprecationVersion.v6_0) {
4355-
if (useInstead) {
4356-
const details = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Use_0_instead, useInstead);
4357-
const chain = chainDiagnosticMessages(details, Diagnostics.Flag_0_is_deprecated_Please_remove_it_from_your_configuration, value || name);
4358-
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, chain);
4359-
}
4360-
else {
4361-
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, Diagnostics.Flag_0_is_deprecated_Please_remove_it_from_your_configuration, value || name);
4362-
}
4396+
createDiagnostic(Diagnostics.Flag_0_is_deprecated_Please_remove_it_from_your_configuration, value || name);
43634397
}
43644398
else {
4365-
if (useInstead) {
4366-
const details = chainDiagnosticMessages(/*details*/ undefined, Diagnostics.Use_0_instead, useInstead);
4367-
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);
4368-
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, chain);
4369-
}
4370-
else {
4371-
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined,
4372-
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);
4373-
}
4399+
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);
43744400
}
43754401
}
43764402

@@ -4514,6 +4540,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
45144540
forEachProjectReference(projectReferences, resolvedProjectReferences, (resolvedRef, parent, index) => {
45154541
const ref = (parent ? parent.commandLine.projectReferences : projectReferences)![index];
45164542
const parentFile = parent && parent.sourceFile as JsonSourceFile;
4543+
verifyDeprecatedProjectReference(ref, parentFile, index);
45174544
if (!resolvedRef) {
45184545
createDiagnosticForReference(parentFile, index, Diagnostics.File_0_not_found, ref.path);
45194546
return;
@@ -4608,14 +4635,14 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
46084635
createDiagnosticForOption(/*onKey*/ false, option1, /*option2*/ undefined, message, arg0, arg1);
46094636
}
46104637

4611-
function createDiagnosticForReference(sourceFile: JsonSourceFile | undefined, index: number, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number) {
4638+
function createDiagnosticForReference(sourceFile: JsonSourceFile | undefined, index: number, message: DiagnosticMessage, arg0?: string | number, arg1?: string | number, arg2?: string | number) {
46124639
const referencesSyntax = firstDefined(getTsConfigPropArray(sourceFile || options.configFile, "references"),
46134640
property => isArrayLiteralExpression(property.initializer) ? property.initializer : undefined);
46144641
if (referencesSyntax && referencesSyntax.elements.length > index) {
4615-
programDiagnostics.add(createDiagnosticForNodeInSourceFile(sourceFile || options.configFile!, referencesSyntax.elements[index], message, arg0, arg1));
4642+
programDiagnostics.add(createDiagnosticForNodeInSourceFile(sourceFile || options.configFile!, referencesSyntax.elements[index], message, arg0, arg1, arg2));
46164643
}
46174644
else {
4618-
programDiagnostics.add(createCompilerDiagnostic(message, arg0, arg1));
4645+
programDiagnostics.add(createCompilerDiagnostic(message, arg0, arg1, arg2));
46194646
}
46204647
}
46214648

src/testRunner/unittests/tsbuild/amdModulesWithOut.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ describe("unittests:: tsbuild:: outFile:: on amd modules with --out", () => {
5959
subScenario: "modules and globals mixed in amd",
6060
});
6161

62+
verifyOutFileScenario({
63+
subScenario: "prepend reports deprecation error",
64+
modifyFs: fs => replaceText(fs, "/src/app/tsconfig.json", `"ignoreDeprecations": "5.0",`, ""),
65+
});
66+
6267
// Prologues
6368
describe("Prologues", () => {
6469
verifyOutFileScenario({

src/testRunner/unittests/tsbuild/javascriptProjectEmit.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
125125
{
126126
"extends": "../tsconfig.base.json",
127127
"compilerOptions": {
128+
"ignoreDeprecations":"5.0",
128129
"composite": true,
129130
"outFile": "sub-project.js",
130131
@@ -150,6 +151,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
150151
{
151152
"extends": "../tsconfig.base.json",
152153
"compilerOptions": {
154+
"ignoreDeprecations":"5.0",
153155
"composite": true,
154156
"outFile": "sub-project-2.js",
155157
@@ -162,6 +164,7 @@ describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
162164
"/src/tsconfig.json": Utils.dedent`
163165
{
164166
"compilerOptions": {
167+
"ignoreDeprecations":"5.0",
165168
"composite": true,
166169
"outFile": "src.js"
167170
},

src/testRunner/unittests/tsbuild/outFile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ ${internal} enum internalEnum { a, b, c }`);
611611
}));
612612
fs.writeFileSync("/src/third/tsconfig.json", JSON.stringify({
613613
compilerOptions: {
614+
ignoreDeprecations: "5.0",
614615
composite: true,
615616
declaration: true,
616617
declarationMap: false,

src/testRunner/unittests/tsbuildWatch/programUpdates.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ export class someClass2 { }`),
274274
const logicTsConfig: File = {
275275
path: logic[0].path,
276276
content: JSON.stringify({
277-
compilerOptions: { composite: true, declaration: true, outFile: "index.js" },
277+
compilerOptions: { ignoreDeprecations: "5.0", composite: true, declaration: true, outFile: "index.js" },
278278
references: [{ path: "../core", prepend: true }]
279279
})
280280
};

tests/baselines/reference/tsbuild/amdModulesWithOut/modules-and-globals-mixed-in-amd.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const myVar = 30;
2424
//// [/src/app/tsconfig.json]
2525
{
2626
"compilerOptions": {
27+
"ignoreDeprecations": "5.0",
2728
"target": "es5",
2829
"module": "amd",
2930
"composite": true,

tests/baselines/reference/tsbuild/amdModulesWithOut/multiple-emitHelpers-in-all-projects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ appfile4Spread(10, ...appfile4_ar);
2929
//// [/src/app/tsconfig.json]
3030
{
3131
"compilerOptions": {
32+
"ignoreDeprecations": "5.0",
3233
"target": "es5",
3334
"module": "amd",
3435
"composite": true,

tests/baselines/reference/tsbuild/amdModulesWithOut/multiple-prologues-in-all-projects.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const myVar = 30;
2626
//// [/src/app/tsconfig.json]
2727
{
2828
"compilerOptions": {
29+
"ignoreDeprecations": "5.0",
2930
"target": "es5",
3031
"module": "amd",
3132
"composite": true,

0 commit comments

Comments
 (0)