Skip to content

Commit

Permalink
Remove preserveValueImports
Browse files Browse the repository at this point in the history
  • Loading branch information
jakebailey committed Feb 25, 2024
1 parent 6560f1e commit 8fb984c
Show file tree
Hide file tree
Showing 33 changed files with 22 additions and 125 deletions.
10 changes: 3 additions & 7 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45945,17 +45945,13 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
case SyntaxKind.ImportClause:
case SyntaxKind.ImportSpecifier:
case SyntaxKind.ImportEqualsDeclaration: {
if (compilerOptions.preserveValueImports || compilerOptions.verbatimModuleSyntax) {
if (compilerOptions.verbatimModuleSyntax) {
Debug.assertIsDefined(node.name, "An ImportClause with a symbol should have a name");
const message = compilerOptions.verbatimModuleSyntax && isInternalModuleImportEqualsDeclaration(node)
? Diagnostics.An_import_alias_cannot_resolve_to_a_type_or_type_only_declaration_when_verbatimModuleSyntax_is_enabled
: isType
? compilerOptions.verbatimModuleSyntax
? Diagnostics._0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled
: Diagnostics._0_is_a_type_and_must_be_imported_using_a_type_only_import_when_preserveValueImports_and_isolatedModules_are_both_enabled
: compilerOptions.verbatimModuleSyntax
? Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled
: Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_preserveValueImports_and_isolatedModules_are_both_enabled;
? Diagnostics._0_is_a_type_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled
: Diagnostics._0_resolves_to_a_type_only_declaration_and_must_be_imported_using_a_type_only_import_when_verbatimModuleSyntax_is_enabled;
const name = idText(node.kind === SyntaxKind.ImportSpecifier ? node.propertyName || node.name : node.name);
addTypeOnlyDeclarationRelatedInfo(
error(node, message, name),
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
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
8 changes: 0 additions & 8 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1468,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
27 changes: 0 additions & 27 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4413,18 +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.allowImportingTsExtensions && !(options.noEmit || options.emitDeclarationOnly)) {
Expand Down Expand Up @@ -4903,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
5 changes: 1 addition & 4 deletions src/compiler/transformers/ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2742,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);
}
}
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7238,6 +7238,7 @@ export interface CompilerOptions {
preserveConstEnums?: boolean;
noImplicitOverride?: boolean;
preserveSymlinks?: boolean;
/** @deprecated */
preserveValueImports?: boolean;
/** @internal */ preserveWatchOutput?: boolean;
project?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8885,7 +8885,7 @@ export function hasJsonModuleEmitEnabled(options: CompilerOptions) {

/** @internal */
export function importNameElisionDisabled(options: CompilerOptions) {
return options.verbatimModuleSyntax || options.isolatedModules && options.preserveValueImports;
return options.verbatimModuleSyntax;
}

/** @internal */
Expand Down
1 change: 0 additions & 1 deletion src/services/transpile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export interface TranspileOutput {

const optionsRedundantWithVerbatimModuleSyntax = new Set([
"isolatedModules",
"preserveValueImports",
]);

/*
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 @@ -7602,6 +7602,7 @@ declare namespace ts {
preserveConstEnums?: boolean;
noImplicitOverride?: boolean;
preserveSymlinks?: boolean;
/** @deprecated */
preserveValueImports?: boolean;
project?: string;
reactNamespace?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
"declarationDir": "lib", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */

/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export default {};
export var b = 0;
export var c = 1;
//// [b.js]
import a, { b, c } from "./a";
export {};
//// [c.js]
import * as a from "./a";
export {};
//// [d.js]
export {};
//// [e.js]
DD;
export {};
//// [f.js]
import { b, c } from "./a";
import { b } from "./a";
b;
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
error TS5102: Option 'preserveValueImports' has been removed. Please remove it from your configuration.
Use 'verbatimModuleSyntax' instead.
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.
d.ts(1,1): error TS1203: Export assignment cannot be used when targeting ECMAScript modules. Consider using 'export default' or another module format instead.
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.
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.
Expand All @@ -14,10 +13,8 @@ e.ts(2,1): error TS1202: Import assignment cannot be used when targeting ECMAScr
export const c = 1;
export interface D {}

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

==== c.ts (0 errors) ====
import * as a from "./a";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ export default {};
export var b = 0;
export var c = 1;
//// [b.js]
import a, { b, c } from "./a";
export {};
//// [c.js]
import * as a from "./a";
export {};
//// [d.js]
export {};
//// [e.js]
DD;
export {};
//// [f.js]
import { b, c } from "./a";
import { b } from "./a";
b;

0 comments on commit 8fb984c

Please sign in to comment.