Skip to content

Commit

Permalink
reorganising the logic for clarity and to avoid having to check for e…
Browse files Browse the repository at this point in the history
…xtra lines added by mistake at the end
  • Loading branch information
Janther committed Oct 31, 2023
1 parent 0a84cc2 commit 95b903e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/common/printer-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,15 @@ export function printPreservingEmptyLines(path, key, options, print) {

parts.push(print(childPath));

if (isNextLineEmpty(options.originalText, options.locEnd(node) + 1)) {
parts.push(hardline);
} else if (
nodeType === 'FunctionDefinition' &&
!isLast(childPath, key, index)
) {
parts.push(separatingLine(node, next(childPath, key, index)));
if (!isLast(childPath, key, index)) {
if (isNextLineEmpty(options.originalText, options.locEnd(node) + 1)) {
parts.push(hardline);
} else if (nodeType === 'FunctionDefinition') {
parts.push(separatingLine(node, next(childPath, key, index)));
}
}
}, key);

if (parts.length > 1 && parts[parts.length - 1] === hardline) {
parts.pop();
}

return parts;
}

Expand Down

0 comments on commit 95b903e

Please sign in to comment.