Skip to content

Commit

Permalink
Cherry-pick PR microsoft#49035 into release-4.7
Browse files Browse the repository at this point in the history
Component commits:
e8df495 Fix module specifier generation crash from typesVersions
  • Loading branch information
andrewbranch authored and typescript-bot committed May 9, 2022
1 parent a5ec725 commit d074a79
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/compiler/moduleSpecifiers.ts
Expand Up @@ -810,6 +810,7 @@ namespace ts.moduleSpecifiers {
function removeExtensionAndIndexPostFix(fileName: string, ending: Ending, options: CompilerOptions, host?: ModuleSpecifierResolutionHost): string {
if (fileExtensionIsOneOf(fileName, [Extension.Json, Extension.Mjs, Extension.Cjs])) return fileName;
const noExtension = removeFileExtension(fileName);
if (fileName === noExtension) return fileName;
if (fileExtensionIsOneOf(fileName, [Extension.Dmts, Extension.Mts, Extension.Dcts, Extension.Cts])) return noExtension + getJSExtensionForFile(fileName, options);
switch (ending) {
case Ending.Minimal:
Expand Down
34 changes: 34 additions & 0 deletions tests/cases/fourslash/importNameCodeFix_typesVersions.ts
@@ -0,0 +1,34 @@
/// <reference path="fourslash.ts" />

// @module: commonjs
// @checkJs: true

// @Filename: /node_modules/unified/package.json
//// {
//// "name": "unified",
//// "types": "types/ts3.4/index.d.ts",
//// "typesVersions": {
//// ">=4.0": {
//// "types/ts3.4/*": [
//// "types/ts4.0/*"
//// ]
//// }
//// }
//// }

// @Filename: /node_modules/unified/types/ts3.4/index.d.ts
//// export declare const x: number;

// @Filename: /node_modules/unified/types/ts4.0/index.d.ts
//// export declare const x: number;

// @Filename: /foo.js
//// import {} from "unified";

// @Filename: /index.js
//// x/**/

verify.importFixModuleSpecifiers("", [
"unified",
"unified/types/ts3.4/", // TODO: this is wrong #49034
], { importModuleSpecifierEnding: "js" });

0 comments on commit d074a79

Please sign in to comment.