Skip to content
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

feat(51000) - Flag Deprecation Plan #51424

Merged
merged 16 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
20 changes: 19 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
createDiagnosticForNodeInSourceFile,
createGetCanonicalFileName,
Debug,
DeprecationVersion,
Diagnostic,
DiagnosticMessage,
Diagnostics,
Expand Down Expand Up @@ -234,6 +235,18 @@ export const libs = libEntries.map(entry => entry[0]);
*/
export const libMap = new Map(libEntries);

/** @internal */
export const ignoreDeprecationsMap = new Map([
[DeprecationVersion.v5_0, "5.0"],
[DeprecationVersion.v5_5, "5.5"],
[DeprecationVersion.v6_0, "6.0"],
]);

/** @internal */
export const inverseIgnoreDeprecationsMap = new Map(
arrayFrom(mapIterator(ignoreDeprecationsMap.entries(), ([key, value]) => [value, key]))
);

// Watch related options
/** @internal */
export const optionsForWatch: CommandLineOption[] = [
Expand Down Expand Up @@ -1470,7 +1483,12 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
description: Diagnostics.Control_what_method_is_used_to_detect_module_format_JS_files,
category: Diagnostics.Language_and_Environment,
defaultValueDescription: Diagnostics.auto_Colon_Treat_files_with_imports_exports_import_meta_jsx_with_jsx_Colon_react_jsx_or_esm_format_with_module_Colon_node16_as_modules,
}
},
{
name: "ignoreDeprecations",
type: inverseIgnoreDeprecationsMap,
defaultValueDescription: undefined,
},
];

/** @internal */
Expand Down
12 changes: 12 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -4221,6 +4221,18 @@
"category": "Error",
"code": 5095
},
"Flag '{0}' is deprecated and will stop functioning in TypeScript {1}. Specify 'ignoreDeprecations: \"{2}\"' to silence this error.": {
"category": "Error",
"code": 5096
},
"Flag '{0}' is deprecated, please remove it from your configuration.": {
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
"category": "Error",
"code": 5097
},
"Invalid value for '--ignoreDeprecations'.": {
"category": "Error",
"code": 5098
},

