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 14 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 6 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1507,7 +1507,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: "string",
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 @@ -4245,6 +4245,18 @@
"category": "Error",
"code": 5100
},
"Flag '{0}' is deprecated and will stop functioning in TypeScript {1}. Specify 'ignoreDeprecations: \"{2}\"' to silence this error.": {
"category": "Error",
"code": 5101
},
"Flag '{0}' is deprecated, please remove it from your configuration.": {
a-tarasyuk marked this conversation as resolved.
Show resolved Hide resolved
"category": "Error",
"code": 5102
},
"Invalid value for '--ignoreDeprecations'.": {
"category": "Error",
"code": 5103
},

"Generates a sourcemap for each corresponding '.d.ts' file.": {
"category": "Message",
Expand Down
57 changes: 54 additions & 3 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 @@ -308,6 +309,7 @@ import {
UnparsedSource,
VariableDeclaration,
VariableStatement,
versionMajorMinor,
walkUpParenthesizedExpressions,
WriteFileCallback,
WriteFileCallbackData,
Expand Down Expand Up @@ -1392,13 +1394,14 @@ function shouldProgramCreateNewSourceFiles(program: Program | undefined, newOpti
return optionsHaveChanges(program.getCompilerOptions(), newOptions, sourceFileAffectingCompilerOptions);
}

function createCreateProgramOptions(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): CreateProgramOptions {
function createCreateProgramOptions(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[], typeScriptVersion?: string): CreateProgramOptions {
return {
rootNames,
options,
host,
oldProgram,
configFileParsingDiagnostics
configFileParsingDiagnostics,
typeScriptVersion,
};
}

Expand Down Expand Up @@ -1430,7 +1433,7 @@ export function createProgram(createProgramOptions: CreateProgramOptions): Progr
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 {
const createProgramOptions = isArray(rootNamesOrOptions) ? createCreateProgramOptions(rootNamesOrOptions, _options!, _host, _oldProgram, _configFileParsingDiagnostics) : rootNamesOrOptions; // TODO: GH#18217
const { rootNames, options, configFileParsingDiagnostics, projectReferences } = createProgramOptions;
const { rootNames, options, configFileParsingDiagnostics, projectReferences, typeScriptVersion } = createProgramOptions;
let { oldProgram } = createProgramOptions;

let processingDefaultLibFiles: SourceFile[] | undefined;
Expand Down Expand Up @@ -3989,6 +3992,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 @@ -4267,6 +4271,53 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}

function verifyDeprecatedCompilerOptions() {
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 {
createOptionValueDiagnostic("ignoreDeprecations", Diagnostics.Invalid_value_for_ignoreDeprecations);
}
}
if (options.target === ScriptTarget.ES3) {
createDeprecatedDiagnosticForOption(version, "target", "ES3");
}
if (options.noImplicitUseStrict) {
createDeprecatedDiagnosticForOption(version, "noImplicitUseStrict");
}
if (options.keyofStringsOnly) {
createDeprecatedDiagnosticForOption(version, "keyofStringsOnly");
}
if (options.suppressExcessPropertyErrors) {
createDeprecatedDiagnosticForOption(version, "suppressExcessPropertyErrors");
}
if (options.suppressImplicitAnyIndexErrors) {
createDeprecatedDiagnosticForOption(version, "suppressImplicitAnyIndexErrors");
}
if (options.noStrictGenericChecks) {
createDeprecatedDiagnosticForOption(version, "noStrictGenericChecks");
}
if (options.charset) {
createDeprecatedDiagnosticForOption(version, "charset");
}
if (options.out) {
createDeprecatedDiagnosticForOption(version, "out");
}
}

function createDeprecatedDiagnosticForOption(version: string, name: string, value?: string) {
if (version === 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, DeprecationVersion.v5_5, DeprecationVersion.v5_0);
}
}

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
12 changes: 12 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6991,6 +6991,7 @@ export interface CompilerOptions {
/** @internal */generateCpuProfile?: string;
/** @internal */generateTrace?: string;
/** @internal */help?: boolean;
ignoreDeprecations?: string;
importHelpers?: boolean;
importsNotUsedAsValues?: ImportsNotUsedAsValues;
/** @internal */init?: boolean;
Expand Down Expand Up @@ -7248,6 +7249,8 @@ export interface CreateProgramOptions {
host?: CompilerHost;
oldProgram?: Program;
configFileParsingDiagnostics?: readonly Diagnostic[];
/** @internal */
typeScriptVersion?: string;
}

/** @internal */
Expand Down Expand Up @@ -9754,3 +9757,12 @@ export interface Queue<T> {
dequeue(): T;
isEmpty(): boolean;
}

/** @internal */
export const enum DeprecationVersion {
/* eslint-disable @typescript-eslint/naming-convention */
v5_0 = "5.0",
v5_5 = "5.5",
v6_0 = "6.0",
/* eslint-enable @typescript-eslint/naming-convention */
}
7 changes: 3 additions & 4 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 @@ -265,11 +265,10 @@ export function compileFiles(host: fakes.CompilerHost, rootFiles: string[] | und
// pre-emit/post-emit error comparison requires declaration emit twice, which can be slow. If it's unlikely to flag any error consistency issues
// 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({ rootNames: rootFiles || [], options: { ...compilerOptions, configFile: compilerOptions.configFile, traceResolution: false }, host, typeScriptVersion }) : undefined;
const preErrors = preProgram && ts.getPreEmitDiagnostics(preProgram);

const program = ts.createProgram(rootFiles || [], compilerOptions, host);
const program = ts.createProgram({ rootNames: rootFiles || [], options: compilerOptions, host, 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 @@ -412,9 +415,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 @@ -442,7 +450,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
2 changes: 2 additions & 0 deletions tests/baselines/reference/ES3For-ofTypeCheck1.errors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck1.ts(1,15): error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.


!!! error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck1.ts (1 errors) ====
for (var v of "") { }
~~
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/reference/ES3For-ofTypeCheck2.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


!!! error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck2.ts (0 errors) ====
for (var v of [true]) { }
2 changes: 2 additions & 0 deletions tests/baselines/reference/ES3For-ofTypeCheck4.errors.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck4.ts(2,17): error TS2494: Using a string in a 'for...of' statement is only supported in ECMAScript 5 and higher.


!!! error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck4.ts (1 errors) ====
var union: string | string[];
for (const v of union) { }
Expand Down
7 changes: 7 additions & 0 deletions tests/baselines/reference/ES3For-ofTypeCheck6.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


!!! error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/conformance/statements/for-ofStatements/ES3For-ofTypeCheck6.ts (0 errors) ====
var union: string[] | number[];
for (var v of union) { }
2 changes: 2 additions & 0 deletions tests/baselines/reference/accessorWithES3.errors.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(10,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(15,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts(19,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.


!!! error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/accessorWithES3.ts (4 errors) ====
// error to use accessors in ES3 mode

Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/accessorsNotAllowedInES3.errors.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
tests/cases/compiler/accessorsNotAllowedInES3.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.
tests/cases/compiler/accessorsNotAllowedInES3.ts(4,15): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher.


!!! error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/compiler/accessorsNotAllowedInES3.ts (2 errors) ====
class C {
get x(): number { return 1; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error TS5053: Option 'noImplicitUseStrict' cannot be specified with option 'alwaysStrict'.
error TS5101: Flag 'noImplicitUseStrict' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
tests/cases/compiler/alwaysStrictNoImplicitUseStrict.ts(3,13): error TS1100: Invalid use of 'arguments' in strict mode.


!!! error TS5053: Option 'noImplicitUseStrict' cannot be specified with option 'alwaysStrict'.
!!! error TS5101: Flag 'noImplicitUseStrict' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/compiler/alwaysStrictNoImplicitUseStrict.ts (1 errors) ====
module M {
export function f() {
Expand Down
19 changes: 19 additions & 0 deletions tests/baselines/reference/ambientAccessors(target=es3).errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


!!! error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/conformance/classes/propertyMemberDeclarations/memberAccessorDeclarations/ambientAccessors.ts (0 errors) ====
// ok to use accessors in ambient class in ES3
declare class C {
static get a(): string;
static set a(value: string);

private static get b(): string;
private static set b(foo: string);

get x(): string;
set x(value: string);

private get y(): string;
private set y(foo: string);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
error TS5101: Flag 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


!!! error TS5101: Flag 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/compiler/Class.ts (0 errors) ====
import { Configurable } from "./Configurable"

export class HiddenClass {}

export class ActualClass extends Configurable(HiddenClass) {}
==== tests/cases/compiler/Configurable.ts (0 errors) ====
export type Constructor<T> = {
new(...args: any[]): T;
}
export function Configurable<T extends Constructor<{}>>(base: T): T {
return class extends base {

constructor(...args: any[]) {
super(...args);
}

};
}

1 change: 1 addition & 0 deletions tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7049,6 +7049,7 @@ declare namespace ts {
exactOptionalPropertyTypes?: boolean;
experimentalDecorators?: boolean;
forceConsistentCasingInFileNames?: boolean;
ignoreDeprecations?: string;
importHelpers?: boolean;
importsNotUsedAsValues?: ImportsNotUsedAsValues;
inlineSourceMap?: boolean;
Expand Down
1 change: 1 addition & 0 deletions tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3115,6 +3115,7 @@ declare namespace ts {
exactOptionalPropertyTypes?: boolean;
experimentalDecorators?: boolean;
forceConsistentCasingInFileNames?: boolean;
ignoreDeprecations?: string;
importHelpers?: boolean;
importsNotUsedAsValues?: ImportsNotUsedAsValues;
inlineSourceMap?: boolean;
Expand Down
2 changes: 2 additions & 0 deletions tests/baselines/reference/bigIntWithTargetES3.errors.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
tests/cases/compiler/bigIntWithTargetES3.ts(5,22): error TS2737: BigInt literals are not available when targeting lower than ES2020.
tests/cases/compiler/bigIntWithTargetES3.ts(5,29): error TS2737: BigInt literals are not available when targeting lower than ES2020.
tests/cases/compiler/bigIntWithTargetES3.ts(5,39): error TS2737: BigInt literals are not available when targeting lower than ES2020.
tests/cases/compiler/bigIntWithTargetES3.ts(5,48): error TS2737: BigInt literals are not available when targeting lower than ES2020.


!!! error TS5101: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.
==== tests/cases/compiler/bigIntWithTargetES3.ts (4 errors) ====
const normalNumber = 123; // should not error
let bigintType: bigint; // should not error
Expand Down
Loading