Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃 Pick PR #49035 (Fix module specifier generation cra...) into release-4.7 #49036

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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" });