"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
Expand Down
59 changes: 57 additions & 2 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
CustomTransformers,
Debug,
DeclarationWithTypeParameterChildren,
DeprecationVersion,
Diagnostic,
DiagnosticCategory,
diagnosticCategoryName,
Expand Down Expand Up @@ -161,10 +162,12 @@ import {
HeritageClause,
Identifier,
identity,
ignoreDeprecationsMap,
ImportClause,
ImportDeclaration,
ImportOrExportSpecifier,
InputFiles,
inverseIgnoreDeprecationsMap,
inverseJsxOptionMap,
isAmbientModule,
isAnyImportOrReExport,
Expand Down Expand Up @@ -308,6 +311,7 @@ import {
UnparsedSource,
VariableDeclaration,
VariableStatement,
versionMajorMinor,
walkUpParenthesizedExpressions,
WriteFileCallback,
WriteFileCallbackData,
Expand Down Expand Up @@ -1358,8 +1362,8 @@ export function createProgram(createProgramOptions: CreateProgramOptions): Progr
* @param configFileParsingDiagnostics - error during config file parsing
* @returns A 'Program' object.
*/
export function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program;
export function createProgram(rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[]): Program {
export function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[], typeScriptVersion?: string): Program;
export function createProgram(rootNamesOrOptions: readonly string[] | CreateProgramOptions, _options?: CompilerOptions, _host?: CompilerHost, _oldProgram?: Program, _configFileParsingDiagnostics?: readonly Diagnostic[], typeScriptVersion?: string): Program {
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions; // TODO: GH#18217
const { rootNames, options, configFileParsingDiagnostics, projectReferences } = createProgramOptions;
let { oldProgram } = createProgramOptions;
Expand Down Expand Up @@ -3886,6 +3890,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
programDiagnostics.add(createCompilerDiagnostic(Diagnostics.Option_incremental_can_only_be_specified_using_tsconfig_emitting_to_single_file_or_when_option_tsBuildInfoFile_is_specified));
}

verifyDeprecatedCompilerOptions();
verifyProjectReferences();

// List of collected files is complete; validate exhautiveness if this is a project with a file list
Expand Down Expand Up @@ -4148,6 +4153,56 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}

function verifyDeprecatedCompilerOptions() {
const version = typeScriptVersion || versionMajorMinor;
const deprecationVersion = inverseIgnoreDeprecationsMap.get(version) as DeprecationVersion;
if (options.ignoreDeprecations) {
const ignoreDeprecationVersion = options.ignoreDeprecations && ignoreDeprecationsMap.get(options.ignoreDeprecations);
if (ignoreDeprecationVersion === undefined || deprecationVersion && options.ignoreDeprecations < deprecationVersion) {
createOptionValueDiagnostic("ignoreDeprecations", Diagnostics.Invalid_value_for_ignoreDeprecations);
}
else {
if (deprecationVersion === DeprecationVersion.v5_0) {
return;
}
}
}
if (options.target === ScriptTarget.ES3) {
createDeprecatedDiagnosticForOption(version, deprecationVersion, "target", "ES3");
}
if (options.noImplicitUseStrict) {
createDeprecatedDiagnosticForOption(version, deprecationVersion, "noImplicitUseStrict");
}
if (options.keyofStringsOnly) {
createDeprecatedDiagnosticForOption(version, deprecationVersion, "keyofStringsOnly");
}
if (options.suppressExcessPropertyErrors) {
createDeprecatedDiagnosticForOption(version, deprecationVersion, "suppressExcessPropertyErrors");
}
if (options.suppressImplicitAnyIndexErrors) {
createDeprecatedDiagnosticForOption(version, deprecationVersion, "suppressImplicitAnyIndexErrors");
}
if (options.noStrictGenericChecks) {
createDeprecatedDiagnosticForOption(version, deprecationVersion, "noStrictGenericChecks");
}
if (options.charset) {
createDeprecatedDiagnosticForOption(version, deprecationVersion, "charset");
}
if (options.out) {
createDeprecatedDiagnosticForOption(version, deprecationVersion, "out");
}
}

function createDeprecatedDiagnosticForOption(version: string, deprecationVersion: DeprecationVersion, name: string, value?: string) {
if (deprecationVersion === DeprecationVersion.v6_0) {
createDiagnosticForOption(/*onKey*/ !value, name, /*option2*/ undefined, Diagnostics.Flag_0_is_deprecated_please_remove_it_from_your_configuration, value || name);
}
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, ignoreDeprecationsMap.get(deprecationVersion + 1), version);
}
}

