Skip to content

Commit 7f4d289

Browse files
committed
Nullish Coalescing Operator is more accurate for describing undefined comments length
1 parent 26a9df2 commit 7f4d289

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/slang-printers/print-comments.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export function printComments(
1717
path: AstPath<PrintableNode>,
1818
options: ParserOptions<PrintableNode>
1919
): Doc[] {
20-
const lastPrintableIndex = (node.comments ?? []).findLastIndex(isPrintable);
20+
const lastPrintableIndex = node.comments?.findLastIndex(isPrintable) ?? -1;
2121
if (lastPrintableIndex === -1) {
2222
return [];
2323
}

src/slang-printers/print-preserving-empty-lines.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export function printIndentedPreservingEmptyLines(
4444
print: PrintFunction,
4545
options: ParserOptions<PrintableNode>
4646
): Doc {
47-
return node.items.length > 0 || (node.comments?.length || 0) > 0
47+
return node.items.length > 0 || (node.comments?.length ?? 0) > 0
4848
? printSeparatedItem(
4949
printPreservingEmptyLines(node, path, print, options),
5050
{ firstSeparator: hardline }

0 commit comments

Comments
 (0)