Simplify printMemberChain (#16535)

This commit is contained in:
fisker Cheung authored and GitHub committed 2024-08-10 00:28:47 +01:00
1 parent 5923e69901
commit 77dead370b
1 file changed
+6 -6
+6 -6
View File
@@ -94,11 +94,11 @@ function printMemberChain(path, options, print) {
return isNextLineEmpty(node, options);
}
function rec(path) {
function rec() {
const { node } = path;
if (node.type === "ChainExpression") {
return path.call(() => rec(path), "expression");
return path.call(rec, "expression");
}
if (
@@ -122,7 +122,7 @@ function printMemberChain(path, options, print) {
hasTrailingEmptyLine ? hardline : "",
],
});
path.call((callee) => rec(callee), "callee");
path.call(rec, "callee");
} else if (isMemberish(node)) {
printedNodes.unshift({
node,
@@ -135,13 +135,13 @@ function printMemberChain(path, options, print) {
options,
),
});
path.call((object) => rec(object), "object");
path.call(rec, "object");
} else if (node.type === "TSNonNullExpression") {
printedNodes.unshift({
node,
printed: printComments(path, "!", options),
});
path.call((expression) => rec(expression), "expression");
path.call(rec, "expression");
} else {
printedNodes.unshift({
node,
@@ -163,7 +163,7 @@ function printMemberChain(path, options, print) {
});
if (node.callee) {
path.call((callee) => rec(callee), "callee");
path.call(rec, "callee");
}
// Once we have a linear list of printed nodes, we want to create groups out