Minor refactoring of printObject (#10696)

This commit is contained in:
Georgii Dolzhykov authored and GitHub committed 2021-04-12 05:20:27 +03:00
1 parent 641fe5e3a4
commit 97db2e3926
1 file changed
+21 -20
+21 -20
View File
@@ -41,11 +41,10 @@ function printObject(path, options, print) {
}
const isTypeAnnotation = node.type === "ObjectTypeAnnotation";
const fields = [];
const fields = [propertiesField];
if (isTypeAnnotation) {
fields.push("indexers", "callProperties", "internalSlots");
}
fields.push(propertiesField);
const firstProperty = fields
.map((field) => node[field][0])
@@ -109,26 +108,28 @@ function printObject(path, options, print) {
}, field);
}
if (fields.length > 1) {
propsAndLoc.sort((a, b) => a.loc - b.loc);
}
/** @type {Doc[]} */
let separatorParts = [];
const props = propsAndLoc
.sort((a, b) => a.loc - b.loc)
.map((prop) => {
const result = [...separatorParts, group(prop.printed)];
separatorParts = [separator, line];
if (
(prop.node.type === "TSPropertySignature" ||
prop.node.type === "TSMethodSignature" ||
prop.node.type === "TSConstructSignatureDeclaration") &&
hasComment(prop.node, CommentCheckFlags.PrettierIgnore)
) {
separatorParts.shift();
}
if (isNextLineEmpty(prop.node, options)) {
separatorParts.push(hardline);
}
return result;
});
const props = propsAndLoc.map((prop) => {
const result = [...separatorParts, group(prop.printed)];
separatorParts = [separator, line];
if (
(prop.node.type === "TSPropertySignature" ||
prop.node.type === "TSMethodSignature" ||
prop.node.type === "TSConstructSignatureDeclaration") &&
hasComment(prop.node, CommentCheckFlags.PrettierIgnore)
) {
separatorParts.shift();
}
if (isNextLineEmpty(prop.node, options)) {
separatorParts.push(hardline);
}
return result;
});
if (node.inexact) {
let printed;