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

Remove 5.5 deprecated compiler options #57527

Merged
merged 14 commits into from
Feb 28, 2024
Merged
  •  
  •  
  •  
115 changes: 24 additions & 91 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
affectsEmit: true,
affectsSemanticDiagnostics: true,
affectsBuildInfo: true,
category: Diagnostics.Emit,
category: Diagnostics.Backwards_Compatibility,
description: Diagnostics.Specify_emit_Slashchecking_behavior_for_imports_that_are_only_used_for_types,
defaultValueDescription: ImportsNotUsedAsValues.Remove,
},
Expand Down Expand Up @@ -1519,7 +1519,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
type: "boolean",
affectsEmit: true,
affectsBuildInfo: true,
category: Diagnostics.Emit,
category: Diagnostics.Backwards_Compatibility,
description: Diagnostics.Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed,
defaultValueDescription: false,
},
Expand Down
12 changes: 0 additions & 12 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1204,10 +1204,6 @@
"category": "Message",
"code": 1369
},
"This import is never used as a value and must use 'import type' because 'importsNotUsedAsValues' is set to 'error'.": {
"category": "Error",
"code": 1371
},
"'await' expressions are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.": {
"category": "Error",
"code": 1375
Expand Down Expand Up @@ -1472,14 +1468,6 @@
"category": "Error",
"code": 1443
},
"'{0}' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.": {
"category": "Error",
"code": 1444
},
"'{0}' resolves to a type-only declaration and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.": {
"category": "Error",
"code": 1446
},
"'{0}' resolves to a type-only declaration and must be re-exported using a type-only re-export when '{1}' is enabled.": {
"category": "Error",
"code": 1448
Expand Down
53 changes: 5 additions & 48 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,14 +396,13 @@ export function createCompilerHost(options: CompilerOptions, setParentNodes?: bo
/** @internal */
export function createGetSourceFile(
readFile: ProgramHost<any>["readFile"],
getCompilerOptions: () => CompilerOptions,
setParentNodes: boolean | undefined,
): CompilerHost["getSourceFile"] {
return (fileName, languageVersionOrOptions, onError) => {
let text: string | undefined;
try {
performance.mark("beforeIORead");
text = readFile(fileName, getCompilerOptions().charset);
text = readFile(fileName);
performance.mark("afterIORead");
performance.measure("I/O Read", "beforeIORead", "afterIORead");
}
Expand Down Expand Up @@ -476,7 +475,7 @@ export function createCompilerHostWorker(
const newLine = getNewLineCharacter(options);
const realpath = system.realpath && ((path: string) => system.realpath!(path));
const compilerHost: CompilerHost = {
getSourceFile: createGetSourceFile(fileName => compilerHost.readFile(fileName), () => options, setParentNodes),
getSourceFile: createGetSourceFile(fileName => compilerHost.readFile(fileName), setParentNodes),
getDefaultLibLocation,
getDefaultLibFileName: options => combinePaths(getDefaultLibLocation(), getDefaultLibFileName(options)),
writeFile: createWriteFileMeasuringIO(
Expand Down Expand Up @@ -4182,10 +4181,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}

if (options.isolatedModules || options.verbatimModuleSyntax) {
if (options.out) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", options.verbatimModuleSyntax ? "verbatimModuleSyntax" : "isolatedModules");
}

if (options.outFile) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "outFile", options.verbatimModuleSyntax ? "verbatimModuleSyntax" : "isolatedModules");
}
Expand Down Expand Up @@ -4281,10 +4276,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}

if (options.out && options.outFile) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "out", "outFile");
}

if (options.mapRoot && !(options.sourceMap || options.declarationMap)) {
// Error to specify --mapRoot without --sourcemap
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "mapRoot", "sourceMap", "declarationMap");
Expand All @@ -4295,7 +4286,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_without_specifying_option_1_or_option_2, "declarationDir", "declaration", "composite");
}
if (outputFile) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declarationDir", options.out ? "out" : "outFile");
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "declarationDir", "outFile");
}
}