function createDiagnosticExplainingFile(file: SourceFile | undefined, fileProcessingReason: FileIncludeReason | undefined, diagnostic: DiagnosticMessage, args: (string | number | undefined)[] | undefined): Diagnostic {
let fileIncludeReasons: DiagnosticMessageChain[] | undefined;
let relatedInfo: Diagnostic[] | undefined;
Expand Down
10 changes: 10 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6701,6 +6701,7 @@ export interface CompilerOptions {
/** @internal */generateCpuProfile?: string;
/** @internal */generateTrace?: string;
/** @internal */help?: boolean;
ignoreDeprecations?: DeprecationVersion;
importHelpers?: boolean;
importsNotUsedAsValues?: ImportsNotUsedAsValues;
/** @internal */init?: boolean;
Expand Down Expand Up @@ -9441,3 +9442,12 @@ export interface Queue<T> {
dequeue(): T;
isEmpty(): boolean;
}

/** @internal */
export const enum DeprecationVersion {
/* eslint-disable @typescript-eslint/naming-convention */
v5_0 = 1,
v5_5 = 2,
v6_0 = 3,
/* eslint-enable @typescript-eslint/naming-convention */
}
6 changes: 3 additions & 3 deletions src/harness/compilerImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class CompilationResult {
}
}

export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | undefined, compilerOptions: ts.CompilerOptions): CompilationResult {
export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | undefined, compilerOptions: ts.CompilerOptions, typeScriptVersion?: string): CompilationResult {
if (compilerOptions.project || !rootFiles || rootFiles.length === 0) {
const project = readProject(host.parseConfigHost, compilerOptions.project, compilerOptions);
if (project) {
Expand All @@ -266,10 +266,10 @@ export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | und
// and if the test is running `skipLibCheck` - an indicator that we want the tets to run quickly - skip the before/after error comparison, too
const skipErrorComparison = ts.length(rootFiles) >= 100 || (!!compilerOptions.skipLibCheck && !!compilerOptions.declaration);

const preProgram = !skipErrorComparison ? ts.createProgram(rootFiles || [], { ...compilerOptions, configFile: compilerOptions.configFile, traceResolution: false }, host) : undefined;
const preProgram = !skipErrorComparison ? ts.createProgram(rootFiles || [], { ...compilerOptions, configFile: compilerOptions.configFile, traceResolution: false }, host, /*oldProgram*/ undefined, /*configFileParsingDiagnostics*/ undefined, typeScriptVersion) : undefined;
const preErrors = preProgram && ts.getPreEmitDiagnostics(preProgram);

const program = ts.createProgram(rootFiles || [], compilerOptions, host);
const program = ts.createProgram(rootFiles || [], compilerOptions, host, /*oldProgram*/ undefined, /*configFileParsingDiagnostics*/ undefined, typeScriptVersion);
const emitResult = program.emit();
const postErrors = ts.getPreEmitDiagnostics(program);
const longerErrors = ts.length(preErrors) > postErrors.length ? preErrors : postErrors;
Expand Down
10 changes: 9 additions & 1 deletion src/harness/harnessIO.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,9 @@ export namespace Compiler {
if (value === undefined) {
throw new Error(`Cannot have undefined value for compiler option '${name}'.`);
}
if (name === "typeScriptVersion") {
continue;
}
const option = getCommandLineOption(name);
if (option) {
const errors: ts.Diagnostic[] = [];
Expand Down Expand Up @@ -411,9 +414,14 @@ export namespace Compiler {
currentDirectory = vfs.srcFolder;
}

let typeScriptVersion: string | undefined;

// Parse settings
if (harnessSettings) {
setCompilerOptionsFromHarnessSetting(harnessSettings, options);
if (ts.isString(harnessSettings.typeScriptVersion) && harnessSettings.typeScriptVersion) {
typeScriptVersion = harnessSettings.typeScriptVersion;
}
}
if (options.rootDirs) {
options.rootDirs = ts.map(options.rootDirs, d => ts.getNormalizedAbsolutePath(d, currentDirectory));
Expand Down Expand Up @@ -441,7 +449,7 @@ export namespace Compiler {
fs.apply(symlinks);
}
const host = new fakes.CompilerHost(fs, options);
const result = compiler.compileFiles(host, programFileNames, options);
const result = compiler.compileFiles(host, programFileNames, options, typeScriptVersion);
result.symlinks = symlinks;
return result;
}
Expand Down
43 changes: 43 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions1.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/foo/tsconfig.json(3,19): error TS5096: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
/foo/tsconfig.json(4,9): error TS5096: Flag 'noImplicitUseStrict' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
/foo/tsconfig.json(5,9): error TS5096: Flag 'keyofStringsOnly' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
/foo/tsconfig.json(6,9): error TS5096: Flag 'suppressExcessPropertyErrors' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
/foo/tsconfig.json(7,9): error TS5096: Flag 'suppressImplicitAnyIndexErrors' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
/foo/tsconfig.json(8,9): error TS5096: Flag 'noStrictGenericChecks' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
/foo/tsconfig.json(9,9): error TS5096: Flag 'charset' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
/foo/tsconfig.json(10,9): error TS5096: Flag 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


==== /foo/tsconfig.json (8 errors) ====
{
"compilerOptions": {
"target": "ES3",
~~~~~
!!! error TS5096: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
"noImplicitUseStrict": true,
~~~~~~~~~~~~~~~~~~~~~
!!! error TS5096: Flag 'noImplicitUseStrict' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
"keyofStringsOnly": true,
~~~~~~~~~~~~~~~~~~
!!! error TS5096: Flag 'keyofStringsOnly' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
"suppressExcessPropertyErrors": true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS5096: Flag 'suppressExcessPropertyErrors' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
"suppressImplicitAnyIndexErrors": true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS5096: Flag 'suppressImplicitAnyIndexErrors' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
"noStrictGenericChecks": true,
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS5096: Flag 'noStrictGenericChecks' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
"charset": "utf8",
~~~~~~~~~
!!! error TS5096: Flag 'charset' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
"out": "dist.js"
~~~~~
!!! error TS5096: Flag 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
}
}

==== /foo/a.ts (0 errors) ====
const a = 1;

6 changes: 6 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [a.ts]
const a = 1;


//// [dist.js]
var a = 1;
4 changes: 4 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== /foo/a.ts ===
const a = 1;
>a : Symbol(a, Decl(a.ts, 0, 5))

5 changes: 5 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== /foo/a.ts ===
const a = 1;
>a : 1
>1 : 1

6 changes: 6 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [a.ts]
const a = 1;


//// [dist.js]
var a = 1;
4 changes: 4 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions2.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== /foo/a.ts ===
const a = 1;
>a : Symbol(a, Decl(a.ts, 0, 5))

5 changes: 5 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== /foo/a.ts ===
const a = 1;
>a : 1
>1 : 1

43 changes: 43 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions3.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/foo/tsconfig.json(3,19): error TS5097: Flag 'ES3' is deprecated, please remove it from your configuration.
/foo/tsconfig.json(4,9): error TS5097: Flag 'noImplicitUseStrict' is deprecated, please remove it from your configuration.
/foo/tsconfig.json(5,9): error TS5097: Flag 'keyofStringsOnly' is deprecated, please remove it from your configuration.
/foo/tsconfig.json(6,9): error TS5097: Flag 'suppressExcessPropertyErrors' is deprecated, please remove it from your configuration.
/foo/tsconfig.json(7,9): error TS5097: Flag 'suppressImplicitAnyIndexErrors' is deprecated, please remove it from your configuration.
/foo/tsconfig.json(8,9): error TS5097: Flag 'noStrictGenericChecks' is deprecated, please remove it from your configuration.
/foo/tsconfig.json(9,9): error TS5097: Flag 'charset' is deprecated, please remove it from your configuration.
/foo/tsconfig.json(10,9): error TS5097: Flag 'out' is deprecated, please remove it from your configuration.


==== /foo/tsconfig.json (8 errors) ====
{
"compilerOptions": {
"target": "ES3",
~~~~~
!!! error TS5097: Flag 'ES3' is deprecated, please remove it from your configuration.
"noImplicitUseStrict": true,
~~~~~~~~~~~~~~~~~~~~~
!!! error TS5097: Flag 'noImplicitUseStrict' is deprecated, please remove it from your configuration.
"keyofStringsOnly": true,
~~~~~~~~~~~~~~~~~~
!!! error TS5097: Flag 'keyofStringsOnly' is deprecated, please remove it from your configuration.
"suppressExcessPropertyErrors": true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS5097: Flag 'suppressExcessPropertyErrors' is deprecated, please remove it from your configuration.
"suppressImplicitAnyIndexErrors": true,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS5097: Flag 'suppressImplicitAnyIndexErrors' is deprecated, please remove it from your configuration.
"noStrictGenericChecks": true,
~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS5097: Flag 'noStrictGenericChecks' is deprecated, please remove it from your configuration.
"charset": "utf8",
~~~~~~~~~
!!! error TS5097: Flag 'charset' is deprecated, please remove it from your configuration.
"out": "dist.js"
~~~~~
!!! error TS5097: Flag 'out' is deprecated, please remove it from your configuration.
}
}

==== /foo/a.ts (0 errors) ====
const a = 1;

6 changes: 6 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//// [a.ts]
const a = 1;


//// [dist.js]
var a = 1;
4 changes: 4 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions3.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
=== /foo/a.ts ===
const a = 1;
>a : Symbol(a, Decl(a.ts, 0, 5))

5 changes: 5 additions & 0 deletions tests/baselines/reference/deprecatedCompilerOptions3.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
=== /foo/a.ts ===
const a = 1;
>a : 1
>1 : 1

Loading