mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-10 21:07:52 -05:00
Fix module specifier generation crash from typesVersions (#49035)
This commit is contained in:
@@ -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:
|
||||
|
||||
34
tests/cases/fourslash/importNameCodeFix_typesVersions.ts
Normal file
34
tests/cases/fourslash/importNameCodeFix_typesVersions.ts
Normal file
@@ -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" });
|
||||
Reference in New Issue
Block a user