-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Resolve rule of fill violation in JSX and add assertion. #16700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolve rule of fill violation in JSX and add assertion. #16700
Conversation
| const rawJsxWhitespace = options.singleQuote ? "{' '}" : '{" "}'; | ||
| const jsxWhitespace = isMdxBlock | ||
| ? " " | ||
| ? line |
There was a problem hiding this comment.
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...
src/document/utils/assert-doc.js
Outdated
| }; | ||
|
|
||
| export { assertDoc, assertDocArray }; | ||
| const assertDocFill = |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
prettier/src/document/builders.js
Lines 120 to 132 in 94fa86e
| function ifBreak(breakContents, flatContents = "", opts = {}) { | |
| assertDoc(breakContents); | |
| if (flatContents !== "") { | |
| assertDoc(flatContents); | |
| } | |
| return { | |
| type: DOC_TYPE_IF_BREAK, | |
| breakContents, | |
| flatContents, | |
| groupId: opts.groupId, | |
| }; | |
| } |
prettier/src/document/utils/traverse-doc.js
Lines 68 to 76 in 1ea2fd0
| 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; |
prettier/src/document/utils/traverse-doc.js
Lines 64 to 66 in 1ea2fd0
| case DOC_TYPE_IF_BREAK: | |
| docsStack.push(doc.flatContents, doc.breakContents); | |
| break; |
Or do I misunderstand?
| throw new Error( | ||
| `Unexpected non-line-break doc at ${i}. Doc type is ${type}.`, | ||
| ); |
There was a problem hiding this comment.
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.
|
@fisker ping (no hurry) |
|
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 |
| } | ||
|
|
||
| /** | ||
| * returns true iff cleanDoc(doc) === "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| * returns true iff cleanDoc(doc) === "" | |
| * returns true if cleanDoc(doc) === "" |
There was a problem hiding this comment.
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")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL
Co-authored-by: fisker Cheung <[email protected]>
commit: |
Description
#16582
Checklist
assertDocFill()? -> done(If changing the API or CLI) I’ve documented the changes I’ve made (in thedocs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.✨Try the playground for this PR✨