Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove type
  • Loading branch information
seiyab committed Jan 25, 2024
commit e85797f53a2dc10b078510bbdb444534e7ab95a4
11 changes: 4 additions & 7 deletions src/language-markdown/print-paragraph.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fill } from "../document/builders.js";
import { DOC_TYPE_ARRAY, DOC_TYPE_FILL } from "../document/constants.js";
import { getDocParts, getDocType } from "../document/utils.js";
import { getDocType } from "../document/utils.js";

/**
* @typedef {import("../common/ast-path.js").default} AstPath
Expand Down Expand Up @@ -31,21 +31,18 @@ function flattenFill(docs) {
/** @type {Doc[]} */
const parts = [""];

/**
* @param {Doc[]} docArray
*/
(function rec(docArray) {
(function rec(/** @type {*} */ docArray) {
for (const doc of docArray) {
const docType = getDocType(doc);
if (docType === DOC_TYPE_ARRAY) {
rec(getDocParts(doc));
rec(doc);
continue;
}

let head = doc;
let rest = [];
if (docType === DOC_TYPE_FILL) {
[head, ...rest] = getDocParts(doc);
[head, ...rest] = doc.parts;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this part, do we need go deeper? head and docs in rest can also be DOC_TYPE_ARRAY or DOC_TYPE_FILL.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to run some test first, prettier/prettier-regression-testing#435 (comment)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not very sure it. But probably fill() isn't nested in paragraph. If we want to go deeper, we should take care that we should go deeper only even (odd for doc.parts) index element.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Searching "fill" in src/language-markdown, I confirmed fill() can't be nested in markdown. There are three use of fill():

  • printSentence() in print-sentence.js: sentence only contains word and whitespace that turns into simple docs like string or line-like. It won't have fill() as children.
  • if (shouldRemainTheSameContent(path)) { block in printer-markdown.js: same as printSentence().
  • flattenFill() in print-paragraph.js: paragraph can't be nested and the other children neither yield nested as described above.

So I think we don't need go deeper for elements of fill() as of now. But feel free to ask me to add recursive flattening for fill if you still worry about it.

if (rest.length % 2 === 1) {
rest.push("");
}
Expand Down