Expand All @@ -4307,10 +4298,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "lib", "noLib");
}

if (options.noImplicitUseStrict && getStrictOptionValue(options, "alwaysStrict")) {
createDiagnosticForOptionName(Diagnostics.Option_0_cannot_be_specified_with_option_1, "noImplicitUseStrict", "alwaysStrict");
}

const languageVersion = getEmitScriptTarget(options);

const firstNonAmbientExternalModuleSourceFile = find(files, f => isExternalModule(f) && !f.isDeclarationFile);
Expand All @@ -4332,11 +4319,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
// Cannot specify module gen that isn't amd or system with --out
if (outputFile && !options.emitDeclarationOnly) {
if (options.module && !(options.module === ModuleKind.AMD || options.module === ModuleKind.System)) {
createDiagnosticForOptionName(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, options.out ? "out" : "outFile", "module");
createDiagnosticForOptionName(Diagnostics.Only_amd_and_system_modules_are_supported_alongside_0, "outFile", "module");
}
else if (options.module === undefined && firstNonAmbientExternalModuleSourceFile) {
const span = getErrorSpanForNode(firstNonAmbientExternalModuleSourceFile, typeof firstNonAmbientExternalModuleSourceFile.externalModuleIndicator === "boolean" ? firstNonAmbientExternalModuleSourceFile : firstNonAmbientExternalModuleSourceFile.externalModuleIndicator!);
programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, options.out ? "out" : "outFile"));
programDiagnostics.add(createFileDiagnostic(firstNonAmbientExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_using_option_0_unless_the_module_flag_is_amd_or_system, "outFile"));
}
}

Expand Down Expand Up @@ -4426,21 +4413,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
}
}

if (options.preserveValueImports && getEmitModuleKind(options) < ModuleKind.ES2015) {
createDiagnosticForOptionName(Diagnostics.Option_0_can_only_be_used_when_module_is_set_to_preserve_or_to_es2015_or_later, "preserveValueImports");
}

const moduleKind = getEmitModuleKind(options);
if (options.verbatimModuleSyntax) {
if (moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.UMD || moduleKind === ModuleKind.System) {
createDiagnosticForOptionName(Diagnostics.Option_verbatimModuleSyntax_cannot_be_used_when_module_is_set_to_UMD_AMD_or_System, "verbatimModuleSyntax");
}
if (options.preserveValueImports) {
createRedundantOptionDiagnostic("preserveValueImports", "verbatimModuleSyntax");
}
if (options.importsNotUsedAsValues) {
createRedundantOptionDiagnostic("importsNotUsedAsValues", "verbatimModuleSyntax");
}
}

if (options.allowImportingTsExtensions && !(options.noEmit || options.emitDeclarationOnly)) {
Expand Down Expand Up @@ -4919,26 +4896,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
return needsCompilerDiagnostic;
}

/**
* Only creates a diagnostic on the option key specified by `errorOnOption`.
* If both options are specified in the program in separate config files via `extends`,
* a diagnostic is only created if `errorOnOption` is specified in the leaf config file.
* Useful if `redundantWithOption` represents a superset of the functionality of `errorOnOption`:
* if a user inherits `errorOnOption` from a base config file, it's still valid and useful to
* override it in the leaf config file.
*/
function createRedundantOptionDiagnostic(errorOnOption: string, redundantWithOption: string) {
const compilerOptionsObjectLiteralSyntax = getCompilerOptionsObjectLiteralSyntax();
if (compilerOptionsObjectLiteralSyntax) {
// This is a no-op if `errorOnOption` isn't present in the leaf config file.
createOptionDiagnosticInObjectLiteralSyntax(compilerOptionsObjectLiteralSyntax, /*onKey*/ true, errorOnOption, /*key2*/ undefined, Diagnostics.Option_0_is_redundant_and_cannot_be_specified_with_option_1, errorOnOption, redundantWithOption);
}
else {
// There was no config file, so both options were specified on the command line.
createDiagnosticForOptionName(Diagnostics.Option_0_is_redundant_and_cannot_be_specified_with_option_1, errorOnOption, redundantWithOption);
}
}

