Skip to content

Commit 8fb984c

Browse files
committed
Remove preserveValueImports
1 parent 6560f1e commit 8fb984c

File tree

33 files changed

+22
-125
lines changed

33 files changed

+22
-125
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45945,17 +45945,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4594545945
case SyntaxKind.ImportClause:
4594645946
case SyntaxKind.ImportSpecifier:
4594745947
case SyntaxKind.ImportEqualsDeclaration: {
45948-
if (compilerOptions.preserveValueImports || compilerOptions.verbatimModuleSyntax) {
45948+
if (compilerOptions.verbatimModuleSyntax) {
4594945949
Debug.assertIsDefined(node.name, "An ImportClause with a symbol should have a name");
4595045950
const message = compilerOptions.verbatimModuleSyntax && isInternalModuleImportEqualsDeclaration(node)
4595145951
? Diagnostics.An_import_alias_cannot_resolve_to_a_type_or_type_only_declaration_when_verbatimModuleSyntax_is_enabled
4595245952
: isType
45953-
? compilerOptions.verbatimModuleSyntax
45954-
? Diagnostics._0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled
45955-
: Diagnostics._0_is_a_type_and_must_be_imported_using_a_type_only_import_when_preserveValueImports_and_isolatedModules_are_both_enabled
45956-
: compilerOptions.verbatimModuleSyntax
45957-
? Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled
45958-
: Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_preserveValueImports_and_isolatedModules_are_both_enabled;
45953+
? Diagnostics._0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled
45954+
: Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled;
4595945955
const name = idText(node.kind === SyntaxKind.ImportSpecifier ? node.propertyName || node.name : node.name);
4596045956
addTypeOnlyDeclarationRelatedInfo(
4596145957
error(node, message, name),

src/compiler/commandLineParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
15191519
type: "boolean",
15201520
affectsEmit: true,
15211521
affectsBuildInfo: true,
1522-
category: Diagnostics.Emit,
1522+
category: Diagnostics.Backwards_Compatibility,
15231523
description: Diagnostics.Preserve_unused_imported_values_in_the_JavaScript_output_that_would_otherwise_be_removed,
15241524
defaultValueDescription: false,
15251525
},

src/compiler/diagnosticMessages.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,14 +1468,6 @@
14681468
"category": "Error",
14691469
"code": 1443
14701470
},
1471-
"'{0}' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.": {
1472-
"category": "Error",
1473-
"code": 1444
1474-
},
1475-
"'{0}' resolves to a type-only declaration and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.": {
1476-
"category": "Error",
1477-
"code": 1446
1478-
},
14791471
"'{0}' resolves to a type-only declaration and must be re-exported using a type-only re-export when '{1}' is enabled.": {
14801472
"category": "Error",
14811473
"code": 1448

src/compiler/program.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,18 +4413,11 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
44134413
}
44144414
}
44154415

4416-
if (options.preserveValueImports && getEmitModuleKind(options) < ModuleKind.ES2015) {
4417-
createDiagnosticForOptionName(Diagnostics.Option_0_can_only_be_used_when_module_is_set_to_preserve_or_to_es2015_or_later, "preserveValueImports");
4418-
}
4419-
44204416
const moduleKind = getEmitModuleKind(options);
44214417
if (options.verbatimModuleSyntax) {
44224418
if (moduleKind === ModuleKind.AMD || moduleKind === ModuleKind.UMD || moduleKind === ModuleKind.System) {
44234419
createDiagnosticForOptionName(Diagnostics.Option_verbatimModuleSyntax_cannot_be_used_when_module_is_set_to_UMD_AMD_or_System, "verbatimModuleSyntax");
44244420
}
4425-
if (options.preserveValueImports) {
4426-
createRedundantOptionDiagnostic("preserveValueImports", "verbatimModuleSyntax");
4427-
}
44284421
}
44294422

44304423
if (options.allowImportingTsExtensions && !(options.noEmit || options.emitDeclarationOnly)) {
@@ -4903,26 +4896,6 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
49034896
return needsCompilerDiagnostic;
49044897
}
49054898

4906-
/**
4907-
* Only creates a diagnostic on the option key specified by `errorOnOption`.
4908-
* If both options are specified in the program in separate config files via `extends`,
4909-
* a diagnostic is only created if `errorOnOption` is specified in the leaf config file.
4910-
* Useful if `redundantWithOption` represents a superset of the functionality of `errorOnOption`:
4911-
* if a user inherits `errorOnOption` from a base config file, it's still valid and useful to
4912-
* override it in the leaf config file.
4913-
*/
4914-
function createRedundantOptionDiagnostic(errorOnOption: string, redundantWithOption: string) {
4915-
const compilerOptionsObjectLiteralSyntax = getCompilerOptionsObjectLiteralSyntax();
4916-
if (compilerOptionsObjectLiteralSyntax) {
4917-
// This is a no-op if `errorOnOption` isn't present in the leaf config file.
4918-
createOptionDiagnosticInObjectLiteralSyntax(compilerOptionsObjectLiteralSyntax, /*onKey*/ true, errorOnOption, /*key2*/ undefined, Diagnostics.Option_0_is_redundant_and_cannot_be_specified_with_option_1, errorOnOption, redundantWithOption);
4919-
}
4920-
else {
4921-
// There was no config file, so both options were specified on the command line.
4922-
createDiagnosticForOptionName(Diagnostics.Option_0_is_redundant_and_cannot_be_specified_with_option_1, errorOnOption, redundantWithOption);
4923-
}
4924-
}
4925-
49264899
function blockEmittingOfFile(emitFileName: string, diag: Diagnostic) {
49274900
hasEmitBlockingDiagnostics.set(toPath(emitFileName), true);
49284901
programDiagnostics.add(diag);

src/compiler/transformers/ts.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2742,9 +2742,6 @@ export function transformTypeScript(context: TransformationContext) {
27422742
}
27432743

27442744
function shouldEmitAliasDeclaration(node: Node): boolean {
2745-
return compilerOptions.verbatimModuleSyntax || isInJSFile(node) ||
2746-
(compilerOptions.preserveValueImports
2747-
? resolver.isValueAliasDeclaration(node)
2748-
: resolver.isReferencedAliasDeclaration(node));
2745+
return compilerOptions.verbatimModuleSyntax || isInJSFile(node) || resolver.isReferencedAliasDeclaration(node);
27492746
}
27502747
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7238,6 +7238,7 @@ export interface CompilerOptions {
72387238
preserveConstEnums?: boolean;
72397239
noImplicitOverride?: boolean;
72407240
preserveSymlinks?: boolean;
7241+
/** @deprecated */
72417242
preserveValueImports?: boolean;
72427243
/** @internal */ preserveWatchOutput?: boolean;
72437244
project?: string;

src/compiler/utilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8885,7 +8885,7 @@ export function hasJsonModuleEmitEnabled(options: CompilerOptions) {
88858885

88868886
/** @internal */
88878887
export function importNameElisionDisabled(options: CompilerOptions) {
8888-
return options.verbatimModuleSyntax || options.isolatedModules && options.preserveValueImports;
8888+
return options.verbatimModuleSyntax;
88898889
}
88908890

88918891
/** @internal */

src/services/transpile.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export interface TranspileOutput {
4747

4848
const optionsRedundantWithVerbatimModuleSyntax = new Set([
4949
"isolatedModules",
50-
"preserveValueImports",
5150
]);
5251

5352
/*

tests/baselines/reference/api/typescript.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7602,6 +7602,7 @@ declare namespace ts {
76027602
preserveConstEnums?: boolean;
76037603
noImplicitOverride?: boolean;
76047604
preserveSymlinks?: boolean;
7605+
/** @deprecated */
76057606
preserveValueImports?: boolean;
76067607
project?: string;
76077608
reactNamespace?: string;

tests/baselines/reference/config/initTSConfig/Default initialized TSConfig/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --help/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with --watch/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with advanced options/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
"declarationDir": "lib", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with boolean value compiler options/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with enum value compiler options/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with files options/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option value/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with incorrect compiler option/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options with enum value/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/config/initTSConfig/Initialized TSConfig with list compiler options/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
7171
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
7272
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
73-
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
7473

7574
/* Interop Constraints */
7675
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */

tests/baselines/reference/preserveValueImports(isolatedmodules=false).js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export default {};
3131
export var b = 0;
3232
export var c = 1;
3333
//// [b.js]
34-
import a, { b, c } from "./a";
34+
export {};
3535
//// [c.js]
36-
import * as a from "./a";
36+
export {};
3737
//// [d.js]
3838
export {};
3939
//// [e.js]
4040
DD;
4141
export {};
4242
//// [f.js]
43-
import { b, c } from "./a";
43+
import { b } from "./a";
4444
b;

tests/baselines/reference/preserveValueImports(isolatedmodules=true).errors.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
error TS5102: Option 'preserveValueImports' has been removed. Please remove it from your configuration.
22
Use 'verbatimModuleSyntax' instead.
3-
b.ts(1,19): error TS1444: 'D' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
43
d.ts(1,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
54
e.ts(1,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
65
e.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScript modules. Consider using 'import * as ns from "mod"', 'import {a} from "mod"', 'import d from "mod"', or another module format instead.
@@ -14,10 +13,8 @@ e.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScr
1413
export const c = 1;
1514
export interface D {}
1615

17-
==== b.ts (1 errors) ====
16+
==== b.ts (0 errors) ====
1817
import a, { b, c, D } from "./a";
19-
~
20-
!!! error TS1444: 'D' is a type and must be imported using a type-only import when 'preserveValueImports' and 'isolatedModules' are both enabled.
2118

2219
==== c.ts (0 errors) ====
2320
import * as a from "./a";

tests/baselines/reference/preserveValueImports(isolatedmodules=true).js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ export default {};
3131
export var b = 0;
3232
export var c = 1;
3333
//// [b.js]
34-
import a, { b, c } from "./a";
34+
export {};
3535
//// [c.js]
36-
import * as a from "./a";
36+
export {};
3737
//// [d.js]
3838
export {};
3939
//// [e.js]
4040
DD;
4141
export {};
4242
//// [f.js]
43-
import { b, c } from "./a";
43+
import { b } from "./a";
4444
b;

0 commit comments

Comments
 (0)