diff --git a/src/domain/functionComparisonDimensions.ts b/src/domain/functionComparisonDimensions.ts index 2b0b6a156cd..fa88f9b5514 100644 --- a/src/domain/functionComparisonDimensions.ts +++ b/src/domain/functionComparisonDimensions.ts @@ -234,28 +234,46 @@ const compareStringsAndNames = ( const stringFacts = compareReferencedStrings(leftStrings, rightStrings); const leftNamesAndLiterals = nameAndSwiftProjection(left, complete); const rightNamesAndLiterals = nameAndSwiftProjection(right, complete); - if (stringFacts.changed) - return stringsAndNamesResult({ - leftStrings, - rightStrings, - leftNamesAndLiterals, - rightNamesAndLiterals, - context, - status: "changed", - limitations: [ - ...stringFacts.limitations, - ...(leftNamesAndLiterals === null || rightNamesAndLiterals === null - ? [ - "Reference source locations could not be normalized to function offsets.", - ] - : []), - ...(complete - ? [] - : [ - "Swift String literal coverage differs or is partial; complete coverage does not establish a differing literal.", - ]), - ], + const result = ( + status: "changed" | "unchanged", + limitations: readonly string[] = [], + leftNames = leftNamesAndLiterals, + rightNames = rightNamesAndLiterals, + ): FunctionDimension => + dimensionResult({ + dimension: "strings_names", + status, + left: { + referenced_strings: leftStrings, + names_and_literals: leftNames, + }, + right: { + referenced_strings: rightStrings, + names_and_literals: rightNames, + }, + ...context, + // Names that cannot be placed in the function leave the side's count unknown. + leftCount: + leftNames === null ? null : leftStrings.length + leftNames.length, + rightCount: + rightNames === null ? null : rightStrings.length + rightNames.length, + textDelta: null, + limitations, }); + if (stringFacts.changed) + return result("changed", [ + ...stringFacts.limitations, + ...(leftNamesAndLiterals === null || rightNamesAndLiterals === null + ? [ + "Reference source locations could not be normalized to function offsets.", + ] + : []), + ...(complete + ? [] + : [ + "Swift String literal coverage differs or is partial; complete coverage does not establish a differing literal.", + ]), + ]); if (leftNamesAndLiterals === null || rightNamesAndLiterals === null) return unresolvedDimension({ dimension: "strings_names", @@ -273,15 +291,7 @@ const compareStringsAndNames = ( context, ); if (compared.status === "changed") - return stringsAndNamesResult({ - leftStrings, - rightStrings, - leftNamesAndLiterals, - rightNamesAndLiterals, - context, - status: "changed", - limitations: stringFacts.limitations, - }); + return result("changed", stringFacts.limitations); // A retained literal differs only when the opposite dossier establishes its absence. if (swiftLiteralSitesConflict(left, right)) { const leftAll = nameAndSwiftProjection(left); @@ -294,15 +304,7 @@ const compareStringsAndNames = ( context, ); if (literalComparison.status === "changed") - return stringsAndNamesResult({ - leftStrings, - rightStrings, - leftNamesAndLiterals: leftAll, - rightNamesAndLiterals: rightAll, - context, - status: "changed", - limitations: stringFacts.limitations, - }); + return result("changed", stringFacts.limitations, leftAll, rightAll); } } const limitations = [ @@ -313,15 +315,7 @@ const compareStringsAndNames = ( "Swift String literal coverage differs or is partial; complete coverage does not establish a differing literal.", ]), ]; - if (limitations.length === 0) - return stringsAndNamesResult({ - leftStrings, - rightStrings, - leftNamesAndLiterals, - rightNamesAndLiterals, - context, - status: "unchanged", - }); + if (limitations.length === 0) return result("unchanged"); return unresolvedDimension({ dimension: "strings_names", links: context.links, @@ -331,48 +325,6 @@ const compareStringsAndNames = ( }); }; -const stringsAndNamesResult = ({ - leftStrings, - rightStrings, - leftNamesAndLiterals, - rightNamesAndLiterals, - context, - status, - limitations = [], -}: { - readonly leftStrings: readonly ReferencedStringFact[]; - readonly rightStrings: readonly ReferencedStringFact[]; - readonly leftNamesAndLiterals: readonly unknown[] | null; - readonly rightNamesAndLiterals: readonly unknown[] | null; - readonly context: ComparisonContext; - readonly status: "changed" | "unchanged"; - readonly limitations?: readonly string[]; -}): FunctionDimension => - dimensionResult({ - dimension: "strings_names", - status, - left: { - referenced_strings: leftStrings, - names_and_literals: leftNamesAndLiterals, - }, - right: { - referenced_strings: rightStrings, - names_and_literals: rightNamesAndLiterals, - }, - ...context, - // Names that cannot be placed in the function leave the side's count unknown. - leftCount: - leftNamesAndLiterals === null - ? null - : leftStrings.length + leftNamesAndLiterals.length, - rightCount: - rightNamesAndLiterals === null - ? null - : rightStrings.length + rightNamesAndLiterals.length, - textDelta: null, - limitations, - }); - type ReferencedStringFact = ReturnType< typeof referencedStringProjection >[number];