function blockEmittingOfFile(emitFileName: string, diag: Diagnostic) {
hasEmitBlockingDiagnostics.set(toPath(emitFileName), true);
programDiagnostics.add(diag);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/transformers/module/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
startLexicalEnvironment();

const statements: Statement[] = [];
const ensureUseStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") || (!compilerOptions.noImplicitUseStrict && isExternalModule(currentSourceFile));
const ensureUseStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") || isExternalModule(currentSourceFile);
const statementOffset = factory.copyPrologue(node.statements, statements, ensureUseStrict && !isJsonSourceFile(node), topLevelVisitor);

if (shouldEmitUnderscoreUnderscoreESModule()) {
Expand Down Expand Up @@ -597,7 +597,7 @@ export function transformModule(context: TransformationContext): (x: SourceFile
startLexicalEnvironment();

const statements: Statement[] = [];
const statementOffset = factory.copyPrologue(node.statements, statements, /*ensureUseStrict*/ !compilerOptions.noImplicitUseStrict, topLevelVisitor);
const statementOffset = factory.copyPrologue(node.statements, statements, /*ensureUseStrict*/ true, topLevelVisitor);

if (shouldEmitUnderscoreUnderscoreESModule()) {
append(statements, createUnderscoreUnderscoreESModule());
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/transformers/module/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export function transformSystemModule(context: TransformationContext): (x: Sourc
startLexicalEnvironment();

// Add any prologue directives.
const ensureUseStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") || (!compilerOptions.noImplicitUseStrict && isExternalModule(currentSourceFile));
const ensureUseStrict = getStrictOptionValue(compilerOptions, "alwaysStrict") || isExternalModule(currentSourceFile);
const statementOffset = factory.copyPrologue(node.statements, statements, ensureUseStrict, topLevelVisitor);

// var __moduleName = context_1 && context_1.id;
Expand Down
36 changes: 4 additions & 32 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ import {
ImportClause,
ImportDeclaration,
ImportEqualsDeclaration,
ImportsNotUsedAsValues,
ImportSpecifier,
InitializedVariableDeclaration,
insertStatementsAfterStandardPrologue,
Expand Down Expand Up @@ -2276,9 +2275,7 @@ export function transformTypeScript(context: TransformationContext) {

// Elide the declaration if the import clause was elided.
const importClause = visitNode(node.importClause, visitImportClause, isImportClause);
return importClause ||
compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Preserve ||
compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Error
return importClause
? factory.updateImportDeclaration(
node,
/*modifiers*/ undefined,
Expand Down Expand Up @@ -2314,10 +2311,7 @@ export function transformTypeScript(context: TransformationContext) {
}
else {
// Elide named imports if all of its import specifiers are elided and settings allow.
const allowEmpty = compilerOptions.verbatimModuleSyntax || compilerOptions.preserveValueImports && (
compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Preserve ||
compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Error
);
const allowEmpty = compilerOptions.verbatimModuleSyntax;
const elements = visitNodes(node.elements, visitImportSpecifier, isImportSpecifier);
return allowEmpty || some(elements) ? factory.updateNamedImports(node, elements) : undefined;
}
Expand Down Expand Up @@ -2363,10 +2357,7 @@ export function transformTypeScript(context: TransformationContext) {
}

// Elide the export declaration if all of its named exports are elided.
const allowEmpty = compilerOptions.verbatimModuleSyntax || !!node.moduleSpecifier && (
compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Preserve ||
compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Error
);
const allowEmpty = !!compilerOptions.verbatimModuleSyntax;
const exportClause = visitNode(
node.exportClause,
(bindings: NamedExportBindings) => visitNamedExportBindings(bindings, allowEmpty),
Expand Down Expand Up @@ -2442,22 +2433,6 @@ export function transformTypeScript(context: TransformationContext) {

if (isExternalModuleImportEqualsDeclaration(node)) {
const isReferenced = shouldEmitAliasDeclaration(node);
// If the alias is unreferenced but we want to keep the import, replace with 'import "mod"'.
if (!isReferenced && compilerOptions.importsNotUsedAsValues === ImportsNotUsedAsValues.Preserve) {
return setOriginalNode(
setTextRange(
factory.createImportDeclaration(
/*modifiers*/ undefined,
/*importClause*/ undefined,
node.moduleReference.expression,
/*attributes*/ undefined,
),
node,
),
node,
);
}

return isReferenced ? visitEachChild(node, visitor, context) : undefined;
}

Expand Down Expand Up @@ -2767,9 +2742,6 @@ export function transformTypeScript(context: TransformationContext) {
}

function shouldEmitAliasDeclaration(node: Node): boolean {
return compilerOptions.verbatimModuleSyntax || isInJSFile(node) ||
(compilerOptions.preserveValueImports
? resolver.isValueAliasDeclaration(node)
: resolver.isReferencedAliasDeclaration(node));
return compilerOptions.verbatimModuleSyntax || isInJSFile(node) || resolver.isReferencedAliasDeclaration(node);
}
}
10 changes: 10 additions & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7147,6 +7147,7 @@ export interface CompilerOptions {
* @internal
*/
build?: boolean;
/** @deprecated */
charset?: string;
checkJs?: boolean;
/** @internal */ configFilePath?: string;
Expand Down Expand Up @@ -7178,12 +7179,14 @@ export interface CompilerOptions {
/** @internal */ help?: boolean;
ignoreDeprecations?: string;
importHelpers?: boolean;
/** @deprecated */
importsNotUsedAsValues?: ImportsNotUsedAsValues;
/** @internal */ init?: boolean;
inlineSourceMap?: boolean;
inlineSources?: boolean;
isolatedModules?: boolean;
jsx?: JsxEmit;
/** @deprecated */
keyofStringsOnly?: boolean;
lib?: string[];
/** @internal */ listEmittedFiles?: boolean;
Expand All @@ -7207,9 +7210,11 @@ export interface CompilerOptions {
noImplicitAny?: boolean; // Always combine with strict property
noImplicitReturns?: boolean;
noImplicitThis?: boolean; // Always combine with strict property
/** @deprecated */
noStrictGenericChecks?: boolean;
noUnusedLocals?: boolean;
noUnusedParameters?: boolean;
/** @deprecated */
noImplicitUseStrict?: boolean;
noPropertyAccessFromIndexSignature?: boolean;
assumeChangesOnlyAffectDirectDependencies?: boolean;
Expand All @@ -7218,6 +7223,7 @@ export interface CompilerOptions {
/** @internal */
noDtsResolution?: boolean;
noUncheckedIndexedAccess?: boolean;
/** @deprecated */
out?: string;
outDir?: string;
outFile?: string;
Expand All @@ -7232,6 +7238,7 @@ export interface CompilerOptions {
preserveConstEnums?: boolean;
noImplicitOverride?: boolean;
preserveSymlinks?: boolean;
/** @deprecated */
preserveValueImports?: boolean;
/** @internal */ preserveWatchOutput?: boolean;
project?: string;
Expand All @@ -7258,7 +7265,9 @@ export interface CompilerOptions {
strictNullChecks?: boolean; // Always combine with strict property
strictPropertyInitialization?: boolean; // Always combine with strict property
stripInternal?: boolean;
/** @deprecated */
suppressExcessPropertyErrors?: boolean;
/** @deprecated */
suppressImplicitAnyIndexErrors?: boolean;
/** @internal */ suppressOutputPathCheck?: boolean;
target?: ScriptTarget;
Expand Down Expand Up @@ -7329,6 +7338,7 @@ export const enum JsxEmit {
ReactJSXDev = 5,
}

/** @deprecated */
export const enum ImportsNotUsedAsValues {
Remove,
Preserve,
Expand Down