Skip to content

Commit be4b1c6

Browse files
committed
Simplify logic
1 parent ac997cc commit be4b1c6

1 file changed

Lines changed: 13 additions & 16 deletions

File tree

src/language-markdown/print-paragraph.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,20 @@ function flattenFill(docs) {
3131
*/
3232
(function rec(docArray) {
3333
for (const doc of docArray) {
34-
switch (getDocType(doc)) {
35-
case DOC_TYPE_FILL: {
36-
const [head, ...rest] = doc.parts;
37-
parts.at(-1).push(head);
38-
parts.push(...rest.map((doc) => [doc]));
39-
if (rest.length % 2 === 1) {
40-
parts.push([]);
41-
}
42-
break;
43-
}
44-
case DOC_TYPE_ARRAY:
45-
rec(doc);
46-
break;
47-
default:
48-
parts.at(-1).push(doc);
49-
break;
34+
const docType = getDocType(doc);
35+
if (docType === DOC_TYPE_ARRAY) {
36+
rec(doc);
37+
continue;
5038
}
39+
40+
let head = doc;
41+
let rest = [];
42+
if (docType === DOC_TYPE_FILL) {
43+
[head, ...rest] = doc.parts;
44+
}
45+
46+
parts[parts.length - 1] = [parts.at(-1), head];
47+
parts.push(...rest);
5148
}
5249
})(docs);
5350

0 commit comments

Comments
 (0)