Skip to content

Conversation

@seiyab
Copy link
Collaborator

@seiyab seiyab commented Sep 28, 2024

Description

#16582

Checklist

  • I’ve added tests to confirm my change works.
    • Should we have test for assertDocFill()? -> done
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

Try the playground for this PR

const rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}';
const jsxWhitespace = isMdxBlock
? " "
? line
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm worrying that it might not be just a careless mistake. I'm not familiar with MDX at all...

@seiyab seiyab marked this pull request as ready for review September 30, 2024 05:47
};

export { assertDoc, assertDocArray };
const assertDocFill =
Copy link
Member

Choose a reason for hiding this comment

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

assertDocFillParts, since it only accept parts not fill

hasUnexpectedString = true;
return;
case DOC_TYPE_IF_BREAK:
traverseDoc(doc.breakContents, rec);
Copy link
Member

Choose a reason for hiding this comment

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

Is this still needed if we use the last argument in outer traverse ?

function traverseDoc(doc, onEnter, onExit, shouldTraverseConditionalGroups) {

Copy link
Collaborator Author

@seiyab seiyab Sep 30, 2024

Choose a reason for hiding this comment

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

Maybe yes. shouldTraverseConditoinalGroups doesn't affect ifBreak(), where we want to modify the behavior.

function ifBreak(breakContents, flatContents = "", opts = {}) {
assertDoc(breakContents);
if (flatContents !== "") {
assertDoc(flatContents);
}
return {
type: DOC_TYPE_IF_BREAK,
breakContents,
flatContents,
groupId: opts.groupId,
};
}

case DOC_TYPE_GROUP:
if (shouldTraverseConditionalGroups && doc.expandedStates) {
for (let ic = doc.expandedStates.length, i = ic - 1; i >= 0; --i) {
docsStack.push(doc.expandedStates[i]);
}
} else {
docsStack.push(doc.contents);
}
break;

case DOC_TYPE_IF_BREAK:
docsStack.push(doc.flatContents, doc.breakContents);
break;

Or do I misunderstand?

Comment on lines +67 to +69
throw new Error(
`Unexpected non-line-break doc at ${i}. Doc type is ${type}.`,
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Using InvalidDocError is not straightforward because InvalidDocError considers such documents valid. Error message gets weird and very hard to understand (message: "doc is valid").
I use just Error here.

@seiyab seiyab requested a review from fisker October 1, 2024 02:51
@seiyab
Copy link
Collaborator Author

seiyab commented Nov 4, 2024

@fisker ping (no hurry)

@fisker
Copy link
Member

fisker commented Nov 24, 2024

I'm really sorry for the long delay, I was super busy recently.

Change looks good, the only reason I didn't approve is that I'm not sure about using cleanDoc, generally it should be avoid but I'm not sure if it's really necessary.

}

/**
* returns true iff cleanDoc(doc) === ""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* returns true iff cleanDoc(doc) === ""
* returns true if cleanDoc(doc) === ""

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's intentional. I mean "if and only if"
https://en.wikipedia.org/wiki/If_and_only_if

"if and only if" (often shortened as "iff")

Copy link
Member

Choose a reason for hiding this comment

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

TIL

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 21, 2024

Open in Stackblitz

npm i https://pkg.pr.new/prettier@16700

commit: ae937dc

@fisker fisker requested a review from sosukesuzuki January 20, 2025 06:28
@fisker fisker added this to the 3.5 milestone Jan 20, 2025
@sosukesuzuki sosukesuzuki merged commit 97d8115 into prettier:main Jan 21, 2025
31 checks passed
@seiyab seiyab deleted the jsx-children-satisfy-rule-of-fill branch January 21, 2025 04:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants