Remove isEmpty (#10295)

This commit is contained in:
fisker Cheung authored and GitHub committed 2021-02-11 04:36:10 +02:00
1 parent 9ff161d482
commit 36d3a0c784
3 files changed
+8 -15

No files matched your search

-5
View File
@@ -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,
+4 -4
View File
@@ -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();
+4 -6
View File
@@ -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 (