mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Don’t assume importing some JSON means you want everything imported with .js extensions (#34961)
This commit is contained in:
@@ -30,7 +30,7 @@ namespace ts.moduleSpecifiers {
|
||||
function getPreferencesForUpdate(compilerOptions: CompilerOptions, oldImportSpecifier: string): Preferences {
|
||||
return {
|
||||
relativePreference: isExternalModuleNameRelative(oldImportSpecifier) ? RelativePreference.Relative : RelativePreference.NonRelative,
|
||||
ending: hasJSOrJsonFileExtension(oldImportSpecifier) ?
|
||||
ending: hasJSFileExtension(oldImportSpecifier) ?
|
||||
Ending.JsExtension :
|
||||
getEmitModuleResolutionKind(compilerOptions) !== ModuleResolutionKind.NodeJs || endsWith(oldImportSpecifier, "index") ? Ending.Index : Ending.Minimal,
|
||||
};
|
||||
@@ -163,7 +163,7 @@ namespace ts.moduleSpecifiers {
|
||||
}
|
||||
|
||||
function usesJsExtensionOnImports({ imports }: SourceFile): boolean {
|
||||
return firstDefined(imports, ({ text }) => pathIsRelative(text) ? hasJSOrJsonFileExtension(text) : undefined) || false;
|
||||
return firstDefined(imports, ({ text }) => pathIsRelative(text) ? hasJSFileExtension(text) : undefined) || false;
|
||||
}
|
||||
|
||||
function numberOfDirectorySeparators(str: string) {
|
||||
|
||||
@@ -8131,10 +8131,6 @@ namespace ts {
|
||||
return some(supportedJSExtensions, extension => fileExtensionIs(fileName, extension));
|
||||
}
|
||||
|
||||
export function hasJSOrJsonFileExtension(fileName: string): boolean {
|
||||
return supportedJSAndJsonExtensions.some(ext => fileExtensionIs(fileName, ext));
|
||||
}
|
||||
|
||||
export function hasTSFileExtension(fileName: string): boolean {
|
||||
return some(supportedTSExtensions, extension => fileExtensionIs(fileName, extension));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path="fourslash.ts" />
|
||||
|
||||
// @Filename: /a.ts
|
||||
////export const a = 'a';
|
||||
|
||||
// @Filename: /b.ts
|
||||
////import "./anything.json";
|
||||
////
|
||||
////a/**/
|
||||
|
||||
goTo.file("/b.ts");
|
||||
verify.importFixAtPosition([`import "./anything.json";
|
||||
import { a } from "./a";
|
||||
|
||||
a`]);
|
||||
Reference in New Issue
Block a user