Minor refactoring of printObject (#10696)
This commit is contained in:
1 parent
641fe5e3a4
commit
97db2e3926
1 file changed
+21
-20
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user