Skip to content

Commit 93944bd

Browse files
committed
Merge branch 'main' of https://github.com/microsoft/TypeScript into feat/direct_imports
2 parents 1f237a6 + 20d4479 commit 93944bd

File tree

80 files changed

+719
-264
lines changed

Some content is hidden

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

80 files changed

+719
-264
lines changed

package-lock.json

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/checker.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4932,7 +4932,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
49324932
* @see https://github.com/microsoft/TypeScript/issues/42151
49334933
*/
49344934
if (emitModuleKindIsNonNodeESM(moduleKind) || mode === ModuleKind.ESNext) {
4935-
return importSourceWithoutExtension + (tsExtension === Extension.Mts ? ".mjs" : tsExtension === Extension.Cts ? ".cjs" : ".js");
4935+
const preferTs = isDeclarationFileName(moduleReference) && shouldAllowImportingTsExtension(compilerOptions);
4936+
const ext =
4937+
tsExtension === Extension.Mts || tsExtension === Extension.Dmts ? preferTs ? ".mts" : ".mjs" :
4938+
tsExtension === Extension.Cts || tsExtension === Extension.Dmts ? preferTs ? ".cts" : ".cjs" :
4939+
preferTs ? ".ts" : ".js";
4940+
return importSourceWithoutExtension + ext;
49364941
}
49374942
return importSourceWithoutExtension;
49384943
}
@@ -43876,9 +43881,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4387643881
// Import equals declaration is deprecated in es6 or above
4387743882
grammarErrorOnNode(node, Diagnostics.Import_assignment_cannot_be_used_when_targeting_ECMAScript_modules_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
4387843883
}
43879-
else if (!(node.flags & NodeFlags.Ambient) && getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Bundler) {
43880-
grammarErrorOnNode(node, Diagnostics.Import_assignment_is_not_allowed_when_moduleResolution_is_set_to_bundler_Consider_using_import_Asterisk_as_ns_from_mod_import_a_from_mod_import_d_from_mod_or_another_module_format_instead);
43881-
}
4388243884
}
4388343885
}
4388443886
}
@@ -44121,9 +44123,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4412144123
// system modules does not support export assignment
4412244124
grammarErrorOnNode(node, Diagnostics.Export_assignment_is_not_supported_when_module_flag_is_system);
4412344125
}
44124-
else if (getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Bundler && !(node.flags & NodeFlags.Ambient)) {
44125-
grammarErrorOnNode(node, Diagnostics.Export_assignment_cannot_be_used_when_moduleResolution_is_set_to_bundler_Consider_using_export_default_or_another_module_format_instead);
44126-
}
4412744126
}
4412844127
}
4412944128

src/compiler/diagnosticMessages.json

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,7 +4265,7 @@
42654265
"category": "Error",
42664266
"code": 5094
42674267
},
4268-
"Option 'preserveValueImports' can only be used when 'module' is set to 'es2015' or later.": {
4268+
"Option '{0}' can only be used when 'module' is set to 'es2015' or later.": {
42694269
"category": "Error",
42704270
"code": 5095
42714271
},
@@ -4281,14 +4281,6 @@
42814281
"category": "Error",
42824282
"code": 5098
42834283
},
4284-
"Import assignment is not allowed when 'moduleResolution' is set to 'bundler'. Consider using 'import * as ns from \"mod\"', 'import {a} from \"mod\"', 'import d from \"mod\"', or another module format instead.": {
4285-
"category": "Error",
4286-
"code": 5099
4287-
},
4288-
"Export assignment cannot be used when 'moduleResolution' is set to 'bundler'. Consider using 'export default' or another module format instead.": {
4289-
"category": "Error",
4290-
"code": 5100
4291-
},
42924284
"Flag '{0}' is deprecated and will stop functioning in TypeScript {1}. Specify compilerOption '\"ignoreDeprecations\": \"{2}\"' to silence this error.": {
42934285
"category": "Error",
42944286
"code": 5101

src/compiler/moduleNameResolver.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
toPath,
8282
} from "./path";
8383
import { perfLogger } from "./perfLogger";
84+
import { ResolutionNameAndModeGetter } from "./program";
8485
import {
8586
Version,
8687
VersionRange,
@@ -100,7 +101,6 @@ import {
100101
PackageId,
101102
Path,
102103
ResolutionMode,
103-
ResolutionNameAndModeGetter,
104104
ResolvedModuleWithFailedLookupLocations,
105105
ResolvedProjectReference,
106106
ResolvedTypeReferenceDirective,
@@ -118,6 +118,7 @@ import {
118118
getResolveJsonModule,
119119
hostGetCanonicalFileName,
120120
matchPatternOrExact,
121+
moduleResolutionSupportsPackageJsonExportsAndImports,
121122
packageIdToString,
122123
tryParsePatterns,
123124
} from "./utilities";
@@ -721,11 +722,14 @@ export function getConditions(options: CompilerOptions, esmMode?: boolean) {
721722
// conditions are only used by the node16/nodenext/bundler resolvers - there's no priority order in the list,
722723
// it's essentially a set (priority is determined by object insertion order in the object we look at).
723724
const conditions = esmMode || getEmitModuleResolutionKind(options) === ModuleResolutionKind.Bundler
724-
? ["node", "import"]
725-
: ["node", "require"];
725+
? ["import"]
726+
: ["require"];
726727
if (!options.noDtsResolution) {
727728
conditions.push("types");
728729
}
730+
if (getEmitModuleResolutionKind(options) !== ModuleResolutionKind.Bundler) {
731+
conditions.push("node");
732+
}
729733
return concatenate(conditions, options.customConditions);
730734
}
731735

@@ -1717,7 +1721,7 @@ function nodeModuleNameResolverWorker(features: NodeResolutionFeatures, moduleNa
17171721
candidateIsFromPackageJsonField: false,
17181722
};
17191723

1720-
if (traceEnabled && getEmitModuleResolutionKind(compilerOptions) >= ModuleResolutionKind.Node16 && getEmitModuleResolutionKind(compilerOptions) <= ModuleResolutionKind.NodeNext) {
1724+
if (traceEnabled && moduleResolutionSupportsPackageJsonExportsAndImports(getEmitModuleResolutionKind(compilerOptions))) {
17211725
trace(host, Diagnostics.Resolving_in_0_mode_with_conditions_1, features & NodeResolutionFeatures.EsmMode ? "ESM" : "CJS", conditions.map(c => `'${c}'`).join(", "));
17221726
}
17231727

0 commit comments

Comments
 (0)