Skip to content

Commit d37d464

Browse files
christian-byrneConnor Byrne
authored andcommitted
refactor: simplify toPreviewText by removing redundant branches
Array.prototype.join already calls String() on non-nullish elements, so the .map() was identity after .filter(). The typeof string fast path returned the same result as the trailing String(text), so it was a no-op too. Four branches collapse to three with identical behavior. Side benefit: return String(text) is now the path strings take, fixing the Codecov uncovered-line flag. Addresses review feedback: #14073 (comment)
1 parent db5abec commit d37d464

1 file changed

Lines changed: 1 addition & 6 deletions

File tree

src/extensions/core/textPreviewWidgets.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,8 @@ export function addTextPreviewWidgets(node: LGraphNode) {
6767
}
6868

6969
function toPreviewText(text: unknown): string {
70-
if (typeof text === 'string') return text
7170
if (text == null) return ''
72-
if (Array.isArray(text))
73-
return text
74-
.filter((part) => part != null)
75-
.map((part) => (typeof part === 'string' ? part : String(part)))
76-
.join('\n\n')
71+
if (Array.isArray(text)) return text.filter((part) => part != null).join('\n\n')
7772
return String(text)
7873
}
7974

0 commit comments

Comments
 (0)