Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
A few code simplificiations / corrections.
These are not related to the perf issue, but I noticed them while editing this file
  • Loading branch information
blickly committed May 30, 2024
commit 3acfe50e88769102d9c7e442df57b38cb1e79694
40 changes: 20 additions & 20 deletions src/services/codefixes/fixMissingTypeAnnotationOnExports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -1107,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));
});
}

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;
// 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));
});
}
if (isIdentifier(node) && hasInitializer(node.parent) && node.parent.initializer) {
return node.parent.initializer;

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;
}
return node;
}