Skip to content

Commit dbee2ab

Browse files
TypeScript Botandrewbranch
TypeScript Bot
andauthored
Cherry-pick PR #49035 into release-4.7 (#49036)
Component commits: e8df495 Fix module specifier generation crash from typesVersions Co-authored-by: Andrew Branch <[email protected]>
1 parent a5ec725 commit dbee2ab

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/compiler/moduleSpecifiers.ts

+1
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ namespace ts.moduleSpecifiers {
810810
function removeExtensionAndIndexPostFix(fileName: string, ending: Ending, options: CompilerOptions, host?: ModuleSpecifierResolutionHost): string {
811811
if (fileExtensionIsOneOf(fileName, [Extension.Json, Extension.Mjs, Extension.Cjs])) return fileName;
812812
const noExtension = removeFileExtension(fileName);
813+
if (fileName === noExtension) return fileName;
813814
if (fileExtensionIsOneOf(fileName, [Extension.Dmts, Extension.Mts, Extension.Dcts, Extension.Cts])) return noExtension + getJSExtensionForFile(fileName, options);
814815
switch (ending) {
815816
case Ending.Minimal:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @module: commonjs
4+
// @checkJs: true
5+
6+
// @Filename: /node_modules/unified/package.json
7+
//// {
8+
//// "name": "unified",
9+
//// "types": "types/ts3.4/index.d.ts",
10+
//// "typesVersions": {
11+
//// ">=4.0": {
12+
//// "types/ts3.4/*": [
13+
//// "types/ts4.0/*"
14+
//// ]
15+
//// }
16+
//// }
17+
//// }
18+
19+
// @Filename: /node_modules/unified/types/ts3.4/index.d.ts
20+
//// export declare const x: number;
21+
22+
// @Filename: /node_modules/unified/types/ts4.0/index.d.ts
23+
//// export declare const x: number;
24+
25+
// @Filename: /foo.js
26+
//// import {} from "unified";
27+
28+
// @Filename: /index.js
29+
//// x/**/
30+
31+
verify.importFixModuleSpecifiers("", [
32+
"unified",
33+
"unified/types/ts3.4/", // TODO: this is wrong #49034
34+
], { importModuleSpecifierEnding: "js" });

0 commit comments

Comments
 (0)