Rewrite a deep nested ternary makeAlign (#8931)
* Rewrite a deep nested ternary `makeAlign` * Rename `ind`
This commit is contained in:
1 parent
ba15a5768e
commit
6ae716cd69
1 file changed
+20
-12
+20
-12
@@ -18,18 +18,26 @@ function makeIndent(ind, options) {
|
||||
return generateInd(ind, { type: "indent" }, options);
|
||||
}
|
||||
|
||||
function makeAlign(ind, n, options) {
|
||||
return n === -Infinity
|
||||
? ind.root || rootIndent()
|
||||
: n < 0
|
||||
? generateInd(ind, { type: "dedent" }, options)
|
||||
: !n
|
||||
? ind
|
||||
: n.type === "root"
|
||||
? { ...ind, root: ind }
|
||||
: typeof n === "string"
|
||||
? generateInd(ind, { type: "stringAlign", n }, options)
|
||||
: generateInd(ind, { type: "numberAlign", n }, options);
|
||||
function makeAlign(indent, n, options) {
|
||||
if (n === -Infinity) {
|
||||
return indent.root || rootIndent();
|
||||
}
|
||||
|
||||
if (n < 0) {
|
||||
return generateInd(indent, { type: "dedent" }, options);
|
||||
}
|
||||
|
||||
if (!n) {
|
||||
return indent;
|
||||
}
|
||||
|
||||
if (n.type === "root") {
|
||||
return { ...indent, root: indent };
|
||||
}
|
||||
|
||||
const alignType = typeof n === "string" ? "stringAlign" : "numberAlign";
|
||||
|
||||
return generateInd(indent, { type: alignType, n }, options);
|
||||
}
|
||||
|
||||
function generateInd(ind, newPart, options) {
|
||||
|
||||
Reference in new issue
Block a user