Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
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 @@ -1470,7 +1470,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 @@ -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.": {
"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
54 changes: 52 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 @@ -304,6 +305,7 @@ import {
UnparsedSource,
VariableDeclaration,
VariableStatement,
versionMajorMinor,
walkUpParenthesizedExpressions,
WriteFileCallback,
WriteFileCallbackData,
Expand Down Expand Up @@ -1423,8 +1425,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 {
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 @@ -3993,6 +3995,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 @@ -4255,6 +4258,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
10 changes: 10 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6717,6 +6717,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 @@ -9470,3 +9471,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 */
}
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
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 TS5096: 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 TS5096: 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 TS5096: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


!!! error TS5096: 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 TS5096: 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 TS5096: 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 TS5096: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


!!! error TS5096: 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 TS5096: 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 TS5096: 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 TS5096: 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 TS5096: 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 TS5096: 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 TS5096: 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 TS5096: Flag 'ES3' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


!!! error TS5096: 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 TS5096: Flag 'out' is deprecated and will stop functioning in TypeScript 5.5. Specify 'ignoreDeprecations: "5.0"' to silence this error.


!!! error TS5096: 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);
}

};
}

3 changes: 2 additions & 1 deletion tests/baselines/reference/api/tsserverlibrary.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7040,6 +7040,7 @@ declare namespace ts {
exactOptionalPropertyTypes?: boolean;
experimentalDecorators?: boolean;
forceConsistentCasingInFileNames?: boolean;
ignoreDeprecations?: string;
importHelpers?: boolean;
importsNotUsedAsValues?: ImportsNotUsedAsValues;
inlineSourceMap?: boolean;
Expand Down Expand Up @@ -9408,7 +9409,7 @@ declare namespace ts {
* @param configFileParsingDiagnostics - error during config file parsing
* @returns A 'Program' object.
*/
function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program;
function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[], typeScriptVersion?: string): Program;
/**
* Returns the target config filename of a project reference.
* Note: The file might not exist.
Expand Down
3 changes: 2 additions & 1 deletion tests/baselines/reference/api/typescript.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3106,6 +3106,7 @@ declare namespace ts {
exactOptionalPropertyTypes?: boolean;
experimentalDecorators?: boolean;
forceConsistentCasingInFileNames?: boolean;
ignoreDeprecations?: string;
importHelpers?: boolean;
importsNotUsedAsValues?: ImportsNotUsedAsValues;
inlineSourceMap?: boolean;
Expand Down Expand Up @@ -5474,7 +5475,7 @@ declare namespace ts {
* @param configFileParsingDiagnostics - error during config file parsing
* @returns A 'Program' object.
*/
function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[]): Program;
function createProgram(rootNames: readonly string[], options: CompilerOptions, host?: CompilerHost, oldProgram?: Program, configFileParsingDiagnostics?: readonly Diagnostic[], typeScriptVersion?: string): Program;
/**
* Returns the target config filename of a project reference.
* Note: The file might not exist.
Expand Down
Loading