mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Improve the performance of isolatedDeclarations quickfix (#58722)
This commit is contained in:
parent
f5b2d9b10e
commit
fc42002a10
@ -1763,6 +1763,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
getImmediateAliasedSymbol,
|
||||
getAliasedSymbol: resolveAlias,
|
||||
getEmitResolver,
|
||||
requiresAddingImplicitUndefined,
|
||||
getExportsOfModule: getExportsOfModuleAsArray,
|
||||
getExportsAndPropertiesOfModule,
|
||||
forEachExportAndPropertyOfModule,
|
||||
|
||||
@ -5265,6 +5265,7 @@ export interface TypeChecker {
|
||||
/** @internal */ getDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
|
||||
/** @internal */ getGlobalDiagnostics(): Diagnostic[];
|
||||
/** @internal */ getEmitResolver(sourceFile?: SourceFile, cancellationToken?: CancellationToken, forceDts?: boolean): EmitResolver;
|
||||
/** @internal */ requiresAddingImplicitUndefined(parameter: ParameterDeclaration | JSDocParameterTag): boolean;
|
||||
|
||||
/** @internal */ getNodeCount(): number;
|
||||
/** @internal */ getIdentifierCount(): number;
|
||||
|
||||
@ -183,7 +183,7 @@ registerCodeFix({
|
||||
|
||||
addCodeAction(addInlineTypeAssertion, fixes, context, TypePrintMode.Full, f => f.addInlineAssertion(context.span));
|
||||
addCodeAction(addInlineTypeAssertion, fixes, context, TypePrintMode.Relative, f => f.addInlineAssertion(context.span));
|
||||
addCodeAction(addAnnotationFix, fixes, context, TypePrintMode.Widened, f => f.addInlineAssertion(context.span));
|
||||
addCodeAction(addInlineTypeAssertion, fixes, context, TypePrintMode.Widened, f => f.addInlineAssertion(context.span));
|
||||
|
||||
addCodeAction(extractExpression, fixes, context, TypePrintMode.Full, f => f.extractAsVariable(context.span));
|
||||
|
||||
@ -237,7 +237,6 @@ function withContext<T>(
|
||||
const sourceFile: SourceFile = context.sourceFile;
|
||||
const program = context.program;
|
||||
const typeChecker: TypeChecker = program.getTypeChecker();
|
||||
const emitResolver = typeChecker.getEmitResolver();
|
||||
const scriptTarget = getEmitScriptTarget(program.getCompilerOptions());
|
||||
const importAdder = createImportAdder(context.sourceFile, context.program, context.preferences, context.host);
|
||||
const fixedNodes = new Set<Node>();
|
||||
@ -887,7 +886,7 @@ function withContext<T>(
|
||||
type = widenedType;
|
||||
}
|
||||
|
||||
if (isParameter(node) && emitResolver.requiresAddingImplicitUndefined(node)) {
|
||||
if (isParameter(node) && typeChecker.requiresAddingImplicitUndefined(node)) {
|
||||
type = typeChecker.getUnionType([typeChecker.getUndefinedType(), type], UnionReduction.None);
|
||||
}
|
||||
const flags = (
|
||||
@ -1108,26 +1107,26 @@ function withContext<T>(
|
||||
setEmitFlags(node, EmitFlags.None);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Some --isolatedDeclarations errors are not present on the node that directly needs type annotation, so look in the
|
||||
// ancestors to look for node that needs type annotation. This function can return undefined if the AST is ill-formed.
|
||||
function findAncestorWithMissingType(node: Node): Node | undefined {
|
||||
return findAncestor(node, n => {
|
||||
return canHaveTypeAnnotation.has(n.kind) &&
|
||||
((!isObjectBindingPattern(n) && !isArrayBindingPattern(n)) || isVariableDeclaration(n.parent));
|
||||
});
|
||||
}
|
||||
// Some --isolatedDeclarations errors are not present on the node that directly needs type annotation, so look in the
|
||||
// ancestors to look for node that needs type annotation. This function can return undefined if the AST is ill-formed.
|
||||
function findAncestorWithMissingType(node: Node): Node | undefined {
|
||||
return findAncestor(node, n => {
|
||||
return canHaveTypeAnnotation.has(n.kind) &&
|
||||
((!isObjectBindingPattern(n) && !isArrayBindingPattern(n)) || isVariableDeclaration(n.parent));
|
||||
});
|
||||
}
|
||||
|
||||
function findBestFittingNode(node: Node, span: TextSpan) {
|
||||
while (node && node.end < span.start + span.length) {
|
||||
node = node.parent;
|
||||
function findBestFittingNode(node: Node, span: TextSpan) {
|
||||
while (node && node.end < span.start + span.length) {
|
||||
node = node.parent;
|
||||
}
|
||||
while (node.parent.pos === node.pos && node.parent.end === node.end) {
|
||||
node = node.parent;
|
||||
}
|
||||
if (isIdentifier(node) && hasInitializer(node.parent) && node.parent.initializer) {
|
||||
return node.parent.initializer;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
while (node.parent.pos === node.pos && node.parent.end === node.end) {
|
||||
node = node.parent;
|
||||
}
|
||||
if (isIdentifier(node) && hasInitializer(node.parent) && node.parent.initializer) {
|
||||
return node.parent.initializer;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user