Skip to content

Commit 0191a46

Browse files
committed
(Non-functional) Apply 'npm run format' on fixMissingTypeAnnotationOnExports.ts
1 parent 4e506f9 commit 0191a46

File tree

1 file changed

+54
-54
lines changed

1 file changed

+54
-54
lines changed

src/services/codefixes/fixMissingTypeAnnotationOnExports.ts

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ function addCodeAction(
204204
fixes: CodeFixAction[],
205205
context: CodeFixContext | CodeFixAllContext,
206206
typePrintMode: TypePrintMode,
207-
cb: (fixer: Fixer) => DiagnosticOrDiagnosticAndArguments | undefined) {
207+
cb: (fixer: Fixer) => DiagnosticOrDiagnosticAndArguments | undefined,
208+
) {
208209
const changes = withContext(context, typePrintMode, cb);
209210
if (changes.result && changes.textChanges.length) {
210211
fixes.push(createCodeFixAction(
@@ -236,7 +237,7 @@ function withContext<T>(
236237
const fixedNodes = new Set<Node>();
237238
const expandoPropertiesAdded = new Set<Node>();
238239
const typePrinter = createPrinter({
239-
preserveSourceNewlines: false,
240+
preserveSourceNewlines: false,
240241
});
241242

242243
const result = cb({ addTypeAnnotation, addInlineAssertion, extractAsVariable });
@@ -318,10 +319,10 @@ function withContext<T>(
318319
}
319320

320321
function createSatisfiesAsExpression(node: Expression, type: TypeNode) {
321-
if (needsParenthesizedExpressionForAssertion(node)) {
322-
node = factory.createParenthesizedExpression(node);
323-
}
324-
return factory.createAsExpression(factory.createSatisfiesExpression(node, getSynthesizedDeepClone(type)), type);
322+
if (needsParenthesizedExpressionForAssertion(node)) {
323+
node = factory.createParenthesizedExpression(node);
324+
}
325+
return factory.createAsExpression(factory.createSatisfiesExpression(node, getSynthesizedDeepClone(type)), type);
325326
}
326327

327328
function addInlineAssertion(span: TextSpan): DiagnosticOrDiagnosticAndArguments | undefined {
@@ -574,22 +575,22 @@ function withContext<T>(
574575
case SyntaxKind.Parameter:
575576
case SyntaxKind.PropertyDeclaration:
576577
case SyntaxKind.VariableDeclaration:
577-
return addTypeToVariableLike(node as ParameterDeclaration | PropertyDeclaration | VariableDeclaration);
578+
return addTypeToVariableLike(node as ParameterDeclaration | PropertyDeclaration | VariableDeclaration);
578579
case SyntaxKind.ArrowFunction:
579580
case SyntaxKind.FunctionExpression:
580581
case SyntaxKind.FunctionDeclaration:
581582
case SyntaxKind.MethodDeclaration:
582583
case SyntaxKind.GetAccessor:
583-
return addTypeToSignatureDeclaration(node as SignatureDeclaration, sourceFile);
584+
return addTypeToSignatureDeclaration(node as SignatureDeclaration, sourceFile);
584585
case SyntaxKind.ExportAssignment:
585-
return transformExportAssignment(node as ExportAssignment);
586+
return transformExportAssignment(node as ExportAssignment);
586587
case SyntaxKind.ClassDeclaration:
587-
return transformExtendsClauseWithExpression(node as ClassDeclaration);
588+
return transformExtendsClauseWithExpression(node as ClassDeclaration);
588589
case SyntaxKind.ObjectBindingPattern:
589590
case SyntaxKind.ArrayBindingPattern:
590-
return transformDestructuringPatterns(node as BindingPattern);
591+
return transformDestructuringPatterns(node as BindingPattern);
591592
default:
592-
throw new Error(`Cannot find a fix for the given node ${node.kind}`);
593+
throw new Error(`Cannot find a fix for the given node ${node.kind}`);
593594
}
594595
}
595596

@@ -609,30 +610,30 @@ function withContext<T>(
609610
}
610611

611612
function transformExportAssignment(defaultExport: ExportAssignment): DiagnosticOrDiagnosticAndArguments | undefined {
612-
if (defaultExport.isExportEquals) {
613-
return;
614-
}
615-
616-
const { typeNode } = inferType(defaultExport.expression);
617-
if (!typeNode) return undefined;
618-
changeTracker.replaceNodeWithNodes(sourceFile, defaultExport, [
619-
factory.createVariableStatement(
620-
/*modifiers*/ undefined,
621-
factory.createVariableDeclarationList(
622-
[factory.createVariableDeclaration(
623-
"__default",
624-
/*exclamationToken*/ undefined,
625-
typeNode,
626-
defaultExport.expression,
627-
)],
628-
NodeFlags.Const,
629-
),
630-
),
631-
factory.updateExportAssignment(defaultExport, defaultExport?.modifiers, factory.createIdentifier("__default")),
632-
]);
633-
return [
634-
Diagnostics.Extract_default_export_to_variable,
635-
];
613+
if (defaultExport.isExportEquals) {
614+
return;
615+
}
616+
617+
const { typeNode } = inferType(defaultExport.expression);
618+
if (!typeNode) return undefined;
619+
changeTracker.replaceNodeWithNodes(sourceFile, defaultExport, [
620+
factory.createVariableStatement(
621+
/*modifiers*/ undefined,
622+
factory.createVariableDeclarationList(
623+
[factory.createVariableDeclaration(
624+
"__default",
625+
/*exclamationToken*/ undefined,
626+
typeNode,
627+
defaultExport.expression,
628+
)],
629+
NodeFlags.Const,
630+
),
631+
),
632+
factory.updateExportAssignment(defaultExport, defaultExport?.modifiers, factory.createIdentifier("__default")),
633+
]);
634+
return [
635+
Diagnostics.Extract_default_export_to_variable,
636+
];
636637
}
637638

638639
/**
@@ -660,7 +661,7 @@ function withContext<T>(
660661
/*modifiers*/ undefined,
661662
factory.createVariableDeclarationList(
662663
[factory.createVariableDeclaration(
663-
baseClassName,
664+
baseClassName,
664665
/*exclamationToken*/ undefined,
665666
heritageTypeNode,
666667
heritageExpression.expression,
@@ -915,7 +916,7 @@ function withContext<T>(
915916

916917
function inferType(node: Node): InferenceResult {
917918
if (typePrintMode !== TypePrintMode.FULL) {
918-
return relativeType(node);
919+
return relativeType(node);
919920
}
920921

921922
let type = isValueSignatureDeclaration(node) ?
@@ -1123,7 +1124,7 @@ function withContext<T>(
11231124
}
11241125
}
11251126

1126-
function addTypeToVariableLike(decl: ParameterDeclaration | VariableDeclaration | PropertyDeclaration): DiagnosticOrDiagnosticAndArguments | undefined{
1127+
function addTypeToVariableLike(decl: ParameterDeclaration | VariableDeclaration | PropertyDeclaration): DiagnosticOrDiagnosticAndArguments | undefined {
11271128
const { typeNode } = inferType(decl);
11281129
if (typeNode) {
11291130
if (decl.type) {
@@ -1147,25 +1148,24 @@ function withContext<T>(
11471148
}
11481149
}
11491150

1150-
11511151
// Some --isolatedDeclarations errors are not present on the node that directly needs type annotation, so look in the
11521152
// ancestors to look for node that needs type annotation. This function can return undefined if the AST is ill-formed.
11531153
function findAncestorWithMissingType(node: Node): Node | undefined {
1154-
return findAncestor(node, (n) => {
1155-
return canHaveTypeAnnotation.has(n.kind) &&
1156-
((!isObjectBindingPattern(n) && !isArrayBindingPattern(n)) || isVariableDeclaration(n.parent));
1157-
});
1154+
return findAncestor(node, n => {
1155+
return canHaveTypeAnnotation.has(n.kind) &&
1156+
((!isObjectBindingPattern(n) && !isArrayBindingPattern(n)) || isVariableDeclaration(n.parent));
1157+
});
11581158
}
11591159

11601160
function findBestFittingNode(node: Node, span: TextSpan) {
1161-
while (node && node.end < span.start + span.length) {
1162-
node = node.parent;
1163-
}
1164-
while (node.parent.pos === node.pos && node.parent.end === node.end) {
1165-
node = node.parent;
1166-
}
1167-
if (isIdentifier(node) && hasInitializer(node.parent) && node.parent.initializer) {
1168-
return node.parent.initializer;
1169-
}
1170-
return node;
1161+
while (node && node.end < span.start + span.length) {
1162+
node = node.parent;
1163+
}
1164+
while (node.parent.pos === node.pos && node.parent.end === node.end) {
1165+
node = node.parent;
1166+
}
1167+
if (isIdentifier(node) && hasInitializer(node.parent) && node.parent.initializer) {
1168+
return node.parent.initializer;
1169+
}
1170+
return node;
11711171
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy