Skip to content

Commit aba9afa

Browse files
committed
Add new option resolveBareImports
1 parent aa249c0 commit aba9afa

File tree

49 files changed

+353
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+353
-0
lines changed

src/compiler/checker.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1502,6 +1502,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
15021502
var noImplicitThis = getStrictOptionValue(compilerOptions, "noImplicitThis");
15031503
var useUnknownInCatchVariables = getStrictOptionValue(compilerOptions, "useUnknownInCatchVariables");
15041504
var exactOptionalPropertyTypes = compilerOptions.exactOptionalPropertyTypes;
1505+
var resolveBareImports = compilerOptions.resolveBareImports;
15051506

15061507
var checkBinaryExpression = createCheckBinaryExpression();
15071508
var emitResolver = createResolver();
@@ -47126,6 +47127,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4712647127
}
4712747128
}
4712847129
}
47130+
else if (resolveBareImports && !importClause) {
47131+
void resolveExternalModuleName(node, node.moduleSpecifier);
47132+
}
4712947133
}
4713047134
checkImportAttributes(node);
4713147135
}

src/compiler/commandLineParser.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,14 @@ const commandOptionsWithoutBuild: CommandLineOption[] = [
11921192
category: Diagnostics.Modules,
11931193
description: Diagnostics.Conditions_to_set_in_addition_to_the_resolver_specific_defaults_when_resolving_imports,
11941194
},
1195+
{
1196+
name: "resolveBareImports",
1197+
type: "boolean",
1198+
affectsModuleResolution: true,
1199+
category: Diagnostics.Modules,
1200+
description: Diagnostics.Resolve_bare_imports,
1201+
defaultValueDescription: false,
1202+
},
11951203

11961204
// Source Maps
11971205
{

src/compiler/diagnosticMessages.json

+4
Original file line numberDiff line numberDiff line change
@@ -6384,6 +6384,10 @@
63846384
"category": "Message",
63856385
"code": 6805
63866386
},
6387+
"Resolve bare imports.": {
6388+
"category": "Message",
6389+
"code": 6806
6390+
},
63876391

63886392
"one of:": {
63896393
"category": "Message",

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -7349,6 +7349,7 @@ export interface CompilerOptions {
73497349
target?: ScriptTarget;
73507350
traceResolution?: boolean;
73517351
useUnknownInCatchVariables?: boolean;
7352+
resolveBareImports?: boolean;
73527353
resolveJsonModule?: boolean;
73537354
types?: string[];
73547355
/** Paths used to compute primary types search locations */

src/testRunner/compilerRunner.ts

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class CompilerTest {
150150
"noUncheckedIndexedAccess",
151151
"preserveConstEnums",
152152
"removeComments",
153+
"resolveBareImports",
153154
"resolveJsonModule",
154155
"resolvePackageJsonExports",
155156
"resolvePackageJsonImports",

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

+1
Original file line numberDiff line numberDiff line change
@@ -6953,6 +6953,7 @@ declare namespace ts {
69536953
target?: ScriptTarget;
69546954
traceResolution?: boolean;
69556955
useUnknownInCatchVariables?: boolean;
6956+
resolveBareImports?: boolean;
69566957
resolveJsonModule?: boolean;
69576958
types?: string[];
69586959
/** Paths used to compute primary types search locations */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */

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

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
4040
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
4141
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42+
// "resolveBareImports": true, /* Resolve bare imports. */
4243
// "resolveJsonModule": true, /* Enable importing .json files. */
4344
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
4445
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"compilerOptions": {
3+
"resolveBareImports": true
4+
}
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
//// [resolveBareImports.ts]
4+
import "does-not-exist";
5+
import "./does-not-exist-either";
6+
import "./does-not-exist-either.js";
7+
8+
9+
//// [resolveBareImports.js]
10+
"use strict";
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
require("does-not-exist");
13+
require("./does-not-exist-either");
14+
require("./does-not-exist-either.js");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
//// [resolveBareImports.ts]
4+
import "does-not-exist";
5+
import "./does-not-exist-either";
6+
import "./does-not-exist-either.js";
7+
8+
9+
//// [resolveBareImports.js]
10+
"use strict";
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
require("does-not-exist");
13+
require("./does-not-exist-either");
14+
require("./does-not-exist-either.js");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resolveBareImports.ts(1,8): error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
2+
resolveBareImports.ts(2,8): error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
3+
resolveBareImports.ts(3,8): error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.
4+
5+
6+
==== resolveBareImports.ts (3 errors) ====
7+
import "does-not-exist";
8+
~~~~~~~~~~~~~~~~
9+
!!! error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
10+
import "./does-not-exist-either";
11+
~~~~~~~~~~~~~~~~~~~~~~~~~
12+
!!! error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
13+
import "./does-not-exist-either.js";
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
!!! error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
//// [resolveBareImports.ts]
4+
import "does-not-exist";
5+
import "./does-not-exist-either";
6+
import "./does-not-exist-either.js";
7+
8+
9+
//// [resolveBareImports.js]
10+
"use strict";
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
require("does-not-exist");
13+
require("./does-not-exist-either");
14+
require("./does-not-exist-either.js");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
//// [resolveBareImports.ts]
4+
import "does-not-exist";
5+
import "./does-not-exist-either";
6+
import "./does-not-exist-either.js";
7+
8+
9+
//// [resolveBareImports.js]
10+
"use strict";
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
require("does-not-exist");
13+
require("./does-not-exist-either");
14+
require("./does-not-exist-either.js");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
//// [resolveBareImports.ts]
4+
import "does-not-exist";
5+
import "./does-not-exist-either";
6+
import "./does-not-exist-either.js";
7+
8+
9+
//// [resolveBareImports.js]
10+
"use strict";
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
require("does-not-exist");
13+
require("./does-not-exist-either");
14+
require("./does-not-exist-either.js");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
resolveBareImports.ts(1,8): error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
2+
resolveBareImports.ts(2,8): error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
3+
resolveBareImports.ts(3,8): error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.
4+
5+
6+
==== resolveBareImports.ts (3 errors) ====
7+
import "does-not-exist";
8+
~~~~~~~~~~~~~~~~
9+
!!! error TS2307: Cannot find module 'does-not-exist' or its corresponding type declarations.
10+
import "./does-not-exist-either";
11+
~~~~~~~~~~~~~~~~~~~~~~~~~
12+
!!! error TS2307: Cannot find module './does-not-exist-either' or its corresponding type declarations.
13+
import "./does-not-exist-either.js";
14+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
15+
!!! error TS2307: Cannot find module './does-not-exist-either.js' or its corresponding type declarations.
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
//// [resolveBareImports.ts]
4+
import "does-not-exist";
5+
import "./does-not-exist-either";
6+
import "./does-not-exist-either.js";
7+
8+
9+
//// [resolveBareImports.js]
10+
"use strict";
11+
Object.defineProperty(exports, "__esModule", { value: true });
12+
require("does-not-exist");
13+
require("./does-not-exist-either");
14+
require("./does-not-exist-either.js");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//// [tests/cases/compiler/resolveBareImports.ts] ////
2+
3+
=== resolveBareImports.ts ===
4+
5+
import "does-not-exist";
6+
import "./does-not-exist-either";
7+
import "./does-not-exist-either.js";
8+

0 commit comments

Comments
 (0)