mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-15 22:15:05 -05:00
Fix accidental relative imports from non namespace barrels (#59544)
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
import {
|
||||
createCodeFixAction,
|
||||
createCombinedCodeActions,
|
||||
createImportAdder,
|
||||
eachDiagnostic,
|
||||
registerCodeFix,
|
||||
typePredicateToAutoImportableTypeNode,
|
||||
typeToAutoImportableTypeNode,
|
||||
} from "../_namespaces/ts.codefix.js";
|
||||
import {
|
||||
ArrayBindingPattern,
|
||||
ArrayLiteralExpression,
|
||||
@@ -97,17 +106,7 @@ import {
|
||||
VariableStatement,
|
||||
walkUpParenthesizedExpressions,
|
||||
} from "../_namespaces/ts.js";
|
||||
|
||||
import {
|
||||
createCodeFixAction,
|
||||
createCombinedCodeActions,
|
||||
createImportAdder,
|
||||
eachDiagnostic,
|
||||
registerCodeFix,
|
||||
typePredicateToAutoImportableTypeNode,
|
||||
typeToAutoImportableTypeNode,
|
||||
} from "../_namespaces/ts.codefix.js";
|
||||
import { getIdentifierForNode } from "../refactors/helpers.js";
|
||||
import { getIdentifierForNode } from "../_namespaces/ts.refactor.js";
|
||||
|
||||
const fixId = "fixMissingTypeAnnotationOnExports";
|
||||
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
import { findIndex } from "../compiler/core.js";
|
||||
import {
|
||||
CancellationToken,
|
||||
Program,
|
||||
SourceFile,
|
||||
Statement,
|
||||
SymbolFlags,
|
||||
TextRange,
|
||||
UserPreferences,
|
||||
} from "../compiler/types.js";
|
||||
import {
|
||||
codefix,
|
||||
Debug,
|
||||
fileShouldUseJavaScriptRequire,
|
||||
findIndex,
|
||||
forEachChild,
|
||||
formatting,
|
||||
getQuotePreference,
|
||||
isIdentifier,
|
||||
Program,
|
||||
SourceFile,
|
||||
Statement,
|
||||
SymbolFlags,
|
||||
textChanges,
|
||||
TextRange,
|
||||
UserPreferences,
|
||||
} from "./_namespaces/ts.js";
|
||||
import { addTargetFileImports } from "./refactors/helpers.js";
|
||||
import {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getModuleSpecifier } from "../../compiler/_namespaces/ts.moduleSpecifiers.js";
|
||||
import {
|
||||
ApplicableRefactorInfo,
|
||||
arrayFrom,
|
||||
@@ -118,6 +117,7 @@ import {
|
||||
ModifierLike,
|
||||
ModuleDeclaration,
|
||||
ModuleKind,
|
||||
moduleSpecifiers,
|
||||
moduleSpecifierToValidIdentifier,
|
||||
NamedImportBindings,
|
||||
Node,
|
||||
@@ -157,8 +157,10 @@ import {
|
||||
VariableDeclarationList,
|
||||
VariableStatement,
|
||||
} from "../_namespaces/ts.js";
|
||||
import { addTargetFileImports } from "../_namespaces/ts.refactor.js";
|
||||
import { registerRefactor } from "../refactorProvider.js";
|
||||
import {
|
||||
addTargetFileImports,
|
||||
registerRefactor,
|
||||
} from "../_namespaces/ts.refactor.js";
|
||||
|
||||
const refactorNameForMoveToFile = "Move to file";
|
||||
const description = getLocaleSpecificMessage(Diagnostics.Move_to_file);
|
||||
@@ -358,7 +360,7 @@ function updateImportsInOtherFiles(
|
||||
|
||||
if (getStringComparer(!program.useCaseSensitiveFileNames())(pathToTargetFileWithExtension, sourceFile.fileName) === Comparison.EqualTo) return;
|
||||
|
||||
const newModuleSpecifier = getModuleSpecifier(program.getCompilerOptions(), sourceFile, sourceFile.fileName, pathToTargetFileWithExtension, createModuleSpecifierResolutionHost(program, host));
|
||||
const newModuleSpecifier = moduleSpecifiers.getModuleSpecifier(program.getCompilerOptions(), sourceFile, sourceFile.fileName, pathToTargetFileWithExtension, createModuleSpecifierResolutionHost(program, host));
|
||||
const newImportDeclaration = filterImport(importNode, makeStringLiteral(newModuleSpecifier, quotePreference), shouldMove);
|
||||
if (newImportDeclaration) changes.insertNodeAfter(sourceFile, statement, newImportDeclaration);
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { getModuleSpecifierPreferences } from "../compiler/moduleSpecifiers.js";
|
||||
import {
|
||||
CompletionKind,
|
||||
createCompletionDetails,
|
||||
@@ -823,7 +822,7 @@ function getFilenameWithExtensionOption(name: string, program: Program, extensio
|
||||
return { name, extension: tryGetExtensionFromPath(name) };
|
||||
}
|
||||
|
||||
let allowedEndings = getModuleSpecifierPreferences(
|
||||
let allowedEndings = moduleSpecifiers.getModuleSpecifierPreferences(
|
||||
{ importModuleSpecifierEnding: extensionOptions.endingPreference },
|
||||
program,
|
||||
program.getCompilerOptions(),
|
||||
|
||||
Reference in New Issue
Block a user