diff --git a/src/document/doc-utils.js b/src/document/doc-utils.js index 796944900..b34b9caf4 100644 --- a/src/document/doc-utils.js +++ b/src/document/doc-utils.js @@ -104,10 +104,6 @@ function findInDoc(doc, fn, defaultValue) { return result; } -function isEmpty(n) { - return typeof n === "string" && n.length === 0; -} - function isLineNextFn(doc) { if (typeof doc === "string") { return false; @@ -382,7 +378,6 @@ function replaceNewlinesWithLiterallines(doc) { module.exports = { isConcat, getDocParts, - isEmpty, willBreak, isLineNext, traverseDoc, diff --git a/src/language-js/print/jsx.js b/src/language-js/print/jsx.js index 05c1a8426..77fb7b5c8 100644 --- a/src/language-js/print/jsx.js +++ b/src/language-js/print/jsx.js @@ -14,7 +14,7 @@ const { lineSuffixBoundary, join, }, - utils: { willBreak, isLineNext, isEmpty }, + utils: { willBreak, isLineNext }, } = require("../../document"); const { getLast, getPreferredQuote } = require("../../common/util"); @@ -177,7 +177,7 @@ function printJsxElementInternal(path, options, print) { // Trim trailing lines (or empty strings) while ( children.length > 0 && - (isLineNext(getLast(children)) || isEmpty(getLast(children))) + (!getLast(children) || isLineNext(getLast(children))) ) { children.pop(); } @@ -185,8 +185,8 @@ function printJsxElementInternal(path, options, print) { // Trim leading lines (or empty strings) while ( children.length > 0 && - (isLineNext(children[0]) || isEmpty(children[0])) && - (isLineNext(children[1]) || isEmpty(children[1])) + (!children[0] || isLineNext(children[0])) && + (!children[1] || isLineNext(children[1])) ) { children.shift(); children.shift(); diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index e419dfcc1..a4f679463 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -15,7 +15,6 @@ const { } = require("../common/util"); const { builders: { join, line, hardline, softline, literalline, group, indent }, - utils: { isEmpty }, } = require("../document"); const embed = require("./embed"); const clean = require("./clean"); @@ -97,14 +96,13 @@ const { printBlock, printBlockBody } = require("./print/block"); const { printComment } = require("./print/comment"); function genericPrint(path, options, printPath, args) { - const node = path.getValue(); - let needsParens = false; const linesWithoutParens = printPathNoParens(path, options, printPath, args); - - if (!node || isEmpty(linesWithoutParens)) { - return linesWithoutParens; + if (!linesWithoutParens) { + return ""; } + let needsParens = false; + const node = path.getValue(); const parentExportDecl = getParentExportDeclaration(path); const decorators = []; if (