-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
delete normalizeDoc()
#15909
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
delete normalizeDoc()
#15909
Conversation
| </Hello>123 | ||
| </Hello> | ||
| 123 |
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 consider this get correct.
| function fillBuilder() { | ||
| const parts = []; | ||
| let pendingDocs = []; | ||
| function flush() { | ||
| parts.push(pendingDocs); | ||
| pendingDocs = []; | ||
| } | ||
|
|
||
| const self = { | ||
| append(doc) { | ||
| pendingDocs.push(doc); | ||
| return self; | ||
| }, | ||
| appendLine(doc) { | ||
| flush(); | ||
| pendingDocs = []; | ||
| parts.push(doc); | ||
| return self; | ||
| }, | ||
| build() { | ||
| flush(); | ||
| return fill(parts); | ||
| }, | ||
| }; | ||
| return self; | ||
| } |
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.
Possible alternative API
const result = buildFill(($) => {
$.append("a");
$.append("b");
$.appendLine(line);
$.append("c");
})instead of
const builder = fillBuilder();
builder.append("a");
builder.append("b");
builder.appendLine(line);
builder.append("c");
const result = builder.build();| @@ -0,0 +1,30 @@ | |||
| import { fill } from "../builders.js"; | |||
|
|
|||
| function fillBuilder() { | |||
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 might be better to encourage using fillBuilder() instead of fill() since this should be safer.
If you agree, let's discuss on another discussion or issue.
| } | ||
|
|
||
| /** @return {false | 'next' | 'start' | 'end'} */ | ||
| function isPrettierIgnore(node) { |
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.
some functions went to util.
| } | ||
| let length = 1; | ||
| if (shouldPrePrintTripleHardline(path)) { | ||
| length = 3; |
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 can't find input that cover this path. I left it anyway.
https://app.codecov.io/gh/prettier/prettier/blob/main/src%2Flanguage-markdown%2Fprinter-markdown.js#L663
src/document/utils/flatten-fill.js
Outdated
|
|
||
| drain(doc); | ||
|
|
||
| return builder.build(); |
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.
Will something like this work?
const parts = []
// Check last part / parts.index is ODD-EVEN
switch (getDocType(doc)) {
case DOC_TYPE_FILL: {
// concat or turn the last element to array and push the first
// push the rest
break;
}
default:
builder.append(doc);
break;
}
return fill(parts)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.
@fisker
I'm sorry but I don't understand what does it mean / aim at.
Do you mean
- it can be faster?
- it can be more readable?
- prefer cleaner doc? (e.g. prefer
fill("a", line, "b")tofill(["a"], line, ["b"])) - recursion should be avoided?
- fillBuilder looks over-engineering?
I'm not sure whether I understand the pseudo code or not but possibly following case can be a counter-example.
input: ["a", fill(["b", line, "c", line]), "b"]
expected output: fill(join(line, [["a", "b"], ["c"], ["b"]]))
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 simply, so we don't need fillBuilder. Can you find other places that we want a "flat" fill?
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.
| let head = doc; | ||
| let rest = []; | ||
| if (docType === DOC_TYPE_FILL) { | ||
| [head, ...rest] = doc.parts; |
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 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.
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 going to run some test first, prettier/prettier-regression-testing#435 (comment)
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 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.
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.
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 havefill()as children.if (shouldRemainTheSameContent(path)) {block in printer-markdown.js: same asprintSentence().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.
Co-authored-by: fisker Cheung <[email protected]>
|
Sorry that I have to rebase to reduce diff in prettier/prettier-regression-testing#435 (comment) |
|
Wow, we are breaking (or maybe improving) a LOT... prettier/prettier-regression-testing#435 (comment) Good opportunity to add more tests. Better add all of them to our tests first (in other PR). |
|
Maybe this PR makes embedded code and normal code consistent. I'll check them. Memo about regression testcontent/files/en-us/learn/css/building_blocks/backgrounds_and_borders/index.md✅ It get consistent Detailsdiff --git ORI/content/files/en-us/learn/css/building_blocks/backgrounds_and_borders/index.md ALT/content/files/en-us/learn/css/building_blocks/backgrounds_and_borders/index.md
index f9114358..dd09ac79 100644
--- ORI/content/files/en-us/learn/css/building_blocks/backgrounds_and_borders/index.md
+++ ALT/content/files/en-us/learn/css/building_blocks/backgrounds_and_borders/index.md
@@ -46,7 +46,8 @@ The CSS {{cssxref("background")}} property is a shorthand for a number of backgr
105deg,
rgb(255 255 255 / 20%) 39%,
rgb(51 56 57 / 100%) 96%
- ) center center / 400px 200px no-repeat,
+ )
+ center center / 400px 200px no-repeat,
url(big-star.png) center no-repeat,
rebeccapurple;
}Stable pure CSS printer: .box {
background:
linear-gradient(
105deg,
rgb(255 255 255 / 20%) 39%,
rgb(51 56 57 / 100%) 96%
)
center center / 400px 200px no-repeat,
url(big-star.png) center no-repeat,
rebeccapurple;
}/content/files/en-us/learn/javascript/client-side_web_apis/video_and_audio_apis/index.md✅ It get consitent Detailsdiff --git ORI/content/files/en-us/learn/javascript/client-side_web_apis/video_and_audio_apis/index.md ALT/content/files/en-us/learn/javascript/client-side_web_apis/video_and_audio_apis/index.md
index 30056ef5..e11799e7 100644
--- ORI/content/files/en-us/learn/javascript/client-side_web_apis/video_and_audio_apis/index.md
+++ ALT/content/files/en-us/learn/javascript/client-side_web_apis/video_and_audio_apis/index.md
@@ -144,7 +144,8 @@ Next, let's look at our button icons:
font-family: "HeydingsControlsRegular";
src: url("fonts/heydings_controls-webfont.eot");
src:
- url("fonts/heydings_controls-webfont.eot?#iefix") format("embedded-opentype"),
+ url("fonts/heydings_controls-webfont.eot?#iefix")
+ format("embedded-opentype"),
url("fonts/heydings_controls-webfont.woff") format("woff"),
url("fonts/heydings_controls-webfont.ttf") format("truetype");
font-weight: normal;Stable pure CSS printer: @font-face {
font-family: "HeydingsControlsRegular";
src: url("fonts/heydings_controls-webfont.eot");
src:
url("fonts/heydings_controls-webfont.eot?#iefix")
format("embedded-opentype"),
url("fonts/heydings_controls-webfont.woff") format("woff"),
url("fonts/heydings_controls-webfont.ttf") format("truetype");
font-weight: normal;
font-style: normal;
} |
|
be4b1c6 can make some sense to me but it looks technically incorrect (but it can be safe for |
|
Feel free to revert e85797f if you regard type safety as important. |
|
|
If you worry about edge cases,
|
|
I see. I'll remove the edge case consideration. I have considered fill can have even length because printer cares even length: prettier/src/document/printer.js Lines 491 to 498 in 1ea2fd0
(I consider "fill should alway have even length" is typo of "rest should alway have even length" or "fill should alway have odd length") |
|
The |
This comment was marked as outdated.
This comment was marked as outdated.
|
@fisker |
Yes, please |
|
I opened #15993 🚀 |
Description
Resolves #15877 and #9503.
flattenFill()is the key.Checklist
(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✨